mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core&ui: add events channel
This commit is contained in:
5 files changed
+132
-36
No files matched your search
@@ -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
|
||||
|
||||
Reference in new issue
Block a user