core&ui: add events channel

This commit is contained in:
undefined committed 2025-05-22 22:51:00 +08:00
1 parent ea2850a51e
commit f3d66edd41
5 files changed
+132 -36

No files matched your search

+8 -7
View File
@@ -295,13 +295,14 @@ class UserModel {
}
@ArgMethod
static async inc(_id: number, field: string, n: number = 1) {
if (_id < -999) return null;
const udoc = await coll.findOne({ _id });
if (!udoc) throw new UserNotFoundError(_id);
await coll.updateOne({ _id }, { $inc: { [field]: n } });
deleteUserCache(udoc);
return udoc;
static async inc(_id: number | number[], field: string, n: number = 1) {
const ids = (Array.isArray(_id) ? _id : [_id]).filter((i) => i >= -999);
if (!ids.length) return null;
const udocs = await coll.find({ _id: { $in: ids } }).toArray();
if (udocs.length !== ids.length) throw new UserNotFoundError(_id);
await coll.updateMany({ _id: { $in: ids } }, { $inc: { [field]: n } });
for (const udoc of udocs) deleteUserCache(udoc);
return udocs;
}
@ArgMethod