5.3 KiB
You are a Senior Full Stack Engineer and Solution Architect.
Project: Training Management System (TMS)
Current status: Sprint 6.11 Identity / Employee Cleanup completed.
Current task: Implement Sprint 6.12 Employee Ownership Final Migration and Employee Directory Data Source Validation.
Goal: Finish migration from user-owned training data to employee-owned training data for employee directory, dashboard, reports, and remaining aggregation paths.
Important constraints:
- Do NOT break existing credential login.
- Do NOT remove legacy columns yet.
- Do NOT remove users.employeeCode fallback yet unless fully safe.
- Do NOT change business features.
- Keep Auth.js working.
- Keep Drizzle ORM.
- Keep Thai UI.
- Minimal-impact changes only.
Part 0: Employee Directory Data Source Validation
Update:
- src/features/employee-directory/server/employee-directory-data.ts
- src/app/dashboard/employee-directory/page.tsx
- src/app/dashboard/employee-directory/[id]/page.tsx
- related employee directory components
Requirements:
- Employee Directory list must use employees as the primary source.
The page:
- รายชื่อพนักงานทั้งหมด
Must read from:
- employees
Not from:
- users
- Employee Directory table must show:
- รหัสพนักงาน from employees.employeeCode
- ชื่อพนักงาน from employees.displayName or firstNameTh + lastNameTh
- ฝ่าย/แผนก from employees.departmentId / department relation
- ตำแหน่ง from employees.positionId / position relation
- Employee Directory detail must use employees as the primary source.
Detail page must show:
ข้อมูลทั่วไปพนักงาน:
- employeeCode
- displayName
- companyName / company
- department
- position
- status
- Training summary must use:
- training_records.employee_id = employees.id
Calculate:
- approved hours
- pending hours
- rejected hours
- total submitted hours
- K/S/A approved hours
- Target resolution must use:
Priority:
- employee_training_targets.employee_id
- training_policy default
Do not use userId target resolution as primary.
- Search must use employees fields:
Search by:
- employees.employeeCode
- employees.displayName
- employees.email
- department name
- position name
- Filters must use employees fields:
- department
- position
- status
- company if available
- Permission:
HRD/Admin:
- can access employee directory
Employee:
- cannot access employee directory by menu or direct URL
- Do not require employee to have user account.
Important: An employee imported into employees but without a linked user account must still appear in Employee Directory.
Part 1: Overview Dashboard Migration
Update:
- src/features/overview/server/overview-data.ts
Requirements:
-
Employee dashboard must resolve current employee through:
- user_employee_maps
- fallback users.employeeId if still exists
- fallback users.employeeCode only if needed
-
Employee dashboard must aggregate from:
- employees
- training_records.employee_id
-
HRD dashboard must use:
- employees as employee source
- training_records.employee_id as training ownership source
-
Pass/fail calculation must use:
- employee_training_targets.employee_id if exists
- fallback Training Policy
-
Avoid using users as the primary employee source.
Part 2: Reports Migration
Update:
- src/features/reports/server/report-data.ts
- src/app/api/reports/export/route.ts if needed
Requirements:
-
Employee Transcript:
- Employee users see only their mapped employee record.
- HRD/Admin can view organization employees.
- Data source must be employees + training_records.employee_id.
-
Training Matrix:
- Use employees + training_records.employee_id.
- Keep existing matrix behavior.
-
Department Summary:
- Count employees from employees table.
- Aggregate training hours from training_records.employee_id.
-
Annual Summary:
- Aggregate by employee-owned training records.
-
Export Excel/PDF must remain working.
Part 3: Employee Target Resolution
Update:
- src/features/training-policy/server/employee-training-target-data.ts
Requirements:
- Resolve target by employeeId first.
- Fallback to policy.
- Avoid userId target resolution except legacy compatibility.
Part 4: Reduce Legacy Dependency
Search and review remaining usage of:
- users.employeeCode
- users.employeeId
- training_records.userId
Do not delete them yet.
Create a list of:
- still required
- can be migrated later
- safe to remove in future cleanup
Part 5: Regression
Validate:
- Employee login
- Employee dashboard
- HRD dashboard
- Employee Directory list
- Employee Directory detail
- Employee imported without user appears in Employee Directory
- Employee transcript
- Department summary
- Annual summary
- Training matrix
- Training record create
- HRD review
- Import employee
- Employee target import
Part 6: Output Review File
Create: docs/sprint-6-12-employee-ownership-final-migration-review.md
Include:
- Summary
- Files Changed
- Employee Directory Data Source Validation
- Overview Migration
- Reports Migration
- Target Resolution Changes
- Remaining Legacy Dependencies
- Regression Checklist
- Risks
- Recommendation Before Sprint 7.2
Return:
- Complete code changes with file paths
- Review file
- Migration commands if required