Commit 47aea8f4 by Denys Tito Urbano

Router auth agregado

parent dfa40f37
const service = require('../services/auth.service');
const { generate_jwt } = require('../helpers');
const post_login = async (req, res) => {
try {
const { email, password } = req.body;
const { json: user } = await service.post_login({ email, password });
if (!user) {
res.status(400).json({ message: 'Usuario / Contraseña incorrecta' });
}
const accessToken = await generate_jwt({ email, documento: user.documento });
res.json({ accessToken, user });
} catch (error) {
res.status(400).json({ error });
}
};
const get_account = async (req, res) => {
try {
const { documento } = req.params;
const { json: user } = await service.get_account({ documento });
res.json({ user });
} catch (error) {
res.status(400).json({ error });
}
};
module.exports = {
post_login,
get_account
};
\ No newline at end of file
const connection = require('./config');
const post_login = async ({ email, password }) => {
return await connection.oneOrNone('SELECT * FROM academico.func_tma_login ( $1, $2 );', [email, password]);
};
const get_account = async ({ documento }) => {
return await connection.oneOrNone('SELECT * FROM academico.func_tma_cuenta ( $1 );', [documento]);
};
module.exports = {
post_login,
get_account
};
\ No newline at end of file
const express = require('express');
const router = express.Router();
const { check } = require('express-validator');
const { post_login, get_account } = require('../controllers/auth.controller');
const { validate_errors, validate_jwt } = require('../middlewares');
router.post('/login',
check('email', 'Usuario inválido').not().isEmpty(),
check('password', 'Contraseña inválida').not().isEmpty(),
validate_errors,
post_login);
router.get('/account',
validate_jwt,
get_account);
module.exports = router;
\ No newline at end of file
......@@ -12,6 +12,7 @@ class Server {
}
routes() {
this.app.use('/api/auth', require('./routes/auth.router'));
}
middlewares() {
......
const db = require('../db/auth.db');
const post_login = async (input) => {
return await db.post_login(input);
};
const get_account = async (input) => {
return await db.get_account(input);
};
module.exports = {
post_login,
get_account
};
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment