cargamasviva
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import { getManager } from 'typeorm'
|
||||
import { Ayuda, AyudaRequest } from '@db/entity/Ayuda'
|
||||
import { TipoProblema } from '@db/entity/TipoProblema'
|
||||
|
||||
export class AyudaController {
|
||||
private ayudaRepository: any
|
||||
private tipoProblemaRepository: any
|
||||
constructor () {
|
||||
this.ayudaRepository = getManager().getRepository(Ayuda)
|
||||
this.tipoProblemaRepository = getManager().getRepository(TipoProblema)
|
||||
}
|
||||
|
||||
async create (request: AyudaRequest) {
|
||||
const tipoProblema = this.tipoProblemaRepository.findOne(
|
||||
request.tipoProblema
|
||||
)
|
||||
request.tipoProblema = tipoProblema
|
||||
const ayuda = this.ayudaRepository.create(request)
|
||||
const result = await this.ayudaRepository.save(ayuda)
|
||||
return result
|
||||
}
|
||||
|
||||
async getOne (id: number) {
|
||||
return await this.ayudaRepository.findOne(id)
|
||||
}
|
||||
|
||||
async getAll () {
|
||||
return await this.ayudaRepository.findOne()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
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
|
||||
}
|
||||
})
|
||||
console.log(tipoFind)
|
||||
const carritoFind = await carritoRepository.findOne({
|
||||
where: {
|
||||
sobrenombre: data.alias_carrito
|
||||
}
|
||||
})
|
||||
|
||||
if (!tipoFind) {
|
||||
tipo.nombre = data.tipo
|
||||
}
|
||||
|
||||
if (!carritoFind) {
|
||||
carrito.kiosko = data.kiosko
|
||||
carrito.sobrenombre = 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)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
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')
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
import { Usuario } from '@src/entity/Usuario'
|
||||
import { Request, Response } from 'express'
|
||||
import { validate } from 'class-validator'
|
||||
import { getRepository } from 'typeorm'
|
||||
export class UsuarioController {
|
||||
static async create (req: Request, res: Response) {
|
||||
const {
|
||||
id,
|
||||
nombre,
|
||||
apellidoPaterno,
|
||||
apellidoMaterno,
|
||||
correoAlternativo,
|
||||
numeroTelefonico,
|
||||
identificacion,
|
||||
institucion
|
||||
} = req.body
|
||||
|
||||
const usuario = new Usuario()
|
||||
usuario.id = id
|
||||
usuario.nombre = nombre
|
||||
usuario.apellidoPaterno = apellidoPaterno
|
||||
usuario.apellidoMaterno = apellidoMaterno
|
||||
usuario.correoAlternativo = correoAlternativo
|
||||
usuario.numeroTelefonico = numeroTelefonico
|
||||
usuario.identificacion = identificacion
|
||||
usuario.institucion = institucion
|
||||
|
||||
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')
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
import { Entity, PrimaryGeneratedColumn, Column, ManyToOne } from 'typeorm'
|
||||
import { Carrito } from './Carrito'
|
||||
|
||||
@Entity()
|
||||
export class Equipo {
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
noSerie: string;
|
||||
|
||||
@Column()
|
||||
noInventario: string;
|
||||
|
||||
@Column()
|
||||
alias: string;
|
||||
|
||||
@Column({ type: 'boolean' })
|
||||
activo: boolean;
|
||||
|
||||
@ManyToOne(
|
||||
(type) => Carrito,
|
||||
(carrito) => carrito.equipos
|
||||
)
|
||||
carrito: Carrito;
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
import { Entity, PrimaryGeneratedColumn, Column } from 'typeorm'
|
||||
|
||||
@Entity()
|
||||
export class Prestamo {
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
activo: boolean;
|
||||
|
||||
@Column({ type: 'date' })
|
||||
fechaInicio: string;
|
||||
|
||||
@Column({ type: 'date' })
|
||||
fechaFin: string;
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
import { Entity, OneToMany, Equal } from 'typeorm'
|
||||
import { Catalogo } from './Catalogo'
|
||||
import { Equipo } from './Equipo'
|
||||
import { Carrito } from './Carrito'
|
||||
|
||||
@Entity()
|
||||
export class Tipo extends Catalogo {
|
||||
@OneToMany(
|
||||
(type) => Carrito,
|
||||
(carrito) => carrito.tipo
|
||||
)
|
||||
carritos: Carrito[];
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
import {Entity, PrimaryGeneratedColumn, Column} from "typeorm";
|
||||
|
||||
@Entity()
|
||||
export class User {
|
||||
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
firstName: string;
|
||||
|
||||
@Column()
|
||||
lastName: string;
|
||||
|
||||
@Column()
|
||||
age: number;
|
||||
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
import { Entity, PrimaryGeneratedColumn, Column } from 'typeorm'
|
||||
|
||||
@Entity()
|
||||
export class Usuario {
|
||||
@PrimaryGeneratedColumn()
|
||||
id: string;
|
||||
|
||||
@Column()
|
||||
nombre: string;
|
||||
|
||||
@Column()
|
||||
apellidoPaterno: string;
|
||||
|
||||
@Column()
|
||||
apellidoMaterno: string;
|
||||
|
||||
@Column()
|
||||
correoAlternativo: string;
|
||||
|
||||
@Column()
|
||||
numeroTelefonico: string;
|
||||
|
||||
@Column()
|
||||
identificacion: string;
|
||||
|
||||
@Column()
|
||||
institucion: string;
|
||||
|
||||
@Column({ type: 'date' })
|
||||
multa: string;
|
||||
|
||||
@Column({ type: 'date' })
|
||||
multaRed: string;
|
||||
|
||||
@Column()
|
||||
baja: boolean;
|
||||
}
|
||||
@@ -8,5 +8,5 @@ export class Actividad extends Catalogo {
|
||||
(type) => Reservacion,
|
||||
(reservacion) => reservacion.actividad
|
||||
)
|
||||
reservaciones: Reservacion[];
|
||||
reservaciones: Reservacion[]
|
||||
}
|
||||
@@ -7,24 +7,33 @@ import {
|
||||
} 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;
|
||||
id: number
|
||||
|
||||
@Column()
|
||||
nombre: string;
|
||||
nombre: string
|
||||
|
||||
@Column()
|
||||
correo: string;
|
||||
correo: string
|
||||
|
||||
@Column()
|
||||
descripcion: string;
|
||||
descripcion: string
|
||||
|
||||
@Column()
|
||||
solucion: string;
|
||||
solucion: string
|
||||
|
||||
@OneToOne((type) => TipoProblema)
|
||||
@JoinColumn()
|
||||
tipoProblema: TipoProblema;
|
||||
tipoProblema: TipoProblema
|
||||
}
|
||||
@@ -3,7 +3,9 @@ import {
|
||||
PrimaryGeneratedColumn,
|
||||
Column,
|
||||
ManyToOne,
|
||||
OneToMany
|
||||
OneToMany,
|
||||
CreateDateColumn,
|
||||
UpdateDateColumn
|
||||
} from 'typeorm'
|
||||
import { Tipo } from './Tipo'
|
||||
import { Reservacion } from './Reservacion'
|
||||
@@ -12,29 +14,37 @@ import { Equipo } from './Equipo'
|
||||
@Entity()
|
||||
export class Carrito {
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number;
|
||||
id: number
|
||||
|
||||
@Column()
|
||||
sobrenombre: number;
|
||||
sobrenombre: number
|
||||
|
||||
@Column()
|
||||
kiosko: number;
|
||||
kiosko: number
|
||||
|
||||
@OneToMany(
|
||||
(type) => Reservacion,
|
||||
(reservacion) => reservacion.carrito
|
||||
)
|
||||
reservaciones: Reservacion[];
|
||||
reservaciones: Reservacion[]
|
||||
|
||||
@OneToMany(
|
||||
(type) => Equipo,
|
||||
(equipo) => equipo.carrito
|
||||
)
|
||||
equipos: Equipo[];
|
||||
equipos: Equipo[]
|
||||
|
||||
@ManyToOne(
|
||||
(type) => Tipo,
|
||||
(tipo) => tipo.carritos
|
||||
)
|
||||
tipo: Tipo;
|
||||
tipo: Tipo
|
||||
|
||||
@Column()
|
||||
@CreateDateColumn()
|
||||
createdAt: Date
|
||||
|
||||
@Column()
|
||||
@UpdateDateColumn()
|
||||
updatedAt: Date
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
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[]
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
import { Entity, PrimaryColumn, Column, ManyToOne } from 'typeorm'
|
||||
import { Usuario } from './Usuario'
|
||||
import { Operador } from './Operador'
|
||||
import { Equipo } from './Equipo'
|
||||
|
||||
@Entity()
|
||||
export class Log {
|
||||
@PrimaryColumn()
|
||||
id: number
|
||||
|
||||
@Column({ type: 'date' })
|
||||
fecha: string
|
||||
|
||||
@Column()
|
||||
accion: string
|
||||
|
||||
@Column()
|
||||
multa: string
|
||||
|
||||
@ManyToOne(
|
||||
(type) => Usuario,
|
||||
(usuario) => usuario.logs
|
||||
)
|
||||
usuario: Usuario
|
||||
|
||||
@ManyToOne(
|
||||
(type) => Operador,
|
||||
(operador) => operador.logs
|
||||
)
|
||||
operador: Operador
|
||||
|
||||
@ManyToOne(
|
||||
(type) => Equipo,
|
||||
(equipo) => equipo.logs
|
||||
)
|
||||
equipo: Equipo
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Entity, OneToMany } from 'typeorm'
|
||||
import { Catalogo } from './Catalogo'
|
||||
import { Prestamo } from './Prestamo'
|
||||
|
||||
@Entity()
|
||||
export class Mesa extends Catalogo {
|
||||
@OneToMany(
|
||||
(type) => Prestamo,
|
||||
(prestamo) => prestamo.mesa
|
||||
)
|
||||
prestamos: Prestamo[]
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
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'
|
||||
|
||||
@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[]
|
||||
|
||||
hashPassword () {
|
||||
this.secreto = bcrypt.hashSync(this.secreto, 10)
|
||||
}
|
||||
|
||||
checkIfUnencryptedPasswordIsValid (unencryptedPassword: string) {
|
||||
return bcrypt.compareSync(unencryptedPassword, this.secreto)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
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[]
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import { Entity, PrimaryGeneratedColumn, Column, ManyToOne } from 'typeorm'
|
||||
import { Usuario } from './Usuario'
|
||||
import { Reporte } from './Reporte'
|
||||
import { Equipo } from './Equipo'
|
||||
import { Mesa } from './Mesa'
|
||||
|
||||
@Entity()
|
||||
export class Prestamo {
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number
|
||||
|
||||
@Column()
|
||||
activo: boolean
|
||||
|
||||
@Column({ type: 'date' })
|
||||
fechaInicio: string
|
||||
|
||||
@Column({ type: 'date' })
|
||||
fechaFin: 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
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
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[]
|
||||
}
|
||||
@@ -3,51 +3,65 @@ 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;
|
||||
id: number
|
||||
|
||||
@Column({ type: 'date' })
|
||||
fechaInicio: string;
|
||||
fechaInicio: string
|
||||
|
||||
@Column({ type: 'date' })
|
||||
fechaFin: string;
|
||||
fechaFin: string
|
||||
|
||||
@Column()
|
||||
descripcion: string;
|
||||
descripcion: string
|
||||
|
||||
@Column({ type: 'boolean' })
|
||||
uso: boolean;
|
||||
uso: boolean
|
||||
|
||||
@Column({ type: 'boolean' })
|
||||
cancelado: boolean;
|
||||
cancelado: boolean
|
||||
|
||||
@Column({ type: 'boolean' })
|
||||
aceptado: boolean;
|
||||
aceptado: boolean
|
||||
|
||||
@ManyToOne(
|
||||
(type) => Actividad,
|
||||
(actividad) => actividad.reservaciones
|
||||
)
|
||||
actividad: Actividad;
|
||||
actividad: Actividad
|
||||
|
||||
@ManyToOne(
|
||||
(type) => Adscripcion,
|
||||
(adscripcion) => adscripcion.reservaciones
|
||||
)
|
||||
adscripcion: Adscripcion;
|
||||
adscripcion: Adscripcion
|
||||
|
||||
@ManyToOne(
|
||||
(type) => Lugar,
|
||||
(lugar) => lugar.reservaciones
|
||||
)
|
||||
lugar: Lugar;
|
||||
lugar: Lugar
|
||||
|
||||
@ManyToOne(
|
||||
(type) => Carrito,
|
||||
(carrito) => carrito.reservaciones
|
||||
)
|
||||
carrito: Carrito;
|
||||
carrito: Carrito
|
||||
|
||||
@ManyToOne(
|
||||
(type) => Reporte,
|
||||
(reporte) => reporte.reservaciones
|
||||
)
|
||||
reporte: Reporte
|
||||
|
||||
@ManyToOne(
|
||||
(type) => Usuario,
|
||||
(reporte) => reporte.reservaciones
|
||||
)
|
||||
usuario: Usuario
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
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[]
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { Entity, PrimaryGeneratedColumn, Column } from 'typeorm'
|
||||
|
||||
@Entity()
|
||||
export class User {
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number
|
||||
|
||||
@Column()
|
||||
firstName: string
|
||||
|
||||
@Column()
|
||||
lastName: string
|
||||
|
||||
@Column()
|
||||
age: number
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
import {
|
||||
Entity,
|
||||
PrimaryGeneratedColumn,
|
||||
Column,
|
||||
OneToMany,
|
||||
Unique,
|
||||
CreateDateColumn,
|
||||
UpdateDateColumn
|
||||
} from 'typeorm'
|
||||
import {
|
||||
IsDate,
|
||||
IsEmail,
|
||||
Length,
|
||||
IsBoolean,
|
||||
IsString,
|
||||
IsOptional
|
||||
} from 'class-validator'
|
||||
import { Reservacion } from './Reservacion'
|
||||
import { Prestamo } from './Prestamo'
|
||||
import { Log } from './Log'
|
||||
|
||||
@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()
|
||||
@IsString()
|
||||
identificacion: string
|
||||
|
||||
@Column()
|
||||
@IsString()
|
||||
institucion: 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
|
||||
|
||||
@OneToMany(
|
||||
(type) => Reservacion,
|
||||
(reservacion) => reservacion.usuario
|
||||
)
|
||||
reservaciones: Reservacion[]
|
||||
|
||||
@OneToMany(
|
||||
(type) => Prestamo,
|
||||
(prestamo) => prestamo.usuario
|
||||
)
|
||||
prestamos: Prestamo[]
|
||||
|
||||
@OneToMany(
|
||||
(type) => Log,
|
||||
(log) => log.usuario
|
||||
)
|
||||
logs: Log[]
|
||||
}
|
||||
+15
-33
@@ -1,39 +1,21 @@
|
||||
import "reflect-metadata";
|
||||
import { createConnection } from "typeorm";
|
||||
import { User } from "./db/entity/User";
|
||||
import { TipoProblema } from "./db/entity/TipoProblema";
|
||||
import { Ayuda } from "./db/entity/Ayuda";
|
||||
|
||||
import * as express from 'express'
|
||||
import * as bodyParser from 'body-parser'
|
||||
import routes from './routes/index'
|
||||
import { createConnection } from 'typeorm'
|
||||
const PORT = 3000
|
||||
createConnection()
|
||||
.then(async (connection) => {
|
||||
console.log("Inserting a new user into the database...");
|
||||
const user = new User();
|
||||
user.firstName = "Timber";
|
||||
user.lastName = "Saw";
|
||||
user.age = 25;
|
||||
await connection.manager.save(user);
|
||||
console.log("Saved a new user with id: " + user.id);
|
||||
const tipoProblema = new TipoProblema();
|
||||
tipoProblema.nombre = "test";
|
||||
const ayuda = new Ayuda();
|
||||
ayuda.nombre = "test";
|
||||
ayuda.correo = "correo@test";
|
||||
ayuda.solucion = "sdasd";
|
||||
ayuda.descripcion = "daskdjskjdjasda";
|
||||
ayuda.tipoProblema = tipoProblema;
|
||||
const app = express()
|
||||
// configure multer
|
||||
app.use(bodyParser.urlencoded({ extended: false }))
|
||||
app.use(bodyParser.json())
|
||||
|
||||
await connection.manager.save(tipoProblema);
|
||||
await connection.manager.save(ayuda);
|
||||
app.get('/', (req, res) => res.send('Hello World!'))
|
||||
|
||||
console.log("Loading users from the database...");
|
||||
const users = await connection.manager.find(User);
|
||||
const problemas = await connection.manager.find(TipoProblema);
|
||||
const ayudasRep = connection.getRepository(Ayuda);
|
||||
const ayudas = await ayudasRep.find({ relations: ["tipoProblema"] });
|
||||
console.log("Loaded users: ", users);
|
||||
console.log("Loaded users: ", problemas);
|
||||
console.log("Loaded users: ", ayudas);
|
||||
app.use('/', routes)
|
||||
|
||||
console.log("Here you can setup and run express/koa/any other framework.");
|
||||
app.listen(PORT, () =>
|
||||
console.log(`Example app listening at http://localhost:${PORT}`)
|
||||
)
|
||||
})
|
||||
.catch((error) => console.log(error));
|
||||
.catch((error) => console.log('TypeORM connection error: ', error))
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
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
|
||||
@@ -0,0 +1,13 @@
|
||||
import { Router } from 'express'
|
||||
|
||||
import usuario from './usuario'
|
||||
import operador from './operador'
|
||||
import carrito from './carrito'
|
||||
|
||||
const routes = Router()
|
||||
|
||||
routes.use('/operador', operador)
|
||||
routes.use('/usuario', usuario)
|
||||
routes.use('/carrito', carrito)
|
||||
|
||||
export default routes
|
||||
@@ -0,0 +1,15 @@
|
||||
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
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Router } from 'express'
|
||||
import { UsuarioController } from '@src/controller/Usuario'
|
||||
|
||||
const router = Router()
|
||||
|
||||
router.post('/', UsuarioController.create)
|
||||
|
||||
router.get('/', UsuarioController.getAll)
|
||||
|
||||
router.get('/:id([0-9]+)', UsuarioController.getOne)
|
||||
|
||||
export default router
|
||||
Reference in New Issue
Block a user