core: contest.list: ignore hidden rule

This commit is contained in:
undefined committed 2022-07-16 18:01:10 +08:00
1 parent 81cf7247d8
commit b3555e030f
2 files changed
+8 -4

No files matched your search

+6 -3
View File
@@ -5,8 +5,9 @@ import moment from 'moment-timezone';
import { ObjectID } from 'mongodb';
import { sortFiles, Time } from '@hydrooj/utils/lib/utils';
import {
ContestNotFoundError, ContestNotLiveError, ForbiddenError, InvalidTokenError,
PermissionError, ValidationError,
BadRequestError, ContestNotFoundError, ContestNotLiveError,
ForbiddenError, InvalidTokenError, PermissionError,
ValidationError,
} from '../error';
import { Tdoc } from '../interface';
import paginate from '../lib/paginate';
@@ -69,7 +70,9 @@ export class ContestListHandler extends Handler {
@param('rule', Types.Range(contest.RULES), true)
@param('page', Types.PositiveInt, true)
async get(domainId: string, rule = '', page = 1) {
const cursor = contest.getMulti(domainId, rule ? { rule } : { rule: { $ne: 'homework' } });
if (rule && contest.RULES[rule].hidden) throw new BadRequestError();
const rules = Object.keys(contest.RULES).filter((i) => !contest.RULES[i].hidden);
const cursor = contest.getMulti(domainId, rule ? { rule } : { rule: { $in: rules } });
const qs = rule ? `rule=${rule}` : '';
const [tdocs, tpcount] = await paginate<Tdoc>(cursor, page, system.get('pagination.contest'));
const tids = [];
+2 -1
View File
@@ -51,7 +51,8 @@ export class HomeHandler extends Handler {
async getContest(domainId: string, limit = 10) {
if (this.user.hasPerm(PERM.PERM_VIEW_CONTEST)) {
const tdocs = await contest.getMulti(domainId, { rule: { $ne: 'homework' } })
const rules = Object.keys(contest.RULES).filter((i) => !contest.RULES[i].hidden);
const tdocs = await contest.getMulti(domainId, { rule: { $in: rules } })
.limit(limit).toArray();
const tsdict = await contest.getListStatus(
domainId, this.user._id, tdocs.map((tdoc) => tdoc.docId),