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 tasktrạng tháiPENDING
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
| Field | Type | Required | Ý nghĩa |
|---|---|---|---|
send_to_user_id | number | ✅ | ID user nhận thông báo |
hostname | string | ✅ | Hostname hệ thống gọi |
action_code | string | ✅ | Mã action nghiệp vụ |
notification_type | NotificationType | ❌ | 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_url | string | ❌ | URL điều hướng. Ví dụ https://phenikaa-school.phx.asia/hrm-checkin/leave/b8126c64-d311-46d1-9c93-4195467d2938 |
mobile_push | MobilePushChannel | ❌ | Payload gửi thông báo mobile. Không truyền thì bỏ qua kênh này |
email_push | SendEmailChannel | ❌ | Payload gửi email. Không truyền thì bỏ qua kênh này |
create_required_action | RequiredActionChannel | ❌ | Đí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;
}
| Field | Type | Required | Ý nghĩa |
|---|---|---|---|
title | string | ✅ | Tiêu đề hiển thị trên mobile push |
message | string | ✅ | Nội dung ngắn hiển thị trên mobile push |
module_code | string | ✅ | Mã module phục vụ setting và routing |
app | string | ✅ | TEACHER / PARENT / BUS |
payload | any | ✅ | Payload firebase bắn về cho mobile qua thông báo |
note | string | ❌ | ID liên quan để trace/log mobile push |
description | string | ❌ | Nội dung chi tiết dạng body text trên mobile |
email_push
email_push: {
enabled: true;
data: SendEmail;
}
| Field | Type | Required | Ý nghĩa |
|---|---|---|---|
emailType | EmailType | ✅ | transaction-basic |
subject | string | ✅ | Tiêu đề email |
title | string | ✅ | Tiêu đề lớn trong nội dung email |
previewText | string | ✅ | Preview text của email |
callToActionText | string | ❌ | Text button trong mail |
content | string | ❌ | Nội dung email |
tag | string | ❌ | Tag phân loại email |
footerMessage | string | ❌ | 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.
| Field | Required | Ý 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ế:
- Service trong business gọi
phxPushNotificationService.completeRequireAction(...) phx-nodegọiPOST /emit/inapp-noti/complete-require-actioninapp-noti-consumernhận eventinapp-noti.complete-require-actionRequiredTaskService.completeTask(...)tìm các taskPENDINGtheoschool_id,user_id,required_task_type_code,task_target_idrồi update sangDONE- 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
| Field | Type | Required | Ý nghĩa |
|---|---|---|---|
hostname | string | ✅ | Hostname hệ thống gọi |
user_id | number | ✅ | ID user cần complete required task |
required_task_type_code | string | ✅ | Cùng mã đã dùng lúc tạo task |
task_target_id | string | ✅ | Cùng ref business đã dùng lúc tạo task |
app | string | ❌ | App mobile để emit lại realtime count đúng ngữ cảnh. TEACHER / PARENT / BUS |
3. Danh sách action code đang dùng
| Module | Nhóm nghiệp vụ | Action code |
|---|---|---|
| Chấm công | Làm từ xa | hrm-checkin-remote-don-cho-duyet |
hrm-checkin-remote-phe-duyet-don | ||
| Chấm công | Làm thêm giờ | hrm-checkin-overtime-don-cho-duyet |
hrm-checkin-overtime-phe-duyet-don | ||
| Chấm công | Xin nghỉ | hrm-checkin-leave-don-cho-duyet |
hrm-checkin-leave-phe-duyet-don | ||
| Chấm công | Đi muộn/Về sớm | hrm-checkin-late-early-don-cho-duyet |
hrm-checkin-late-early-phe-duyet-don | ||
| Chấm công | Giải trình công | hrm-checkin-explanation-don-cho-duyet |
hrm-checkin-explanation-phe-duyet-don |