Files
tm_back/internal/notification/entity.go
T
Mazyar aafae2a26f Enhance notification entity and service for improved delivery channel handling
- Introduced new event types for notifications, including email and push, to support a broader range of delivery methods.
- Added a `persistedEventType` function to map delivery channels to their corresponding event types, improving clarity and maintainability.
- Updated the `sendToRecipient` method to ensure in-app notifications are always persisted, enhancing the reliability of notification records.
- Improved error logging for in-app notification persistence failures, providing better context for debugging.

This update enhances the notification system's flexibility and reliability by supporting multiple delivery channels and improving error handling.
2026-07-11 21:07:37 +03:30

89 lines
2.9 KiB
Go

package notification
// NotificationType represents the type of notification
type NotificationType string
const (
NotificationTypeInfo NotificationType = "info"
NotificationTypeWarning NotificationType = "warning"
NotificationTypeAlert NotificationType = "alert"
NotificationTypeReject NotificationType = "reject"
)
// NotificationPriority represents the priority level of notification
type NotificationPriority string
const (
NotificationPriorityLow NotificationPriority = "low"
NotificationPriorityMedium NotificationPriority = "medium"
NotificationPriorityImportant NotificationPriority = "important"
)
// DeliveryChannel represents the delivery channel for notification
type DeliveryChannel string
const (
DeliveryChannelPush DeliveryChannel = "push"
DeliveryChannelEmail DeliveryChannel = "email"
DeliveryChannelInApp DeliveryChannel = "in_app"
)
// Persisted event types for stored notifications (admin list / notification center).
const (
EventTypeInApp = "in_app"
EventTypeEmail = "email"
EventTypePush = "push"
)
// persistedEventType maps a delivery channel to the event_type stored in MongoDB.
func persistedEventType(channel DeliveryChannel) (string, bool) {
switch channel {
case DeliveryChannelEmail:
return EventTypeEmail, true
case DeliveryChannelPush:
return EventTypePush, true
case DeliveryChannelInApp:
return EventTypeInApp, true
default:
return "", false
}
}
// DeliveryStatus represents the delivery status of notification
type NotificationStatus string
const (
DeliveryStatusPending NotificationStatus = "pending"
DeliveryStatusSent NotificationStatus = "sent"
DeliveryStatusFailed NotificationStatus = "failed"
)
// TargetAudienceType represents the type of target audience
// Supported audience types:
// - all_users: All users in the system
// - specific_users: Specific users by their IDs
// - all_role: All users with a specific role (e.g., all admins)
// - specific_role: Users with a specific role, optionally filtered by tender
// - specific_company: All users belonging to a specific company
// - all_companies: All users from all companies
// - specific_customer: All users belonging to a specific customer
// - all_customers: All users from all customers
type TargetAudienceType string
const (
TargetAudienceAllUsers TargetAudienceType = "all_users"
TargetAudienceSpecificUsers TargetAudienceType = "specific_users"
TargetAudienceAllRole TargetAudienceType = "all_role"
TargetAudienceSpecificRole TargetAudienceType = "specific_role"
TargetAudienceAllCompanies TargetAudienceType = "all_companies"
TargetAudienceSpecificCompany TargetAudienceType = "specific_company"
TargetAudienceAllCustomers TargetAudienceType = "all_customers"
TargetAudienceSpecificCustomer TargetAudienceType = "specific_customer"
)
type notificationRecipient struct {
UserID string
Email string
DeviceTokens []string
}