Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BACKEND: Implement Create Result Endpoint for the Result Module #122

Open
BigBen-7 opened this issue Feb 24, 2025 · 2 comments
Open

BACKEND: Implement Create Result Endpoint for the Result Module #122

BigBen-7 opened this issue Feb 24, 2025 · 2 comments

Comments

@BigBen-7
Copy link
Collaborator

"⚠️Please ensure you read and follow the contribution guidelines. Failure to do so may result in your contribution being rejected."
"⚠️Please include an expected delivery date in your application. Failure to do so may void your application. Also, test your code thoroughly to ensure it works as expected before creating a PR."

Feature:

Description

We need an endpoint to create a result entry for users in the Result Module. This should store key user performance metrics. Change placeholders in the result modules, i.e., entity, DTO, controller, and services:

  • Times Played
  • Current Streak
  • Max Streak
  • Win Percentage

Additionally, when a new user signs up, a default result entry should be created automatically.

Tasks

1. Create ResultDto for Data Validation

Fields:

  • userId: string (linked to the user)
  • timesPlayed: number (default: 0)
  • currentStreak: number (default: 0)
  • maxStreak: number (default: 0)
  • winPercentage: number (default: 0.0)

Use class-validator to enforce correct data types.

2. Implement Create Result Endpoint

  • POST /results → Creates a new result entry for a user.
  • Validate the request using ResultDto.
  • Ensure that a user can only have one result entry.

3. Auto-Create a Result When a User Signs Up

Modify the User Service or Auth Module to:

  • Call ResultService.createResult(userId) after a successful signup.
  • Ensure result creation is transactional (user and result must be created together).

4. Implement ResultService Methods

  • createResult(userId: string)
    • Check if the user already has a result entry.
    • If not, create a new one with default values.
    • Save the result in the database.

5. Handle Errors Gracefully

  • 400 Bad Request → If the result data is invalid.
  • 409 Conflict → If a result already exists for the user.
  • 500 Internal Server Error → If an unexpected error occurs.

Tech Stack

  • Backend: NestJS
  • Validation: class-validator
  • Database: PostgreSQL (or relevant DB)
  • Authentication: JWT/AuthGuard

Acceptance Criteria

✅ Users have a result entry automatically created upon signup.
✅ The POST /results endpoint allows manual creation if needed (ensuring no duplicates).
Proper validation and error handling are in place.

@ryzen-xp
Copy link

**Solution **

  • Implement ResultDto with validation.
  • Create POST /results ensuring unique result entries.
  • Auto-create result entry on user signup (transactional).
  • Implement ResultService for handling result logic.
  • Add error handling for 400, 409, 500 statuses.
  • ETA: ~ 29 hours

@jaiminRaiyani
Copy link

Can I start working on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants