| 
									
										
										
										
											2021-11-22 20:10:48 -09:00
										 |  |  | import { BaseCRUDAPI } from "../_base"; | 
					
						
							| 
									
										
										
										
											2021-12-10 19:48:06 -09:00
										 |  |  | import { Recipe } from "~/types/api-types/recipe"; | 
					
						
							| 
									
										
										
										
											2021-11-22 20:10:48 -09:00
										 |  |  | 
 | 
					
						
							|  |  |  | const prefix = "/api"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export interface CreateTool { | 
					
						
							|  |  |  |   name: string; | 
					
						
							|  |  |  |   onHand: boolean; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export interface Tool extends CreateTool { | 
					
						
							|  |  |  |   id: number; | 
					
						
							| 
									
										
										
										
											2021-12-10 19:48:06 -09:00
										 |  |  |   slug: string; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export interface RecipeToolResponse extends Tool { | 
					
						
							|  |  |  |   recipes: Recipe[]; | 
					
						
							| 
									
										
										
										
											2021-11-22 20:10:48 -09:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const routes = { | 
					
						
							|  |  |  |   tools: `${prefix}/tools`, | 
					
						
							|  |  |  |   toolsId: (id: string) => `${prefix}/tools/${id}`, | 
					
						
							| 
									
										
										
										
											2021-12-10 19:48:06 -09:00
										 |  |  |   toolsSlug: (id: string) => `${prefix}/tools/slug/${id}`, | 
					
						
							| 
									
										
										
										
											2021-11-22 20:10:48 -09:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export class ToolsApi extends BaseCRUDAPI<Tool, CreateTool> { | 
					
						
							|  |  |  |   baseRoute: string = routes.tools; | 
					
						
							|  |  |  |   itemRoute = routes.toolsId; | 
					
						
							| 
									
										
										
										
											2021-12-10 19:48:06 -09:00
										 |  |  | 
 | 
					
						
							|  |  |  |   async byslug(slug: string) { | 
					
						
							|  |  |  |     return await this.requests.get<Tool>(routes.toolsSlug(slug)); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2021-11-22 20:10:48 -09:00
										 |  |  | } |