mirror of https://github.com/fantasticit/think.git
server: fix get recent documents
This commit is contained in:
parent
c8f37fecf9
commit
9257e683da
|
@ -592,24 +592,14 @@ export class DocumentService {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取用户最近更新的10篇文档
|
* 获取用户最近访问的10篇文档
|
||||||
* @param user
|
* @param user
|
||||||
* @param dto
|
* @param dto
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
public async getRecentDocuments(user: OutUser) {
|
public async getRecentDocuments(user: OutUser) {
|
||||||
const query = await this.documentAuthorityRepo
|
const documentIds = await this.viewService.getUserRecentVisitedDocuments(user.id);
|
||||||
.createQueryBuilder('documentAuth')
|
|
||||||
.where('documentAuth.userId=:userId')
|
|
||||||
.andWhere('documentAuth.readable=:readable')
|
|
||||||
.setParameter('userId', user.id)
|
|
||||||
.setParameter('readable', 1);
|
|
||||||
|
|
||||||
query.orderBy('documentAuth.updatedAt', 'DESC');
|
|
||||||
|
|
||||||
query.take(20);
|
|
||||||
|
|
||||||
const documentIds = await (await query.getMany()).map((docAuth) => docAuth.documentId);
|
|
||||||
const documents = await this.documentRepo.findByIds(documentIds, { order: { updatedAt: 'DESC' } });
|
const documents = await this.documentRepo.findByIds(documentIds, { order: { updatedAt: 'DESC' } });
|
||||||
const docs = documents.filter((doc) => !doc.isWikiHome).map((doc) => instanceToPlain(doc));
|
const docs = documents.filter((doc) => !doc.isWikiHome).map((doc) => instanceToPlain(doc));
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { ViewEntity } from '@entities/view.entity';
|
||||||
import { parseUserAgent } from '@helpers/ua.helper';
|
import { parseUserAgent } from '@helpers/ua.helper';
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { InjectRepository } from '@nestjs/typeorm';
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
import { IPagination } from '@think/domains';
|
import { IDocument, IPagination, IUser } from '@think/domains';
|
||||||
import { Repository } from 'typeorm';
|
import { Repository } from 'typeorm';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
|
@ -54,4 +54,12 @@ export class ViewService {
|
||||||
|
|
||||||
return { data, total };
|
return { data, total };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getUserRecentVisitedDocuments(userId: IUser['id']): Promise<Array<IDocument['id']>> {
|
||||||
|
const [ret] = await this.viewRepo.findAndCount({
|
||||||
|
where: { userId },
|
||||||
|
take: 20,
|
||||||
|
});
|
||||||
|
return ret.map((item) => item.documentId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue