Skip to content

Commit

Permalink
Merge pull request #11 from DiegoCL311/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
DiegoCL311 authored May 15, 2024
2 parents 9e60469 + d2fd08e commit 812848d
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

strategy:
matrix:
node-version: [14.x, 16.x, 18.x]
node-version: [20.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
Expand Down
4 changes: 2 additions & 2 deletions dbscripts/mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ CREATE TABLE `usuarios` (
`updatedAt` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
UNIQUE KEY `email` (`email`)
) ENGINE=InnoDB AUTO_INCREMENT=104 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;



Expand All @@ -29,4 +29,4 @@ CREATE TABLE `usuarios` (
`updatedAt` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
UNIQUE KEY `email` (`email`)
) ENGINE=InnoDB AUTO_INCREMENT=104 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
4 changes: 2 additions & 2 deletions src/controllers/auth/auth.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Request, Response } from 'express';
import bcrypt from 'bcrypt';
import { SuccessResponse } from '../../core/ApiResponse';
import { BadRequestError } from '../../core/ApiError';
import * as usuarioService from "../../services/usuarioService";
import bcrypt from 'bcrypt';
import { createTokens } from '../../utils/utils';

const register = async (req: Request, res: Response) => {
Expand Down Expand Up @@ -42,7 +42,7 @@ const login = async (req: Request, res: Response) => {
maxAge: 1000 * 60 * 60 * 24 * 7,
});

new SuccessResponse(res, "Inicio de sesion exitoso", { usuario: usuario, accessToken: accessToken })
new SuccessResponse(res, "Inicio de sesion exitoso", { usuario, accessToken })
}

export default {
Expand Down
8 changes: 8 additions & 0 deletions src/controllers/test/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Request, Response } from 'express';
import { SuccessMsgResponse } from '../../core/ApiResponse';

const test = async (req: Request, res: Response) => {
new SuccessMsgResponse(res, "Respuesta de prueba!");
}

export default { test }
13 changes: 6 additions & 7 deletions src/loaders/express.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import express from "express";
import { Express } from "express";
import routes from "../routes/index";
import routes from "../routes";

import cors from "cors";
import cookieParser from "cookie-parser";
import helmet from "helmet";
import { errorMiddleware } from "../middlewares/errorMiddleware";
import { requestLogger } from "../middlewares/requestLoggerMiddleware";
import { notFoundMiddleware } from "../middlewares/404Middleware";
import helmet from "helmet";
import asyncErrorHandler from "../../src/utils/asyncErrorHandler";
import authMiddleware from "../../src/middlewares/authMiddleware";

const expressLoader = async ({ app }: { app: Express }) => {
app.use(express.json());
Expand All @@ -24,13 +23,13 @@ const expressLoader = async ({ app }: { app: Express }) => {
app.use(requestLogger);
app.use(helmet());


//Rutas de la applicación
app.use("/api", routes);


//Middleware para manejar rutas no encontradas
app.use("*", notFoundMiddleware);
app.use(asyncErrorHandler(authMiddleware))

//Middleware para manejar errores
app.use(errorMiddleware);
};

Expand Down
2 changes: 1 addition & 1 deletion src/middlewares/404Middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import { Request, Response, NextFunction } from 'express';
import { NotFoundError } from '../core/ApiError'

export const notFoundMiddleware = (req: Request, res: Response, next: NextFunction) => {
const error = new NotFoundError(`Not Found - ${req.originalUrl}`);
const error = new NotFoundError(`Not Found - ${req.method} - ${req.originalUrl}`);
next(error);
};
2 changes: 1 addition & 1 deletion src/routes/auth.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Router, Request, Response, NextFunction } from "express";
import { Router } from "express";
import asyncErrorHandler from "../utils/asyncErrorHandler";
import { validateRequest } from "../middlewares/validateRequest";
import authController from "../controllers/auth/auth";
Expand Down
12 changes: 8 additions & 4 deletions src/routes/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import express from "express";
import auth from "./auth";
import authMiddleware from "../middlewares/authMiddleware";
import asyncErrorHandler from "../utils/asyncErrorHandler";
import testRoutes from "./test"
import authRoutes from "./auth";
import asyncErrorHandler from "../../src/utils/asyncErrorHandler";
import authMiddleware from "../../src/middlewares/authMiddleware";


const app = express();

// Rutas no protegidas por middleware de autenticación
app.use("/auth", auth);
app.use("/auth", authRoutes);

// Rutas protegidas por middleware de autenticación
app.get("/test", asyncErrorHandler(authMiddleware), testRoutes);

export default app;
10 changes: 10 additions & 0 deletions src/routes/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Router } from "express";
import asyncErrorHandler from "../utils/asyncErrorHandler";
import testController from "../controllers/test/test";

const app = Router();

app.get("/", asyncErrorHandler(testController.test));


export default app;

0 comments on commit 812848d

Please sign in to comment.