diff --git a/packages/client/src/components/wiki/card/index.tsx b/packages/client/src/components/wiki/card/index.tsx
index 270dd81..0daece6 100644
--- a/packages/client/src/components/wiki/card/index.tsx
+++ b/packages/client/src/components/wiki/card/index.tsx
@@ -1,21 +1,21 @@
import { IconUser } from '@douyinfe/semi-icons';
import { Avatar, Skeleton, Space, Typography } from '@douyinfe/semi-ui';
-import { IWiki } from '@think/domains';
import { IconDocument } from 'components/icons/IconDocument';
import { LocaleTime } from 'components/locale-time';
import { WikiStar } from 'components/wiki/star';
+import { IWikiWithIsMember } from 'data/wiki';
import Link from 'next/link';
import styles from './index.module.scss';
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 (
diff --git a/packages/client/src/data/wiki.tsx b/packages/client/src/data/wiki.tsx
index 7d6e8c9..9c8bcf5 100644
--- a/packages/client/src/data/wiki.tsx
+++ b/packages/client/src/data/wiki.tsx
@@ -9,6 +9,7 @@ export type IWikiUserOpeateData = {
userName: Pick;
userRole: Pick;
};
+export type IWikiWithIsMember = IWiki & { isMember: boolean };
/**
* 获取用户所有知识库
@@ -239,7 +240,7 @@ export const useWikiStar = (wikiId) => {
* @returns
*/
export const useStaredWikis = () => {
- const { data, error, mutate } = useSWR('/collector/wikis', (url) => HttpClient.post(url), {
+ const { data, error, mutate } = useSWR('/collector/wikis', (url) => HttpClient.post(url), {
revalidateOnFocus: true,
});
const loading = !data && !error;
diff --git a/packages/server/src/services/collector.service.ts b/packages/server/src/services/collector.service.ts
index 5e64e2b..c845fee 100644
--- a/packages/server/src/services/collector.service.ts
+++ b/packages/server/src/services/collector.service.ts
@@ -50,7 +50,8 @@ export class CollectorService {
const withCreateUserRes = await Promise.all(
res.map(async (wiki) => {
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 };
})
);
diff --git a/packages/server/src/services/wiki.service.ts b/packages/server/src/services/wiki.service.ts
index 9d28399..f5841d8 100644
--- a/packages/server/src/services/wiki.service.ts
+++ b/packages/server/src/services/wiki.service.ts
@@ -63,6 +63,17 @@ export class WikiService {
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