| 
									
										
										
										
											2021-11-25 14:17:02 -09:00
										 |  |  | import { BaseCRUDAPI } from "../_base"; | 
					
						
							|  |  |  | import { UserRead } from "./admin-users"; | 
					
						
							|  |  |  | const prefix = "/api"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export interface Token { | 
					
						
							|  |  |  |   name: string; | 
					
						
							|  |  |  |   id: number; | 
					
						
							|  |  |  |   createdAt: Date; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export interface Preferences { | 
					
						
							|  |  |  |   privateGroup: boolean; | 
					
						
							|  |  |  |   firstDayOfWeek: number; | 
					
						
							|  |  |  |   recipePublic: boolean; | 
					
						
							|  |  |  |   recipeShowNutrition: boolean; | 
					
						
							|  |  |  |   recipeShowAssets: boolean; | 
					
						
							|  |  |  |   recipeLandscapeView: boolean; | 
					
						
							|  |  |  |   recipeDisableComments: boolean; | 
					
						
							|  |  |  |   recipeDisableAmount: boolean; | 
					
						
							|  |  |  |   groupId: number; | 
					
						
							|  |  |  |   id: number; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export interface GroupCreate { | 
					
						
							|  |  |  |   name: string; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export interface GroupRead extends GroupCreate { | 
					
						
							|  |  |  |   id: number; | 
					
						
							|  |  |  |   categories: any[]; | 
					
						
							|  |  |  |   webhooks: any[]; | 
					
						
							|  |  |  |   users: UserRead[]; | 
					
						
							|  |  |  |   preferences: Preferences; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export interface AdminGroupUpdate { | 
					
						
							|  |  |  |   name: string; | 
					
						
							|  |  |  |   id: number; | 
					
						
							|  |  |  |   preferences: Preferences; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const routes = { | 
					
						
							|  |  |  |   adminUsers: `${prefix}/admin/groups`, | 
					
						
							|  |  |  |   adminUsersId: (id: number) => `${prefix}/admin/groups/${id}`, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export class AdminGroupsApi extends BaseCRUDAPI<GroupRead, GroupCreate> { | 
					
						
							|  |  |  |   baseRoute: string = routes.adminUsers; | 
					
						
							|  |  |  |   itemRoute = routes.adminUsersId; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   async updateOne(id: number, payload: AdminGroupUpdate) { | 
					
						
							| 
									
										
										
										
											2022-01-09 07:15:23 +01:00
										 |  |  |     // TODO: This should probably be a patch request, which isn't offered by the API currently
 | 
					
						
							|  |  |  |     return await this.requests.put<GroupRead, AdminGroupUpdate>(this.itemRoute(id), payload); | 
					
						
							| 
									
										
										
										
											2021-11-25 14:17:02 -09:00
										 |  |  |   } | 
					
						
							|  |  |  | } |