usando operador de token en put prestamo

This commit is contained in:
xXpuma99Xx
2022-09-28 21:43:17 -05:00
parent 5f9d98f23b
commit 6c16999cc6
6 changed files with 17 additions and 50 deletions
@@ -1,9 +1,6 @@
import { IsInt, IsNotEmpty, IsString, MaxLength } from 'class-validator';
export class CancelarOperadorDto {
@IsInt()
id_operador: number;
@IsInt()
id_prestamo: number;
-3
View File
@@ -1,9 +1,6 @@
import { IsInt } from 'class-validator';
export class EntregarDto {
@IsInt()
id_operador: number;
@IsInt()
id_prestamo: number;
}
@@ -7,9 +7,6 @@ import {
} from 'class-validator';
export class RegresarIdPrestamoDto {
@IsInt()
id_operador: number;
@IsInt()
id_prestamo: number;
@@ -7,9 +7,6 @@ import {
} from 'class-validator';
export class RegresarNumeroInventarioDto {
@IsInt()
id_operador: number;
@IsString()
numero_inventario: string;
+6 -13
View File
@@ -127,7 +127,7 @@ export class PrestamoController {
@ApiBody({
description: 'Ambas variables son obligatorias.',
examples: {
ejemplo: { value: { id_operador: 1, id_prestamo: 1, motivo: '' } },
ejemplo: { value: { id_prestamo: 1, motivo: '' } },
},
})
cancelarOperador(@Request() req, @Body() body: CancelarOperadorDto) {
@@ -135,8 +135,8 @@ export class PrestamoController {
this.validarUsuarioService.validarAdminOperador(operador);
return this.prestamoService.cancelarOperador(
operador,
body.id_prestamo,
body.id_operador,
body.motivo,
);
}
@@ -167,13 +167,13 @@ export class PrestamoController {
@ApiBearerAuth('jwt')
@ApiBody({
description: 'Ambas variables son obligatorias.',
examples: { ejemplo: { value: { id_operador: 4, id_prestamo: 1 } } },
examples: { ejemplo: { value: { id_prestamo: 1 } } },
})
entregar(@Request() req, @Body() body: EntregarDto) {
const operador: Operador = req.user.operador;
this.validarUsuarioService.validarAdminOperador(operador);
return this.prestamoService.entregar(body.id_prestamo, body.id_operador);
return this.prestamoService.entregar(operador, body.id_prestamo);
}
@Serealize(PrestamosOutputDto)
@@ -424,7 +424,6 @@ export class PrestamoController {
examples: {
ejemplo: {
value: {
id_operador: 4,
id_prestamo: 1,
_descripcion: '',
_id_institucion_infraccion: 603,
@@ -437,7 +436,7 @@ export class PrestamoController {
this.validarUsuarioService.validarAdminOperador(operador);
return this.prestamoService.regresarIdPrestamo(
body.id_operador,
operador,
body.id_prestamo,
body.descripcion,
body.id_institucion_infraccion,
@@ -453,7 +452,6 @@ export class PrestamoController {
examples: {
ejemplo: {
value: {
id_operador: 4,
numero_inventario: '',
_descripcion: '',
_id_institucion_infraccion: 603,
@@ -469,15 +467,10 @@ export class PrestamoController {
this.validarUsuarioService.validarAdminOperador(operador);
return this.prestamoService.regresarNumeroInventario(
body.id_operador,
operador,
body.numero_inventario,
body.descripcion,
body.id_institucion_infraccion,
);
}
// @Get('reporte')
// @UseGuards(AuthGuard('jwt'))
// @ApiBearerAuth('jwt')
// reporte() {}
}
+11 -25
View File
@@ -49,12 +49,11 @@ export class PrestamoService {
) {}
async cancelarOperador(
operadorRegreso: Operador,
id_prestamo: number,
id_operador: number,
motivo: string,
) {
const ahora = moment();
const operadorRegreso = await this.operadorService.findById(id_operador);
const prestamo = await this.findById(id_prestamo);
this.validacionBasicaPrestamo(prestamo, operadorRegreso);
@@ -230,10 +229,9 @@ export class PrestamoService {
});
}
async entregar(id_prestamo: number, id_operador: number) {
async entregar(operadorEntrega: Operador, id_prestamo: number) {
const ahora = moment();
const ahoraStr = ahora.format('YYYY-MM-DD');
const operadorEntrega = await this.operadorService.findById(id_operador);
const prestamo = await this.findById(id_prestamo);
const institucionDia =
await this.institucionDiaService.findByInstitucionDia(
@@ -631,40 +629,28 @@ export class PrestamoService {
});
}
async regresarIdPrestamo(
id_operador: number,
regresarIdPrestamo(
operador: Operador,
id_prestamo: number,
descripcion?: string,
id_institucion_infraccion?: number,
) {
const operador = await this.operadorService.findById(id_operador);
const prestamo = await this.findById(id_prestamo);
return this.regresar(
prestamo,
operador,
descripcion,
id_institucion_infraccion,
return this.findById(id_prestamo).then((prestamo) =>
this.regresar(prestamo, operador, descripcion, id_institucion_infraccion),
);
}
async regresarNumeroInventario(
id_operador: number,
regresarNumeroInventario(
operador: Operador,
numero_inventario: string,
descripcion?: string,
id_institucion_infraccion?: number,
) {
const operador = await this.operadorService.findById(id_operador);
const prestamo = await this.findByNumeroInventario(
return this.findByNumeroInventario(
operador.institucion,
numero_inventario,
);
return this.regresar(
prestamo,
operador,
descripcion,
id_institucion_infraccion,
).then((prestamo) =>
this.regresar(prestamo, operador, descripcion, id_institucion_infraccion),
);
}