diff --git a/src/api/acts/roomContent.ts b/src/api/acts/roomContent.ts index 1f31729..f9e14b9 100644 --- a/src/api/acts/roomContent.ts +++ b/src/api/acts/roomContent.ts @@ -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,