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;