automatic cat order

This commit is contained in:
jusax23 2023-03-29 21:23:31 +02:00
parent 27bdd2e15b
commit dcfa6d5df5
Signed by: jusax23
GPG key ID: 499E2AA870C1CD41
3 changed files with 14 additions and 14 deletions

8
package-lock.json generated
View file

@ -12,7 +12,7 @@
"auth-header": "^1.0.0", "auth-header": "^1.0.0",
"commander": "^10.0.0", "commander": "^10.0.0",
"cors": "^2.8.5", "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", "express": "^4.18.2",
"juml": "https://jusax.de/git/attachments/208913c5-2851-4b86-a53d-ca99fed168cc", "juml": "https://jusax.de/git/attachments/208913c5-2851-4b86-a53d-ca99fed168cc",
"nman": "https://jusax.de/git/attachments/5333948b-fe6b-45d2-9230-ca388f6a89bc", "nman": "https://jusax.de/git/attachments/5333948b-fe6b-45d2-9230-ca388f6a89bc",
@ -1107,9 +1107,9 @@
} }
}, },
"node_modules/dblang": { "node_modules/dblang": {
"version": "0.9.5", "version": "0.9.6",
"resolved": "https://jusax.de/git/attachments/84353ff6-f81e-450b-93e1-d0a4d6d4556f", "resolved": "https://jusax.de/git/attachments/f2de0e38-4004-4bd4-9d97-d58cd7a3b4e3",
"integrity": "sha512-g7hBlnib2Tg7DoeGaygvnzBCPn1m47yrS9rMHkThqRfQp43wT/gUWqmnvxunNMVo0ka7PEwdwW4FpKz7VnpGqA==", "integrity": "sha512-cwEWiH2YHauJJiZCXJYqiQwjYHJG3Kza794EzZmWzgFNdtAAps6S623nOpNaGU5mPY2CUjleuFOWLpPzdpXTSg==",
"license": "UNLICENSED", "license": "UNLICENSED",
"dependencies": { "dependencies": {
"gitea-release": "git+https://jusax.de/git/jusax23/gitea-release.git", "gitea-release": "git+https://jusax.de/git/jusax23/gitea-release.git",

View file

@ -57,7 +57,7 @@
"auth-header": "^1.0.0", "auth-header": "^1.0.0",
"commander": "^10.0.0", "commander": "^10.0.0",
"cors": "^2.8.5", "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", "express": "^4.18.2",
"juml": "https://jusax.de/git/attachments/208913c5-2851-4b86-a53d-ca99fed168cc", "juml": "https://jusax.de/git/attachments/208913c5-2851-4b86-a53d-ca99fed168cc",
"nman": "https://jusax.de/git/attachments/5333948b-fe6b-45d2-9230-ca388f6a89bc", "nman": "https://jusax.de/git/attachments/5333948b-fe6b-45d2-9230-ca388f6a89bc",

View file

@ -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 { checkSelfTag } from "../../server/outbagURL.js";
import { Act, Client, STATE } from "../user.js"; import { Act, Client, STATE } from "../user.js";
import { db, listCategories, listItems, listProducts } from "../../sys/db.js"; import { db, listCategories, listItems, listProducts } from "../../sys/db.js";
@ -31,6 +31,7 @@ export const getCategories: Act = {
listCategories.color listCategories.color
], listCategories) ], listCategories)
.where(eq(listCategories.roomID, roomID)) .where(eq(listCategories.roomID, roomID))
.orderBY(listCategories.weight, order.ASC)
.query(db); .query(db);
let out = req.map(d => { let out = req.map(d => {
let id = d[listCategories.listCatID]; let id = d[listCategories.listCatID];
@ -38,8 +39,9 @@ export const getCategories: Act = {
let weight = d[listCategories.weight]; let weight = d[listCategories.weight];
let color = d[listCategories.color]; let color = d[listCategories.color];
return { id, title, weight, color }; return { id, title, weight, color };
}); }).filter(d => d != null);
aws("ok", out.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, state: STATE.client | STATE.remote,
right: 0, right: 0,
data: { data: {
room: "string", room: "string",
server: "string", server: "string",
listCatIDs: "array-number", listCatIDs: "array-number"
weights: "array-number",
}, },
func: async (client: Client, data: any, aws: (code: string, data: any) => void) => { func: async (client: Client, data: any, aws: (code: string, data: any) => void) => {
if (!checkSelfTag(data.server)) { if (!checkSelfTag(data.server)) {
if (client.state != STATE.client) return void aws("error", "right"); 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); aws(resp.state, resp.data);
return; return;
} }
@ -143,12 +144,11 @@ export const changeCategoryWeights: Act = {
aws("error", "existence"); aws("error", "existence");
return; return;
} }
if (data.weights.length != data.listCatIDs.length) return void aws("error", "data");
let affacted = 0; let affacted = 0;
for (let i = 0; i < data.listCatIDs.length; i++) { for (let i = 0; i < data.listCatIDs.length; i++) {
const listCatID = data.listCatIDs[i]; const listCatID = data.listCatIDs[i];
let req = await update(listCategories) let req = await update(listCategories)
.set(listCategories.weight, data.title) .set(listCategories.weight, i)
.where(and( .where(and(
eq(listCategories.roomID, roomID), eq(listCategories.roomID, roomID),
eq(listCategories.listCatID, listCatID) eq(listCategories.listCatID, listCatID)