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

Method get

packages/hydrooj/src/handler/record.ts:38–129  ·  view source on GitHub ↗
(
        domainId: string, page = 1, pid?: string | number, tid?: ObjectId,
        uidOrName?: string, lang?: string, status?: number, full = false,
        all = false, allDomain = false, stat = false,
    )

Source from the content-addressed store, hash-verified

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

Callers 6

prepareMethod · 0.45
getMethod · 0.45
postRejudgeMethod · 0.45
prepareMethod · 0.45
onRecordChangeMethod · 0.45
prepareMethod · 0.45

Calls 15

buildProjectionFunction · 0.90
getByIdMethod · 0.80
getByUnameMethod · 0.80
getByEmailMethod · 0.80
checkPermMethod · 0.80
checkPrivMethod · 0.80
hasPermMethod · 0.80
ownMethod · 0.80
hasPrivMethod · 0.80
statMethod · 0.80
getStatusMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected