mirror of https://github.com/fantasticit/think.git
Merge pull request #149 from fantasticit/fix/delete
This commit is contained in:
commit
f2b5692643
|
@ -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),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue