Skip to content

Type Deep Dive — Direct Schedule Upsert And Import

1. WorkingSchedule đang ghi thẳng time_slot_user

Page WorkingScheduleCreate submit mutation upsertTimeSlotUser:

  • trước tiên delete_time_slot_user trong khoảng _gte/_lte cho userIds,
  • sau đó insert_time_slot_user với on_conflict update start_time, end_time.

Nếu edit theo ngày:

  • range delete chỉ nằm ở ngày đó,
  • nếu create theo tuần:
  • range delete bao trọn tuần hiện tại của user đó.

Kết luận: đây là direct schedule write model, không hề qua request approval.

2. Form semantics

WorkingScheduleForm:

  • build working dates theo weekday của tuần,
  • map từ template id sang start/end/break/workday,
  • cho phép cả template-based slot và manual slot,
  • validate tối thiểu là phải có ít nhất một ca.

Form cũng đọc time_slot_user.requests(status = approved) để hiển thị change-shift semantics khi format slot.

3. Import semantics

WorkingScheduleImport + useWorkingScheduleImport:

  1. đọc Excel mẫu tuần hiện tại hoặc tuần sau,
  2. map mã ca sang time_slot_template,
  3. map user theo email nội bộ @diva.vn,
  4. build list Time_Slot_User_Insert_Input,
  5. gọi cùng mutation UpsertTimeSlotUserDocument.

Quan trọng nhất: import là destructive overwrite theo tuần cho danh sách user trong file. Nó không merge từng ô.

4. Export semantics

WorkingSchedule export:

  • load tất cả time_slot_user trong tuần,
  • group theo user,
  • map tên ca sang template id,
  • ghi Excel với 7 cột ngày trong tuần.

Đây là export từ source time_slot_user, không cộng overlay request chưa/đã duyệt theo logic timesheet.

5. Filter/User scope

Page WorkingSchedule xác định tập user bằng cách trộn:

  • department users,
  • branch users,
  • CRM displayed accounts khi chạy platform CRM,
  • shift group filters,
  • disabled users chỉ bị loại nếu disable date nằm trước period đang xem.

Điều này làm schedule page thiên về operational planning surface hơn là request-tracking surface.

6. Findings kỹ thuật

IDMứcFinding
S-01P0Import và create/edit cùng dùng upsertTimeSlotUser, tức toàn bộ schedule planning path hiện bypass approval engine.
S-02P0Mutation import xóa slot cũ trong tuần của user trước khi insert lại, nên file thiếu dữ liệu sẽ gây mất lịch chứ không chỉ "không import đủ".
S-03P1UI WorkingSchedule vẫn hiển thị approved requests gắn vào slot gốc, tạo cảm giác request flow và direct schedule flow là một, trong khi write paths thực tế tách đôi.
S-04P1Scope user phụ thuộc cả branch, department và CRM account filters; vì vậy chênh lệch platform/role có thể làm 2 người nhìn cùng một tuần nhưng thấy tập nhân sự khác nhau.