nuevas dependencias
This commit is contained in:
@@ -1,47 +0,0 @@
|
||||
import { createConnection, getRepository } from 'typeorm'
|
||||
import { Horario } from './entity/Horario'
|
||||
import { Mesa } from './entity/Mesa'
|
||||
import { TipoUsuario } from './entity/TipoUsuario'
|
||||
import { Sala } from './entity/Sala'
|
||||
|
||||
createConnection()
|
||||
.then(async (connection) => {
|
||||
const horarioRepository = getRepository(Horario)
|
||||
const mesaRepository = getRepository(Mesa)
|
||||
const tipoUsuarioRepository = getRepository(TipoUsuario)
|
||||
const salaRepository = getRepository(Sala)
|
||||
const horarios = [
|
||||
'8:00-10:00',
|
||||
'10:00-12:00',
|
||||
'12:00-14:00',
|
||||
'14:00-16:00',
|
||||
'16:00-18:00',
|
||||
'18:00-20:00'
|
||||
]
|
||||
for (let index = 0; index < horarios.length; index++) {
|
||||
const horario = new Horario()
|
||||
horario.hora = horarios[index]
|
||||
console.log(horario)
|
||||
await horarioRepository.save(horario)
|
||||
}
|
||||
for (let i = 1; i < 30; i++) {
|
||||
const mesa = new Mesa()
|
||||
mesa.nombre = String(i)
|
||||
await mesaRepository.save(mesa)
|
||||
}
|
||||
for (let i = 1; i < 30; i++) {
|
||||
const sala = new Sala()
|
||||
sala.nombre = String(i)
|
||||
await salaRepository.save(sala)
|
||||
}
|
||||
const tipos = ['alumno_interno', 'alumno_externo', 'profesor_interno']
|
||||
for (let index = 0; index < tipos.length; index++) {
|
||||
const tipoUsuario = new TipoUsuario()
|
||||
tipoUsuario.nombre = tipos[index]
|
||||
console.log(tipoUsuario)
|
||||
await tipoUsuarioRepository.save(tipoUsuario)
|
||||
}
|
||||
|
||||
process.exit()
|
||||
})
|
||||
.catch((error) => console.log('TypeORM connection error: ', error))
|
||||
@@ -1,8 +0,0 @@
|
||||
import { createConnection, getRepository } from 'typeorm'
|
||||
import { Configuracion } from './entity/Configuracion'
|
||||
|
||||
createConnection()
|
||||
.then(async (connection) => {
|
||||
console.log('base de datos configurada')
|
||||
})
|
||||
.catch((error) => console.log('TypeORM connection error: ', error))
|
||||
@@ -1,8 +0,0 @@
|
||||
import * as jwt from 'jsonwebtoken'
|
||||
export class AuthController {
|
||||
static async signUsuario (type: string, usuarioId: string) {
|
||||
const secret = 'Holabeb'
|
||||
const token = jwt.sign({ type, usuarioId }, secret, { expiresIn: '1h' })
|
||||
return token
|
||||
}
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
import { Request, Response } from 'express'
|
||||
import * as Papa from 'papaparse'
|
||||
import * as fs from 'fs'
|
||||
import { Carrito } from '@src/entity/Carrito'
|
||||
import { getRepository } from 'typeorm'
|
||||
import { Tipo } from '@src/entity/Tipo'
|
||||
import { Equipo } from '@src/entity/Equipo'
|
||||
export class CarritoController {
|
||||
public async carga (req: Request, res: Response) {
|
||||
const cargaFile = req.file
|
||||
if (!cargaFile) {
|
||||
res.status(400).send({
|
||||
status: false,
|
||||
data: 'No file is selected.'
|
||||
})
|
||||
return false
|
||||
}
|
||||
const fileReadResult = fs.readFileSync(cargaFile.path, 'utf-8')
|
||||
const parseResult = await Papa.parse(fileReadResult, {
|
||||
header: true
|
||||
})
|
||||
console.log(parseResult)
|
||||
let data: any = {}
|
||||
try {
|
||||
for (const i in parseResult.data) {
|
||||
data = parseResult.data[i]
|
||||
if (
|
||||
!data.kiosko ||
|
||||
!data.alias_carrito ||
|
||||
!data.no_serie ||
|
||||
!data.no_inventario
|
||||
) {
|
||||
continue
|
||||
}
|
||||
console.log(data)
|
||||
await this.saveCarrito(data)
|
||||
}
|
||||
} catch (err) {
|
||||
res.status(400).send(err.message)
|
||||
return
|
||||
}
|
||||
res.status(200).send('okay')
|
||||
}
|
||||
|
||||
private async saveCarrito (data: any) {
|
||||
// console.log(data)
|
||||
const carritoRepository = getRepository(Carrito)
|
||||
const tipoRepository = getRepository(Tipo)
|
||||
const equipoRepository = getRepository(Equipo)
|
||||
|
||||
const tipo = new Tipo()
|
||||
const carrito = new Carrito()
|
||||
const equipo = new Equipo()
|
||||
|
||||
const tipoFind = await tipoRepository.findOne({
|
||||
where: {
|
||||
nombre: data.tipo
|
||||
}
|
||||
})
|
||||
if (!tipoFind) {
|
||||
tipo.nombre = data.tipo
|
||||
}
|
||||
const carritoFind = await carritoRepository.findOne({
|
||||
where: {
|
||||
kiosko: data.kiosko,
|
||||
alias: data.alias_carrito,
|
||||
tipo: tipoFind
|
||||
}
|
||||
})
|
||||
|
||||
if (!carritoFind) {
|
||||
carrito.kiosko = data.kiosko
|
||||
carrito.alias = data.alias_carrito
|
||||
carrito.tipo = !tipoFind ? tipo : tipoFind
|
||||
}
|
||||
|
||||
equipo.alias = data.equipo_carrito
|
||||
equipo.noSerie = data.no_serie
|
||||
equipo.noInventario = data.no_inventario
|
||||
equipo.carrito = !carritoFind ? carrito : carritoFind
|
||||
if (!tipoFind) await tipoRepository.save(tipo)
|
||||
if (!carritoFind) await carritoRepository.save(carrito)
|
||||
await equipoRepository.save(equipo)
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
import { Request, Response } from 'express'
|
||||
import { getRepository } from 'typeorm'
|
||||
import { Horario } from '@src/entity/Horario'
|
||||
|
||||
export class HorarioController {
|
||||
static async getAll (req: Request, res: Response) {
|
||||
const repository = getRepository(Horario)
|
||||
const horarios = await repository.find()
|
||||
res.status(200).json(horarios)
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
import { Operador } from '@src/entity/Operador'
|
||||
import { Request, Response } from 'express'
|
||||
import { validate } from 'class-validator'
|
||||
import { getRepository } from 'typeorm'
|
||||
|
||||
export class OperadorController {
|
||||
static async create (req: Request, res: Response) {
|
||||
const { usuario, secreto, admin } = req.body
|
||||
|
||||
const operador = new Operador()
|
||||
|
||||
operador.usuario = usuario
|
||||
operador.secreto = secreto
|
||||
operador.admin = admin
|
||||
|
||||
const errors = await validate(operador)
|
||||
if (errors.length > 0) {
|
||||
res.status(400).send(errors)
|
||||
}
|
||||
|
||||
operador.hashPassword()
|
||||
|
||||
const repository = getRepository(Operador)
|
||||
try {
|
||||
await repository.save(operador)
|
||||
} catch (e) {
|
||||
res.status(409).send('username already in use')
|
||||
}
|
||||
res.status(201).send('User created')
|
||||
}
|
||||
|
||||
static async getAll (req: Request, res: Response) {
|
||||
const repository = getRepository(Operador)
|
||||
const result = await repository.find({
|
||||
select: ['id', 'usuario', 'admin']
|
||||
})
|
||||
res.status(200).json(result)
|
||||
}
|
||||
|
||||
static async getOne (req: Request, res: Response) {
|
||||
const id: number = +req.params.id
|
||||
const repository = getRepository(Operador)
|
||||
try {
|
||||
const operador = await repository.findOneOrFail(id, {
|
||||
select: ['id', 'usuario', 'admin']
|
||||
})
|
||||
res.status(200).json(operador)
|
||||
} catch (e) {
|
||||
res.status(404).send('User not found')
|
||||
}
|
||||
}
|
||||
|
||||
static async remove (req: Request, res: Response) {
|
||||
const id = +req.params.id
|
||||
const repository = getRepository(Operador)
|
||||
try {
|
||||
const operador = await repository.findOneOrFail(id)
|
||||
repository.remove(operador)
|
||||
res.status(204).send()
|
||||
} catch (error) {
|
||||
res.status(404).send('User not found')
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,191 +0,0 @@
|
||||
import { Request, Response } from 'express'
|
||||
import { getRepository } from 'typeorm'
|
||||
import { Equipo } from '@src/entity/Equipo'
|
||||
import { Prestamo } from '@src/entity/Prestamo'
|
||||
import { Usuario } from '@src/entity/Usuario'
|
||||
import { Operador } from '@src/entity/Operador'
|
||||
import * as moment from 'moment'
|
||||
import { Mesa } from '@src/entity/Mesa'
|
||||
export class PrestamoController {
|
||||
static async crear (request: Request, res: Response) {
|
||||
const usuarioRepository = await getRepository(Usuario)
|
||||
const equipoRepository = await getRepository(Equipo)
|
||||
const prestamoRepository = await getRepository(Prestamo)
|
||||
|
||||
const { usuarioId, tipoId } = request.body
|
||||
|
||||
const usuario = await usuarioRepository.findOne(usuarioId, {
|
||||
select: ['id', 'baja', 'multa']
|
||||
})
|
||||
|
||||
if (!usuario) {
|
||||
res.status(400).json({ err: 'Usuario no encontrado' })
|
||||
return
|
||||
}
|
||||
|
||||
if (usuario.baja) {
|
||||
res.status(400).json({ err: 'El usuario esta dado de baja' })
|
||||
return
|
||||
}
|
||||
|
||||
const prestamoActivo = await prestamoRepository
|
||||
.createQueryBuilder('prestamo')
|
||||
.where('prestamo.usuarioId = :idUsuario', { idUsuario: usuario.id })
|
||||
.andWhere('prestamo.activo = true')
|
||||
.orWhere('prestamo.reservado = true')
|
||||
.getOne()
|
||||
|
||||
if (prestamoActivo) {
|
||||
res.status(400).json({ err: 'El usuario tiene un prestamo activo' })
|
||||
return
|
||||
}
|
||||
|
||||
const equipo = await equipoRepository
|
||||
.createQueryBuilder('equipo')
|
||||
.leftJoinAndSelect('equipo.carrito', 'carrito')
|
||||
.leftJoinAndSelect('carrito.tipo', 'tipo')
|
||||
.where('equipo.activo = :activo', { activo: false })
|
||||
.andWhere('carrito.kiosko = :kiosko', { kiosko: 1 })
|
||||
.andWhere('tipo.id = :tipoId', { tipoId })
|
||||
.orderBy('equipo.updatedAt', 'ASC')
|
||||
.getOne()
|
||||
|
||||
const prestamo = new Prestamo()
|
||||
|
||||
equipo.activo = true
|
||||
|
||||
prestamo.equipo = equipo
|
||||
prestamo.usuario = usuario
|
||||
prestamo.tipo = 'equipo'
|
||||
const m = moment()
|
||||
.add({ hours: 2, minutes: 35 })
|
||||
.toLocaleString()
|
||||
|
||||
prestamo.horaMaxEntrega = m
|
||||
|
||||
await equipoRepository.save(equipo)
|
||||
await prestamoRepository.save(prestamo)
|
||||
|
||||
prestamo.qr = `https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=${prestamo.id}`
|
||||
|
||||
console.log(prestamo)
|
||||
res.status(200).json({
|
||||
prestamo
|
||||
})
|
||||
}
|
||||
|
||||
static async confirmar (req: Request, res: Response) {
|
||||
const prestamoRepository = getRepository(Prestamo)
|
||||
const operadorRepository = getRepository(Operador)
|
||||
|
||||
const { prestamoId, operadorId } = req.body
|
||||
|
||||
const prestamo = await prestamoRepository.findOne(prestamoId, {
|
||||
relations: ['equipo']
|
||||
})
|
||||
if (!prestamo) {
|
||||
res.status(400).json({
|
||||
err: 'El prestamo no existe'
|
||||
})
|
||||
return
|
||||
}
|
||||
const operador = await operadorRepository.findOne(operadorId)
|
||||
|
||||
if (!operador) {
|
||||
res.status(400).json({
|
||||
err: 'El operador no existe'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
prestamo.operadorEntrega = operador
|
||||
prestamo.reservado = false
|
||||
prestamo.activo = true
|
||||
try {
|
||||
await prestamoRepository.save(prestamo)
|
||||
res.status(200).json(prestamo)
|
||||
} catch (err) {
|
||||
res.status(400).json({ err: err.message })
|
||||
}
|
||||
}
|
||||
|
||||
static async regreso (req: Request, res: Response) {
|
||||
const equipoRepository = getRepository(Equipo)
|
||||
const prestamoRepository = getRepository(Prestamo)
|
||||
const operadorRepository = getRepository(Operador)
|
||||
const mesaRepository = getRepository(Mesa)
|
||||
|
||||
const { prestamoId, operadorId } = req.body
|
||||
|
||||
const prestamo = await prestamoRepository.findOne(prestamoId, {
|
||||
relations: ['equipo', 'usuario', 'mesa']
|
||||
})
|
||||
if (!prestamo) {
|
||||
res.status(400).json({ err: 'Prestamo no encontrado' })
|
||||
}
|
||||
const operador = await operadorRepository.findOne(operadorId)
|
||||
if (!operador) {
|
||||
res.status(400).json({ err: 'Operador no encontrado' })
|
||||
}
|
||||
|
||||
if (prestamo.usuario.tipoUsuario.nombre === 'usuario_externo') {
|
||||
prestamo.mesa.activo = false
|
||||
}
|
||||
prestamo.activo = false
|
||||
prestamo.equipo.activo = false
|
||||
prestamo.operadorRegreso = operador
|
||||
try {
|
||||
if (prestamo.usuario.tipoUsuario.nombre === 'usuario_externo') {
|
||||
await mesaRepository.save(prestamo.mesa)
|
||||
}
|
||||
await equipoRepository.save(prestamo.equipo)
|
||||
await prestamoRepository.save(prestamo)
|
||||
res.status(200).send('Prestamo regresado Exitosamente')
|
||||
} catch (err) {
|
||||
res.status(400).json({ err: err.message })
|
||||
}
|
||||
}
|
||||
|
||||
static async estatus (req: Request, res: Response) {
|
||||
const repository = getRepository(Prestamo)
|
||||
const { usuarioId } = req.query
|
||||
console.log(usuarioId)
|
||||
|
||||
const prestamo = await repository
|
||||
.createQueryBuilder('prestamo')
|
||||
.leftJoinAndSelect('prestamo.usuario', 'usuario')
|
||||
.leftJoinAndSelect('prestamo.mesa', 'mesa')
|
||||
.where('usuario.id = :usuarioId', { usuarioId })
|
||||
.andWhere('prestamo.activo = :activo', { activo: true })
|
||||
.getOne()
|
||||
|
||||
if (!prestamo) {
|
||||
res.status(200).json({ err: 'El usuario no tiene prestamos activos' })
|
||||
return
|
||||
}
|
||||
console.log(prestamo)
|
||||
|
||||
res.status(200).json(prestamo)
|
||||
}
|
||||
|
||||
static async cancelar (req: Request, res: Response) {
|
||||
const repository = getRepository(Prestamo)
|
||||
|
||||
const { prestamoId } = req.body
|
||||
|
||||
const prestamo = await repository.findOne(prestamoId)
|
||||
|
||||
if (!prestamo) {
|
||||
res.status(400).json({ err: 'El prestamo no existe' })
|
||||
}
|
||||
|
||||
prestamo.reservado = false
|
||||
|
||||
try {
|
||||
await repository.save(prestamo)
|
||||
res.status(200).send('Cancelado correctamente')
|
||||
} catch (err) {
|
||||
res.status(400).json({ err: err.message })
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,269 +0,0 @@
|
||||
import { Request, Response } from 'express'
|
||||
import { getRepository } from 'typeorm'
|
||||
import { Prestamo } from '@src/entity/Prestamo'
|
||||
import * as moment from 'moment'
|
||||
import { Horario } from '@src/entity/Horario'
|
||||
import { Usuario } from '@src/entity/Usuario'
|
||||
import { Equipo } from '@src/entity/Equipo'
|
||||
import { Operador } from '@src/entity/Operador'
|
||||
import { Mesa } from '@src/entity/Mesa'
|
||||
import { Sala } from '@src/entity/Sala'
|
||||
|
||||
export class ResevacionController {
|
||||
static async espaciosDisponibles (req: Request, res: Response) {
|
||||
const repository = getRepository(Horario)
|
||||
const fecha = moment().format('L')
|
||||
console.log(fecha)
|
||||
const espacios = await repository
|
||||
.createQueryBuilder('horario')
|
||||
.leftJoinAndSelect('horario.prestamos', 'prestamo')
|
||||
.where('prestamo.createdAt >= :fecha', { fecha })
|
||||
.groupBy('horario.hora')
|
||||
.getMany()
|
||||
return res.status(200).json(espacios)
|
||||
}
|
||||
|
||||
static async reservarEquipo (req: Request, res: Response) {
|
||||
const prestamoRepository = getRepository(Prestamo)
|
||||
const horarioRepository = getRepository(Horario)
|
||||
const usuarioRepository = getRepository(Usuario)
|
||||
const equipoRepository = getRepository(Equipo)
|
||||
|
||||
const { usuarioId, tipoId, horarioId } = req.body
|
||||
|
||||
console.log('equipo', usuarioId)
|
||||
const usuario = await usuarioRepository.findOne(usuarioId, {
|
||||
select: ['id', 'baja', 'multa']
|
||||
})
|
||||
|
||||
if (!usuario) {
|
||||
res.status(400).json({ err: 'Usuario no encontrado' })
|
||||
return
|
||||
}
|
||||
|
||||
if (usuario.baja) {
|
||||
res.status(400).json({ err: 'El usuario esta dado de baja' })
|
||||
return
|
||||
}
|
||||
const horario = await horarioRepository.findOne(horarioId)
|
||||
|
||||
if (!horario) {
|
||||
res.status(400).json({ err: 'El horario no existe' })
|
||||
return
|
||||
}
|
||||
|
||||
const prestamoActivo = await prestamoRepository
|
||||
.createQueryBuilder('prestamo')
|
||||
.where('prestamo.usuarioId = :idUsuario', { idUsuario: usuario.id })
|
||||
.andWhere('prestamo.activo = true')
|
||||
.orWhere('prestamo.reservado = true')
|
||||
.getOne()
|
||||
|
||||
if (prestamoActivo) {
|
||||
res.status(400).json({ err: 'El usuario tiene un prestamo activo' })
|
||||
return
|
||||
}
|
||||
const equipo = await equipoRepository
|
||||
.createQueryBuilder('equipo')
|
||||
.leftJoinAndSelect('equipo.carrito', 'carrito')
|
||||
.leftJoinAndSelect('carrito.tipo', 'tipo')
|
||||
.where('equipo.activo = :activo', { activo: false })
|
||||
.andWhere('carrito.kiosko = :kiosko', { kiosko: 3 })
|
||||
.andWhere('tipo.id = :tipoId', { tipoId })
|
||||
.orderBy('equipo.updatedAt', 'ASC')
|
||||
.getOne()
|
||||
|
||||
if (!equipo) {
|
||||
res.status(400).json({ err: 'Ya no hay equipos' })
|
||||
return
|
||||
}
|
||||
const prestamo = new Prestamo()
|
||||
const horamax = horario.hora.split('-')[1].split(':')[0]
|
||||
const m = moment()
|
||||
.hour(+horamax)
|
||||
.minute(0)
|
||||
.toLocaleString()
|
||||
|
||||
equipo.activo = true
|
||||
|
||||
prestamo.equipo = equipo
|
||||
prestamo.usuario = usuario
|
||||
prestamo.horaMaxEntrega = m
|
||||
prestamo.horario = horario
|
||||
prestamo.tipo = 'equipo'
|
||||
|
||||
await equipoRepository.save(equipo)
|
||||
await prestamoRepository.save(prestamo)
|
||||
|
||||
prestamo.qr = `https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=${prestamo.id}`
|
||||
|
||||
console.log(prestamo)
|
||||
res.status(200).json({
|
||||
prestamo
|
||||
})
|
||||
}
|
||||
|
||||
static async reservarSala (req: Request, res: Response) {
|
||||
const prestamoRepository = getRepository(Prestamo)
|
||||
const horarioRepository = getRepository(Horario)
|
||||
const usuarioRepository = getRepository(Usuario)
|
||||
const salaRepository = getRepository(Sala)
|
||||
|
||||
const { usuarioId, horarioId } = req.body
|
||||
console.log('sala', usuarioId)
|
||||
const usuario = await usuarioRepository.findOne(usuarioId, {
|
||||
relations: ['tipoUsuario'],
|
||||
select: ['id', 'baja', 'multa', 'tipoUsuario']
|
||||
})
|
||||
console.log(usuario)
|
||||
|
||||
if (!usuario) {
|
||||
res.status(400).json({ err: 'Usuario no encontrado' })
|
||||
return
|
||||
}
|
||||
if (usuario.tipoUsuario.nombre !== 'profesor_interno') {
|
||||
res.status(400).json({ err: 'Usuario no es profesor' })
|
||||
return
|
||||
}
|
||||
|
||||
if (usuario.baja) {
|
||||
res.status(400).json({ err: 'El usuario esta dado de baja' })
|
||||
return
|
||||
}
|
||||
const horario = await horarioRepository.findOne(horarioId)
|
||||
|
||||
if (!horario) {
|
||||
res.status(400).json({ err: 'El horario no existe' })
|
||||
return
|
||||
}
|
||||
|
||||
const prestamoActivo = await prestamoRepository
|
||||
.createQueryBuilder('prestamo')
|
||||
.where('prestamo.usuarioId = :idUsuario', { idUsuario: usuario.id })
|
||||
.andWhere('prestamo.activo = true')
|
||||
.orWhere('prestamo.reservado = true')
|
||||
.getOne()
|
||||
|
||||
if (prestamoActivo) {
|
||||
res.status(400).json({ err: 'El usuario tiene un prestamo activo' })
|
||||
return
|
||||
}
|
||||
const sala = await salaRepository
|
||||
.createQueryBuilder('sala')
|
||||
.orderBy('sala.updatedAt', 'ASC')
|
||||
.getOne()
|
||||
|
||||
if (!sala) {
|
||||
res.status(400).json({ err: 'Ya no hay salas' })
|
||||
return
|
||||
}
|
||||
const prestamo = new Prestamo()
|
||||
const horamax = horario.hora.split('-')[1].split(':')[0]
|
||||
const m = moment()
|
||||
.hour(+horamax)
|
||||
.minute(0)
|
||||
.toLocaleString()
|
||||
|
||||
sala.activo = true
|
||||
|
||||
prestamo.tipo = 'sala'
|
||||
prestamo.sala = sala
|
||||
prestamo.usuario = usuario
|
||||
prestamo.horaMaxEntrega = m
|
||||
prestamo.horario = horario
|
||||
|
||||
await salaRepository.save(sala)
|
||||
await prestamoRepository.save(prestamo)
|
||||
|
||||
prestamo.qr = `https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=${prestamo.id}`
|
||||
|
||||
console.log(prestamo)
|
||||
res.status(200).json({
|
||||
prestamo
|
||||
})
|
||||
}
|
||||
|
||||
static async confirmar (req: Request, res: Response) {
|
||||
const prestamoRepository = getRepository(Prestamo)
|
||||
const operadorRepository = getRepository(Operador)
|
||||
const mesaRepository = getRepository(Mesa)
|
||||
|
||||
const mesa = await mesaRepository
|
||||
.createQueryBuilder('mesa')
|
||||
.where('mesa.activo = :activo', { activo: false })
|
||||
.orderBy('mesa.updatedAt', 'ASC')
|
||||
.getOne()
|
||||
|
||||
const { prestamoId, operadorId } = req.body
|
||||
|
||||
if (!mesa) {
|
||||
res.status(400).json({
|
||||
err: 'Ya no hay mesas disponbles'
|
||||
})
|
||||
return
|
||||
}
|
||||
const prestamo = await prestamoRepository.findOne(prestamoId, {
|
||||
relations: ['equipo']
|
||||
})
|
||||
if (!prestamo) {
|
||||
res.status(400).json({
|
||||
err: 'El prestamo no existe'
|
||||
})
|
||||
return
|
||||
}
|
||||
const operador = await operadorRepository.findOne(operadorId)
|
||||
|
||||
if (!operador) {
|
||||
res.status(400).json({
|
||||
err: 'El operador no existe'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
mesa.activo = true
|
||||
|
||||
prestamo.operadorEntrega = operador
|
||||
prestamo.reservado = false
|
||||
prestamo.activo = true
|
||||
prestamo.mesa = mesa
|
||||
|
||||
try {
|
||||
await mesaRepository.save(mesa)
|
||||
await prestamoRepository.save(prestamo)
|
||||
res.status(200).json(prestamo)
|
||||
} catch (err) {
|
||||
res.status(400).json({ err: err.message })
|
||||
}
|
||||
}
|
||||
|
||||
static async regreso (req: Request, res: Response) {
|
||||
const equipoRepository = getRepository(Equipo)
|
||||
const prestamoRepository = getRepository(Prestamo)
|
||||
const operadorRepository = getRepository(Operador)
|
||||
const mesaRepository = getRepository(Mesa)
|
||||
|
||||
const prestamo = await prestamoRepository.findOne(req.body.prestamoId, {
|
||||
relations: ['equipo', 'mesa']
|
||||
})
|
||||
if (!prestamo) {
|
||||
res.status(400).json({ err: 'Prestamo no encontrado' })
|
||||
}
|
||||
const operador = await operadorRepository.findOne(req.body.operadorId)
|
||||
if (!operador) {
|
||||
res.status(400).json({ err: 'Operador no encontrado' })
|
||||
}
|
||||
prestamo.activo = false
|
||||
prestamo.equipo.activo = false
|
||||
prestamo.operadorRegreso = operador
|
||||
prestamo.mesa.activo = false
|
||||
|
||||
try {
|
||||
await equipoRepository.save(prestamo.equipo)
|
||||
await mesaRepository.save(prestamo.mesa)
|
||||
await prestamoRepository.save(prestamo)
|
||||
res.status(200).json(prestamo)
|
||||
} catch (err) {
|
||||
res.status(400).json({ err: err.message })
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
import { Request } from 'express'
|
||||
import { Response } from 'express-serve-static-core'
|
||||
import { getRepository } from 'typeorm'
|
||||
import { Tipo } from '@src/entity/Tipo'
|
||||
|
||||
export class TipoController {
|
||||
static async getAll (req: Request, res: Response) {
|
||||
const repository = await getRepository(Tipo)
|
||||
const tipos = await repository.find()
|
||||
res.status(200).json(tipos)
|
||||
}
|
||||
}
|
||||
@@ -1,271 +0,0 @@
|
||||
import { Usuario } from "@src/entity/Usuario";
|
||||
import { Request, Response } from "express";
|
||||
import { validate } from "class-validator";
|
||||
import { getRepository } from "typeorm";
|
||||
import { AuthController } from "./Auth";
|
||||
import { TipoUsuario } from "@src/entity/TipoUsuario";
|
||||
export class UsuarioController {
|
||||
static async create(req: Request, res: Response) {
|
||||
const tipoUsuarioRepository = getRepository(TipoUsuario);
|
||||
console.log(req.file);
|
||||
const {
|
||||
id,
|
||||
nombre,
|
||||
apellidoPaterno,
|
||||
apellidoMaterno,
|
||||
correoAlternativo,
|
||||
numeroTelefonico,
|
||||
institucion,
|
||||
secreto,
|
||||
tipoUsuarioId,
|
||||
} = JSON.parse(req.body.usuario);
|
||||
|
||||
const tipoUsuario = await tipoUsuarioRepository.findOne(tipoUsuarioId);
|
||||
if (!tipoUsuario) {
|
||||
res.status(400).send({
|
||||
status: false,
|
||||
data: "Tipo de usuario no encointrado",
|
||||
});
|
||||
return false;
|
||||
}
|
||||
const identificacion = req.file;
|
||||
if (tipoUsuario.nombre === "alumno_externo" && !identificacion) {
|
||||
res.status(400).send({
|
||||
status: false,
|
||||
data: "Un usuario externo tiene que mandar fotoo de su identificacion",
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
const usuario = new Usuario();
|
||||
usuario.id = id;
|
||||
usuario.nombre = nombre;
|
||||
usuario.apellidoPaterno = apellidoPaterno;
|
||||
usuario.apellidoMaterno = apellidoMaterno;
|
||||
usuario.correoAlternativo = correoAlternativo;
|
||||
usuario.numeroTelefonico = numeroTelefonico;
|
||||
usuario.identificacion =
|
||||
tipoUsuario.nombre === "alumno_externo"
|
||||
? "null"
|
||||
: JSON.stringify(identificacion);
|
||||
usuario.institucion = institucion;
|
||||
usuario.secreto = secreto;
|
||||
usuario.tipoUsuario = tipoUsuario;
|
||||
|
||||
usuario.hashPassword();
|
||||
|
||||
const errors = await validate(usuario);
|
||||
if (errors.length > 0) {
|
||||
res.status(400).send(errors);
|
||||
}
|
||||
|
||||
const repository = getRepository(Usuario);
|
||||
try {
|
||||
await repository.save(usuario);
|
||||
} catch (e) {
|
||||
res.status(409).send(e.message);
|
||||
return;
|
||||
}
|
||||
res.status(201).send("User create");
|
||||
}
|
||||
|
||||
static async getAll(req: Request, res: Response) {
|
||||
const respository = getRepository(Usuario);
|
||||
const result = await respository.find({
|
||||
select: ["id", "nombre", "apellidoMaterno", "apellidoPaterno"],
|
||||
});
|
||||
res.status(200).json(result);
|
||||
}
|
||||
|
||||
static async getOne(req: Request, res: Response) {
|
||||
const respository = getRepository(Usuario);
|
||||
const id: number = +req.params.id;
|
||||
try {
|
||||
const result = await respository.findOneOrFail(id, {
|
||||
select: ["id", "nombre", "apellidoMaterno", "apellidoPaterno"],
|
||||
});
|
||||
res.status(200).json(result);
|
||||
} catch (e) {
|
||||
res.status(404).send("Usuario no encontrado");
|
||||
}
|
||||
}
|
||||
|
||||
static async login(req: Request, res: Response) {
|
||||
const repository = getRepository(Usuario);
|
||||
const { id, secreto } = req.body;
|
||||
try {
|
||||
const usuario = await repository.findOne({
|
||||
relations: ["tipoUsuario"],
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
});
|
||||
if (!usuario) {
|
||||
throw new Error("*Usuario o contraseña invalidos");
|
||||
}
|
||||
if (!usuario.checkIfUnencryptedPasswordIsValid(secreto)) {
|
||||
throw new Error("Usuario o *contraseña invalidos");
|
||||
}
|
||||
const token = await AuthController.signUsuario(
|
||||
usuario.tipoUsuario.nombre,
|
||||
usuario.id
|
||||
);
|
||||
console.log(token);
|
||||
res.status(200).json({
|
||||
nombre: usuario.nombre,
|
||||
apellidoPaterno: usuario.apellidoPaterno,
|
||||
apellidoMaterno: usuario.apellidoMaterno,
|
||||
tipoUsuario: usuario.tipoUsuario,
|
||||
token,
|
||||
});
|
||||
} catch (err) {
|
||||
res.status(400).send(err.message);
|
||||
}
|
||||
}
|
||||
|
||||
static async verificar(req: Request, res: Response) {
|
||||
const usuarioId = req.params.id;
|
||||
|
||||
const alumnos = [
|
||||
{
|
||||
cuenta: 124493,
|
||||
nombre: "Nora",
|
||||
apellidoPaterno: "Goris",
|
||||
apellidoMaterno: "Mayans",
|
||||
institucion: "FES Acatlan",
|
||||
carrera: "Sociologia",
|
||||
tipoUsuario: {
|
||||
id: 1,
|
||||
nombre: "alumno_interno",
|
||||
},
|
||||
},
|
||||
{
|
||||
cuenta: 91770,
|
||||
nombre: "Manuel",
|
||||
apellidoPaterno: "Martinez",
|
||||
apellidoMaterno: "Justo",
|
||||
institucion: "FES Acatlan",
|
||||
carrera: "Derecho",
|
||||
tipoUsuario: {
|
||||
id: 1,
|
||||
nombre: "alumno_interno",
|
||||
},
|
||||
},
|
||||
{
|
||||
cuenta: 123456789,
|
||||
nombre: "Enrique",
|
||||
apellidoPaterno: "Graue",
|
||||
apellidoMaterno: "Wiechers",
|
||||
institucion: "Facultad de Mediciona",
|
||||
carrera: "Medicina",
|
||||
tipoUsuario: {
|
||||
id: 2,
|
||||
nombre: "alumno_externo",
|
||||
},
|
||||
},
|
||||
{
|
||||
cuenta: 40108,
|
||||
nombre: "Fernando",
|
||||
apellidoPaterno: "Martinez",
|
||||
apellidoMaterno: "Ramirez",
|
||||
institucion: "Facultad de Ciencias",
|
||||
carrera: "Matematicas",
|
||||
tipoUsuario: {
|
||||
id: 1,
|
||||
nombre: "alumno_interno",
|
||||
},
|
||||
},
|
||||
{
|
||||
cuenta: 415112132,
|
||||
nombre: "arturo",
|
||||
apellidoPaterno: "Guerrero",
|
||||
apellidoMaterno: "Lopez",
|
||||
institucion: "FES Acatlan",
|
||||
carrera: "M.A.C",
|
||||
tipoUsuario: {
|
||||
id: 1,
|
||||
nombre: "alumno_interno",
|
||||
},
|
||||
},
|
||||
{
|
||||
cuenta: 1,
|
||||
nombre: "Andres",
|
||||
apellidoPaterno: "Martinez",
|
||||
apellidoMaterno: "Ramirez",
|
||||
institucion: "Facultad de Química",
|
||||
carrera: "Ing. Química",
|
||||
tipoUsuario: {
|
||||
id: 1,
|
||||
nombre: "alumno_interno",
|
||||
},
|
||||
},
|
||||
{
|
||||
cuenta: 12,
|
||||
nombre: "Andrea",
|
||||
apellidoPaterno: "Del Valle",
|
||||
apellidoMaterno: "Ramirez",
|
||||
institucion: "Facultad de Psicología",
|
||||
carrera: "Psicología",
|
||||
tipoUsuario: {
|
||||
id: 2,
|
||||
nombre: "alumno_externo",
|
||||
},
|
||||
},
|
||||
{
|
||||
cuenta: 123,
|
||||
nombre: "Leticia",
|
||||
apellidoPaterno: "Cruz",
|
||||
apellidoMaterno: "Garcia",
|
||||
institucion: "Facultad de Derecho",
|
||||
carrera: "Derecho",
|
||||
tipoUsuario: {
|
||||
id: 3,
|
||||
nombre: "profesor_interno",
|
||||
},
|
||||
},
|
||||
{
|
||||
cuenta: 812917,
|
||||
nombre: "Araceli",
|
||||
apellidoPaterno: "Pérez",
|
||||
apellidoMaterno: "Palma",
|
||||
institucion: "FES Acatlan",
|
||||
carrera: "MAC",
|
||||
tipoUsuario: {
|
||||
id: 3,
|
||||
nombre: "profesor_interno",
|
||||
},
|
||||
},
|
||||
{
|
||||
cuenta: 316313528,
|
||||
nombre: "Lemuel Helon",
|
||||
apellidoPaterno: "Márquez",
|
||||
apellidoMaterno: "Rosas",
|
||||
institucion: "FES Acatlan",
|
||||
carrera: "MAC",
|
||||
tipoUsuario: {
|
||||
id: 3,
|
||||
nombre: "profesor_interno",
|
||||
},
|
||||
},
|
||||
{
|
||||
cuenta: 808684,
|
||||
nombre: "Fernando Israel",
|
||||
apellidoPaterno: "González",
|
||||
apellidoMaterno: "Trejo",
|
||||
institucion: "FES Acatlan",
|
||||
carrera: "MAC",
|
||||
tipoUsuario: {
|
||||
id: 3,
|
||||
nombre: "profesor_interno",
|
||||
},
|
||||
},
|
||||
];
|
||||
for (let index = 0; index < alumnos.length; index++) {
|
||||
if (alumnos[index].cuenta === +usuarioId) {
|
||||
res.status(200).json(alumnos[index]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
res.status(400).json({ err: "no se encontro un usuario" });
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
import { Entity, OneToMany } from 'typeorm'
|
||||
import { Catalogo } from './Catalogo'
|
||||
import { Reservacion } from './Reservacion'
|
||||
|
||||
@Entity()
|
||||
export class Actividad extends Catalogo {
|
||||
@OneToMany(
|
||||
(type) => Reservacion,
|
||||
(reservacion) => reservacion.actividad
|
||||
)
|
||||
reservaciones: Reservacion[]
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
import { Entity, ManyToOne } from 'typeorm'
|
||||
import { Catalogo } from './Catalogo'
|
||||
import { Reservacion } from './Reservacion'
|
||||
|
||||
@Entity()
|
||||
export class Adscripcion extends Catalogo {
|
||||
@ManyToOne(
|
||||
(type) => Reservacion,
|
||||
(reservacion) => reservacion.adscripcion
|
||||
)
|
||||
reservaciones: Reservacion[];
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
import {
|
||||
PrimaryGeneratedColumn,
|
||||
Column,
|
||||
Entity,
|
||||
OneToOne,
|
||||
JoinColumn
|
||||
} from 'typeorm'
|
||||
import { TipoProblema } from './TipoProblema'
|
||||
|
||||
export interface AyudaRequest {
|
||||
id: number
|
||||
nombre: string
|
||||
correo: string
|
||||
descripcion: string
|
||||
solucion: string
|
||||
tipoProblema: number
|
||||
}
|
||||
|
||||
@Entity()
|
||||
export class Ayuda {
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number
|
||||
|
||||
@Column()
|
||||
nombre: string
|
||||
|
||||
@Column()
|
||||
correo: string
|
||||
|
||||
@Column()
|
||||
descripcion: string
|
||||
|
||||
@Column()
|
||||
solucion: string
|
||||
|
||||
@OneToOne((type) => TipoProblema)
|
||||
@JoinColumn()
|
||||
tipoProblema: TipoProblema
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
import {
|
||||
Entity,
|
||||
PrimaryGeneratedColumn,
|
||||
Column,
|
||||
ManyToOne,
|
||||
OneToMany,
|
||||
CreateDateColumn,
|
||||
UpdateDateColumn
|
||||
} from 'typeorm'
|
||||
import { Tipo } from './Tipo'
|
||||
import { Reservacion } from './Reservacion'
|
||||
import { Equipo } from './Equipo'
|
||||
|
||||
@Entity()
|
||||
export class Carrito {
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number
|
||||
|
||||
@Column()
|
||||
alias: number
|
||||
|
||||
@Column()
|
||||
kiosko: number
|
||||
|
||||
@OneToMany(
|
||||
(type) => Reservacion,
|
||||
(reservacion) => reservacion.carrito
|
||||
)
|
||||
reservaciones: Reservacion[]
|
||||
|
||||
@OneToMany(
|
||||
(type) => Equipo,
|
||||
(equipo) => equipo.carrito
|
||||
)
|
||||
equipos: Equipo[]
|
||||
|
||||
@ManyToOne(
|
||||
(type) => Tipo,
|
||||
(tipo) => tipo.carritos
|
||||
)
|
||||
tipo: Tipo
|
||||
|
||||
@Column()
|
||||
@CreateDateColumn()
|
||||
createdAt: Date
|
||||
|
||||
@Column()
|
||||
@UpdateDateColumn()
|
||||
updatedAt: Date
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
import { PrimaryGeneratedColumn, Column, Entity } from 'typeorm'
|
||||
|
||||
export abstract class Catalogo {
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number
|
||||
|
||||
@Column()
|
||||
nombre: string
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
import {
|
||||
PrimaryGeneratedColumn,
|
||||
Column,
|
||||
UpdateDateColumn,
|
||||
CreateDateColumn,
|
||||
Entity
|
||||
} from 'typeorm'
|
||||
|
||||
@Entity()
|
||||
export class Configuracion {
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number
|
||||
|
||||
@Column()
|
||||
nombre: string
|
||||
|
||||
@Column()
|
||||
value: string
|
||||
|
||||
@UpdateDateColumn()
|
||||
updatedAt: Date
|
||||
|
||||
@CreateDateColumn()
|
||||
createdAt: Date
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
import {
|
||||
Entity,
|
||||
PrimaryGeneratedColumn,
|
||||
Column,
|
||||
ManyToOne,
|
||||
OneToMany,
|
||||
CreateDateColumn,
|
||||
UpdateDateColumn
|
||||
} from 'typeorm'
|
||||
import { Carrito } from './Carrito'
|
||||
import { Prestamo } from './Prestamo'
|
||||
import { Log } from './Log'
|
||||
import { IsString, IsBoolean, IsNumber } from 'class-validator'
|
||||
|
||||
@Entity()
|
||||
export class Equipo {
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number
|
||||
|
||||
@Column()
|
||||
@IsString()
|
||||
noSerie: string
|
||||
|
||||
@Column()
|
||||
@IsString()
|
||||
noInventario: string
|
||||
|
||||
@Column()
|
||||
@IsNumber()
|
||||
alias: number
|
||||
|
||||
@Column({ type: 'boolean', default: false })
|
||||
@IsBoolean()
|
||||
activo: boolean
|
||||
|
||||
@Column()
|
||||
@CreateDateColumn()
|
||||
createdAt: Date
|
||||
|
||||
@Column()
|
||||
@UpdateDateColumn()
|
||||
updatedAt: Date
|
||||
|
||||
@ManyToOne(
|
||||
(type) => Carrito,
|
||||
(carrito) => carrito.equipos
|
||||
)
|
||||
carrito: Carrito
|
||||
|
||||
@OneToMany(
|
||||
(type) => Prestamo,
|
||||
(prestamo) => prestamo.equipo
|
||||
)
|
||||
prestamos: Prestamo[]
|
||||
|
||||
@ManyToOne(
|
||||
(type) => Log,
|
||||
(log) => log.equipo
|
||||
)
|
||||
logs: Log[]
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
import { Entity, PrimaryGeneratedColumn, Column, OneToMany } from 'typeorm'
|
||||
import { Prestamo } from './Prestamo'
|
||||
|
||||
@Entity()
|
||||
export class Horario {
|
||||
@PrimaryGeneratedColumn()
|
||||
id: string
|
||||
|
||||
@Column()
|
||||
hora: string
|
||||
|
||||
@OneToMany(
|
||||
(type) => Prestamo,
|
||||
(prestamo) => prestamo.horario
|
||||
)
|
||||
prestamos: Prestamo[]
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
import {
|
||||
Entity,
|
||||
Column,
|
||||
ManyToOne,
|
||||
UpdateDateColumn,
|
||||
CreateDateColumn,
|
||||
PrimaryGeneratedColumn
|
||||
} from 'typeorm'
|
||||
import { Usuario } from './Usuario'
|
||||
import { Operador } from './Operador'
|
||||
import { Equipo } from './Equipo'
|
||||
|
||||
@Entity()
|
||||
export class Log {
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number
|
||||
|
||||
@Column()
|
||||
accion: string
|
||||
|
||||
@Column({ default: false })
|
||||
multa: string
|
||||
|
||||
@UpdateDateColumn()
|
||||
updateAt: Date
|
||||
|
||||
@CreateDateColumn()
|
||||
createAt: Date
|
||||
|
||||
@ManyToOne(
|
||||
(type) => Usuario,
|
||||
(usuario) => usuario.logs
|
||||
)
|
||||
usuario: Usuario
|
||||
|
||||
@ManyToOne(
|
||||
(type) => Operador,
|
||||
(operador) => operador.logs
|
||||
)
|
||||
operador: Operador
|
||||
|
||||
@ManyToOne(
|
||||
(type) => Equipo,
|
||||
(equipo) => equipo.logs
|
||||
)
|
||||
equipo: Equipo
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
import { Entity, OneToMany } from 'typeorm'
|
||||
import { Catalogo } from './Catalogo'
|
||||
import { Reservacion } from './Reservacion'
|
||||
|
||||
@Entity()
|
||||
export class Lugar extends Catalogo {
|
||||
@OneToMany(
|
||||
(type) => Reservacion,
|
||||
(reservacion) => reservacion.lugar
|
||||
)
|
||||
reservaciones: Reservacion[];
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
import {
|
||||
Entity,
|
||||
OneToMany,
|
||||
Column,
|
||||
UpdateDateColumn,
|
||||
CreateDateColumn
|
||||
} from 'typeorm'
|
||||
import { Catalogo } from './Catalogo'
|
||||
import { Prestamo } from './Prestamo'
|
||||
|
||||
@Entity()
|
||||
export class Mesa extends Catalogo {
|
||||
@Column({ default: false })
|
||||
activo: boolean
|
||||
|
||||
@UpdateDateColumn()
|
||||
updatedAt: Date
|
||||
|
||||
@CreateDateColumn()
|
||||
createdAt: Date
|
||||
|
||||
@OneToMany(
|
||||
(type) => Prestamo,
|
||||
(prestamo) => prestamo.mesa
|
||||
)
|
||||
prestamos: Prestamo[]
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
import {
|
||||
Entity,
|
||||
PrimaryGeneratedColumn,
|
||||
Column,
|
||||
OneToMany,
|
||||
Unique,
|
||||
UpdateDateColumn,
|
||||
CreateDateColumn
|
||||
} from 'typeorm'
|
||||
import * as bcrypt from 'bcrypt'
|
||||
import { Log } from './Log'
|
||||
import { IsString, IsBoolean } from 'class-validator'
|
||||
import { Prestamo } from './Prestamo'
|
||||
|
||||
@Entity()
|
||||
@Unique(['usuario'])
|
||||
export class Operador {
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number
|
||||
|
||||
@Column()
|
||||
@IsString()
|
||||
usuario: string
|
||||
|
||||
@Column()
|
||||
@IsString()
|
||||
secreto: string
|
||||
|
||||
@Column()
|
||||
@IsBoolean()
|
||||
admin: boolean
|
||||
|
||||
@Column()
|
||||
@UpdateDateColumn()
|
||||
updatedAt: Date
|
||||
|
||||
@Column()
|
||||
@CreateDateColumn()
|
||||
createdAt: Date
|
||||
|
||||
@OneToMany(
|
||||
(type) => Log,
|
||||
(log) => log.operador
|
||||
)
|
||||
logs: Log[]
|
||||
|
||||
@OneToMany(
|
||||
(type) => Prestamo,
|
||||
(prestamo) => prestamo.operadorEntrega
|
||||
)
|
||||
entregas: Prestamo[]
|
||||
|
||||
@OneToMany(
|
||||
(type) => Prestamo,
|
||||
(prestamo) => prestamo.operadorRegreso
|
||||
)
|
||||
regresos: Prestamo[]
|
||||
|
||||
hashPassword () {
|
||||
this.secreto = bcrypt.hashSync(this.secreto, 10)
|
||||
}
|
||||
|
||||
checkIfUnencryptedPasswordIsValid (unencryptedPassword: string) {
|
||||
return bcrypt.compareSync(unencryptedPassword, this.secreto)
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
import { Entity, OneToMany } from 'typeorm'
|
||||
import { Catalogo } from './Catalogo'
|
||||
import { Reporte } from './Reporte'
|
||||
|
||||
@Entity()
|
||||
export class Parte extends Catalogo {
|
||||
@OneToMany(
|
||||
(type) => Reporte,
|
||||
(reporte) => reporte.parte
|
||||
)
|
||||
reportes: Reporte[]
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
import {
|
||||
Entity,
|
||||
PrimaryGeneratedColumn,
|
||||
Column,
|
||||
ManyToOne,
|
||||
UpdateDateColumn,
|
||||
CreateDateColumn
|
||||
} from 'typeorm'
|
||||
import { Usuario } from './Usuario'
|
||||
import { Reporte } from './Reporte'
|
||||
import { Equipo } from './Equipo'
|
||||
import { Mesa } from './Mesa'
|
||||
import { Operador } from './Operador'
|
||||
import { Horario } from './Horario'
|
||||
import { Sala } from './Sala'
|
||||
|
||||
@Entity()
|
||||
export class Prestamo {
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number
|
||||
|
||||
@Column({ default: false })
|
||||
activo: boolean
|
||||
|
||||
@Column({ default: true })
|
||||
reservado: boolean
|
||||
|
||||
@UpdateDateColumn()
|
||||
updatedAt: Date
|
||||
|
||||
@CreateDateColumn()
|
||||
createdAt: Date
|
||||
|
||||
@Column()
|
||||
tipo: String
|
||||
|
||||
horaMaxEntrega: string
|
||||
|
||||
qr: string
|
||||
|
||||
@ManyToOne(
|
||||
(type) => Usuario,
|
||||
(usuario) => usuario.prestamos
|
||||
)
|
||||
usuario: Usuario
|
||||
|
||||
@ManyToOne(
|
||||
(type) => Mesa,
|
||||
(mesa) => mesa.prestamos
|
||||
)
|
||||
mesa: Mesa
|
||||
|
||||
@ManyToOne(
|
||||
(type) => Reporte,
|
||||
(reporte) => reporte.prestamos
|
||||
)
|
||||
reporte: Reporte
|
||||
|
||||
@ManyToOne(
|
||||
(type) => Equipo,
|
||||
(equipo) => equipo.prestamos
|
||||
)
|
||||
equipo: Equipo
|
||||
|
||||
@ManyToOne(
|
||||
(type) => Operador,
|
||||
(operador) => operador.entregas
|
||||
)
|
||||
operadorEntrega: Operador
|
||||
|
||||
@ManyToOne(
|
||||
(type) => Operador,
|
||||
(operador) => operador.regresos
|
||||
)
|
||||
operadorRegreso: Operador
|
||||
|
||||
@ManyToOne(
|
||||
(type) => Horario,
|
||||
(horario) => horario.prestamos
|
||||
)
|
||||
horario: Horario
|
||||
|
||||
@ManyToOne(
|
||||
(type) => Sala,
|
||||
(sala) => sala.prestamos
|
||||
)
|
||||
sala: Sala
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
import {
|
||||
Entity,
|
||||
PrimaryGeneratedColumn,
|
||||
Column,
|
||||
ManyToOne,
|
||||
OneToMany
|
||||
} from 'typeorm'
|
||||
import { Parte } from './Parte'
|
||||
import { Reservacion } from './Reservacion'
|
||||
import { Prestamo } from './Prestamo'
|
||||
|
||||
@Entity()
|
||||
export class Reporte {
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number
|
||||
|
||||
@Column()
|
||||
equipos: number
|
||||
|
||||
@Column()
|
||||
descripcion: string
|
||||
|
||||
@ManyToOne(
|
||||
(type) => Parte,
|
||||
(parte) => parte.reportes
|
||||
)
|
||||
parte: Parte
|
||||
|
||||
@OneToMany(
|
||||
(type) => Reservacion,
|
||||
(reservacion) => reservacion.reporte
|
||||
)
|
||||
reservaciones: Reservacion[]
|
||||
|
||||
@OneToMany(
|
||||
(type) => Prestamo,
|
||||
(prestamo) => prestamo.reporte
|
||||
)
|
||||
prestamos: Prestamo[]
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
import { Entity, PrimaryGeneratedColumn, Column, ManyToOne } from 'typeorm'
|
||||
import { Actividad } from './Actividad'
|
||||
import { Adscripcion } from './Adscripcion'
|
||||
import { Lugar } from './Lugar'
|
||||
import { Carrito } from './Carrito'
|
||||
import { Reporte } from './Reporte'
|
||||
import { Usuario } from './Usuario'
|
||||
|
||||
@Entity()
|
||||
export class Reservacion {
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number
|
||||
|
||||
@Column({ type: 'date' })
|
||||
fechaInicio: string
|
||||
|
||||
@Column({ type: 'date' })
|
||||
fechaFin: string
|
||||
|
||||
@Column()
|
||||
descripcion: string
|
||||
|
||||
@Column({ type: 'boolean' })
|
||||
uso: boolean
|
||||
|
||||
@Column({ type: 'boolean' })
|
||||
cancelado: boolean
|
||||
|
||||
@Column({ type: 'boolean' })
|
||||
aceptado: boolean
|
||||
|
||||
@ManyToOne(
|
||||
(type) => Actividad,
|
||||
(actividad) => actividad.reservaciones
|
||||
)
|
||||
actividad: Actividad
|
||||
|
||||
@ManyToOne(
|
||||
(type) => Adscripcion,
|
||||
(adscripcion) => adscripcion.reservaciones
|
||||
)
|
||||
adscripcion: Adscripcion
|
||||
|
||||
@ManyToOne(
|
||||
(type) => Lugar,
|
||||
(lugar) => lugar.reservaciones
|
||||
)
|
||||
lugar: Lugar
|
||||
|
||||
@ManyToOne(
|
||||
(type) => Carrito,
|
||||
(carrito) => carrito.reservaciones
|
||||
)
|
||||
carrito: Carrito
|
||||
|
||||
@ManyToOne(
|
||||
(type) => Reporte,
|
||||
(reporte) => reporte.reservaciones
|
||||
)
|
||||
reporte: Reporte
|
||||
|
||||
@ManyToOne(
|
||||
(type) => Usuario,
|
||||
(reporte) => reporte.reservaciones
|
||||
)
|
||||
usuario: Usuario
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
import {
|
||||
Entity,
|
||||
UpdateDateColumn,
|
||||
CreateDateColumn,
|
||||
OneToMany,
|
||||
Column
|
||||
} from 'typeorm'
|
||||
import { Catalogo } from './Catalogo'
|
||||
import { Prestamo } from './Prestamo'
|
||||
|
||||
@Entity()
|
||||
export class Sala extends Catalogo {
|
||||
@Column({ default: false })
|
||||
activo: boolean
|
||||
|
||||
@UpdateDateColumn()
|
||||
updatedAt: Date
|
||||
|
||||
@CreateDateColumn()
|
||||
createdAt: Date
|
||||
|
||||
@OneToMany(
|
||||
(type) => Prestamo,
|
||||
(prestamo) => prestamo.sala
|
||||
)
|
||||
prestamos: Prestamo[]
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
import { Entity, OneToMany, PrimaryGeneratedColumn, Column } from 'typeorm'
|
||||
import { Catalogo } from './Catalogo'
|
||||
import { Carrito } from './Carrito'
|
||||
import { IsString } from 'class-validator'
|
||||
|
||||
@Entity()
|
||||
export class Tipo extends Catalogo {
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number
|
||||
|
||||
@Column()
|
||||
@IsString()
|
||||
nombre: string
|
||||
|
||||
@OneToMany(
|
||||
(type) => Carrito,
|
||||
(carrito) => carrito.tipo
|
||||
)
|
||||
carritos: Carrito[]
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
import { PrimaryGeneratedColumn, Column, Entity } from 'typeorm'
|
||||
|
||||
@Entity()
|
||||
export class TipoProblema {
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
nombre: string;
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
import { Entity, UpdateDateColumn, CreateDateColumn, OneToMany } from 'typeorm'
|
||||
import { Catalogo } from './Catalogo'
|
||||
import { Usuario } from './Usuario'
|
||||
|
||||
@Entity()
|
||||
export class TipoUsuario extends Catalogo {
|
||||
@UpdateDateColumn()
|
||||
updatedAt: Date
|
||||
|
||||
@CreateDateColumn()
|
||||
createdAt: Date
|
||||
|
||||
@OneToMany(
|
||||
(type) => Usuario,
|
||||
(usuario) => usuario.tipoUsuario
|
||||
)
|
||||
usuarios: Usuario[]
|
||||
}
|
||||
@@ -1,120 +0,0 @@
|
||||
import * as bcrypt from 'bcrypt'
|
||||
|
||||
import {
|
||||
Entity,
|
||||
PrimaryGeneratedColumn,
|
||||
Column,
|
||||
OneToMany,
|
||||
Unique,
|
||||
CreateDateColumn,
|
||||
UpdateDateColumn,
|
||||
ManyToOne
|
||||
} from 'typeorm'
|
||||
import {
|
||||
IsDate,
|
||||
IsEmail,
|
||||
Length,
|
||||
IsBoolean,
|
||||
IsString,
|
||||
IsOptional
|
||||
} from 'class-validator'
|
||||
import { Reservacion } from './Reservacion'
|
||||
import { Prestamo } from './Prestamo'
|
||||
import { Log } from './Log'
|
||||
import { TipoUsuario } from './TipoUsuario'
|
||||
|
||||
@Entity()
|
||||
@Unique(['id', 'correoAlternativo'])
|
||||
export class Usuario {
|
||||
@PrimaryGeneratedColumn()
|
||||
id: string
|
||||
|
||||
@Column()
|
||||
@IsString()
|
||||
nombre: string
|
||||
|
||||
@Column()
|
||||
@IsString()
|
||||
apellidoPaterno: string
|
||||
|
||||
@Column()
|
||||
@IsString()
|
||||
apellidoMaterno: string
|
||||
|
||||
@Column()
|
||||
@IsEmail()
|
||||
correoAlternativo: string
|
||||
|
||||
@Column()
|
||||
@Length(10)
|
||||
numeroTelefonico: string
|
||||
|
||||
@Column({ type: 'text' })
|
||||
@IsString()
|
||||
identificacion: string
|
||||
|
||||
@Column()
|
||||
@IsString()
|
||||
institucion: string
|
||||
|
||||
@Column()
|
||||
@IsString()
|
||||
secreto: string
|
||||
|
||||
@Column({ type: 'date', default: '1996-11-07' })
|
||||
@IsDate()
|
||||
@IsOptional()
|
||||
multa: string
|
||||
|
||||
@Column({ type: 'date', default: '1996-11-07' })
|
||||
@IsDate()
|
||||
@IsOptional()
|
||||
multaRed: string
|
||||
|
||||
@Column({ default: false })
|
||||
@IsBoolean()
|
||||
@IsOptional()
|
||||
baja: boolean
|
||||
|
||||
@Column()
|
||||
@CreateDateColumn()
|
||||
createdAt: Date
|
||||
|
||||
@Column()
|
||||
@UpdateDateColumn()
|
||||
updatedAt: Date
|
||||
|
||||
token: string
|
||||
|
||||
@OneToMany(
|
||||
(type) => Reservacion,
|
||||
(reservacion) => reservacion.usuario
|
||||
)
|
||||
reservaciones: Reservacion[]
|
||||
|
||||
@OneToMany(
|
||||
(type) => Prestamo,
|
||||
(prestamo) => prestamo.usuario
|
||||
)
|
||||
prestamos: Prestamo[]
|
||||
|
||||
@OneToMany(
|
||||
(type) => Log,
|
||||
(log) => log.usuario
|
||||
)
|
||||
logs: Log[]
|
||||
|
||||
@ManyToOne(
|
||||
(type) => TipoUsuario,
|
||||
(tipoUsuario) => tipoUsuario.usuarios
|
||||
)
|
||||
tipoUsuario: TipoUsuario
|
||||
|
||||
hashPassword () {
|
||||
this.secreto = bcrypt.hashSync(this.secreto, 10)
|
||||
}
|
||||
|
||||
checkIfUnencryptedPasswordIsValid (unencryptedPassword: string) {
|
||||
return bcrypt.compareSync(unencryptedPassword, this.secreto)
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
import * as express from 'express'
|
||||
import * as bodyParser from 'body-parser'
|
||||
import routes from './routes/index'
|
||||
import { createConnection } from 'typeorm'
|
||||
import * as cors from 'cors'
|
||||
|
||||
const PORT = 3000
|
||||
createConnection()
|
||||
.then(async (connection) => {
|
||||
const app = express()
|
||||
// configure multer
|
||||
app.use(cors())
|
||||
app.use(bodyParser.urlencoded({ extended: false }))
|
||||
app.use(bodyParser.json())
|
||||
|
||||
app.get('/', (req, res) => res.send('Hello World!'))
|
||||
|
||||
app.use('/', routes)
|
||||
|
||||
app.listen(PORT, () =>
|
||||
console.log(`Example app listening at http://localhost:${PORT}`)
|
||||
)
|
||||
})
|
||||
.catch((error) => console.log('TypeORM connection error: ', error))
|
||||
@@ -1,17 +0,0 @@
|
||||
import * as jwt from 'jsonwebtoken'
|
||||
import { Request, Response, NextFunction } from 'express'
|
||||
|
||||
const verificaToken = (req: Request, res: Response, next: NextFunction) => {
|
||||
const token = req.get('authorization')
|
||||
jwt.verify(token.split(' ')[1], 'Holabeb', (err, decoded) => {
|
||||
if (err) {
|
||||
return res.status(401).json({
|
||||
status: false,
|
||||
err: 'jsonwebtoken error'
|
||||
})
|
||||
}
|
||||
next()
|
||||
})
|
||||
}
|
||||
|
||||
export default verificaToken
|
||||
@@ -1,13 +0,0 @@
|
||||
import { Router } from 'express'
|
||||
import { CarritoController } from '@src/controller/Carrito'
|
||||
import * as multer from 'multer'
|
||||
|
||||
var upload = multer({ dest: 'uploads/' })
|
||||
const router = Router()
|
||||
|
||||
router.post('/', upload.single('masiva'), (req, res) => {
|
||||
const carrito = new CarritoController()
|
||||
carrito.carga(req, res)
|
||||
})
|
||||
|
||||
export default router
|
||||
@@ -1,7 +0,0 @@
|
||||
import { Router } from 'express'
|
||||
import { HorarioController } from '@src/controller/Horario'
|
||||
const router = Router()
|
||||
|
||||
router.get('/', HorarioController.getAll)
|
||||
|
||||
export default router
|
||||
@@ -1,21 +0,0 @@
|
||||
import { Router } from 'express'
|
||||
|
||||
import usuario from './usuario'
|
||||
import operador from './operador'
|
||||
import carrito from './carrito'
|
||||
import prestamo from './prestamo'
|
||||
import tipo from './tipo'
|
||||
import reservacion from './reservacion'
|
||||
import horario from './horario'
|
||||
|
||||
const routes = Router()
|
||||
|
||||
routes.use('/operador', operador)
|
||||
routes.use('/usuario', usuario)
|
||||
routes.use('/carrito', carrito)
|
||||
routes.use('/prestamo', prestamo)
|
||||
routes.use('/tipo', tipo)
|
||||
routes.use('/reservacion', reservacion)
|
||||
routes.use('/horario', horario)
|
||||
|
||||
export default routes
|
||||
@@ -1,15 +0,0 @@
|
||||
import { Router } from 'express'
|
||||
|
||||
import { OperadorController } from '@src/controller/Operador'
|
||||
|
||||
const router = Router()
|
||||
|
||||
router.post('/', OperadorController.create)
|
||||
|
||||
router.get('/', OperadorController.getAll)
|
||||
|
||||
router.get('/:id([0-9]+)', OperadorController.getOne)
|
||||
|
||||
router.delete('/:id([0-9]+)', OperadorController.remove)
|
||||
|
||||
export default router
|
||||
@@ -1,11 +0,0 @@
|
||||
import { Router } from 'express'
|
||||
import { PrestamoController } from '@src/controller/Prestamo'
|
||||
const router = Router()
|
||||
|
||||
router.post('/', PrestamoController.crear)
|
||||
router.put('/regreso', PrestamoController.regreso)
|
||||
router.put('/confirmar', PrestamoController.confirmar)
|
||||
router.get('/estatus', PrestamoController.estatus)
|
||||
router.put('/cancelar', PrestamoController.cancelar)
|
||||
|
||||
export default router
|
||||
@@ -1,11 +0,0 @@
|
||||
import { Router } from 'express'
|
||||
import { ResevacionController } from '@src/controller/Reservacion'
|
||||
|
||||
const router = Router()
|
||||
|
||||
router.post('/equipo', ResevacionController.reservarEquipo)
|
||||
router.post('/sala', ResevacionController.reservarSala)
|
||||
router.get('/espacios', ResevacionController.espaciosDisponibles)
|
||||
router.put('/confirmar', ResevacionController.confirmar)
|
||||
|
||||
export default router
|
||||
@@ -1,8 +0,0 @@
|
||||
import { Router } from 'express'
|
||||
import { TipoController } from '@src/controller/Tipo'
|
||||
|
||||
const router = Router()
|
||||
|
||||
router.get('/', TipoController.getAll)
|
||||
|
||||
export default router
|
||||
@@ -1,19 +0,0 @@
|
||||
import { Router } from 'express'
|
||||
import { UsuarioController } from '@src/controller/Usuario'
|
||||
import * as multer from 'multer'
|
||||
import verificaToken from '@src/middleware/auth'
|
||||
|
||||
var upload = multer({ dest: 'uploads/identifiaciones' })
|
||||
const router = Router()
|
||||
|
||||
router.post('/', upload.single('identificacion'), UsuarioController.create)
|
||||
|
||||
router.post('/login', UsuarioController.login)
|
||||
|
||||
router.get('/', [verificaToken], UsuarioController.getAll)
|
||||
|
||||
router.get('/:id([0-9]+)', UsuarioController.getOne)
|
||||
|
||||
router.get('/verifica/:id([0-9]+)', UsuarioController.verificar)
|
||||
|
||||
export default router
|
||||
Reference in New Issue
Block a user