|
1
|
import { |
|
2
|
BelongsTo, |
|
3
|
DmlEntity, |
|
4
|
DMLEntitySchemaBuilder, |
|
5
|
HasMany, |
|
6
|
IdProperty, |
|
7
|
JSONProperty, |
|
8
|
model, |
|
9
|
NullableModifier, |
|
10
|
PrimaryKeyModifier, |
|
11
|
TextProperty, |
|
12
|
} from "@medusajs/framework/utils" |
|
13
|
|
|
14
|
import { FulfillmentSet } from "./fulfillment-set" |
|
15
|
import { GeoZone } from "./geo-zone" |
|
16
|
import { ShippingOption } from "./shipping-option" |
|
17
|
|
|
18
|
export type ServiceZoneSchema = { |
|
19
|
id: PrimaryKeyModifier<string, IdProperty> |
|
20
|
name: TextProperty |
|
21
|
fulfillment_set: BelongsTo<() => typeof FulfillmentSet> |
|
22
|
geo_zones: HasMany<() => typeof GeoZone> |
|
23
|
shipping_options: HasMany<() => typeof ShippingOption> |
|
24
|
metadata: NullableModifier<Record<string, unknown>, JSONProperty> |
|
25
|
} |
|
26
|
|
|
27
|
export const ServiceZone = model |
|
28
|
.define("service_zone", { |
|
29
|
id: model.id({ prefix: "serzo" }).primaryKey(), |
|
30
|
name: model.text(), |
|
31
|
fulfillment_set: model.belongsTo<() => typeof FulfillmentSet>( |
|
32
|
() => FulfillmentSet, |
|
33
|
{ |
|
34
|
mappedBy: "service_zones", |
|
35
|
} |
|
36
|
), |
|
37
|
geo_zones: model.hasMany<() => typeof GeoZone>(() => GeoZone, { |
|
38
|
mappedBy: "service_zone", |
|
39
|
}), |
|
40
|
shipping_options: model.hasMany<() => typeof ShippingOption>( |
|
41
|
() => ShippingOption, |
|
42
|
{ |
|
43
|
mappedBy: "service_zone", |
|
44
|
} |
|
45
|
), |
|
46
|
metadata: model.json().nullable(), |
|
47
|
}) |
|
48
|
.indexes([ |
|
49
|
{ |
|
50
|
on: ["name"], |
|
51
|
unique: true, |
|
52
|
where: "deleted_at IS NULL", |
|
53
|
}, |
|
54
|
]) |
|
55
|
.cascades({ |
|
56
|
delete: ["geo_zones", "shipping_options"], |
|
57
|
}) as unknown as DmlEntity< |
|
58
|
DMLEntitySchemaBuilder<ServiceZoneSchema>, |
|
59
|
"ServiceZone" |
|
60
|
> |