-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproteins.js
82 lines (67 loc) · 2.51 KB
/
proteins.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
'use strict';
import bsi from './bsi/module.js';
import dynamo from './dynamo/module.js';
import got from 'got';
import { SecretsManager } from '@aws-sdk/client-secrets-manager';
const secretClient = new SecretsManager();
var proteinsModule = (() => {
async function getCdrSecrets() {
return secretClient.getSecretValue({SecretId: process.env.CDR_SECRET});
}
async function createCdrRequest(proteins) {
let data = await getCdrSecrets();
var secrets = JSON.parse(data.SecretString);
const url = process.env.CDR_BASE_URL + 'proteinEvent/';
let response = await got.post(url, {
json: proteins,
username: secrets.username,
password: secrets.password,
throwHttpErrors: false,
});
return response.statusCode;
}
return {
pullRecentChanges: async () => {
await bsi.login();
var lastUpdated = await dynamo.getLatest('Case');
var bsiCases = await bsi.cases.getUpdated(lastUpdated.lastModified);
for (let index = 0; index < bsiCases.length; index++) {
var protein = await bsi.proteins.get(bsiCases[index]);
if (protein) {
await dynamo.proteins.update(protein);
}
}
await dynamo.updateLatest(lastUpdated);
await bsi.logoff();
},
sync: async (protein) => {
console.log("Syncing " + protein.caseId + " to CDR.");
var lastModified = protein.lastModified;
delete protein.lastModified;
var statusCode = await createCdrRequest(protein);
console.log("Recording status code " + statusCode + ".");
await dynamo.proteins.updateSync({
caseId: protein.caseId,
lastModified: lastModified,
lastSynced: new Date().toISOString(),
syncResult: statusCode
});
},
dynamoToJson: (data) => {
return dynamo.toJson(data);
},
get: async (caseId) => {
return dynamo.proteins.get(caseId);
},
getSync: async (caseId) => {
return dynamo.proteins.getSync(caseId);
},
rebuild: async (caseId) => {
await bsi.login();
var protein = await bsi.proteins.get(caseId);
await dynamo.proteins.update(protein);
await bsi.logoff();
}
};
})();
export default proteinsModule;