| 
									
										
										
										
											2022-10-22 11:51:07 -08:00
										 |  |  | import { BaseCRUDAPI } from "../base/base-clients"; | 
					
						
							| 
									
										
										
										
											2024-08-22 10:14:32 -05:00
										 |  |  | import { GroupBase, GroupInDB, GroupSummary, UserSummary } from "~/lib/api/types/user"; | 
					
						
							| 
									
										
										
										
											2022-10-22 11:51:07 -08:00
										 |  |  | import { | 
					
						
							|  |  |  |   GroupAdminUpdate, | 
					
						
							|  |  |  |   GroupStorage, | 
					
						
							|  |  |  |   ReadGroupPreferences, | 
					
						
							|  |  |  |   UpdateGroupPreferences, | 
					
						
							|  |  |  | } from "~/lib/api/types/group"; | 
					
						
							| 
									
										
										
										
											2021-08-06 16:28:12 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | const prefix = "/api"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const routes = { | 
					
						
							| 
									
										
										
										
											2021-09-09 08:51:29 -08:00
										 |  |  |   groups: `${prefix}/admin/groups`, | 
					
						
							| 
									
										
										
										
											2021-08-06 16:28:12 -08:00
										 |  |  |   groupsSelf: `${prefix}/groups/self`, | 
					
						
							| 
									
										
										
										
											2021-09-05 22:05:29 -08:00
										 |  |  |   preferences: `${prefix}/groups/preferences`, | 
					
						
							| 
									
										
										
										
											2022-03-27 15:12:18 -08:00
										 |  |  |   storage: `${prefix}/groups/storage`, | 
					
						
							| 
									
										
										
										
											2024-08-22 10:14:32 -05:00
										 |  |  |   membersHouseholdId: (householdId: string | number | null) => { | 
					
						
							|  |  |  |     return householdId ? | 
					
						
							|  |  |  |       `${prefix}/households/members?householdId=${householdId}` : | 
					
						
							|  |  |  |       `${prefix}/groups/members`; | 
					
						
							|  |  |  |   }, | 
					
						
							| 
									
										
										
										
											2021-09-09 08:51:29 -08:00
										 |  |  |   groupsId: (id: string | number) => `${prefix}/admin/groups/${id}`, | 
					
						
							| 
									
										
										
										
											2021-08-06 16:28:12 -08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-21 21:22:02 +02:00
										 |  |  | export class GroupAPI extends BaseCRUDAPI<GroupBase, GroupInDB, GroupAdminUpdate> { | 
					
						
							| 
									
										
										
										
											2021-08-06 16:28:12 -08:00
										 |  |  |   baseRoute = routes.groups; | 
					
						
							|  |  |  |   itemRoute = routes.groupsId; | 
					
						
							|  |  |  |   /** Returns the Group Data for the Current User | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   async getCurrentUserGroup() { | 
					
						
							| 
									
										
										
										
											2024-03-15 19:50:39 +00:00
										 |  |  |     return await this.requests.get<GroupSummary>(routes.groupsSelf); | 
					
						
							| 
									
										
										
										
											2021-09-01 21:39:40 -08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-05 22:05:29 -08:00
										 |  |  |   async getPreferences() { | 
					
						
							| 
									
										
										
										
											2022-05-21 21:22:02 +02:00
										 |  |  |     return await this.requests.get<ReadGroupPreferences>(routes.preferences); | 
					
						
							| 
									
										
										
										
											2021-09-05 22:05:29 -08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-21 21:22:02 +02:00
										 |  |  |   async setPreferences(payload: UpdateGroupPreferences) { | 
					
						
							| 
									
										
										
										
											2022-01-09 07:15:23 +01:00
										 |  |  |     // TODO: This should probably be a patch request, which isn't offered by the API currently
 | 
					
						
							| 
									
										
										
										
											2022-05-21 21:22:02 +02:00
										 |  |  |     return await this.requests.put<ReadGroupPreferences, UpdateGroupPreferences>(routes.preferences, payload); | 
					
						
							| 
									
										
										
										
											2021-09-05 22:05:29 -08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2021-09-09 08:51:29 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-22 10:14:32 -05:00
										 |  |  |   async fetchMembers(householdId: string | number | null = null) { | 
					
						
							|  |  |  |     return await this.requests.get<UserSummary[]>(routes.membersHouseholdId(householdId)); | 
					
						
							| 
									
										
										
										
											2021-10-04 20:16:37 -08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2022-03-27 15:12:18 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   async storage() { | 
					
						
							|  |  |  |     return await this.requests.get<GroupStorage>(routes.storage); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2021-08-06 16:28:12 -08:00
										 |  |  | } |