Skip to content

Instantly share code, notes, and snippets.

@denisidoro
Last active January 6, 2019 11:54
server.addRoute("/customers/:id/companies", middlewares, ::customerCompaniesHandler)
fun customerCompaniesHandler(req: Request, res: Response) {
val db = req.components.db
val customerId = req.params.id;
res.send(getCustomerCompanies(customerId, db)
}
fun getCustomerCompanies(customerId: Int, db: Database): List<Company> {
val stocks = getStocks(customerId, db)
val companyIds = stocks.map { it.companyId }
return companyIds.map { getCompanyById(it, db) }
}
fun getCompanyById(companyId: Int, db: Database) =
CompanyStore.Db.Queries.companyById(id, db)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment