From dcfa6d5df599865b2216279d41a8755c2365b675 Mon Sep 17 00:00:00 2001 From: jusax23 Date: Wed, 29 Mar 2023 21:23:31 +0200 Subject: [PATCH] automatic cat order --- package-lock.json | 8 ++++---- package.json | 2 +- src/api/acts/roomContent.ts | 18 +++++++++--------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/package-lock.json b/package-lock.json index 35e8772..f02a00e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,7 @@ "auth-header": "^1.0.0", "commander": "^10.0.0", "cors": "^2.8.5", - "dblang": "https://jusax.de/git/attachments/84353ff6-f81e-450b-93e1-d0a4d6d4556f", + "dblang": "https://jusax.de/git/attachments/f2de0e38-4004-4bd4-9d97-d58cd7a3b4e3", "express": "^4.18.2", "juml": "https://jusax.de/git/attachments/208913c5-2851-4b86-a53d-ca99fed168cc", "nman": "https://jusax.de/git/attachments/5333948b-fe6b-45d2-9230-ca388f6a89bc", @@ -1107,9 +1107,9 @@ } }, "node_modules/dblang": { - "version": "0.9.5", - "resolved": "https://jusax.de/git/attachments/84353ff6-f81e-450b-93e1-d0a4d6d4556f", - "integrity": "sha512-g7hBlnib2Tg7DoeGaygvnzBCPn1m47yrS9rMHkThqRfQp43wT/gUWqmnvxunNMVo0ka7PEwdwW4FpKz7VnpGqA==", + "version": "0.9.6", + "resolved": "https://jusax.de/git/attachments/f2de0e38-4004-4bd4-9d97-d58cd7a3b4e3", + "integrity": "sha512-cwEWiH2YHauJJiZCXJYqiQwjYHJG3Kza794EzZmWzgFNdtAAps6S623nOpNaGU5mPY2CUjleuFOWLpPzdpXTSg==", "license": "UNLICENSED", "dependencies": { "gitea-release": "git+https://jusax.de/git/jusax23/gitea-release.git", diff --git a/package.json b/package.json index 59c2d2c..1a8cdad 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,7 @@ "auth-header": "^1.0.0", "commander": "^10.0.0", "cors": "^2.8.5", - "dblang": "https://jusax.de/git/attachments/84353ff6-f81e-450b-93e1-d0a4d6d4556f", + "dblang": "https://jusax.de/git/attachments/f2de0e38-4004-4bd4-9d97-d58cd7a3b4e3", "express": "^4.18.2", "juml": "https://jusax.de/git/attachments/208913c5-2851-4b86-a53d-ca99fed168cc", "nman": "https://jusax.de/git/attachments/5333948b-fe6b-45d2-9230-ca388f6a89bc", diff --git a/src/api/acts/roomContent.ts b/src/api/acts/roomContent.ts index 87cc681..a83e9de 100644 --- a/src/api/acts/roomContent.ts +++ b/src/api/acts/roomContent.ts @@ -1,4 +1,4 @@ -import { and, coalesce, eq, insert, max, plus, remove, select, update } from "dblang"; +import { and, coalesce, eq, insert, max, order, plus, remove, select, update } from "dblang"; import { checkSelfTag } from "../../server/outbagURL.js"; import { Act, Client, STATE } from "../user.js"; import { db, listCategories, listItems, listProducts } from "../../sys/db.js"; @@ -31,6 +31,7 @@ export const getCategories: Act = { listCategories.color ], listCategories) .where(eq(listCategories.roomID, roomID)) + .orderBY(listCategories.weight, order.ASC) .query(db); let out = req.map(d => { let id = d[listCategories.listCatID]; @@ -38,8 +39,9 @@ export const getCategories: Act = { let weight = d[listCategories.weight]; let color = d[listCategories.color]; return { id, title, weight, color }; - }); - aws("ok", out.filter(d => d != null)); + }).filter(d => d != null); + out.sort((a,b) => a.weight - b.weight); + aws("ok", out); } }; @@ -122,19 +124,18 @@ export const changeCategory: Act = { } }; -export const changeCategoryWeights: Act = { +export const changeCategoriesOrder: Act = { state: STATE.client | STATE.remote, right: 0, data: { room: "string", server: "string", - listCatIDs: "array-number", - weights: "array-number", + listCatIDs: "array-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, "changeCategoryWeights", data); + let resp = await client.pass(data.server, "changeCategoriesOrder", data); aws(resp.state, resp.data); return; } @@ -143,12 +144,11 @@ export const changeCategoryWeights: Act = { aws("error", "existence"); return; } - if (data.weights.length != data.listCatIDs.length) return void aws("error", "data"); let affacted = 0; for (let i = 0; i < data.listCatIDs.length; i++) { const listCatID = data.listCatIDs[i]; let req = await update(listCategories) - .set(listCategories.weight, data.title) + .set(listCategories.weight, i) .where(and( eq(listCategories.roomID, roomID), eq(listCategories.listCatID, listCatID)