| 51 | } |
| 52 | |
| 53 | async fetchComment(id: number): Promise<CommentModel | void> { |
| 54 | logger('Fetching comment:', `${HN_API_URL}/item/${id}.json`); |
| 55 | |
| 56 | return get(child(this.db, `item/${id}`)) |
| 57 | .then((itemSnapshot) => { |
| 58 | const item = itemSnapshot.val(); |
| 59 | |
| 60 | if (item !== null && !item.deleted && !item.dead) { |
| 61 | const comment = new CommentModel({ |
| 62 | comments: item.kids, |
| 63 | creationTime: item.time * 1000, |
| 64 | id: item.id, |
| 65 | parent: item.parent, |
| 66 | submitterId: item.by, |
| 67 | text: item.text, |
| 68 | }); |
| 69 | |
| 70 | this.cache.setComment(comment.id, comment); |
| 71 | logger('Created Comment:', item.id); |
| 72 | |
| 73 | return comment; |
| 74 | } |
| 75 | |
| 76 | throw item; |
| 77 | }) |
| 78 | .catch((reason) => logger('Fetching comment failed:', reason)); |
| 79 | } |
| 80 | |
| 81 | async fetchUser(id: string): Promise<UserModel | void> { |
| 82 | logger('Fetching user:', `${HN_API_URL}/user/${id}.json`); |