| 234 | } |
| 235 | |
| 236 | static async edit(domainId: string, _id: number, $set: Partial<ProblemDoc>): Promise<ProblemDoc> { |
| 237 | const delpid = $set.pid === ''; |
| 238 | const ddoc = await DomainModel.get(domainId); |
| 239 | const $unset = delpid ? { pid: '' } : {}; |
| 240 | if (delpid) { |
| 241 | delete $set.pid; |
| 242 | $set.sort = sortable(`P${_id}`, ddoc.namespaces); |
| 243 | } else if ($set.pid) { |
| 244 | $set.sort = sortable($set.pid, ddoc.namespaces); |
| 245 | } |
| 246 | await bus.parallel('problem/before-edit', $set, $unset); |
| 247 | const result = await document.set(domainId, document.TYPE_PROBLEM, _id, $set, $unset); |
| 248 | await bus.emit('problem/edit', result); |
| 249 | return result; |
| 250 | } |
| 251 | |
| 252 | static async copy(domainId: string, _id: number, target: string, pid?: string, hidden?: boolean) { |
| 253 | const original = await ProblemModel.get(domainId, _id); |