Skip to content

Commit 0ee1b4e

Browse files
committed
feat: check trust user
1 parent b4390b8 commit 0ee1b4e

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/graphql/user.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export const typeDef = gql`
2424
series_list: [Series]
2525
user_meta: UserMeta
2626
is_followed: Boolean
27+
is_trusted: Boolean
2728
}
2829
type UserProfile {
2930
id: ID!
@@ -122,6 +123,10 @@ export const resolvers: IResolvers<any, ApolloContext> = {
122123
if (!ctx.user_id) return false;
123124
return await userService.isFollowed(parent.id, ctx.user_id);
124125
},
126+
is_trusted: async (parent: User, _, ctx) => {
127+
if (!parent.id) return false;
128+
return await userService.checkTrust(parent.id);
129+
},
125130
},
126131
Query: {
127132
user: async (parent: any, { id, username }: any) => {

src/services/userService.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import Cookies from 'cookies';
1111
import Axios, { AxiosError, AxiosResponse } from 'axios';
1212
import postService from './postService';
1313
import { getEndpoint } from '../lib/getEndpoint';
14+
import { differenceInDays } from 'date-fns';
1415

1516
const { API_V3_HOST, CLIENT_V2_HOST } = process.env;
1617

@@ -222,6 +223,23 @@ const userService = {
222223
async isFollowed(followingUserId: string, signedUserId: string): Promise<boolean> {
223224
return !!(await this.findFollowRelationship(followingUserId, signedUserId));
224225
},
226+
async checkTrust(userId: string): Promise<boolean> {
227+
const user = await db.user.findUnique({
228+
where: {
229+
id: userId,
230+
},
231+
});
232+
233+
if (!user) {
234+
throw new ApolloError('User not found', 'NOT_FOUND');
235+
}
236+
237+
const joinDay = new Date(user.created_at);
238+
const today = new Date();
239+
240+
const diffDays = differenceInDays(today, joinDay);
241+
return diffDays > 20;
242+
},
225243
};
226244

227245
export default userService;

0 commit comments

Comments
 (0)