| 79 | } |
| 80 | |
| 81 | async fetchUser(id: string): Promise<UserModel | void> { |
| 82 | logger('Fetching user:', `${HN_API_URL}/user/${id}.json`); |
| 83 | |
| 84 | return get(child(this.db, `user/${id}`)) |
| 85 | .then((itemSnapshot) => { |
| 86 | const item = itemSnapshot.val(); |
| 87 | |
| 88 | if (item !== null && !item.deleted && !item.dead) { |
| 89 | const user = new UserModel({ |
| 90 | about: item.about, |
| 91 | creationTime: item.created * 1000, |
| 92 | id: item.id, |
| 93 | karma: item.karma, |
| 94 | posts: item.submitted, |
| 95 | }); |
| 96 | |
| 97 | this.cache.setUser(user.id, user); |
| 98 | logger('Created User:', item.id, item); |
| 99 | |
| 100 | return user; |
| 101 | } |
| 102 | |
| 103 | throw item; |
| 104 | }) |
| 105 | .catch((reason) => logger('Fetching user failed:', reason)); |
| 106 | } |
| 107 | |
| 108 | async getFeed(feedType: FeedType): Promise<number[] | void> { |
| 109 | logger('Fetching', `/${feedType}stories.json`); |