mirror of https://github.com/fantasticit/think.git
server: fix delete action
parent
1660db0678
commit
abea1fbd6f
|
@ -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),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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),
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue