1 import { model } from "@medusajs/framework/utils"
2
3 import { FulfillmentAddress } from "./address"
4 import { FulfillmentItem } from "./fulfillment-item"
5 import { FulfillmentLabel } from "./fulfillment-label"
6 import { FulfillmentProvider } from "./fulfillment-provider"
7 import { ShippingOption } from "./shipping-option"
8
9 export const Fulfillment = model
10 .define("fulfillment", {
11 id: model.id({ prefix: "ful" }).primaryKey(),
12 location_id: model.text(),
13 packed_at: model.dateTime().nullable(),
14 shipped_at: model.dateTime().nullable(),
15 marked_shipped_by: model.text().nullable(),
16 created_by: model.text().nullable(),
17 delivered_at: model.dateTime().nullable(),
18 canceled_at: model.dateTime().nullable(),
19 data: model.json().nullable(),
20 requires_shipping: model.boolean().default(true),
21 items: model.hasMany(() => FulfillmentItem, {
22 mappedBy: "fulfillment",
23 }),
24 labels: model.hasMany(() => FulfillmentLabel, {
25 mappedBy: "fulfillment",
26 }),
27 provider: model
28 .hasOne(() => FulfillmentProvider, {
29 foreignKey: true,
30 mappedBy: undefined,
31 })
32 .nullable(),
33 shipping_option: model
34 .belongsTo(() => ShippingOption, {
35 mappedBy: "fulfillments",
36 })
37 .nullable(),
38 delivery_address: model
39 .hasOne(() => FulfillmentAddress, {
40 foreignKey: true,
41 mappedBy: undefined,
42 })
43 .nullable(),
44 metadata: model.json().nullable(),
45 })
46 .indexes([
47 {
48 on: ["location_id"],
49 where: "deleted_at IS NULL",
50 },
51 ])
52 .cascades({
53 delete: ["delivery_address", "items", "labels"],
54 })