Files
medusa-store/packages/modules/customer/src/models/customer-group.ts
2024-12-11 14:37:27 +05:30

28 lines
681 B
TypeScript

import { model } from "@medusajs/framework/utils"
import Customer from "./customer"
import { CustomerGroupCustomer } from "@models"
const CustomerGroup = model
.define("CustomerGroup", {
id: model.id({ prefix: "cusgroup" }).primaryKey(),
name: model.text().searchable(),
metadata: model.json().nullable(),
created_by: model.text().nullable(),
customers: model.manyToMany(() => Customer, {
mappedBy: "groups",
pivotEntity: () => CustomerGroupCustomer,
}),
})
.indexes([
{
on: ["name"],
unique: true,
where: "deleted_at IS NULL",
},
])
.cascades({
detach: ["customers"],
})
export default CustomerGroup