change item state time
This commit is contained in:
parent
4856d477e4
commit
c46f9c8752
2 changed files with 48 additions and 1 deletions
|
@ -1,10 +1,11 @@
|
|||
import { and, coalesce, eq, insert, leftJoinOn, leftJoinUsing, max, order, plus, remove, select, update } from "dblang";
|
||||
import { and, coalesce, eq, insert, le, leftJoinOn, leftJoinUsing, 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";
|
||||
import { isCategoryInRoom, isItemInRoom, isProductInRoom, isRoomDataFull } from "../helper.js"
|
||||
import { ROOM_RIGHTS } from "../../server/permissions.js";
|
||||
import { act_error } from "../../server/errors.js";
|
||||
import { uts } from "../../sys/tools.js";
|
||||
|
||||
export const getCategories: Act = {
|
||||
state: STATE.client | STATE.remote,
|
||||
|
@ -716,6 +717,7 @@ export const changeItemState: Act = {
|
|||
if (!isItemInRoom(roomID, data.listItemID)) return void aws("error", act_error.ITEM_NOT_EXISTS);
|
||||
let req = await update(listItems)
|
||||
.set(listItems.state, data.state)
|
||||
.set(listItems.lastStateTime, uts())
|
||||
.where(and(
|
||||
eq(listItems.listItemID, data.listItemID),
|
||||
eq(listItems.roomID, roomID)
|
||||
|
@ -726,6 +728,50 @@ export const changeItemState: Act = {
|
|||
}
|
||||
};
|
||||
|
||||
export const changeItemStates: Act = {
|
||||
state: STATE.client | STATE.remote,
|
||||
right: 0,
|
||||
data: {
|
||||
room: "string",
|
||||
server: "string",
|
||||
listItemIDs: "array-number",
|
||||
changedTimes: "array-number", //in uts time sec
|
||||
states: "array-number", // 0 = added; 1 = in cart/bought
|
||||
},
|
||||
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, "changeItemStates", 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;
|
||||
}
|
||||
if (
|
||||
data.listItemIDs.length != data.changedTimes.length
|
||||
|| data.changedTimes.length != data.states.length
|
||||
) return void aws("error", "data");
|
||||
for (let i = 0; i < data.listItemIDs.length; i++) {
|
||||
let id = data.listItemIDs[i];
|
||||
let time = data.changedTimes[i];
|
||||
let state = data.states[i] == 0 ? 0 : 1;
|
||||
await update(listItems)
|
||||
.set(listItems.state, state)
|
||||
.set(listItems.lastStateTime, uts())
|
||||
.where(and(
|
||||
eq(listItems.listItemID, id),
|
||||
eq(listItems.roomID, roomID),
|
||||
le(listItems.lastStateTime, time)
|
||||
))
|
||||
.query(db);
|
||||
}
|
||||
aws("ok", "");
|
||||
}
|
||||
};
|
||||
|
||||
export const deleteItem: Act = {
|
||||
state: STATE.client | STATE.remote,
|
||||
right: 0,
|
||||
|
|
|
@ -230,6 +230,7 @@ listItems.addAttributes({
|
|||
}
|
||||
},
|
||||
state: { type: SMALLINT, default: 0 },
|
||||
lastStateTime: { type: BIGINT, default: 0 },
|
||||
title: { type: TEXT },
|
||||
description: { type: TEXT },
|
||||
category: {
|
||||
|
|
Loading…
Reference in a new issue