(
domainId: string, pid: string | number,
projection: Projection<ProblemDoc> = ProblemModel.PROJECTION_PUBLIC,
rawConfig = false,
)
| 190 | } |
| 191 | |
| 192 | static async get( |
| 193 | domainId: string, pid: string | number, |
| 194 | projection: Projection<ProblemDoc> = ProblemModel.PROJECTION_PUBLIC, |
| 195 | rawConfig = false, |
| 196 | ): Promise<ProblemDoc | null> { |
| 197 | if (Number.isSafeInteger(+pid)) pid = +pid; |
| 198 | const ddoc = await DomainModel.get(domainId); |
| 199 | const res = typeof pid === 'number' |
| 200 | ? await document.get(domainId, document.TYPE_PROBLEM, pid, projection) |
| 201 | : (await document.getMulti(domainId, document.TYPE_PROBLEM, { sort: sortable(pid, ddoc?.namespaces), pid }) |
| 202 | .project(buildProjection(projection)).limit(1).toArray())[0]; |
| 203 | if (!res) return null; |
| 204 | try { |
| 205 | if (!rawConfig && projection.includes('config')) res.config = await parseConfig(res.config, res.data?.map((i) => i.name) || []); |
| 206 | } catch (e) { |
| 207 | res.config = `Cannot parse: ${e.message}`; |
| 208 | } |
| 209 | return res; |
| 210 | } |
| 211 | |
| 212 | static getMulti(domainId: string, query: Filter<ProblemDoc>, projection = ProblemModel.PROJECTION_LIST) { |
| 213 | return document.getMulti(domainId, document.TYPE_PROBLEM, query, projection).sort({ sort: 1 }); |
no test coverage detected