Modifiche
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
const { NotFoundError, DatabaseError } = require('../../shared/errors');
|
||||
const { Op } = require('sequelize');
|
||||
const { NotFoundError, DatabaseError } = require('../../shared/errors');
|
||||
|
||||
class FriendRequestsRepository {
|
||||
constructor({ sequelize }) {
|
||||
@@ -30,7 +30,7 @@ class FriendRequestsRepository {
|
||||
try {
|
||||
return await this.FriendRequest.findAll({
|
||||
where: {
|
||||
toUserId: userId,
|
||||
[Op.or]: [{ toUserId: userId }, { fromUserId: userId }],
|
||||
status: 'PENDING',
|
||||
},
|
||||
include: [
|
||||
@@ -39,10 +39,7 @@ class FriendRequestsRepository {
|
||||
],
|
||||
});
|
||||
} catch (error) {
|
||||
throw new DatabaseError(
|
||||
`Failed to fetch pending requests for user ${userId}`,
|
||||
error
|
||||
);
|
||||
throw new DatabaseError(`Failed to fetch pending requests for user ${userId}`, error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,11 +61,12 @@ class FriendRequestsRepository {
|
||||
|
||||
async create(fromUserId, toUserId) {
|
||||
try {
|
||||
return await this.FriendRequest.create({
|
||||
const created = await this.FriendRequest.create({
|
||||
fromUserId,
|
||||
toUserId,
|
||||
status: 'PENDING',
|
||||
});
|
||||
return await this.findById(created.id);
|
||||
} catch (error) {
|
||||
throw new DatabaseError('Failed to create friend request', error);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user