Backend fixes
This commit is contained in:
@ -139,20 +139,29 @@ router.post('documents.delete', auth(), async (ctx) => {
|
|||||||
ctx.assertPresent(id, 'id is required');
|
ctx.assertPresent(id, 'id is required');
|
||||||
|
|
||||||
const user = ctx.state.user;
|
const user = ctx.state.user;
|
||||||
let document = await Document.findOne({
|
const document = await Document.findOne({
|
||||||
where: {
|
where: {
|
||||||
id: id,
|
id: id,
|
||||||
teamId: user.teamId,
|
teamId: user.teamId,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
const atlas = await Atlas.findById(document.atlasId);
|
||||||
|
|
||||||
if (!document) throw httpErrors.BadRequest();
|
if (!document) throw httpErrors.BadRequest();
|
||||||
|
|
||||||
// TODO: Don't allow to destroy root docs
|
|
||||||
// TODO: handle sub documents
|
// TODO: handle sub documents
|
||||||
|
|
||||||
|
// Don't allow deletion of root docs
|
||||||
|
if (atlas.type === 'atlas' && !document.parentDocumentId) {
|
||||||
|
throw httpErrors.BadRequest('Unable to delete atlas\'s root document');
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await document.destroy();
|
await document.destroy();
|
||||||
|
|
||||||
|
if (atlas.type === 'atlas') {
|
||||||
|
await atlas.updateNavigationTree();
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw httpErrors.BadRequest('Error while deleting');
|
throw httpErrors.BadRequest('Error while deleting');
|
||||||
};
|
};
|
||||||
|
@ -8,10 +8,6 @@ module.exports = {
|
|||||||
{
|
{
|
||||||
type: Sequelize.UUID,
|
type: Sequelize.UUID,
|
||||||
allowNull: true,
|
allowNull: true,
|
||||||
references: {
|
|
||||||
model: "documents",
|
|
||||||
key: "id",
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
@ -96,8 +96,7 @@ const Atlas = sequelize.define('atlas', {
|
|||||||
atlasId: this.id,
|
atlasId: this.id,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
if (!childDocument) throw new Error;
|
if (childDocument) {
|
||||||
|
|
||||||
childNodes.push({
|
childNodes.push({
|
||||||
id: childDocument.id,
|
id: childDocument.id,
|
||||||
title: childDocument.title,
|
title: childDocument.title,
|
||||||
@ -106,6 +105,7 @@ const Atlas = sequelize.define('atlas', {
|
|||||||
})
|
})
|
||||||
nodeIds.push(child.id);
|
nodeIds.push(child.id);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return childNodes;
|
return childNodes;
|
||||||
};
|
};
|
||||||
newTree.children = await getIdsForChildren(tree.children);
|
newTree.children = await getIdsForChildren(tree.children);
|
||||||
|
Reference in New Issue
Block a user