Sistemato profilo
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user