Skip to main content

PHXPushNotificationService

PHXPushNotificationService là service của phx-node dùng để đẩy notification sang hệ thống inapp-noti-consumer. Trong một lần gọi send(...), có thể đồng thời:

  • tạo bản ghi in-app notification
  • đẩy vào queue gửi email
  • dẩy vào queue mobile push
  • tạo required task trạng thái PENDING

Service này không tự quyết định business flow approve/reject. Khi user xử lý xong nghiệp vụ, phải đi qua luồng completeRequireAction(...) riêng để đóng required task.

1. Tạo push notification​

Gọi PHXPushNotificationService.send(payload) — payload sẽ được gửi lên POST /emit/inapp-noti.

Payload chính​

FieldTypeRequiredÝ nghĩa
send_to_user_idnumber✅ID user nhận thông báo
hostnamestring✅Hostname hệ thống gọi
action_codestring✅Mã action nghiệp vụ
notification_typeNotificationType❌Tab hiển thị notification. Mặc định SYSTEM, truyền TO_ME nếu muốn hiển thị ở tab Gửi tới tôi
call_to_action_urlstring❌URL điều hướng. Ví dụ https://phenikaa-school.phx.asia/hrm-checkin/leave/b8126c64-d311-46d1-9c93-4195467d2938
mobile_pushMobilePushChannel❌Payload gửi thông báo mobile. Không truyền thì bỏ qua kênh này
email_pushSendEmailChannel❌Payload gửi email. Không truyền thì bỏ qua kênh này
create_required_actionRequiredActionChannel❌Đính kèm nếu notification là việc user cần làm; downstream sẽ tạo required task trạng thái PENDING

Có thể truyền đồng thời mobile_push, email_push và create_required_action trong cùng một lần gọi.

mobile_push​

mobile_push: {
enabled: true;
data: MobilePush;
}
FieldTypeRequiredÝ nghĩa
titlestring✅Tiêu đề hiển thị trên mobile push
messagestring✅Nội dung ngắn hiển thị trên mobile push
module_codestring✅Mã module phục vụ setting và routing
appstring✅TEACHER / PARENT / BUS
payloadany✅Payload firebase bắn về cho mobile qua thông báo
notestring❌ID liên quan để trace/log mobile push
descriptionstring❌Nội dung chi tiết dạng body text trên mobile

email_push​

email_push: {
enabled: true;
data: SendEmail;
}
FieldTypeRequiredÝ nghĩa
emailTypeEmailType✅transaction-basic
subjectstring✅Tiêu đề email
titlestring✅Tiêu đề lớn trong nội dung email
previewTextstring✅Preview text của email
callToActionTextstring❌Text button trong mail
contentstring❌Nội dung email
tagstring❌Tag phân loại email
footerMessagestring❌Nội dung footer email

create_required_action​

create_required_action: {
enabled: true;
data: RequiredAction;
}

Khi có field này, inapp-noti-consumer sẽ tạo required task ở trạng thái PENDING.

FieldRequiredÝ nghĩa
task_target_id✅ID của đối tượng nghiệp vụ cần xử lý. Ví dụ trong HRM thì đây là ID của đơn.
due_date❌Hạn xử lý. Ví dụ: "2025-05-19T17:00:00+07:00"
await phxPushNotificationService.send({
send_to_user_id: nextApproverId,
hostname,
action_code: "hrm-checkin-remote-don-cho-duyet",
notification_type: NotificationType.TO_ME,
email_push: {
enabled: true,
data: {
emailType: EmailType.HRM_REMIND,
subject: "Don remote cho duyet",
title: "Ban co 1 don can xu ly",
previewText: "Nhan vao de xem chi tiet",
content: "<p>Ban co 1 don remote dang cho duyet</p>",
callToActionURL: "https://portal.example.com/request/123",
},
},
mobile_push: {
enabled: true,
data: {
title: "Don remote",
message: "Ban co 1 don dang cho duyet",
module_code: "HRM_CHECKIN",
app: "TEACHER",
payload: {
action: "OPEN_REMOTE_DETAIL_PAGE",
task_target_id: requestId,
},
description: "Ban co 1 don remote dang cho duyet",
},
},
create_required_action: {
enabled: true,
data: {
task_target_id: requestId,
},
},
});

2. Complete notification​

Khi user xử lý xong, không gọi lại send(...). Bên phx-node dùng hàm:

PHXPushNotificationService.completeRequireAction(payload)

Luồng thực tế:

  1. Service trong business gọi phxPushNotificationService.completeRequireAction(...)
  2. phx-node gọi POST /emit/inapp-noti/complete-require-action
  3. inapp-noti-consumer nhận event inapp-noti.complete-require-action
  4. RequiredTaskService.completeTask(...) tìm các task PENDING theo school_id, user_id, task_target_id rồi update sang DONE
  5. Sau khi complete, consumer emit lại socket counter cho user
await phxPushNotificationService.completeRequireAction({
hostname,
user_id: approverId,
task_target_id: requestId,
app: "TEACHER",
});

Payload completeRequireAction​

FieldTypeRequiredÝ nghĩa
hostnamestring✅Hostname hệ thống gọi
user_idnumber✅ID user cần complete required task
task_target_idstring✅Cùng ref business đã dùng lúc tạo task
appstring❌App mobile để emit lại realtime count đúng ngữ cảnh. TEACHER / PARENT / BUS

3. Danh sách action code đang dùng​

ModuleNhóm nghiệp vụAction code
Chấm côngLàm từ xahrm-checkin-remote-don-cho-duyet
hrm-checkin-remote-phe-duyet-don
Chấm côngLàm thêm giờhrm-checkin-overtime-don-cho-duyet
hrm-checkin-overtime-phe-duyet-don
Chấm côngXin nghỉhrm-checkin-leave-don-cho-duyet
hrm-checkin-leave-phe-duyet-don
Chấm côngĐi muộn/Về sớmhrm-checkin-late-early-don-cho-duyet
hrm-checkin-late-early-phe-duyet-don
Chấm côngGiải trình cônghrm-checkin-explanation-don-cho-duyet
hrm-checkin-explanation-phe-duyet-don