fix: fix get recent documents

This commit is contained in:
fantasticit 2022-05-06 23:15:30 +08:00
parent 1754841fa1
commit c03d1ab00d
2 changed files with 29 additions and 11 deletions

View File

@ -2,7 +2,7 @@ import type { NextPage } from 'next';
import type { IDocument } from '@think/domains';
import Link from 'next/link';
import React, { useMemo } from 'react';
import { Typography, Button, Table, List } from '@douyinfe/semi-ui';
import { Typography, Button, Table, List, Avatar } from '@douyinfe/semi-ui';
import { useToggle } from 'hooks/use-toggle';
import { Seo } from 'components/seo';
import { DataRender } from 'components/data-render';
@ -37,6 +37,7 @@ const RecentDocs = () => {
title="标题"
dataIndex="title"
key="title"
width={200}
render={(_, document: IDocument) => {
return (
<Link href={'/wiki/[wikiId]/document/[docId]'} as={`/wiki/${document.wikiId}/document/${document.id}`}>
@ -46,6 +47,21 @@ const RecentDocs = () => {
}}
/>,
<Column title="阅读量" dataIndex="views" key="views" />,
<Column
title="创建者"
dataIndex="createUser"
key="createUser"
render={(createUser) => {
return (
<div>
<Avatar size="small" src={createUser.avatar} style={{ marginRight: 4 }}>
{createUser.name.slice(0, 1)}
</Avatar>
{createUser.name}
</div>
);
}}
/>,
<Column
title="更新时间"
dataIndex="updatedAt"

View File

@ -598,18 +598,20 @@ export class DocumentService {
* @returns
*/
public async getRecentDocuments(user: OutUser) {
const query = await this.documentRepo
.createQueryBuilder('document')
.where('document.createUserId=:createUserId')
.andWhere('document.isWikiHome=:isWikiHome')
.setParameter('createUserId', user.id)
.setParameter('isWikiHome', 0);
const query = await this.documentAuthorityRepo
.createQueryBuilder('documentAuth')
.where('documentAuth.userId=:userId')
.andWhere('documentAuth.readable=:readable')
.setParameter('userId', user.id)
.setParameter('readable', 1);
query.orderBy('document.updatedAt', 'DESC');
query.take(10);
const documents = await query.getMany();
query.orderBy('documentAuth.updatedAt', 'DESC');
const docs = documents.map((doc) => instanceToPlain(doc));
query.take(20);
const documentIds = await (await query.getMany()).map((docAuth) => docAuth.documentId);
const documents = await this.documentRepo.findByIds(documentIds, { order: { updatedAt: 'DESC' } });
const docs = documents.filter((doc) => !doc.isWikiHome).map((doc) => instanceToPlain(doc));
const res = await Promise.all(
docs.map(async (doc) => {