server: fix delete action

This commit is contained in:
fantasticit 2022-08-06 23:55:25 +08:00
parent 1660db0678
commit abea1fbd6f
4 changed files with 28 additions and 13 deletions

View File

@ -390,6 +390,7 @@ export class DocumentService {
await Promise.all([
this.authService.deleteDocument(document.organizationId, document.wikiId, document.id),
this.documentRepo.remove(document),
this.viewService.deleteDeletedDocumentView(user, document.organizationId, document.id),
]);
}

View File

@ -106,11 +106,9 @@ export class OrganizationService {
wikiId: null,
documentId: null,
});
await Promise.all([
this.authService.deleteOrganization(organization.id),
this.organizationRepo.remove(organization),
this.wikiService.deleteOrganizationWiki(user, organizationId),
]);
await this.wikiService.deleteOrganizationWiki(user, organizationId);
await this.organizationRepo.remove(organization);
await this.authService.deleteOrganization(organization.id);
return organization;
}

View File

@ -1,6 +1,5 @@
import { RedisDBEnum } from '@constants/*';
import { DocumentEntity } from '@entities/document.entity';
import { UserEntity } from '@entities/user.entity';
import { buildRedis } from '@helpers/redis.helper';
import { Injectable } from '@nestjs/common';
import { IDocument, IOrganization, IUser } from '@think/domains';
@ -73,7 +72,7 @@ export class ViewService {
* @param user
* @param document
*/
private async recordUserVisitedDocumentInOrganization(user: UserEntity, document: DocumentEntity) {
private async recordUserVisitedDocumentInOrganization(user: IUser, document: DocumentEntity) {
const { id: userId } = user;
const { organizationId, id: documentId } = document;
const key = this.buildVisitedDocumentInOrganizationKey(organizationId);
@ -113,11 +112,30 @@ export class ViewService {
}
}
/**
* 访
* @param user
* @param organizationId
* @param documentId
*/
public async deleteDeletedDocumentView(
user: IUser,
organizationId: IOrganization['id'],
documentId: IDocument['id']
) {
const { id: userId } = user;
const key = this.buildVisitedDocumentInOrganizationKey(organizationId);
const oldData = await this.redis.hget(key, userId);
const filterData = (JSON.parse(oldData || '[]') || []).filter((record) => record.documentId !== documentId);
await this.redis.hset(key, userId, JSON.stringify(filterData));
}
/**
* 访
* @returns
*/
async create(user: UserEntity | null, document: DocumentEntity) {
async create(user: IUser | null, document: DocumentEntity) {
await Promise.all([
this.recordDocumentViews(document.id),
user && this.recordUserVisitedDocumentInOrganization(user, document),

View File

@ -483,11 +483,9 @@ export class WikiService {
wikiId: wiki.id,
documentId: null,
});
await Promise.all([
this.authService.deleteWiki(wiki.organizationId, wiki.id),
this.wikiRepo.remove(wiki),
this.documentService.deleteWikiDocuments(user, wikiId),
]);
await this.wikiRepo.remove(wiki);
await this.documentService.deleteWikiDocuments(user, wikiId);
await this.authService.deleteWiki(wiki.organizationId, wiki.id);
return wiki;
}