Modifiche
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
const { Op } = require('sequelize');
|
||||
const { NotFoundError, DatabaseError } = require('../../shared/errors');
|
||||
|
||||
class GroupsRepository {
|
||||
@@ -15,6 +16,29 @@ class GroupsRepository {
|
||||
}
|
||||
}
|
||||
|
||||
async findByUserId(userId) {
|
||||
try {
|
||||
return await this.Group.findAll({
|
||||
include: [
|
||||
{
|
||||
model: this.User,
|
||||
as: 'members',
|
||||
through: { attributes: [] },
|
||||
},
|
||||
],
|
||||
where: {
|
||||
id: {
|
||||
[Op.in]: this.sequelize.literal(
|
||||
`(SELECT "groupId" FROM "UserGroups" WHERE "userId" = ${parseInt(userId, 10)})`
|
||||
),
|
||||
},
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
throw new DatabaseError('Failed to fetch groups for user', error);
|
||||
}
|
||||
}
|
||||
|
||||
async findById(id, includeMembers = false) {
|
||||
try {
|
||||
const options = {};
|
||||
|
||||
Reference in New Issue
Block a user