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

Method get

packages/hydrooj/src/handler/homework.ts:95–137  ·  view source on GitHub ↗
(domainId: string, tid: ObjectId, page = 1)

Source from the content-addressed store, hash-verified

93 @param('tid', Types.ObjectId)
94 @param('page', Types.PositiveInt, true)
95 async get(domainId: string, tid: ObjectId, page = 1) {
96 const tsdoc = await contest.getStatus(domainId, tid, this.user._id);
97 if (this.tdoc.rule !== 'homework') throw new ContestNotFoundError(domainId, tid);
98 // discussion
99 const [ddocs, dpcount, dcount] = await this.paginate(
100 discussion.getMulti(domainId, { parentType: this.tdoc.docType, parentId: this.tdoc.docId }),
101 page,
102 'discussion',
103 );
104 const uids = ddocs.map((ddoc) => ddoc.owner);
105 uids.push(this.tdoc.owner);
106 const udict = await user.getList(domainId, uids);
107 this.response.template = 'homework_detail.html';
108 this.response.body = {
109 tdoc: this.tdoc, tsdoc, udict, ddocs, page, dpcount, dcount,
110 };
111 this.response.body.tdoc.content = this.response.body.tdoc.content
112 .replace(/\(file:\/\//g, `(./${this.tdoc.docId}/file/public/`)
113 .replace(/="file:\/\//g, `="./${this.tdoc.docId}/file/public/`);
114 if (
115 (contest.isNotStarted(this.tdoc) || (!tsdoc?.attend && !contest.isDone(this.tdoc)))
116 && !this.user.own(this.tdoc)
117 && !this.user.hasPerm(PERM.PERM_VIEW_HOMEWORK_HIDDEN_SCOREBOARD)
118 ) return;
119 const pdict = await problem.getList(domainId, this.tdoc.pids, true, true, problem.PROJECTION_CONTEST_LIST);
120 const psdict = {};
121 let rdict = {};
122 if (tsdoc) {
123 if (tsdoc.attend && !tsdoc.startAt && contest.isOngoing(this.tdoc)) {
124 await contest.setStatus(domainId, tid, this.user._id, { startAt: new Date() });
125 tsdoc.startAt = new Date();
126 }
127 const valid = (tsdoc.journal || []).filter((p) => this.tdoc.pids.includes(p.pid));
128 for (const pdetail of valid) {
129 psdict[pdetail.pid] = pdetail;
130 rdict[pdetail.rid.toHexString()] = { _id: pdetail.rid };
131 }
132 if (contest.canShowSelfRecord.call(this, this.tdoc) && valid.length) {
133 rdict = await record.getList(domainId, valid.map((pdetail) => pdetail.rid));
134 }
135 }
136 Object.assign(this.response.body, { pdict, psdict, rdict });
137 }
138
139 async postAttend({ domainId }) {
140 this.checkPerm(PERM.PERM_ATTEND_HOMEWORK);

Callers

nothing calls this directly

Calls 8

ownMethod · 0.80
hasPermMethod · 0.80
setStatusMethod · 0.80
paginateMethod · 0.65
getStatusMethod · 0.45
getMultiMethod · 0.45
pushMethod · 0.45
getListMethod · 0.45

Tested by

no test coverage detected