hora del servidor

This commit is contained in:
Lemuel Marquez 2023-05-30 15:15:10 -06:00
parent f5e768ca99
commit eefcc15760
2 changed files with 60 additions and 11 deletions

View File

@ -11,6 +11,9 @@ export class PrestamoOutputDto {
@Expose()
fecha_inicio;
@Expose()
hora_server;
@Expose()
hora_fin;

View File

@ -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<string>('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)