Skip to content

Commit 94170a6

Browse files
committed
refact: router file and user routes
1 parent 32989cc commit 94170a6

File tree

3 files changed

+20
-25
lines changed

3 files changed

+20
-25
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"mongoose": "^8.4.4",
4545
"morgan": "^1.10.0",
4646
"multer": "^1.4.5-lts.1",
47-
"nodemailer": "^6.9.14",
47+
"nodemailer": "^7.0.10",
4848
"npm": "^10.8.1",
4949
"socket.io": "^4.7.5",
5050
"winston": "^3.13.0",

src/app/modules/user/user.route.ts

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,28 @@
1-
import express, { NextFunction, Request, Response } from 'express';
1+
import express from 'express';
22
import auth from '../../middlewares/auth';
33
import validateRequest from '../../middlewares/validateRequest';
44
import { UserController } from './user.controller';
55
import { UserValidation } from './user.validation';
66
import fileUploadHandler from '../../middlewares/fileUploadHandler';
7-
import { USER_ROLES } from './user.constant';
87
const router = express.Router();
98

10-
router
11-
.route('/profile')
12-
.get(auth(USER_ROLES.ADMIN, USER_ROLES.USER), UserController.getUserProfile)
13-
.patch(
14-
auth(USER_ROLES.SUPER_ADMIN, USER_ROLES.ADMIN, USER_ROLES.USER),
15-
fileUploadHandler(),
16-
(req: Request, res: Response, next: NextFunction) => {
17-
if (req.body.data) {
18-
req.body = UserValidation.updateUserZodSchema.parse(
19-
JSON.parse(req.body.data)
20-
);
21-
}
22-
return UserController.updateProfile(req, res, next);
23-
}
24-
);
9+
// create user
10+
router.post(
11+
'/create-user',
12+
validateRequest(UserValidation.createUserZodSchema),
13+
UserController.createUser
14+
);
2515

26-
router
27-
.route('/')
28-
.post(
29-
validateRequest(UserValidation.createUserZodSchema),
30-
UserController.createUser
31-
);
16+
// update profile
17+
router.patch(
18+
'/profile',
19+
auth(),
20+
fileUploadHandler(),
21+
validateRequest(UserValidation.updateUserZodSchema),
22+
UserController.updateProfile
23+
);
24+
25+
// get profile
26+
router.get('/profile', auth(), UserController.getUserProfile);
3227

3328
export const UserRoutes = router;

src/routes/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const router = express.Router();
55

66
const apiRoutes = [
77
{
8-
path: '/user',
8+
path: '/users',
99
route: UserRoutes,
1010
},
1111
{

0 commit comments

Comments
 (0)