Skip to content

Commit

Permalink
feat(backend): add endpoint for fetching writers from database
Browse files Browse the repository at this point in the history
  • Loading branch information
Harjot1Singh committed Feb 21, 2020
1 parent 567c47e commit 27c36d5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 4 additions & 1 deletion app/lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { readJSON } from 'fs-extra'

import { CUSTOM_THEMES_FOLDER, APP_FOLDER, FRONTEND_THEMES_FOLDER, DATABASE_FOLDER, CUSTOM_OVERLAY_THEMES_FOLDER, FRONTEND_OVERLAY_THEMES_FOLDER } from './consts'
import { listCSSFiles, getNetworkedAddresses } from './utils'
import { getSources, getLanguages } from './db'
import { getSources, getLanguages, getWriters } from './db'

const api = Router()

Expand Down Expand Up @@ -42,4 +42,7 @@ api.get( '/sources', ( _, res ) => getSources().then( sources => res.json( sourc
// Gurbani Sources, with possible translations
api.get( '/languages', ( _, res ) => getLanguages().then( languages => res.json( { languages } ) ) )

// Writers/authors
api.get( '/writers', ( _, res ) => getWriters().then( writers => res.json( { writers } ) ) )

export default api
6 changes: 4 additions & 2 deletions app/lib/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* @ignore
*/

import { groupBy, last } from 'lodash'
import { Lines, Shabads, Banis, Sources, Languages } from '@shabados/database'
import { groupBy, last, keyBy } from 'lodash'
import { Lines, Shabads, Banis, Sources, Languages, Writers } from '@shabados/database'

import { MAX_RESULTS } from './consts'

Expand Down Expand Up @@ -120,6 +120,8 @@ export const getSources = () => Sources
*/
export const getLanguages = () => Languages.query()

export const getWriters = async () => keyBy( await Writers.query(), 'id' )

/**
* Gets the range of the order IDs of all lines.
*/
Expand Down

0 comments on commit 27c36d5

Please sign in to comment.