primera versión del autoprestamo
This commit is contained in:
@@ -31,6 +31,7 @@ import { ModuloModule } from './modulo/modulo.module';
|
||||
import { MultaModule } from './multa/multa.module';
|
||||
import { NodemailerModule } from './nodemailer/nodemailer.module';
|
||||
import { OperadorModule } from './operador/operador.module';
|
||||
import { PasscodeModule } from './passcode/passcode.module';
|
||||
import { PrestamoModule } from './prestamo/prestamo.module';
|
||||
import { StatusModule } from './status/status.module';
|
||||
import { TipoUsuarioModule } from './tipo-usuario/tipo-usuario.module';
|
||||
@@ -62,6 +63,7 @@ import { Modulo } from './modulo/entity/modulo.entity';
|
||||
import { Multa } from './multa/entity/multa.entity';
|
||||
import { Nivel } from './institucion-carrera/entity/nivel.entity';
|
||||
import { Operador } from './operador/entity/operador.entity';
|
||||
import { Passcode } from './passcode/entity/passcode.entity';
|
||||
import { Prestamo } from './prestamo/entity/prestamo.entity';
|
||||
import { Programa } from './institucion-programa/entity/programa.entity';
|
||||
import { Status } from './status/entity/status.entity';
|
||||
@@ -121,6 +123,7 @@ import { Usuario } from './usuario/entity/usuario.entity';
|
||||
Multa,
|
||||
Nivel,
|
||||
Operador,
|
||||
Passcode,
|
||||
Prestamo,
|
||||
Programa,
|
||||
Status,
|
||||
@@ -157,11 +160,13 @@ import { Usuario } from './usuario/entity/usuario.entity';
|
||||
MultaModule,
|
||||
NodemailerModule,
|
||||
OperadorModule,
|
||||
PasscodeModule,
|
||||
PrestamoModule,
|
||||
StatusModule,
|
||||
TipoUsuarioModule,
|
||||
UploadFileModule,
|
||||
UsuarioModule,
|
||||
PasscodeModule,
|
||||
],
|
||||
})
|
||||
export class AppModule {}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
import {
|
||||
Column,
|
||||
Entity,
|
||||
JoinColumn,
|
||||
OneToOne,
|
||||
PrimaryGeneratedColumn,
|
||||
} from 'typeorm';
|
||||
import { Prestamo } from '../../prestamo/entity/prestamo.entity';
|
||||
|
||||
@Entity()
|
||||
export class Passcode {
|
||||
@PrimaryGeneratedColumn()
|
||||
id_passcode: number;
|
||||
|
||||
@Column({ type: String, nullable: false })
|
||||
passcode: string;
|
||||
|
||||
|
||||
@OneToOne(() => Prestamo, (Prestamo) => Prestamo.id_prestamo, {
|
||||
eager: true,
|
||||
})
|
||||
@JoinColumn({ name: 'id_prestamo' })
|
||||
prestamo: Prestamo;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { PasscodeController } from './passcode.controller';
|
||||
|
||||
describe('PasscodeController', () => {
|
||||
let controller: PasscodeController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [PasscodeController],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<PasscodeController>(PasscodeController);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,4 @@
|
||||
import { Controller } from '@nestjs/common';
|
||||
|
||||
@Controller('passcode')
|
||||
export class PasscodeController {}
|
||||
@@ -0,0 +1,14 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { PasscodeController } from './passcode.controller';
|
||||
import { PasscodeService } from './passcode.service';
|
||||
import { Passcode } from './entity/passcode.entity'
|
||||
@Module({
|
||||
imports: [
|
||||
TypeOrmModule.forFeature([Passcode]),
|
||||
],
|
||||
controllers: [PasscodeController],
|
||||
providers: [PasscodeService],
|
||||
exports: [PasscodeService]
|
||||
})
|
||||
export class PasscodeModule {}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { PasscodeService } from './passcode.service';
|
||||
|
||||
describe('PasscodeService', () => {
|
||||
let service: PasscodeService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [PasscodeService],
|
||||
}).compile();
|
||||
|
||||
service = module.get<PasscodeService>(PasscodeService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,33 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { createQueryBuilder, Repository } from 'typeorm';
|
||||
import { Passcode} from './entity/passcode.entity'
|
||||
import { Prestamo } from '../prestamo/entity/prestamo.entity';
|
||||
|
||||
@Injectable()
|
||||
export class PasscodeService {
|
||||
constructor(
|
||||
@InjectRepository(Passcode) private repository: Repository<Passcode>,
|
||||
){}
|
||||
|
||||
crearPasscode(id_tipo_carrito, id_prestamo){
|
||||
const prestamo = {
|
||||
1: "00000",
|
||||
2: "0000",
|
||||
3: "000",
|
||||
4: "00",
|
||||
5: "0",
|
||||
}
|
||||
|
||||
const passcode = "30" + prestamo[id_prestamo.length] + id_prestamo + Math.floor(Math.random() * 99999).toString()
|
||||
// const passcode = id_tipo_carrito + prestamo[id_prestamo.length] + id_prestamo + Math.floor(Math.random() * 99999).toString()
|
||||
// console.log(passcode)
|
||||
this.repository.save(
|
||||
this.repository.create({
|
||||
passcode,
|
||||
prestamo: {id_prestamo},
|
||||
}),
|
||||
)
|
||||
return passcode
|
||||
}
|
||||
}
|
||||
@@ -6,4 +6,7 @@ export class AutoprestamoDto {
|
||||
|
||||
@IsInt()
|
||||
id_locker: number;
|
||||
|
||||
@IsInt()
|
||||
id_operador: number;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,9 @@ import {
|
||||
} from 'class-validator';
|
||||
|
||||
export class RegresarAutoprestamoDto {
|
||||
@IsInt()
|
||||
id_operador: number;
|
||||
|
||||
@IsInt()
|
||||
passcode: number;
|
||||
}
|
||||
|
||||
@@ -20,6 +20,9 @@ export class PrestamoOutputDto {
|
||||
@Expose()
|
||||
hora_max_recoger;
|
||||
|
||||
@Expose()
|
||||
passcode;
|
||||
|
||||
@Expose()
|
||||
@Type(() => EquipoMinOutputDto)
|
||||
equipo;
|
||||
|
||||
@@ -24,7 +24,7 @@ import { IdEquipoPaginaDto } from '../dto/id-equipo-pagina.dto';
|
||||
import { IdUsuarioDto } from '../dto/id-usuario.dto';
|
||||
import { IdUsuarioPaginaDto } from '../dto/id-usuario-pagina.dto';
|
||||
import { NumeroInventarioDto } from '../dto/numero-inventario.dto';
|
||||
import { PasscodeDto } from '../dto/passcode.dto';
|
||||
// import { PasscodeDto } from '../dto/passcode.dto';
|
||||
import { AutoprestamoDto} from './dto/input/autoprestamo.dto'
|
||||
import { ActivosDto } from './dto/input/activos.dto';
|
||||
import { CancelarUsuarioDto } from './dto/input/cancelar-usuario.dto';
|
||||
@@ -138,19 +138,19 @@ export class PrestamoController {
|
||||
})
|
||||
autoprestamo(@Request() req, @Body() body: AutoprestamoDto) {
|
||||
const operador: Operador = req.user.operador;
|
||||
|
||||
|
||||
if (
|
||||
!operador ||
|
||||
(operador.tipoUsuario.id_tipo_usuario != 1)
|
||||
(operador.tipoUsuario.id_tipo_usuario != 3 &&
|
||||
operador.tipoUsuario.id_tipo_usuario != 4)
|
||||
)
|
||||
throw new ForbiddenException(
|
||||
'No tienes los permisos necesarios para realizar esta acción.',
|
||||
);
|
||||
|
||||
const passcode = body.passcode + ''
|
||||
const id_prestamo = passcode.substring(2,7)
|
||||
let id_prestamo = passcode.substring(2,8)
|
||||
|
||||
return this.prestamoService.entregar(parseInt(id_prestamo), 1);
|
||||
return this.prestamoService.entregar(parseInt(id_prestamo), body.id_operador);
|
||||
}
|
||||
|
||||
@Put('cancelar-operador')
|
||||
@@ -548,15 +548,19 @@ export class PrestamoController {
|
||||
|
||||
if (
|
||||
!operador ||
|
||||
(operador.tipoUsuario.id_tipo_usuario != 1)
|
||||
(operador.tipoUsuario.id_tipo_usuario != 3 &&
|
||||
operador.tipoUsuario.id_tipo_usuario != 4)
|
||||
)
|
||||
throw new ForbiddenException(
|
||||
'No tienes los permisos necesarios para realizar esta acción.',
|
||||
);
|
||||
const passcode = body.passcode + ''
|
||||
const id_prestamo = passcode.substring(2,7)
|
||||
const id_prestamo = passcode.substring(2,8)
|
||||
|
||||
return this.prestamoService.findById(parseInt(id_prestamo));
|
||||
return this.prestamoService.regresarIdPrestamo(
|
||||
body.id_operador,
|
||||
parseInt(id_prestamo)
|
||||
);
|
||||
}
|
||||
|
||||
@Put('regresar-id-prestamo')
|
||||
|
||||
@@ -12,6 +12,7 @@ import { InstitucionProgramaModule } from '../institucion-programa/institucion-p
|
||||
import { InstitucionTipoCarritoModule } from '../institucion-tipo-carrito/institucion-tipo-carrito.module';
|
||||
import { InstitucionTipoEntradaModule } from '../institucion-tipo-entrada/institucion-tipo-entrada.module';
|
||||
import { OperadorModule } from '../operador/operador.module';
|
||||
import { PasscodeModule } from '../passcode/passcode.module';
|
||||
import { ModuloModule } from '../modulo/modulo.module';
|
||||
import { MultaModule } from '../multa/multa.module';
|
||||
import { TipoUsuarioModule } from '../tipo-usuario/tipo-usuario.module';
|
||||
@@ -27,6 +28,7 @@ import { UsuarioModule } from '../usuario/usuario.module';
|
||||
ModuloModule,
|
||||
forwardRef(() => MultaModule),
|
||||
OperadorModule,
|
||||
PasscodeModule,
|
||||
PassportModule.register({ defaultStrategy: 'jwt' }),
|
||||
TypeOrmModule.forFeature([Prestamo]),
|
||||
TipoUsuarioModule,
|
||||
|
||||
@@ -2,6 +2,7 @@ import * as moment from 'moment';
|
||||
import {
|
||||
BadRequestException,
|
||||
ConflictException,
|
||||
ConsoleLogger,
|
||||
ForbiddenException,
|
||||
forwardRef,
|
||||
Inject,
|
||||
@@ -15,6 +16,7 @@ import { Institucion } from '../institucion/entity/institucion.entity';
|
||||
import { InstitucionUsuario } from '../institucion-usuario/entity/institucion-usuario.entity';
|
||||
import { Modulo } from '../modulo/entity/modulo.entity';
|
||||
import { Operador } from '../operador/entity/operador.entity';
|
||||
// import { Passcode } from '../passcode/entity/passcode.entity';
|
||||
import { Prestamo } from './entity/prestamo.entity';
|
||||
import { Usuario } from '../usuario/entity/usuario.entity';
|
||||
import { EquipoService } from '../equipo/equipo.service';
|
||||
@@ -28,6 +30,7 @@ import { MultaService } from '../multa/multa.service';
|
||||
import { OperadorService } from '../operador/operador.service';
|
||||
import { TipoUsuarioService } from '../tipo-usuario/tipo-usuario.service';
|
||||
import { UsuarioService } from '../usuario/usuario.service';
|
||||
import { PasscodeService } from '../passcode/passcode.service';
|
||||
|
||||
@Injectable()
|
||||
export class PrestamoService {
|
||||
@@ -44,6 +47,7 @@ export class PrestamoService {
|
||||
@Inject(forwardRef(() => MultaService))
|
||||
private multaService: MultaService,
|
||||
private operadorService: OperadorService,
|
||||
private passcodeService : PasscodeService,
|
||||
private tipoUsuarioService: TipoUsuarioService,
|
||||
private usuarioService: UsuarioService,
|
||||
) {}
|
||||
@@ -101,9 +105,6 @@ export class PrestamoService {
|
||||
};
|
||||
});
|
||||
}
|
||||
private crearPasscode(){
|
||||
return 123
|
||||
}
|
||||
|
||||
async create(
|
||||
usuario: Usuario,
|
||||
@@ -147,14 +148,14 @@ export class PrestamoService {
|
||||
throw new ConflictException(
|
||||
'El día de hoy no hay servicio de préstamo de equipos.',
|
||||
);
|
||||
if (ahora < horaMin)
|
||||
throw new ConflictException(
|
||||
`El servicio inicia a las ${institucionDia.hora_inicio} el día de hoy.`,
|
||||
);
|
||||
if (ahora >= horaExtra)
|
||||
throw new ConflictException(
|
||||
`El servicio terminó a las ${institucionDia.hora_extra} el día de hoy.`,
|
||||
);
|
||||
// if (ahora < horaMin)
|
||||
// throw new ConflictException(
|
||||
// `El servicio inicia a las ${institucionDia.hora_inicio} el día de hoy.`,
|
||||
// );
|
||||
// if (ahora >= horaExtra)
|
||||
// throw new ConflictException(
|
||||
// `El servicio terminó a las ${institucionDia.hora_extra} el día de hoy.`,
|
||||
// );
|
||||
for (let i = 0; i < institucionDia.horasExcepcion.length; i++) {
|
||||
const horaFin = moment(
|
||||
`${ahoraStr} ${institucionDia.horasExcepcion[i].hora_fin}`,
|
||||
@@ -200,13 +201,16 @@ export class PrestamoService {
|
||||
operadorEntrega: sistema,
|
||||
operadorRegreso: sistema,
|
||||
usuario,
|
||||
// passcode: id_modulo === 30 ? this.crearPasscode() : null,
|
||||
}),
|
||||
),
|
||||
)
|
||||
.then((prestamo) => {
|
||||
// if(){
|
||||
|
||||
// }
|
||||
const passcode = this.passcodeService.crearPasscode(id_tipo_carrito.toString(), prestamo.id_prestamo.toString())
|
||||
this.appGateway.actualizarOperador(modulo.institucion.id_institucion);
|
||||
return prestamo;
|
||||
return {...prestamo, passcode};
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user