Skip to content

Commit

Permalink
get organisations from datasette
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeGoodall committed Aug 2, 2024
1 parent 6c75e2e commit d8b66fb
Showing 1 changed file with 22 additions and 75 deletions.
97 changes: 22 additions & 75 deletions src/controllers/OrganisationsController.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import datasette from '../services/datasette.js'
import performanceDbApi from '../services/performanceDbApi.js' // Assume you have an API service module
import logger from '../utils/logger.js'
import { dataSubjects } from '../utils/utils.js'
Expand Down Expand Up @@ -70,85 +71,31 @@ const organisationsController = {
}
},

/**
* Handles the GET /organisations request
*
* @param {Request} req
* @param {Response} res
* @param {NextFunction} next
*/
async getOrganisations (req, res, next) {
const alphabetisedOrgs = {
A: [
{
name: 'Aberdeen'
},
{
name: 'Aylesbury'
},
{
name: 'Ashford'
}
],
B: [
{
name: 'Bath'
},
{
name: 'Birmingham'
},
{
name: 'Brighton'
}
],
C: [
{
name: 'Cambridge'
},
{
name: 'Cardiff'
},
{
name: 'Cheltenham'
},
{
name: 'Chester'
}
],
D: [
{
name: 'Derby'
},
{
name: 'Dundee'
}
],
E: [
{
name: 'Edinburgh'
},
{
name: 'Epsom'
}
],
G: [
{
name: 'Glasgow'
},
{
name: 'Gloucester'
}
],
H: [
{
name: 'Hull'
}
],
L: [
{
name: 'Leeds'
},
{
name: 'London'
}
]
}
const sql = 'select name, organisation from organisation'
const result = await datasette.runQuery(sql)

const sortedResults = result.formattedData.sort((a, b) => {
return a.name.localeCompare(b.name)
})

const alphabetisedOrgs = sortedResults.reduce((acc, current) => {
const firstLetter = current.name.charAt(0).toUpperCase()
acc[firstLetter] = acc[firstLetter] || []
acc[firstLetter].push(current)
return acc
}, {})

res.render('organisations/find.html', { alphabetisedOrgs })
}

}

export default organisationsController

0 comments on commit d8b66fb

Please sign in to comment.