|
1
|
import { model, NotificationStatus } from "@medusajs/framework/utils" |
|
2
|
import { NotificationProvider } from "./notification-provider" |
|
3
|
|
|
4
|
// We probably want to have a TTL for each entry, so we don't bloat the DB (and also for GDPR reasons if TTL < 30 days). |
|
5
|
export const Notification = model.define("notification", { |
|
6
|
id: model.id({ prefix: "noti" }).primaryKey(), |
|
7
|
// This can be an email, phone number, or username, depending on the channel. |
|
8
|
to: model.text().searchable(), |
|
9
|
// This can be an email, phone number, or username, depending on the channel. |
|
10
|
from: model.text().searchable().nullable(), |
|
11
|
channel: model.text(), |
|
12
|
// The template name in the provider's system. |
|
13
|
template: model.text().nullable(), |
|
14
|
// The data that gets passed over to the provider for rendering the notification. |
|
15
|
data: model.json().nullable(), |
|
16
|
// Additional data specific to the channel or provider. For example, cc and bcc for emails. |
|
17
|
provider_data: model.json().nullable(), |
|
18
|
// This can be the event name, the workflow, or anything else that can help to identify what triggered the notification. |
|
19
|
trigger_type: model.text().nullable(), |
|
20
|
// The ID of the resource this notification is for, if applicable. Useful for displaying relevant information in the UI |
|
21
|
resource_id: model.text().searchable().nullable(), |
|
22
|
// The typeame of the resource this notification is for, if applicable, eg. "order" |
|
23
|
resource_type: model.text().nullable(), |
|
24
|
// The ID of the receiver of the notification, if applicable. This can be a customer, user, a company, or anything else. |
|
25
|
receiver_id: model.text().index().nullable(), |
|
26
|
// The original notification, in case this is a retried notification. |
|
27
|
original_notification_id: model.text().nullable(), |
|
28
|
idempotency_key: model.text().unique().nullable(), |
|
29
|
// The ID of the notification in the external system, if applicable |
|
30
|
external_id: model.text().nullable(), |
|
31
|
// The status of the notification |
|
32
|
status: model.enum(NotificationStatus).default(NotificationStatus.PENDING), |
|
33
|
|
|
34
|
provider: model |
|
35
|
.belongsTo(() => NotificationProvider, { mappedBy: "notifications" }) |
|
36
|
.nullable(), |
|
37
|
}) |