add Category
This commit is contained in:
parent
37e3957130
commit
5c73b83c87
1 changed files with 41 additions and 1 deletions
|
@ -1,4 +1,4 @@
|
|||
import { and, eq, remove, select, update } from "dblang";
|
||||
import { and, eq, insert, remove, select, update } from "dblang";
|
||||
import { checkSelfTag } from "../../server/outbagURL.js";
|
||||
import { Act, Client, STATE } from "../user.js";
|
||||
import { db, listCategories, listProducts } from "../../sys/db.js";
|
||||
|
@ -41,6 +41,46 @@ export const getCategories: Act = {
|
|||
}
|
||||
};
|
||||
|
||||
export const addCategories: Act = {
|
||||
state: STATE.client | STATE.remote,
|
||||
right: 0,
|
||||
data: {
|
||||
room: "string",
|
||||
server: "string",
|
||||
title: "string-256",
|
||||
color: "string-32",
|
||||
weight: "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", "right");
|
||||
let resp = await client.pass(data.server, "getCategories", data);
|
||||
aws(resp.state, resp.data);
|
||||
return;
|
||||
}
|
||||
let roomID = await client.isInRoom(data.room);
|
||||
if (roomID == -1) {
|
||||
aws("error", "existence");
|
||||
return;
|
||||
}
|
||||
let req = await insert(
|
||||
listCategories.roomID,
|
||||
listCategories.title,
|
||||
listCategories.weight,
|
||||
listCategories.color
|
||||
).add(
|
||||
roomID,
|
||||
data.title,
|
||||
data.weight,
|
||||
data.color
|
||||
).query(db);
|
||||
if (req.affectedRows > 0) aws("ok", {
|
||||
catID: req.insertId
|
||||
});
|
||||
else aws("error", "existence");
|
||||
}
|
||||
};
|
||||
|
||||
export const changeCategory: Act = {
|
||||
state: STATE.client | STATE.remote,
|
||||
right: 0,
|
||||
|
|
Loading…
Reference in a new issue