diff --git a/src/prestamo/dto/prestamo-cancelar-operador.dto.ts b/src/prestamo/dto/prestamo-update-operador.dto.ts similarity index 72% rename from src/prestamo/dto/prestamo-cancelar-operador.dto.ts rename to src/prestamo/dto/prestamo-update-operador.dto.ts index 8c7ab41..7494872 100644 --- a/src/prestamo/dto/prestamo-cancelar-operador.dto.ts +++ b/src/prestamo/dto/prestamo-update-operador.dto.ts @@ -1,6 +1,6 @@ import { IsInt } from 'class-validator'; -export class PrestamoCancelarOperadorDto { +export class PrestamoUpdateOperadorDto { @IsInt() id_operador: number; diff --git a/src/prestamo/prestamo.controller.ts b/src/prestamo/prestamo.controller.ts index 9b08b8f..18ded66 100644 --- a/src/prestamo/prestamo.controller.ts +++ b/src/prestamo/prestamo.controller.ts @@ -9,7 +9,7 @@ import { PrestamoNumeroInventarioDto } from './dto/prestamo-numero-inventario.dt import { PrestamoHistorialEquipoDto } from './dto/prestamo-historial-equipo.dto'; import { PrestamoHistorialUsuarioDto } from './dto/prestamo-historial-usuario.dto'; import { PrestamoHistorialDto } from './dto/prestamo-historial.dto'; -import { PrestamoCancelarOperadorDto } from './dto/prestamo-cancelar-operador.dto'; +import { PrestamoUpdateOperadorDto } from './dto/prestamo-update-operador.dto'; import { PrestamoCancelarUsuarioDto } from './dto/prestamo-cancelar-usuario.dto'; @Controller('prestamo') @@ -87,7 +87,7 @@ export class PrestamoController { description: 'Ambas variables son obligatorias.', examples: { ejemplo: { value: { id_prestamo: 1, id_operador: 1 } } }, }) - cancelarOperador(@Body() body: PrestamoCancelarOperadorDto) { + cancelarOperador(@Body() body: PrestamoUpdateOperadorDto) { return this.prestamoService.cancelarOperador( body.id_prestamo, body.id_operador, @@ -110,7 +110,13 @@ export class PrestamoController { @ApiOperation({ description: 'Endpoint que actualiza el status del equipo a "En uso".', }) - entregar() {} + @ApiBody({ + description: 'Ambas variables son obligatorias.', + examples: { ejemplo: { value: { id_prestamo: 1, id_operador: 4 } } }, + }) + entregar(@Body() body: PrestamoUpdateOperadorDto) { + return this.prestamoService.entregar(body.id_prestamo, body.id_operador); + } @Get('historial') @ApiOperation({ @@ -301,8 +307,14 @@ export class PrestamoController { } @Put('regresar') - @ApiOperation({ description: 'Endpoint .' }) - regresar() {} + @ApiOperation({ description: 'Endpoint que desactiva un préstamo.' }) + @ApiBody({ + description: 'Ambas variables son obligatorias.', + examples: { ejemplo: { value: { id_prestamo: 1, id_operador: 4 } } }, + }) + regresar(@Body() body: PrestamoUpdateOperadorDto) { + return this.prestamoService.regresar(body.id_prestamo, body.id_operador); + } // @Get('reporte') // reporte() {} diff --git a/src/prestamo/prestamo.service.ts b/src/prestamo/prestamo.service.ts index 90ccea3..021915d 100644 --- a/src/prestamo/prestamo.service.ts +++ b/src/prestamo/prestamo.service.ts @@ -137,6 +137,43 @@ export class PrestamoService { ); } + async entregar(id_prestamo: number, id_operador: number) { + const ahora = moment(); + const operadorEntrega = await this.operadorService.findById(id_operador); + const prestamo = await this.findById(id_prestamo); + + prestamo.hora_inicio = ahora.toDate(); + prestamo.hora_fin = ahora + .add(operadorEntrega.institucion.tiempo_prestamo, 'm') + .toDate(); + prestamo.operadorEntrega = operadorEntrega; + prestamo.equipo.status = await this.statusService.findById(3); + prestamo.equipo.prestado = true; + return this.equipoService + .update(prestamo.equipo) + .then((_) => this.repository.save(prestamo)) + .then((_) => ({ + message: 'Se entregó el equipo de cómputo correctamente.', + })); + } + + async regresar(id_prestamo: number, id_operador: number) { + const ahora = moment(); + const operadorRegreso = await this.operadorService.findById(id_operador); + const prestamo = await this.findById(id_prestamo); + + prestamo.activo = false; + prestamo.fecha_entrega = ahora.toDate(); + prestamo.operadorRegreso = operadorRegreso; + prestamo.equipo.status = await this.statusService.findById(1); + return this.equipoService + .update(prestamo.equipo) + .then((_) => this.repository.save(prestamo)) + .then((_) => ({ + message: 'Se regresó el equipo de cómputo correctamente.', + })); + } + async findAll(filtros: { pagina: string; activo?: string | boolean;