institucion infraccion listo
This commit is contained in:
parent
bce48bf1c6
commit
6519c71a6f
22
catalogos.sql
Normal file
22
catalogos.sql
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
INSERT INTO institucion (institucion, logo) VALUES ("Facultad de Arquitectura", "url");
|
||||||
|
INSERT INTO institucion (institucion, logo) VALUES ("FES Acatlán", "url");
|
||||||
|
|
||||||
|
INSERT INTO carrera (carrera, id_institucion) VALUES ("Matemáticas Aplicadas y Computación", 2);
|
||||||
|
INSERT INTO carrera (carrera, id_institucion) VALUES ("Arquitectura", 1);
|
||||||
|
|
||||||
|
INSERT INTO status (status) VALUES ("Activo");
|
||||||
|
INSERT INTO status (status) VALUES ("Apartado");
|
||||||
|
INSERT INTO status (status) VALUES ("En uso");
|
||||||
|
INSERT INTO status (status) VALUES ("Desactivado");
|
||||||
|
INSERT INTO status (status) VALUES ("Cargando");
|
||||||
|
INSERT INTO status (status) VALUES ("Revisar");
|
||||||
|
INSERT INTO status (status) VALUES ("Reparación");
|
||||||
|
INSERT INTO status (status) VALUES ("Mantenimiento");
|
||||||
|
|
||||||
|
INSERT INTO tipo_usuario (tipo_usuario) VALUES ("Sistema");
|
||||||
|
INSERT INTO tipo_usuario (tipo_usuario) VALUES ("Super Admin");
|
||||||
|
INSERT INTO tipo_usuario (tipo_usuario) VALUES ("Admin");
|
||||||
|
INSERT INTO tipo_usuario (tipo_usuario) VALUES ("Operador");
|
||||||
|
INSERT INTO tipo_usuario (tipo_usuario) VALUES ("Profesor");
|
||||||
|
INSERT INTO tipo_usuario (tipo_usuario) VALUES ("Alumno");
|
||||||
|
INSERT INTO tipo_usuario (tipo_usuario) VALUES ("Posgrado");
|
@ -0,0 +1,6 @@
|
|||||||
|
import { IsString } from 'class-validator';
|
||||||
|
|
||||||
|
export class InstitucionInfraccionCreateDto {
|
||||||
|
@IsString()
|
||||||
|
infraccion: string;
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
import { IsNumber } from 'class-validator';
|
||||||
|
|
||||||
|
export class InstitucionInfraccionUpdateDto {
|
||||||
|
@IsNumber()
|
||||||
|
id_institucion_infraccion: number;
|
||||||
|
|
||||||
|
@IsNumber()
|
||||||
|
dias_multa: number;
|
||||||
|
}
|
@ -21,6 +21,7 @@ export class InstitucionInfraccion {
|
|||||||
@ManyToOne(
|
@ManyToOne(
|
||||||
() => Infraccion,
|
() => Infraccion,
|
||||||
(infraccion) => infraccion.institucionInfracciones,
|
(infraccion) => infraccion.institucionInfracciones,
|
||||||
|
{ eager: true },
|
||||||
)
|
)
|
||||||
@JoinColumn({ name: 'id_infraccion' })
|
@JoinColumn({ name: 'id_infraccion' })
|
||||||
infraccion: Infraccion;
|
infraccion: Infraccion;
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
import { Controller, Get, Put } from '@nestjs/common';
|
import { Body, Controller, Get, Post, Put, Query } from '@nestjs/common';
|
||||||
import { InstitucionInfraccionService } from './institucion-infraccion.service';
|
import { InstitucionInfraccionService } from './institucion-infraccion.service';
|
||||||
|
import { IdInstitucionDto } from '../dto/id-institucion.dto';
|
||||||
|
import { InstitucionInfraccionCreateDto } from './dto/institucion-infraccion-create.dto';
|
||||||
|
import { InstitucionInfraccionUpdateDto } from './dto/institucion-infraccion-update.dto';
|
||||||
|
|
||||||
@Controller('institucion-infraccion')
|
@Controller('institucion-infraccion')
|
||||||
export class InstitucionInfraccionController {
|
export class InstitucionInfraccionController {
|
||||||
@ -7,9 +10,25 @@ export class InstitucionInfraccionController {
|
|||||||
private institucionInfraccionService: InstitucionInfraccionService,
|
private institucionInfraccionService: InstitucionInfraccionService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
@Post()
|
||||||
|
create(@Body() body: InstitucionInfraccionCreateDto) {
|
||||||
|
return this.institucionInfraccionService.create(body.infraccion);
|
||||||
|
}
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
get() {}
|
get() {
|
||||||
|
return this.institucionInfraccionService.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get('institucion_infracciones')
|
||||||
|
institucionInfracciones(@Query() query: IdInstitucionDto) {
|
||||||
|
return this.institucionInfraccionService.findAllByIdInstitucion(
|
||||||
|
Number(query.id_institucion),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@Put()
|
@Put()
|
||||||
update() {}
|
update(@Body() body: InstitucionInfraccionUpdateDto) {
|
||||||
|
return this.institucionInfraccionService.update(body);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,9 +4,13 @@ import { InstitucionInfraccionController } from './institucion-infraccion.contro
|
|||||||
import { InstitucionInfraccionService } from './institucion-infraccion.service';
|
import { InstitucionInfraccionService } from './institucion-infraccion.service';
|
||||||
import { Infraccion } from './entity/infraccion.entity';
|
import { Infraccion } from './entity/infraccion.entity';
|
||||||
import { InstitucionInfraccion } from './entity/institucion-infraccion.entity';
|
import { InstitucionInfraccion } from './entity/institucion-infraccion.entity';
|
||||||
|
import { InstitucionModule } from '../institucion/institucion.module';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [TypeOrmModule.forFeature([Infraccion, InstitucionInfraccion])],
|
imports: [
|
||||||
|
TypeOrmModule.forFeature([Infraccion, InstitucionInfraccion]),
|
||||||
|
InstitucionModule,
|
||||||
|
],
|
||||||
controllers: [InstitucionInfraccionController],
|
controllers: [InstitucionInfraccionController],
|
||||||
providers: [InstitucionInfraccionService],
|
providers: [InstitucionInfraccionService],
|
||||||
})
|
})
|
||||||
|
@ -1,12 +1,78 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
import {
|
||||||
|
ConflictException,
|
||||||
|
Injectable,
|
||||||
|
NotFoundException,
|
||||||
|
} from '@nestjs/common';
|
||||||
import { InjectRepository } from '@nestjs/typeorm';
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
import { Repository } from 'typeorm';
|
import { Repository } from 'typeorm';
|
||||||
import { InstitucionInfraccion } from './entity/institucion-infraccion.entity';
|
import { InstitucionInfraccion } from './entity/institucion-infraccion.entity';
|
||||||
|
import { Infraccion } from './entity/infraccion.entity';
|
||||||
|
import { InstitucionService } from 'src/institucion/institucion.service';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class InstitucionInfraccionService {
|
export class InstitucionInfraccionService {
|
||||||
constructor(
|
constructor(
|
||||||
@InjectRepository(InstitucionInfraccion)
|
@InjectRepository(InstitucionInfraccion)
|
||||||
private repository: Repository<InstitucionInfraccion>,
|
private repositoryInstitucionInfraccion: Repository<InstitucionInfraccion>,
|
||||||
|
@InjectRepository(Infraccion)
|
||||||
|
private repositoryInfraccion: Repository<Infraccion>,
|
||||||
|
private institucionService: InstitucionService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
create(infraccion: string) {
|
||||||
|
return this.repositoryInfraccion
|
||||||
|
.findOne({ infraccion })
|
||||||
|
.then((existeInfraccion) => {
|
||||||
|
if (existeInfraccion)
|
||||||
|
throw new ConflictException('Ya existe esta infracción.');
|
||||||
|
return this.repositoryInfraccion.save(
|
||||||
|
this.repositoryInfraccion.create({ infraccion }),
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.then(async (infraccion) => {
|
||||||
|
const instituciones = await this.institucionService.findAll();
|
||||||
|
|
||||||
|
for (let i = 0; i < instituciones.length; i++)
|
||||||
|
await this.repositoryInstitucionInfraccion.save(
|
||||||
|
this.repositoryInstitucionInfraccion.create({
|
||||||
|
infraccion,
|
||||||
|
institucion: instituciones[i],
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
return { message: 'Se creo creo correctamente la infracción.' };
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
findAll() {
|
||||||
|
return this.repositoryInfraccion.find();
|
||||||
|
}
|
||||||
|
|
||||||
|
findAllByIdInstitucion(id_institucion: number) {
|
||||||
|
return this.institucionService
|
||||||
|
.findById(id_institucion)
|
||||||
|
.then((institucion) =>
|
||||||
|
this.repositoryInstitucionInfraccion.find({ institucion }),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
findById(id_institucion_infraccion: number) {
|
||||||
|
return this.repositoryInstitucionInfraccion
|
||||||
|
.findOne({ id_institucion_infraccion })
|
||||||
|
.then((institucionInfraccion) => {
|
||||||
|
if (!institucionInfraccion)
|
||||||
|
throw new NotFoundException('No existe esta institucion infracción.');
|
||||||
|
return institucionInfraccion;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
update(attrs: Partial<InstitucionInfraccion>) {
|
||||||
|
return this.findById(attrs.id_institucion_infraccion)
|
||||||
|
.then((institucionInfraccion) => {
|
||||||
|
Object.assign(institucionInfraccion, attrs);
|
||||||
|
return this.repositoryInstitucionInfraccion.save(institucionInfraccion);
|
||||||
|
})
|
||||||
|
.then((_) => ({
|
||||||
|
message: 'Se actualió correctamente la institucion infracción.',
|
||||||
|
}));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,14 +41,13 @@ export class InstitucionTipoCarritoService {
|
|||||||
.then(async (tipoCarrito) => {
|
.then(async (tipoCarrito) => {
|
||||||
const instituciones = await this.institucionService.findAll();
|
const instituciones = await this.institucionService.findAll();
|
||||||
|
|
||||||
for (let i = 0; i < instituciones.length; i++) {
|
for (let i = 0; i < instituciones.length; i++)
|
||||||
await this.repositoryInstitucionTipoCarrito.save(
|
await this.repositoryInstitucionTipoCarrito.save(
|
||||||
this.repositoryInstitucionTipoCarrito.create({
|
this.repositoryInstitucionTipoCarrito.create({
|
||||||
tipoCarrito,
|
tipoCarrito,
|
||||||
institucion: instituciones[i],
|
institucion: instituciones[i],
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
|
||||||
return { message: 'Se creo correctamente el tipo carrito.' };
|
return { message: 'Se creo correctamente el tipo carrito.' };
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user