-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhelper.ts
100 lines (92 loc) · 2.64 KB
/
helper.ts
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import {
searchUser,
getToken,
createQuestionnarie,
changeOwnerQuestionnarie,
changeQuestionAnswers,
changeQuestionAnswer,
createUser,
activateUser,
searchQuestionnarie,
} from "./dmp-api";
import mapping from "./useroffice-dmp-mapping.json";
import facilityInformation from "./facilityInformation.json";
import instrumentInformation from "./instrumentInformation.json";
import {
ProposalAcceptedMessage,
ProposalTopicAnswer,
} from "./messageInterfaces";
export async function addUser(acceptMessage: ProposalAcceptedMessage) {
let users = await searchUser(
`${acceptMessage.proposer.firstName} ${acceptMessage.proposer.lastName}`
);
let userUuid = "";
if (users.length === 0) {
userUuid = await createUser(
acceptMessage.proposer.firstName,
acceptMessage.proposer.lastName,
acceptMessage.proposer.email,
" "
);
return await activateUser(
userUuid,
acceptMessage.proposer.firstName,
acceptMessage.proposer.lastName,
acceptMessage.proposer.email,
" "
);
} else {
return users[0].uuid;
}
}
// this will create a new questionnarie with the facility information set
export async function addDMP(
acceptMessage: ProposalAcceptedMessage,
userUuid: string
) {
let questionnaireUuid = await createQuestionnarie("tmp");
await changeOwnerQuestionnarie(
`${acceptMessage.shortCode}-DMP`,
questionnaireUuid,
userUuid
);
// Set initial information about PI and already known facility information
await changeQuestionAnswer(
questionnaireUuid,
mapping.projectCoordinator,
`${acceptMessage.proposer.firstName} ${acceptMessage.proposer.lastName}`
);
await changeQuestionAnswers(questionnaireUuid, facilityInformation.data);
return questionnaireUuid;
}
export async function updateDMP(acceptMessage: ProposalAcceptedMessage) {
const uuid = await searchQuestionnarie(acceptMessage.shortCode);
if (uuid.length === 1) {
const questionnaireUuid = uuid[0].uuid;
await changeQuestionAnswer(
questionnaireUuid,
mapping.title,
acceptMessage.title
);
await changeQuestionAnswer(
questionnaireUuid,
mapping.abstract,
acceptMessage.abstract
);
await changeQuestionAnswer(
questionnaireUuid,
mapping.purpose,
acceptMessage.abstract
);
await changeQuestionAnswer(
questionnaireUuid,
mapping.projectCoordinator,
`${acceptMessage.proposer.firstName} ${acceptMessage.proposer.lastName}`
);
await changeQuestionAnswer(
questionnaireUuid,
mapping.dataPerson,
`${acceptMessage.proposer.firstName} ${acceptMessage.proposer.lastName}`
);
}
}