core: fix discussion.problem relation

This commit is contained in:
undefined committed 2021-11-17 22:12:47 +08:00
1 parent 86379f4ace
commit 2f66bbfabd
3 files changed
+16 -2

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "hydrooj",
"version": "3.1.31",
"version": "3.1.32",
"bin": "bin/hydrooj.js",
"main": "src/loader",
"module": "src/loader",
+1 -1
View File
@@ -250,7 +250,7 @@ export async function getVnode(domainId: string, type: number, id: string, uid?:
if (type === document.TYPE_PROBLEM) {
const pdoc = await problem.get(domainId, Number.isSafeInteger(+id) ? +id : id);
if (!pdoc) throw new DiscussionNodeNotFoundError(id);
return { ...pdoc, type, id };
return { ...pdoc, type, id: pdoc.docId };
}
if ([document.TYPE_CONTEST, document.TYPE_TRAINING, document.TYPE_HOMEWORK].includes(type as any)) {
const model = type === document.TYPE_TRAINING ? training : contest;
+14
View File
@@ -634,6 +634,20 @@ const scripts: UpgradeScript[] = [
}
return true;
},
async function _53_54() {
const _FRESH_INSTALL_IGNORE = 1;
let ddocs = await db.collection('document').find({ docType: 21, parentType: 10 })
.project({ _id: 1, parentId: 1 }).toArray();
ddocs = ddocs.filter((i) => Number.isSafeInteger(+i.parentId));
if (ddocs.length) {
const bulk = db.collection('document').initializeUnorderedBulkOp();
for (const ddoc of ddocs) {
bulk.find({ _id: ddoc._id }).updateOne({ $set: { parentId: +ddoc.parentId } });
}
await bulk.execute();
}
return true;
},
];
export default scripts;