-1 to null for pointers
This commit is contained in:
parent
9c9e930d10
commit
b00a14a9c2
2 changed files with 28 additions and 30 deletions
|
@ -277,8 +277,6 @@ export const getProducts: Act = {
|
|||
let defValue = d[listProducts.defValue];
|
||||
let ean = d[listProducts.ean];
|
||||
let parent = d[listProducts.parent];
|
||||
parent = parent == null ? -1 : parent;
|
||||
category = category == null ? -1 : category;
|
||||
return { listProdID, title, description, category, defUnit, defValue, ean, parent };
|
||||
});
|
||||
aws("ok", out.filter(d => d != null));
|
||||
|
@ -329,8 +327,6 @@ export const getProduct: Act = {
|
|||
let defValue = req[0][listProducts.defValue];
|
||||
let ean = req[0][listProducts.ean];
|
||||
let parent = req[0][listProducts.parent];
|
||||
parent = parent == null ? -1 : parent;
|
||||
category = category == null ? -1 : category;
|
||||
aws("ok", { listProdID, title, description, category, defUnit, defValue, ean, parent });
|
||||
} else {
|
||||
aws("error", act_error.PROD_NOT_EXISTS);
|
||||
|
@ -350,7 +346,7 @@ export const addProduct: Act = {
|
|||
defUnit: "number",
|
||||
defValue: "string-256",
|
||||
ean: "string-64",
|
||||
parent: "number" //-1 = no parent
|
||||
parent: "nullpointer" //null = no parent
|
||||
},
|
||||
func: async (client: Client, data: any, aws: (code: string, data: any) => void) => {
|
||||
if (!checkSelfTag(data.server)) {
|
||||
|
@ -365,8 +361,8 @@ export const addProduct: Act = {
|
|||
return;
|
||||
}
|
||||
if (await isRoomDataFull(roomID)) return void aws("error", act_error.ROOM_DATA_LIMIT);
|
||||
if (data.listCatID > -1 && !isCategoryInRoom(roomID, data.listCatID)) return void aws("error", act_error.CAT_NOT_EXISTS);
|
||||
if (data.parent > -1 && !isProductInRoom(roomID, data.parent)) return void aws("error", act_error.PROD_NOT_EXISTS);
|
||||
if (data.listCatID != null && !isCategoryInRoom(roomID, data.listCatID)) return void aws("error", act_error.CAT_NOT_EXISTS);
|
||||
if (data.parent != null && !isProductInRoom(roomID, data.parent)) return void aws("error", act_error.PROD_NOT_EXISTS);
|
||||
let req = await insert(
|
||||
listProducts.roomID,
|
||||
listProducts.title,
|
||||
|
@ -380,11 +376,11 @@ export const addProduct: Act = {
|
|||
roomID,
|
||||
data.title,
|
||||
data.description,
|
||||
data.listCatID > -1 ? data.listCatID : null,
|
||||
data.listCatID != null ? data.listCatID : null,
|
||||
data.defUnit,
|
||||
data.defValue,
|
||||
data.ean,
|
||||
data.parent > -1 ? data.parent : null,
|
||||
data.parent != null ? data.parent : null,
|
||||
).query(db);
|
||||
if (req.affectedRows > 0) aws("ok", {
|
||||
listProdID: Number(req.insertId)
|
||||
|
@ -406,7 +402,7 @@ export const changeProduct: Act = {
|
|||
defUnit: "number",
|
||||
defValue: "string-256",
|
||||
ean: "string-64",
|
||||
parent: "number" //-1 = no parent
|
||||
parent: "nullpointer" //null = no parent
|
||||
},
|
||||
func: async (client: Client, data: any, aws: (code: string, data: any) => void) => {
|
||||
if (!checkSelfTag(data.server)) {
|
||||
|
@ -421,17 +417,17 @@ export const changeProduct: Act = {
|
|||
return;
|
||||
}
|
||||
if (!isProductInRoom(roomID, data.listProdID)) return void aws("error", act_error.PROD_NOT_EXISTS);
|
||||
if (data.listCatID > -1 && !isCategoryInRoom(roomID, data.listCatID)) return void aws("error", act_error.CAT_NOT_EXISTS);
|
||||
if (data.parent > -1 && !isProductInRoom(roomID, data.parent)) return void aws("error", act_error.PROD_NOT_EXISTS);
|
||||
if (data.listCatID != null && !isCategoryInRoom(roomID, data.listCatID)) return void aws("error", act_error.CAT_NOT_EXISTS);
|
||||
if (data.parent != null && !isProductInRoom(roomID, data.parent)) return void aws("error", act_error.PROD_NOT_EXISTS);
|
||||
|
||||
let req = await update(listProducts)
|
||||
.set(listProducts.title, data.title)
|
||||
.set(listProducts.description, data.description)
|
||||
.set(listProducts.category, data.listCatID > -1 ? data.listCatID : null)
|
||||
.set(listProducts.category, data.listCatID != null ? data.listCatID : null)
|
||||
.set(listProducts.defUnit, data.defUnit)
|
||||
.set(listProducts.defValue, data.defValue)
|
||||
.set(listProducts.ean, data.ean)
|
||||
.set(listProducts.parent, data.parent > -1 ? data.parent : null)
|
||||
.set(listProducts.parent, data.parent != null ? data.parent : null)
|
||||
.where(and(
|
||||
eq(listProducts.listProdID, data.listProdID),
|
||||
eq(listProducts.roomID, roomID),
|
||||
|
@ -518,10 +514,10 @@ export const getItems: Act = {
|
|||
state, // 0 = added; 1 = in cart/bought
|
||||
title,
|
||||
description,
|
||||
listCatID: listCatID == null ? -1 : listCatID,
|
||||
listCatID,
|
||||
unit,
|
||||
value,
|
||||
listProdID: listProdID == null ? -1 : listProdID
|
||||
listProdID
|
||||
};
|
||||
});
|
||||
aws("ok", out.filter(d => d != null));
|
||||
|
@ -577,10 +573,10 @@ export const getItem: Act = {
|
|||
state, // 0 = added; 1 = in cart/bought
|
||||
title,
|
||||
description,
|
||||
listCatID: listCatID == null ? -1 : listCatID,
|
||||
listCatID,
|
||||
unit,
|
||||
value,
|
||||
listProdID: listProdID == null ? -1 : listProdID
|
||||
listProdID
|
||||
});
|
||||
} else {
|
||||
aws("error", act_error.ITEM_NOT_EXISTS);
|
||||
|
@ -597,10 +593,10 @@ export const addItem: Act = {
|
|||
state: "number",
|
||||
title: "string-256",
|
||||
description: "string-4096",
|
||||
listCatID: "number", //-1 = no parent
|
||||
listCatID: "nullpointer", //null = no parent
|
||||
unit: "number",
|
||||
value: "string-256",
|
||||
listProdID: "number" //-1 = no parent
|
||||
listProdID: "nullpointer" //null = no parent
|
||||
},
|
||||
func: async (client: Client, data: any, aws: (code: string, data: any) => void) => {
|
||||
if (!checkSelfTag(data.server)) {
|
||||
|
@ -616,8 +612,8 @@ export const addItem: Act = {
|
|||
}
|
||||
if (data.state != 1 && data.state != 0) return void aws("error", act_error.DATA);
|
||||
if (await isRoomDataFull(roomID)) return void aws("error", act_error.ROOM_DATA_LIMIT);
|
||||
if (data.listCatID > -1 && !isCategoryInRoom(roomID, data.listCatID)) return void aws("error", act_error.CAT_NOT_EXISTS);
|
||||
if (data.listProdID > -1 && !isProductInRoom(roomID, data.listProdID)) return void aws("error", act_error.PROD_NOT_EXISTS);
|
||||
if (data.listCatID != null && !isCategoryInRoom(roomID, data.listCatID)) return void aws("error", act_error.CAT_NOT_EXISTS);
|
||||
if (data.listProdID != null && !isProductInRoom(roomID, data.listProdID)) return void aws("error", act_error.PROD_NOT_EXISTS);
|
||||
let req = await insert(
|
||||
listItems.roomID,
|
||||
listItems.state,
|
||||
|
@ -632,10 +628,10 @@ export const addItem: Act = {
|
|||
data.state,
|
||||
data.title,
|
||||
data.description,
|
||||
data.listCatID > -1 ? data.listCatID : null,
|
||||
data.listCatID != null ? data.listCatID : null,
|
||||
data.unit,
|
||||
data.value,
|
||||
data.listProdID > -1 ? data.parent : null,
|
||||
data.listProdID != null ? data.parent : null,
|
||||
).query(db);
|
||||
if (req.affectedRows > 0) aws("ok", {
|
||||
listItemID: Number(req.insertId)
|
||||
|
@ -654,10 +650,10 @@ export const changeItem: Act = {
|
|||
state: "number", // 0 = added; 1 = in cart/bought
|
||||
title: "string-256",
|
||||
description: "string-4096",
|
||||
listCatID: "number", //-1 = no parent
|
||||
listCatID: "nullpointer", //null = no parent
|
||||
unit: "number",
|
||||
value: "string-256",
|
||||
listProdID: "number" //-1 = no parent
|
||||
listProdID: "nullpointer" //null = no parent
|
||||
},
|
||||
func: async (client: Client, data: any, aws: (code: string, data: any) => void) => {
|
||||
if (!checkSelfTag(data.server)) {
|
||||
|
@ -673,16 +669,16 @@ export const changeItem: Act = {
|
|||
}
|
||||
if (data.state != 1 && data.state != 0) return void aws("error", act_error.DATA);
|
||||
if (!isItemInRoom(roomID, data.listItemID)) return void aws("error", act_error.ITEM_NOT_EXISTS);
|
||||
if (data.listCatID > -1 && !isCategoryInRoom(roomID, data.listCatID)) return void aws("error", act_error.CAT_NOT_EXISTS);
|
||||
if (data.listProdID > -1 && !isProductInRoom(roomID, data.listProdID)) return void aws("error", act_error.PROD_NOT_EXISTS);
|
||||
if (data.listCatID != null && !isCategoryInRoom(roomID, data.listCatID)) return void aws("error", act_error.CAT_NOT_EXISTS);
|
||||
if (data.listProdID != null && !isProductInRoom(roomID, data.listProdID)) return void aws("error", act_error.PROD_NOT_EXISTS);
|
||||
let req = await update(listItems)
|
||||
.set(listItems.state, data.state)
|
||||
.set(listItems.title, data.title)
|
||||
.set(listItems.description, data.description)
|
||||
.set(listItems.category, data.listCatID > -1 ? data.listCatID : null)
|
||||
.set(listItems.category, data.listCatID != null ? data.listCatID : null)
|
||||
.set(listItems.unit, data.unit)
|
||||
.set(listItems.value, data.value)
|
||||
.set(listItems.link, data.listProdID > -1 ? data.listProdID : null)
|
||||
.set(listItems.link, data.listProdID != null ? data.listProdID : null)
|
||||
.where(and(
|
||||
eq(listItems.listItemID, data.listItemID),
|
||||
eq(listItems.roomID, data.roomID)
|
||||
|
|
|
@ -126,6 +126,8 @@ export function checktype(data: any, type: string) {
|
|||
const re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
||||
if (typeof data == type) {
|
||||
return true;
|
||||
} else if (type == "nullpointer") {
|
||||
return data == null || (typeof data == "number" && Number.isInteger(data) && data >= 0);
|
||||
} else if (type == "int" && typeof data == "number" && Number.isInteger(data)) {
|
||||
return true;
|
||||
} else if (type == "email" && typeof data == "string" && re.test(data)) {
|
||||
|
|
Loading…
Reference in a new issue