server: fix delete wiki

pull/59/head
fantasticit 2022-05-21 13:12:45 +08:00
parent 995be31a41
commit e804dea750
2 changed files with 6 additions and 2 deletions

View File

@ -358,7 +358,10 @@ export class DocumentService {
async deleteDocument(user: OutUser, documentId) { async deleteDocument(user: OutUser, documentId) {
const document = await this.documentRepo.findOne(documentId); const document = await this.documentRepo.findOne(documentId);
if (document.isWikiHome) { if (document.isWikiHome) {
throw new HttpException('该文档作为知识库首页使用,无法删除', HttpStatus.FORBIDDEN); const isWikiExist = await this.wikiService.findById(document.wikiId);
if (isWikiExist) {
throw new HttpException('该文档作为知识库首页使用,无法删除', HttpStatus.FORBIDDEN);
}
} }
const children = await this.documentRepo.find({ const children = await this.documentRepo.find({
parentDocumentId: document.id, parentDocumentId: document.id,

View File

@ -458,9 +458,10 @@ export class WikiService {
if (user.id !== wiki.createUserId) { if (user.id !== wiki.createUserId) {
throw new HttpException('您不是创建者,无法删除该知识库', HttpStatus.FORBIDDEN); throw new HttpException('您不是创建者,无法删除该知识库', HttpStatus.FORBIDDEN);
} }
await this.wikiRepo.remove(wiki);
await this.documentService.deleteWikiDocuments(user, wikiId); await this.documentService.deleteWikiDocuments(user, wikiId);
const users = await this.wikiUserRepo.find({ wikiId }); const users = await this.wikiUserRepo.find({ wikiId });
await Promise.all([this.wikiRepo.remove(wiki), this.wikiUserRepo.remove(users)]); await Promise.all([this.wikiUserRepo.remove(users)]);
return wiki; return wiki;
} }