修复training显示异常

This commit is contained in:
masnn committed 2020-05-30 12:26:54 +08:00
1 parent 257d9814a9
commit b2989cb9ea
14 files changed
+88 -89

No files matched your search

+9 -7
View File
@@ -119,6 +119,7 @@ const acm = {
}
return rows;
},
rank: (tdocs) => ranked(tdocs, (a, b) => a.score === b.score),
};
const oi = {
@@ -251,16 +252,17 @@ async function get(domainId, tid) {
if (!tdoc) throw new ContestNotFoundError(tid);
return tdoc;
}
async function updateStatus(domainId, tid, uid, rid, pid, accept, score) {
async function updateStatus(domainId, tid, uid, rid, pid, accept = false, score = 0) {
await get(domainId, tid);
const tsdoc = await document.revPushStatus(domainId, document.TYPE_CONTEST, tid, uid, 'journal', {
rid, pid, accept, score,
});
if (!tsdoc.value.attend) throw new ContestNotAttendedError(tid, uid);
if (!tsdoc.attend) throw new ContestNotAttendedError(tid, uid);
}
function getStatus(domainId, tid, uid) {
return document.getStatus(domainId, tid, uid);
return document.getStatus(domainId, document.TYPE_CONTEST, tid, uid);
}
async function getListStatus(domainId, uid, tids) {
@@ -276,7 +278,7 @@ async function attend(domainId, tid, uid) {
} catch (e) {
throw new ContestAlreadyAttendedError(tid, uid);
}
await document.inc(domainId, document, document.TYPE_CONTEST, tid, 'attend', 1);
await document.inc(domainId, document.TYPE_CONTEST, tid, 'attend', 1);
return {};
}
@@ -330,7 +332,7 @@ const ContestHandlerMixin = (c) => class extends c {
const uids = [];
for (const tsdoc of tsdocs) uids.push(tsdoc.uid);
const [udict, pdict] = await Promise.all([
user.getList(uids),
user.getList(domainId, uids),
problem.getList(domainId, tdoc.pids),
]);
const rankedTsdocs = RULES[tdoc.rule].rank(tsdocs);
@@ -363,8 +365,8 @@ global.Hydro.model.contest = module.exports = {
get,
updateStatus,
getStatus,
count: (query) => document.count({ ...query, docType: document.TYPE_CONTEST }),
getMulti: (query = {}) => document.getMulti({ ...query, docType: document.TYPE_CONTEST }),
count: (domainId, query) => document.count(domainId, document.TYPE_CONTEST, query),
getMulti: (domainId, query = {}) => document.getMulti(domainId, document.TYPE_CONTEST, query),
setStatus,
isNew,
isUpcoming,
+2 -2
View File
@@ -18,7 +18,7 @@ const TYPE_FILE = 50;
const TYPE_HOMEWORK = 60;
async function add(
domainId, content, owner, docType, docId,
domainId, content, owner, docType, docId = null,
parentType = null, parentId = null, args = {},
) {
const _id = new ObjectID();
@@ -210,7 +210,7 @@ async function cappedIncStatus(
{
domainId, docType, docId, uid, [key]: { $not },
},
{ $inc: { key: value } },
{ $inc: { [key]: value } },
{ upsert: true, returnOriginal: false },
);
return res.value;
+8 -21
View File
@@ -1,7 +1,5 @@
const assert = require('assert');
const document = require('./document');
const validator = require('../lib/validator');
const { ValidationError, TrainingNotFoundError, TrainingAlreadyEnrollError } = require('../error');
const { TrainingNotFoundError, TrainingAlreadyEnrollError } = require('../error');
function getStatus(domainId, tid, uid) {
return document.getStatus(domainId, document.TYPE_TRAINING, tid, uid);
@@ -34,14 +32,6 @@ function setStatus(domainId, tid, uid, $set) {
}
function add(domainId, title, content, owner, dag = [], description = '') {
validator.checkTitle(title);
validator.checkIntro(content);
validator.checkDescription(description);
for (const node of dag) {
for (const nid of node.requireNids) {
if (nid >= node._id) throw new ValidationError('dag');
}
}
return document.add(domainId, content, owner, document.TYPE_TRAINING, null, null, null, {
dag,
title,
@@ -51,16 +41,6 @@ function add(domainId, title, content, owner, dag = [], description = '') {
}
function edit(domainId, tid, $set) {
if ($set.title) validator.checkTitle($set.title);
if ($set.content) validator.checkIntro($set.content);
if ($set.desc) validator.checkDescription($set.description);
if ($set.dag) {
for (const node of $set.dag) {
for (const nid of node.requireNids) {
assert(nid >= node._id, new ValidationError('dag'));
}
}
}
return document.set(domainId, document.TYPE_TRAINING, tid, $set);
}
@@ -101,6 +81,13 @@ global.Hydro.model.training = module.exports = {
async get(domainId, tid) {
const tdoc = await document.get(domainId, document.TYPE_TRAINING, tid);
if (!tdoc) throw new TrainingNotFoundError(tid);
for (const i in tdoc.dag) {
for (const j in tdoc.dag[i].pids) {
if (Number.isSafeInteger(parseInt(tdoc.dag[i].pids[j]))) {
tdoc.dag[i].pids[j] = parseInt(tdoc.dag[i].pids[j]);
}
}
}
return tdoc;
},
async getList(domainId, tids) {
+8 -3
View File
@@ -47,7 +47,7 @@ async function getPerm(domainId, udoc) {
return p.content;
}
const role = await document.getStatus(domainId, document.TYPE_DOMAIN_ROLE, 0, udoc._id);
const p = await document.get(domainId, document.TYPE_DOMAIN_ROLE, role || 'default');
const p = await document.get(domainId, document.TYPE_DOMAIN_ROLE, role.role || 'default');
return p.content;
}
@@ -159,8 +159,13 @@ function setRole(domainId, uid, role) {
return document.setStatus(domainId, document.TYPE_DOMAIN_ROLE, 0, uid, { role });
}
function getRoles(domainId) {
return document.getMulti(domainId, document.TYPE_DOMAIN_ROLE).sort('_id', 1).toArray();
async function getRoles(domainId) {
const docs = await document.getMulti(domainId, document.TYPE_DOMAIN_ROLE).sort('_id', 1).toArray();
const roles = [];
for (const doc of docs) {
roles.push({ _id: doc.docId, perm: doc.content });
}
return roles;
}
function getRole(domainId, name) {