Allowed for null products, move ingredient spreading server-side #2

Merged
jacob merged 6 commits from nullproduct into master 2025-07-28 23:22:59 +00:00
2 changed files with 11 additions and 16 deletions
Showing only changes of commit 67cbb370ed - Show all commits

View file

@ -56,11 +56,11 @@ export default {
},
methods: {
async updateShoppingList(save = false) {
const requests = save ?
const new_ingredients = save ?
await data.saveMyShoppingList(this.ingredients) :
await data.getMyShoppingList();
this.ingredients = requests.map(r => r.ingredient);
this.ingredients = new_ingredients;
},
addIngredient() {
this.ingredients = [{ id: -1 }, ...this.ingredients];

View file

@ -3,9 +3,8 @@ const BASE_URL = window.location.href.replace(/^(https?:\/\/[^/]+).*/, "$1/api")
const datesToFix = {
Meal: { fields: [ "suggested_date", "purchase_date", "consumed_date" ] },
CurrentShoppingList: { dependants: l => ({ ShoppingListRequest: l.requests, ShoppingList: l.overlapping_previous_shops }) },
ShoppingList: { fields: [ "created_date", "purchased_date" ], dependants: l => ({ ShoppingListResult: l.results, ShoppingListRequest: l.requests }) },
ShoppingListResult: { fields: [ "found_date", "created_date" ], },
ShoppingListRequest: { fields: [ "created_date" ], dependants: r => ({ Meal: r.meal }) },
ShoppingList: { fields: [ "created_date" ], dependants: l => ({ ShoppingListItem: l.items }) },
ShoppingListItem: { fields: [ "created_date" ], dependants: r => ({ Meal: r.meal }) },
Recipe: { fields: [ "date_created", "date_hidden" ], },
};
@ -213,10 +212,8 @@ export default {
},
async getMyShoppingList() {
const response = await fetch(BASE_URL + "/shopping/current/me/ingredients", { credentials: "include" });
const requests = await response.json();
fixDates(requests, "ShoppingListRequest");
return requests;
return await response.json();
},
async saveMyShoppingList(list) {
const response = await fetch(BASE_URL + "/shopping/current/me/ingredients", {
@ -228,10 +225,7 @@ export default {
body: JSON.stringify(list),
});
const requests = await response.json();
fixDates(requests, "ShoppingListRequest");
return requests;
return await response.json();
},
async getShoppingList(id) {
const response = await fetch(BASE_URL + `/shopping/${encodeURIComponent(id)}`);
@ -273,7 +267,7 @@ export default {
});
const requests = await response.json();
fixDates(requests, "ShoppingListRequest");
fixDates(requests, "ShoppingListItem");
return requests;
},
@ -283,8 +277,9 @@ export default {
credentials: "include",
});
const requests = await response.json();
fixDates(requests, "ShoppingListRequest");
if (!response.ok) {
throw new Error("Failed to unrequest meal");
}
},
async getPersonsInHome() {
const response = await fetch(BASE_URL + "/persons");