pre sala
This commit is contained in:
@@ -1,11 +1,15 @@
|
||||
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',
|
||||
@@ -25,6 +29,18 @@ createConnection()
|
||||
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 tipoUsuario = new TipoUsuario()
|
||||
tipoUsuario.nombre = 'alumno_interno'
|
||||
await tipoUsuarioRepository.save(tipoUsuario)
|
||||
tipoUsuario.nombre = 'alumno_externo'
|
||||
await tipoUsuarioRepository.save(tipoUsuario)
|
||||
tipoUsuario.nombre = 'profesor_interno'
|
||||
await tipoUsuarioRepository.save(tipoUsuario)
|
||||
|
||||
process.exit()
|
||||
})
|
||||
|
||||
@@ -7,6 +7,7 @@ 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) {
|
||||
@@ -22,7 +23,7 @@ export class ResevacionController {
|
||||
return res.status(200).json(espacios)
|
||||
}
|
||||
|
||||
static async reservar (req: Request, res: Response) {
|
||||
static async reservarEquipo (req: Request, res: Response) {
|
||||
const prestamoRepository = getRepository(Prestamo)
|
||||
const horarioRepository = getRepository(Horario)
|
||||
const usuarioRepository = getRepository(Usuario)
|
||||
@@ -100,6 +101,83 @@ export class ResevacionController {
|
||||
})
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
const usuario = await usuarioRepository.findOne(usuarioId, {
|
||||
select: ['id', 'baja', 'multa', 'tipoUsuario']
|
||||
})
|
||||
|
||||
if (!usuario) {
|
||||
res.status(400).json({ err: 'Usuario no encontrado' })
|
||||
return
|
||||
}
|
||||
if (usuario.tipoUsuario.nombre !== 'profesor') {
|
||||
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 sala = await salaRepository
|
||||
.createQueryBuilder('sala')
|
||||
.orderBy('equipo.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.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)
|
||||
|
||||
@@ -110,19 +110,8 @@ export class UsuarioController {
|
||||
}
|
||||
|
||||
static async verificar (req: Request, res: Response) {
|
||||
const usuarios = ['415112132', '41511216']
|
||||
const externos = ['315112132', '31511216']
|
||||
|
||||
const usuarioId = req.params.id
|
||||
|
||||
const usuarioInterno = {
|
||||
nombre: 'Arturo',
|
||||
apellidoPaterno: 'Guerrero',
|
||||
apellidoMaterno: 'Lopez',
|
||||
institucion: 'Fes acatlan',
|
||||
carrera: 'Matematicas aplicadas',
|
||||
interno: true
|
||||
}
|
||||
const alumnos = [
|
||||
{
|
||||
cuenta: 124493,
|
||||
@@ -131,7 +120,7 @@ export class UsuarioController {
|
||||
apellidoMaterno: 'Mayans',
|
||||
institucion: 'FES Acatlan',
|
||||
carrera: 'Sociologia',
|
||||
interno: false
|
||||
tipo: 1
|
||||
},
|
||||
{
|
||||
cuenta: 91770,
|
||||
@@ -140,7 +129,7 @@ export class UsuarioController {
|
||||
apellidoMaterno: 'Justo',
|
||||
institucion: 'FES Acatlan',
|
||||
carrera: 'Derecho',
|
||||
interno: false
|
||||
tipo: 1
|
||||
},
|
||||
{
|
||||
cuenta: 123456789,
|
||||
@@ -149,7 +138,7 @@ export class UsuarioController {
|
||||
apellidoMaterno: 'Wiechers',
|
||||
institucion: 'Facultad de Mediciona',
|
||||
carrera: 'Medicina',
|
||||
interno: false
|
||||
tipo: 1
|
||||
},
|
||||
{
|
||||
cuenta: 40108,
|
||||
@@ -158,7 +147,7 @@ export class UsuarioController {
|
||||
apellidoMaterno: 'Ramirez',
|
||||
institucion: 'Facultad de Ciencias',
|
||||
carrera: 'Matematicas',
|
||||
interno: false
|
||||
tipo: 1
|
||||
},
|
||||
{
|
||||
cuenta: 415112133,
|
||||
@@ -167,7 +156,7 @@ export class UsuarioController {
|
||||
apellidoMaterno: 'Lopez',
|
||||
institucion: 'FES Iztacala',
|
||||
carrera: 'Biologia',
|
||||
interno: false
|
||||
tipo: 1
|
||||
}
|
||||
]
|
||||
for (let index = 0; index < alumnos.length; index++) {
|
||||
@@ -182,7 +171,7 @@ export class UsuarioController {
|
||||
// apellidoMaterno: 'Lopez',
|
||||
// institucion: 'FES Iztacala',
|
||||
// carrera: 'Biologia',
|
||||
// interno: false
|
||||
// tipo: false
|
||||
// }
|
||||
|
||||
// if (usuarios.includes(usuarioId)) {
|
||||
|
||||
+11
-1
@@ -12,6 +12,7 @@ import { Equipo } from './Equipo'
|
||||
import { Mesa } from './Mesa'
|
||||
import { Operador } from './Operador'
|
||||
import { Horario } from './Horario'
|
||||
import { Sala } from './Sala'
|
||||
|
||||
@Entity()
|
||||
export class Prestamo {
|
||||
@@ -30,6 +31,9 @@ export class Prestamo {
|
||||
@CreateDateColumn()
|
||||
createdAt: Date
|
||||
|
||||
@Column()
|
||||
tipo: String
|
||||
|
||||
horaMaxEntrega: string
|
||||
|
||||
qr: string
|
||||
@@ -68,11 +72,17 @@ export class Prestamo {
|
||||
(type) => Operador,
|
||||
(operador) => operador.regresos
|
||||
)
|
||||
operadorRegreso: Operador
|
||||
|
||||
@ManyToOne(
|
||||
(type) => Horario,
|
||||
(horario) => horario.prestamos
|
||||
)
|
||||
horario: Horario
|
||||
|
||||
operadorRegreso: Operador
|
||||
@ManyToOne(
|
||||
(type) => Sala,
|
||||
(sala) => sala.prestamos
|
||||
)
|
||||
sala: Sala
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import {
|
||||
Entity,
|
||||
UpdateDateColumn,
|
||||
CreateDateColumn,
|
||||
OneToMany,
|
||||
Column
|
||||
} from 'typeorm'
|
||||
import { Catalogo } from './Catalogo'
|
||||
import { Prestamo } from './Prestamo'
|
||||
|
||||
@Entity()
|
||||
export class Sala extends Catalogo {
|
||||
@Column()
|
||||
activo: boolean
|
||||
|
||||
@UpdateDateColumn()
|
||||
updatedAt: Date
|
||||
|
||||
@CreateDateColumn()
|
||||
createdAt: Date
|
||||
|
||||
@OneToMany(
|
||||
(type) => Prestamo,
|
||||
(prestamo) => prestamo.sala
|
||||
)
|
||||
prestamos: Prestamo[]
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
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[]
|
||||
}
|
||||
@@ -7,7 +7,8 @@ import {
|
||||
OneToMany,
|
||||
Unique,
|
||||
CreateDateColumn,
|
||||
UpdateDateColumn
|
||||
UpdateDateColumn,
|
||||
ManyToOne
|
||||
} from 'typeorm'
|
||||
import {
|
||||
IsDate,
|
||||
@@ -20,6 +21,7 @@ import {
|
||||
import { Reservacion } from './Reservacion'
|
||||
import { Prestamo } from './Prestamo'
|
||||
import { Log } from './Log'
|
||||
import { TipoUsuario } from './TipoUsuario'
|
||||
|
||||
@Entity()
|
||||
@Unique(['id', 'correoAlternativo'])
|
||||
@@ -106,6 +108,12 @@ export class Usuario {
|
||||
)
|
||||
logs: Log[]
|
||||
|
||||
@ManyToOne(
|
||||
(type) => TipoUsuario,
|
||||
(tipoUsuario) => tipoUsuario.usuarios
|
||||
)
|
||||
tipoUsuario: TipoUsuario
|
||||
|
||||
hashPassword () {
|
||||
this.secreto = bcrypt.hashSync(this.secreto, 10)
|
||||
}
|
||||
|
||||
@@ -3,7 +3,8 @@ import { ResevacionController } from '@src/controller/Reservacion'
|
||||
|
||||
const router = Router()
|
||||
|
||||
router.post('/', ResevacionController.reservar)
|
||||
router.post('/equipo', ResevacionController.reservarEquipo)
|
||||
router.post('/sala', ResevacionController.reservarSala)
|
||||
router.get('/espacios', ResevacionController.espaciosDisponibles)
|
||||
router.put('/confirmar', ResevacionController.confirmar)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user