listo
This commit is contained in:
@@ -20,3 +20,21 @@ 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");
|
||||
|
||||
INSERT INTO dia (dia) VALUES ("Lunes");
|
||||
INSERT INTO dia (dia) VALUES ("Martes");
|
||||
INSERT INTO dia (dia) VALUES ("Miercoles");
|
||||
INSERT INTO dia (dia) VALUES ("Jueves");
|
||||
INSERT INTO dia (dia) VALUES ("Viernes");
|
||||
|
||||
INSERT INTO institucion_dia (id_institucion, id_dia) VALUES (1, 1);
|
||||
INSERT INTO institucion_dia (id_institucion, id_dia) VALUES (1, 2);
|
||||
INSERT INTO institucion_dia (id_institucion, id_dia) VALUES (1, 3);
|
||||
INSERT INTO institucion_dia (id_institucion, id_dia) VALUES (1, 4);
|
||||
INSERT INTO institucion_dia (id_institucion, id_dia) VALUES (1, 5);
|
||||
INSERT INTO institucion_dia (id_institucion, id_dia) VALUES (2, 1);
|
||||
INSERT INTO institucion_dia (id_institucion, id_dia) VALUES (2, 2);
|
||||
INSERT INTO institucion_dia (id_institucion, id_dia) VALUES (2, 3);
|
||||
INSERT INTO institucion_dia (id_institucion, id_dia) VALUES (2, 4);
|
||||
INSERT INTO institucion_dia (id_institucion, id_dia) VALUES (2, 5);
|
||||
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import {
|
||||
IsBoolean,
|
||||
IsMilitaryTime,
|
||||
IsNumber,
|
||||
IsOptional,
|
||||
} from 'class-validator';
|
||||
|
||||
export class InstitucionDiaUpdateDto {
|
||||
@IsNumber()
|
||||
id_institucion_dia: number;
|
||||
|
||||
@IsBoolean()
|
||||
@IsOptional()
|
||||
activo: boolean;
|
||||
|
||||
@IsMilitaryTime()
|
||||
@IsOptional()
|
||||
hora_fin: string;
|
||||
|
||||
@IsMilitaryTime()
|
||||
@IsOptional()
|
||||
hora_inicio: string;
|
||||
}
|
||||
@@ -18,13 +18,13 @@ export class InstitucionDia {
|
||||
@Column({ type: Boolean, nullable: false, default: false })
|
||||
activo: boolean;
|
||||
|
||||
@Column({ type: Date, nullable: false })
|
||||
hora_fin: Date;
|
||||
@Column({ type: String, nullable: false, default: '17:45', length: 5 })
|
||||
hora_fin: string;
|
||||
|
||||
@Column({ type: Date, nullable: false })
|
||||
hora_inicio: Date;
|
||||
@Column({ type: String, nullable: false, default: '09:00', length: 5 })
|
||||
hora_inicio: string;
|
||||
|
||||
@ManyToOne(() => Dia, (dia) => dia.institucionesDias)
|
||||
@ManyToOne(() => Dia, (dia) => dia.institucionesDias, { eager: true })
|
||||
@JoinColumn({ name: 'id_dia' })
|
||||
dia: Dia;
|
||||
|
||||
|
||||
@@ -1,13 +1,26 @@
|
||||
import { Controller, Get, Put } from '@nestjs/common';
|
||||
import { Body, Controller, Get, Put, Query } from '@nestjs/common';
|
||||
import { InstitucionDiaService } from './institucion-dia.service';
|
||||
import { IdInstitucionDto } from '../dto/id-institucion.dto';
|
||||
import { InstitucionDiaUpdateDto } from './dto/institucion-dia-update.dto';
|
||||
|
||||
@Controller('institucion-dia')
|
||||
export class InstitucionDiaController {
|
||||
constructor(private institucionDiaService: InstitucionDiaService) {}
|
||||
|
||||
@Get()
|
||||
get() {}
|
||||
get() {
|
||||
return this.institucionDiaService.findAll();
|
||||
}
|
||||
|
||||
@Get('instituciones_dias')
|
||||
institucionesDias(@Query() query: IdInstitucionDto) {
|
||||
return this.institucionDiaService.findAllByIdInstitucion(
|
||||
Number(query.id_institucion),
|
||||
);
|
||||
}
|
||||
|
||||
@Put()
|
||||
update() {}
|
||||
update(@Body() body: InstitucionDiaUpdateDto) {
|
||||
return this.institucionDiaService.update(body);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,9 +4,10 @@ import { InstitucionDiaController } from './institucion-dia.controller';
|
||||
import { InstitucionDiaService } from './institucion-dia.service';
|
||||
import { InstitucionDia } from './entity/institucion-dia.entity';
|
||||
import { Dia } from './entity/dia.entity';
|
||||
import { InstitucionModule } from '../institucion/institucion.module';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([Dia, InstitucionDia])],
|
||||
imports: [TypeOrmModule.forFeature([Dia, InstitucionDia]), InstitucionModule],
|
||||
controllers: [InstitucionDiaController],
|
||||
providers: [InstitucionDiaService],
|
||||
})
|
||||
|
||||
@@ -2,11 +2,44 @@ import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { InstitucionDia } from './entity/institucion-dia.entity';
|
||||
|
||||
import { InstitucionService } from '../institucion/institucion.service';
|
||||
@Injectable()
|
||||
export class InstitucionDiaService {
|
||||
constructor(
|
||||
@InjectRepository(InstitucionDia)
|
||||
private repository: Repository<InstitucionDia>,
|
||||
private repositoryInstitucionDia: Repository<InstitucionDia>,
|
||||
private institucionService: InstitucionService,
|
||||
) {}
|
||||
|
||||
findAll() {
|
||||
return this.repositoryInstitucionDia.find();
|
||||
}
|
||||
|
||||
findAllByIdInstitucion(id_institucion: number) {
|
||||
return this.institucionService
|
||||
.findById(id_institucion)
|
||||
.then((institucion) =>
|
||||
this.repositoryInstitucionDia.find({ institucion }),
|
||||
);
|
||||
}
|
||||
|
||||
findById(id_institucion_dia: number) {
|
||||
return this.repositoryInstitucionDia
|
||||
.findOne({ id_institucion_dia })
|
||||
.then((institucionDia) => {
|
||||
if (!institucionDia) throw new Error('No existe esta institucion dia.');
|
||||
return institucionDia;
|
||||
});
|
||||
}
|
||||
|
||||
update(attrs: Partial<InstitucionDia>) {
|
||||
return this.findById(attrs.id_institucion_dia)
|
||||
.then((institucionDia) => {
|
||||
Object.assign(institucionDia, attrs);
|
||||
return this.repositoryInstitucionDia.save(institucionDia);
|
||||
})
|
||||
.then((_) => ({
|
||||
message: 'Se actualió correctamente la institucion infracción.',
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user