Created two API endpoints.

This commit is contained in:
Lukian 2024-12-11 13:00:19 +01:00
parent 00e78c2dff
commit 8a61aaa68f
8 changed files with 854 additions and 203 deletions

View file

@ -1,16 +1,8 @@
const express = require('express');
const cookieParser = require('cookie-parser');
const cors = require('cors');
const jwt = require('jsonwebtoken');
const router = express.Router();
router.use(express.json());
router.use(cookieParser());
router.use(cors());
router.get('/', (req, res) => {
res.send('Hello World!');
});
module.exports = router;
module.exports = router;

18
api/shareholders.js Normal file
View file

@ -0,0 +1,18 @@
const express = require('express');
const router = express.Router();
const { getConnection, getShareholders } = 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)
});
module.exports = router;

17
api/shares.js Normal file
View file

@ -0,0 +1,17 @@
const express = require('express');
const router = express.Router();
const { getConnection, getShares } = require("../libs/mysql.js")
router.get('/', async (req, res) => {
const connection = await getConnection()
const shares = await getShares(connection)
connection.end()
if (!shares[0]) {
return res.status(500).send({message: "There are no shares in the databse."})
}
return res.status(200).send(shares)
});
module.exports = router;