mirror of https://github.com/fantasticit/think.git
fix: add isMember for wiki collector
parent
2a3bedcbfe
commit
232c2bb6fd
|
@ -1,21 +1,21 @@
|
||||||
import { IconUser } from '@douyinfe/semi-icons';
|
import { IconUser } from '@douyinfe/semi-icons';
|
||||||
import { Avatar, Skeleton, Space, Typography } from '@douyinfe/semi-ui';
|
import { Avatar, Skeleton, Space, Typography } from '@douyinfe/semi-ui';
|
||||||
import { IWiki } from '@think/domains';
|
|
||||||
import { IconDocument } from 'components/icons/IconDocument';
|
import { IconDocument } from 'components/icons/IconDocument';
|
||||||
import { LocaleTime } from 'components/locale-time';
|
import { LocaleTime } from 'components/locale-time';
|
||||||
import { WikiStar } from 'components/wiki/star';
|
import { WikiStar } from 'components/wiki/star';
|
||||||
|
import { IWikiWithIsMember } from 'data/wiki';
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
|
|
||||||
import styles from './index.module.scss';
|
import styles from './index.module.scss';
|
||||||
|
|
||||||
const { Text, Paragraph } = Typography;
|
const { Text, Paragraph } = Typography;
|
||||||
|
|
||||||
export const WikiCard: React.FC<{ wiki: IWiki; shareMode?: boolean }> = ({ wiki, shareMode = false }) => {
|
export const WikiCard: React.FC<{ wiki: IWikiWithIsMember; shareMode?: boolean }> = ({ wiki, shareMode = false }) => {
|
||||||
return (
|
return (
|
||||||
<div className={styles.cardWrap}>
|
<div className={styles.cardWrap}>
|
||||||
<Link
|
<Link
|
||||||
href={{
|
href={{
|
||||||
pathname: `${shareMode ? '/share' : ''}/wiki/[wikiId]`,
|
pathname: `${shareMode || !wiki.isMember ? '/share' : ''}/wiki/[wikiId]`,
|
||||||
query: { wikiId: wiki.id },
|
query: { wikiId: wiki.id },
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|
|
@ -9,6 +9,7 @@ export type IWikiUserOpeateData = {
|
||||||
userName: Pick<IUser, 'name'>;
|
userName: Pick<IUser, 'name'>;
|
||||||
userRole: Pick<IWikiUser, 'userRole'>;
|
userRole: Pick<IWikiUser, 'userRole'>;
|
||||||
};
|
};
|
||||||
|
export type IWikiWithIsMember = IWiki & { isMember: boolean };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取用户所有知识库
|
* 获取用户所有知识库
|
||||||
|
@ -239,7 +240,7 @@ export const useWikiStar = (wikiId) => {
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export const useStaredWikis = () => {
|
export const useStaredWikis = () => {
|
||||||
const { data, error, mutate } = useSWR<IWiki[]>('/collector/wikis', (url) => HttpClient.post(url), {
|
const { data, error, mutate } = useSWR<IWikiWithIsMember[]>('/collector/wikis', (url) => HttpClient.post(url), {
|
||||||
revalidateOnFocus: true,
|
revalidateOnFocus: true,
|
||||||
});
|
});
|
||||||
const loading = !data && !error;
|
const loading = !data && !error;
|
||||||
|
|
|
@ -50,7 +50,8 @@ export class CollectorService {
|
||||||
const withCreateUserRes = await Promise.all(
|
const withCreateUserRes = await Promise.all(
|
||||||
res.map(async (wiki) => {
|
res.map(async (wiki) => {
|
||||||
const createUser = await this.userService.findById(wiki.createUserId);
|
const createUser = await this.userService.findById(wiki.createUserId);
|
||||||
return { createUser, ...wiki };
|
const isMember = await this.wikiService.isMember(wiki.id, user.id);
|
||||||
|
return { createUser, isMember, ...wiki };
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -63,6 +63,17 @@ export class WikiService {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 目标用户是否为知识库成员
|
||||||
|
* @param wikiId
|
||||||
|
* @param userId
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
public async isMember(wikiId: string, userId: string) {
|
||||||
|
const auth = await this.wikiUserRepo.findOne({ wikiId, userId });
|
||||||
|
return !!auth && [WikiUserRole.admin, WikiUserRole.normal].includes(auth.userRole);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取知识库成员信息
|
* 获取知识库成员信息
|
||||||
* @param wikiId
|
* @param wikiId
|
||||||
|
|
Loading…
Reference in New Issue