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

Method get

packages/hydrooj/src/handler/training.ts:63–96  ·  view source on GitHub ↗
(domainId: string, page = 1, q = '')

Source from the content-addressed store, hash-verified

61 @param('page', Types.PositiveInt, true)
62 @param('q', Types.String, true)
63 async get(domainId: string, page = 1, q = '') {
64 const query: Filter<TrainingDoc> = {};
65 if (q) query.title = { $regex: new RegExp(escapeRegExp(q), 'i') };
66 await this.ctx.parallel('training/list', query, this);
67 const [tdocs, tpcount] = await this.paginate(
68 training.getMulti(domainId, query),
69 page,
70 'training',
71 );
72 const tids: Set<ObjectId> = new Set();
73 for (const tdoc of tdocs) tids.add(tdoc.docId);
74 const tsdict = {};
75 let tdict = {};
76 if (this.user.hasPriv(PRIV.PRIV_USER_PROFILE)) {
77 const enrolledTids: Set<ObjectId> = new Set();
78 const tsdocs = await training.getMultiStatus(domainId, {
79 uid: this.user._id,
80 $or: [{ docId: { $in: Array.from(tids) } }, { enroll: 1 }],
81 }).toArray();
82 for (const tsdoc of tsdocs) {
83 tsdict[tsdoc.docId.toHexString()] = tsdoc;
84 enrolledTids.add(tsdoc.docId);
85 }
86 for (const tid of tids) enrolledTids.delete(tid);
87 if (enrolledTids.size) {
88 tdict = await training.getList(domainId, Array.from(enrolledTids));
89 }
90 }
91 for (const tdoc of tdocs) tdict[tdoc.docId.toHexString()] = tdoc;
92 this.response.template = 'training_main.html';
93 this.response.body = {
94 tdocs, page, tpcount, tsdict, tdict, q,
95 };
96 }
97}
98
99class TrainingDetailHandler extends Handler {

Callers 7

_parseDagJsonFunction · 0.45
getMethod · 0.45
postEnrollMethod · 0.45
postDeleteMethod · 0.45
prepareMethod · 0.45
prepareMethod · 0.45
postUploadFileMethod · 0.45

Calls 6

hasPrivMethod · 0.80
getMultiStatusMethod · 0.80
paginateMethod · 0.65
getMultiMethod · 0.45
addMethod · 0.45
getListMethod · 0.45

Tested by

no test coverage detected