-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMeetingActions.ts
81 lines (72 loc) · 2.25 KB
/
MeetingActions.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
import { callInternalAPI } from "&server/utils/ActionUtils";
import { HttpMethod } from "&server/models/HttpMethod";
import urls from "&utils/urls";
import {
Meeting,
MeetingCore,
MeetingWithAvailability,
} from "&server/models/Meeting";
import { DateTime } from "luxon";
import { availabilityFromJsonResponse } from "&actions/AvailabilityActions";
const meetingRoute = urls.api.meeting;
export async function getMeetingById(objectId: string): Promise<Meeting> {
const response: Record<string, any> = await callInternalAPI(
meetingRoute + `?id=${objectId}`,
HttpMethod.GET
);
return meetingFromJsonResponse(response);
}
export async function getMeetingByApplicationId(
objectId: string
): Promise<MeetingWithAvailability> {
const response: Record<string, any> = await callInternalAPI(
meetingRoute + `?applicationId=${objectId}`,
HttpMethod.GET
);
return meetingWithAvailabilityFromJsonResponse(response);
}
export async function getMeetings(): Promise<Meeting[]> {
const response: Record<string, any>[] = await callInternalAPI(
meetingRoute,
HttpMethod.GET
);
return response.map(meetingFromJsonResponse);
}
export async function createMeeting(meeting: Meeting): Promise<Meeting> {
const response: Record<string, any>[] = await callInternalAPI(
meetingRoute,
HttpMethod.PUT,
{
meeting,
}
);
return meetingFromJsonResponse(response);
}
export async function cancelMeeting(id: string): Promise<void> {
await callInternalAPI(meetingRoute + `?id=${id}`, HttpMethod.DELETE);
}
export function meetingFromJsonResponse(object: {
[key: string]: any;
}): Meeting {
return {
...meetingCoreFromJsonResponse(object),
availability: object.availability as string,
};
}
export function meetingWithAvailabilityFromJsonResponse(object: {
[key: string]: any;
}): MeetingWithAvailability {
return {
...meetingCoreFromJsonResponse(object),
availability: availabilityFromJsonResponse(object.availability),
};
}
export function meetingCoreFromJsonResponse(object: {
[key: string]: any;
}): MeetingCore {
return {
...object,
createdAt: DateTime.fromISO(new Date(object.createdAt).toISOString()),
updatedAt: DateTime.fromISO(new Date(object.updatedAt).toISOString()),
} as MeetingCore;
}