mirror of
				https://github.com/mealie-recipes/mealie.git
				synced 2025-10-30 17:53:31 -04:00 
			
		
		
		
	* feat: ✨ base-shoppinglist infra (WIP) * add type checker * implement controllers * apply router fixes * add checked section hide/animation * add label support * formatting * fix overflow images * add experimental banner * fix #912 word break issue * remove any type errors * bump dependencies * remove templates * fix build errors * bump node version * fix template literal
		
			
				
	
	
		
			61 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			61 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| import { BaseCRUDAPI } from "../_base";
 | |
| import { ApiRequestInstance } from "~/types/api";
 | |
| import { IngredientFood, IngredientUnit } from "~/types/api-types/recipe";
 | |
| 
 | |
| 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}`,
 | |
| };
 | |
| 
 | |
| export interface ShoppingListItemCreate {
 | |
|   id: string;
 | |
|   shoppingListId: string;
 | |
|   checked: boolean;
 | |
|   position: number;
 | |
|   note: string;
 | |
|   quantity: number;
 | |
| 
 | |
|   isFood: boolean;
 | |
|   unit: IngredientUnit | null;
 | |
|   food: IngredientFood | null;
 | |
| 
 | |
|   labelId: string | null;
 | |
|   label?: {
 | |
|     id: string;
 | |
|     name: string;
 | |
|   };
 | |
| }
 | |
| 
 | |
| export interface ShoppingListCreate {
 | |
|   name: string;
 | |
| }
 | |
| 
 | |
| export interface ShoppingListSummary extends ShoppingListCreate {
 | |
|   id: string;
 | |
|   groupId: string;
 | |
| }
 | |
| 
 | |
| export interface ShoppingList extends ShoppingListSummary {
 | |
|   listItems: ShoppingListItemCreate[];
 | |
| }
 | |
| 
 | |
| export class ShoppingListsApi extends BaseCRUDAPI<ShoppingList, ShoppingListCreate> {
 | |
|   baseRoute = routes.shoppingLists;
 | |
|   itemRoute = routes.shoppingListsId;
 | |
| 
 | |
|   async addRecipe(itemId: string, recipeId: number) {
 | |
|     return await this.requests.post(routes.shoppingListIdAddRecipe(itemId, recipeId), {});
 | |
|   }
 | |
| }
 | |
| 
 | |
| export class ShoppingApi {
 | |
|   public lists: ShoppingListsApi;
 | |
| 
 | |
|   constructor(requests: ApiRequestInstance) {
 | |
|     this.lists = new ShoppingListsApi(requests);
 | |
|   }
 | |
| }
 |