File: //home/arjun/projects/good-life-be/api/User/index.js
import express from 'express';
import {
changePassword,
editProfile,
getAllUsers,
getProfile,
removeProfileImage,
statusUpdate,
} from './controller.js';
import { changePasswordValidation } from './validator.js';
const router = express.Router();
router.post('/change-password', changePasswordValidation, changePassword);
/**
* @swagger
* /api/user/change-password:
* post:
* summary: User
* tags:
* - User
* security:
* - bearerAuth: []
* requestBody:
* content:
* application/json:
* schema:
* type: object
* properties:
* currentPassword:
* type: string
* example: "admin@1234"
* newPassword:
* type: string
* example: "admin@123"
* responses:
* 200:
* description: Success. Password changed successfully.
* 400:
* description: Bad request. Invalid parameters or missing data.
* 500:
* description: Internal server error.
*/
router.get('/profile', getProfile);
/**
* @swagger
* /api/user/profile:
* get:
* tags:
* - User
* summary: Get user profile using the id
* description: This endpoint allows the user to get the user profile using the corresponding user id.
* security:
* - bearerAuth: []
* responses:
* 200:
* description: Profile fetched successfully.
* 400:
* description: Invalid user ID.
* 404:
* description: User not found or token does not match.
*/
router.get('/', getAllUsers);
/**
* @swagger
* /api/user:
* get:
* summary: Get all users
* tags:
* - User
* security:
* - bearerAuth: []
* description: Retrieve a list of users with pagination, sorting, and filtering options.
* parameters:
* - in: query
* name: page
* schema:
* type: integer
* default: 1
* description: Page number (default is 1).
* - in: query
* name: limit
* schema:
* type: integer
* default: 10
* description: Number of users per page (default is 10).
* - in: query
* name: sortBy
* schema:
* type: string
* enum: [first_name, second_name, createdAt, email]
* default: first_name
* description: Field to sort by. Possible values are `first_name`, `second_name`, `createdAt`, `email`.
* - in: query
* name: sortOrder
* schema:
* type: string
* enum: [ASC, DESC]
* default: ASC
* description: Sort order (ASC or DESC, default is ASC).
* - in: query
* name: search
* schema:
* type: string
* description: Search query to filter users by name or email.
* - in: query
* name: fromDate
* schema:
* type: string
* format: date
* description: Filter users starting from this date (e.g., `2025-01-01`).
* - in: query
* name: toDate
* schema:
* type: string
* format: date
* description: Filter users up to this date (e.g., `2025-01-31`).
* responses:
* 200:
* description: Successfully retrieved users.
* 400:
* description: Invalid query parameters.
* 401:
* description: Unauthorized access.
* 500:
* description: Internal server error.
*/
router.put('/profile-update', editProfile);
/**
* @swagger
* /api/user/profile-update:
* put:
* tags:
* - User
* security:
* - bearerAuth: []
* summary: Edit User Profile
* description: Allows a user to update their first name, second name, and profile image.
* requestBody:
* required: true
* content:
* multipart/form-data:
* schema:
* type: object
* properties:
* first_name:
* type: string
* description: The user's first name
* second_name:
* type: string
* description: The user's second name
* image:
* type: string
* format: binary
* description: The user's profile image
* responses:
* 200:
* description: Profile updated successfully
* 400:
* description: Bad request
* 404:
* description: User not found
*/
router.delete('/remove-profile-image', removeProfileImage);
/**
* @swagger
* /api/user/remove-profile-image:
* delete:
* tags:
* - User
* security:
* - bearerAuth: []
* summary: Remove User Profile Image
* responses:
* 200:
* description: Profile updated successfully
* 400:
* description: Bad request
* 404:
* description: User not found
*/
router.put('/status-update/:id', statusUpdate);
/**
* @swagger
* /api/user/status-update/{id}:
* put:
* tags:
* - User
* summary: Update user status and deletion status
* description: Update the `status` and/or `is_deleted` field of a user.
* security:
* - bearerAuth: []
* parameters:
* - name: id
* in: path
* required: true
* description: The unique ID of the user to update.
* schema:
* type: string
* format: uuid
* - name: status
* in: query
* required: false
* description: The new status of the user (e.g., "active", "inactive").
* schema:
* type: string
* - name: is_deleted
* in: query
* required: false
* description: Flag indicating whether the user is deleted.
* schema:
* type: boolean
* responses:
* 200:
* description: User status updated successfully.
* 400:
* description: Bad Request - Invalid parameters or user not found.
* 500:
* description: Internal Server Error.
*/
export default router;