Skip to content

Conversation

@KashGiannis34
Copy link
Contributor

Solo Leveling the Leveling System

Issue Number(s): #157

What does this PR change and why?

Added backend functionality for streaks and dynamic xp reqs for each level. Not much was implemented on the frontend since this was a BE ticket but i did add info about the current streak and stuff like that on the store page.

Checklist

  • Requirements have been implemented
  • Acceptance criteria is met
  • Database schema docs have been updated or are not necessary
  • Code follows design and style guidelines
  • Commits follow guidelines (concise, squashed, etc)
  • Relevant reviewers (Senior Dev/EM/Designers) have been assigned to this PR

Critical Changes

  • Database change/migration to run
  • Environment config change
  • Breaking API change

Related PRs

  • #number_of_pr

Testing

Enumerate steps to test the functionality of your ticket. This should include edge cases and testing of error handling, if applicable.

@netlify
Copy link

netlify bot commented Nov 18, 2025

Deploy Preview for bog-ican ready!

Name Link
🔨 Latest commit 6b5f7e6
🔍 Latest deploy log https://app.netlify.com/projects/bog-ican/deploys/691bbd9d30b7ba00080daba7
😎 Deploy Preview https://deploy-preview-200--bog-ican.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@greptile-apps
Copy link

greptile-apps bot commented Nov 18, 2025

Disclaimer: This comment was AI-generated and is not necessarily completely accurate. Please take code comments with a grain of salt.

Greptile Summary

  • Implemented dynamic XP leveling system with formula 90 + level * 10 replacing hardcoded threshold of 100
  • Added comprehensive streak tracking system with daily check-ins, perfect week bonuses (15 coins), and milestone detection at 30/50/100/150/200/365 days
  • Introduced streak-locked store items with level-based pricing and reorganized all items into level tiers (1-4)

Confidence Score: 3/5

  • This PR contains a critical logical error in milestone detection that will prevent milestones from triggering correctly
  • The implementation is mostly solid with proper schema changes, type updates, and frontend integration. However, the milestone detection logic in src/services/streak.ts:66-76 has a fundamental flaw that will cause it to fail for most milestone streaks
  • Pay close attention to src/services/streak.ts - the milestone detection logic needs to be fixed before merging

Important Files Changed

Filename Overview
src/services/streak.ts New file implementing streak tracking with daily check-ins, perfect week bonuses, and milestone detection - contains logical error in milestone detection.
src/services/pets.ts Updated XP leveling from hardcoded threshold (100) to dynamic calculation (90 + level * 10), correctly implements level-up logic with modulo operation.
src/services/medication.ts Integrated streak system into medication logging, awards coins for perfect weeks and updates streak counters on each dose.
src/db/models/pet.ts Added four new fields to Pet schema: currentStreak, longestStreak, perfectWeeksCount, lastDoseDate with appropriate defaults.
src/lib/storeItems.ts Reorganized all items by level (1-4), changed costs from hardcoded to ItemPrice enum and dynamic streak pricing, added streak-locked items.

Sequence Diagram

sequenceDiagram
    participant User
    participant "MedicationService" as Med
    participant "StreakService" as Streak
    participant "PetDAO" as Pet
    participant Database

    User->>Med: createMedicationLog(medicationId, localTime)
    Med->>Database: getMedicationById(medicationId)
    Database-->>Med: medication
    Med->>Database: getPetByUserId(userId)
    Database-->>Med: pet
    Med->>Streak: calculateStreakUpdate(pet, now)
    Streak->>Streak: Calculate days difference from lastDoseDate
    alt First dose or streak continues
        Streak->>Streak: Increment currentStreak
        Streak->>Streak: Check for perfect week (7 days)
        Streak->>Streak: Check for milestone (30, 50, 100, etc)
    else Streak broken
        Streak->>Streak: Reset currentStreak to 1
    end
    Streak-->>Med: streakUpdate (coins, streak data)
    Med->>Pet: updatePetByUserId(food, coins, streaks)
    Pet->>Database: Update pet document
    Database-->>Pet: Success
    Med->>Database: createMedicationLog(medicationId)
    Database-->>Med: Success
    Med-->>User: Streak info (isPerfectWeek, coins awarded)
Loading

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

15 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile
React with 👍 or 👎 to share your feedback on this new summary format

Copy link
Member

@rgodha24 rgodha24 left a comment

Choose a reason for hiding this comment

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

small things:

Image

locked b/c of streak required is much taller than locked bc of level. it kinda messes with the design of the whole page

Image

should probably be a more coherent ordering here

@rgodha24
Copy link
Member

i think we are gonna have a bit more of a longer conversation abt what to do with streaks and maybe push implementation to next semester?
if u have time, can you make a pr with like just the 4 line change to tutorial logic, and we can leave this as a draft for next sem to deal with please?


await PetDAO.updatePetByUserId(userId, {
food: existingPet.food + FOOD_INC,
coins: existingPet.coins + streakUpdate.coinsAwarded + 10,
Copy link
Member

@rgodha24 rgodha24 Nov 18, 2025

Choose a reason for hiding this comment

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

why the +10?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the tutorial gave +10 coins after the user logged the practice medication so i applied the same logic to the regular functionality

Comment on lines +12 to +14
CHEAP = 10,
MEDIUM = 25,
EXPENSIVE = 50,
Copy link
Member

Choose a reason for hiding this comment

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

need to talk abt this too
also, typescript enums are kinda an antipattern

Comment on lines +1 to +4
export const calculateXPForLevel = (level: number): number => {
return 90 + level * 10;
};

Copy link
Member

Choose a reason for hiding this comment

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

i feel like this doesnt rly need to be a helper

@KashGiannis34
Copy link
Contributor Author

i think we are gonna have a bit more of a longer conversation abt what to do with streaks and maybe push implementation to next semester? if u have time, can you make a pr with like just the 4 line change to tutorial logic, and we can leave this as a draft for next sem to deal with please?

bet

@rgodha24 rgodha24 changed the title Updated the leveling system Streaks and Dynamic XP Dec 8, 2025
@rgodha24 rgodha24 marked this pull request as draft December 8, 2025 22:31
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.

3 participants