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