Modifiche

This commit is contained in:
Lorenzo Sanesi
2026-04-01 23:49:19 +02:00
parent 8752acd2c4
commit e2fe8b264f
52 changed files with 1351 additions and 400 deletions
@@ -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);
}