Skip to content

Instantly share code, notes, and snippets.

@supermacro
Created December 29, 2018 17:43
Show Gist options
  • Save supermacro/86287bd69d3459fe4b566deb149497d4 to your computer and use it in GitHub Desktop.
Save supermacro/86287bd69d3459fe4b566deb149497d4 to your computer and use it in GitHub Desktop.
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