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_idnumberID user nhận thông báo
hostnamestringHostname hệ thống gọi
action_codestringMã action nghiệp vụ
notification_typeNotificationTypeTab 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_urlstringURL điều hướng. Ví dụ https://phenikaa-school.phx.asia/hrm-checkin/leave/b8126c64-d311-46d1-9c93-4195467d2938
mobile_pushMobilePushChannelPayload gửi thông báo mobile. Không truyền thì bỏ qua kênh này
email_pushSendEmailChannelPayload 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_pushcreate_required_action trong cùng một lần gọi.

mobile_push

mobile_push: {
enabled: true;
data: MobilePush;
}
FieldTypeRequiredÝ nghĩa
titlestringTiêu đề hiển thị trên mobile push
messagestringNội dung ngắn hiển thị trên mobile push
module_codestringMã module phục vụ setting và routing
appstringTEACHER / PARENT / BUS
payloadanyPayload firebase bắn về cho mobile qua thông báo
notestringID liên quan để trace/log mobile push
descriptionstringNội dung chi tiết dạng body text trên mobile

email_push

email_push: {
enabled: true;
data: SendEmail;
}
FieldTypeRequiredÝ nghĩa
emailTypeEmailTypetransaction-basic
subjectstringTiêu đề email
titlestringTiêu đề lớn trong nội dung email
previewTextstringPreview text của email
callToActionTextstringText button trong mail
contentstringNội dung email
tagstringTag phân loại email
footerMessagestringNộ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_idID của đối tượng nghiệp vụ cần xử lý. Ví dụ trong HRM thì đây là ID của đơn.
due_dateHạ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, required_task_type_code, 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,
required_task_type_code: REQUIRED_TASK_TYPE_CODE.REMOTE,
app: "TEACHER",
});

Payload completeRequireAction

FieldTypeRequiredÝ nghĩa
hostnamestringHostname hệ thống gọi
user_idnumberID user cần complete required task
required_task_type_codestringCùng mã đã dùng lúc tạo task
task_target_idstringCùng ref business đã dùng lúc tạo task
appstringApp 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