Skip to content

Commit

Permalink
refactor: change method de import utils
Browse files Browse the repository at this point in the history
  • Loading branch information
guilhiz committed May 2, 2023
1 parent 031f690 commit 1158c89
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/middlewares/auth.middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import jwt from 'jsonwebtoken';

import { Request, Response, NextFunction } from 'express';

import erros from '../erros/index';
import erros from '../erros';
import 'dotenv/config';

type JWTPayload = {
Expand Down
2 changes: 1 addition & 1 deletion src/middlewares/schema.middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Schema, ZodIssue } from 'zod';
import { NextFunction, Request, Response } from 'express';

import erros from '../erros';
import sanitizeObject from '../utils/functions/sanitizeObject';
import { sanitizeObject } from '../utils/functions';

const schemaMiddleware = (schema: Schema) => {
return (req: Request, res: Response, next: NextFunction) => {
Expand Down
1 change: 1 addition & 0 deletions src/utils/constants/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './times';
4 changes: 2 additions & 2 deletions src/utils/functions/generateToken.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import jwt from 'jsonwebtoken';

import { MS_IN_DAY } from '../constants/times';
import { MS_IN_DAY } from '../constants';
import 'dotenv/config';

export const generateToken = (payload: object): string => {
export const generateToken = async (payload: object): Promise<string> => {
const token = jwt.sign(payload, process.env.JWT_SECRET!, {
expiresIn: MS_IN_DAY
});
Expand Down
4 changes: 4 additions & 0 deletions src/utils/functions/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from './comparePasswords';
export * from './generateToken';
export * from './hashPassword';
export * from './sanitizeObject';
4 changes: 1 addition & 3 deletions src/utils/functions/sanitizeObject.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { stripHtml } from 'string-strip-html';

const sanitizeObject = (object: Record<string, unknown>): Record<string, unknown> => {
export const sanitizeObject = (object: Record<string, unknown>): Record<string, unknown> => {
for (const key of Object.keys(object)) {
if (typeof object[key] === 'string') {
object[key] = stripHtml(object[key] as string).result.trim();
Expand All @@ -11,5 +11,3 @@ const sanitizeObject = (object: Record<string, unknown>): Record<string, unknown

return object;
};

export default sanitizeObject;

0 comments on commit 1158c89

Please sign in to comment.