1 import { model, OrderChangeStatus } from "@medusajs/framework/utils"
2 import { Order } from "./order"
3 import { OrderChangeAction } from "./order-change-action"
4
5 const _OrderChange = model
6 .define("OrderChange", {
7 id: model.id({ prefix: "ordch" }).primaryKey(),
8 return_id: model.text().nullable(),
9 claim_id: model.text().nullable(),
10 exchange_id: model.text().nullable(),
11 version: model.number(),
12 change_type: model.text().nullable(),
13 description: model.text().nullable(),
14 status: model
15 .enum(OrderChangeStatus)
16 .default(OrderChangeStatus.PENDING)
17 .nullable(),
18 internal_note: model.text().nullable(),
19 created_by: model.text().nullable(),
20 requested_by: model.text().nullable(),
21 requested_at: model.dateTime().nullable(),
22 confirmed_by: model.text().nullable(),
23 confirmed_at: model.dateTime().nullable(),
24 declined_by: model.text().nullable(),
25 declined_reason: model.text().nullable(),
26 metadata: model.json().nullable(),
27 declined_at: model.dateTime().nullable(),
28 canceled_by: model.text().nullable(),
29 canceled_at: model.dateTime().nullable(),
30 /**
31 * @since 2.12.0
32 */
33 carry_over_promotions: model.boolean().nullable(),
34 /**
35 * @since 2.19.0
36 */
37 no_notification: model.boolean().nullable(),
38 order: model.belongsTo<() => typeof Order>(() => Order, {
39 mappedBy: "changes",
40 }),
41 actions: model.hasMany<() => typeof OrderChangeAction>(
42 () => OrderChangeAction
43 ),
44 })
45 .cascades({
46 delete: ["actions"],
47 })
48 .indexes([
49 {
50 name: "IDX_order_change_order_id",
51 on: ["order_id"],
52 unique: false,
53 where: "deleted_at IS NULL",
54 },
55 {
56 name: "IDX_order_change_return_id",
57 on: ["return_id"],
58 unique: false,
59 where: "return_id IS NOT NULL AND deleted_at IS NULL",
60 },
61 {
62 name: "IDX_order_change_claim_id",
63 on: ["claim_id"],
64 unique: false,
65 where: "claim_id IS NOT NULL AND deleted_at IS NULL",
66 },
67 {
68 name: "IDX_order_change_exchange_id",
69 on: ["exchange_id"],
70 unique: false,
71 where: "exchange_id IS NOT NULL AND deleted_at IS NULL",
72 },
73 {
74 name: "IDX_order_change_status",
75 on: ["status"],
76 unique: false,
77 where: "deleted_at IS NULL",
78 },
79 {
80 name: "IDX_order_change_deleted_at",
81 on: ["deleted_at"],
82 unique: false,
83 where: "deleted_at IS NOT NULL",
84 },
85 {
86 name: "IDX_order_change_version",
87 on: ["order_id", "version"],
88 unique: false,
89 where: "deleted_at IS NULL",
90 },
91 ])
92
93 export const OrderChange = _OrderChange