-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApplicationActions.ts
78 lines (71 loc) · 2.16 KB
/
ApplicationActions.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
import { DateTime } from "luxon";
import { Application } from "&server/models/Application";
import { callInternalAPI } from "&server/utils/ActionUtils";
import { HttpMethod } from "&server/models/HttpMethod";
import urls from "&utils/urls";
import { contactFromJsonResponse } from "&server/models/Contact";
import { NewApplication } from "&server/mongodb/actions/ApplicationManager";
const applicationRoute = urls.api.application;
export async function createApplication(
application: NewApplication
): Promise<Application> {
const response: Record<string, any> = await callInternalAPI(
applicationRoute,
HttpMethod.PUT,
{
application: application,
}
);
return applicationFromJson(response);
}
export async function getApplicationById(
applicationId: string
): Promise<Application> {
const response: Record<string, any> = await callInternalAPI(
applicationRoute + `?id=${applicationId}`,
HttpMethod.GET
);
return applicationFromJson(response);
}
export async function getApplications(
adminAll = false
): Promise<Application[]> {
const response: Record<string, any>[] = await callInternalAPI(
applicationRoute + `?all=${adminAll}`,
HttpMethod.GET
);
return response.map(applicationFromJson);
}
export async function deleteApplication(
applicationId: string
): Promise<Application> {
const response: Record<string, any> = await callInternalAPI(
applicationRoute + `?id=${applicationId}`,
HttpMethod.DELETE
);
return applicationFromJson(response);
}
export async function updateApplicationDecision(
applicationId: string,
decision: boolean
): Promise<Application> {
const response: Record<string, any> = await callInternalAPI(
applicationRoute,
HttpMethod.POST,
{
id: applicationId,
decision,
}
);
return applicationFromJson(response);
}
export function applicationFromJson(object: {
[key: string]: any;
}): Application {
return {
...object,
primaryContact: contactFromJsonResponse(object.primaryContact),
createdAt: DateTime.fromISO(new Date(object.createdAt).toISOString()),
updatedAt: DateTime.fromISO(new Date(object.updatedAt).toISOString()),
} as Application;
}