92cf97e401
* generate types * use generated types * ui updates * init button link for common styles * add links * setup label views * add delete confirmation * reset when not saved * link label to foods and auto set when adding to shopping list * generate types * use inheritence to manage exception handling * fix schema generation and add test for open_api generation * add header to api docs * move list consilidation to service * split list and list items controller * shopping list/list item tests - PARTIAL * enable recipe add/remove in shopping lists * generate types * linting * init global utility components * update types and add list item api * fix import cycle and database error * add container and border classes * new recipe list component * fix tests * breakout item editor * refactor item editor * update bulk actions * update input / color contrast * type generation * refactor controller dependencies * include food/unit editor * remove console.logs * fix and update type generation * fix incorrect type for column * fix postgres error * fix delete by variable * auto remove refs * fix typo
61 lines
1.9 KiB
TypeScript
61 lines
1.9 KiB
TypeScript
import { BaseCRUDAPI } from "../_base";
|
|
import { ApiRequestInstance } from "~/types/api";
|
|
import {
|
|
ShoppingListCreate,
|
|
ShoppingListItemCreate,
|
|
ShoppingListItemOut,
|
|
ShoppingListOut,
|
|
} from "~/types/api-types/group";
|
|
|
|
const prefix = "/api";
|
|
|
|
const routes = {
|
|
shoppingLists: `${prefix}/groups/shopping/lists`,
|
|
shoppingListsId: (id: string) => `${prefix}/groups/shopping/lists/${id}`,
|
|
shoppingListIdAddRecipe: (id: string, recipeId: number) => `${prefix}/groups/shopping/lists/${id}/recipe/${recipeId}`,
|
|
|
|
shoppingListItems: `${prefix}/groups/shopping/items`,
|
|
shoppingListItemsId: (id: string) => `${prefix}/groups/shopping/items/${id}`,
|
|
};
|
|
|
|
export class ShoppingListsApi extends BaseCRUDAPI<ShoppingListOut, ShoppingListCreate> {
|
|
baseRoute = routes.shoppingLists;
|
|
itemRoute = routes.shoppingListsId;
|
|
|
|
async addRecipe(itemId: string, recipeId: number) {
|
|
return await this.requests.post(routes.shoppingListIdAddRecipe(itemId, recipeId), {});
|
|
}
|
|
|
|
async removeRecipe(itemId: string, recipeId: number) {
|
|
return await this.requests.delete(routes.shoppingListIdAddRecipe(itemId, recipeId));
|
|
}
|
|
}
|
|
|
|
export class ShoppingListItemsApi extends BaseCRUDAPI<ShoppingListItemOut, ShoppingListItemCreate> {
|
|
baseRoute = routes.shoppingListItems;
|
|
itemRoute = routes.shoppingListItemsId;
|
|
|
|
async updateMany(items: ShoppingListItemOut[]) {
|
|
return await this.requests.put(routes.shoppingListItems, items);
|
|
}
|
|
|
|
async deleteMany(items: ShoppingListItemOut[]) {
|
|
let query = "?";
|
|
|
|
items.forEach((item) => {
|
|
query += `ids=${item.id}&`;
|
|
});
|
|
|
|
return await this.requests.delete(routes.shoppingListItems + query);
|
|
}
|
|
}
|
|
|
|
export class ShoppingApi {
|
|
public lists: ShoppingListsApi;
|
|
public items: ShoppingListItemsApi;
|
|
|
|
constructor(requests: ApiRequestInstance) {
|
|
this.lists = new ShoppingListsApi(requests);
|
|
this.items = new ShoppingListItemsApi(requests);
|
|
}
|
|
}
|