File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed
Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff 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 ) => {
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import Cookies from 'cookies';
1111import Axios , { AxiosError , AxiosResponse } from 'axios' ;
1212import postService from './postService' ;
1313import { getEndpoint } from '../lib/getEndpoint' ;
14+ import { differenceInDays } from 'date-fns' ;
1415
1516const { 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
227245export default userService ;
You can’t perform that action at this time.
0 commit comments