Skip to content

62 get chats match endpoints#63

Merged
YoungMame merged 8 commits into
mainfrom
62-get-chats-match-endpoints
Dec 26, 2025
Merged

62 get chats match endpoints#63
YoungMame merged 8 commits into
mainfrom
62-get-chats-match-endpoints

Conversation

@YoungMame
Copy link
Copy Markdown
Owner

GET /private/match return
[ { id: user id, firstName: user first name, profilePicture, user picture, chatId: chat id beetween both users } ]

Copilot AI review requested due to automatic review settings December 26, 2025 14:27
@YoungMame YoungMame linked an issue Dec 26, 2025 that may be closed by this pull request
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request implements a GET endpoint at /private/match/:offset/:limit to retrieve matches between users along with their associated chat IDs. The implementation includes database queries to find reciprocal likes (matches) and retrieve the chat ID for matched users.

Key changes:

  • Added new /private/match endpoint that returns matched users with their profile information and chat IDs
  • Improved profile picture deletion logic to better handle index updates
  • Cleaned up debugging console.log statements throughout the codebase
  • Updated test fixtures to use longer bio text that meets validation requirements

Reviewed changes

Copilot reviewed 19 out of 20 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
fastify/assets/srcs/routes/private/match/index.ts New route definition for GET /match endpoint with offset/limit parameters
fastify/assets/srcs/controllers/private/match/index.ts New controller handler to fetch matches for authenticated user
fastify/assets/srcs/models/Like/index.ts Added Match interface and getMatches() method with SQL query for reciprocal likes
fastify/assets/srcs/services/UserService.ts Added getMatches() service method, updated profile picture deletion logic, removed debug logging
fastify/assets/@types/fastify.d.ts Added getMatches type definition to UserService interface
fastify/assets/srcs/routes/private/index.ts Registered new match routes with /match prefix
fastify/assets/srcs/routes/private/user/me/profilePicture.ts Changed index parameter schema from integer to string with int32 format
fastify/assets/srcs/controllers/private/me/profilePictures.ts Updated to parse index as string and convert to number
fastify/assets/srcs/services/BrowsingService.ts Removed debug console.log statements
fastify/assets/srcs/plugins/oAuth/facebook.ts Removed debug console.log statements
fastify/assets/srcs/models/User/index.ts Removed debug console.log statement
postgresql/init.sql Refactored notifications_details view with clearer alias naming
fastify/assets/test/integration/ws/like.test.ts Added test case for GET /match endpoint
fastify/assets/test/integration/ws/ws.test.ts Updated test bio/tags to meet validation requirements
fastify/assets/test/integration/ws/view.test.ts Removed unused imports
fastify/assets/test/integration/ws/browsing.test.ts Updated test bio/tags to meet validation requirements
fastify/assets/test/integration/private/me/profilePicture.test.ts Updated test bio/tags to meet validation requirements
fastify/assets/test/integration/private/me/profile.test.ts Updated test data and removed obsolete test assertions
fastify/assets/test/integration/fixtures/auth.fixtures.ts Updated quickUser bio template and added error logging
fastify/assets/test/integration/auth/auth.test.ts Updated test bio/tags to meet validation requirements

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

const { offset, limit } = request.params as { offset: string, limit: string };
if (!userId)
throw new UnauthorizedError();
const matches = await request.server.userService.getMatches(userId, Number(offset), Number(limit));
Copy link

Copilot AI Dec 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No validation for negative or invalid offset/limit values before passing them to the database query. The Number() conversion could result in NaN for non-numeric strings, which would cause SQL query issues. Add validation to ensure offset and limit are non-negative integers before using them.

Suggested change
const matches = await request.server.userService.getMatches(userId, Number(offset), Number(limit));
const offsetNum = Number(offset);
const limitNum = Number(limit);
if (!Number.isInteger(offsetNum) || offsetNum < 0 || !Number.isInteger(limitNum) || limitNum < 0) {
return reply.status(400).send({ error: 'Invalid offset or limit' });
}
const matches = await request.server.userService.getMatches(userId, offsetNum, limitNum);

