generated from lucien/api-template
44 lines
1.2 KiB
JavaScript
44 lines
1.2 KiB
JavaScript
const express = require('express');
|
|
const router = express.Router();
|
|
const { getConnection, getShareholders, getShareholder, getShareholderShares } = require("../libs/mysql.js")
|
|
|
|
router.get('/', async (req, res) => {
|
|
const connection = await getConnection()
|
|
const shareholders = await getShareholders(connection)
|
|
connection.end()
|
|
|
|
if (!shareholders[0]) {
|
|
return res.status(500).send({message: "There are no shareholders in the databse."})
|
|
}
|
|
|
|
return res.status(200).send(shareholders)
|
|
});
|
|
|
|
router.get('/:id', async (req, res) => {
|
|
const id = req.params.id
|
|
const connection = await getConnection()
|
|
const shareholder = await getShareholder(connection, id)
|
|
connection.end()
|
|
|
|
if (!shareholder[0]) {
|
|
return res.status(500).send({message: "There are no shareholder for this id."})
|
|
}
|
|
|
|
return res.status(200).send(shareholder[0])
|
|
});
|
|
|
|
router.get('/:id/shares', async (req, res) => {
|
|
const id = req.params.id
|
|
const connection = await getConnection()
|
|
const shares = await getShareholderShares(connection, id)
|
|
connection.end()
|
|
|
|
if (!shares[0]) {
|
|
return res.status(500).send({message: "There are no shares for that shareholder id."})
|
|
}
|
|
|
|
return res.status(200).send(shares)
|
|
});
|
|
|
|
module.exports = router;
|
|
|