Seyi Adebajo 4d0d746fe3 adds typescript. adds mirage. updates dependencies. begins separating api concerns from app: datasets. removes jshint.
adds mirage model+factory for compliance suggestion

updates gitignore: removes typings. adds environment.d.ts declaration file for config/environment. adds unit test for datasets-test. adds extracted datasets api file

updates destroy app test helper

updates compliance component to work with modified api from compliance api: removes isSubject, adds securityClassification

updates uploaded compliance shape validation. updates the dataset route

adds typescript files to prettier linting

updates gitignore with vscode
2017-08-16 10:04:36 -07:00

56 lines
1.9 KiB
TypeScript

import Ember from 'ember';
/// <reference path='wherehows-web/typings/untyped-js-module' />
import { createInitialComplianceInfo } from 'wherehows-web/utils/datasets/functions';
import { apiRoot } from 'wherehows-web/utils/api';
const { $: { getJSON }, assert } = Ember;
/**
* Defines the endpoint for datasets
* @type {string}
*/
const datasetsUrlRoot = `${apiRoot}/datasets`;
/**
* Constructs a url to get a dataset with a given id
* @param {number} id the id of the dataset
* @return {string} the dataset url
*/
const datasetUrlById = (id: number): string => `${datasetsUrlRoot}/${id}`;
/**
* Constructs the dataset compliance url
* @param {number} id the id of the dataset
* @return {string} the dataset compliance url
*/
const datasetComplianceUrlById = (id: number): string => `${datasetUrlById(id)}/compliance`;
/**
* Fetches the current compliance policy for a dataset with thi given id
* @param {number} id the id of the dataset
* @return {Promise<{isNewComplianceInfo: boolean, complianceInfo: *}>}
*/
const datasetComplianceFor = async (id: number): Promise<{ isNewComplianceInfo: boolean; complianceInfo: any }> => {
assert(`Expected id to be a number but received ${typeof id}`, typeof id === 'number');
const failedStatus = 'failed';
const notFound = 'actual 0';
// complianceInfo contains the compliance data for the specified dataset
let {
msg = '',
status,
complianceInfo
}: { msg: string; status: string; complianceInfo: any } = await Promise.resolve(
getJSON(datasetComplianceUrlById(id))
);
// If the endpoint responds with a failed status, and the msg contains the indicator that a compliance does not exist
const isNewComplianceInfo: boolean = status === failedStatus && String(msg).includes(notFound);
if (isNewComplianceInfo) {
complianceInfo = createInitialComplianceInfo(id);
}
return { isNewComplianceInfo, complianceInfo };
};
export { datasetsUrlRoot, datasetComplianceFor };