MCPcopy Create free account
hub / github.com/hydro-dev/Hydro / get

Method get

packages/hydrooj/src/handler/homework.ts:37–76  ·  view source on GitHub ↗
(domainId: string, group = '', page = 1, q = '')

Source from the content-addressed store, hash-verified

35 @param('page', Types.PositiveInt, true)
36 @param('q', Types.String, true)
37 async get(domainId: string, group = '', page = 1, q = '') {
38 const groups = (await user.listGroup(domainId, this.user.hasPerm(PERM.PERM_VIEW_HIDDEN_HOMEWORK) ? undefined : this.user._id))
39 .map((i) => i.name);
40 if (group && !groups.includes(group)) throw new NotAssignedError(group);
41 const escaped = escapeRegExp(q.toLowerCase());
42 const cursor = contest.getMulti(domainId, {
43 rule: 'homework',
44 ...this.user.hasPerm(PERM.PERM_VIEW_HIDDEN_HOMEWORK) && !group
45 ? {}
46 : {
47 $or: [
48 { maintainer: this.user._id },
49 { owner: this.user._id },
50 { assign: { $in: groups } },
51 { assign: { $size: 0 } },
52 ],
53 },
54 ...group ? { assign: { $in: [group] } } : {},
55 ...q ? { title: { $regex: new RegExp(q.length >= 2 ? escaped : `\\A${escaped}`, 'gim') } } : {},
56 }).sort({
57 penaltySince: -1, endAt: -1, beginAt: -1, _id: -1,
58 });
59 const [tdocs, tpcount] = await this.paginate(cursor, page, 'contest');
60 const calendar = [];
61 for (const tdoc of tdocs) {
62 const cal = { ...tdoc, url: this.url('homework_detail', { tid: tdoc.docId }) };
63 if (contest.isExtended(tdoc) || contest.isDone(tdoc)) {
64 cal.endAt = tdoc.endAt;
65 cal.penaltySince = tdoc.penaltySince;
66 } else cal.endAt = tdoc.penaltySince;
67 calendar.push(cal);
68 }
69 let qs = group ? `group=${group}` : '';
70 if (q) qs += `${qs ? '&' : ''}q=${encodeURIComponent(q)}`;
71 const groupsFilter = groups.filter((i) => !Number.isSafeInteger(+i));
72 this.response.body = {
73 tdocs, calendar, tpcount, page, qs, groups: groupsFilter, group, q,
74 };
75 this.response.template = 'homework_main.html';
76 }
77}
78
79class HomeworkDetailHandler extends Handler {

Callers 6

prepareMethod · 0.45
getMethod · 0.45
postUpdateMethod · 0.45
postDeleteMethod · 0.45
prepareMethod · 0.45
postUploadFileMethod · 0.45

Calls 6

listGroupMethod · 0.80
hasPermMethod · 0.80
urlMethod · 0.80
paginateMethod · 0.65
getMultiMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected