-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgear.ts
More file actions
165 lines (148 loc) · 3.48 KB
/
gear.ts
File metadata and controls
165 lines (148 loc) · 3.48 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
164
165
import { request } from "./client";
import { GearItemID, GearTypeID, LocationID, PurchasableID } from "./idTypes";
import { PersonBase, PersonSummary } from "./people";
import { ListWrapper, Note } from "./types";
export interface GearSummary {
id: GearItemID;
available: boolean;
broken: string;
// TODO: This is weird, we shouldn't have the rentals in there
checkedOutTo: PersonSummary | null;
dailyFee: number;
depositAmount: number;
description?: string;
missing: string;
restricted: boolean;
retired: string;
size?: string;
specification?: string;
type: GearTypeWithFee;
picture?: string;
location: {
id: LocationID;
shorthand: string;
};
}
export interface GearItem extends GearSummary {
notes: Note[];
}
export interface GearRental {
person: PersonBase;
checkedout: string;
returned: string;
weeksOut: number;
}
export interface PurchasableItem {
id: PurchasableID;
price: number;
name: string;
}
/** The minimal representation of a gear type*/
export interface GearTypeBase {
id: GearTypeID;
typeName: string;
}
export interface GearTypeWithShorthand extends GearTypeBase {
shorthand: string;
}
export interface GearTypeWithFee extends GearTypeBase {
rentalAmount: number;
}
/** The representation of a gear type in the list endpoint*/
export interface GearType extends GearTypeWithShorthand {
defaultDeposit: number;
shouldInventory: boolean;
restricted: boolean;
}
export interface GearLocation {
id: LocationID;
shorthand: string;
}
async function getGearRentalHistory(
id: GearItemID,
page?: number,
): Promise<ListWrapper<GearRental>> {
return request(`/gear/${id}/rentals/`, "GET", { ...(page && { page }) });
}
async function addNote(id: GearItemID, note: string) {
return request(`/gear/${id}/note/`, "POST", {
note,
});
}
async function markRetired(id: GearItemID, note?: string) {
return request(`/gear/${id}/retired/`, "POST", {
note,
});
}
async function markBroken(id: GearItemID, note: string) {
return request(`/gear/${id}/broken/`, "POST", {
note,
});
}
async function markMissing(id: GearItemID, note?: string) {
return request(`/gear/${id}/missing/`, "POST", {
note,
});
}
async function markUnretired(id: GearItemID, note?: string) {
return request(`/gear/${id}/retired/`, "DELETE", {
note,
});
}
async function markFixed(id: GearItemID, note?: string) {
return request(`/gear/${id}/broken/`, "DELETE", {
note,
});
}
async function markFound(id: GearItemID, note?: string) {
return request(`/gear/${id}/missing/`, "DELETE", {
note,
});
}
export type CreateGearArgs = {
type: string;
id?: string;
quantity: number;
size?: string;
specification?: string;
depositAmount?: number;
description?: string;
location?: string;
};
async function createGear(
args: CreateGearArgs,
): Promise<{ items: GearSummary[] }> {
return request(`/gear/`, "POST", args);
}
async function editGearItem(
id: GearItemID,
item: {
specification?: string;
description?: string;
size?: string;
depositAmount?: number;
location?: number;
picture?: string | null;
},
) {
return request(`/gear/${id}/`, "PATCH", item);
}
async function editGearType(
id: number,
gearType: Partial<Omit<GearType, "id" | "shorthand">>,
) {
return request(`/gear-types/${id}/`, "PATCH", gearType);
}
export {
addNote,
createGear,
editGearItem,
editGearType,
getGearRentalHistory,
markBroken,
markFixed,
markFound,
markMissing,
markRetired,
markUnretired,
};