deleteItemByState
This commit is contained in:
parent
3a6280ceca
commit
f67846ab39
1 changed files with 45 additions and 4 deletions
|
@ -408,7 +408,16 @@ export const getItems: Act = {
|
|||
let unit = d[listItems.unit];
|
||||
let value = d[listItems.value];
|
||||
let listProdID = d[listItems.link];
|
||||
return { listItemID, state, title, description, listCatID, unit, value, listProdID };
|
||||
return {
|
||||
listItemID,
|
||||
state, // 0 = added; 1 = in cart/bought
|
||||
title,
|
||||
description,
|
||||
listCatID,
|
||||
unit,
|
||||
value,
|
||||
listProdID
|
||||
};
|
||||
});
|
||||
aws("ok", out.filter(d => d != null));
|
||||
}
|
||||
|
@ -440,6 +449,7 @@ export const addItem: Act = {
|
|||
aws("error", "existence");
|
||||
return;
|
||||
}
|
||||
if (data.state != 1 && data.state != 0) return void aws("error", "data");
|
||||
if (await isRoomDataFull(roomID)) return void aws("error", "limit");
|
||||
if (data.listCatID > -1 && !isCategoryInRoom(roomID, data.listCatID)) return void aws("error", "existence");
|
||||
if (data.listProdID > -1 && !isProductInRoom(roomID, data.listProdID)) return void aws("error", "existence");
|
||||
|
@ -476,7 +486,7 @@ export const changeItem: Act = {
|
|||
room: "string",
|
||||
server: "string",
|
||||
listItemID: "number",
|
||||
state: "number", // 0 = added; 1 = in cart; 2 = bourght
|
||||
state: "number", // 0 = added; 1 = in cart/bought
|
||||
title: "string-256",
|
||||
description: "string-4096",
|
||||
listCatID: "number", //-1 = no parent
|
||||
|
@ -496,6 +506,7 @@ export const changeItem: Act = {
|
|||
aws("error", "existence");
|
||||
return;
|
||||
}
|
||||
if (data.state != 1 && data.state != 0) return void aws("error", "data");
|
||||
if (!isItemInRoom(roomID, data.listItemID)) return void aws("error", "existence");
|
||||
if (data.listCatID > -1 && !isCategoryInRoom(roomID, data.listCatID)) return void aws("error", "existence");
|
||||
if (data.listProdID > -1 && !isProductInRoom(roomID, data.listProdID)) return void aws("error", "existence");
|
||||
|
@ -521,7 +532,7 @@ export const changeItemState: Act = {
|
|||
room: "string",
|
||||
server: "string",
|
||||
listItemID: "number",
|
||||
state: "number",
|
||||
state: "number", // 0 = added; 1 = in cart/bought
|
||||
},
|
||||
func: async (client: Client, data: any, aws: (code: string, data: any) => void) => {
|
||||
if (!checkSelfTag(data.server)) {
|
||||
|
@ -535,6 +546,7 @@ export const changeItemState: Act = {
|
|||
aws("error", "existence");
|
||||
return;
|
||||
}
|
||||
if (data.state != 1 && data.state != 0) return void aws("error", "data");
|
||||
if (!isItemInRoom(roomID, data.listItemID)) return void aws("error", "existence");
|
||||
let req = await update(listItems)
|
||||
.set(listItems.state, data.state)
|
||||
|
@ -574,3 +586,32 @@ export const deleteItem: Act = {
|
|||
else aws("error", "existence");
|
||||
}
|
||||
};
|
||||
export const deleteItemByState: Act = {
|
||||
state: STATE.client | STATE.remote,
|
||||
right: 0,
|
||||
data: {
|
||||
room: "string",
|
||||
server: "string",
|
||||
state: "number", // 0 = added; 1 = in cart/bought
|
||||
},
|
||||
func: async (client: Client, data: any, aws: (code: string, data: any) => void) => {
|
||||
if (!checkSelfTag(data.server)) {
|
||||
if (client.state != STATE.client) return void aws("error", "right");
|
||||
let resp = await client.pass(data.server, "deleteItem", data);
|
||||
aws(resp.state, resp.data);
|
||||
return;
|
||||
}
|
||||
let roomID = await client.isRoomAdmin(data.room, ROOM_RIGHTS.REMOVE_ARTICLES);
|
||||
if (roomID == -1) {
|
||||
aws("error", "existence");
|
||||
return;
|
||||
}
|
||||
let req = await remove(listItems)
|
||||
.where(and(
|
||||
eq(listItems.state, data.state),
|
||||
eq(listItems.roomID, roomID)
|
||||
)).query(db);
|
||||
if (req.affectedRows > 0) aws("ok", "");
|
||||
else aws("error", "existence");
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue