File tree Expand file tree Collapse file tree 5 files changed +278
-133
lines changed Expand file tree Collapse file tree 5 files changed +278
-133
lines changed Original file line number Diff line number Diff line change @@ -73,6 +73,34 @@ export function fetchComment(id) {
73
73
. catch ( reason => logger ( `Fetching comment failed: ${ reason } ` ) ) ;
74
74
}
75
75
76
+ export function fetchUser ( id ) {
77
+ logger ( `Fetching user ${ HN_API_URL } /user/${ id } .json` ) ;
78
+ return api . child ( `user/${ id } ` ) . once ( 'value' )
79
+ . then ( ( itemSnapshot ) => {
80
+ const item = itemSnapshot . val ( ) ;
81
+ if ( item !== null && ! item . deleted && ! item . dead ) {
82
+ const user = {
83
+ id : item . id ,
84
+ about : item . about ,
85
+ creationTime : item . created * 1000 ,
86
+ dateOfBirth : null ,
87
+ email : null ,
88
+ firstName : null ,
89
+ hidden : [ ] ,
90
+ karma : item . karma ,
91
+ lastName : null ,
92
+ likes : [ ] ,
93
+ posts : item . submitted ,
94
+ } ;
95
+ cache . setUser ( user . id , user ) ;
96
+ logger ( `Created User: ${ item . id } ` , item ) ;
97
+ return user ;
98
+ }
99
+ throw item ;
100
+ } )
101
+ . catch ( reason => logger ( `Fetching user failed: ${ reason } ` ) ) ;
102
+ }
103
+
76
104
export function getFeed ( feedType ) {
77
105
logger ( `Fetching /${ feedType } stories.json` ) ;
78
106
return api . child ( `${ feedType } stories` ) . once ( 'value' )
Original file line number Diff line number Diff line change @@ -631,6 +631,7 @@ export default {
631
631
{
632
632
// id: 1, // username is Primary Key
633
633
id : 'clintonwoo' , // Aka. username
634
+ about : 'I am a software engineer who lives in New York.' ,
634
635
creationTime : 1506024614000 ,
635
636
dateOfBirth : 723618000000 ,
636
637
@@ -642,6 +643,7 @@ export default {
642
643
} ,
643
644
{
644
645
id : 'john' , // Aka. username
646
+ about : 'Just a bloke' ,
645
647
creationTime : 1506024554000 ,
646
648
dateOfBirth : 554875200000 ,
647
649
Original file line number Diff line number Diff line change @@ -100,6 +100,8 @@ const typeDefs = `
100
100
# The user ID is a string of the username
101
101
id: String!
102
102
103
+ about: String
104
+
103
105
creationTime: Date!
104
106
105
107
dateOfBirth: Date
Original file line number Diff line number Diff line change 1
1
import * as DB from '../Database' ;
2
+ import * as HNDB from '../HNDataAPI' ;
2
3
import cache from '../Cache' ;
3
4
4
5
export default class User {
5
6
static getUser ( id ) {
6
- return cache . getUser ( id ) || DB . getUser ( id ) ;
7
+ return cache . getUser ( id ) || HNDB . fetchUser ( id ) ;
7
8
}
8
9
static getPostsForUser ( id ) {
9
10
return DB . getNewsItems ( )
You can’t perform that action at this time.
0 commit comments