mirror of https://github.com/fantasticit/think.git
fix: fix get recent documents
This commit is contained in:
parent
1754841fa1
commit
c03d1ab00d
|
@ -2,7 +2,7 @@ import type { NextPage } from 'next';
|
||||||
import type { IDocument } from '@think/domains';
|
import type { IDocument } from '@think/domains';
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
import React, { useMemo } from 'react';
|
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 { useToggle } from 'hooks/use-toggle';
|
||||||
import { Seo } from 'components/seo';
|
import { Seo } from 'components/seo';
|
||||||
import { DataRender } from 'components/data-render';
|
import { DataRender } from 'components/data-render';
|
||||||
|
@ -37,6 +37,7 @@ const RecentDocs = () => {
|
||||||
title="标题"
|
title="标题"
|
||||||
dataIndex="title"
|
dataIndex="title"
|
||||||
key="title"
|
key="title"
|
||||||
|
width={200}
|
||||||
render={(_, document: IDocument) => {
|
render={(_, document: IDocument) => {
|
||||||
return (
|
return (
|
||||||
<Link href={'/wiki/[wikiId]/document/[docId]'} as={`/wiki/${document.wikiId}/document/${document.id}`}>
|
<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="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
|
<Column
|
||||||
title="更新时间"
|
title="更新时间"
|
||||||
dataIndex="updatedAt"
|
dataIndex="updatedAt"
|
||||||
|
|
|
@ -598,18 +598,20 @@ export class DocumentService {
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
public async getRecentDocuments(user: OutUser) {
|
public async getRecentDocuments(user: OutUser) {
|
||||||
const query = await this.documentRepo
|
const query = await this.documentAuthorityRepo
|
||||||
.createQueryBuilder('document')
|
.createQueryBuilder('documentAuth')
|
||||||
.where('document.createUserId=:createUserId')
|
.where('documentAuth.userId=:userId')
|
||||||
.andWhere('document.isWikiHome=:isWikiHome')
|
.andWhere('documentAuth.readable=:readable')
|
||||||
.setParameter('createUserId', user.id)
|
.setParameter('userId', user.id)
|
||||||
.setParameter('isWikiHome', 0);
|
.setParameter('readable', 1);
|
||||||
|
|
||||||
query.orderBy('document.updatedAt', 'DESC');
|
query.orderBy('documentAuth.updatedAt', 'DESC');
|
||||||
query.take(10);
|
|
||||||
const documents = await query.getMany();
|
|
||||||
|
|
||||||
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(
|
const res = await Promise.all(
|
||||||
docs.map(async (doc) => {
|
docs.map(async (doc) => {
|
||||||
|
|
Loading…
Reference in New Issue