Uecko_ERP/apps/server/src/routes/auth.routes.ts

84 lines
2.6 KiB
TypeScript
Raw Normal View History

2025-02-01 21:48:13 +00:00
import { validateRequest } from "@common/presentation";
2025-02-04 14:58:33 +00:00
import { validateTabHeader } from "@contexts/auth/presentation";
2025-02-03 21:54:51 +00:00
import {
createLoginController,
createRegisterController,
} from "@contexts/auth/presentation/controllers";
import { LoginUserSchema, RegisterUserSchema } from "@contexts/auth/presentation/dto";
2025-02-03 18:03:23 +00:00
import { Router } from "express";
2025-02-01 21:48:13 +00:00
export const authRouter = (appRouter: Router) => {
const authRoutes: Router = Router({ mergeParams: true });
/**
* @api {post} /api/auth/register Register a new user
* @apiName RegisterUser
* @apiGroup Authentication
* @apiVersion 1.0.0
*
* @apiBody {String} username User's unique username.
* @apiBody {String} email User's email address.
* @apiBody {String} password User's password (minimum 8 characters).
*
* @apiSuccess (201) {String} userId The unique ID of the created user.
*
* @apiError (400) {String} message Error message.
*/
2025-02-03 13:12:36 +00:00
authRoutes.post("/register", validateRequest(RegisterUserSchema), (req, res, next) => {
createRegisterController().execute(req, res, next);
});
2025-02-01 21:48:13 +00:00
/**
* @api {post} /api/auth/login Authenticate a user
* @apiName LoginUser
* @apiGroup Authentication
* @apiVersion 1.0.0
*
* @apiBody {String} email User's email address.
* @apiBody {String} password User's password.
*
* @apiSuccess (200) {String} token JWT authentication token.
* @apiSuccess (200) {String} userId The unique ID of the authenticated user.
*
* @apiError (401) {String} message Invalid email or password.
*/
2025-02-04 14:58:33 +00:00
authRoutes.post(
"/login",
validateRequest(LoginUserSchema),
validateTabHeader,
(req, res, next) => {
createLoginController().execute(req, res, next);
}
);
2025-02-01 21:48:13 +00:00
/**
* @api {post} /api/auth/select-company Select an active company
* @apiName SelectCompany
* @apiGroup Authentication
* @apiVersion 1.0.0
*
* @apiHeader {String} Authorization Bearer token.
*
* @apiBody {String} companyId The ID of the company to select.
*
* @apiSuccess (200) {String} message Success message.
*
* @apiError (403) {String} message Unauthorized or invalid company selection.
*/
2025-02-03 13:12:36 +00:00
//authRoutes.post("/select-company", authMiddleware, authController.selectCompany);
2025-02-01 21:48:13 +00:00
/**
* @api {post} /api/auth/logout Logout user
* @apiName LogoutUser
* @apiGroup Authentication
* @apiVersion 1.0.0
*
* @apiHeader {String} Authorization Bearer token.
*
* @apiSuccess (200) {String} message Success message.
*/
2025-02-03 13:12:36 +00:00
//authRoutes.post("/logout", authMiddleware, authController.logout);
2025-02-01 21:48:13 +00:00
appRouter.use("/auth", authRoutes);
};