|
1
|
import { |
|
2
|
BelongsTo, |
|
3
|
DmlEntity, |
|
4
|
DMLEntitySchemaBuilder, |
|
5
|
GeoZoneType, |
|
6
|
IdProperty, |
|
7
|
JSONProperty, |
|
8
|
model, |
|
9
|
NullableModifier, |
|
10
|
PrimaryKeyModifier, |
|
11
|
TextProperty, |
|
12
|
} from "@medusajs/framework/utils" |
|
13
|
|
|
14
|
import { ServiceZone } from "./service-zone" |
|
15
|
|
|
16
|
export type GeoZoneSchema = { |
|
17
|
id: PrimaryKeyModifier<string, IdProperty> |
|
18
|
type: TextProperty |
|
19
|
country_code: TextProperty |
|
20
|
province_code?: NullableModifier<string, TextProperty> |
|
21
|
city?: NullableModifier<string, TextProperty> |
|
22
|
postal_expression?: NullableModifier<Record<string, unknown>, JSONProperty> |
|
23
|
service_zone: BelongsTo<() => typeof ServiceZone> |
|
24
|
metadata?: NullableModifier<Record<string, unknown>, JSONProperty> |
|
25
|
} |
|
26
|
|
|
27
|
export const GeoZone = model |
|
28
|
.define("geo_zone", { |
|
29
|
id: model.id({ prefix: "fgz" }).primaryKey(), |
|
30
|
type: model.enum(GeoZoneType).default(GeoZoneType.COUNTRY), |
|
31
|
country_code: model.text(), |
|
32
|
province_code: model.text().nullable(), |
|
33
|
city: model.text().nullable(), |
|
34
|
postal_expression: model.json().nullable(), |
|
35
|
service_zone: model.belongsTo<() => typeof ServiceZone>(() => ServiceZone, { |
|
36
|
mappedBy: "geo_zones", |
|
37
|
}), |
|
38
|
metadata: model.json().nullable(), |
|
39
|
}) |
|
40
|
.indexes([ |
|
41
|
{ |
|
42
|
on: ["country_code"], |
|
43
|
where: "deleted_at IS NULL", |
|
44
|
}, |
|
45
|
{ |
|
46
|
on: ["province_code"], |
|
47
|
where: "deleted_at IS NULL", |
|
48
|
}, |
|
49
|
{ |
|
50
|
on: ["city"], |
|
51
|
where: "deleted_at IS NULL", |
|
52
|
}, |
|
53
|
]) as unknown as DmlEntity<DMLEntitySchemaBuilder<GeoZoneSchema>, "GeoZone"> |