(
domainId: string, page = 1, pid?: string | number, tid?: ObjectId,
uidOrName?: string, lang?: string, status?: number, full = false,
all = false, allDomain = false, stat = false,
)
| 36 | @param('allDomain', Types.Boolean) |
| 37 | @param('stat', Types.Boolean) |
| 38 | async get( |
| 39 | domainId: string, page = 1, pid?: string | number, tid?: ObjectId, |
| 40 | uidOrName?: string, lang?: string, status?: number, full = false, |
| 41 | all = false, allDomain = false, stat = false, |
| 42 | ) { |
| 43 | const notification = []; |
| 44 | let tdoc = null; |
| 45 | let invalid = false; |
| 46 | this.response.template = 'record_main.html'; |
| 47 | const q: Filter<RecordDoc> = { contest: tid }; |
| 48 | if (full) uidOrName = this.user._id.toString(); |
| 49 | if (uidOrName) { |
| 50 | const udoc = await user.getById(domainId, +uidOrName) |
| 51 | || await user.getByUname(domainId, uidOrName) |
| 52 | || await user.getByEmail(domainId, uidOrName); |
| 53 | if (udoc) q.uid = udoc._id; |
| 54 | else invalid = true; |
| 55 | } |
| 56 | if (q.uid !== this.user._id) this.checkPerm(PERM.PERM_VIEW_RECORD); |
| 57 | if (tid) { |
| 58 | tdoc = await contest.get(domainId, tid); |
| 59 | this.tdoc = tdoc; |
| 60 | if (!tdoc) throw new ContestNotFoundError(domainId, pid); |
| 61 | if (!contest.canShowScoreboard.call(this, tdoc, true)) throw new PermissionError(PERM.PERM_VIEW_CONTEST_HIDDEN_SCOREBOARD); |
| 62 | if (!contest[q.uid === this.user._id ? 'canShowSelfRecord' : 'canShowRecord'].call(this, tdoc, true)) { |
| 63 | throw new PermissionError(PERM.PERM_VIEW_CONTEST_HIDDEN_SCOREBOARD); |
| 64 | } |
| 65 | if (!(await contest.getStatus(domainId, tid, this.user._id))?.attend) { |
| 66 | const name = tdoc.rule === 'homework' |
| 67 | ? "You haven't claimed this homework yet." |
| 68 | : "You haven't attended this contest yet."; |
| 69 | notification.push({ name, args: { type: 'note' }, checker: () => true }); |
| 70 | } |
| 71 | } |
| 72 | if (pid) { |
| 73 | if (typeof pid === 'string' && tdoc && /^[A-Z]$/.test(pid)) { |
| 74 | pid = tdoc.pids[Number.parseInt(pid, 36) - 10]; |
| 75 | } |
| 76 | const pdoc = await problem.get(domainId, pid); |
| 77 | if (pdoc) q.pid = pdoc.docId; |
| 78 | else invalid = true; |
| 79 | } |
| 80 | if (lang) q.lang = lang; |
| 81 | if (typeof status === 'number') q.status = status; |
| 82 | if (all) { |
| 83 | this.checkPerm(PERM.PERM_VIEW_CONTEST_HIDDEN_SCOREBOARD); |
| 84 | this.checkPerm(PERM.PERM_VIEW_HOMEWORK_HIDDEN_SCOREBOARD); |
| 85 | delete q.contest; |
| 86 | } |
| 87 | if (allDomain) { |
| 88 | this.checkPriv(PRIV.PRIV_MANAGE_ALL_DOMAIN); |
| 89 | delete q.contest; |
| 90 | q._id = { $gt: Time.getObjectID(new Date(Date.now() - 10 * Time.week)) }; |
| 91 | } |
| 92 | let cursor = record.getMulti(allDomain ? '' : domainId, q).sort('_id', -1); |
| 93 | if (!full) cursor = cursor.project(buildProjection(record.PROJECTION_LIST)); |
| 94 | const limit = full ? 10 : system.get('pagination.record'); |
| 95 | let rdocs = invalid |
no test coverage detected