listo modulo motivo
This commit is contained in:
@@ -12,8 +12,6 @@ import { Socket, Server } from 'socket.io';
|
||||
origin: [
|
||||
// 'http://localhost:3176',
|
||||
// 'http://localhost:3186',
|
||||
// 'http://132.248.80.196:3155',
|
||||
// 'http://132.248.80.196:3185',
|
||||
// 'https://pmodulospcpuma.unam.mx',
|
||||
// 'https://pmodulospcpuma.unam.mx:3015',
|
||||
'https://modulospcpuma.unam.mx',
|
||||
|
||||
@@ -61,6 +61,7 @@ import { InstitucionUsuario } from './institucion-usuario/entity/institucion-usu
|
||||
import { Marca } from './marca/entity/marca.entity';
|
||||
import { Modelo } from './modelo/entity/modelo.entity';
|
||||
import { Modulo } from './modulo/entity/modulo.entity';
|
||||
import { ModuloMotivo } from './modulo-motivo/entity/modulo-motivo.entity';
|
||||
import { Multa } from './multa/entity/multa.entity';
|
||||
import { Nivel } from './institucion-carrera/entity/nivel.entity';
|
||||
import { Operador } from './operador/entity/operador.entity';
|
||||
@@ -93,6 +94,7 @@ import { FullInformacionPrestamoView } from './prestamo/entity/views/full-inform
|
||||
import { PrestamoInformacionView } from './prestamo/entity/views/prestamo-informacion.view';
|
||||
import { InformacionPrestamoView } from './prestamo/entity/views/informacion-prestamo.view';
|
||||
import { FullInformacionUsuarioView } from './usuario/entity/views/full-informacion-usuario.view';
|
||||
import { ModuloMotivoModule } from './modulo-motivo/modulo-motivo.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
@@ -142,6 +144,7 @@ import { FullInformacionUsuarioView } from './usuario/entity/views/full-informac
|
||||
Marca,
|
||||
Modelo,
|
||||
Modulo,
|
||||
ModuloMotivo,
|
||||
Multa,
|
||||
Nivel,
|
||||
Operador,
|
||||
@@ -209,6 +212,7 @@ import { FullInformacionUsuarioView } from './usuario/entity/views/full-informac
|
||||
UploadFileModule,
|
||||
UsuarioModule,
|
||||
ValidarUsuarioModule,
|
||||
ModuloMotivoModule,
|
||||
],
|
||||
})
|
||||
export class AppModule {}
|
||||
|
||||
@@ -16,20 +16,18 @@ export class CarritoMotivoService {
|
||||
private carritoService: CarritoService,
|
||||
) {}
|
||||
|
||||
async create(
|
||||
create(
|
||||
carrito: Carrito,
|
||||
operador: Operador,
|
||||
status: boolean,
|
||||
motivo: string,
|
||||
laboratorioMovil: boolean,
|
||||
) {
|
||||
const ahora = moment();
|
||||
|
||||
// Creo y gurado registro
|
||||
return this.repository.save(
|
||||
this.repository.create({
|
||||
carrito,
|
||||
fecha_creacion: ahora.toDate(),
|
||||
fecha_creacion: moment().toDate(),
|
||||
motivo,
|
||||
operador,
|
||||
status,
|
||||
|
||||
@@ -35,7 +35,9 @@ export class CarritoMotivo {
|
||||
@JoinColumn({ name: 'id_carrito' })
|
||||
carrito: Carrito;
|
||||
|
||||
@ManyToOne(() => Operador, (operador) => operador.motivos, { eager: true })
|
||||
@ManyToOne(() => Operador, (operador) => operador.motivosCarrito, {
|
||||
eager: true,
|
||||
})
|
||||
@JoinColumn({ name: 'id_operador' })
|
||||
operador: Operador;
|
||||
}
|
||||
|
||||
@@ -30,7 +30,9 @@ export class EquipoMotivo {
|
||||
@Column({ type: Number, nullable: true })
|
||||
id_status: number;
|
||||
|
||||
@ManyToOne(() => Operador, (operador) => operador.motivos, { eager: true })
|
||||
@ManyToOne(() => Operador, (operador) => operador.motivosEquipo, {
|
||||
eager: true,
|
||||
})
|
||||
@JoinColumn({ name: 'id_operador' })
|
||||
operador: Operador;
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ import { ValidarUsuarioModule } from '../validar-usuario/validar-usuario.module'
|
||||
CarritoModule,
|
||||
forwardRef(() => EquipoProgramaModule),
|
||||
forwardRef(() => EquipoTipoEntradaModule),
|
||||
forwardRef(() => EquipoMotivoModule),
|
||||
InstitucionModule,
|
||||
InstitucionProgramaModule,
|
||||
InstitucionTipoCarritoModule,
|
||||
@@ -34,7 +35,6 @@ import { ValidarUsuarioModule } from '../validar-usuario/validar-usuario.module'
|
||||
MarcaModule,
|
||||
ModeloModule,
|
||||
ModuloModule,
|
||||
forwardRef(() => EquipoMotivoModule),
|
||||
OperadorModule,
|
||||
PassportModule.register({ defaultStrategy: 'jwt' }),
|
||||
StatusModule,
|
||||
|
||||
@@ -25,11 +25,6 @@ export class UpdateInstitucionDto {
|
||||
@IsOptional()
|
||||
dias_multa_retraso?: number;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@IsOptional()
|
||||
dominio?: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@IsOptional()
|
||||
|
||||
@@ -16,9 +16,6 @@ export class InstitucionOutputDto {
|
||||
@Expose()
|
||||
dias_multa_retraso;
|
||||
|
||||
@Expose()
|
||||
dominio;
|
||||
|
||||
@Expose()
|
||||
institucion;
|
||||
|
||||
|
||||
@@ -6,7 +6,4 @@ export class InstitucionesMinOutputDto {
|
||||
|
||||
@Expose()
|
||||
institucion;
|
||||
|
||||
@Expose()
|
||||
dominio;
|
||||
}
|
||||
|
||||
@@ -7,9 +7,6 @@ export class InstitucionesOutputDto {
|
||||
@Expose()
|
||||
correo;
|
||||
|
||||
@Expose()
|
||||
dominio;
|
||||
|
||||
@Expose()
|
||||
id_institucion;
|
||||
|
||||
|
||||
@@ -25,9 +25,6 @@ export class Institucion {
|
||||
@Column({ type: Number, nullable: false, default: 7 })
|
||||
dias_multa_retraso: number;
|
||||
|
||||
@Column({ type: String, nullable: true, length: 40 })
|
||||
dominio: string;
|
||||
|
||||
@Column({ type: String, nullable: false, length: 150 })
|
||||
institucion: string;
|
||||
|
||||
|
||||
@@ -119,7 +119,6 @@ export class InstitucionController {
|
||||
id_institucion: 200,
|
||||
_activo: true,
|
||||
_dias_multa_retraso: 7,
|
||||
_dominio: '@pcpuma.acatlan.unam.mx',
|
||||
_responsable: '',
|
||||
_telefono: '',
|
||||
_tiempo_entrega: 15,
|
||||
|
||||
@@ -52,7 +52,6 @@ export class InstitucionService {
|
||||
'id_institucion',
|
||||
'activo',
|
||||
'correo',
|
||||
'dominio',
|
||||
'institucion',
|
||||
'responsable',
|
||||
],
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
import { IsNumberString } from 'class-validator';
|
||||
|
||||
export class GetDto {
|
||||
@IsNumberString()
|
||||
id_modulo: string;
|
||||
|
||||
@IsNumberString()
|
||||
pagina: string;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import { Expose, Type } from 'class-transformer';
|
||||
import { OperadorMinOutputDto } from '../../../operador/dto/output/operador-min.dto';
|
||||
|
||||
export class ModuloMotivoOutputDto {
|
||||
@Expose()
|
||||
id_motivo;
|
||||
|
||||
@Expose()
|
||||
fecha_creacion;
|
||||
|
||||
@Expose()
|
||||
motivo;
|
||||
|
||||
@Expose()
|
||||
numero_alumnos;
|
||||
|
||||
@Expose()
|
||||
@Type(() => OperadorMinOutputDto)
|
||||
operador;
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import {
|
||||
Column,
|
||||
Entity,
|
||||
JoinColumn,
|
||||
ManyToOne,
|
||||
PrimaryGeneratedColumn,
|
||||
} from 'typeorm';
|
||||
import { Modulo } from '../../modulo/entity/modulo.entity';
|
||||
import { Operador } from '../../operador/entity/operador.entity';
|
||||
|
||||
@Entity()
|
||||
export class ModuloMotivo {
|
||||
@PrimaryGeneratedColumn()
|
||||
id_motivo: number;
|
||||
|
||||
@Column({ type: Date, nullable: false })
|
||||
fecha_creacion: Date;
|
||||
|
||||
@Column({ type: String, nullable: false, length: 250 })
|
||||
motivo: string;
|
||||
|
||||
@Column({ type: Number, nullable: false })
|
||||
numero_alumnos: number;
|
||||
|
||||
@Column({ type: Number, nullable: true })
|
||||
id_modulo: number;
|
||||
|
||||
@Column({ type: Number, nullable: true })
|
||||
id_operador: number;
|
||||
|
||||
@ManyToOne(() => Modulo, (modulo) => modulo.motivos)
|
||||
@JoinColumn({ name: 'id_modulo' })
|
||||
modulo: Modulo;
|
||||
|
||||
@ManyToOne(() => Operador, (operador) => operador.motivosModulo, {
|
||||
eager: true,
|
||||
})
|
||||
@JoinColumn({ name: 'id_operador' })
|
||||
operador: Operador;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { ModuloMotivoController } from './modulo-motivo.controller';
|
||||
|
||||
describe('ModuloMotivoController', () => {
|
||||
let controller: ModuloMotivoController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [ModuloMotivoController],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<ModuloMotivoController>(ModuloMotivoController);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,45 @@
|
||||
import { Controller, Get, Query, Request, UseGuards } from '@nestjs/common';
|
||||
import { AuthGuard } from '@nestjs/passport';
|
||||
import { ApiBearerAuth, ApiOperation, ApiQuery } from '@nestjs/swagger';
|
||||
import { Serealize } from '../interceptors/serialize.interceptor';
|
||||
import { ModuloMotivoService } from './modulo-motivo.service';
|
||||
import { ValidarUsuarioService } from '../validar-usuario/validar-usuario.service';
|
||||
import { Operador } from '../operador/entity/operador.entity';
|
||||
import { GetDto } from './dto/input/get.dto';
|
||||
import { ModuloMotivoOutputDto } from './dto/output/modulo-motivo.dto';
|
||||
|
||||
@Controller('modulo-motivo')
|
||||
export class ModuloMotivoController {
|
||||
constructor(
|
||||
private moduloMotivoService: ModuloMotivoService,
|
||||
private validarUsuarioService: ValidarUsuarioService,
|
||||
) {}
|
||||
|
||||
@Serealize(ModuloMotivoOutputDto)
|
||||
@Get()
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
@ApiOperation({
|
||||
description:
|
||||
'Endpoint que retorna 25 cambios de status que ha tenido un carrito dependiendo de la página en la que se encuentra el alumno.',
|
||||
})
|
||||
@ApiBearerAuth('jwt')
|
||||
@ApiQuery({
|
||||
description: 'Id del carrito.',
|
||||
name: 'id_carrito',
|
||||
type: 'string',
|
||||
})
|
||||
@ApiQuery({
|
||||
description: 'Página en la que se encuentra el usuario.',
|
||||
name: 'pagina',
|
||||
type: 'string',
|
||||
})
|
||||
get(@Request() req, @Query() query: GetDto) {
|
||||
const operador: Operador = req.user.operador;
|
||||
|
||||
this.validarUsuarioService.validarAdminOperador(operador);
|
||||
return this.moduloMotivoService.findAllByIdModulo(
|
||||
parseInt(query.id_modulo),
|
||||
parseInt(query.pagina),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import { forwardRef, Module } from '@nestjs/common';
|
||||
import { PassportModule } from '@nestjs/passport';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { ModuloMotivoController } from './modulo-motivo.controller';
|
||||
import { ModuloMotivoService } from './modulo-motivo.service';
|
||||
import { ModuloMotivo } from './entity/modulo-motivo.entity';
|
||||
import { ModuloModule } from '../modulo/modulo.module';
|
||||
import { ValidarUsuarioModule } from '../validar-usuario/validar-usuario.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
forwardRef(() => ModuloModule),
|
||||
PassportModule.register({ defaultStrategy: 'jwt' }),
|
||||
TypeOrmModule.forFeature([ModuloMotivo]),
|
||||
ValidarUsuarioModule,
|
||||
],
|
||||
controllers: [ModuloMotivoController],
|
||||
providers: [ModuloMotivoService],
|
||||
exports: [ModuloMotivoService],
|
||||
})
|
||||
export class ModuloMotivoModule {}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { ModuloMotivoService } from './modulo-motivo.service';
|
||||
|
||||
describe('ModuloMotivoService', () => {
|
||||
let service: ModuloMotivoService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [ModuloMotivoService],
|
||||
}).compile();
|
||||
|
||||
service = module.get<ModuloMotivoService>(ModuloMotivoService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,46 @@
|
||||
import * as moment from 'moment';
|
||||
import { forwardRef, Inject, Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { Modulo } from '../modulo/entity/modulo.entity';
|
||||
import { ModuloMotivo } from './entity/modulo-motivo.entity';
|
||||
import { Operador } from '../operador/entity/operador.entity';
|
||||
import { ModuloService } from '../modulo/modulo.service';
|
||||
|
||||
@Injectable()
|
||||
export class ModuloMotivoService {
|
||||
constructor(
|
||||
@InjectRepository(ModuloMotivo)
|
||||
private repository: Repository<ModuloMotivo>,
|
||||
@Inject(forwardRef(() => ModuloService))
|
||||
private moduloService: ModuloService,
|
||||
) {}
|
||||
|
||||
create(
|
||||
operador: Operador,
|
||||
modulo: Modulo,
|
||||
motivo: string,
|
||||
numero_alumnos: number,
|
||||
fecha_creacion: string,
|
||||
) {
|
||||
return this.repository.save(
|
||||
this.repository.create({
|
||||
motivo,
|
||||
numero_alumnos,
|
||||
operador,
|
||||
modulo,
|
||||
fecha_creacion: moment(fecha_creacion).toDate(),
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
findAllByIdModulo(id_modulo: number, pagina: number) {
|
||||
return this.moduloService.findById(id_modulo).then((modulo) =>
|
||||
this.repository.findAndCount({
|
||||
where: { modulo },
|
||||
skip: (pagina - 1) * 25,
|
||||
take: 25,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
})
|
||||
|
||||
@@ -7,7 +7,9 @@ import {
|
||||
PrimaryGeneratedColumn,
|
||||
} from 'typeorm';
|
||||
import { Institucion } from '../../institucion/entity/institucion.entity';
|
||||
import { CarritoMotivo } from '../../carrito-motivo/entity/carrito-motivo.entity';
|
||||
import { EquipoMotivo } from '../../equipo-motivo/entity/equipo-motivo.entity';
|
||||
import { ModuloMotivo } from '../../modulo-motivo/entity/modulo-motivo.entity';
|
||||
import { Multa } from '../../multa/entity/multa.entity';
|
||||
import { Prestamo } from '../../prestamo/entity/prestamo.entity';
|
||||
import { TipoUsuario } from '../../tipo-usuario/entity/tipo-usuario.entity';
|
||||
@@ -46,8 +48,14 @@ export class Operador {
|
||||
@JoinColumn({ name: 'id_tipo_usuario' })
|
||||
tipoUsuario: TipoUsuario;
|
||||
|
||||
@OneToMany(() => CarritoMotivo, (motivo) => motivo.operador)
|
||||
motivosCarrito: CarritoMotivo[];
|
||||
|
||||
@OneToMany(() => EquipoMotivo, (motivo) => motivo.operador)
|
||||
motivos: EquipoMotivo[];
|
||||
motivosEquipo: EquipoMotivo[];
|
||||
|
||||
@OneToMany(() => ModuloMotivo, (motivo) => motivo.operador)
|
||||
motivosModulo: ModuloMotivo[];
|
||||
|
||||
@OneToMany(() => Multa, (multa) => multa.operadorMulta)
|
||||
multas: Multa[];
|
||||
|
||||
Reference in New Issue
Block a user