negyedik gyakorlat + megoldasok

This commit is contained in:
magdo
2026-03-04 20:02:39 +01:00
parent afc3777ac9
commit 388aa908de
217 changed files with 19791 additions and 0 deletions
@@ -0,0 +1,62 @@
export class UserController {
constructor(getMeHandler, getAllUsersHandler, getUserByIdHandler, updateProfileHandler) {
this.getMeHandler = getMeHandler;
this.getAllUsersHandler = getAllUsersHandler;
this.getUserByIdHandler = getUserByIdHandler;
this.updateProfileHandler = updateProfileHandler;
}
async getMe(req, res, next) {
try {
const user = await this.getMeHandler.handle({ userId: req.user.id });
res.json({
success: true,
data: user.toJSON()
});
} catch (error) {
next(error);
}
}
async getAllUsers(req, res, next) {
try {
const users = await this.getAllUsersHandler.handle({});
res.json({
success: true,
data: users.map(u => u.toJSON())
});
} catch (error) {
next(error);
}
}
async getUserById(req, res, next) {
try {
const user = await this.getUserByIdHandler.handle({ userId: req.params.id });
res.json({
success: true,
data: user.toJSON()
});
} catch (error) {
next(error);
}
}
async updateProfile(req, res, next) {
try {
const { name, email } = req.body;
const user = await this.updateProfileHandler.handle({
userId: req.user.id,
name,
email
});
res.json({
success: true,
message: 'Profile updated successfully',
data: user.toJSON()
});
} catch (error) {
next(error);
}
}
}