core: try to fix #121

This commit is contained in:
undefined committed 2021-04-27 22:40:58 +08:00
1 parent d77d7d9ade
commit 00586b5883
8 files changed
+22 -13

No files matched your search

+7 -2
View File
@@ -10,6 +10,7 @@ import task from './task';
import problem from './problem';
import { Rdoc, ContestInfo, ProblemConfig } from '../interface';
import { ArgMethod, Time } from '../utils';
import { MaybeArray } from '../typeutils';
import * as bus from '../service/bus';
import db from '../service/db';
@@ -109,7 +110,7 @@ class RecordModel {
}
static async update(
domainId: string, _id: ObjectID,
domainId: string, _id: MaybeArray<ObjectID>,
$set?: MatchKeysAndValues<Rdoc>,
$push?: PushOperator<Rdoc>,
$unset?: OnlyFieldsOfType<Rdoc, any, true | '' | 1>,
@@ -118,6 +119,10 @@ class RecordModel {
if ($set && Object.keys($set).length) $update.$set = $set;
if ($push && Object.keys($push).length) $update.$push = $push;
if ($unset && Object.keys($unset).length) $update.$unset = $unset;
if (_id instanceof Array) {
await RecordModel.coll.updateMany({ _id: { $in: _id }, domainId }, $update);
return null;
}
if (Object.keys($update).length) {
const res = await RecordModel.coll.findOneAndUpdate(
{ _id, domainId },
@@ -143,7 +148,7 @@ class RecordModel {
return res.modifiedCount;
}
static reset(domainId: string, rid: ObjectID, isRejudge: boolean) {
static reset(domainId: string, rid: MaybeArray<ObjectID>, isRejudge: boolean) {
const upd: any = {
score: 0,
status: STATUS.STATUS_WAITING,
+6 -2
View File
@@ -115,12 +115,13 @@ class UserModel {
};
@ArgMethod
static async getById(domainId: string, _id: number, scope: bigint = PERM.PERM_ALL): Promise<User | null> {
static async getById(domainId: string, _id: number, scope: bigint | string = PERM.PERM_ALL): Promise<User | null> {
const udoc = _id === 0 || _id === 1
? BUILTIN_USERS[_id]
: await coll.findOne({ _id });
if (!udoc) return null;
const dudoc = await domain.getDomainUser(domainId, udoc);
if (typeof scope === 'string') scope = BigInt(scope);
return new User(udoc, dudoc, scope);
}
@@ -197,7 +198,10 @@ class UserModel {
uid: number = 0, regip: string = '127.0.0.1', priv: number = system.get('default.priv'),
) {
const salt = String.random();
if (!uid) uid = await system.inc('user');
if (!uid) {
const [udoc] = await coll.find({}).sort({ _id: -1 }).limit(1).toArray();
uid = Math.max((udoc._id || 0) + 1, 2);
}
try {
await coll.insertOne({
_id: uid,