Skip to content
This repository has been archived by the owner on Jan 16, 2024. It is now read-only.

Commit

Permalink
fix(api:users:submissions:overtime): submission with one year
Browse files Browse the repository at this point in the history
  ## problem
  - user submissions overtime chart doesn't render correctly if the user
    has only one year of submissions

  ## solution
  - check if the submissions contain the current year
    - if it doesn't add an entry in the object
      - `[current year]: 0`

  ## why
  - this will fix the issue if there was one year in the user
    submissions
    - ex:
      - user submissions only has year 2015
      - checks if current year is included in the submissions,
        - adds current year
      - fill in the years missing
      - chart renders correctly

  ## where
  - ./src/app/api/users/[username]/submissions/overtime/route.ts

  ## usage
  • Loading branch information
Clumsy-Coder committed Jan 16, 2024
1 parent 0b7c987 commit 2df9d9f
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/app/api/users/[username]/submissions/overtime/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ export const GET = async (_request: Request, { params }: getParamsType) => {
return obj;
}, initData);

// add current year if it doesn't exist
// this to make sure the chart draws a lint upto the current year
const curYear = new Date().getFullYear()
if(reducedData[curYear] === undefined) {
reducedData[curYear] = 0
}

// add missing years
// - loop through the array starting from index 1 going upto last array element
// - convert processedData into an array using Object.entries
Expand Down

0 comments on commit 2df9d9f

Please sign in to comment.