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

Method get

packages/hydrooj/src/model/problem.ts:192–210  ·  view source on GitHub ↗
(
        domainId: string, pid: string | number,
        projection: Projection<ProblemDoc> = ProblemModel.PROJECTION_PUBLIC,
        rawConfig = false,
    )

Source from the content-addressed store, hash-verified

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 });

Callers 8

addWithIdMethod · 0.45
editMethod · 0.45
copyMethod · 0.45
getListMethod · 0.45
importMethod · 0.45
isValidPidMethod · 0.45
exportMethod · 0.45
applyFunction · 0.45

Calls 4

buildProjectionFunction · 0.90
parseConfigFunction · 0.90
sortableFunction · 0.70
getMultiMethod · 0.45

Tested by

no test coverage detected