Copilot uses AI. Check for mistakes.
profilePicture: row.profile_picture,
chatId: row.chat_id
})));
} catch {
Copy link

Copilot AI Dec 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The catch block swallows all error information without logging. This makes debugging difficult when database queries fail. Consider logging the error before throwing InternalServerError, similar to how it's done in other methods in this class (e.g., getAllByLikerId and getAllByLikedId).

Suggested change
} catch {
} catch (error) {
this.fastify.log.error((error as Error).message || undefined);

Copilot uses AI. Check for mistakes.
Comment on lines 286 to 287
user.profilePictureIndex = user.profilePictures.length > 0 ? user.profilePictureIndex - 1 : undefined;
} else if (pictureIndex === user.profilePictureIndex) {
Copy link

Copilot AI Dec 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic for updating profilePictureIndex when removing a picture at an index less than the current index appears incorrect. When you decrement the index, you're checking if profilePictures.length > 0, but this check happens after the picture has already been removed from the array. If there are still pictures remaining after removal, the index should always be decremented by 1, not conditionally set to undefined. The current logic could incorrectly set the index to undefined when there are still pictures in the array.

Suggested change
user.profilePictureIndex = user.profilePictures.length > 0 ? user.profilePictureIndex - 1 : undefined;
} else if (pictureIndex === user.profilePictureIndex) {
// A picture before the current profile picture was removed:
// shift the profile picture index left by 1.
user.profilePictureIndex = user.profilePictureIndex - 1;
} else if (pictureIndex === user.profilePictureIndex) {
// The current profile picture was removed: reset to first picture if any remain.

Copilot uses AI. Check for mistakes.
Comment on lines +26 to +28
age: { type: 'integer' },
commonInterests: { type: 'integer' },
distance: { type: 'number' },
Copy link

Copilot AI Dec 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The response schema defines fields (age, commonInterests, distance) that are not returned by the Match interface or getMatches method implementation. The Match interface only includes id, firstName, profilePicture, and chatId fields. Either remove these unused fields from the schema or update the implementation to return them.

Suggested change
age: { type: 'integer' },
commonInterests: { type: 'integer' },
distance: { type: 'number' },

Copilot uses AI. Check for mistakes.
Comment on lines +4 to +16
// matches: { type: 'array', items: {
// type: 'object',
// properties: {
// id: { type: 'integer' },
// firstName: { type: 'string' },
// profilePicture: { type: 'string', nullable: true },
// age: { type: 'integer' },
// commonInterests: { type: 'integer' },
// distance: { type: 'number' },
// chatId: { type: 'integer', nullable: true }
// }
// }}

Copy link

Copilot AI Dec 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a commented-out code block showing the expected schema structure, but it doesn't match the actual implementation. The actual Match interface only returns id, firstName, profilePicture, and chatId, but this comment suggests age, commonInterests, and distance should also be returned. Either remove this misleading comment or update the implementation to match it.

Suggested change
// matches: { type: 'array', items: {
// type: 'object',
// properties: {
// id: { type: 'integer' },
// firstName: { type: 'string' },
// profilePicture: { type: 'string', nullable: true },
// age: { type: 'integer' },
// commonInterests: { type: 'integer' },
// distance: { type: 'number' },
// chatId: { type: 'integer', nullable: true }
// }
// }}

Copilot uses AI. Check for mistakes.
'Cookie': `jwt=${tokenA}`
}
});
console.log('get matches response:', res.body);
Copy link

Copilot AI Dec 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Console.log statement left in test code. This debug statement should be removed before merging to production.

Suggested change
console.log('get matches response:', res.body);

Copilot uses AI. Check for mistakes.
headers: {
'Cookie': `jwt=${token}`
}
}
Copy link

Copilot AI Dec 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace added at the end of the line. This should be removed for code cleanliness.

Suggested change
}
}

Copilot uses AI. Check for mistakes.
if (!user)
throw new NotFoundError();
if (user.profilePictures.length <= 1)
if (user.profilePictures.length < 1)
Copy link

Copilot AI Dec 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The validation logic check has been changed from <= 1 to < 1, which means users can now delete their last profile picture when they have exactly 1 picture. This creates an inconsistency - the error message says "Cannot delete the last profile picture" but the condition now allows deletion when there's only 1 picture left. The original <= 1 condition was correct to prevent deletion of the last picture.

Suggested change
if (user.profilePictures.length < 1)
if (user.profilePictures.length <= 1)

Copilot uses AI. Check for mistakes.
gender: userData.gender,
orientation: userData.orientation,
bornAt: new Date(userData.bornAt)
}
Copy link

Copilot AI Dec 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid automated semicolon insertion (95% of all statements in the enclosing function have an explicit semicolon).

Copilot uses AI. Check for mistakes.
@YoungMame YoungMame merged commit aa87897 into main Dec 26, 2025
1 check passed
@YoungMame YoungMame deleted the 62-get-chats-match-endpoints branch December 26, 2025 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Get chats / match endpoints

2 participants