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

Method copy

packages/hydrooj/src/model/problem.ts:252–264  ·  view source on GitHub ↗
(domainId: string, _id: number, target: string, pid?: string, hidden?: boolean)

Source from the content-addressed store, hash-verified

250 }
251
252 static async copy(domainId: string, _id: number, target: string, pid?: string, hidden?: boolean) {
253 const original = await ProblemModel.get(domainId, _id);
254 if (!original) throw new ProblemNotFoundError(domainId, _id);
255 if (original.reference) throw new ValidationError('reference');
256 if (pid && (/^[0-9]+$/.test(pid) || await ProblemModel.get(target, pid))) pid = '';
257 if (!pid && original.pid && !await ProblemModel.get(target, original.pid)) pid = original.pid;
258 const $set = { hidden: hidden || original.hidden, reference: { domainId, pid: _id } } as any;
259 if (typeof original.difficulty === 'number') $set.difficulty = original.difficulty;
260 return await ProblemModel.add(
261 target, pid, original.title, original.content,
262 original.owner, original.tag, $set,
263 );
264 }
265
266 static push<T extends ArrayKeys<ProblemDoc>>(domainId: string, _id: number, key: ArrayKeys<ProblemDoc>, value: ProblemDoc[T][0]) {
267 return document.push(domainId, document.TYPE_PROBLEM, _id, key, value);

Callers

nothing calls this directly

Calls 2

getMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected