10 KiB
Pre-Sprint 6 Stabilization Review
Summary
งาน pre-sprint รอบนี้โฟกัสที่การปิดช่องโหว่ด้าน authorization, ความสม่ำเสมอของ dashboard, การลด hardcoded policy target, การปรับข้อความภาษาไทยบนหน้าหลักของ TMS และการ harden workflow ของ Employee Import และ Master Review ก่อนเริ่ม Sprint 6
ผลลัพธ์หลัก:
- ยืนยันว่า dashboard และการคำนวณชั่วโมงหลักใช้เฉพาะรายการ
APPROVED - เอา default training target แบบ hardcoded
30 / 12 / 12 / 6ออกจาก runtime fallback - ปิด route/API protection ที่ยังขาดใน
proxy.tsสำหรับ training policy, employee import และ master review - ปรับข้อความ API/UI หลายจุดเป็นภาษาไทยให้สอดคล้องกับ TMS
- เพิ่ม downloadable error summary สำหรับ employee import
- ตรวจซ้ำ org scoping และ duplicate prevention ของ master review / import flow
Files Changed
src/proxy.tssrc/features/training-policy/constants/training-policy-defaults.tssrc/features/training-policy/components/training-policy-page.tsxsrc/features/training-policy/components/training-policy-form.tsxsrc/features/training-policy/schemas/training-policy.tssrc/app/api/training-policies/route.tssrc/app/api/training-policies/[id]/route.tssrc/app/api/training-records/route.tssrc/app/api/training-records/[id]/route.tssrc/app/api/training-records/[id]/review/route.tssrc/app/api/training-records/[id]/certificates/route.tssrc/app/api/training-records/[id]/certificates/[certificateId]/route.tssrc/app/api/import-employees/route.tssrc/app/api/master-review/route.tssrc/features/import-employees/components/employee-import-page.tsxsrc/features/import-employees/components/master-review-page.tsxsrc/features/courses/components/course-tables/index.tsxsrc/features/training-matrix/components/training-compliance-card.tsxsrc/features/training-matrix/components/training-matrix-tables/columns.tsxsrc/features/training-matrix/components/training-matrix-tables/options.tsxsrc/app/dashboard/pending-review/page.tsxsrc/app/dashboard/training-policy/page.tsxsrc/app/dashboard/import-employees/page.tsxsrc/app/dashboard/master-review/page.tsx
Issues Found
proxy.tsยังไม่ได้บังคับ auth กับบาง API route ที่เป็น HRD flow- Training policy fallback ยังมีค่าฮาร์ดโค้ด
30 / 12 / 12 / 6 - Empty state บางจุดยังอ้างอิง target เดิมแบบฮาร์ดโค้ด
- ข้อความ UI/API หลายจุดยังเป็นอังกฤษหรือมีอาการ encoding เพี้ยน
- Employee import ยังไม่มีไฟล์สรุป error สำหรับดาวน์โหลด
Issues Fixed
- เพิ่ม protected API prefixes และ matcher ใน
src/proxy.tsสำหรับ:/api/training-policies/api/import-employees/api/master-review
- เปลี่ยน default fallback training policy เป็น
0 / 0 / 0 / 0ในsrc/features/training-policy/constants/training-policy-defaults.ts - ปรับ training policy page/form และ validation message เป็นภาษาไทย
- ปรับ training records review/certificate/training-policy/import/master-review API messages เป็นภาษาไทย
- เพิ่มปุ่มดาวน์โหลด CSV สรุป error ใน employee import page
- ปรับ master review UI และ employee import UI ให้เป็นภาษาไทยและมี empty/result state ที่อ่านง่ายขึ้น
Authorization Review
Pages
HRD-only pages ถูกป้องกัน server-side แล้วผ่าน requireHRDDashboardAccess():
/dashboard/pending-review/dashboard/training-policy/dashboard/import-employees/dashboard/master-review
ผลการตรวจ:
- direct URL access จาก role
userควรถูกบล็อกที่ page guard - nav filtering ยังเป็นเพียง UX layer ตามสถาปัตยกรรมเดิม
APIs
ตรวจ route handlers ที่เกี่ยวข้องแล้ว:
training-policiesใช้requireOrganizationAccess()และเช็ก role ระดับ reviewer/adminimport-employeesใช้requireOrganizationAccess()และเช็กสิทธิ์ HRD/adminmaster-reviewใช้requireOrganizationAccess()และเช็กสิทธิ์ HRD/admintraining-records review/certificate/update/deleteมีการบังคับสิทธิ์และ owner/org scoping ฝั่ง server
Fix Applied
เดิม proxy.ts ยังไม่ครอบ /api/training-policies, /api/import-employees, /api/master-review จึงเพิ่ม matcher เพื่อไม่ให้ route เหล่านี้หลุดออกจาก middleware auth layer
Localization Review
จุดที่ปรับแล้ว:
- Training Policy page/form
- Employee Import page
- Master Review page
- Pending Review page header
- Training matrix table labels / compliance card
- Course empty state
- Training record review/certificate/import/master-review/training-policy API response messages
หลักการที่คงไว้:
- UI label/message ใช้ภาษาไทย
- internal enum/db values เช่น
approved,pending,department,positionยังคงเป็นภาษาอังกฤษตาม schema/runtime contract เดิม
Dashboard Review
Approved Records Only
ตรวจแล้วว่าการคำนวณหลักใช้เฉพาะรายการอนุมัติ:
src/features/overview/server/overview-data.tssrc/features/training-matrix/server/training-matrix-data.tssrc/features/reports/server/report-data.ts
ผลลัพธ์:
- Total training hours ใช้ approved records
- Dashboard summary K/S/A ใช้ approved records
- Employee dashboard progress ผูกกับ policy + approved records
- Training matrix compliance ใช้ approved records
Hardcoded Target Review
พบ hardcoded training target เดิมใน runtime flow ที่เกี่ยวกับ policy:
src/features/training-policy/constants/training-policy-defaults.tssrc/features/training-policy/components/training-policy-page.tsx
การแก้ไข:
- เอา fallback
30 / 12 / 12 / 6ออก - ให้ระบบอ่านค่าจาก Training Policy จริงเป็นหลัก
- ถ้ายังไม่มี policy สำหรับ organization จะ fallback เป็น
0
หมายเหตุ:
- ตัวเลข
30 / 60 / 90 / 180ใน reports ใช้สำหรับ filter วันหมดอายุใบรับรอง ไม่ใช่ training target - ตัวเลข
6บางจุดใน overview เป็นจำนวนเดือนย้อนหลัง ไม่ใช่ policy target
Import Review
Current Validation / Hardening
ตรวจ flow import แล้วพบว่ารองรับ:
- duplicate employee code / email ด้วยการ update user เดิมตามเงื่อนไขของระบบ
- invalid status handling
- invalid template / missing required columns
- clear Thai error messages ใน API response
- downloadable CSV error summary จากหน้า UI
Pending Master Data
import flow สร้าง pending master data เฉพาะกรณีจำเป็น และสรุปจำนวน:
- pending companies
- pending departments
- pending positions
Master Review
Review Actions
ตรวจแล้วว่า approve / reject ทำงานผ่าน server-side route เดิมโดยไม่เปลี่ยนโครงสร้างระบบ
Duplicate Prevention
duplicate department/position ถูกกันด้วยการตรวจข้อมูลเดิมก่อน insert ใน import flow และใช้รายการ pending/master data ที่แยกจากกัน
Organization Scope
review action และผลกระทบที่ตามมาอ้างอิง active organization ของ session ปัจจุบัน ไม่เปิดช่องให้อนุมัติ/ปฏิเสธข้าม organization
Remaining Technical Debt
- ยังมีหน้า legacy/non-TMS บางส่วนที่ใช้ภาษาอังกฤษ ซึ่งอยู่นอกขอบเขต pre-sprint นี้
npm run lintผ่านในระดับใช้งานได้ แต่ยังมี warning เดิมในไฟล์ที่ไม่เกี่ยวกับ sprint นี้:src/components/ui/slider.tsxsrc/components/ui/calendar.tsxsrc/features/products/components/product-form.tsxsrc/components/kbar/render-result.tsxsrc/constants/mock-api-users.tssrc/constants/mock-api.ts
- ยังควรมี regression test เชิง integration สำหรับ HRD-only routes และ import/master review workflow ใน Sprint 6
Recommended Sprint 6 Scope
- เพิ่ม automated regression coverage สำหรับ auth + import + review flow
- เก็บ Thai localization ให้ครบทุก TMS surface ที่ยังเหลือ
- ทำ audit ของ notification flow และ dashboard aggregates เพิ่มเติม
- พิจารณาเพิ่ม observability/logging สำหรับ import job และ review action