Skip to content

Commit d70dbb2

Browse files
aldoEMatamalanegro89
authored andcommitted
(IN-612): cambiar periodos de registros de internacion
1 parent a588408 commit d70dbb2

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

auth/auth.class.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ export class Auth {
591591
type: 'huds-token'
592592

593593
};
594-
return jwt.sign(token, configPrivate.auth.jwtKey, { expiresIn: 60 * 60 * 4 }); // 4 Horas
594+
return jwt.sign(token, configPrivate.auth.jwtKey, { expiresIn: 60 * 60 }); // 1 Hora
595595
}
596596

597597
static refreshAPPToken(token: string) {
@@ -631,6 +631,17 @@ export class Auth {
631631

632632
return null;
633633
}
634+
static getTokenTimeLeft(token: any): number {
635+
let timeLeft = 0;
636+
const decodedToken: any = jwt.decode(token);
637+
if (!decodedToken || !decodedToken.exp) {
638+
timeLeft = -1;
639+
} else {
640+
const currentTime = Math.floor(Date.now() / 1000); // Current time in seconds
641+
timeLeft = decodedToken.exp - currentTime;
642+
}
643+
return timeLeft;
644+
}
634645

635646
static async authorizeByToken(req: Request, res: Response, next: express.NextFunction, requiredPermissions: string[]) {
636647
const permisos = req.user.permisos;

modules/huds/hudsAccesos.routes.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ router.get('/accesos', asyncHandler(async (req: any, res) => {
1313
const result = await HudsAccesosCtr.search(req.query);
1414
res.json(result);
1515
}));
16+
router.get('/accesos/timeLeft', asyncHandler(async (req: any, res) => {
17+
const result = await Auth.getTokenTimeLeft(req.query.token);
18+
res.json(result);
19+
}));
20+
1621

1722
router.post('/accesos/token', asyncHandler(async (req: any, res) => {
1823
// Persiste los datos de accesos y genera el token para acceder a la HUDS del paciente

0 commit comments

Comments
 (0)