| 161 | } |
| 162 | |
| 163 | static async addWithId( |
| 164 | domainId: string, docId: number, pid: string = '', title: string, |
| 165 | content: string, owner: number, tag: string[] = [], |
| 166 | meta: ProblemCreateOptions = {}, |
| 167 | ) { |
| 168 | const ddoc = await DomainModel.get(domainId); |
| 169 | const args: Partial<ProblemDoc> = { |
| 170 | title, |
| 171 | tag, |
| 172 | hidden: meta.hidden || false, |
| 173 | nSubmit: 0, |
| 174 | nAccept: 0, |
| 175 | sort: sortable(pid || `P${docId}`, ddoc?.namespaces), |
| 176 | data: [], |
| 177 | additional_file: [], |
| 178 | }; |
| 179 | if (pid) args.pid = pid; |
| 180 | if (meta.difficulty) args.difficulty = meta.difficulty; |
| 181 | if (meta.reference) args.reference = meta.reference; |
| 182 | await bus.parallel('problem/before-add', domainId, content, owner, docId, args); |
| 183 | const result = await document.add(domainId, content, owner, document.TYPE_PROBLEM, docId, null, null, args); |
| 184 | args.content = content; |
| 185 | args.owner = owner; |
| 186 | args.docType = document.TYPE_PROBLEM; |
| 187 | args.domainId = domainId; |
| 188 | await bus.emit('problem/add', args, result); |
| 189 | return result; |
| 190 | } |
| 191 | |
| 192 | static async get( |
| 193 | domainId: string, pid: string | number, |