an neues handleResponse return angepasst
This commit is contained in:
1 parent
719f633615
commit
882c4d2707
2 files changed
+6
-8
No files matched your search
@@ -1,6 +1,5 @@
|
||||
import { ShoppingCategory } from "../../models/ShoppingCategory.js";
|
||||
import { ShoppingItem } from "../../models/ShoppingItem.js";
|
||||
import { initErrors } from "../../shared/error.js";
|
||||
import * as api from "./api/listAPI.js"
|
||||
import * as ui from "./frontend/listUI.js"
|
||||
import { handleResponse } from "../../shared/helper.js";
|
||||
@@ -16,14 +15,14 @@ async function addItem(itemName, itemAmount, categoryID) {
|
||||
console.log(` adding item with id:${currentList.dataset.id}, name: ${itemName}, amount: ${itemAmount}, category: ${categoryID}`)
|
||||
|
||||
const json = await handleResponse(api.addItem(currentList.dataset.id, itemName, itemAmount, categoryID), `item couldnt be created!`);
|
||||
if (json) ui.addItem(json);
|
||||
if (json.ok) ui.addItem(json.json);
|
||||
}
|
||||
|
||||
async function addCategory(categoryName) {
|
||||
console.log(`adding category ${categoryName}`)
|
||||
|
||||
const json = await handleResponse(api.addCategory(currentList.dataset.id, categoryName), `category couldnt be added!`);
|
||||
if (json) ui.addCategory(json);
|
||||
if (json.ok) ui.addCategory(json.json);
|
||||
|
||||
}
|
||||
|
||||
@@ -31,25 +30,24 @@ async function deleteItem(li) {
|
||||
console.log(`deleting item ${li.dataset.id}`)
|
||||
|
||||
const json = await handleResponse(api.deleteItem(li.dataset.id), `error deleting item`);
|
||||
if (json) ui.deleteItem(li);
|
||||
if (json.ok) ui.deleteItem(li);
|
||||
}
|
||||
|
||||
async function deleteCategory(deleteAllItems, categoryID) {
|
||||
console.log(`deleting category with allItems: ${deleteAllItems} id: ${categoryID}`);
|
||||
const json = await handleResponse(api.deleteCategory(deleteAllItems, categoryID), `error deleting category`);
|
||||
|
||||
if (json) ui.deleteCategory(deleteAllItems, categoryID);
|
||||
if (json.ok) ui.deleteCategory(deleteAllItems, categoryID);
|
||||
}
|
||||
|
||||
async function deleteAllDoneItems() {
|
||||
console.log(`deleting all done items...`)
|
||||
const json = await handleResponse(api.deleteAllDoneItems(currentList.dataset.id), `error deleting all done items`);
|
||||
if (json) ui.deleteAllDoneItems();
|
||||
if (json.ok) ui.deleteAllDoneItems();
|
||||
}
|
||||
|
||||
function init() {
|
||||
|
||||
initErrors(document.querySelector(".nav"));
|
||||
|
||||
customElements.define("shopping-item", ShoppingItem);
|
||||
customElements.define("shopping-category", ShoppingCategory);
|
||||
|
||||
@@ -15,7 +15,7 @@ export async function editElement({ element, fields, apiCall, id, onSuccess, onF
|
||||
let result = await handleResponse(apiCall(id, formData), errmsg);
|
||||
|
||||
|
||||
if (result) {
|
||||
if (result.ok) {
|
||||
onSuccess(formData);
|
||||
abortEditing(formElement, element);
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user