Sistemato profilo

This commit is contained in:
Lorenzo Sanesi
2026-04-04 02:40:34 +02:00
parent 162e0de62a
commit aa5ca9bbe3
10 changed files with 454 additions and 28 deletions
@@ -1,3 +1,4 @@
const { Op } = require('sequelize');
const { NotFoundError, DatabaseError } = require('../../shared/errors');
class UsersRepository {
@@ -6,6 +7,23 @@ class UsersRepository {
this.User = sequelize.models.User;
}
async search(query, excludeUserId) {
try {
return await this.User.findAll({
where: {
id: { [Op.ne]: excludeUserId },
[Op.or]: [
{ name: { [Op.iLike]: `%${query}%` } },
{ email: { [Op.iLike]: `%${query}%` } },
],
},
limit: 20,
});
} catch (error) {
throw new DatabaseError('Failed to search users', error);
}
}
async findAll(options = {}) {
try {
return await this.User.findAll(options);