Files
kittyBE/src/routes/userRoutes.ts
sherl 41f3b0f0f2
All checks were successful
Update changelog / changelog (push) Successful in 27s
feat: major code refactor, add login and register endpoints with swagger
2025-12-29 18:26:50 +01:00

72 lines
1.9 KiB
TypeScript

import { Router, Request, Response } from 'express';
import validateSchema from '../tools/validateSchema';
import * as ac from '../controllers/authController';
import * as as from '../schemas/authSchema';
const userRouter = Router();
/**
* @openapi
*
* /api/v1/user/signUp:
* post:
* description: Add user
* tags: [User]
* summary: Register a user
* requestBody:
* required: true
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/LoginRequestDTO'
* produces:
* - application/json
* responses:
* 200:
* description: User created successfully
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/UserInfoDTO'
* 400:
* description: Bad request
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/ErrorDTO'
*/
userRouter.post('/api/v1/user/signUp', validateSchema(as.loginRequestSchema), ac.createUserHandler);
/**
* @openapi
*
* /api/v1/user/signIn:
* post:
* description: Log in
* tags: [User]
* summary: Log in to an account
* requestBody:
* required: true
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/LoginRequestDTO'
* produces:
* - application/json
* responses:
* 200:
* description: User logged in successfully
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/UserInfoDTO'
* 400:
* description: Wrong password/non-existent user
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/ErrorDTO'
*/
userRouter.post('/api/v1/user/signIn', validateSchema(as.loginRequestSchema), ac.loginUserHandler);
export default userRouter;