organizacion de institucion y modulo
This commit is contained in:
parent
594af0cde9
commit
29bb3fe79b
@ -35,7 +35,7 @@ import { Equipo } from './equipo/equipo.entity';
|
||||
import { EquipoTipoEntrada } from './equipo-tipo-entrada/equipo-tipo-entrada.entity';
|
||||
import { HoraExcepcion } from './hora-excepcion/hora-excepcion.entity';
|
||||
import { Infraccion } from './infraccion/infraccion.entity';
|
||||
import { Institucion } from './institucion/institucion.entity';
|
||||
import { Institucion } from './institucion/entity/institucion.entity';
|
||||
import { InstitucionDia } from './institucion-dia/institucion-dia.entity';
|
||||
import { InstitucionInfraccion } from './institucion-infraccion/institucion-infraccion.entity';
|
||||
import { Modulo } from './modulo/entity/modulo.entity';
|
||||
|
@ -6,7 +6,7 @@ import {
|
||||
ManyToOne,
|
||||
JoinColumn,
|
||||
} from 'typeorm';
|
||||
import { Institucion } from '../institucion/institucion.entity';
|
||||
import { Institucion } from '../institucion/entity/institucion.entity';
|
||||
import { Usuario } from '../usuario/usuario.entity';
|
||||
import { CarreraPrograma } from '../carrera-programa/carrera-programa.entity';
|
||||
|
||||
|
@ -6,7 +6,7 @@ import {
|
||||
ManyToOne,
|
||||
JoinColumn,
|
||||
} from 'typeorm';
|
||||
import { Institucion } from '../institucion/institucion.entity';
|
||||
import { Institucion } from '../institucion/entity/institucion.entity';
|
||||
import { Dia } from '../dia/dia.entity';
|
||||
import { HoraExcepcion } from '../hora-excepcion/hora-excepcion.entity';
|
||||
|
||||
@ -24,7 +24,7 @@ export class InstitucionDia {
|
||||
@Column()
|
||||
activo: boolean;
|
||||
|
||||
@ManyToOne(() => Institucion, (institucion) => institucion.institucionesDias)
|
||||
@ManyToOne(() => Institucion, (institucion) => institucion.institucionDias)
|
||||
@JoinColumn({ name: 'id_institucion' })
|
||||
institucion: Institucion;
|
||||
|
||||
|
@ -7,7 +7,7 @@ import {
|
||||
JoinColumn,
|
||||
} from 'typeorm';
|
||||
import { Infraccion } from '../infraccion/infraccion.entity';
|
||||
import { Institucion } from '../institucion/institucion.entity';
|
||||
import { Institucion } from '../institucion/entity/institucion.entity';
|
||||
import { Multa } from '../multa/multa.entity';
|
||||
|
||||
@Entity()
|
||||
|
@ -1,16 +1,19 @@
|
||||
import { Entity, Column, PrimaryGeneratedColumn, OneToMany } from 'typeorm';
|
||||
import { InstitucionDia } from '../institucion-dia/institucion-dia.entity';
|
||||
import { InstitucionInfraccion } from '../institucion-infraccion/institucion-infraccion.entity';
|
||||
import { Carrera } from '../carrera/carrera.entity';
|
||||
import { Modulo } from '../modulo/entity/modulo.entity';
|
||||
import { Operador } from '../operador/operador.entity';
|
||||
import { Usuario } from '../usuario/usuario.entity';
|
||||
import { Column, Entity, OneToMany, PrimaryGeneratedColumn } from 'typeorm';
|
||||
import { Carrera } from '../../carrera/carrera.entity';
|
||||
import { InstitucionDia } from '../../institucion-dia/institucion-dia.entity';
|
||||
import { InstitucionInfraccion } from '../../institucion-infraccion/institucion-infraccion.entity';
|
||||
import { Modulo } from '../../modulo/entity/modulo.entity';
|
||||
import { Operador } from '../../operador/operador.entity';
|
||||
import { Usuario } from '../../usuario/usuario.entity';
|
||||
|
||||
@Entity()
|
||||
export class Institucion {
|
||||
@PrimaryGeneratedColumn()
|
||||
id_institucion: number;
|
||||
|
||||
@Column()
|
||||
dias_multa_retraso: number;
|
||||
|
||||
@Column()
|
||||
institucion: string;
|
||||
|
||||
@ -23,14 +26,14 @@ export class Institucion {
|
||||
@Column()
|
||||
tiempo_recoger: number;
|
||||
|
||||
@Column()
|
||||
dias_multa_retraso: number;
|
||||
@OneToMany(() => Carrera, (carrera) => carrera.institucion)
|
||||
carreras: Carrera[];
|
||||
|
||||
@OneToMany(
|
||||
() => InstitucionDia,
|
||||
(institucionDia) => institucionDia.institucion,
|
||||
)
|
||||
institucionesDias: InstitucionDia[];
|
||||
institucionDias: InstitucionDia[];
|
||||
|
||||
@OneToMany(
|
||||
() => InstitucionInfraccion,
|
||||
@ -41,9 +44,6 @@ export class Institucion {
|
||||
@OneToMany(() => Modulo, (modulo) => modulo.institucion)
|
||||
modulos: Modulo[];
|
||||
|
||||
@OneToMany(() => Carrera, (carrera) => carrera.institucion)
|
||||
carreras: Carrera[];
|
||||
|
||||
@OneToMany(() => Operador, (operador) => operador.institucion)
|
||||
operadores: Operador[];
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { InstitucionController } from './institucion.controller';
|
||||
import { Institucion } from './institucion.entity';
|
||||
import { InstitucionService } from './institucion.service';
|
||||
import { Institucion } from './entity/institucion.entity';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([Institucion])],
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { Repository } from 'typeorm';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Institucion } from './institucion.entity';
|
||||
import { Institucion } from './entity/institucion.entity';
|
||||
|
||||
@Injectable()
|
||||
export class InstitucionService {
|
||||
|
@ -1,25 +1,25 @@
|
||||
import {
|
||||
Entity,
|
||||
Column,
|
||||
PrimaryGeneratedColumn,
|
||||
OneToMany,
|
||||
ManyToOne,
|
||||
Entity,
|
||||
JoinColumn,
|
||||
ManyToOne,
|
||||
OneToMany,
|
||||
PrimaryGeneratedColumn,
|
||||
} from 'typeorm';
|
||||
import { Carrito } from '../../carrito/carrito.entity';
|
||||
import { Institucion } from '../../institucion/institucion.entity';
|
||||
import { Institucion } from '../../institucion/entity/institucion.entity';
|
||||
|
||||
@Entity()
|
||||
export class Modulo {
|
||||
@PrimaryGeneratedColumn()
|
||||
id_modulo: number;
|
||||
|
||||
@Column({ type: String, nullable: false, length: 50 })
|
||||
modulo: string;
|
||||
|
||||
@Column({ type: Boolean, nullable: false, default: false })
|
||||
activo: boolean;
|
||||
|
||||
@Column({ type: String, nullable: false, length: 50 })
|
||||
modulo: string;
|
||||
|
||||
@ManyToOne(() => Institucion, (institucion) => institucion.modulos, {
|
||||
eager: true,
|
||||
})
|
||||
|
@ -8,23 +8,23 @@ import { ModuloUpdateDto } from './dto/modulo-update.dto';
|
||||
export class ModuloController {
|
||||
constructor(private moduloService: ModuloService) {}
|
||||
|
||||
@Get('')
|
||||
@Post()
|
||||
create(@Body() body: ModuloCrearDto) {
|
||||
return this.moduloService.create(body.id_institucion, body.modulo);
|
||||
}
|
||||
|
||||
@Get()
|
||||
get() {
|
||||
return this.moduloService.findAll();
|
||||
}
|
||||
|
||||
@Get('modulos')
|
||||
modulosInstitucion(@Query() query: IdInstitucionDto) {
|
||||
modulos(@Query() query: IdInstitucionDto) {
|
||||
return this.moduloService.findAllByIdInstitucion(
|
||||
Number(query.id_institucion),
|
||||
);
|
||||
}
|
||||
|
||||
@Post()
|
||||
create(@Body() body: ModuloCrearDto) {
|
||||
return this.moduloService.create(body.id_institucion, body.modulo);
|
||||
}
|
||||
|
||||
@Put()
|
||||
update(@Body() body: ModuloUpdateDto) {
|
||||
return this.moduloService.update(body);
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { ModuloController } from './modulo.controller';
|
||||
import { Modulo } from './entity/modulo.entity';
|
||||
import { ModuloService } from './modulo.service';
|
||||
import { Modulo } from './entity/modulo.entity';
|
||||
import { InstitucionModule } from '../institucion/institucion.module';
|
||||
|
||||
@Module({
|
||||
|
@ -5,8 +5,8 @@ import {
|
||||
} from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { Modulo } from './entity/modulo.entity';
|
||||
import { InstitucionService } from '../institucion/institucion.service';
|
||||
import { Modulo } from './entity/modulo.entity';
|
||||
|
||||
@Injectable()
|
||||
export class ModuloService {
|
||||
@ -15,23 +15,6 @@ export class ModuloService {
|
||||
private institucionService: InstitucionService,
|
||||
) {}
|
||||
|
||||
findById(id_modulo: number) {
|
||||
return this.moduloRepository.findOne({ id_modulo }).then((modulo) => {
|
||||
if (!modulo) throw new NotFoundException('No existe este módulo.');
|
||||
return modulo;
|
||||
});
|
||||
}
|
||||
|
||||
findAll() {
|
||||
return this.moduloRepository.find();
|
||||
}
|
||||
|
||||
findAllByIdInstitucion(id_institucion: number) {
|
||||
return this.institucionService
|
||||
.findById(id_institucion)
|
||||
.then((institucion) => this.moduloRepository.find({ institucion }));
|
||||
}
|
||||
|
||||
async create(id_institucion: number, modulo: string) {
|
||||
const institucion = await this.institucionService.findById(id_institucion);
|
||||
const nuevoModulo = this.moduloRepository.create({
|
||||
@ -51,6 +34,23 @@ export class ModuloService {
|
||||
.then(() => ({ message: 'Se creo correctamente el módulo.' }));
|
||||
}
|
||||
|
||||
findAll() {
|
||||
return this.moduloRepository.find();
|
||||
}
|
||||
|
||||
findAllByIdInstitucion(id_institucion: number) {
|
||||
return this.institucionService
|
||||
.findById(id_institucion)
|
||||
.then((institucion) => this.moduloRepository.find({ institucion }));
|
||||
}
|
||||
|
||||
findById(id_modulo: number) {
|
||||
return this.moduloRepository.findOne({ id_modulo }).then((modulo) => {
|
||||
if (!modulo) throw new NotFoundException('No existe este módulo.');
|
||||
return modulo;
|
||||
});
|
||||
}
|
||||
|
||||
async update(attrs: Partial<Modulo>) {
|
||||
const modulo = await this.findById(attrs.id_modulo);
|
||||
|
||||
|
@ -6,7 +6,7 @@ import {
|
||||
ManyToOne,
|
||||
JoinColumn,
|
||||
} from 'typeorm';
|
||||
import { Institucion } from '../institucion/institucion.entity';
|
||||
import { Institucion } from '../institucion/entity/institucion.entity';
|
||||
import { Motivo } from '../motivo/motivo.entity';
|
||||
import { Prestamo } from '../prestamo/prestamo.entity';
|
||||
import { TipoUsuario } from '../tipo-usuario/tipo-usuario.entity';
|
||||
|
@ -7,7 +7,7 @@ import {
|
||||
JoinColumn,
|
||||
} from 'typeorm';
|
||||
import { Carrera } from '../carrera/carrera.entity';
|
||||
import { Institucion } from '../institucion/institucion.entity';
|
||||
import { Institucion } from '../institucion/entity/institucion.entity';
|
||||
import { Prestamo } from '../prestamo/prestamo.entity';
|
||||
import { TipoUsuario } from '../tipo-usuario/tipo-usuario.entity';
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user