fix: fix create document index

This commit is contained in:
fantasticit 2022-03-12 17:14:59 +08:00
parent 40b5cb0c0b
commit f99d766e15
1 changed files with 7 additions and 0 deletions

View File

@ -313,11 +313,16 @@ export class DocumentService {
userId: user.id, userId: user.id,
}); });
const query = this.documentRepo.createQueryBuilder('documemt');
query.select('MAX(documemt.index)', 'maxIndex');
const { maxIndex } = await query.getRawOne();
const data = { const data = {
...dto, ...dto,
createUserId: user.id, createUserId: user.id,
isWikiHome, isWikiHome,
title: '未命名文档', title: '未命名文档',
index: maxIndex + 1,
// content: '', // content: '',
// state: Buffer.from(new Uint8Array()), // state: Buffer.from(new Uint8Array()),
...DOCUMENT_PLACEHOLDERS[0], ...DOCUMENT_PLACEHOLDERS[0],
@ -710,6 +715,7 @@ export class DocumentService {
* @returns * @returns
*/ */
public async getWikiTocs(user: OutUser, wikiId: string) { public async getWikiTocs(user: OutUser, wikiId: string) {
const ONE_DAY_TIME = 24 * 60 * 60 * 1000;
await this.wikiService.getWikiDetail(user, wikiId); await this.wikiService.getWikiDetail(user, wikiId);
// @ts-ignore // @ts-ignore
const records = await this.documentAuthorityRepo.find({ const records = await this.documentAuthorityRepo.find({
@ -722,6 +728,7 @@ export class DocumentService {
order: { createdAt: 'ASC' }, order: { createdAt: 'ASC' },
}); });
documents.sort((a, b) => a.index - b.index); documents.sort((a, b) => a.index - b.index);
documents.forEach((doc) => { documents.forEach((doc) => {
delete doc.state; delete doc.state;
}); });