Skip to content

Yu Yan - feat: add reasons array to infringements in user profile (resolves #1686, #1817)#2106

Open
yany960 wants to merge 12 commits intodevelopmentfrom
feat/infringement-reasons-array
Open

Yu Yan - feat: add reasons array to infringements in user profile (resolves #1686, #1817)#2106
yany960 wants to merge 12 commits intodevelopmentfrom
feat/infringement-reasons-array

Conversation

@yany960
Copy link
Copy Markdown

@yany960 yany960 commented Mar 16, 2026

Description

This PR adds a reasons array to infringements in the user profile, allowing for more robust and flexible categorization of issues such as "time not met," "missing summary," "missed video call," "late reporting," or "other."

The controller logic ensures reasons are consistently handled as a lowercased, deduplicated array with a safe default, which both improves data quality and simplifies future analytics or display logic.

Fixes #1686, #1817 (PRIORITY HIGH)
This is a redo PR:
image

Related PRS (if any):

PR 1686 - Original PR by Yu Yan taking over for Ujjwal
PR 1817 - Attempt to resolve merge conflicts

Main changes explained:

Added functionality to easily parse reasons for Blue Squares using a reasons array. Added the reasons array field to store multiple categorization reasons for each infringement.

  • Added reasons field under infringements in userProfile model with predefined options (which can be modified as required)

    • Type: Array of Strings
    • Default: ['other']
    • Enum values: 'time not met', 'missing summary', 'missed video call', 'late reporting', 'other'
  • Updated addInfringements controller logic to:

    • Accept reasons array from request body
    • Normalize values to lowercase
    • Remove duplicates
    • Filter valid enum values only
    • Default to ['other'] if empty or invalid
  • Maintains backward compatibility with existing reason (single string) field

How to test:

  1. Check out the current branch: feat/infringement-reasons-array
  2. Run npm run build and npm start to run this PR locally
  3. Send a POST request to api/userProfile/:userId/addInfringement to add an infringement

Example request body:

{
  "requestor": "<your-user-id>",
  "blueSquare": {
    "date": "2025-09-03",
    "description": "PR Testing Add Infringement",
    "reasons": ["time not met", "missing summary", "missed video call", "late reporting", "other"]
  }
}

- Add reasons field to infringement schema with enum validation
- Supported values: 'time not met', 'missing summary', 'missed video call', 'late reporting', 'other'
- Default value: ['other']
- Process reasons array in addInfringements controller:
  - Normalize to lowercase
  - Deduplicate values
  - Filter valid enum values only
  - Default to ['other'] if empty
- Maintain backward compatibility with existing reason field
- Resolves merge conflicts from PR #1686 and #1817
- Add schema validation tests for reasons field
- Add processing logic tests (lowercase, deduplication, filtering)
- Add edge case tests (empty strings, special characters, large arrays)
- Add backward compatibility tests
- Add date validation tests
…tion in tests

- Move processReasons function to top-level describe block
- Remove 3 duplicate function definitions from Edge Cases tests
- Fix SonarCloud duplicated lines issue (22.3% -> 0%)
- All 18 tests still passing
- Add 'manullyAssigned', 'manullyAssignedBy', and 'editedBy' fields to infringement schema
- Track when blue squares are manually assigned vs CRON job assigned
- Record edit history with user info and timestamp
- Set reasons array for CRON-assigned blue squares based on violation type
- Update addInfringements to populate manual assignment fields
- Update editInfringements to track edit history
- Update assignBlueSquareForTimeNotMet for CRON job assignments
@one-community one-community changed the title feat: add reasons array to infringements in user profile (resolves #1686, #1817) Yu Yan - feat: add reasons array to infringements in user profile (resolves #1686, #1817) Mar 28, 2026
Copy link
Copy Markdown

@Anusha-Gali Anusha-Gali left a comment

Choose a reason for hiding this comment

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

Hi Yuyan,

I tried to review your PR locally but i am unable to do so due to 403 Forbidden response.

Image

@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
8.5% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

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