Can edit own requests
This commit is contained in:
parent
728532a7c8
commit
67cbb370ed
2 changed files with 11 additions and 16 deletions
|
|
@ -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];
|
||||
|
|
|
|||
23
src/data.js
23
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");
|
||||
|
|
|
|||
Loading…
Reference in a new issue