-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpeople.ts
More file actions
163 lines (140 loc) · 3.73 KB
/
Copy pathpeople.ts
File metadata and controls
163 lines (140 loc) · 3.73 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import dayjs from "dayjs";
import { request } from "./client";
import { GearTypeWithFee } from "./gear";
import { GearItemID, PeopleGroupID, PersonID } from "./idTypes";
import { ListWrapper, Note } from "./types";
/** The minimal representation of a person*/
export interface PersonBase {
id: PersonID;
firstName: string;
lastName: string;
}
/** Representation of a person including office access tag*/
export interface PersonWithOfficeAccess extends PersonBase {
hasOfficeAccess: boolean;
}
/** The representation of a person in the list endpoint*/
export interface PersonSummary extends PersonBase {
email: string;
rentals: Rental[];
}
export interface Expireable {
expires: string;
}
export interface PeopleGroup {
groupName: string;
id: PeopleGroupID;
}
/** The representation of a person in the retrieve endpoint*/
export interface Person extends PersonSummary {
affiliation: string;
membership?: Expireable & { membershipType: string };
waiver?: Expireable;
frequentFlyerCheck?: Expireable;
groups: PeopleGroup[];
notes: Note[];
mitocCredit: number;
alternateEmails: string[];
}
export interface Rental {
id: GearItemID;
checkedout: string;
returned?: string;
totalAmount: number;
weeksOut: number;
type: GearTypeWithFee;
}
export interface GearToReturn {
id: GearItemID;
daysCharged?: number;
}
export type CreatePersonArgs = {
firstName: string;
lastName: string;
email: string;
};
async function createPerson(args: CreatePersonArgs): Promise<PersonSummary> {
return request(`/people/`, "POST", args);
}
async function addFFChecks(id: PersonID, date: Date, checkNumber: string) {
return request(`/people/${id}/frequent_flyer_check/`, "POST", {
expires: dayjs(date).format("YYYY-MM-DD"),
...(checkNumber && { checkNumber }),
});
}
async function addWaiver(id: PersonID, date: Date) {
return request(`/people/${id}/waiver/`, "POST", {
expires: dayjs(date).format("YYYY-MM-DD"),
});
}
async function addMembership(id: PersonID, date: Date, membershipType: string) {
return request(`/people/${id}/membership/`, "POST", {
expires: dayjs(date).format("YYYY-MM-DD"),
membershipType,
});
}
async function addNote(id: PersonID, note: string) {
return request(`/people/${id}/note/`, "POST", {
note,
});
}
async function archiveNote(personId: PersonID, noteId: number) {
return request(`/people/${personId}/note/${noteId}/archive/`, "POST");
}
async function getPersonRentalHistory(
id: PersonID,
page?: number,
): Promise<ListWrapper<Rental>> {
return request(`/people/${id}/rentals/`, "GET", { ...(page && { page }) });
}
async function checkoutGear(personID: PersonID, gearIDs: string[]) {
return request(`/people/${personID}/rentals/`, "POST", { gearIds: gearIDs });
}
async function returnGear(
personID: PersonID,
gear: GearToReturn[],
purchases: number[] = [],
checkNumber: string = "",
useMitocCredit?: number,
) {
return request(`/people/${personID}/return/`, "POST", {
gear,
checkNumber,
purchases,
useMitocCredit,
});
}
async function editPerson(
id: PersonID,
firstName: string,
lastName: string,
email: string,
altEmails: string[],
) {
return request(`/people/${id}/`, "PATCH", {
firstName,
lastName,
email,
alternateEmails: altEmails,
});
}
async function updatePersonGroups(id: PersonID, groups: number[]) {
return request(`/people/${id}/groups/`, "PUT", { groups });
}
async function addMitocCredit(id: PersonID, amount: number) {
return request(`/people/${id}/credit/add/`, "PATCH", { amount });
}
export {
addFFChecks,
addMembership,
addMitocCredit,
addNote,
addWaiver,
archiveNote,
checkoutGear,
createPerson,
editPerson,
getPersonRentalHistory,
returnGear,
updatePersonGroups,
};