| 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; |