added endpoints

This commit is contained in:
Lukian 2024-12-18 09:39:20 +01:00
parent 8a61aaa68f
commit 7d0406ef6e
6 changed files with 314 additions and 2 deletions

View file

@ -1,6 +1,6 @@
const express = require('express');
const router = express.Router();
const { getConnection, getShareholders } = require("../libs/mysql.js")
const { getConnection, getShareholders, getShareholder, getShareholderShares } = require("../libs/mysql.js")
router.get('/', async (req, res) => {
const connection = await getConnection()
@ -14,5 +14,31 @@ router.get('/', async (req, res) => {
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;