get single RoomContent

This commit is contained in:
jusax23 2023-04-01 19:54:44 +02:00
parent eacae8835e
commit b0867761d9
Signed by: jusax23
GPG key ID: 499E2AA870C1CD41

View file

@ -46,6 +46,50 @@ export const getCategories: Act = {
} }
}; };
export const getCategory: Act = {
state: STATE.client | STATE.remote,
right: 0,
data: {
room: "string",
server: "string",
listCatID: "number",
},
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", act_error.RECURSION);
let resp = await client.pass(data.server, "getCategory", data);
aws(resp.state, resp.data);
return;
}
let roomID = await client.isInRoom(data.room);
if (roomID == -1) {
aws("error", act_error.NOT_IN_ROOM);
return;
}
let req = await select([
listCategories.listCatID,
listCategories.title,
listCategories.weight,
listCategories.color
], listCategories)
.where(and(
eq(listCategories.roomID, roomID),
eq(listCategories.listCatID, data.listCatID)
))
.query(db);
if (req.length > 0) {
aws("ok", {
id: req[0][listCategories.listCatID],
title: req[0][listCategories.title],
weight: req[0][listCategories.weight],
color: req[0][listCategories.color]
});
} else {
aws("error", act_error.CAT_NOT_EXISTS);
}
}
};
export const addCategory: Act = { export const addCategory: Act = {
state: STATE.client | STATE.remote, state: STATE.client | STATE.remote,
right: 0, right: 0,
@ -241,6 +285,59 @@ export const getProducts: Act = {
} }
}; };
export const getProduct: Act = {
state: STATE.client | STATE.remote,
right: 0,
data: {
room: "string",
server: "string",
listProdID: "number",
},
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", act_error.RECURSION);
let resp = await client.pass(data.server, "getProducts", data);
aws(resp.state, resp.data);
return;
}
let roomID = await client.isInRoom(data.room);
if (roomID == -1) {
aws("error", act_error.NOT_IN_ROOM);
return;
}
let req = await select([
listProducts.listProdID,
listProducts.title,
listProducts.description,
listProducts.category,
listProducts.defUnit,
listProducts.defValue,
listProducts.ean,
listProducts.parent
], listProducts)
.where(and(
eq(listProducts.listProdID, data.listProdID),
eq(listProducts.roomID, roomID),
))
.query(db);
if (req.length > 0) {
let listProdID = req[0][listProducts.listProdID];
let title = req[0][listProducts.title];
let description = req[0][listProducts.description];
let category = req[0][listProducts.category];
let defUnit = req[0][listProducts.defUnit];
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);
}
}
};
export const addProduct: Act = { export const addProduct: Act = {
state: STATE.client | STATE.remote, state: STATE.client | STATE.remote,
right: 0, right: 0,
@ -431,6 +528,66 @@ export const getItems: Act = {
} }
}; };
export const getItem: Act = {
state: STATE.client | STATE.remote,
right: 0,
data: {
room: "string",
server: "string",
listItemID: "number",
},
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", act_error.RECURSION);
let resp = await client.pass(data.server, "getItems", data);
aws(resp.state, resp.data);
return;
}
let roomID = await client.isInRoom(data.room);
if (roomID == -1) {
aws("error", act_error.NOT_IN_ROOM);
return;
}
let req = await select([
listItems.listItemID,
listItems.state,
listItems.title,
listItems.description,
listItems.category,
listItems.unit,
listItems.value,
listItems.link,
], listProducts)
.where(and(
eq(listItems.listItemID, data.listItemID),
eq(listItems.roomID, data.roomID)
))
.query(db);
if (req.length > 0) {
let listItemID = Number(req[0][listItems.listItemID]);
let state = req[0][listItems.state];
let title = req[0][listItems.title];
let description = req[0][listItems.description];
let listCatID = req[0][listItems.category];
let unit = req[0][listItems.unit];
let value = req[0][listItems.value];
let listProdID = req[0][listItems.link];
aws("ok", {
listItemID,
state, // 0 = added; 1 = in cart/bought
title,
description,
listCatID: listCatID == null ? -1 : listCatID,
unit,
value,
listProdID: listProdID == null ? -1 : listProdID
});
} else {
aws("error", act_error.ITEM_NOT_EXISTS);
}
}
};
export const addItem: Act = { export const addItem: Act = {
state: STATE.client | STATE.remote, state: STATE.client | STATE.remote,
right: 0, right: 0,
@ -526,7 +683,10 @@ export const changeItem: Act = {
.set(listItems.unit, data.unit) .set(listItems.unit, data.unit)
.set(listItems.value, data.value) .set(listItems.value, data.value)
.set(listItems.link, data.listProdID > -1 ? data.listProdID : null) .set(listItems.link, data.listProdID > -1 ? data.listProdID : null)
.where(eq(listItems.listItemID, data.listItemID)) .where(and(
eq(listItems.listItemID, data.listItemID),
eq(listItems.roomID, data.roomID)
))
.query(db); .query(db);
if (req.affectedRows > 0) aws("ok", ""); if (req.affectedRows > 0) aws("ok", "");
else aws("error", act_error.ITEM_NOT_EXISTS); else aws("error", act_error.ITEM_NOT_EXISTS);