usuario casi listo

This commit is contained in:
2020-10-04 23:04:19 -05:00
parent c582c7da86
commit 3b5dca38d1
3 changed files with 76 additions and 28 deletions
+20 -18
View File
@@ -16,34 +16,36 @@ const create = async (body) => {
.validarTexto(body.apMaterno)
.then((res) => res)
let correo = await validador.validarEmail(body.email).then((res) => res)
let telefono = ''
let telefono = body.telefono
let idCarreraPlantel = await validador
.validarId(body.idCarreraPlantel)
.then((res) => res)
let idTipoUsuario = 1
return Usuario.findOne({ where: { idUsuario } }).then((res) => {
if (res) validador.error('El numero de cuanta ya a sido registrado.', 400)
let data = {
idUsuario,
password,
nombre,
apPaterno,
apMaterno,
correo,
telefono,
identificacion: '',
foto: '',
idTipoUsuario,
idCarreraPlantel,
}
return Usuario.create(data).then((res) => {
return Usuario.findOne({ where: { idUsuario } })
.then((res) => {
if (res) validador.error('El numero de cuanta ya a sido registrado.', 400)
let data = {
idUsuario,
password,
nombre,
apPaterno,
apMaterno,
correo,
telefono,
identificacion: '',
foto: '',
idTipoUsuario,
idCarreraPlantel,
}
return Usuario.create(data)
})
.then((res) => {
return {
code: 201,
message: 'Se registro correctamente el numero de cuenta',
}
})
})
}
module.exports = create
+53 -6
View File
@@ -1,12 +1,59 @@
const validador = require('../validador')
const Usuario = require('../../db/tables/Usuario')
const TipoUsuario = require('../../db/tables/TipoUsuario')
const CarreraPlantel = require('../../db/tables/CarreraPlantel')
const Carrera = require('../../db/tables/Carrera')
const Plantel = require('../../db/tables/Plantel')
const Prestamo = require('../../db/tables/Prestamo')
const get = async (body) => {
console.log(body)
return Usuario.findAll({ where: { idUsuario: body.idUsuario } })
.then((res) => {
return res
})
.catch((err) => {})
let idUsuario = await validador.validarId(body.idUsuario).then((res) => res)
let busqueda = {
where: { idUsuario },
include: [
{ model: TipoUsuario },
{
model: CarreraPlantel,
include: [{ model: Plantel }, { model: Carrera }],
},
],
}
return Usuario.findOne(busqueda).then((res) => {
if (!res) validador.error('No existe este número de cuenta.', 400)
return {
code: 200,
data: {
idUsuario: res.idUsuario,
nombre: res.nombre,
apPaterno: res.apPaterno,
apMaterno: res.apMaterno,
correo: res.correo,
telefono: res.telefono,
// identificacion:,
// foto: ,
baneado: res.baneado,
createdAt: res.createdAt,
updatedAt: res.updatedAt,
TipoUsuario: {
idTipoUsuario: res.TipoUsuario.idTipoUsuario,
nombre: res.TipoUsuario.nombre,
},
CarreraPlantel: {
idCarreraPlantel: res.CarreraPlantel.idCarreraPlantel,
Plantel: {
idPlantel: res.CarreraPlantel.Plantel.idPlantel,
plantel: res.CarreraPlantel.Plantel.plantel,
},
Carrera: {
idCarrera: res.CarreraPlantel.Carrera.idCarrera,
carrera: res.CarreraPlantel.Carrera.carrera,
nivel: res.CarreraPlantel.Carrera.nivel,
},
},
},
}
})
}
module.exports = get
+3 -4
View File
@@ -8,8 +8,7 @@ const route = '/usuario'
app.get(`${route}`, (req, res) => {
return get(req.query)
.then((data) => {
console.log(data)
res.status(data.code).json(data.data)
res.status(data.code).json({ usuario: data.data })
})
.catch((err) => res.status(err.code).json({ err: err.message }))
})
@@ -17,7 +16,7 @@ app.get(`${route}`, (req, res) => {
app.post(`${route}/create`, (req, res) => {
return create(req.body)
.then((data) => {
res.status(data.code).json(data.message)
res.status(data.code).json({ message: data.message })
})
.catch((err) => res.status(err.code).json({ err: err.message }))
})
@@ -25,7 +24,7 @@ app.post(`${route}/create`, (req, res) => {
app.post(`${route}/login`, (req, res) => {
return login(req.body)
.then((data) => {
res.status(data.code).json(data.data)
res.status(data.code).json({ usuario: data.data })
})
.catch((err) => res.status(err.code).json({ err: err.message }))
})