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