mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
修复一些错误
This commit is contained in:
1 parent
bc50913e6e
commit
2b6a510c1e
23 files changed
+321
-191
No files matched your search
+11
-16
@@ -74,7 +74,7 @@ const acm = {
|
||||
const rows = [columns];
|
||||
for (const [rank, tsdoc] of rankedTsdocs) {
|
||||
const tsddict = {};
|
||||
if (tdoc.detail) { for (const item of tsdoc.detail) tsddict[item.pid] = item; }
|
||||
if (tdoc.detail) { for (const item of tsdoc.journal) tsddict[item.pid] = item; }
|
||||
const row = [];
|
||||
row.push(
|
||||
{ type: 'string', value: rank },
|
||||
@@ -229,13 +229,8 @@ function add(domainId, title, content, owner, rule,
|
||||
* @returns {Tdoc} tdoc after modification
|
||||
*/
|
||||
async function edit(domainId, tid, $set, type = document.TYPE_CONTEST) {
|
||||
if ($set.title) validator.checkTitle($set.title);
|
||||
if ($set.content) validator.checkIntro($set.content);
|
||||
if ($set.rule) { if (!this.RULES[$set.rule]) throw new ValidationError('rule'); }
|
||||
if ($set.beginAt && $set.endAt) {
|
||||
if ($set.beginAt >= $set.endAt) {
|
||||
throw new ValidationError('beginAt', 'endAt');
|
||||
}
|
||||
if ($set.rule) {
|
||||
if (!this.RULES[$set.rule]) throw new ValidationError('rule');
|
||||
}
|
||||
const tdoc = await document.get(domainId, type, tid);
|
||||
if (!tdoc) throw new ContestNotFoundError(tid);
|
||||
@@ -259,7 +254,7 @@ async function updateStatus(
|
||||
domainId, tid, uid, rid, pid,
|
||||
accept = false, score = 0, type = document.TYPE_CONTEST,
|
||||
) {
|
||||
await get(domainId, tid);
|
||||
await get(domainId, tid, type);
|
||||
const tsdoc = await document.revPushStatus(domainId, type, tid, uid, 'journal', {
|
||||
rid, pid, accept, score,
|
||||
});
|
||||
@@ -287,8 +282,8 @@ async function attend(domainId, tid, uid, type = document.TYPE_CONTEST) {
|
||||
return {};
|
||||
}
|
||||
|
||||
function getMultiStatus(query) {
|
||||
return document.getMultiStatus(query);
|
||||
function getMultiStatus(domainId, query, docType = document.TYPE_CONTEST) {
|
||||
return document.getMultiStatus(domainId, docType, query);
|
||||
}
|
||||
|
||||
function isNew(tdoc, days = 1) {
|
||||
@@ -329,10 +324,10 @@ const ContestHandlerMixin = (c) => class extends c {
|
||||
return false;
|
||||
}
|
||||
|
||||
async getScoreboard(domainId, tid, isExport = false) {
|
||||
const tdoc = await get(domainId, tid);
|
||||
async getScoreboard(domainId, tid, isExport = false, docType = document.TYPE_CONTEST) {
|
||||
const tdoc = await get(domainId, tid, docType);
|
||||
if (!this.canShowScoreboard(tdoc)) throw new ContestScoreboardHiddenError(tid);
|
||||
const tsdocs = await getMultiStatus(domainId, tid)
|
||||
const tsdocs = await getMultiStatus(domainId, tid, docType)
|
||||
.sort(RULES[tdoc.rule].statusSort).toArray();
|
||||
const uids = [];
|
||||
for (const tsdoc of tsdocs) uids.push(tsdoc.uid);
|
||||
@@ -375,10 +370,10 @@ function _getStatusJournal(tsdoc) {
|
||||
async function recalcStatus(domainId, tid, type) {
|
||||
const [tdoc, tsdocs] = await Promise.all([
|
||||
document.get(domainId, type, tid),
|
||||
document.getMultiStatus(domainId, type, { docId: tid }),
|
||||
document.getMultiStatus(domainId, type, { docId: tid }).toArray(),
|
||||
]);
|
||||
const tasks = [];
|
||||
for (const tsdoc of tsdocs) {
|
||||
for (const tsdoc of tsdocs || []) {
|
||||
if (tsdoc.journal) {
|
||||
const journal = _getStatusJournal(tsdoc);
|
||||
const stats = RULES[tdoc.rule].stat(tdoc, journal);
|
||||
|
||||
@@ -47,7 +47,7 @@ function get(domainId, docType, docId) {
|
||||
async function set(domainId, docType, docId, args) {
|
||||
const res = await coll.findOneAndUpdate(
|
||||
{ domainId, docType, docId },
|
||||
{ $set: { args } },
|
||||
{ $set: args },
|
||||
{ returnOriginal: false },
|
||||
);
|
||||
return res.value;
|
||||
|
||||
+14
-3
@@ -26,7 +26,19 @@ async function add(domainId, data) {
|
||||
judger: null,
|
||||
judgeAt: null,
|
||||
});
|
||||
const res = await coll.insertOne(data);
|
||||
const [pdoc, res] = await Promise.all([
|
||||
problem.get(domainId, data.pid),
|
||||
coll.insertOne(data),
|
||||
]);
|
||||
await task.add({
|
||||
type: 'judge',
|
||||
rid: res.insertedId,
|
||||
domainId,
|
||||
pid: data.pid,
|
||||
data: pdoc.data,
|
||||
lang: data.lang,
|
||||
code: data.code,
|
||||
});
|
||||
return res.insertedId;
|
||||
}
|
||||
|
||||
@@ -35,11 +47,10 @@ async function add(domainId, data) {
|
||||
* @param {ObjectID} rid
|
||||
* @returns {import('../interface').Record}
|
||||
*/
|
||||
async function get(domainId, rid, showHidden = false) {
|
||||
async function get(domainId, rid) {
|
||||
const _id = new ObjectID(rid);
|
||||
const rdoc = await coll.findOne({ domainId, _id });
|
||||
if (!rdoc) throw new RecordNotFoundError(rid);
|
||||
if (rdoc.hidden && !showHidden) throw new PermissionError(rid);
|
||||
return rdoc;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@ class USER {
|
||||
this.salt = () => user.salt;
|
||||
this.hash = () => user.hash;
|
||||
this.perm = user.perm;
|
||||
this.priv = user.priv;
|
||||
this.role = user.role;
|
||||
this.viewLang = user.language || 'zh_CN';
|
||||
this.codeLang = user.codeLang || 'c';
|
||||
this.codeTemplate = user.codeTemplate || '';
|
||||
@@ -161,6 +163,16 @@ function setRole(domainId, uid, role) {
|
||||
return document.setStatus(domainId, document.TYPE_DOMAIN_ROLE, 0, uid, { role });
|
||||
}
|
||||
|
||||
function setRoles(domainId, roles) {
|
||||
const tasks = [];
|
||||
for (const role in roles) {
|
||||
tasks.push(document.set(
|
||||
domainId, document.TYPE_DOMAIN_ROLE, role, { content: roles[role] },
|
||||
));
|
||||
}
|
||||
return Promise.all(tasks);
|
||||
}
|
||||
|
||||
async function getRoles(domainId) {
|
||||
const docs = await document.getMulti(domainId, document.TYPE_DOMAIN_ROLE).sort('_id', 1).toArray();
|
||||
const roles = [];
|
||||
@@ -174,6 +186,10 @@ function getRole(domainId, name) {
|
||||
return document.get(domainId, document.TYPE_DOMAIN_ROLE, name);
|
||||
}
|
||||
|
||||
function getInDomain(domainId) {
|
||||
return document.getMultiStatus(domainId, document.TYPE_DOMAIN_ROLE).toArray();
|
||||
}
|
||||
|
||||
function addRole(domainId, name, permission) {
|
||||
return document.add(domainId, permission, 1, document.TYPE_DOMAIN_ROLE, name);
|
||||
}
|
||||
@@ -205,9 +221,11 @@ global.Hydro.model.user = module.exports = {
|
||||
setPassword,
|
||||
getPrefixList,
|
||||
setRole,
|
||||
setRoles,
|
||||
getRole,
|
||||
getList,
|
||||
getRoles,
|
||||
getInDomain,
|
||||
addRole,
|
||||
deleteRoles,
|
||||
ensureIndexes,
|
||||
|
||||
Reference in new issue
Block a user