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: {
|
methods: {
|
||||||
async updateShoppingList(save = false) {
|
async updateShoppingList(save = false) {
|
||||||
const requests = save ?
|
const new_ingredients = save ?
|
||||||
await data.saveMyShoppingList(this.ingredients) :
|
await data.saveMyShoppingList(this.ingredients) :
|
||||||
await data.getMyShoppingList();
|
await data.getMyShoppingList();
|
||||||
|
|
||||||
this.ingredients = requests.map(r => r.ingredient);
|
this.ingredients = new_ingredients;
|
||||||
},
|
},
|
||||||
addIngredient() {
|
addIngredient() {
|
||||||
this.ingredients = [{ id: -1 }, ...this.ingredients];
|
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 = {
|
const datesToFix = {
|
||||||
Meal: { fields: [ "suggested_date", "purchase_date", "consumed_date" ] },
|
Meal: { fields: [ "suggested_date", "purchase_date", "consumed_date" ] },
|
||||||
CurrentShoppingList: { dependants: l => ({ ShoppingListRequest: l.requests, ShoppingList: l.overlapping_previous_shops }) },
|
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 }) },
|
ShoppingList: { fields: [ "created_date" ], dependants: l => ({ ShoppingListItem: l.items }) },
|
||||||
ShoppingListResult: { fields: [ "found_date", "created_date" ], },
|
ShoppingListItem: { fields: [ "created_date" ], dependants: r => ({ Meal: r.meal }) },
|
||||||
ShoppingListRequest: { fields: [ "created_date" ], dependants: r => ({ Meal: r.meal }) },
|
|
||||||
Recipe: { fields: [ "date_created", "date_hidden" ], },
|
Recipe: { fields: [ "date_created", "date_hidden" ], },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -213,10 +212,8 @@ export default {
|
||||||
},
|
},
|
||||||
async getMyShoppingList() {
|
async getMyShoppingList() {
|
||||||
const response = await fetch(BASE_URL + "/shopping/current/me/ingredients", { credentials: "include" });
|
const response = await fetch(BASE_URL + "/shopping/current/me/ingredients", { credentials: "include" });
|
||||||
const requests = await response.json();
|
|
||||||
fixDates(requests, "ShoppingListRequest");
|
return await response.json();
|
||||||
|
|
||||||
return requests;
|
|
||||||
},
|
},
|
||||||
async saveMyShoppingList(list) {
|
async saveMyShoppingList(list) {
|
||||||
const response = await fetch(BASE_URL + "/shopping/current/me/ingredients", {
|
const response = await fetch(BASE_URL + "/shopping/current/me/ingredients", {
|
||||||
|
|
@ -228,10 +225,7 @@ export default {
|
||||||
body: JSON.stringify(list),
|
body: JSON.stringify(list),
|
||||||
});
|
});
|
||||||
|
|
||||||
const requests = await response.json();
|
return await response.json();
|
||||||
fixDates(requests, "ShoppingListRequest");
|
|
||||||
|
|
||||||
return requests;
|
|
||||||
},
|
},
|
||||||
async getShoppingList(id) {
|
async getShoppingList(id) {
|
||||||
const response = await fetch(BASE_URL + `/shopping/${encodeURIComponent(id)}`);
|
const response = await fetch(BASE_URL + `/shopping/${encodeURIComponent(id)}`);
|
||||||
|
|
@ -273,7 +267,7 @@ export default {
|
||||||
});
|
});
|
||||||
|
|
||||||
const requests = await response.json();
|
const requests = await response.json();
|
||||||
fixDates(requests, "ShoppingListRequest");
|
fixDates(requests, "ShoppingListItem");
|
||||||
|
|
||||||
return requests;
|
return requests;
|
||||||
},
|
},
|
||||||
|
|
@ -283,8 +277,9 @@ export default {
|
||||||
credentials: "include",
|
credentials: "include",
|
||||||
});
|
});
|
||||||
|
|
||||||
const requests = await response.json();
|
if (!response.ok) {
|
||||||
fixDates(requests, "ShoppingListRequest");
|
throw new Error("Failed to unrequest meal");
|
||||||
|
}
|
||||||
},
|
},
|
||||||
async getPersonsInHome() {
|
async getPersonsInHome() {
|
||||||
const response = await fetch(BASE_URL + "/persons");
|
const response = await fetch(BASE_URL + "/persons");
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue