Initial commit

This commit is contained in:
Lorenzo Sanesi
2026-03-26 22:46:03 +01:00
commit 18e0e04700
80 changed files with 13114 additions and 0 deletions
+36
View File
@@ -0,0 +1,36 @@
const { ValidationError } = require('../shared/errors');
class UsersService {
constructor({ usersRepository }) {
this.usersRepository = usersRepository;
}
async getAllUsers() {
return await this.usersRepository.findAll();
}
async getUserById(id) {
return await this.usersRepository.findById(id);
}
async updateUserProfile(id, updateData) {
const { name, email, avatarUrl } = updateData;
if (name && name.trim() === '') {
throw new ValidationError('Name cannot be empty');
}
if (email && email.trim() === '') {
throw new ValidationError('Email cannot be empty');
}
const dataToUpdate = {};
if (name !== undefined) dataToUpdate.name = name;
if (email !== undefined) dataToUpdate.email = email;
if (avatarUrl !== undefined) dataToUpdate.avatarUrl = avatarUrl;
return await this.usersRepository.update(id, dataToUpdate);
}
}
module.exports = UsersService;