generated from lucien/api-template
add: added some api endpoints
This commit is contained in:
parent
217c763abd
commit
736f097d20
4 changed files with 89 additions and 5 deletions
35
back/api/@me.js
Normal file
35
back/api/@me.js
Normal file
|
@ -0,0 +1,35 @@
|
|||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const { getConnection, getUserAccounts, getUserCards } = require('../libs/mysql');
|
||||
const { checkAuth } = require('../libs/middlewares');
|
||||
|
||||
router.post('/', checkAuth, async (req, res) => {
|
||||
const user = req.user;
|
||||
res.send({ id: user.id, name: user.name, lastname: user.lastname, admin: user.admin });
|
||||
});
|
||||
|
||||
router.post('/accounts', checkAuth, async (req, res) => {
|
||||
const user = req.user;
|
||||
const connection = await getConnection();
|
||||
const accounts = await getUserAccounts(connection, user.id);
|
||||
connection.end();
|
||||
|
||||
if (!accounts[0]) {
|
||||
return res.status(404).send({ error: 'No accounts found' });
|
||||
}
|
||||
res.send({ accounts: accounts });
|
||||
});
|
||||
|
||||
router.post('/cards', checkAuth, async (req, res) => {
|
||||
const user = req.user;
|
||||
const connection = await getConnection();
|
||||
const cards = await getUserCards(connection, user.id);
|
||||
connection.end();
|
||||
|
||||
if (!cards[0]) {
|
||||
return res.status(404).send({ error: 'No cards found' });
|
||||
}
|
||||
res.send({ cards: cards });
|
||||
});
|
||||
|
||||
module.exports = router;
|
Loading…
Add table
Add a link
Reference in a new issue