From 80c6859a8b9b71cdb4bff2150d6ddc234994216a Mon Sep 17 00:00:00 2001 From: jusax23 Date: Fri, 24 Mar 2023 22:05:16 +0100 Subject: [PATCH] added produkt parent --- src/api/acts/roomContent.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/api/acts/roomContent.ts b/src/api/acts/roomContent.ts index e1a8ab6..63bd63d 100644 --- a/src/api/acts/roomContent.ts +++ b/src/api/acts/roomContent.ts @@ -245,7 +245,8 @@ export const addProduct: Act = { listCatID: "number", defUnit: "number", defValue: "string-256", - ean: "string-64" + ean: "string-64", + parent: "number" //-1 = no parent }, func: async (client: Client, data: any, aws: (code: string, data: any) => void) => { if (!checkSelfTag(data.server)) { @@ -260,6 +261,7 @@ export const addProduct: Act = { return; } if (!isCategoryInRoom(roomID, data.listCatID)) return void aws("error", "existence"); + if (data.parent > -1 && !isProductInRoom(roomID, data.parent)) return void aws("error", "existence"); let req = await insert( listProducts.roomID, listProducts.title, @@ -268,6 +270,7 @@ export const addProduct: Act = { listProducts.defUnit, listProducts.defValue, listProducts.ean, + listProducts.parent, ).add( roomID, data.title, @@ -275,7 +278,8 @@ export const addProduct: Act = { data.listCatID, data.defUnit, data.defValue, - data.ean + data.ean, + data.parent > -1 ? data.parent : null, ).query(db); if (req.affectedRows > 0) aws("ok", { listProdID: req.insertId @@ -296,7 +300,8 @@ export const changeProduct: Act = { listCatID: "number", defUnit: "number", defValue: "string-256", - ean: "string-64" + ean: "string-64", + parent: "number" //-1 = no parent }, func: async (client: Client, data: any, aws: (code: string, data: any) => void) => { if (!checkSelfTag(data.server)) { @@ -312,6 +317,8 @@ export const changeProduct: Act = { } if (!isCategoryInRoom(roomID, data.listCatID)) return void aws("error", "existence"); if (!isProductInRoom(roomID, data.listProdID)) return void aws("error", "existence"); + if (data.parent > -1 && !isProductInRoom(roomID, data.parent)) return void aws("error", "existence"); + let req = await update(listProducts) .set(listProducts.title, data.title) .set(listProducts.description, data.description) @@ -319,6 +326,7 @@ export const changeProduct: Act = { .set(listProducts.defUnit, data.defUnit) .set(listProducts.defValue, data.defValue) .set(listProducts.ean, data.ean) + .set(listProducts.parent, data.parent > -1 ? data.parent : null) .where(eq(listProducts.listProdID, data.listProdID)) .query(db); if (req.affectedRows > 0) aws("ok", "");