chore(fulfillment, utils): Migrate module to DML (#10617)
**What**
- Allow to provide `foreignKeyName` option for hasOne and belongsTo relationships
- `model.hasOne(() => OtherEntity, { foreignKey: true, foreignKeyName: 'other_entity_something_id' })`
- The above will also output a generated type that takes into consideration the custom fk name 🔽
- Update types to account for defined custom foreign key name
- Fix joiner config linkable generation to account for custom linkable keys that provide a public API for their model but are not part of the list of the models included in the MedusaService
- This was supposed to be handled correctly but the implementation was not considering that custom linkable keys could reference models not part of the one provided to medusa service
- Migrate fulfillment module to DML
- Fix has one with fk behaviour and hooks (the relation should be assigned but not the fk)
- Fix has one belongsTo hooks (the relation should be assigned but not the fk)
- Fix hasOneWithFk and belongsTo non persisted fk to be selectable
- Allow to define `belongsTo` without other side definition for `ManyToOne` with no counter part defined
- Meaning that if a user defined `belongsTo` on one side andnot mapped by and no counter part on the other entity it will be considered as a `ManyToOne`
- `orphanRemoval` on `OneToOne` have been removed, this means that when assigning a new object relation to an entity, the previous one gets deconected but not deleted automatically. This prevent removing data un volountarely
**NOTE**
As per our convention here are some information to keep in mind
**HasOne <> BelongsTo**
Define `OneToOne`, The foreign key is owned by the belongs to and the relation needs to be provided to cascade if wanted
**HasMany <> BelongsTo**
Define `OneToMane` <> `ManyToOne`, the foreign key is owned by the many to one and for those relation no cascade will be performed, the foreign key must be provided. For the `HasMany` the cascade is available
**HasOne (with FK)**
Will act similarly to belongs to with **HasOne <> BelongsTo**
Co-authored-by: Carlos R. L. Rodrigues <37986729+carlos-r-l-rodrigues@users.noreply.github.com>
This commit is contained in:
co-authored by
Carlos R. L. Rodrigues
parent
65007c49f6
commit
100da64242
@@ -1,5 +1,7 @@
|
||||
{
|
||||
"namespaces": ["public"],
|
||||
"namespaces": [
|
||||
"public"
|
||||
],
|
||||
"name": "public",
|
||||
"tables": [
|
||||
{
|
||||
@@ -150,15 +152,17 @@
|
||||
"indexes": [
|
||||
{
|
||||
"keyName": "IDX_fulfillment_address_deleted_at",
|
||||
"columnNames": ["deleted_at"],
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_fulfillment_address_deleted_at\" ON \"fulfillment_address\" (deleted_at) WHERE deleted_at IS NOT NULL"
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_fulfillment_address_deleted_at\" ON \"fulfillment_address\" (deleted_at) WHERE deleted_at IS NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "fulfillment_address_pkey",
|
||||
"columnNames": ["id"],
|
||||
"columnNames": [
|
||||
"id"
|
||||
],
|
||||
"composite": false,
|
||||
"primary": true,
|
||||
"unique": true
|
||||
@@ -187,14 +191,56 @@
|
||||
"nullable": false,
|
||||
"default": "true",
|
||||
"mappedType": "boolean"
|
||||
},
|
||||
"created_at": {
|
||||
"name": "created_at",
|
||||
"type": "timestamptz",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": false,
|
||||
"length": 6,
|
||||
"default": "now()",
|
||||
"mappedType": "datetime"
|
||||
},
|
||||
"updated_at": {
|
||||
"name": "updated_at",
|
||||
"type": "timestamptz",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": false,
|
||||
"length": 6,
|
||||
"default": "now()",
|
||||
"mappedType": "datetime"
|
||||
},
|
||||
"deleted_at": {
|
||||
"name": "deleted_at",
|
||||
"type": "timestamptz",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": true,
|
||||
"length": 6,
|
||||
"mappedType": "datetime"
|
||||
}
|
||||
},
|
||||
"name": "fulfillment_provider",
|
||||
"schema": "public",
|
||||
"indexes": [
|
||||
{
|
||||
"keyName": "IDX_fulfillment_provider_deleted_at",
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_fulfillment_provider_deleted_at\" ON \"fulfillment_provider\" (deleted_at) WHERE deleted_at IS NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "fulfillment_provider_pkey",
|
||||
"columnNames": ["id"],
|
||||
"columnNames": [
|
||||
"id"
|
||||
],
|
||||
"composite": false,
|
||||
"primary": true,
|
||||
"unique": true
|
||||
@@ -277,25 +323,27 @@
|
||||
"name": "fulfillment_set",
|
||||
"schema": "public",
|
||||
"indexes": [
|
||||
{
|
||||
"keyName": "IDX_fulfillment_set_deleted_at",
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_fulfillment_set_deleted_at\" ON \"fulfillment_set\" (deleted_at) WHERE deleted_at IS NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_fulfillment_set_name_unique",
|
||||
"columnNames": ["name"],
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE UNIQUE INDEX IF NOT EXISTS \"IDX_fulfillment_set_name_unique\" ON \"fulfillment_set\" (name) WHERE deleted_at IS NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_fulfillment_set_deleted_at",
|
||||
"columnNames": ["deleted_at"],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_fulfillment_set_deleted_at\" ON \"fulfillment_set\" (deleted_at) WHERE deleted_at IS NOT NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "fulfillment_set_pkey",
|
||||
"columnNames": ["id"],
|
||||
"columnNames": [
|
||||
"id"
|
||||
],
|
||||
"composite": false,
|
||||
"primary": true,
|
||||
"unique": true
|
||||
@@ -324,15 +372,6 @@
|
||||
"nullable": false,
|
||||
"mappedType": "text"
|
||||
},
|
||||
"metadata": {
|
||||
"name": "metadata",
|
||||
"type": "jsonb",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": true,
|
||||
"mappedType": "json"
|
||||
},
|
||||
"fulfillment_set_id": {
|
||||
"name": "fulfillment_set_id",
|
||||
"type": "text",
|
||||
@@ -342,6 +381,15 @@
|
||||
"nullable": false,
|
||||
"mappedType": "text"
|
||||
},
|
||||
"metadata": {
|
||||
"name": "metadata",
|
||||
"type": "jsonb",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": true,
|
||||
"mappedType": "json"
|
||||
},
|
||||
"created_at": {
|
||||
"name": "created_at",
|
||||
"type": "timestamptz",
|
||||
@@ -378,17 +426,9 @@
|
||||
"name": "service_zone",
|
||||
"schema": "public",
|
||||
"indexes": [
|
||||
{
|
||||
"keyName": "IDX_service_zone_name_unique",
|
||||
"columnNames": ["name"],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE UNIQUE INDEX IF NOT EXISTS \"IDX_service_zone_name_unique\" ON \"service_zone\" (name) WHERE deleted_at IS NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_service_zone_fulfillment_set_id",
|
||||
"columnNames": ["fulfillment_set_id"],
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
@@ -396,15 +436,25 @@
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_service_zone_deleted_at",
|
||||
"columnNames": ["deleted_at"],
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_service_zone_deleted_at\" ON \"service_zone\" (deleted_at) WHERE deleted_at IS NOT NULL"
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_service_zone_deleted_at\" ON \"service_zone\" (deleted_at) WHERE deleted_at IS NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_service_zone_name_unique",
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE UNIQUE INDEX IF NOT EXISTS \"IDX_service_zone_name_unique\" ON \"service_zone\" (name) WHERE deleted_at IS NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "service_zone_pkey",
|
||||
"columnNames": ["id"],
|
||||
"columnNames": [
|
||||
"id"
|
||||
],
|
||||
"composite": false,
|
||||
"primary": true,
|
||||
"unique": true
|
||||
@@ -414,9 +464,13 @@
|
||||
"foreignKeys": {
|
||||
"service_zone_fulfillment_set_id_foreign": {
|
||||
"constraintName": "service_zone_fulfillment_set_id_foreign",
|
||||
"columnNames": ["fulfillment_set_id"],
|
||||
"columnNames": [
|
||||
"fulfillment_set_id"
|
||||
],
|
||||
"localTableName": "public.service_zone",
|
||||
"referencedColumnNames": ["id"],
|
||||
"referencedColumnNames": [
|
||||
"id"
|
||||
],
|
||||
"referencedTableName": "public.fulfillment_set",
|
||||
"deleteRule": "cascade",
|
||||
"updateRule": "cascade"
|
||||
@@ -442,7 +496,12 @@
|
||||
"primary": false,
|
||||
"nullable": false,
|
||||
"default": "'country'",
|
||||
"enumItems": ["country", "province", "city", "zip"],
|
||||
"enumItems": [
|
||||
"country",
|
||||
"province",
|
||||
"city",
|
||||
"zip"
|
||||
],
|
||||
"mappedType": "enum"
|
||||
},
|
||||
"country_code": {
|
||||
@@ -472,15 +531,6 @@
|
||||
"nullable": true,
|
||||
"mappedType": "text"
|
||||
},
|
||||
"service_zone_id": {
|
||||
"name": "service_zone_id",
|
||||
"type": "text",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": false,
|
||||
"mappedType": "text"
|
||||
},
|
||||
"postal_expression": {
|
||||
"name": "postal_expression",
|
||||
"type": "jsonb",
|
||||
@@ -490,6 +540,15 @@
|
||||
"nullable": true,
|
||||
"mappedType": "json"
|
||||
},
|
||||
"service_zone_id": {
|
||||
"name": "service_zone_id",
|
||||
"type": "text",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": false,
|
||||
"mappedType": "text"
|
||||
},
|
||||
"metadata": {
|
||||
"name": "metadata",
|
||||
"type": "jsonb",
|
||||
@@ -535,33 +594,9 @@
|
||||
"name": "geo_zone",
|
||||
"schema": "public",
|
||||
"indexes": [
|
||||
{
|
||||
"keyName": "IDX_geo_zone_country_code",
|
||||
"columnNames": ["country_code"],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_geo_zone_country_code\" ON \"geo_zone\" (country_code) WHERE deleted_at IS NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_geo_zone_province_code",
|
||||
"columnNames": ["province_code"],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_geo_zone_province_code\" ON \"geo_zone\" (province_code) WHERE deleted_at IS NULL AND province_code IS NOT NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_geo_zone_city",
|
||||
"columnNames": ["city"],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_geo_zone_city\" ON \"geo_zone\" (city) WHERE deleted_at IS NULL AND city IS NOT NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_geo_zone_service_zone_id",
|
||||
"columnNames": ["service_zone_id"],
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
@@ -569,15 +604,41 @@
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_geo_zone_deleted_at",
|
||||
"columnNames": ["deleted_at"],
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_geo_zone_deleted_at\" ON \"geo_zone\" (deleted_at) WHERE deleted_at IS NOT NULL"
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_geo_zone_deleted_at\" ON \"geo_zone\" (deleted_at) WHERE deleted_at IS NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_geo_zone_country_code",
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_geo_zone_country_code\" ON \"geo_zone\" (country_code) WHERE deleted_at IS NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_geo_zone_province_code",
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_geo_zone_province_code\" ON \"geo_zone\" (province_code) WHERE deleted_at IS NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_geo_zone_city",
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_geo_zone_city\" ON \"geo_zone\" (city) WHERE deleted_at IS NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "geo_zone_pkey",
|
||||
"columnNames": ["id"],
|
||||
"columnNames": [
|
||||
"id"
|
||||
],
|
||||
"composite": false,
|
||||
"primary": true,
|
||||
"unique": true
|
||||
@@ -587,9 +648,13 @@
|
||||
"foreignKeys": {
|
||||
"geo_zone_service_zone_id_foreign": {
|
||||
"constraintName": "geo_zone_service_zone_id_foreign",
|
||||
"columnNames": ["service_zone_id"],
|
||||
"columnNames": [
|
||||
"service_zone_id"
|
||||
],
|
||||
"localTableName": "public.geo_zone",
|
||||
"referencedColumnNames": ["id"],
|
||||
"referencedColumnNames": [
|
||||
"id"
|
||||
],
|
||||
"referencedTableName": "public.service_zone",
|
||||
"deleteRule": "cascade",
|
||||
"updateRule": "cascade"
|
||||
@@ -672,15 +737,17 @@
|
||||
"indexes": [
|
||||
{
|
||||
"keyName": "IDX_shipping_option_type_deleted_at",
|
||||
"columnNames": ["deleted_at"],
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_shipping_option_type_deleted_at\" ON \"shipping_option_type\" (deleted_at) WHERE deleted_at IS NOT NULL"
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_shipping_option_type_deleted_at\" ON \"shipping_option_type\" (deleted_at) WHERE deleted_at IS NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "shipping_option_type_pkey",
|
||||
"columnNames": ["id"],
|
||||
"columnNames": [
|
||||
"id"
|
||||
],
|
||||
"composite": false,
|
||||
"primary": true,
|
||||
"unique": true
|
||||
@@ -763,25 +830,27 @@
|
||||
"name": "shipping_profile",
|
||||
"schema": "public",
|
||||
"indexes": [
|
||||
{
|
||||
"keyName": "IDX_shipping_profile_deleted_at",
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_shipping_profile_deleted_at\" ON \"shipping_profile\" (deleted_at) WHERE deleted_at IS NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_shipping_profile_name_unique",
|
||||
"columnNames": ["name"],
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE UNIQUE INDEX IF NOT EXISTS \"IDX_shipping_profile_name_unique\" ON \"shipping_profile\" (name) WHERE deleted_at IS NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_shipping_profile_deleted_at",
|
||||
"columnNames": ["deleted_at"],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_shipping_profile_deleted_at\" ON \"shipping_profile\" (deleted_at) WHERE deleted_at IS NOT NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "shipping_profile_pkey",
|
||||
"columnNames": ["id"],
|
||||
"columnNames": [
|
||||
"id"
|
||||
],
|
||||
"composite": false,
|
||||
"primary": true,
|
||||
"unique": true
|
||||
@@ -818,9 +887,30 @@
|
||||
"primary": false,
|
||||
"nullable": false,
|
||||
"default": "'flat'",
|
||||
"enumItems": ["calculated", "flat"],
|
||||
"enumItems": [
|
||||
"calculated",
|
||||
"flat"
|
||||
],
|
||||
"mappedType": "enum"
|
||||
},
|
||||
"data": {
|
||||
"name": "data",
|
||||
"type": "jsonb",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": true,
|
||||
"mappedType": "json"
|
||||
},
|
||||
"metadata": {
|
||||
"name": "metadata",
|
||||
"type": "jsonb",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": true,
|
||||
"mappedType": "json"
|
||||
},
|
||||
"service_zone_id": {
|
||||
"name": "service_zone_id",
|
||||
"type": "text",
|
||||
@@ -848,24 +938,6 @@
|
||||
"nullable": true,
|
||||
"mappedType": "text"
|
||||
},
|
||||
"data": {
|
||||
"name": "data",
|
||||
"type": "jsonb",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": true,
|
||||
"mappedType": "json"
|
||||
},
|
||||
"metadata": {
|
||||
"name": "metadata",
|
||||
"type": "jsonb",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": true,
|
||||
"mappedType": "json"
|
||||
},
|
||||
"shipping_option_type_id": {
|
||||
"name": "shipping_option_type_id",
|
||||
"type": "text",
|
||||
@@ -911,16 +983,9 @@
|
||||
"name": "shipping_option",
|
||||
"schema": "public",
|
||||
"indexes": [
|
||||
{
|
||||
"columnNames": ["shipping_option_type_id"],
|
||||
"composite": false,
|
||||
"keyName": "shipping_option_shipping_option_type_id_unique",
|
||||
"primary": false,
|
||||
"unique": true
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_shipping_option_service_zone_id",
|
||||
"columnNames": ["service_zone_id"],
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
@@ -928,39 +993,25 @@
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_shipping_option_shipping_profile_id",
|
||||
"columnNames": ["shipping_profile_id"],
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_shipping_option_shipping_profile_id\" ON \"shipping_option\" (shipping_profile_id) WHERE deleted_at IS NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_shipping_option_provider_id",
|
||||
"columnNames": ["provider_id"],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_shipping_option_provider_id\" ON \"shipping_option\" (provider_id) WHERE deleted_at IS NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_shipping_option_shipping_option_type_id",
|
||||
"columnNames": ["shipping_option_type_id"],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_shipping_option_shipping_option_type_id\" ON \"shipping_option\" (shipping_option_type_id) WHERE deleted_at IS NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_shipping_option_deleted_at",
|
||||
"columnNames": ["deleted_at"],
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_shipping_option_deleted_at\" ON \"shipping_option\" (deleted_at) WHERE deleted_at IS NOT NULL"
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_shipping_option_deleted_at\" ON \"shipping_option\" (deleted_at) WHERE deleted_at IS NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "shipping_option_pkey",
|
||||
"columnNames": ["id"],
|
||||
"columnNames": [
|
||||
"id"
|
||||
],
|
||||
"composite": false,
|
||||
"primary": true,
|
||||
"unique": true
|
||||
@@ -970,39 +1021,29 @@
|
||||
"foreignKeys": {
|
||||
"shipping_option_service_zone_id_foreign": {
|
||||
"constraintName": "shipping_option_service_zone_id_foreign",
|
||||
"columnNames": ["service_zone_id"],
|
||||
"columnNames": [
|
||||
"service_zone_id"
|
||||
],
|
||||
"localTableName": "public.shipping_option",
|
||||
"referencedColumnNames": ["id"],
|
||||
"referencedColumnNames": [
|
||||
"id"
|
||||
],
|
||||
"referencedTableName": "public.service_zone",
|
||||
"deleteRule": "cascade",
|
||||
"updateRule": "cascade"
|
||||
},
|
||||
"shipping_option_shipping_profile_id_foreign": {
|
||||
"constraintName": "shipping_option_shipping_profile_id_foreign",
|
||||
"columnNames": ["shipping_profile_id"],
|
||||
"columnNames": [
|
||||
"shipping_profile_id"
|
||||
],
|
||||
"localTableName": "public.shipping_option",
|
||||
"referencedColumnNames": ["id"],
|
||||
"referencedColumnNames": [
|
||||
"id"
|
||||
],
|
||||
"referencedTableName": "public.shipping_profile",
|
||||
"deleteRule": "set null",
|
||||
"updateRule": "cascade"
|
||||
},
|
||||
"shipping_option_provider_id_foreign": {
|
||||
"constraintName": "shipping_option_provider_id_foreign",
|
||||
"columnNames": ["provider_id"],
|
||||
"localTableName": "public.shipping_option",
|
||||
"referencedColumnNames": ["id"],
|
||||
"referencedTableName": "public.fulfillment_provider",
|
||||
"deleteRule": "set null",
|
||||
"updateRule": "cascade"
|
||||
},
|
||||
"shipping_option_shipping_option_type_id_foreign": {
|
||||
"constraintName": "shipping_option_shipping_option_type_id_foreign",
|
||||
"columnNames": ["shipping_option_type_id"],
|
||||
"localTableName": "public.shipping_option",
|
||||
"referencedColumnNames": ["id"],
|
||||
"referencedTableName": "public.shipping_option_type",
|
||||
"deleteRule": "cascade",
|
||||
"updateRule": "cascade"
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -1033,7 +1074,16 @@
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": false,
|
||||
"enumItems": ["in", "eq", "ne", "gt", "gte", "lt", "lte", "nin"],
|
||||
"enumItems": [
|
||||
"in",
|
||||
"eq",
|
||||
"ne",
|
||||
"gt",
|
||||
"gte",
|
||||
"lt",
|
||||
"lte",
|
||||
"nin"
|
||||
],
|
||||
"mappedType": "enum"
|
||||
},
|
||||
"value": {
|
||||
@@ -1092,7 +1142,7 @@
|
||||
"indexes": [
|
||||
{
|
||||
"keyName": "IDX_shipping_option_rule_shipping_option_id",
|
||||
"columnNames": ["shipping_option_id"],
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
@@ -1100,15 +1150,17 @@
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_shipping_option_rule_deleted_at",
|
||||
"columnNames": ["deleted_at"],
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_shipping_option_rule_deleted_at\" ON \"shipping_option_rule\" (deleted_at) WHERE deleted_at IS NOT NULL"
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_shipping_option_rule_deleted_at\" ON \"shipping_option_rule\" (deleted_at) WHERE deleted_at IS NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "shipping_option_rule_pkey",
|
||||
"columnNames": ["id"],
|
||||
"columnNames": [
|
||||
"id"
|
||||
],
|
||||
"composite": false,
|
||||
"primary": true,
|
||||
"unique": true
|
||||
@@ -1118,9 +1170,13 @@
|
||||
"foreignKeys": {
|
||||
"shipping_option_rule_shipping_option_id_foreign": {
|
||||
"constraintName": "shipping_option_rule_shipping_option_id_foreign",
|
||||
"columnNames": ["shipping_option_id"],
|
||||
"columnNames": [
|
||||
"shipping_option_id"
|
||||
],
|
||||
"localTableName": "public.shipping_option_rule",
|
||||
"referencedColumnNames": ["id"],
|
||||
"referencedColumnNames": [
|
||||
"id"
|
||||
],
|
||||
"referencedTableName": "public.shipping_option",
|
||||
"deleteRule": "cascade",
|
||||
"updateRule": "cascade"
|
||||
@@ -1214,6 +1270,16 @@
|
||||
"nullable": true,
|
||||
"mappedType": "json"
|
||||
},
|
||||
"requires_shipping": {
|
||||
"name": "requires_shipping",
|
||||
"type": "boolean",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": false,
|
||||
"default": "true",
|
||||
"mappedType": "boolean"
|
||||
},
|
||||
"provider_id": {
|
||||
"name": "provider_id",
|
||||
"type": "text",
|
||||
@@ -1232,15 +1298,6 @@
|
||||
"nullable": true,
|
||||
"mappedType": "text"
|
||||
},
|
||||
"metadata": {
|
||||
"name": "metadata",
|
||||
"type": "jsonb",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": true,
|
||||
"mappedType": "json"
|
||||
},
|
||||
"delivery_address_id": {
|
||||
"name": "delivery_address_id",
|
||||
"type": "text",
|
||||
@@ -1250,15 +1307,14 @@
|
||||
"nullable": true,
|
||||
"mappedType": "text"
|
||||
},
|
||||
"requires_shipping": {
|
||||
"name": "requires_shipping",
|
||||
"type": "boolean",
|
||||
"metadata": {
|
||||
"name": "metadata",
|
||||
"type": "jsonb",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": false,
|
||||
"default": "true",
|
||||
"mappedType": "boolean"
|
||||
"nullable": true,
|
||||
"mappedType": "json"
|
||||
},
|
||||
"created_at": {
|
||||
"name": "created_at",
|
||||
@@ -1296,32 +1352,9 @@
|
||||
"name": "fulfillment",
|
||||
"schema": "public",
|
||||
"indexes": [
|
||||
{
|
||||
"columnNames": ["delivery_address_id"],
|
||||
"composite": false,
|
||||
"keyName": "fulfillment_delivery_address_id_unique",
|
||||
"primary": false,
|
||||
"unique": true
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_fulfillment_location_id",
|
||||
"columnNames": ["location_id"],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_fulfillment_location_id\" ON \"fulfillment\" (location_id) WHERE deleted_at IS NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_fulfillment_provider_id",
|
||||
"columnNames": ["provider_id"],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_fulfillment_provider_id\" ON \"fulfillment\" (provider_id) WHERE deleted_at IS NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_fulfillment_shipping_option_id",
|
||||
"columnNames": ["shipping_option_id"],
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
@@ -1329,15 +1362,25 @@
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_fulfillment_deleted_at",
|
||||
"columnNames": ["deleted_at"],
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_fulfillment_deleted_at\" ON \"fulfillment\" (deleted_at) WHERE deleted_at IS NOT NULL"
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_fulfillment_deleted_at\" ON \"fulfillment\" (deleted_at) WHERE deleted_at IS NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_fulfillment_location_id",
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_fulfillment_location_id\" ON \"fulfillment\" (location_id) WHERE deleted_at IS NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "fulfillment_pkey",
|
||||
"columnNames": ["id"],
|
||||
"columnNames": [
|
||||
"id"
|
||||
],
|
||||
"composite": false,
|
||||
"primary": true,
|
||||
"unique": true
|
||||
@@ -1345,32 +1388,18 @@
|
||||
],
|
||||
"checks": [],
|
||||
"foreignKeys": {
|
||||
"fulfillment_provider_id_foreign": {
|
||||
"constraintName": "fulfillment_provider_id_foreign",
|
||||
"columnNames": ["provider_id"],
|
||||
"localTableName": "public.fulfillment",
|
||||
"referencedColumnNames": ["id"],
|
||||
"referencedTableName": "public.fulfillment_provider",
|
||||
"deleteRule": "set null",
|
||||
"updateRule": "cascade"
|
||||
},
|
||||
"fulfillment_shipping_option_id_foreign": {
|
||||
"constraintName": "fulfillment_shipping_option_id_foreign",
|
||||
"columnNames": ["shipping_option_id"],
|
||||
"columnNames": [
|
||||
"shipping_option_id"
|
||||
],
|
||||
"localTableName": "public.fulfillment",
|
||||
"referencedColumnNames": ["id"],
|
||||
"referencedColumnNames": [
|
||||
"id"
|
||||
],
|
||||
"referencedTableName": "public.shipping_option",
|
||||
"deleteRule": "set null",
|
||||
"updateRule": "cascade"
|
||||
},
|
||||
"fulfillment_delivery_address_id_foreign": {
|
||||
"constraintName": "fulfillment_delivery_address_id_foreign",
|
||||
"columnNames": ["delivery_address_id"],
|
||||
"localTableName": "public.fulfillment",
|
||||
"referencedColumnNames": ["id"],
|
||||
"referencedTableName": "public.fulfillment_address",
|
||||
"deleteRule": "cascade",
|
||||
"updateRule": "cascade"
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -1459,7 +1488,7 @@
|
||||
"indexes": [
|
||||
{
|
||||
"keyName": "IDX_fulfillment_label_fulfillment_id",
|
||||
"columnNames": ["fulfillment_id"],
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
@@ -1467,15 +1496,17 @@
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_fulfillment_label_deleted_at",
|
||||
"columnNames": ["deleted_at"],
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_fulfillment_label_deleted_at\" ON \"fulfillment_label\" (deleted_at) WHERE deleted_at IS NOT NULL"
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_fulfillment_label_deleted_at\" ON \"fulfillment_label\" (deleted_at) WHERE deleted_at IS NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "fulfillment_label_pkey",
|
||||
"columnNames": ["id"],
|
||||
"columnNames": [
|
||||
"id"
|
||||
],
|
||||
"composite": false,
|
||||
"primary": true,
|
||||
"unique": true
|
||||
@@ -1485,9 +1516,13 @@
|
||||
"foreignKeys": {
|
||||
"fulfillment_label_fulfillment_id_foreign": {
|
||||
"constraintName": "fulfillment_label_fulfillment_id_foreign",
|
||||
"columnNames": ["fulfillment_id"],
|
||||
"columnNames": [
|
||||
"fulfillment_id"
|
||||
],
|
||||
"localTableName": "public.fulfillment_label",
|
||||
"referencedColumnNames": ["id"],
|
||||
"referencedColumnNames": [
|
||||
"id"
|
||||
],
|
||||
"referencedTableName": "public.fulfillment",
|
||||
"deleteRule": "cascade",
|
||||
"updateRule": "cascade"
|
||||
@@ -1541,15 +1576,6 @@
|
||||
"nullable": false,
|
||||
"mappedType": "decimal"
|
||||
},
|
||||
"raw_quantity": {
|
||||
"name": "raw_quantity",
|
||||
"type": "jsonb",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": false,
|
||||
"mappedType": "json"
|
||||
},
|
||||
"line_item_id": {
|
||||
"name": "line_item_id",
|
||||
"type": "text",
|
||||
@@ -1577,6 +1603,15 @@
|
||||
"nullable": false,
|
||||
"mappedType": "text"
|
||||
},
|
||||
"raw_quantity": {
|
||||
"name": "raw_quantity",
|
||||
"type": "jsonb",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": false,
|
||||
"mappedType": "json"
|
||||
},
|
||||
"created_at": {
|
||||
"name": "created_at",
|
||||
"type": "timestamptz",
|
||||
@@ -1613,25 +1648,9 @@
|
||||
"name": "fulfillment_item",
|
||||
"schema": "public",
|
||||
"indexes": [
|
||||
{
|
||||
"keyName": "IDX_fulfillment_item_line_item_id",
|
||||
"columnNames": ["line_item_id"],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_fulfillment_item_line_item_id\" ON \"fulfillment_item\" (line_item_id) WHERE deleted_at IS NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_fulfillment_item_inventory_item_id",
|
||||
"columnNames": ["inventory_item_id"],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_fulfillment_item_inventory_item_id\" ON \"fulfillment_item\" (inventory_item_id) WHERE deleted_at IS NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_fulfillment_item_fulfillment_id",
|
||||
"columnNames": ["fulfillment_id"],
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
@@ -1639,15 +1658,33 @@
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_fulfillment_item_deleted_at",
|
||||
"columnNames": ["deleted_at"],
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_fulfillment_item_deleted_at\" ON \"fulfillment_item\" (deleted_at) WHERE deleted_at IS NOT NULL"
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_fulfillment_item_deleted_at\" ON \"fulfillment_item\" (deleted_at) WHERE deleted_at IS NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_fulfillment_item_inventory_item_id",
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_fulfillment_item_inventory_item_id\" ON \"fulfillment_item\" (inventory_item_id) WHERE deleted_at IS NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_fulfillment_item_line_item_id",
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_fulfillment_item_line_item_id\" ON \"fulfillment_item\" (line_item_id) WHERE deleted_at IS NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "fulfillment_item_pkey",
|
||||
"columnNames": ["id"],
|
||||
"columnNames": [
|
||||
"id"
|
||||
],
|
||||
"composite": false,
|
||||
"primary": true,
|
||||
"unique": true
|
||||
@@ -1657,9 +1694,13 @@
|
||||
"foreignKeys": {
|
||||
"fulfillment_item_fulfillment_id_foreign": {
|
||||
"constraintName": "fulfillment_item_fulfillment_id_foreign",
|
||||
"columnNames": ["fulfillment_id"],
|
||||
"columnNames": [
|
||||
"fulfillment_id"
|
||||
],
|
||||
"localTableName": "public.fulfillment_item",
|
||||
"referencedColumnNames": ["id"],
|
||||
"referencedColumnNames": [
|
||||
"id"
|
||||
],
|
||||
"referencedTableName": "public.fulfillment",
|
||||
"deleteRule": "cascade",
|
||||
"updateRule": "cascade"
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
import { Migration } from "@mikro-orm/migrations"
|
||||
|
||||
export class Migration20241217110416 extends Migration {
|
||||
async up(): Promise<void> {
|
||||
this.addSql(
|
||||
'alter table if exists "shipping_option" drop constraint if exists "shipping_option_provider_id_foreign";'
|
||||
)
|
||||
this.addSql(
|
||||
'alter table if exists "shipping_option" drop constraint if exists "shipping_option_shipping_option_type_id_foreign";'
|
||||
)
|
||||
|
||||
this.addSql(
|
||||
'alter table if exists "fulfillment" drop constraint if exists "fulfillment_provider_id_foreign";'
|
||||
)
|
||||
this.addSql(
|
||||
'alter table if exists "fulfillment" drop constraint if exists "fulfillment_delivery_address_id_foreign";'
|
||||
)
|
||||
|
||||
this.addSql(
|
||||
'alter table if exists "fulfillment_provider" add column if not exists "created_at" timestamptz not null default now(), add column if not exists "updated_at" timestamptz not null default now(), add column if not exists "deleted_at" timestamptz null;'
|
||||
)
|
||||
this.addSql(
|
||||
'CREATE INDEX IF NOT EXISTS "IDX_fulfillment_provider_deleted_at" ON "fulfillment_provider" (deleted_at) WHERE deleted_at IS NULL;'
|
||||
)
|
||||
|
||||
this.addSql(
|
||||
'alter table if exists "shipping_option" drop constraint if exists "shipping_option_shipping_option_type_id_unique";'
|
||||
)
|
||||
this.addSql('drop index if exists "IDX_shipping_option_provider_id";')
|
||||
this.addSql(
|
||||
'drop index if exists "IDX_shipping_option_shipping_option_type_id";'
|
||||
)
|
||||
|
||||
this.addSql(
|
||||
'alter table if exists "fulfillment" drop constraint if exists "fulfillment_delivery_address_id_unique";'
|
||||
)
|
||||
this.addSql('drop index if exists "IDX_fulfillment_provider_id";')
|
||||
}
|
||||
|
||||
async down(): Promise<void> {
|
||||
this.addSql('drop index if exists "IDX_fulfillment_provider_deleted_at";')
|
||||
this.addSql(
|
||||
'alter table if exists "fulfillment_provider" drop column if exists "created_at";'
|
||||
)
|
||||
this.addSql(
|
||||
'alter table if exists "fulfillment_provider" drop column if exists "updated_at";'
|
||||
)
|
||||
this.addSql(
|
||||
'alter table if exists "fulfillment_provider" drop column if exists "deleted_at";'
|
||||
)
|
||||
|
||||
this.addSql(
|
||||
'alter table if exists "shipping_option" add constraint "shipping_option_provider_id_foreign" foreign key ("provider_id") references "fulfillment_provider" ("id") on update cascade on delete set null;'
|
||||
)
|
||||
this.addSql(
|
||||
'alter table if exists "shipping_option" add constraint "shipping_option_shipping_option_type_id_foreign" foreign key ("shipping_option_type_id") references "shipping_option_type" ("id") on update cascade on delete cascade;'
|
||||
)
|
||||
this.addSql(
|
||||
'alter table if exists "shipping_option" add constraint "shipping_option_shipping_option_type_id_unique" unique ("shipping_option_type_id");'
|
||||
)
|
||||
this.addSql(
|
||||
'CREATE INDEX IF NOT EXISTS "IDX_shipping_option_provider_id" ON "shipping_option" (provider_id) WHERE deleted_at IS NULL;'
|
||||
)
|
||||
this.addSql(
|
||||
'CREATE INDEX IF NOT EXISTS "IDX_shipping_option_shipping_option_type_id" ON "shipping_option" (shipping_option_type_id) WHERE deleted_at IS NULL;'
|
||||
)
|
||||
|
||||
this.addSql(
|
||||
'alter table if exists "fulfillment" add constraint "fulfillment_provider_id_foreign" foreign key ("provider_id") references "fulfillment_provider" ("id") on update cascade on delete set null;'
|
||||
)
|
||||
this.addSql(
|
||||
'alter table if exists "fulfillment" add constraint "fulfillment_delivery_address_id_foreign" foreign key ("delivery_address_id") references "fulfillment_address" ("id") on update cascade on delete cascade;'
|
||||
)
|
||||
this.addSql(
|
||||
'alter table if exists "fulfillment" add constraint "fulfillment_delivery_address_id_unique" unique ("delivery_address_id");'
|
||||
)
|
||||
this.addSql(
|
||||
'CREATE INDEX IF NOT EXISTS "IDX_fulfillment_provider_id" ON "fulfillment" (provider_id) WHERE deleted_at IS NULL;'
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,91 +1,16 @@
|
||||
import { DAL } from "@medusajs/framework/types"
|
||||
import {
|
||||
createPsqlIndexStatementHelper,
|
||||
generateEntityId,
|
||||
} from "@medusajs/framework/utils"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Entity,
|
||||
OnInit,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import { model } from "@medusajs/framework/utils"
|
||||
|
||||
type OptionalAddressProps = DAL.SoftDeletableModelDateColumns
|
||||
|
||||
const FulfillmentDeletedAtIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "fulfillment_address",
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
export const FulfillmentAddress = model.define("fulfillment_address", {
|
||||
id: model.id({ prefix: "fuladdr" }).primaryKey(),
|
||||
company: model.text().nullable(),
|
||||
first_name: model.text().nullable(),
|
||||
last_name: model.text().nullable(),
|
||||
address_1: model.text().nullable(),
|
||||
address_2: model.text().nullable(),
|
||||
city: model.text().nullable(),
|
||||
country_code: model.text().nullable(),
|
||||
province: model.text().nullable(),
|
||||
postal_code: model.text().nullable(),
|
||||
phone: model.text().nullable(),
|
||||
metadata: model.json().nullable(),
|
||||
})
|
||||
|
||||
@Entity({ tableName: "fulfillment_address" })
|
||||
export default class FulfillmentAddress {
|
||||
[OptionalProps]: OptionalAddressProps
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id!: string
|
||||
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
company: string | null = null
|
||||
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
first_name: string | null = null
|
||||
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
last_name: string | null = null
|
||||
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
address_1: string | null = null
|
||||
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
address_2: string | null = null
|
||||
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
city: string | null = null
|
||||
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
country_code: string | null = null
|
||||
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
province: string | null = null
|
||||
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
postal_code: string | null = null
|
||||
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
phone: string | null = null
|
||||
|
||||
@Property({ columnType: "jsonb", nullable: true })
|
||||
metadata: Record<string, unknown> | null = null
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
created_at: Date
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
onUpdate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
updated_at: Date
|
||||
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
@FulfillmentDeletedAtIndex.MikroORMIndex()
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "fuladdr")
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "fuladdr")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,122 +1,27 @@
|
||||
import {
|
||||
BigNumber,
|
||||
createPsqlIndexStatementHelper,
|
||||
DALUtils,
|
||||
generateEntityId,
|
||||
MikroOrmBigNumberProperty,
|
||||
} from "@medusajs/framework/utils"
|
||||
import { model } from "@medusajs/framework/utils"
|
||||
|
||||
import { BigNumberRawValue, DAL } from "@medusajs/framework/types"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Entity,
|
||||
Filter,
|
||||
ManyToOne,
|
||||
OnInit,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
Rel,
|
||||
} from "@mikro-orm/core"
|
||||
import Fulfillment from "./fulfillment"
|
||||
import { Fulfillment } from "./fulfillment"
|
||||
|
||||
type FulfillmentItemOptionalProps = DAL.SoftDeletableModelDateColumns
|
||||
|
||||
const FulfillmentIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "fulfillment_item",
|
||||
columns: "fulfillment_id",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
const LineItemIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "fulfillment_item",
|
||||
columns: "line_item_id",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
const InventoryItemIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "fulfillment_item",
|
||||
columns: "inventory_item_id",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
const FulfillmentItemDeletedAtIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "fulfillment_item",
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
@Entity()
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
export default class FulfillmentItem {
|
||||
[OptionalProps]?: FulfillmentItemOptionalProps
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id: string
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
title: string
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
sku: string
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
barcode: string
|
||||
|
||||
@MikroOrmBigNumberProperty()
|
||||
quantity: BigNumber | number
|
||||
|
||||
@Property({ columnType: "jsonb" })
|
||||
raw_quantity: BigNumberRawValue
|
||||
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
@LineItemIdIndex.MikroORMIndex()
|
||||
line_item_id: string | null = null
|
||||
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
@InventoryItemIdIndex.MikroORMIndex()
|
||||
inventory_item_id: string | null = null
|
||||
|
||||
@ManyToOne(() => Fulfillment, {
|
||||
columnType: "text",
|
||||
mapToPk: true,
|
||||
fieldName: "fulfillment_id",
|
||||
onDelete: "cascade",
|
||||
export const FulfillmentItem = model
|
||||
.define("fulfillment_item", {
|
||||
id: model.id({ prefix: "fulit" }).primaryKey(),
|
||||
title: model.text(),
|
||||
sku: model.text(),
|
||||
barcode: model.text(),
|
||||
quantity: model.bigNumber(),
|
||||
line_item_id: model.text().nullable(),
|
||||
inventory_item_id: model.text().nullable(),
|
||||
fulfillment: model.belongsTo(() => Fulfillment, {
|
||||
mappedBy: "items",
|
||||
}),
|
||||
})
|
||||
@FulfillmentIdIndex.MikroORMIndex()
|
||||
fulfillment_id: string
|
||||
|
||||
@ManyToOne(() => Fulfillment, { persist: false })
|
||||
fulfillment: Rel<Fulfillment>
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
created_at: Date
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
onUpdate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
updated_at: Date
|
||||
|
||||
@FulfillmentItemDeletedAtIndex.MikroORMIndex()
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "fulit")
|
||||
this.fulfillment_id ??= this.fulfillment.id
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "fulit")
|
||||
this.fulfillment_id ??= this.fulfillment.id
|
||||
}
|
||||
}
|
||||
.indexes([
|
||||
{
|
||||
on: ["inventory_item_id"],
|
||||
where: "deleted_at IS NULL",
|
||||
},
|
||||
{
|
||||
on: ["line_item_id"],
|
||||
where: "deleted_at IS NULL",
|
||||
},
|
||||
])
|
||||
|
||||
@@ -1,94 +1,13 @@
|
||||
import {
|
||||
createPsqlIndexStatementHelper,
|
||||
DALUtils,
|
||||
generateEntityId,
|
||||
} from "@medusajs/framework/utils"
|
||||
import { model } from "@medusajs/framework/utils"
|
||||
|
||||
import { DAL } from "@medusajs/framework/types"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Entity,
|
||||
Filter,
|
||||
ManyToOne,
|
||||
OnInit,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
Rel,
|
||||
} from "@mikro-orm/core"
|
||||
import Fulfillment from "./fulfillment"
|
||||
import { Fulfillment } from "./fulfillment"
|
||||
|
||||
type FulfillmentLabelOptionalProps = DAL.SoftDeletableModelDateColumns
|
||||
|
||||
const FulfillmentIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "fulfillment_label",
|
||||
columns: "fulfillment_id",
|
||||
where: "deleted_at IS NULL",
|
||||
export const FulfillmentLabel = model.define("fulfillment_label", {
|
||||
id: model.id({ prefix: "fulla" }).primaryKey(),
|
||||
tracking_number: model.text(),
|
||||
tracking_url: model.text(),
|
||||
label_url: model.text(),
|
||||
fulfillment: model.belongsTo(() => Fulfillment, {
|
||||
mappedBy: "labels",
|
||||
}),
|
||||
})
|
||||
|
||||
const DeletedAtIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "fulfillment_label",
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
@Entity()
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
export default class FulfillmentLabel {
|
||||
[OptionalProps]?: FulfillmentLabelOptionalProps
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id: string
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
tracking_number: string
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
tracking_url: string
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
label_url: string
|
||||
|
||||
@ManyToOne(() => Fulfillment, {
|
||||
columnType: "text",
|
||||
mapToPk: true,
|
||||
fieldName: "fulfillment_id",
|
||||
onDelete: "cascade",
|
||||
})
|
||||
@FulfillmentIdIndex.MikroORMIndex()
|
||||
fulfillment_id: string
|
||||
|
||||
@ManyToOne(() => Fulfillment, { persist: false })
|
||||
fulfillment: Rel<Fulfillment>
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
created_at: Date
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
onUpdate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
updated_at: Date
|
||||
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
@DeletedAtIndex.MikroORMIndex()
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "fulla")
|
||||
this.fulfillment_id ??= this.fulfillment.id
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "fulla")
|
||||
this.fulfillment_id ??= this.fulfillment.id
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +1,6 @@
|
||||
import { Searchable, generateEntityId } from "@medusajs/framework/utils"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Entity,
|
||||
OnInit,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import { model } from "@medusajs/framework/utils"
|
||||
|
||||
@Entity()
|
||||
export default class FulfillmentProvider {
|
||||
@Searchable()
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id: string
|
||||
|
||||
@Property({ columnType: "boolean", defaultRaw: "true" })
|
||||
is_enabled: boolean = true
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "serpro")
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "serpro")
|
||||
}
|
||||
}
|
||||
export const FulfillmentProvider = model.define("fulfillment_provider", {
|
||||
id: model.id({ prefix: "serpro" }).primaryKey(),
|
||||
is_enabled: model.boolean().default(true),
|
||||
})
|
||||
|
||||
@@ -1,90 +1,24 @@
|
||||
import {
|
||||
createPsqlIndexStatementHelper,
|
||||
DALUtils,
|
||||
generateEntityId,
|
||||
} from "@medusajs/framework/utils"
|
||||
import { model } from "@medusajs/framework/utils"
|
||||
|
||||
import { DAL } from "@medusajs/framework/types"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Cascade,
|
||||
Collection,
|
||||
Entity,
|
||||
Filter,
|
||||
OneToMany,
|
||||
OnInit,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
Rel,
|
||||
} from "@mikro-orm/core"
|
||||
import ServiceZone from "./service-zone"
|
||||
import { ServiceZone } from "./service-zone"
|
||||
|
||||
type FulfillmentSetOptionalProps = DAL.SoftDeletableModelDateColumns
|
||||
|
||||
const DeletedAtIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "fulfillment_set",
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
const NameIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "fulfillment_set",
|
||||
columns: "name",
|
||||
unique: true,
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
@Entity()
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
export default class FulfillmentSet {
|
||||
[OptionalProps]?: FulfillmentSetOptionalProps
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id: string
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
@NameIndex.MikroORMIndex()
|
||||
name: string
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
type: string
|
||||
|
||||
@Property({ columnType: "jsonb", nullable: true })
|
||||
metadata: Record<string, unknown> | null = null
|
||||
|
||||
@OneToMany(() => ServiceZone, "fulfillment_set", {
|
||||
cascade: [Cascade.PERSIST, "soft-remove"] as any,
|
||||
orphanRemoval: true,
|
||||
export const FulfillmentSet = model
|
||||
.define("fulfillment_set", {
|
||||
id: model.id({ prefix: "fuset" }).primaryKey(),
|
||||
name: model.text(),
|
||||
type: model.text(),
|
||||
service_zones: model.hasMany(() => ServiceZone, {
|
||||
mappedBy: "fulfillment_set",
|
||||
}),
|
||||
metadata: model.json().nullable(),
|
||||
})
|
||||
service_zones = new Collection<Rel<ServiceZone>>(this)
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
.indexes([
|
||||
{
|
||||
on: ["name"],
|
||||
where: "deleted_at IS NULL",
|
||||
unique: true,
|
||||
},
|
||||
])
|
||||
.cascades({
|
||||
delete: ["service_zones"],
|
||||
})
|
||||
created_at: Date
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
onUpdate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
updated_at: Date
|
||||
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
@DeletedAtIndex.MikroORMIndex()
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "fuset")
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "fuset")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,183 +1,54 @@
|
||||
import {
|
||||
createPsqlIndexStatementHelper,
|
||||
DALUtils,
|
||||
generateEntityId,
|
||||
} from "@medusajs/framework/utils"
|
||||
import { model } from "@medusajs/framework/utils"
|
||||
|
||||
import { DAL } from "@medusajs/framework/types"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Cascade,
|
||||
Collection,
|
||||
Entity,
|
||||
Filter,
|
||||
ManyToOne,
|
||||
OneToMany,
|
||||
OneToOne,
|
||||
OnInit,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
Rel,
|
||||
} from "@mikro-orm/core"
|
||||
import FulfillmentAddress from "./address"
|
||||
import FulfillmentItem from "./fulfillment-item"
|
||||
import FulfillmentLabel from "./fulfillment-label"
|
||||
import FulfillmentProvider from "./fulfillment-provider"
|
||||
import ShippingOption from "./shipping-option"
|
||||
import { FulfillmentAddress } from "./address"
|
||||
import { FulfillmentItem } from "./fulfillment-item"
|
||||
import { FulfillmentLabel } from "./fulfillment-label"
|
||||
import { FulfillmentProvider } from "./fulfillment-provider"
|
||||
import { ShippingOption } from "./shipping-option"
|
||||
|
||||
type FulfillmentOptionalProps = DAL.SoftDeletableModelDateColumns
|
||||
|
||||
const FulfillmentDeletedAtIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "fulfillment",
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
const FulfillmentProviderIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "fulfillment",
|
||||
columns: "provider_id",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
const FulfillmentLocationIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "fulfillment",
|
||||
columns: "location_id",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
const FulfillmentShippingOptionIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "fulfillment",
|
||||
columns: "shipping_option_id",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
@Entity()
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
export default class Fulfillment {
|
||||
[OptionalProps]?: FulfillmentOptionalProps
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id: string
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
@FulfillmentLocationIdIndex.MikroORMIndex()
|
||||
location_id: string
|
||||
|
||||
@Property({
|
||||
columnType: "timestamptz",
|
||||
nullable: true,
|
||||
export const Fulfillment = model
|
||||
.define("fulfillment", {
|
||||
id: model.id({ prefix: "ful" }).primaryKey(),
|
||||
location_id: model.text(),
|
||||
packed_at: model.dateTime().nullable(),
|
||||
shipped_at: model.dateTime().nullable(),
|
||||
marked_shipped_by: model.text().nullable(),
|
||||
created_by: model.text().nullable(),
|
||||
delivered_at: model.dateTime().nullable(),
|
||||
canceled_at: model.dateTime().nullable(),
|
||||
data: model.json().nullable(),
|
||||
requires_shipping: model.boolean().default(true),
|
||||
items: model.hasMany(() => FulfillmentItem, {
|
||||
mappedBy: "fulfillment",
|
||||
}),
|
||||
labels: model.hasMany(() => FulfillmentLabel, {
|
||||
mappedBy: "fulfillment",
|
||||
}),
|
||||
provider: model
|
||||
.hasOne(() => FulfillmentProvider, {
|
||||
foreignKey: true,
|
||||
mappedBy: undefined,
|
||||
})
|
||||
.nullable(),
|
||||
shipping_option: model
|
||||
.belongsTo(() => ShippingOption, {
|
||||
mappedBy: "fulfillments",
|
||||
})
|
||||
.nullable(),
|
||||
delivery_address: model
|
||||
.hasOne(() => FulfillmentAddress, {
|
||||
foreignKey: true,
|
||||
mappedBy: undefined,
|
||||
})
|
||||
.nullable(),
|
||||
metadata: model.json().nullable(),
|
||||
})
|
||||
packed_at: Date | null = null
|
||||
|
||||
@Property({
|
||||
columnType: "timestamptz",
|
||||
nullable: true,
|
||||
.indexes([
|
||||
{
|
||||
on: ["location_id"],
|
||||
where: "deleted_at IS NULL",
|
||||
},
|
||||
])
|
||||
.cascades({
|
||||
delete: ["delivery_address", "items", "labels"],
|
||||
})
|
||||
shipped_at: Date | null = null
|
||||
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
marked_shipped_by: string | null = null
|
||||
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
created_by: string | null = null
|
||||
|
||||
@Property({
|
||||
columnType: "timestamptz",
|
||||
nullable: true,
|
||||
})
|
||||
delivered_at: Date | null = null
|
||||
|
||||
@Property({
|
||||
columnType: "timestamptz",
|
||||
nullable: true,
|
||||
})
|
||||
canceled_at: Date | null = null
|
||||
|
||||
@Property({ columnType: "jsonb", nullable: true })
|
||||
data: Record<string, unknown> | null = null
|
||||
|
||||
@ManyToOne(() => FulfillmentProvider, {
|
||||
columnType: "text",
|
||||
fieldName: "provider_id",
|
||||
mapToPk: true,
|
||||
nullable: true,
|
||||
onDelete: "set null",
|
||||
})
|
||||
@FulfillmentProviderIdIndex.MikroORMIndex()
|
||||
provider_id: string
|
||||
|
||||
@ManyToOne(() => ShippingOption, {
|
||||
columnType: "text",
|
||||
fieldName: "shipping_option_id",
|
||||
nullable: true,
|
||||
mapToPk: true,
|
||||
onDelete: "set null",
|
||||
})
|
||||
@FulfillmentShippingOptionIdIndex.MikroORMIndex()
|
||||
shipping_option_id: string | null = null
|
||||
|
||||
@Property({ columnType: "jsonb", nullable: true })
|
||||
metadata: Record<string, unknown> | null = null
|
||||
|
||||
@ManyToOne(() => ShippingOption, { persist: false })
|
||||
shipping_option: ShippingOption | null
|
||||
|
||||
@ManyToOne(() => FulfillmentProvider, { persist: false })
|
||||
provider: Rel<FulfillmentProvider>
|
||||
|
||||
@OneToOne({
|
||||
entity: () => FulfillmentAddress,
|
||||
owner: true,
|
||||
cascade: [Cascade.PERSIST, "soft-remove"] as any,
|
||||
nullable: true,
|
||||
onDelete: "cascade",
|
||||
})
|
||||
delivery_address!: Rel<FulfillmentAddress>
|
||||
|
||||
@Property({ columnType: "boolean", default: true })
|
||||
requires_shipping: boolean = true
|
||||
|
||||
@OneToMany(() => FulfillmentItem, (item) => item.fulfillment, {
|
||||
cascade: [Cascade.PERSIST, "soft-remove"] as any,
|
||||
orphanRemoval: true,
|
||||
})
|
||||
items = new Collection<Rel<FulfillmentItem>>(this)
|
||||
|
||||
@OneToMany(() => FulfillmentLabel, (label) => label.fulfillment, {
|
||||
cascade: [Cascade.PERSIST, "soft-remove"] as any,
|
||||
orphanRemoval: true,
|
||||
})
|
||||
labels = new Collection<Rel<FulfillmentLabel>>(this)
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
created_at: Date
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
onUpdate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
updated_at: Date
|
||||
|
||||
@FulfillmentDeletedAtIndex.MikroORMIndex()
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "ful")
|
||||
this.provider_id ??= this.provider_id ?? this.provider?.id
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "ful")
|
||||
this.provider_id ??= this.provider_id ?? this.provider?.id
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,128 +1,53 @@
|
||||
import {
|
||||
createPsqlIndexStatementHelper,
|
||||
DALUtils,
|
||||
generateEntityId,
|
||||
BelongsTo,
|
||||
DmlEntity,
|
||||
DMLEntitySchemaBuilder,
|
||||
GeoZoneType,
|
||||
IdProperty,
|
||||
JSONProperty,
|
||||
model,
|
||||
NullableModifier,
|
||||
PrimaryKeyModifier,
|
||||
TextProperty,
|
||||
} from "@medusajs/framework/utils"
|
||||
|
||||
import { DAL } from "@medusajs/framework/types"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Entity,
|
||||
Enum,
|
||||
Filter,
|
||||
ManyToOne,
|
||||
OnInit,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
Rel,
|
||||
} from "@mikro-orm/core"
|
||||
import ServiceZone from "./service-zone"
|
||||
import { ServiceZone } from "./service-zone"
|
||||
|
||||
type GeoZoneOptionalProps = DAL.SoftDeletableModelDateColumns
|
||||
|
||||
const DeletedAtIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "geo_zone",
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
const CountryCodeIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "geo_zone",
|
||||
columns: "country_code",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
const ProvinceCodeIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "geo_zone",
|
||||
columns: "province_code",
|
||||
where: "deleted_at IS NULL AND province_code IS NOT NULL",
|
||||
})
|
||||
|
||||
const CityIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "geo_zone",
|
||||
columns: "city",
|
||||
where: "deleted_at IS NULL AND city IS NOT NULL",
|
||||
})
|
||||
|
||||
const ServiceZoneIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "geo_zone",
|
||||
columns: "service_zone_id",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
@Entity()
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
export default class GeoZone {
|
||||
[OptionalProps]?: GeoZoneOptionalProps
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id: string
|
||||
|
||||
@Enum({ items: () => GeoZoneType, default: GeoZoneType.COUNTRY })
|
||||
type: GeoZoneType
|
||||
|
||||
@CountryCodeIndex.MikroORMIndex()
|
||||
@Property({ columnType: "text" })
|
||||
country_code: string
|
||||
|
||||
@ProvinceCodeIndex.MikroORMIndex()
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
province_code: string | null = null
|
||||
|
||||
@CityIndex.MikroORMIndex()
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
city: string | null = null
|
||||
|
||||
@ManyToOne(() => ServiceZone, {
|
||||
type: "text",
|
||||
mapToPk: true,
|
||||
fieldName: "service_zone_id",
|
||||
onDelete: "cascade",
|
||||
})
|
||||
@ServiceZoneIdIndex.MikroORMIndex()
|
||||
service_zone_id: string
|
||||
|
||||
@Property({ columnType: "jsonb", nullable: true })
|
||||
postal_expression: Record<string, unknown> | null = null
|
||||
|
||||
@Property({ columnType: "jsonb", nullable: true })
|
||||
metadata: Record<string, unknown> | null = null
|
||||
|
||||
@ManyToOne(() => ServiceZone, {
|
||||
persist: false,
|
||||
})
|
||||
service_zone: Rel<ServiceZone>
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
created_at: Date
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
onUpdate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
updated_at: Date
|
||||
|
||||
@DeletedAtIndex.MikroORMIndex()
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "fgz")
|
||||
this.service_zone_id ??= this.service_zone?.id
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "fgz")
|
||||
this.service_zone_id ??= this.service_zone?.id
|
||||
}
|
||||
export type GeoZoneSchema = {
|
||||
id: PrimaryKeyModifier<string, IdProperty>
|
||||
type: TextProperty
|
||||
country_code: TextProperty
|
||||
province_code?: NullableModifier<string, TextProperty>
|
||||
city?: NullableModifier<string, TextProperty>
|
||||
postal_expression?: NullableModifier<Record<string, unknown>, JSONProperty>
|
||||
service_zone: BelongsTo<() => typeof ServiceZone>
|
||||
metadata?: NullableModifier<Record<string, unknown>, JSONProperty>
|
||||
}
|
||||
|
||||
export const GeoZone = model
|
||||
.define("geo_zone", {
|
||||
id: model.id({ prefix: "fgz" }).primaryKey(),
|
||||
type: model.enum(GeoZoneType).default(GeoZoneType.COUNTRY),
|
||||
country_code: model.text(),
|
||||
province_code: model.text().nullable(),
|
||||
city: model.text().nullable(),
|
||||
postal_expression: model.json().nullable(),
|
||||
service_zone: model.belongsTo<() => typeof ServiceZone>(() => ServiceZone, {
|
||||
mappedBy: "geo_zones",
|
||||
}),
|
||||
metadata: model.json().nullable(),
|
||||
})
|
||||
.indexes([
|
||||
{
|
||||
on: ["country_code"],
|
||||
where: "deleted_at IS NULL",
|
||||
},
|
||||
{
|
||||
on: ["province_code"],
|
||||
where: "deleted_at IS NULL",
|
||||
},
|
||||
{
|
||||
on: ["city"],
|
||||
where: "deleted_at IS NULL",
|
||||
},
|
||||
]) as unknown as DmlEntity<DMLEntitySchemaBuilder<GeoZoneSchema>, "GeoZone">
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
export { default as FulfillmentAddress } from "./address"
|
||||
export { default as Fulfillment } from "./fulfillment"
|
||||
export { default as FulfillmentItem } from "./fulfillment-item"
|
||||
export { default as FulfillmentLabel } from "./fulfillment-label"
|
||||
export { default as FulfillmentProvider } from "./fulfillment-provider"
|
||||
export { default as FulfillmentSet } from "./fulfillment-set"
|
||||
export { default as GeoZone } from "./geo-zone"
|
||||
export { default as ServiceZone } from "./service-zone"
|
||||
export { default as ShippingOption } from "./shipping-option"
|
||||
export { default as ShippingOptionRule } from "./shipping-option-rule"
|
||||
export { default as ShippingOptionType } from "./shipping-option-type"
|
||||
export { default as ShippingProfile } from "./shipping-profile"
|
||||
export { FulfillmentAddress } from "./address"
|
||||
export { Fulfillment } from "./fulfillment"
|
||||
export { FulfillmentItem } from "./fulfillment-item"
|
||||
export { FulfillmentLabel } from "./fulfillment-label"
|
||||
export { FulfillmentProvider } from "./fulfillment-provider"
|
||||
export { FulfillmentSet } from "./fulfillment-set"
|
||||
export { GeoZone } from "./geo-zone"
|
||||
export { ServiceZone } from "./service-zone"
|
||||
export { ShippingOption } from "./shipping-option"
|
||||
export { ShippingOptionRule } from "./shipping-option-rule"
|
||||
export { ShippingOptionType } from "./shipping-option-type"
|
||||
export { ShippingProfile } from "./shipping-profile"
|
||||
|
||||
@@ -1,126 +1,60 @@
|
||||
import {
|
||||
createPsqlIndexStatementHelper,
|
||||
DALUtils,
|
||||
generateEntityId,
|
||||
BelongsTo,
|
||||
DmlEntity,
|
||||
DMLEntitySchemaBuilder,
|
||||
HasMany,
|
||||
IdProperty,
|
||||
JSONProperty,
|
||||
model,
|
||||
NullableModifier,
|
||||
PrimaryKeyModifier,
|
||||
TextProperty,
|
||||
} from "@medusajs/framework/utils"
|
||||
|
||||
import { DAL } from "@medusajs/framework/types"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Cascade,
|
||||
Collection,
|
||||
Entity,
|
||||
Filter,
|
||||
Index,
|
||||
ManyToOne,
|
||||
OneToMany,
|
||||
OnInit,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
Rel,
|
||||
} from "@mikro-orm/core"
|
||||
import FulfillmentSet from "./fulfillment-set"
|
||||
import GeoZone from "./geo-zone"
|
||||
import ShippingOption from "./shipping-option"
|
||||
import { FulfillmentSet } from "./fulfillment-set"
|
||||
import { GeoZone } from "./geo-zone"
|
||||
import { ShippingOption } from "./shipping-option"
|
||||
|
||||
type ServiceZoneOptionalProps = DAL.SoftDeletableModelDateColumns
|
||||
|
||||
const deletedAtIndexName = "IDX_service_zone_deleted_at"
|
||||
const deletedAtIndexStatement = createPsqlIndexStatementHelper({
|
||||
name: deletedAtIndexName,
|
||||
tableName: "service_zone",
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
}).expression
|
||||
|
||||
const NameIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "service_zone",
|
||||
columns: "name",
|
||||
unique: true,
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
const FulfillmentSetIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "service_zone",
|
||||
columns: "fulfillment_set_id",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
@Entity()
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
export default class ServiceZone {
|
||||
[OptionalProps]?: ServiceZoneOptionalProps
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id: string
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
@NameIndex.MikroORMIndex()
|
||||
name: string
|
||||
|
||||
@Property({ columnType: "jsonb", nullable: true })
|
||||
metadata: Record<string, unknown> | null = null
|
||||
|
||||
@ManyToOne(() => FulfillmentSet, {
|
||||
type: "text",
|
||||
mapToPk: true,
|
||||
fieldName: "fulfillment_set_id",
|
||||
onDelete: "cascade",
|
||||
})
|
||||
@FulfillmentSetIdIndex.MikroORMIndex()
|
||||
fulfillment_set_id: string
|
||||
|
||||
@ManyToOne(() => FulfillmentSet, { persist: false })
|
||||
fulfillment_set: Rel<FulfillmentSet>
|
||||
|
||||
@OneToMany(() => GeoZone, "service_zone", {
|
||||
cascade: [Cascade.PERSIST, "soft-remove"] as any,
|
||||
orphanRemoval: true,
|
||||
})
|
||||
geo_zones = new Collection<Rel<GeoZone>>(this)
|
||||
|
||||
@OneToMany(
|
||||
() => ShippingOption,
|
||||
(shippingOption) => shippingOption.service_zone,
|
||||
{
|
||||
cascade: [Cascade.PERSIST, "soft-remove"] as any,
|
||||
orphanRemoval: true,
|
||||
}
|
||||
)
|
||||
shipping_options = new Collection<Rel<ShippingOption>>(this)
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
created_at: Date
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
onUpdate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
updated_at: Date
|
||||
|
||||
@Index({
|
||||
name: deletedAtIndexName,
|
||||
expression: deletedAtIndexStatement,
|
||||
})
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "serzo")
|
||||
this.fulfillment_set_id ??= this.fulfillment_set?.id
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "serzo")
|
||||
this.fulfillment_set_id ??= this.fulfillment_set?.id
|
||||
}
|
||||
export type ServiceZoneSchema = {
|
||||
id: PrimaryKeyModifier<string, IdProperty>
|
||||
name: TextProperty
|
||||
fulfillment_set: BelongsTo<() => typeof FulfillmentSet>
|
||||
geo_zones: HasMany<() => typeof GeoZone>
|
||||
shipping_options: HasMany<() => typeof ShippingOption>
|
||||
metadata: NullableModifier<Record<string, unknown>, JSONProperty>
|
||||
}
|
||||
|
||||
export const ServiceZone = model
|
||||
.define("service_zone", {
|
||||
id: model.id({ prefix: "serzo" }).primaryKey(),
|
||||
name: model.text(),
|
||||
fulfillment_set: model.belongsTo<() => typeof FulfillmentSet>(
|
||||
() => FulfillmentSet,
|
||||
{
|
||||
mappedBy: "service_zones",
|
||||
}
|
||||
),
|
||||
geo_zones: model.hasMany<() => typeof GeoZone>(() => GeoZone, {
|
||||
mappedBy: "service_zone",
|
||||
}),
|
||||
shipping_options: model.hasMany<() => typeof ShippingOption>(
|
||||
() => ShippingOption,
|
||||
{
|
||||
mappedBy: "service_zone",
|
||||
}
|
||||
),
|
||||
metadata: model.json().nullable(),
|
||||
})
|
||||
.indexes([
|
||||
{
|
||||
on: ["name"],
|
||||
unique: true,
|
||||
where: "deleted_at IS NULL",
|
||||
},
|
||||
])
|
||||
.cascades({
|
||||
delete: ["geo_zones", "shipping_options"],
|
||||
}) as unknown as DmlEntity<
|
||||
DMLEntitySchemaBuilder<ServiceZoneSchema>,
|
||||
"ServiceZone"
|
||||
>
|
||||
|
||||
@@ -1,100 +1,12 @@
|
||||
import { DAL } from "@medusajs/framework/types"
|
||||
import {
|
||||
createPsqlIndexStatementHelper,
|
||||
DALUtils,
|
||||
generateEntityId,
|
||||
RuleOperator,
|
||||
} from "@medusajs/framework/utils"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Entity,
|
||||
Enum,
|
||||
Filter,
|
||||
ManyToOne,
|
||||
OnInit,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
Rel,
|
||||
} from "@mikro-orm/core"
|
||||
import ShippingOption from "./shipping-option"
|
||||
import { model, RuleOperator } from "@medusajs/framework/utils"
|
||||
import { ShippingOption } from "./shipping-option"
|
||||
|
||||
type ShippingOptionRuleOptionalProps = DAL.SoftDeletableModelDateColumns
|
||||
|
||||
const DeletedAtIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "shipping_option_rule",
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
export const ShippingOptionRule = model.define("shipping_option_rule", {
|
||||
id: model.id({ prefix: "sorul" }).primaryKey(),
|
||||
attribute: model.text(),
|
||||
operator: model.enum(RuleOperator),
|
||||
value: model.json().nullable(),
|
||||
shipping_option: model.belongsTo(() => ShippingOption, {
|
||||
mappedBy: "rules",
|
||||
}),
|
||||
})
|
||||
|
||||
const ShippingOptionIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "shipping_option_rule",
|
||||
columns: "shipping_option_id",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
@Entity()
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
export default class ShippingOptionRule {
|
||||
[OptionalProps]?: ShippingOptionRuleOptionalProps
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id: string
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
attribute: string
|
||||
|
||||
@Enum({
|
||||
items: () => Object.values(RuleOperator),
|
||||
columnType: "text",
|
||||
})
|
||||
operator: Lowercase<keyof typeof RuleOperator>
|
||||
|
||||
@Property({ columnType: "jsonb", nullable: true })
|
||||
value: string | string[] | null = null
|
||||
|
||||
@ManyToOne(() => ShippingOption, {
|
||||
type: "text",
|
||||
mapToPk: true,
|
||||
fieldName: "shipping_option_id",
|
||||
onDelete: "cascade",
|
||||
})
|
||||
@ShippingOptionIdIndex.MikroORMIndex()
|
||||
shipping_option_id: string
|
||||
|
||||
@ManyToOne(() => ShippingOption, {
|
||||
persist: false,
|
||||
})
|
||||
shipping_option: Rel<ShippingOption>
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
created_at: Date
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
onUpdate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
updated_at: Date
|
||||
|
||||
@DeletedAtIndex.MikroORMIndex()
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "sorul")
|
||||
this.shipping_option_id ??= this.shipping_option?.id
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "sorul")
|
||||
this.shipping_option_id ??= this.shipping_option?.id
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,80 +1,13 @@
|
||||
import {
|
||||
createPsqlIndexStatementHelper,
|
||||
DALUtils,
|
||||
generateEntityId,
|
||||
} from "@medusajs/framework/utils"
|
||||
import { model } from "@medusajs/framework/utils"
|
||||
|
||||
import { DAL } from "@medusajs/framework/types"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Entity,
|
||||
Filter,
|
||||
OneToOne,
|
||||
OnInit,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
Rel,
|
||||
} from "@mikro-orm/core"
|
||||
import ShippingOption from "./shipping-option"
|
||||
import { ShippingOption } from "./shipping-option"
|
||||
|
||||
type ShippingOptionTypeOptionalProps = DAL.SoftDeletableModelDateColumns
|
||||
|
||||
const DeletedAtIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "shipping_option_type",
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
export const ShippingOptionType = model.define("shipping_option_type", {
|
||||
id: model.id({ prefix: "sotype" }).primaryKey(),
|
||||
label: model.text(),
|
||||
description: model.text().nullable(),
|
||||
code: model.text(),
|
||||
shipping_option: model.hasOne(() => ShippingOption, {
|
||||
mappedBy: "type",
|
||||
}),
|
||||
})
|
||||
|
||||
@Entity()
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
export default class ShippingOptionType {
|
||||
[OptionalProps]?: ShippingOptionTypeOptionalProps
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id: string
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
label: string
|
||||
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
description: string | null = null
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
code: string
|
||||
|
||||
@OneToOne(() => ShippingOption, (so) => so.type, {
|
||||
type: "text",
|
||||
onDelete: "cascade",
|
||||
})
|
||||
shipping_option: Rel<ShippingOption>
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
created_at: Date
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
onUpdate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
updated_at: Date
|
||||
|
||||
@DeletedAtIndex.MikroORMIndex()
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "sotype")
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "sotype")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,182 +1,42 @@
|
||||
import {
|
||||
createPsqlIndexStatementHelper,
|
||||
DALUtils,
|
||||
generateEntityId,
|
||||
Searchable,
|
||||
ShippingOptionPriceType,
|
||||
} from "@medusajs/framework/utils"
|
||||
import { model, ShippingOptionPriceType } from "@medusajs/framework/utils"
|
||||
|
||||
import { DAL } from "@medusajs/framework/types"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Cascade,
|
||||
Collection,
|
||||
Entity,
|
||||
Enum,
|
||||
Filter,
|
||||
ManyToOne,
|
||||
OneToMany,
|
||||
OneToOne,
|
||||
OnInit,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
Rel,
|
||||
} from "@mikro-orm/core"
|
||||
import Fulfillment from "./fulfillment"
|
||||
import FulfillmentProvider from "./fulfillment-provider"
|
||||
import ServiceZone from "./service-zone"
|
||||
import ShippingOptionRule from "./shipping-option-rule"
|
||||
import ShippingOptionType from "./shipping-option-type"
|
||||
import ShippingProfile from "./shipping-profile"
|
||||
import { Fulfillment } from "./fulfillment"
|
||||
import { FulfillmentProvider } from "./fulfillment-provider"
|
||||
import { ServiceZone } from "./service-zone"
|
||||
import { ShippingOptionRule } from "./shipping-option-rule"
|
||||
import { ShippingOptionType } from "./shipping-option-type"
|
||||
import { ShippingProfile } from "./shipping-profile"
|
||||
|
||||
type ShippingOptionOptionalProps = DAL.SoftDeletableModelDateColumns
|
||||
|
||||
const DeletedAtIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "shipping_option",
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
const ServiceZoneIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "shipping_option",
|
||||
columns: "service_zone_id",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
const ShippingProfileIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "shipping_option",
|
||||
columns: "shipping_profile_id",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
const FulfillmentProviderIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "shipping_option",
|
||||
columns: "provider_id",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
const ShippingOptionTypeIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "shipping_option",
|
||||
columns: "shipping_option_type_id",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
@Entity()
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
export default class ShippingOption {
|
||||
[OptionalProps]?: ShippingOptionOptionalProps
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id: string
|
||||
|
||||
@Searchable()
|
||||
@Property({ columnType: "text" })
|
||||
name: string
|
||||
|
||||
@Enum({
|
||||
items: () => ShippingOptionPriceType,
|
||||
default: ShippingOptionPriceType.FLAT,
|
||||
export const ShippingOption = model
|
||||
.define("shipping_option", {
|
||||
id: model.id({ prefix: "so" }).primaryKey(),
|
||||
name: model.text(),
|
||||
price_type: model
|
||||
.enum(ShippingOptionPriceType)
|
||||
.default(ShippingOptionPriceType.FLAT),
|
||||
data: model.json().nullable(),
|
||||
metadata: model.json().nullable(),
|
||||
service_zone: model.belongsTo(() => ServiceZone, {
|
||||
mappedBy: "shipping_options",
|
||||
}),
|
||||
shipping_profile: model
|
||||
.belongsTo(() => ShippingProfile, {
|
||||
mappedBy: "shipping_options",
|
||||
})
|
||||
.nullable(),
|
||||
provider: model.belongsTo(() => FulfillmentProvider).nullable(),
|
||||
type: model.hasOne(() => ShippingOptionType, {
|
||||
foreignKey: true,
|
||||
foreignKeyName: "shipping_option_type_id",
|
||||
mappedBy: undefined,
|
||||
}),
|
||||
rules: model.hasMany(() => ShippingOptionRule, {
|
||||
mappedBy: "shipping_option",
|
||||
}),
|
||||
fulfillments: model.hasMany(() => Fulfillment, {
|
||||
mappedBy: "shipping_option",
|
||||
}),
|
||||
})
|
||||
price_type: ShippingOptionPriceType
|
||||
|
||||
@ManyToOne(() => ServiceZone, {
|
||||
type: "text",
|
||||
fieldName: "service_zone_id",
|
||||
mapToPk: true,
|
||||
onDelete: "cascade",
|
||||
.cascades({
|
||||
delete: ["rules", "type"],
|
||||
})
|
||||
@ServiceZoneIdIndex.MikroORMIndex()
|
||||
service_zone_id: string
|
||||
|
||||
@ManyToOne(() => ShippingProfile, {
|
||||
type: "text",
|
||||
fieldName: "shipping_profile_id",
|
||||
mapToPk: true,
|
||||
nullable: true,
|
||||
onDelete: "set null",
|
||||
})
|
||||
@ShippingProfileIdIndex.MikroORMIndex()
|
||||
shipping_profile_id: string | null
|
||||
|
||||
@ManyToOne(() => FulfillmentProvider, {
|
||||
type: "text",
|
||||
fieldName: "provider_id",
|
||||
mapToPk: true,
|
||||
nullable: true,
|
||||
})
|
||||
@FulfillmentProviderIdIndex.MikroORMIndex()
|
||||
provider_id: string
|
||||
|
||||
@Property({ columnType: "text", persist: false })
|
||||
@ShippingOptionTypeIdIndex.MikroORMIndex()
|
||||
shipping_option_type_id: string | null = null
|
||||
|
||||
@Property({ columnType: "jsonb", nullable: true })
|
||||
data: Record<string, unknown> | null = null
|
||||
|
||||
@Property({ columnType: "jsonb", nullable: true })
|
||||
metadata: Record<string, unknown> | null = null
|
||||
|
||||
@ManyToOne(() => ServiceZone, { persist: false })
|
||||
service_zone: Rel<ServiceZone>
|
||||
|
||||
@ManyToOne(() => ShippingProfile, {
|
||||
persist: false,
|
||||
})
|
||||
shipping_profile: Rel<ShippingProfile> | null
|
||||
|
||||
@ManyToOne(() => FulfillmentProvider, {
|
||||
persist: false,
|
||||
})
|
||||
provider: Rel<FulfillmentProvider> | null
|
||||
|
||||
@OneToOne(() => ShippingOptionType, (so) => so.shipping_option, {
|
||||
owner: true,
|
||||
cascade: [Cascade.PERSIST, "soft-remove"] as any,
|
||||
orphanRemoval: true,
|
||||
fieldName: "shipping_option_type_id",
|
||||
onDelete: "cascade",
|
||||
})
|
||||
type: Rel<ShippingOptionType>
|
||||
|
||||
@OneToMany(() => ShippingOptionRule, "shipping_option", {
|
||||
cascade: [Cascade.PERSIST, "soft-remove"] as any,
|
||||
orphanRemoval: true,
|
||||
})
|
||||
rules = new Collection<Rel<ShippingOptionRule>>(this)
|
||||
|
||||
@OneToMany(() => Fulfillment, (fulfillment) => fulfillment.shipping_option)
|
||||
fulfillments = new Collection<Rel<Fulfillment>>(this)
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
created_at: Date
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
onUpdate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
updated_at: Date
|
||||
|
||||
@DeletedAtIndex.MikroORMIndex()
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "so")
|
||||
this.shipping_option_type_id ??= this.type?.id
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "so")
|
||||
this.shipping_option_type_id ??= this.type?.id
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,92 +1,21 @@
|
||||
import {
|
||||
createPsqlIndexStatementHelper,
|
||||
DALUtils,
|
||||
generateEntityId,
|
||||
Searchable,
|
||||
} from "@medusajs/framework/utils"
|
||||
import { model } from "@medusajs/framework/utils"
|
||||
|
||||
import { DAL } from "@medusajs/framework/types"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Collection,
|
||||
Entity,
|
||||
Filter,
|
||||
OneToMany,
|
||||
OnInit,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
Rel,
|
||||
} from "@mikro-orm/core"
|
||||
import ShippingOption from "./shipping-option"
|
||||
import { ShippingOption } from "./shipping-option"
|
||||
|
||||
type ShippingProfileOptionalProps = DAL.SoftDeletableModelDateColumns
|
||||
|
||||
const DeletedAtIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "shipping_profile",
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
const ShippingProfileTypeIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "shipping_profile",
|
||||
columns: "name",
|
||||
unique: true,
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
@Entity()
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
export default class ShippingProfile {
|
||||
[OptionalProps]?: ShippingProfileOptionalProps
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id: string
|
||||
|
||||
@Searchable()
|
||||
@Property({ columnType: "text" })
|
||||
@ShippingProfileTypeIndex.MikroORMIndex()
|
||||
name: string
|
||||
|
||||
@Searchable()
|
||||
@Property({ columnType: "text" })
|
||||
type: string
|
||||
|
||||
@OneToMany(
|
||||
() => ShippingOption,
|
||||
(shippingOption) => shippingOption.shipping_profile
|
||||
)
|
||||
shipping_options = new Collection<Rel<ShippingOption>>(this)
|
||||
|
||||
@Property({ columnType: "jsonb", nullable: true })
|
||||
metadata: Record<string, unknown> | null = null
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
export const ShippingProfile = model
|
||||
.define("shipping_profile", {
|
||||
id: model.id({ prefix: "sp" }).primaryKey(),
|
||||
name: model.text(),
|
||||
type: model.text(),
|
||||
shipping_options: model.hasMany(() => ShippingOption, {
|
||||
mappedBy: "shipping_profile",
|
||||
}),
|
||||
metadata: model.json().nullable(),
|
||||
})
|
||||
created_at: Date
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
onUpdate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
updated_at: Date
|
||||
|
||||
@DeletedAtIndex.MikroORMIndex()
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "sp")
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "sp")
|
||||
}
|
||||
}
|
||||
.indexes([
|
||||
{
|
||||
on: ["name"],
|
||||
unique: true,
|
||||
where: "deleted_at IS NULL",
|
||||
},
|
||||
])
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
import { Context, FulfillmentTypes } from "@medusajs/framework/types"
|
||||
import { DALUtils, promiseAll } from "@medusajs/framework/utils"
|
||||
import { FulfillmentSet, ServiceZone } from "@models"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
|
||||
interface CreateFulfillmentSetDTO
|
||||
extends FulfillmentTypes.CreateFulfillmentSetDTO {
|
||||
service_zones: { id: string; name: string }[]
|
||||
}
|
||||
|
||||
export class FulfillmentSetRepository extends DALUtils.mikroOrmBaseRepositoryFactory<FulfillmentSet>(
|
||||
FulfillmentSet
|
||||
) {
|
||||
async update(
|
||||
data: {
|
||||
entity: FulfillmentSet
|
||||
update: FulfillmentTypes.FulfillmentSetDTO
|
||||
}[],
|
||||
context?: Context
|
||||
): Promise<FulfillmentSet[]> {
|
||||
const manager = this.getActiveManager<SqlEntityManager>(context)
|
||||
|
||||
// init all service zones collections
|
||||
await promiseAll(
|
||||
data.map(async ({ entity }) => {
|
||||
return await entity.service_zones.init()
|
||||
})
|
||||
)
|
||||
|
||||
const flfillmentSetsToUpdate = data.map(({ entity, update }) => {
|
||||
const { service_zones, ...restToUpdate } = update
|
||||
|
||||
const currentServiceZones = entity.service_zones.getItems()
|
||||
const serviceZonesToDetach = currentServiceZones.filter(
|
||||
(serviceZone) =>
|
||||
!update.service_zones.find(
|
||||
(newServiceZone) => newServiceZone.id === serviceZone.id
|
||||
)
|
||||
)
|
||||
const serviceZonesToAttach = update.service_zones.filter(
|
||||
(newServiceZone) =>
|
||||
!currentServiceZones.find(
|
||||
(serviceZone) => serviceZone.id === newServiceZone.id
|
||||
)
|
||||
)
|
||||
|
||||
entity.service_zones.remove(serviceZonesToDetach)
|
||||
entity.service_zones.add(serviceZonesToAttach as unknown as ServiceZone[])
|
||||
|
||||
return manager.assign(entity, restToUpdate)
|
||||
})
|
||||
|
||||
manager.persist(flfillmentSetsToUpdate)
|
||||
|
||||
return flfillmentSetsToUpdate
|
||||
}
|
||||
}
|
||||
*/
|
||||
@@ -1 +0,0 @@
|
||||
export { MikroOrmBaseRepository as BaseRepository } from "@medusajs/framework/utils"
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
FulfillmentOption,
|
||||
FulfillmentTypes,
|
||||
IFulfillmentModuleService,
|
||||
InferEntityType,
|
||||
InternalModuleDeclaration,
|
||||
Logger,
|
||||
ModuleJoinerConfig,
|
||||
@@ -19,6 +20,7 @@ import {
|
||||
} from "@medusajs/framework/types"
|
||||
import {
|
||||
arrayDifference,
|
||||
deepCopy,
|
||||
deepEqualObj,
|
||||
EmitEvents,
|
||||
getSetDifference,
|
||||
@@ -49,6 +51,7 @@ import {
|
||||
buildCreatedServiceZoneEvents,
|
||||
eventBuilders,
|
||||
isContextValid,
|
||||
Rule,
|
||||
validateAndNormalizeRules,
|
||||
} from "@utils"
|
||||
import { joinerConfig } from "../joiner-config"
|
||||
@@ -70,6 +73,7 @@ const generateMethodForModels = {
|
||||
|
||||
type InjectedDependencies = {
|
||||
baseRepository: DAL.RepositoryService
|
||||
fulfillmentAddressService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
fulfillmentSetService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
serviceZoneService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
geoZoneService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
@@ -96,15 +100,31 @@ export default class FulfillmentModuleService
|
||||
implements IFulfillmentModuleService
|
||||
{
|
||||
protected baseRepository_: DAL.RepositoryService
|
||||
protected readonly fulfillmentSetService_: ModulesSdkTypes.IMedusaInternalService<FulfillmentSet>
|
||||
protected readonly serviceZoneService_: ModulesSdkTypes.IMedusaInternalService<ServiceZone>
|
||||
protected readonly geoZoneService_: ModulesSdkTypes.IMedusaInternalService<GeoZone>
|
||||
protected readonly shippingProfileService_: ModulesSdkTypes.IMedusaInternalService<ShippingProfile>
|
||||
protected readonly shippingOptionService_: ModulesSdkTypes.IMedusaInternalService<ShippingOption>
|
||||
protected readonly shippingOptionRuleService_: ModulesSdkTypes.IMedusaInternalService<ShippingOptionRule>
|
||||
protected readonly shippingOptionTypeService_: ModulesSdkTypes.IMedusaInternalService<ShippingOptionType>
|
||||
protected readonly fulfillmentSetService_: ModulesSdkTypes.IMedusaInternalService<
|
||||
InferEntityType<typeof FulfillmentSet>
|
||||
>
|
||||
protected readonly serviceZoneService_: ModulesSdkTypes.IMedusaInternalService<
|
||||
InferEntityType<typeof ServiceZone>
|
||||
>
|
||||
protected readonly geoZoneService_: ModulesSdkTypes.IMedusaInternalService<
|
||||
InferEntityType<typeof GeoZone>
|
||||
>
|
||||
protected readonly shippingProfileService_: ModulesSdkTypes.IMedusaInternalService<
|
||||
InferEntityType<typeof ShippingProfile>
|
||||
>
|
||||
protected readonly shippingOptionService_: ModulesSdkTypes.IMedusaInternalService<
|
||||
InferEntityType<typeof ShippingOption>
|
||||
>
|
||||
protected readonly shippingOptionRuleService_: ModulesSdkTypes.IMedusaInternalService<
|
||||
InferEntityType<typeof ShippingOptionRule>
|
||||
>
|
||||
protected readonly shippingOptionTypeService_: ModulesSdkTypes.IMedusaInternalService<
|
||||
InferEntityType<typeof ShippingOptionType>
|
||||
>
|
||||
protected readonly fulfillmentProviderService_: FulfillmentProviderService
|
||||
protected readonly fulfillmentService_: ModulesSdkTypes.IMedusaInternalService<Fulfillment>
|
||||
protected readonly fulfillmentService_: ModulesSdkTypes.IMedusaInternalService<
|
||||
InferEntityType<typeof Fulfillment>
|
||||
>
|
||||
|
||||
constructor(
|
||||
{
|
||||
@@ -118,6 +138,7 @@ export default class FulfillmentModuleService
|
||||
shippingOptionTypeService,
|
||||
fulfillmentProviderService,
|
||||
fulfillmentService,
|
||||
fulfillmentAddressService,
|
||||
}: InjectedDependencies,
|
||||
protected readonly moduleDeclaration: InternalModuleDeclaration
|
||||
) {
|
||||
@@ -188,7 +209,7 @@ export default class FulfillmentModuleService
|
||||
|
||||
return isContextValid(
|
||||
context,
|
||||
shippingOption.rules.map((r) => r)
|
||||
shippingOption.rules.map((r) => r) as unknown as Rule[]
|
||||
)
|
||||
})
|
||||
}
|
||||
@@ -292,7 +313,7 @@ export default class FulfillmentModuleService
|
||||
| FulfillmentTypes.CreateFulfillmentSetDTO
|
||||
| FulfillmentTypes.CreateFulfillmentSetDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<FulfillmentSet[]> {
|
||||
): Promise<InferEntityType<typeof FulfillmentSet>[]> {
|
||||
const data_ = Array.isArray(data) ? data : [data]
|
||||
|
||||
if (!data_.length) {
|
||||
@@ -358,7 +379,7 @@ export default class FulfillmentModuleService
|
||||
| FulfillmentTypes.CreateServiceZoneDTO[]
|
||||
| FulfillmentTypes.CreateServiceZoneDTO,
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<ServiceZone[]> {
|
||||
): Promise<InferEntityType<typeof ServiceZone>[]> {
|
||||
const data_ = Array.isArray(data) ? data : [data]
|
||||
|
||||
if (!data_.length) {
|
||||
@@ -422,7 +443,7 @@ export default class FulfillmentModuleService
|
||||
| FulfillmentTypes.CreateShippingOptionDTO[]
|
||||
| FulfillmentTypes.CreateShippingOptionDTO,
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<ShippingOption[]> {
|
||||
): Promise<InferEntityType<typeof ShippingOption>[]> {
|
||||
const data_ = Array.isArray(data) ? data : [data]
|
||||
|
||||
if (!data_.length) {
|
||||
@@ -491,7 +512,7 @@ export default class FulfillmentModuleService
|
||||
| FulfillmentTypes.CreateShippingProfileDTO[]
|
||||
| FulfillmentTypes.CreateShippingProfileDTO,
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<ShippingProfile[]> {
|
||||
): Promise<InferEntityType<typeof ShippingProfile>[]> {
|
||||
const data_ = Array.isArray(data) ? data : [data]
|
||||
|
||||
if (!data_.length) {
|
||||
@@ -580,7 +601,7 @@ export default class FulfillmentModuleService
|
||||
| FulfillmentTypes.CreateShippingOptionRuleDTO[]
|
||||
| FulfillmentTypes.CreateShippingOptionRuleDTO,
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<ShippingOptionRule[]> {
|
||||
): Promise<InferEntityType<typeof ShippingOptionRule>[]> {
|
||||
const data_ = Array.isArray(data) ? data : [data]
|
||||
|
||||
if (!data_.length) {
|
||||
@@ -625,7 +646,7 @@ export default class FulfillmentModuleService
|
||||
try {
|
||||
const providerResult =
|
||||
await this.fulfillmentProviderService_.createFulfillment(
|
||||
provider_id,
|
||||
provider_id!, // TODO: should we add a runtime check on provider_id being provided?
|
||||
fulfillmentData || {},
|
||||
items.map((i) => i),
|
||||
order,
|
||||
@@ -692,7 +713,7 @@ export default class FulfillmentModuleService
|
||||
try {
|
||||
const providerResult =
|
||||
await this.fulfillmentProviderService_.createReturn(
|
||||
fulfillment.provider_id,
|
||||
fulfillment.provider_id!, // TODO: should we add a runtime check on provider_id being provided?,
|
||||
fulfillment as Record<any, any>
|
||||
)
|
||||
await this.fulfillmentService_.update(
|
||||
@@ -750,7 +771,10 @@ export default class FulfillmentModuleService
|
||||
protected async updateFulfillmentSets_(
|
||||
data: UpdateFulfillmentSetDTO[] | UpdateFulfillmentSetDTO,
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<FulfillmentSet[] | FulfillmentSet> {
|
||||
): Promise<
|
||||
| InferEntityType<typeof FulfillmentSet>[]
|
||||
| InferEntityType<typeof FulfillmentSet>
|
||||
> {
|
||||
const data_ = Array.isArray(data) ? data : [data]
|
||||
|
||||
if (!data_.length) {
|
||||
@@ -789,9 +813,10 @@ export default class FulfillmentModuleService
|
||||
)
|
||||
}
|
||||
|
||||
const fulfillmentSetMap = new Map<string, FulfillmentSet>(
|
||||
fulfillmentSets.map((f) => [f.id, f])
|
||||
)
|
||||
const fulfillmentSetMap = new Map<
|
||||
string,
|
||||
InferEntityType<typeof FulfillmentSet>
|
||||
>(fulfillmentSets.map((f) => [f.id, f]))
|
||||
|
||||
const serviceZoneIdsToDelete: string[] = []
|
||||
const geoZoneIdsToDelete: string[] = []
|
||||
@@ -1013,7 +1038,9 @@ export default class FulfillmentModuleService
|
||||
| FulfillmentTypes.UpdateServiceZoneDTO[]
|
||||
| FulfillmentTypes.UpdateServiceZoneDTO,
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<ServiceZone | ServiceZone[]> {
|
||||
): Promise<
|
||||
InferEntityType<typeof ServiceZone> | InferEntityType<typeof ServiceZone>[]
|
||||
> {
|
||||
const data_ = Array.isArray(data) ? data : [data]
|
||||
|
||||
if (!data_.length) {
|
||||
@@ -1052,7 +1079,7 @@ export default class FulfillmentModuleService
|
||||
)
|
||||
}
|
||||
|
||||
const serviceZoneMap = new Map<string, ServiceZone>(
|
||||
const serviceZoneMap = new Map<string, InferEntityType<typeof ServiceZone>>(
|
||||
serviceZones.map((s) => [s.id, s])
|
||||
)
|
||||
|
||||
@@ -1209,7 +1236,9 @@ export default class FulfillmentModuleService
|
||||
| FulfillmentTypes.UpsertServiceZoneDTO[]
|
||||
| FulfillmentTypes.UpsertServiceZoneDTO,
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<ServiceZone[] | ServiceZone> {
|
||||
): Promise<
|
||||
InferEntityType<typeof ServiceZone>[] | InferEntityType<typeof ServiceZone>
|
||||
> {
|
||||
const input = Array.isArray(data) ? data : [data]
|
||||
const forUpdate = input.filter(
|
||||
(serviceZone): serviceZone is FulfillmentTypes.UpdateServiceZoneDTO =>
|
||||
@@ -1220,8 +1249,8 @@ export default class FulfillmentModuleService
|
||||
!serviceZone.id
|
||||
)
|
||||
|
||||
const created: ServiceZone[] = []
|
||||
const updated: ServiceZone[] = []
|
||||
const created: InferEntityType<typeof ServiceZone>[] = []
|
||||
const updated: InferEntityType<typeof ServiceZone>[] = []
|
||||
|
||||
if (forCreate.length) {
|
||||
const createdServiceZones = await this.createServiceZones_(
|
||||
@@ -1304,8 +1333,13 @@ export default class FulfillmentModuleService
|
||||
async updateShippingOptions_(
|
||||
data: UpdateShippingOptionsInput[] | UpdateShippingOptionsInput,
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<ShippingOption | ShippingOption[]> {
|
||||
const dataArray = Array.isArray(data) ? data : [data]
|
||||
): Promise<
|
||||
| InferEntityType<typeof ShippingOption>
|
||||
| InferEntityType<typeof ShippingOption>[]
|
||||
> {
|
||||
const dataArray = Array.isArray(data)
|
||||
? data.map((d) => deepCopy(d))
|
||||
: [deepCopy(data)]
|
||||
|
||||
if (!dataArray.length) {
|
||||
return []
|
||||
@@ -1365,7 +1399,8 @@ export default class FulfillmentModuleService
|
||||
|
||||
const existingRulesMap: Map<
|
||||
string,
|
||||
FulfillmentTypes.UpdateShippingOptionRuleDTO | ShippingOptionRule
|
||||
| FulfillmentTypes.UpdateShippingOptionRuleDTO
|
||||
| InferEntityType<typeof ShippingOptionRule>
|
||||
> = new Map(existingRules.map((rule) => [rule.id, rule]))
|
||||
|
||||
const updatedRules = shippingOption.rules
|
||||
@@ -1378,6 +1413,13 @@ export default class FulfillmentModuleService
|
||||
updatedRuleIds.push(rule.id)
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
delete rule.created_at
|
||||
// @ts-ignore
|
||||
delete rule.updated_at
|
||||
// @ts-ignore
|
||||
delete rule.deleted_at
|
||||
|
||||
const ruleData: FulfillmentTypes.UpdateShippingOptionRuleDTO = {
|
||||
...existingRule,
|
||||
...rule,
|
||||
@@ -1530,7 +1572,7 @@ export default class FulfillmentModuleService
|
||||
| FulfillmentTypes.UpsertShippingOptionDTO[]
|
||||
| FulfillmentTypes.UpsertShippingOptionDTO,
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<ShippingOption[] | ShippingOption> {
|
||||
): Promise<InferEntityType<typeof ShippingOption>[]> {
|
||||
const input = Array.isArray(data) ? data : [data]
|
||||
const forUpdate = input.filter(
|
||||
(shippingOption): shippingOption is UpdateShippingOptionsInput =>
|
||||
@@ -1543,8 +1585,8 @@ export default class FulfillmentModuleService
|
||||
!shippingOption.id
|
||||
)
|
||||
|
||||
let created: ShippingOption[] = []
|
||||
let updated: ShippingOption[] = []
|
||||
let created: InferEntityType<typeof ShippingOption>[] = []
|
||||
let updated: InferEntityType<typeof ShippingOption>[] = []
|
||||
|
||||
if (forCreate.length) {
|
||||
const createdShippingOptions = await this.createShippingOptions_(
|
||||
@@ -1649,8 +1691,8 @@ export default class FulfillmentModuleService
|
||||
(prof): prof is FulfillmentTypes.CreateShippingProfileDTO => !prof.id
|
||||
)
|
||||
|
||||
let created: ShippingProfile[] = []
|
||||
let updated: ShippingProfile[] = []
|
||||
let created: InferEntityType<typeof ShippingProfile>[] = []
|
||||
let updated: InferEntityType<typeof ShippingProfile>[] = []
|
||||
|
||||
if (forCreate.length) {
|
||||
created = await this.shippingProfileService_.create(
|
||||
@@ -1755,7 +1797,10 @@ export default class FulfillmentModuleService
|
||||
| FulfillmentTypes.UpdateShippingOptionRuleDTO[]
|
||||
| FulfillmentTypes.UpdateShippingOptionRuleDTO,
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<ShippingOptionRule | ShippingOptionRule[]> {
|
||||
): Promise<
|
||||
| InferEntityType<typeof ShippingOptionRule>
|
||||
| InferEntityType<typeof ShippingOptionRule>[]
|
||||
> {
|
||||
const data_ = Array.isArray(data) ? data : [data]
|
||||
|
||||
if (!data_.length) {
|
||||
@@ -1796,8 +1841,8 @@ export default class FulfillmentModuleService
|
||||
id: string,
|
||||
data: FulfillmentTypes.UpdateFulfillmentDTO,
|
||||
@MedusaContext() sharedContext: Context
|
||||
): Promise<Fulfillment> {
|
||||
const existingFulfillment: Fulfillment =
|
||||
): Promise<InferEntityType<typeof Fulfillment>> {
|
||||
const existingFulfillment: InferEntityType<typeof Fulfillment> =
|
||||
await this.fulfillmentService_.retrieve(
|
||||
id,
|
||||
{
|
||||
@@ -1868,7 +1913,7 @@ export default class FulfillmentModuleService
|
||||
}
|
||||
|
||||
private handleFulfillmentUpdateEvents(
|
||||
fulfillment: Fulfillment,
|
||||
fulfillment: InferEntityType<typeof Fulfillment>,
|
||||
existingLabelIds: string[],
|
||||
updatedLabelIds: string[],
|
||||
deletedLabelIds: string[],
|
||||
@@ -1919,7 +1964,7 @@ export default class FulfillmentModuleService
|
||||
if (!fulfillment.canceled_at) {
|
||||
try {
|
||||
await this.fulfillmentProviderService_.cancelFulfillment(
|
||||
fulfillment.provider_id,
|
||||
fulfillment.provider_id!, // TODO: should we add a runtime check on provider_id being provided?,
|
||||
fulfillment.data ?? {}
|
||||
)
|
||||
} catch (error) {
|
||||
@@ -2094,7 +2139,9 @@ export default class FulfillmentModuleService
|
||||
}
|
||||
}
|
||||
|
||||
protected static canCancelFulfillmentOrThrow(fulfillment: Fulfillment) {
|
||||
protected static canCancelFulfillmentOrThrow(
|
||||
fulfillment: InferEntityType<typeof Fulfillment>
|
||||
) {
|
||||
if (fulfillment.shipped_at) {
|
||||
throw new MedusaError(
|
||||
MedusaError.Types.INVALID_DATA,
|
||||
@@ -2113,7 +2160,7 @@ export default class FulfillmentModuleService
|
||||
}
|
||||
|
||||
protected static validateMissingShippingOptions_(
|
||||
shippingOptions: ShippingOption[],
|
||||
shippingOptions: InferEntityType<typeof ShippingOption>[],
|
||||
shippingOptionsData: UpdateShippingOptionsInput[]
|
||||
) {
|
||||
const missingShippingOptionIds = arrayDifference(
|
||||
@@ -2132,7 +2179,7 @@ export default class FulfillmentModuleService
|
||||
}
|
||||
|
||||
protected static validateMissingShippingOptionRules(
|
||||
shippingOption: ShippingOption,
|
||||
shippingOption: InferEntityType<typeof ShippingOption>,
|
||||
shippingOptionUpdateData: FulfillmentTypes.UpdateShippingOptionDTO
|
||||
) {
|
||||
if (!shippingOptionUpdateData.rules) {
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
ShippingOptionRule,
|
||||
ShippingOptionType,
|
||||
} from "@models"
|
||||
import { Context } from "@medusajs/framework/types"
|
||||
import { Context, InferEntityType } from "@medusajs/framework/types"
|
||||
import {
|
||||
CommonEvents,
|
||||
FulfillmentEvents,
|
||||
@@ -172,7 +172,7 @@ export function buildCreatedFulfillmentEvents({
|
||||
fulfillments,
|
||||
sharedContext,
|
||||
}: {
|
||||
fulfillments: Fulfillment[]
|
||||
fulfillments: InferEntityType<typeof Fulfillment>[]
|
||||
sharedContext: Context
|
||||
}) {
|
||||
if (!fulfillments.length) {
|
||||
@@ -210,7 +210,7 @@ export function buildCreatedShippingOptionEvents({
|
||||
shippingOptions,
|
||||
sharedContext,
|
||||
}: {
|
||||
shippingOptions: ShippingOption[]
|
||||
shippingOptions: InferEntityType<typeof ShippingOption>[]
|
||||
sharedContext: Context
|
||||
}) {
|
||||
if (!shippingOptions.length) {
|
||||
@@ -218,8 +218,8 @@ export function buildCreatedShippingOptionEvents({
|
||||
}
|
||||
|
||||
const options: { id: string }[] = []
|
||||
const types: ShippingOptionType[] = []
|
||||
const rules: ShippingOptionRule[] = []
|
||||
const types: InferEntityType<typeof ShippingOptionType>[] = []
|
||||
const rules: InferEntityType<typeof ShippingOptionRule>[] = []
|
||||
|
||||
shippingOptions.forEach((shippingOption) => {
|
||||
options.push({ id: shippingOption.id })
|
||||
@@ -242,14 +242,14 @@ export function buildCreatedFulfillmentSetEvents({
|
||||
fulfillmentSets,
|
||||
sharedContext,
|
||||
}: {
|
||||
fulfillmentSets: FulfillmentSet[]
|
||||
fulfillmentSets: InferEntityType<typeof FulfillmentSet>[]
|
||||
sharedContext: Context
|
||||
}): void {
|
||||
if (!fulfillmentSets.length) {
|
||||
return
|
||||
}
|
||||
|
||||
const serviceZones: ServiceZone[] = []
|
||||
const serviceZones: InferEntityType<typeof ServiceZone>[] = []
|
||||
|
||||
fulfillmentSets.forEach((fulfillmentSet) => {
|
||||
if (!fulfillmentSet.service_zones?.length) {
|
||||
@@ -268,14 +268,14 @@ export function buildCreatedServiceZoneEvents({
|
||||
serviceZones,
|
||||
sharedContext,
|
||||
}: {
|
||||
serviceZones: ServiceZone[]
|
||||
serviceZones: InferEntityType<typeof ServiceZone>[]
|
||||
sharedContext: Context
|
||||
}): void {
|
||||
if (!serviceZones.length) {
|
||||
return
|
||||
}
|
||||
|
||||
const geoZones: GeoZone[] = []
|
||||
const geoZones: InferEntityType<typeof GeoZone>[] = []
|
||||
|
||||
serviceZones.forEach((serviceZone) => {
|
||||
if (!serviceZone.geo_zones.length) {
|
||||
|
||||
@@ -16,7 +16,7 @@ import {
|
||||
|
||||
export type Rule = {
|
||||
attribute: string
|
||||
operator: Lowercase<keyof typeof RuleOperator>
|
||||
operator: Lowercase<keyof typeof RuleOperator> | (string & {})
|
||||
value: string | string[] | null
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user