From eefcc1576044ee77da9d405b955b647fab6b8dd4 Mon Sep 17 00:00:00 2001 From: Lemuel Marquez Date: Tue, 30 May 2023 15:15:10 -0600 Subject: [PATCH] hora del servidor --- src/prestamo/dto/output/prestamo.dto.ts | 3 ++ src/prestamo/prestamo.controller.ts | 68 +++++++++++++++++++++---- 2 files changed, 60 insertions(+), 11 deletions(-) diff --git a/src/prestamo/dto/output/prestamo.dto.ts b/src/prestamo/dto/output/prestamo.dto.ts index 5309df4..dae8472 100644 --- a/src/prestamo/dto/output/prestamo.dto.ts +++ b/src/prestamo/dto/output/prestamo.dto.ts @@ -11,6 +11,9 @@ export class PrestamoOutputDto { @Expose() fecha_inicio; + @Expose() + hora_server; + @Expose() hora_fin; diff --git a/src/prestamo/prestamo.controller.ts b/src/prestamo/prestamo.controller.ts index 649f9d4..02614a4 100644 --- a/src/prestamo/prestamo.controller.ts +++ b/src/prestamo/prestamo.controller.ts @@ -1,3 +1,4 @@ +import * as moment from 'moment'; import { Body, Controller, @@ -8,6 +9,7 @@ import { Request, UseGuards, } from '@nestjs/common'; +import { ConfigService } from '@nestjs/config'; import { AuthGuard } from '@nestjs/passport'; import { ApiBearerAuth, @@ -47,10 +49,15 @@ import { ReporteOutputDto } from './dto/output/reporte'; @Controller('prestamo') @ApiTags('prestamo') export class PrestamoController { + private add: number; + constructor( + private configService: ConfigService, private prestamoService: PrestamoService, private validarUsuarioService: ValidarUsuarioService, - ) {} + ) { + this.add = parseInt(this.configService.get('ADD_HORA')); + } @Serealize(ActivosOutputDto) @Get('activos') @@ -371,14 +378,27 @@ export class PrestamoController { const usuario: Usuario = req.user.usuario; this.validarUsuarioService.validarUsuario(usuario); - return this.prestamoService.create( - usuario, - body.id_institucion_usuario, - body.id_modulo, - body.id_tipo_carrito, - body.id_programa, - body.id_tipo_entrada, - ); + return this.prestamoService + .create( + usuario, + body.id_institucion_usuario, + body.id_modulo, + body.id_tipo_carrito, + body.id_programa, + body.id_tipo_entrada, + ) + .then((prestamo) => { + if (prestamo) { + const ahora = moment(); + + if (this.add) ahora.add(this.add, 'h'); + + const hora_server = { hora_server: ahora.format() }; + + Object.assign(prestamo, hora_server); + } + return prestamo; + }); } @Serealize(PrestamoOutputDto) @@ -398,7 +418,20 @@ export class PrestamoController { if (usuarioOperador instanceof Usuario) this.validarUsuarioService.validarUsuario(usuarioOperador); else this.validarUsuarioService.validarSoloOperador(usuarioOperador); - return this.prestamoService.prestamoInfoById(parseInt(query.id_prestamo)); + return this.prestamoService + .prestamoInfoById(parseInt(query.id_prestamo)) + .then((prestamo) => { + if (prestamo) { + const ahora = moment(); + + if (this.add) ahora.add(this.add, 'h'); + + const hora_server = { hora_server: ahora.format() }; + + Object.assign(prestamo, hora_server); + } + return prestamo; + }); } @Serealize(PrestamoOutputDto) @@ -412,7 +445,20 @@ export class PrestamoController { const usuario: Usuario = req.user.usuario; this.validarUsuarioService.validarUsuario(usuario); - return this.prestamoService.prestamoInfoByUsuario(usuario, false); + return this.prestamoService + .prestamoInfoByUsuario(usuario, false) + .then((prestamo) => { + if (prestamo) { + const ahora = moment(); + + if (this.add) ahora.add(this.add, 'h'); + + const hora_server = { hora_server: ahora.format() }; + + Object.assign(prestamo, hora_server); + } + return prestamo; + }); } @Serealize(PrestamoEquipoOutputDto)