listo modulo motivo
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import {
|
||||
IsBoolean,
|
||||
IsDateString,
|
||||
IsInt,
|
||||
IsNotEmpty,
|
||||
IsOptional,
|
||||
@@ -20,4 +21,19 @@ export class UpdateModuloDto {
|
||||
@MaxLength(30)
|
||||
@IsOptional()
|
||||
modulo?: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@MaxLength(250)
|
||||
@IsOptional()
|
||||
motivo?: string;
|
||||
|
||||
@IsInt()
|
||||
@IsOptional()
|
||||
numero_alumnos?: number;
|
||||
|
||||
@IsString()
|
||||
@IsDateString()
|
||||
@IsOptional()
|
||||
fecha_creacion?: string;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
} from 'typeorm';
|
||||
import { Carrito } from '../../carrito/entity/carrito.entity';
|
||||
import { Institucion } from '../../institucion/entity/institucion.entity';
|
||||
import { ModuloMotivo } from '../../modulo-motivo/entity/modulo-motivo.entity';
|
||||
|
||||
@Entity()
|
||||
export class Modulo {
|
||||
@@ -31,4 +32,7 @@ export class Modulo {
|
||||
|
||||
@OneToMany(() => Carrito, (carrito) => carrito.modulo)
|
||||
carritos: Carrito[];
|
||||
|
||||
@OneToMany(() => ModuloMotivo, (motivo) => motivo.modulo)
|
||||
motivos: ModuloMotivo[];
|
||||
}
|
||||
|
||||
@@ -136,8 +136,18 @@ export class ModuloController {
|
||||
})
|
||||
update(@Request() req, @Body() body: UpdateModuloDto) {
|
||||
const admin: Operador = req.user.operador;
|
||||
const data = { ...body };
|
||||
|
||||
this.validarUsuarioService.validarAdmin(admin);
|
||||
return this.moduloService.update(admin, body);
|
||||
delete data.modulo;
|
||||
delete data.numero_alumnos;
|
||||
delete data.fecha_creacion;
|
||||
return this.moduloService.update(
|
||||
admin,
|
||||
data,
|
||||
body.motivo,
|
||||
body.numero_alumnos,
|
||||
body.fecha_creacion,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { forwardRef, Module } from '@nestjs/common';
|
||||
import { PassportModule } from '@nestjs/passport';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { ModuloController } from './modulo.controller';
|
||||
@@ -6,11 +6,13 @@ import { ModuloService } from './modulo.service';
|
||||
import { Modulo } from './entity/modulo.entity';
|
||||
import { InformacionModuloView } from './entity/views/informacion-modulo.view';
|
||||
import { MinInformacionModuloView } from './entity/views/min-informacion-modulo.view';
|
||||
import { ModuloMotivoModule } from '../modulo-motivo/modulo-motivo.module';
|
||||
import { InstitucionModule } from '../institucion/institucion.module';
|
||||
import { ValidarUsuarioModule } from '../validar-usuario/validar-usuario.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
forwardRef(() => ModuloMotivoModule),
|
||||
InstitucionModule,
|
||||
PassportModule.register({ defaultStrategy: 'jwt' }),
|
||||
TypeOrmModule.forFeature([
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import {
|
||||
ConflictException,
|
||||
forwardRef,
|
||||
Inject,
|
||||
Injectable,
|
||||
NotFoundException,
|
||||
} from '@nestjs/common';
|
||||
@@ -11,6 +13,7 @@ import { InformacionModuloView } from './entity/views/informacion-modulo.view';
|
||||
import { MinInformacionModuloView } from './entity/views/min-informacion-modulo.view';
|
||||
import { Operador } from '../operador/entity/operador.entity';
|
||||
import { InstitucionService } from '../institucion/institucion.service';
|
||||
import { ModuloMotivoService } from '../modulo-motivo/modulo-motivo.service';
|
||||
|
||||
@Injectable()
|
||||
export class ModuloService {
|
||||
@@ -20,6 +23,8 @@ export class ModuloService {
|
||||
private informacionModuloView: Repository<InformacionModuloView>,
|
||||
@InjectRepository(MinInformacionModuloView)
|
||||
private minInformacionModuloView: Repository<MinInformacionModuloView>,
|
||||
@Inject(forwardRef(() => ModuloMotivoService))
|
||||
private moduloMotivoService: ModuloMotivoService,
|
||||
private institucionService: InstitucionService,
|
||||
) {}
|
||||
|
||||
@@ -125,7 +130,15 @@ export class ModuloService {
|
||||
});
|
||||
}
|
||||
|
||||
update(admin: Operador, attrs: Partial<Modulo>) {
|
||||
update(
|
||||
admin: Operador,
|
||||
attrs: Partial<Modulo>,
|
||||
motivo?: string,
|
||||
numero_alumnos?: number,
|
||||
fecha_creacion?: string,
|
||||
) {
|
||||
if (!motivo || !numero_alumnos || !fecha_creacion)
|
||||
throw new ConflictException('No se mandó toda la información necesaria.');
|
||||
return this.findById(attrs.id_modulo)
|
||||
.then(async (modulo) => {
|
||||
// Valido que el modulo enviado sea del admin que realiza esta acción
|
||||
@@ -140,6 +153,14 @@ export class ModuloService {
|
||||
await this.findModulo(modulo.institucion, attrs.modulo, true);
|
||||
// Asigno valores enviados al objeto
|
||||
Object.assign(modulo, attrs);
|
||||
if (motivo)
|
||||
await this.moduloMotivoService.create(
|
||||
admin,
|
||||
modulo,
|
||||
motivo,
|
||||
numero_alumnos,
|
||||
fecha_creacion,
|
||||
);
|
||||
// Guardar
|
||||
return this.repository.save(modulo);
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user