From 67cbb370edd5f48ff9f26632331fabf3b61f8fe5 Mon Sep 17 00:00:00 2001 From: jableader Date: Sun, 27 Jul 2025 15:25:37 +1000 Subject: [PATCH] Can edit own requests --- src/components/shopping/MyShoppingPage.vue | 4 ++-- src/data.js | 23 +++++++++------------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/components/shopping/MyShoppingPage.vue b/src/components/shopping/MyShoppingPage.vue index ab32f06..1c73209 100644 --- a/src/components/shopping/MyShoppingPage.vue +++ b/src/components/shopping/MyShoppingPage.vue @@ -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]; diff --git a/src/data.js b/src/data.js index 40e0fd3..a44f980 100644 --- a/src/data.js +++ b/src/data.js @@ -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");