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([ await Promise.all([
this.authService.deleteDocument(document.organizationId, document.wikiId, document.id), this.authService.deleteDocument(document.organizationId, document.wikiId, document.id),
this.documentRepo.remove(document), this.documentRepo.remove(document),
this.viewService.deleteDeletedDocumentView(user, document.organizationId, document.id),
]); ]);
} }

View File

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

View File

@ -1,6 +1,5 @@
import { RedisDBEnum } from '@constants/*'; import { RedisDBEnum } from '@constants/*';
import { DocumentEntity } from '@entities/document.entity'; import { DocumentEntity } from '@entities/document.entity';
import { UserEntity } from '@entities/user.entity';
import { buildRedis } from '@helpers/redis.helper'; import { buildRedis } from '@helpers/redis.helper';
import { Injectable } from '@nestjs/common'; import { Injectable } from '@nestjs/common';
import { IDocument, IOrganization, IUser } from '@think/domains'; import { IDocument, IOrganization, IUser } from '@think/domains';
@ -73,7 +72,7 @@ export class ViewService {
* @param user * @param user
* @param document * @param document
*/ */
private async recordUserVisitedDocumentInOrganization(user: UserEntity, document: DocumentEntity) { private async recordUserVisitedDocumentInOrganization(user: IUser, document: DocumentEntity) {
const { id: userId } = user; const { id: userId } = user;
const { organizationId, id: documentId } = document; const { organizationId, id: documentId } = document;
const key = this.buildVisitedDocumentInOrganizationKey(organizationId); 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 * @returns
*/ */
async create(user: UserEntity | null, document: DocumentEntity) { async create(user: IUser | null, document: DocumentEntity) {
await Promise.all([ await Promise.all([
this.recordDocumentViews(document.id), this.recordDocumentViews(document.id),
user && this.recordUserVisitedDocumentInOrganization(user, document), user && this.recordUserVisitedDocumentInOrganization(user, document),

View File

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