File tree 2 files changed +23
-0
lines changed 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`
24
24
series_list: [Series]
25
25
user_meta: UserMeta
26
26
is_followed: Boolean
27
+ is_trusted: Boolean
27
28
}
28
29
type UserProfile {
29
30
id: ID!
@@ -122,6 +123,10 @@ export const resolvers: IResolvers<any, ApolloContext> = {
122
123
if ( ! ctx . user_id ) return false ;
123
124
return await userService . isFollowed ( parent . id , ctx . user_id ) ;
124
125
} ,
126
+ is_trusted : async ( parent : User , _ , ctx ) => {
127
+ if ( ! parent . id ) return false ;
128
+ return await userService . checkTrust ( parent . id ) ;
129
+ } ,
125
130
} ,
126
131
Query : {
127
132
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';
11
11
import Axios , { AxiosError , AxiosResponse } from 'axios' ;
12
12
import postService from './postService' ;
13
13
import { getEndpoint } from '../lib/getEndpoint' ;
14
+ import { differenceInDays } from 'date-fns' ;
14
15
15
16
const { API_V3_HOST , CLIENT_V2_HOST } = process . env ;
16
17
@@ -222,6 +223,23 @@ const userService = {
222
223
async isFollowed ( followingUserId : string , signedUserId : string ) : Promise < boolean > {
223
224
return ! ! ( await this . findFollowRelationship ( followingUserId , signedUserId ) ) ;
224
225
} ,
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
+ } ,
225
243
} ;
226
244
227
245
export default userService ;
You can’t perform that action at this time.
0 commit comments