Skip to content

Commit

Permalink
👌 IMPROVE: added user details route
Browse files Browse the repository at this point in the history
  • Loading branch information
hyper-dot committed Oct 14, 2024
1 parent ddbde62 commit c8ee7ed
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/app/user/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,9 @@ export default class UserController {
const response = await this.service.addUser(req.body);
return res.status(201).json(response);
});

getMyData = asyncWrapper(async (req, res) => {
const data = await this.service.getUserData(req.userId);
return res.json({ data });
});
}
2 changes: 2 additions & 0 deletions src/app/user/user.route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Router } from 'express';
import UserController from './user.controller';
import { isAuthencticated } from '../../middleware';

class UserRoutes {
public router: Router;
Expand All @@ -14,6 +15,7 @@ class UserRoutes {

mountRoutes() {
this.router.post('/', this.controller.addUser);
this.router.get('/my-data', isAuthencticated, this.controller.getMyData);
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/app/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,8 @@ export default class UserService {
await newUser.save();
return { message: 'User created successfully' };
}

async getUserData(id: string) {
return await UserModel.findById(id).select('name role email');
}
}

0 comments on commit c8ee7ed

Please sign in to comment.