Skip to main content

Support Ticket Model - Implementation Summary

Changes Implemented

✅ 1. Fixed Critical Field Name Inconsistency

  • Before: requesterId, requesterEmail, requesterName
  • After: userId, userEmail, userName
  • Impact: Now matches Firestore rules which use userId
  • Files Updated:
    • toto-bo/src/lib/seeding/supportTickets.ts - Updated interface and creation logic
    • toto-bo/src/app/api/support/route.ts - Updated interface, validation, and creation logic
    • toto-docs/app/docs/architecture/support-ticket-base-model.ts - Base model uses correct field names

✅ 2. Standardized Collection Name

  • Before: App used supportTickets (camelCase), Backoffice used support_tickets (snake_case)
  • After: Both use support_tickets (snake_case)
  • Files Updated:
    • toto-app/firebase/firestore.rules - Updated collection name to support_tickets

✅ 3. Made userId Optional

  • Before: requesterId was required
  • After: userId is optional, but at least one of userId or userEmail is required
  • Validation: API validates if (!userId && !userEmail)
  • Files Updated:
    • toto-bo/src/app/api/support/route.ts - Updated validation logic
  • Added: caseId?: string and guardianId?: string fields
  • Purpose: Link tickets to specific cases or guardians
  • Files Updated:
    • toto-bo/src/lib/seeding/supportTickets.ts - Added to interface
    • toto-bo/src/app/api/support/route.ts - Added to interface and creation logic
    • toto-docs/app/docs/architecture/support-ticket-base-model.ts - Added to base model

✅ 5. Included 'cancelled' Status

  • Status: Already in code, now documented in base model
  • Type: 'open' | 'in_progress' | 'resolved' | 'closed' | 'cancelled'
  • Files Updated:
    • toto-docs/app/docs/architecture/support-ticket-base-model.ts - Included in TicketStatus type

Files Modified

  1. toto-docs/app/docs/architecture/support-ticket-base-model.ts (NEW)

    • Created base support ticket model as single source of truth
    • Defined BaseSupportTicket, TicketStatus, TicketPriority, TicketCategory
  2. toto-bo/src/lib/seeding/supportTickets.ts

    • Updated SupportTicket interface: requesterIduserId, requesterEmailuserEmail, requesterNameuserName
    • Added caseId and guardianId optional fields
    • Updated ticket creation logic to use new field names
  3. toto-bo/src/app/api/support/route.ts

    • Updated SupportTicket interface: same field name changes
    • Updated validation: userId optional, require at least one of userId or userEmail
    • Updated search filter: use userEmail instead of requesterEmail
    • Updated ticket creation: use new field names and add caseId/guardianId
  4. toto-app/firebase/firestore.rules

    • Updated collection name: supportTicketssupport_tickets

Model Structure

BaseSupportTicket

{
id: string;
ticketNumber: string;
title: string;
description: string;
status: TicketStatus; // 'open' | 'in_progress' | 'resolved' | 'closed' | 'cancelled'
priority: TicketPriority; // 'low' | 'medium' | 'high' | 'urgent'
category: TicketCategory;
assignedTo?: string;
assignedToName?: string;
userId?: string; // Optional - at least one of userId or userEmail required
userEmail: string; // Required
userName?: string; // Denormalized
caseId?: string; // Optional - related case
guardianId?: string; // Optional - related guardian
createdAt: string;
updatedAt: string;
dueDate?: string;
resolvedAt?: string;
closedAt?: string;
tags?: string[];
attachments?: string[];
internalNotes?: string;
}

Breaking Changes

⚠️ Note: These changes may require updates in other parts of the codebase:

  1. Field Names: Any code using requesterId/requesterEmail/requesterName needs to use userId/userEmail/userName
  2. Collection Name: App code using supportTickets collection needs to use support_tickets
  3. userId Optional: Code assuming userId is always present needs to handle optional case

Migration Notes

When migrating existing support tickets:

  1. Rename requesterIduserId (if present)
  2. Rename requesterEmailuserEmail
  3. Rename requesterNameuserName (if present)
  4. Ensure at least one of userId or userEmail exists
  5. Add caseId and guardianId if tickets are related to cases/guardians

Next Steps

  • Update any remaining code that uses old field names (requesterId, requesterEmail, requesterName)
  • Create migration script for existing support tickets
  • Test ticket creation, reading, and updating
  • Verify Firestore rules work correctly with new field names