chore: Migrate notification module to DML (#7835)

This commit is contained in:
Stevche Radevski
2024-07-01 11:17:32 +02:00
committed by GitHub
parent c661180c44
commit 9daec5d7ac
11 changed files with 161 additions and 177 deletions

View File

@@ -1,46 +1,11 @@
import { generateEntityId } from "@medusajs/utils"
import {
ArrayType,
BeforeCreate,
Collection,
Entity,
OnInit,
OneToMany,
PrimaryKey,
Property,
} from "@mikro-orm/core"
import Notification from "./notification"
import { model } from "@medusajs/utils"
import { Notification } from "./notification"
@Entity()
export default class NotificationProvider {
@PrimaryKey({ columnType: "text" })
id: string
@Property({ columnType: "text" })
handle: string
@Property({ columnType: "text" })
name: string
@Property({ columnType: "boolean", defaultRaw: "true" })
is_enabled: boolean = true
@Property({ type: ArrayType })
channels: string[]
@OneToMany({
entity: () => Notification,
mappedBy: (notification) => notification.provider_id,
})
notifications = new Collection<Notification>(this)
@BeforeCreate()
onCreate() {
this.id = generateEntityId(this.id, "notpro")
}
@OnInit()
onInit() {
this.id = generateEntityId(this.id, "notpro")
}
}
export const NotificationProvider = model.define("notificationProvider", {
id: model.id({ prefix: "notpro" }),
handle: model.text(),
name: model.text(),
is_enabled: model.boolean().default(true),
channels: model.array().default([]),
notifications: model.hasMany(() => Notification, { mappedBy: "provider" }),
})