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

Method __prepare

packages/hydrooj/src/handler/contest.ts:83–102  ·  view source on GitHub ↗
(domainId: string, tid: ObjectId)

Source from the content-addressed store, hash-verified

81
82 @param('tid', Types.ObjectId, true)
83 async __prepare(domainId: string, tid: ObjectId) {
84 if (!tid) return; // ProblemDetailHandler also extends from ContestDetailBaseHandler
85 [this.tdoc, this.tsdoc] = await Promise.all([
86 contest.get(domainId, tid),
87 contest.getStatus(domainId, tid, this.user._id),
88 ]);
89 if (this.tdoc.assign?.length && !this.user.own(this.tdoc) && !this.user.hasPerm(PERM.PERM_VIEW_HIDDEN_CONTEST)) {
90 const groups = await user.listGroup(domainId, this.user._id);
91 if (!new Set(this.tdoc.assign).intersection(new Set(groups.map((i) => i.name))).size) {
92 throw new NotAssignedError('contest', tid);
93 }
94 }
95 if (this.tdoc.duration && this.tsdoc?.startAt) {
96 this.tsdoc.endAt = moment.min([
97 moment(this.tsdoc.startAt).add(this.tdoc.duration, 'hours'),
98 moment(this.tdoc.endAt),
99 ...(this.tsdoc.endAt ? [moment(this.tsdoc.endAt)] : []),
100 ]).toDate();
101 }
102 }
103
104 tsdocAsPublic() {
105 if (!this.tsdoc) return null;

Callers

nothing calls this directly

Calls 7

ownMethod · 0.80
hasPermMethod · 0.80
listGroupMethod · 0.80
allMethod · 0.45
getMethod · 0.45
getStatusMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected