(domainId: string, page = 1, q = '')
| 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 | |
| 99 | class TrainingDetailHandler extends Handler { |
no test coverage detected