Created
February 27, 2019 02:10
-
-
Save camwhite/48089f65f3731bb51b6832649b8fb571 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| async show (id) { | |
| const [ shown ] = await this.knex | |
| .select( | |
| 'items.id', | |
| 'items.title', | |
| 'items.fulfilled', | |
| 'items.description', | |
| 'items.image', | |
| 'items.url', | |
| 'items.updated_at', | |
| 'lists_items.list_id', | |
| this.knex.raw(`json_build_object('id', users.id, 'handle', users.handle, 'full_name', users.full_name) as user`), | |
| this.knex.raw(`json_build_object('id', u.id, 'handle', u.handle, 'full_name', u.full_name) as fulfiller`) | |
| ) | |
| .from('items') | |
| .innerJoin('lists_items', 'lists_items.item_id', '=', 'items.id') | |
| .innerJoin('lists', 'lists.id', '=', 'lists_items.list_id') | |
| .innerJoin('users', 'lists.user_id', '=', 'users.id') | |
| .leftJoin('users as u', 'items.fulfiller_id', '=', 'u.id') | |
| .where('items.id', id) | |
| .groupBy('items.id', 'users.id', 'u.id', 'lists_items.list_id') | |
| return shown | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment