-
-
Notifications
You must be signed in to change notification settings - Fork 5k
Expand file tree
/
Copy pathorder.ts
More file actions
118 lines (116 loc) · 3.25 KB
/
Copy pathorder.ts
File metadata and controls
118 lines (116 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import { model, OrderStatus } from "@medusajs/framework/utils"
import { Return } from "@models"
import { OrderAddress } from "./address"
import { OrderCreditLine } from "./credit-line"
import { OrderItem } from "./order-item"
import { OrderShipping } from "./order-shipping-method"
import { OrderSummary } from "./order-summary"
import { OrderTransaction } from "./transaction"
const _Order = model
.define("Order", {
id: model.id({ prefix: "order" }).primaryKey(),
display_id: model.autoincrement().searchable(),
region_id: model.text().nullable(),
customer_id: model.text().nullable(),
version: model.number().default(1),
sales_channel_id: model.text().nullable(),
status: model.enum(OrderStatus).default(OrderStatus.PENDING),
is_draft_order: model.boolean().default(false),
email: model.text().searchable().nullable(),
currency_code: model.text(),
no_notification: model.boolean().nullable(),
metadata: model.json().nullable(),
canceled_at: model.dateTime().nullable(),
shipping_address: model
.hasOne<any>(() => OrderAddress, {
mappedBy: undefined,
foreignKey: true,
})
.searchable()
.nullable(),
billing_address: model
.hasOne<any>(() => OrderAddress, {
mappedBy: undefined,
foreignKey: true,
})
.searchable()
.nullable(),
summary: model.hasMany<any>(() => OrderSummary, {
mappedBy: "order",
}),
items: model.hasMany<any>(() => OrderItem, {
mappedBy: "order",
}),
shipping_methods: model.hasMany<any>(() => OrderShipping, {
mappedBy: "order",
}),
transactions: model.hasMany<any>(() => OrderTransaction, {
mappedBy: "order",
}),
credit_lines: model.hasMany<any>(() => OrderCreditLine, {
mappedBy: "order",
}),
returns: model.hasMany<any>(() => Return, {
mappedBy: "order",
}),
})
.cascades({
delete: ["summary", "items", "shipping_methods", "transactions"],
})
.indexes([
{
name: "IDX_order_display_id",
on: ["display_id"],
unique: false,
where: "deleted_at IS NOT NULL",
},
{
name: "IDX_order_region_id",
on: ["region_id"],
unique: false,
where: "deleted_at IS NOT NULL",
},
{
name: "IDX_order_customer_id",
on: ["customer_id"],
unique: false,
where: "deleted_at IS NOT NULL",
},
{
name: "IDX_order_sales_channel_id",
on: ["sales_channel_id"],
unique: false,
where: "deleted_at IS NOT NULL",
},
{
name: "IDX_order_deleted_at",
on: ["deleted_at"],
unique: false,
where: "deleted_at IS NOT NULL",
},
{
name: "IDX_order_currency_code",
on: ["currency_code"],
unique: false,
where: "deleted_at IS NOT NULL",
},
{
name: "IDX_order_shipping_address_id",
on: ["shipping_address_id"],
unique: false,
where: "deleted_at IS NOT NULL",
},
{
name: "IDX_order_billing_address_id",
on: ["billing_address_id"],
unique: false,
where: "deleted_at IS NOT NULL",
},
{
name: "IDX_order_is_draft_order",
on: ["is_draft_order"],
unique: false,
where: "deleted_at IS NOT NULL",
},
])
export const Order = _Order