added produkt parent
This commit is contained in:
parent
b0dc1672fc
commit
80c6859a8b
1 changed files with 11 additions and 3 deletions
|
@ -245,7 +245,8 @@ export const addProduct: Act = {
|
||||||
listCatID: "number",
|
listCatID: "number",
|
||||||
defUnit: "number",
|
defUnit: "number",
|
||||||
defValue: "string-256",
|
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) => {
|
func: async (client: Client, data: any, aws: (code: string, data: any) => void) => {
|
||||||
if (!checkSelfTag(data.server)) {
|
if (!checkSelfTag(data.server)) {
|
||||||
|
@ -260,6 +261,7 @@ export const addProduct: Act = {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!isCategoryInRoom(roomID, data.listCatID)) return void aws("error", "existence");
|
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(
|
let req = await insert(
|
||||||
listProducts.roomID,
|
listProducts.roomID,
|
||||||
listProducts.title,
|
listProducts.title,
|
||||||
|
@ -268,6 +270,7 @@ export const addProduct: Act = {
|
||||||
listProducts.defUnit,
|
listProducts.defUnit,
|
||||||
listProducts.defValue,
|
listProducts.defValue,
|
||||||
listProducts.ean,
|
listProducts.ean,
|
||||||
|
listProducts.parent,
|
||||||
).add(
|
).add(
|
||||||
roomID,
|
roomID,
|
||||||
data.title,
|
data.title,
|
||||||
|
@ -275,7 +278,8 @@ export const addProduct: Act = {
|
||||||
data.listCatID,
|
data.listCatID,
|
||||||
data.defUnit,
|
data.defUnit,
|
||||||
data.defValue,
|
data.defValue,
|
||||||
data.ean
|
data.ean,
|
||||||
|
data.parent > -1 ? data.parent : null,
|
||||||
).query(db);
|
).query(db);
|
||||||
if (req.affectedRows > 0) aws("ok", {
|
if (req.affectedRows > 0) aws("ok", {
|
||||||
listProdID: req.insertId
|
listProdID: req.insertId
|
||||||
|
@ -296,7 +300,8 @@ export const changeProduct: Act = {
|
||||||
listCatID: "number",
|
listCatID: "number",
|
||||||
defUnit: "number",
|
defUnit: "number",
|
||||||
defValue: "string-256",
|
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) => {
|
func: async (client: Client, data: any, aws: (code: string, data: any) => void) => {
|
||||||
if (!checkSelfTag(data.server)) {
|
if (!checkSelfTag(data.server)) {
|
||||||
|
@ -312,6 +317,8 @@ export const changeProduct: Act = {
|
||||||
}
|
}
|
||||||
if (!isCategoryInRoom(roomID, data.listCatID)) return void aws("error", "existence");
|
if (!isCategoryInRoom(roomID, data.listCatID)) return void aws("error", "existence");
|
||||||
if (!isProductInRoom(roomID, data.listProdID)) 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)
|
let req = await update(listProducts)
|
||||||
.set(listProducts.title, data.title)
|
.set(listProducts.title, data.title)
|
||||||
.set(listProducts.description, data.description)
|
.set(listProducts.description, data.description)
|
||||||
|
@ -319,6 +326,7 @@ export const changeProduct: Act = {
|
||||||
.set(listProducts.defUnit, data.defUnit)
|
.set(listProducts.defUnit, data.defUnit)
|
||||||
.set(listProducts.defValue, data.defValue)
|
.set(listProducts.defValue, data.defValue)
|
||||||
.set(listProducts.ean, data.ean)
|
.set(listProducts.ean, data.ean)
|
||||||
|
.set(listProducts.parent, data.parent > -1 ? data.parent : null)
|
||||||
.where(eq(listProducts.listProdID, data.listProdID))
|
.where(eq(listProducts.listProdID, data.listProdID))
|
||||||
.query(db);
|
.query(db);
|
||||||
if (req.affectedRows > 0) aws("ok", "");
|
if (req.affectedRows > 0) aws("ok", "");
|
||||||
|
|
Loading…
Reference in a new issue