(
domainId: string, pids: number[], canViewHidden: number | boolean = false,
doThrow = true, projection = ProblemModel.PROJECTION_PUBLIC, indexByDocIdOnly = false,
)
| 382 | } |
| 383 | |
| 384 | static async getList( |
| 385 | domainId: string, pids: number[], canViewHidden: number | boolean = false, |
| 386 | doThrow = true, projection = ProblemModel.PROJECTION_PUBLIC, indexByDocIdOnly = false, |
| 387 | ): Promise<ProblemDict> { |
| 388 | if (!pids?.length) return {}; |
| 389 | const r: Record<number, ProblemDoc> = {}; |
| 390 | const l: Record<string, ProblemDoc> = {}; |
| 391 | const q: any = { docId: { $in: pids } }; |
| 392 | const projectionExpr = buildProjection(projection.includes('config') ? [...projection, 'data', 'reference'] : projection); |
| 393 | let pdocs = await document.getMulti(domainId, document.TYPE_PROBLEM, q) |
| 394 | .project<ProblemDoc>(projectionExpr).toArray(); |
| 395 | if (canViewHidden !== true) { |
| 396 | pdocs = pdocs.filter((i) => i.owner === canViewHidden || i.maintainer?.includes(canViewHidden as any) || !i.hidden); |
| 397 | } |
| 398 | await Promise.all(pdocs.map(async (pdoc) => { |
| 399 | if (projection.includes('config')) { |
| 400 | if (pdoc.reference) { |
| 401 | const src = await ProblemModel.get(pdoc.reference.domainId, pdoc.reference.pid); |
| 402 | pdoc.config = src ? src.config : 'Cannot find source problem'; |
| 403 | } else { |
| 404 | try { |
| 405 | pdoc.config = await parseConfig(pdoc.config as string, pdoc.data?.map((i) => i.name) || []); |
| 406 | } catch (e) { |
| 407 | pdoc.config = `Cannot parse: ${e.message}`; |
| 408 | } |
| 409 | } |
| 410 | } |
| 411 | if (!projection.includes('data')) delete pdoc.data; |
| 412 | if (!projection.includes('reference')) delete pdoc.reference; |
| 413 | r[pdoc.docId] = pdoc; |
| 414 | if (pdoc.pid) l[pdoc.pid] = pdoc; |
| 415 | })); |
| 416 | // TODO enhance |
| 417 | if (pdocs.length !== pids.length) { |
| 418 | for (const pid of pids) { |
| 419 | if (!r[pid] && !l[pid]) { |
| 420 | if (doThrow) throw new ProblemNotFoundError(domainId, pid); |
| 421 | if (!indexByDocIdOnly) r[pid] = { ...ProblemModel.default, domainId, pid: pid.toString() }; |
| 422 | } |
| 423 | } |
| 424 | } |
| 425 | return indexByDocIdOnly ? r : Object.assign(r, l); |
| 426 | } |
| 427 | |
| 428 | static async getListStatus(domainId: string, uid: number, pids: number[]) { |
| 429 | const psdocs = await ProblemModel.getMultiStatus( |
nothing calls this directly
no test coverage detected