Created
December 29, 2018 17:43
-
-
Save supermacro/86287bd69d3459fe4b566deb149497d4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const fetchComments = async ({ | |
postId, | |
host | |
}: RequestInfo): Promise<Result<Array<Comments.Schema>, string>> => { | |
try { | |
const comments = await db(Comments.Table.name) | |
.select(everything(Comments.Table)) | |
.join( | |
Posts.Table.name, | |
`${Comments.Table.name}.${Comments.Table.cols.post_id}`, | |
`${Posts.Table.name}.${Posts.Table.cols.id}` | |
) | |
.join( | |
Sites.Table.name, | |
`${Posts.Table.name}.${Posts.Table.cols.site_id}`, | |
`${Sites.Table.name}.${Sites.Table.cols.id}` | |
) | |
.where( | |
`${Posts.Table.name}.${Posts.Table.cols.uuid}`, | |
postId | |
) | |
.andWhere( | |
`${Sites.Table.name}.${Sites.Table.cols.hostname}`, | |
host | |
) | |
return Result.ok(comments) | |
} catch (e) { | |
// TODO: log `e` | |
return Result.err('Error while retrieving comments') | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment