UNPKG

easy-express-cwa

Version:

CLI tool to setup a common Express.js backend developed by codewithashim

62 lines (52 loc) 1.69 kB
import { Request, Response } from "express"; import httpStatus from "http-status"; import catchAsync from "../../../shared/catchAsync"; import sendResponse from "../../../shared/sendResponse"; import { IUser } from "./user.interface"; import { UserService } from "./user.service"; import { responseMessage } from "../../../constants/message"; const getAllUsers = catchAsync(async (req: Request, res: Response) => { const result = await UserService.getAllUsers(); sendResponse<IUser[]>(res, { statusCode: httpStatus.OK, success: true, message: responseMessage.GET_ALL_USERS_MESSAGE, data: result, }); }); const getUserById = catchAsync(async (req: Request, res: Response) => { const result = await UserService.getUserById(req.params.id); sendResponse<IUser>(res, { statusCode: httpStatus.OK, success: true, message: responseMessage.GET_USER_BY_ID_MESSAGE, data: result, }); }); const updateUser = catchAsync(async (req: Request, res: Response) => { const id = req.params.id; const updatedData = req.body; const result = await UserService.updateUser(id, updatedData); sendResponse<IUser>(res, { statusCode: httpStatus.OK, success: true, message: responseMessage.UPDATE_USER_MESSAGE, data: result, }); }); const deleteUser = catchAsync(async (req: Request, res: Response) => { const { id } = req.params; const result = await UserService.deleteUser(id); sendResponse<IUser>(res, { statusCode: httpStatus.OK, success: true, message: responseMessage.DELETE_USER_MESSAGE, data: result, }); }); export const UserController = { getAllUsers, getUserById, updateUser, deleteUser, };