core: allow username change

This commit is contained in:
undefined committed 2021-07-04 13:53:11 +08:00
1 parent 70abfd2595
commit c5f9f86dd7
2 files changed
+14 -1

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "hydrooj", "name": "hydrooj",
"version": "2.29.18", "version": "2.29.19",
"bin": "bin/hydrooj.js", "bin": "bin/hydrooj.js",
"main": "dist/loader.js", "main": "dist/loader.js",
"typings": "dist/loader.d.ts", "typings": "dist/loader.d.ts",
+13
View File
@@ -264,6 +264,19 @@ class UserModel {
return uid; return uid;
} }
@ArgMethod
static async changeUsername(uid: number, uname: string) {
const udoc = await coll.findOne({ _id: uid });
deleteUserCache(udoc);
const res = await coll.findOneAndUpdate(
{ _id: uid },
{ $set: { uname, unameLower: uname.trim().toLowerCase() } },
{ returnDocument: 'after' },
);
deleteUserCache(res.value);
return res.value;
}
static getMulti(params: any = {}) { static getMulti(params: any = {}) {
return coll.find(params); return coll.find(params);
} }