mirror of
				https://github.com/mealie-recipes/mealie.git
				synced 2025-11-03 19:18:22 -05:00 
			
		
		
		
	* added backend for shopping list label config * updated codegen * refactored shopping list ops to service removed unique contraint removed label settings from main route/schema added new route for label settings * codegen * made sure label settings output in position order * implemented submenu for label order drag and drop * removed redundant label and tweaked formatting * added view by label to user preferences * made items draggable within each label section * moved reorder labels to its own button * made dialog scrollable * fixed broken model * refactored labels to use a service moved shopping list label logic to service modified label seeder to use service * added tests * fix for first label missing the tag icon * fixed wrong mapped type * added statement to create existing relationships * fix restore test, maybe
		
			
				
	
	
		
			76 lines
		
	
	
		
			2.7 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			76 lines
		
	
	
		
			2.7 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
import { BaseCRUDAPI } from "../base/base-clients";
 | 
						|
import { RecipeIngredient } from "../types/recipe";
 | 
						|
import { ApiRequestInstance } from "~/lib/api/types/non-generated";
 | 
						|
import {
 | 
						|
  ShoppingListCreate,
 | 
						|
  ShoppingListItemCreate,
 | 
						|
  ShoppingListItemOut,
 | 
						|
  ShoppingListItemUpdateBulk,
 | 
						|
  ShoppingListMultiPurposeLabelUpdate,
 | 
						|
  ShoppingListOut,
 | 
						|
  ShoppingListUpdate,
 | 
						|
} from "~/lib/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: string) => `${prefix}/groups/shopping/lists/${id}/recipe/${recipeId}`,
 | 
						|
  shoppingListIdRemoveRecipe: (id: string, recipeId: string) => `${prefix}/groups/shopping/lists/${id}/recipe/${recipeId}/delete`,
 | 
						|
  shoppingListIdUpdateLabelSettings: (id: string) => `${prefix}/groups/shopping/lists/${id}/label-settings`,
 | 
						|
 | 
						|
  shoppingListItems: `${prefix}/groups/shopping/items`,
 | 
						|
  shoppingListItemsId: (id: string) => `${prefix}/groups/shopping/items/${id}`,
 | 
						|
};
 | 
						|
 | 
						|
export class ShoppingListsApi extends BaseCRUDAPI<ShoppingListCreate, ShoppingListOut, ShoppingListUpdate> {
 | 
						|
  baseRoute = routes.shoppingLists;
 | 
						|
  itemRoute = routes.shoppingListsId;
 | 
						|
 | 
						|
  async addRecipe(itemId: string, recipeId: string, recipeIncrementQuantity = 1, recipeIngredients: RecipeIngredient[] | null = null) {
 | 
						|
    return await this.requests.post(routes.shoppingListIdAddRecipe(itemId, recipeId), { recipeIncrementQuantity, recipeIngredients });
 | 
						|
  }
 | 
						|
 | 
						|
  async removeRecipe(itemId: string, recipeId: string, recipeDecrementQuantity = 1) {
 | 
						|
    return await this.requests.post(routes.shoppingListIdRemoveRecipe(itemId, recipeId), { recipeDecrementQuantity });
 | 
						|
  }
 | 
						|
 | 
						|
  async updateLabelSettings(itemId: string, listSettings: ShoppingListMultiPurposeLabelUpdate[]) {
 | 
						|
    return await this.requests.put(routes.shoppingListIdUpdateLabelSettings(itemId), listSettings);
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
export class ShoppingListItemsApi extends BaseCRUDAPI<
 | 
						|
  ShoppingListItemCreate,
 | 
						|
  ShoppingListItemOut,
 | 
						|
  ShoppingListItemUpdateBulk
 | 
						|
> {
 | 
						|
  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);
 | 
						|
  }
 | 
						|
}
 |