Skip to content

Type — Timeline, Notification And Role Boundary

1. Timeline model

Complaint timeline được dựng từ complaint_schedule_history, không phải từ diff của complaint_schedule.

Shape dữ liệu chính

FieldVai trò
complaint_schedule_idComplaint cha
user_idNgười thực hiện activity
statusLoại activity
contentsJSONB nội dung business của activity
filesFile đính kèm của activity
created_atThời điểm activity

ComplaintTimeline render history theo thứ tự thời gian và hiển thị label/status dựa trên mapping FE ở types.ts.

2. Complaint detail không chỉ đọc bảng chính

complaintScheduleDetail trả về ít nhất 3 lớp dữ liệu:

  1. complaint core fields,
  2. history/timeline,
  3. complaint_action_role.

Do đó detail action này vừa là read model vừa là permission projection. Nếu thay đổi permission logic mà không cập nhật detail action, FE sẽ drift ngay.

3. Branch permission model

Bảng cấu hình

TableVai trò
complaint_permission_branchBật/tắt branch permission
complaint_permission_resolverGắn resolver vào branch
complaint_permission_approverGắn approver vào branch

Runtime use cases

SurfaceCách dùng
ListGom branch mà user là resolver/approver để mở rộng scope nhìn thấy
DetailQuyết định complaint có mở được không và action role là gì
Mutate actionsCheck resolver/approver của branch trước khi transition

Điểm chốt là branch permission không chỉ là setting screen; nó là runtime gate của toàn bộ complaint workflow.

4. Full-view boundary

Full-view roles ở list/detail

  • it_leader
  • it_staff
  • audit_leader
  • audit_staff
  • accountant_leader
  • accountant_staff
  • customer_service_leader
  • customer_service_staff
  • bod

Ý nghĩa

  • Những role này có thể xem complaint ngay cả khi không nằm trong branch permission tables.
  • Nhưng việc "xem được" không đồng nghĩa "mutate được", vì mutate actions có guard riêng và đang không đồng nhất.

5. Customer workspace boundary

Complaint xuất hiện ở customer workspace qua raw query ComplaintDetail.

SurfaceSemantics
Complaint moduleruntime operation surface, có action role và mutate path
Customer workspacereference/read-only surface, FE ép complaint_action_role = view

Đây là boundary quan trọng cho BA/QA:

  • cùng một complaint nhưng ở user module không mang semantics thao tác giống complaint module,
  • bug "không thấy nút" trong customer workspace chưa chắc là bug, có thể là chủ đích read-only.

6. Notification boundary

Trong phạm vi code đã đọc cho complaint workflow:

  • không thấy action notification riêng cho complaint,
  • không thấy event trigger hoặc scheduler dành riêng cho complaint lifecycle,
  • không thấy FE complaint dialog tự gọi notification action sau transition.

Suy ra hợp lý nhất là:

  1. complaint timeline/audit là first-class,
  2. notification nếu có thì đang nằm ở layer khác hoặc chưa được implement ngay trong complaint surface này.

Điều này quan trọng vì nhiều business flow thường giả định "approve/reject sẽ tự gửi thông báo". Với complaint hiện tại, assumption đó chưa được chứng minh từ code đã đọc.

7. Rủi ro / Findings

IDFinding
TRN-F01Timeline correctness phụ thuộc vào việc mọi mutate action đều insert history đúng schema; thiếu history là mất audit trail ngay.
TRN-F02Branch permission tables là runtime dependency thật, không chỉ là admin config tĩnh.
TRN-F03List/detail visibility và mutate permission hiện không hoàn toàn dùng cùng semantics, nên role boundary có risk drift.
TRN-F04Không thấy notification-specific runtime trong complaint path đã đọc; nếu business kỳ vọng có thông báo tự động thì hiện docs/module khác mới cần xác minh tiếp.