feat(fulfillment): implementation part 2 (#6408)

**What**

> [!NOTE]  
> I can see this pr becoming huge, so I d like to get this partial one merged 👍 


- Fixes shared connection usage (mikro orm compare the instance to its own package and therefore was resulting in not trully reusing the provided connection leading to exhausting the connection pool as multiple connections was created and end up not being all destroyed properly under the hood, discovered in my integration tests)
- Create shipping options method implementation
- DTO's definition and service interface update
- integration tests 
- Re work of the indexes with new util update
- Test runner utils to remove a big chunk of the boilerplate of the packages integrations

FIXES CORE-1742
This commit is contained in:
Adrien de Peretti
2024-02-19 12:33:46 +00:00
committed by GitHub
parent 680dfcdad3
commit 1d91b7429b
59 changed files with 2213 additions and 1741 deletions
@@ -493,20 +493,7 @@
}
],
"checks": [],
"foreignKeys": {
"service_zone_fulfillment_set_id_foreign": {
"constraintName": "service_zone_fulfillment_set_id_foreign",
"columnNames": [
"fulfillment_set_id"
],
"localTableName": "public.service_zone",
"referencedColumnNames": [
"id"
],
"referencedTableName": "public.fulfillment_set",
"updateRule": "cascade"
}
}
"foreignKeys": {}
},
{
"columns": {
@@ -686,20 +673,7 @@
}
],
"checks": [],
"foreignKeys": {
"geo_zone_service_zone_id_foreign": {
"constraintName": "geo_zone_service_zone_id_foreign",
"columnNames": [
"service_zone_id"
],
"localTableName": "public.geo_zone",
"referencedColumnNames": [
"id"
],
"referencedTableName": "public.service_zone",
"updateRule": "cascade"
}
}
"foreignKeys": {}
},
{
"columns": {
@@ -828,6 +802,24 @@
"nullable": false,
"mappedType": "text"
},
"name": {
"name": "name",
"type": "text",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"mappedType": "text"
},
"type": {
"name": "type",
"type": "text",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"mappedType": "text"
},
"metadata": {
"name": "metadata",
"type": "jsonb",
@@ -873,6 +865,16 @@
"name": "shipping_profile",
"schema": "public",
"indexes": [
{
"keyName": "IDX_shipping_profile_name_unique",
"columnNames": [
"name"
],
"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": [
@@ -945,7 +947,7 @@
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"nullable": true,
"mappedType": "text"
},
"service_provider_id": {
@@ -954,15 +956,6 @@
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"mappedType": "text"
},
"shipping_option_type_id": {
"name": "shipping_option_type_id",
"type": "text",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": true,
"mappedType": "text"
},
@@ -984,6 +977,15 @@
"nullable": true,
"mappedType": "json"
},
"shipping_option_type_id": {
"name": "shipping_option_type_id",
"type": "text",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": true,
"mappedType": "text"
},
"created_at": {
"name": "created_at",
"type": "timestamptz",
@@ -1091,18 +1093,6 @@
],
"checks": [],
"foreignKeys": {
"shipping_option_service_zone_id_foreign": {
"constraintName": "shipping_option_service_zone_id_foreign",
"columnNames": [
"service_zone_id"
],
"localTableName": "public.shipping_option",
"referencedColumnNames": [
"id"
],
"referencedTableName": "public.service_zone",
"updateRule": "cascade"
},
"shipping_option_shipping_profile_id_foreign": {
"constraintName": "shipping_option_shipping_profile_id_foreign",
"columnNames": [
@@ -1113,6 +1103,7 @@
"id"
],
"referencedTableName": "public.shipping_profile",
"deleteRule": "set null",
"updateRule": "cascade"
},
"shipping_option_service_provider_id_foreign": {
@@ -1125,6 +1116,7 @@
"id"
],
"referencedTableName": "public.service_provider",
"deleteRule": "set null",
"updateRule": "cascade"
},
"shipping_option_shipping_option_type_id_foreign": {
@@ -1137,6 +1129,7 @@
"id"
],
"referencedTableName": "public.shipping_option_type",
"deleteRule": "cascade",
"updateRule": "cascade"
}
}
@@ -1224,6 +1217,16 @@
"name": "shipping_option_rule",
"schema": "public",
"indexes": [
{
"keyName": "IDX_shipping_option_rule_shipping_option_id",
"columnNames": [
"shipping_option_id"
],
"composite": false,
"primary": false,
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_shipping_option_rule_shipping_option_id\" ON \"shipping_option_rule\" (shipping_option_id) WHERE deleted_at IS NULL"
},
{
"keyName": "IDX_shipping_option_rule_deleted_at",
"columnNames": [
@@ -1245,20 +1248,7 @@
}
],
"checks": [],
"foreignKeys": {
"shipping_option_rule_shipping_option_id_foreign": {
"constraintName": "shipping_option_rule_shipping_option_id_foreign",
"columnNames": [
"shipping_option_id"
],
"localTableName": "public.shipping_option_rule",
"referencedColumnNames": [
"id"
],
"referencedTableName": "public.shipping_option",
"updateRule": "cascade"
}
}
"foreignKeys": {}
},
{
"columns": {
@@ -1760,7 +1750,7 @@
"composite": false,
"primary": false,
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_fulfillment_item_fulfillment_id\" ON \"fulfillment_item\" (line_item_id) WHERE deleted_at IS NULL"
"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",
@@ -1770,7 +1760,7 @@
"composite": false,
"primary": false,
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_fulfillment_item_fulfillment_id\" ON \"fulfillment_item\" (inventory_item_id) WHERE deleted_at IS NULL"
"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",
@@ -1,6 +1,6 @@
import { Migration } from '@mikro-orm/migrations';
export class Migration20240214103108 extends Migration {
export class Migration20240219115644 extends Migration {
async up(): Promise<void> {
this.addSql('create table if not exists "fulfillment_address" ("id" text not null, "fulfillment_id" text null, "company" text null, "first_name" text null, "last_name" text null, "address_1" text null, "address_2" text null, "city" text null, "country_code" text null, "province" text null, "postal_code" text null, "phone" text null, "metadata" jsonb null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "fulfillment_address_pkey" primary key ("id"));');
@@ -30,10 +30,11 @@ export class Migration20240214103108 extends Migration {
this.addSql('CREATE INDEX IF NOT EXISTS "IDX_shipping_option_type_shipping_option_id" ON "shipping_option_type" (shipping_option_id) WHERE deleted_at IS NULL;');
this.addSql('CREATE INDEX IF NOT EXISTS "IDX_shipping_option_type_deleted_at" ON "shipping_option_type" (deleted_at) WHERE deleted_at IS NOT NULL;');
this.addSql('create table if not exists "shipping_profile" ("id" text not null, "metadata" jsonb null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "shipping_profile_pkey" primary key ("id"));');
this.addSql('create table if not exists "shipping_profile" ("id" text not null, "name" text not null, "type" text not null, "metadata" jsonb null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "shipping_profile_pkey" primary key ("id"));');
this.addSql('CREATE UNIQUE INDEX IF NOT EXISTS "IDX_shipping_profile_name_unique" ON "shipping_profile" (name) WHERE deleted_at IS NULL;');
this.addSql('CREATE INDEX IF NOT EXISTS "IDX_shipping_profile_deleted_at" ON "shipping_profile" (deleted_at) WHERE deleted_at IS NOT NULL;');
this.addSql('create table if not exists "shipping_option" ("id" text not null, "name" text not null, "price_type" text check ("price_type" in (\'calculated\', \'flat\')) not null default \'calculated\', "service_zone_id" text not null, "shipping_profile_id" text not null, "service_provider_id" text not null, "shipping_option_type_id" text null, "data" jsonb null, "metadata" jsonb null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "shipping_option_pkey" primary key ("id"));');
this.addSql('create table if not exists "shipping_option" ("id" text not null, "name" text not null, "price_type" text check ("price_type" in (\'calculated\', \'flat\')) not null default \'calculated\', "service_zone_id" text not null, "shipping_profile_id" text null, "service_provider_id" text null, "data" jsonb null, "metadata" jsonb null, "shipping_option_type_id" text null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "shipping_option_pkey" primary key ("id"));');
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_service_zone_id" ON "shipping_option" (service_zone_id) WHERE deleted_at IS NULL;');
this.addSql('CREATE INDEX IF NOT EXISTS "IDX_shipping_option_shipping_profile_id" ON "shipping_option" (shipping_profile_id) WHERE deleted_at IS NULL;');
@@ -42,6 +43,7 @@ export class Migration20240214103108 extends Migration {
this.addSql('CREATE INDEX IF NOT EXISTS "IDX_shipping_option_deleted_at" ON "shipping_option" (deleted_at) WHERE deleted_at IS NOT NULL;');
this.addSql('create table if not exists "shipping_option_rule" ("id" text not null, "attribute" text not null, "operator" text not null, "value" jsonb null, "shipping_option_id" text not null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "shipping_option_rule_pkey" primary key ("id"));');
this.addSql('CREATE INDEX IF NOT EXISTS "IDX_shipping_option_rule_shipping_option_id" ON "shipping_option_rule" (shipping_option_id) WHERE deleted_at IS NULL;');
this.addSql('CREATE INDEX IF NOT EXISTS "IDX_shipping_option_rule_deleted_at" ON "shipping_option_rule" (deleted_at) WHERE deleted_at IS NOT NULL;');
this.addSql('create table if not exists "fulfillment" ("id" text not null, "location_id" text not null, "packed_at" timestamptz null, "shipped_at" timestamptz null, "delivered_at" timestamptz null, "canceled_at" timestamptz null, "data" jsonb null, "provider_id" text not null, "shipping_option_id" text null, "metadata" jsonb null, "delivery_address_id" text not null, "items_id" text not null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "fulfillment_pkey" primary key ("id"));');
@@ -55,21 +57,14 @@ export class Migration20240214103108 extends Migration {
this.addSql('CREATE INDEX IF NOT EXISTS "IDX_fulfillment_label_deleted_at" ON "fulfillment_label" (deleted_at) WHERE deleted_at IS NOT NULL;');
this.addSql('create table if not exists "fulfillment_item" ("id" text not null, "title" text not null, "sku" text not null, "barcode" text not null, "quantity" numeric not null, "line_item_id" text null, "inventory_item_id" text null, "fulfillment_id" text not null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "fulfillment_item_pkey" primary key ("id"));');
this.addSql('CREATE INDEX IF NOT EXISTS "IDX_fulfillment_item_fulfillment_id" ON "fulfillment_item" (line_item_id) WHERE deleted_at IS NULL;');
this.addSql('CREATE INDEX IF NOT EXISTS "IDX_fulfillment_item_fulfillment_id" ON "fulfillment_item" (inventory_item_id) WHERE deleted_at IS NULL;');
this.addSql('CREATE INDEX IF NOT EXISTS "IDX_fulfillment_item_line_item_id" ON "fulfillment_item" (line_item_id) WHERE deleted_at IS NULL;');
this.addSql('CREATE INDEX IF NOT EXISTS "IDX_fulfillment_item_inventory_item_id" ON "fulfillment_item" (inventory_item_id) WHERE deleted_at IS NULL;');
this.addSql('CREATE INDEX IF NOT EXISTS "IDX_fulfillment_item_fulfillment_id" ON "fulfillment_item" (fulfillment_id) WHERE deleted_at IS NULL;');
this.addSql('CREATE INDEX IF NOT EXISTS "IDX_fulfillment_item_deleted_at" ON "fulfillment_item" (deleted_at) WHERE deleted_at IS NOT NULL;');
this.addSql('alter table if exists "service_zone" add constraint "service_zone_fulfillment_set_id_foreign" foreign key ("fulfillment_set_id") references "fulfillment_set" ("id") on update cascade;');
this.addSql('alter table if exists "geo_zone" add constraint "geo_zone_service_zone_id_foreign" foreign key ("service_zone_id") references "service_zone" ("id") on update cascade;');
this.addSql('alter table if exists "shipping_option" add constraint "shipping_option_service_zone_id_foreign" foreign key ("service_zone_id") references "service_zone" ("id") on update cascade;');
this.addSql('alter table if exists "shipping_option" add constraint "shipping_option_shipping_profile_id_foreign" foreign key ("shipping_profile_id") references "shipping_profile" ("id") on update cascade;');
this.addSql('alter table if exists "shipping_option" add constraint "shipping_option_service_provider_id_foreign" foreign key ("service_provider_id") references "service_provider" ("id") on update cascade;');
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;');
this.addSql('alter table if exists "shipping_option_rule" add constraint "shipping_option_rule_shipping_option_id_foreign" foreign key ("shipping_option_id") references "shipping_option" ("id") on update cascade;');
this.addSql('alter table if exists "shipping_option" add constraint "shipping_option_shipping_profile_id_foreign" foreign key ("shipping_profile_id") references "shipping_profile" ("id") on update cascade on delete set null;');
this.addSql('alter table if exists "shipping_option" add constraint "shipping_option_service_provider_id_foreign" foreign key ("service_provider_id") references "service_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 "fulfillment" add constraint "fulfillment_shipping_option_id_foreign" foreign key ("shipping_option_id") references "shipping_option" ("id") on update cascade on delete set null;');
this.addSql('alter table if exists "fulfillment" add constraint "fulfillment_provider_id_foreign" foreign key ("provider_id") references "service_provider" ("id") on update cascade;');
+6 -17
View File
@@ -6,7 +6,6 @@ import {
import {
BeforeCreate,
Entity,
Index,
OnInit,
OptionalProps,
PrimaryKey,
@@ -15,21 +14,17 @@ import {
type OptionalAddressProps = DAL.SoftDeletableEntityDateColumns
const fulfillmentIdIndexName = "IDX_fulfillment_address_fulfillment_id"
const fulfillmentIdIndexStatement = createPsqlIndexStatementHelper({
name: fulfillmentIdIndexName,
const FulfillmentIdIndex = createPsqlIndexStatementHelper({
tableName: "fulfillment_address",
columns: "fulfillment_id",
where: "deleted_at IS NULL",
}).expression
})
const fulfillmentDeletedAtIndexName = "IDX_fulfillment_address_deleted_at"
const fulfillmentDeletedAtIndexStatement = createPsqlIndexStatementHelper({
name: fulfillmentDeletedAtIndexName,
const FulfillmentDeletedAtIndex = createPsqlIndexStatementHelper({
tableName: "fulfillment_address",
columns: "deleted_at",
where: "deleted_at IS NOT NULL",
}).expression
})
@Entity({ tableName: "fulfillment_address" })
export default class Address {
@@ -39,10 +34,7 @@ export default class Address {
id!: string
@Property({ columnType: "text", nullable: true })
@Index({
name: fulfillmentIdIndexName,
expression: fulfillmentIdIndexStatement,
})
@FulfillmentIdIndex.MikroORMIndex()
fulfillment_id: string | null = null
@Property({ columnType: "text", nullable: true })
@@ -94,10 +86,7 @@ export default class Address {
updated_at: Date
@Property({ columnType: "timestamptz", nullable: true })
@Index({
name: fulfillmentDeletedAtIndexName,
expression: fulfillmentDeletedAtIndexStatement,
})
@FulfillmentDeletedAtIndex.MikroORMIndex()
deleted_at: Date | null = null
@BeforeCreate()
@@ -9,7 +9,6 @@ import {
BeforeCreate,
Entity,
Filter,
Index,
ManyToOne,
OnInit,
OptionalProps,
@@ -20,37 +19,29 @@ import Fulfillment from "./fulfillment"
type FulfillmentItemOptionalProps = DAL.SoftDeletableEntityDateColumns
const fulfillmentIdIndexName = "IDX_fulfillment_item_fulfillment_id"
const fulfillmentIdIndexStatement = createPsqlIndexStatementHelper({
name: fulfillmentIdIndexName,
const FulfillmentIdIndex = createPsqlIndexStatementHelper({
tableName: "fulfillment_item",
columns: "fulfillment_id",
where: "deleted_at IS NULL",
}).expression
})
const lineItemIndexName = "IDX_fulfillment_item_line_item_id"
const lineItemIdIndexStatement = createPsqlIndexStatementHelper({
name: fulfillmentIdIndexName,
const LineItemIdIndex = createPsqlIndexStatementHelper({
tableName: "fulfillment_item",
columns: "line_item_id",
where: "deleted_at IS NULL",
}).expression
})
const inventoryItemIndexName = "IDX_fulfillment_item_inventory_item_id"
const inventoryItemIdIndexStatement = createPsqlIndexStatementHelper({
name: fulfillmentIdIndexName,
const InventoryItemIdIndex = createPsqlIndexStatementHelper({
tableName: "fulfillment_item",
columns: "inventory_item_id",
where: "deleted_at IS NULL",
}).expression
})
const fulfillmentItemDeletedAtIndexName = "IDX_fulfillment_item_deleted_at"
const fulfillmentItemDeletedAtIndexStatement = createPsqlIndexStatementHelper({
name: fulfillmentItemDeletedAtIndexName,
const FulfillmentItemDeletedAtIndex = createPsqlIndexStatementHelper({
tableName: "fulfillment_item",
columns: "deleted_at",
where: "deleted_at IS NOT NULL",
}).expression
})
@Entity()
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
@@ -73,24 +64,15 @@ export default class FulfillmentItem {
quantity: number // TODO: probably allow big numbers here
@Property({ columnType: "text", nullable: true })
@Index({
name: lineItemIndexName,
expression: lineItemIdIndexStatement,
})
@LineItemIdIndex.MikroORMIndex()
line_item_id: string | null = null
@Property({ columnType: "text", nullable: true })
@Index({
name: inventoryItemIndexName,
expression: inventoryItemIdIndexStatement,
})
@InventoryItemIdIndex.MikroORMIndex()
inventory_item_id: string | null = null
@Property({ columnType: "text" })
@Index({
name: fulfillmentIdIndexName,
expression: fulfillmentIdIndexStatement,
})
@FulfillmentIdIndex.MikroORMIndex()
fulfillment_id: string
@ManyToOne(() => Fulfillment)
@@ -111,10 +93,7 @@ export default class FulfillmentItem {
})
updated_at: Date
@Index({
name: fulfillmentItemDeletedAtIndexName,
expression: fulfillmentItemDeletedAtIndexStatement,
})
@FulfillmentItemDeletedAtIndex.MikroORMIndex()
@Property({ columnType: "timestamptz", nullable: true })
deleted_at: Date | null = null
@@ -9,7 +9,6 @@ import {
BeforeCreate,
Entity,
Filter,
Index,
ManyToOne,
OnInit,
OptionalProps,
@@ -20,21 +19,17 @@ import Fulfillment from "./fulfillment"
type FulfillmentLabelOptionalProps = DAL.SoftDeletableEntityDateColumns
const fulfillmentIdIndexName = "IDX_fulfillment_label_fulfillment_id"
const fulfillmentIdIndexStatement = createPsqlIndexStatementHelper({
name: fulfillmentIdIndexName,
const FulfillmentIdIndex = createPsqlIndexStatementHelper({
tableName: "fulfillment_label",
columns: "fulfillment_id",
where: "deleted_at IS NULL",
}).expression
})
const deletedAtIndexName = "IDX_fulfillment_label_deleted_at"
const deletedAtIndexStatement = createPsqlIndexStatementHelper({
name: deletedAtIndexName,
const DeletedAtIndex = createPsqlIndexStatementHelper({
tableName: "fulfillment_label",
columns: "deleted_at",
where: "deleted_at IS NOT NULL",
}).expression
})
@Entity()
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
@@ -54,10 +49,7 @@ export default class FulfillmentLabel {
label_url: string
@Property({ columnType: "text" })
@Index({
name: fulfillmentIdIndexName,
expression: fulfillmentIdIndexStatement,
})
@FulfillmentIdIndex.MikroORMIndex()
fulfillment_id: string
@ManyToOne(() => Fulfillment)
@@ -79,10 +71,7 @@ export default class FulfillmentLabel {
updated_at: Date
@Property({ columnType: "timestamptz", nullable: true })
@Index({
name: deletedAtIndexName,
expression: deletedAtIndexStatement,
})
@DeletedAtIndex.MikroORMIndex()
deleted_at: Date | null = null
@BeforeCreate()
+15 -38
View File
@@ -10,7 +10,6 @@ import {
Collection,
Entity,
Filter,
Index,
ManyToOne,
OneToMany,
OnInit,
@@ -26,39 +25,29 @@ import ShippingOption from "./shipping-option"
type FulfillmentOptionalProps = DAL.SoftDeletableEntityDateColumns
const fulfillmentDeletedAtIndexName = "IDX_fulfillment_deleted_at"
const fulfillmentDeletedAtIndexStatement = createPsqlIndexStatementHelper({
name: fulfillmentDeletedAtIndexName,
const FulfillmentDeletedAtIndex = createPsqlIndexStatementHelper({
tableName: "fulfillment",
columns: "deleted_at",
where: "deleted_at IS NOT NULL",
}).expression
})
const fulfillmentProviderIdIndexName = "IDX_fulfillment_provider_id"
const fulfillmentProviderIdIndexStatement = createPsqlIndexStatementHelper({
name: fulfillmentProviderIdIndexName,
const FulfillmentProviderIdIndex = createPsqlIndexStatementHelper({
tableName: "fulfillment",
columns: "provider_id",
where: "deleted_at IS NULL",
}).expression
})
const fulfillmentLocationIdIndexName = "IDX_fulfillment_location_id"
const fulfillmentLocationIdIndexStatement = createPsqlIndexStatementHelper({
name: fulfillmentLocationIdIndexName,
const FulfillmentLocationIdIndex = createPsqlIndexStatementHelper({
tableName: "fulfillment",
columns: "location_id",
where: "deleted_at IS NULL",
}).expression
})
const fulfillmentShippingOptionIdIndexName =
"IDX_fulfillment_shipping_option_id"
const fulfillmentShippingOptionIdIndexStatement =
createPsqlIndexStatementHelper({
name: fulfillmentShippingOptionIdIndexName,
tableName: "fulfillment",
columns: "shipping_option_id",
where: "deleted_at IS NULL",
}).expression
const FulfillmentShippingOptionIdIndex = createPsqlIndexStatementHelper({
tableName: "fulfillment",
columns: "shipping_option_id",
where: "deleted_at IS NULL",
})
@Entity()
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
@@ -69,10 +58,7 @@ export default class Fulfillment {
id: string
@Property({ columnType: "text" })
@Index({
name: fulfillmentLocationIdIndexName,
expression: fulfillmentLocationIdIndexStatement,
})
@FulfillmentLocationIdIndex.MikroORMIndex()
location_id: string
@Property({
@@ -103,17 +89,11 @@ export default class Fulfillment {
data: Record<string, unknown> | null = null
@Property({ columnType: "text" })
@Index({
name: fulfillmentProviderIdIndexName,
expression: fulfillmentProviderIdIndexStatement,
})
@FulfillmentProviderIdIndex.MikroORMIndex()
provider_id: string
@Property({ columnType: "text", nullable: true })
@Index({
name: fulfillmentShippingOptionIdIndexName,
expression: fulfillmentShippingOptionIdIndexStatement,
})
@FulfillmentShippingOptionIdIndex.MikroORMIndex()
shipping_option_id: string | null = null
@Property({ columnType: "jsonb", nullable: true })
@@ -149,10 +129,7 @@ export default class Fulfillment {
})
updated_at: Date
@Index({
name: fulfillmentDeletedAtIndexName,
expression: fulfillmentDeletedAtIndexStatement,
})
@FulfillmentDeletedAtIndex.MikroORMIndex()
@Property({ columnType: "timestamptz", nullable: true })
deleted_at: Date | null = null
@@ -11,7 +11,6 @@ import {
Collection,
Entity,
Filter,
Index,
OneToMany,
OnInit,
OptionalProps,
@@ -22,22 +21,18 @@ import ServiceZone from "./service-zone"
type FulfillmentSetOptionalProps = DAL.SoftDeletableEntityDateColumns
const deletedAtIndexName = "IDX_fulfillment_set_deleted_at"
const deletedAtIndexStatement = createPsqlIndexStatementHelper({
name: deletedAtIndexName,
const DeletedAtIndex = createPsqlIndexStatementHelper({
tableName: "fulfillment_set",
columns: "deleted_at",
where: "deleted_at IS NOT NULL",
}).expression
})
const nameIndexName = "IDX_fulfillment_set_name_unique"
const nameIndexStatement = createPsqlIndexStatementHelper({
name: nameIndexName,
const NameIndex = createPsqlIndexStatementHelper({
tableName: "fulfillment_set",
columns: "name",
unique: true,
where: "deleted_at IS NULL",
}).expression
})
@Entity()
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
@@ -48,10 +43,7 @@ export default class FulfillmentSet {
id: string
@Property({ columnType: "text" })
@Index({
name: nameIndexName,
expression: nameIndexStatement,
})
@NameIndex.MikroORMIndex()
name: string
@Property({ columnType: "text" })
@@ -82,10 +74,7 @@ export default class FulfillmentSet {
updated_at: Date
@Property({ columnType: "timestamptz", nullable: true })
@Index({
name: deletedAtIndexName,
expression: deletedAtIndexStatement,
})
@DeletedAtIndex.MikroORMIndex()
deleted_at: Date | null = null
@BeforeCreate()
+15 -41
View File
@@ -11,7 +11,6 @@ import {
Entity,
Enum,
Filter,
Index,
ManyToOne,
OnInit,
OptionalProps,
@@ -22,45 +21,35 @@ import ServiceZone from "./service-zone"
type GeoZoneOptionalProps = DAL.SoftDeletableEntityDateColumns
const deletedAtIndexName = "IDX_geo_zone_deleted_at"
const deletedAtIndexStatement = createPsqlIndexStatementHelper({
name: deletedAtIndexName,
const DeletedAtIndex = createPsqlIndexStatementHelper({
tableName: "geo_zone",
columns: "deleted_at",
where: "deleted_at IS NOT NULL",
}).expression
})
const countryCodeIndexName = "IDX_geo_zone_country_code"
const countryCodeIndexStatement = createPsqlIndexStatementHelper({
name: countryCodeIndexName,
const CountryCodeIndex = createPsqlIndexStatementHelper({
tableName: "geo_zone",
columns: "country_code",
where: "deleted_at IS NULL",
}).expression
})
const provinceCodeIndexName = "IDX_geo_zone_province_code"
const provinceCodeIndexStatement = createPsqlIndexStatementHelper({
name: provinceCodeIndexName,
const ProvinceCodeIndex = createPsqlIndexStatementHelper({
tableName: "geo_zone",
columns: "province_code",
where: "deleted_at IS NULL AND province_code IS NOT NULL",
}).expression
})
const cityIndexName = "IDX_geo_zone_city"
const cityIndexStatement = createPsqlIndexStatementHelper({
name: cityIndexName,
const CityIndex = createPsqlIndexStatementHelper({
tableName: "geo_zone",
columns: "city",
where: "deleted_at IS NULL AND city IS NOT NULL",
}).expression
})
const serviceZoneIdIndexName = "IDX_geo_zone_service_zone_id"
const serviceZoneIdStatement = createPsqlIndexStatementHelper({
name: serviceZoneIdIndexName,
const ServiceZoneIdIndex = createPsqlIndexStatementHelper({
tableName: "geo_zone",
columns: "service_zone_id",
where: "deleted_at IS NULL",
}).expression
})
@Entity()
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
@@ -73,32 +62,20 @@ export default class GeoZone {
@Enum({ items: () => GeoZoneType, default: GeoZoneType.COUNTRY })
type: GeoZoneType
@Index({
name: countryCodeIndexName,
expression: countryCodeIndexStatement,
})
@CountryCodeIndex.MikroORMIndex()
@Property({ columnType: "text" })
country_code: string
@Index({
name: provinceCodeIndexName,
expression: provinceCodeIndexStatement,
})
@ProvinceCodeIndex.MikroORMIndex()
@Property({ columnType: "text", nullable: true })
province_code: string | null = null
@Index({
name: cityIndexName,
expression: cityIndexStatement,
})
@CityIndex.MikroORMIndex()
@Property({ columnType: "text", nullable: true })
city: string | null = null
@Property({ columnType: "text" })
@Index({
name: serviceZoneIdIndexName,
expression: serviceZoneIdStatement,
})
@ServiceZoneIdIndex.MikroORMIndex()
service_zone_id: string
// TODO: Do we have an example or idea of what would be stored in this field? like lat/long for example?
@@ -128,10 +105,7 @@ export default class GeoZone {
})
updated_at: Date
@Index({
name: deletedAtIndexName,
expression: deletedAtIndexStatement,
})
@DeletedAtIndex.MikroORMIndex()
@Property({ columnType: "timestamptz", nullable: true })
deleted_at: Date | null = null
@@ -10,7 +10,6 @@ import {
Collection,
Entity,
Filter,
Index,
OneToMany,
OnInit,
OptionalProps,
@@ -21,13 +20,11 @@ import ShippingOption from "./shipping-option"
type ServiceProviderOptionalProps = DAL.SoftDeletableEntityDateColumns
const deletedAtIndexName = "IDX_service_provider_deleted_at"
const deletedAtIndexStatement = createPsqlIndexStatementHelper({
name: deletedAtIndexName,
const DeletedAtIndex = createPsqlIndexStatementHelper({
tableName: "service_provider",
columns: "deleted_at",
where: "deleted_at IS NOT NULL",
}).expression
})
@Entity()
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
@@ -61,10 +58,7 @@ export default class ServiceProvider {
})
updated_at: Date
@Index({
name: deletedAtIndexName,
expression: deletedAtIndexStatement,
})
@DeletedAtIndex.MikroORMIndex()
@Property({ columnType: "timestamptz", nullable: true })
deleted_at: Date | null = null
@@ -33,22 +33,18 @@ const deletedAtIndexStatement = createPsqlIndexStatementHelper({
where: "deleted_at IS NOT NULL",
}).expression
const nameIndexName = "IDX_service_zone_name_unique"
const nameIndexStatement = createPsqlIndexStatementHelper({
name: nameIndexName,
const NameIndex = createPsqlIndexStatementHelper({
tableName: "service_zone",
columns: "name",
unique: true,
where: "deleted_at IS NULL",
}).expression
})
const fulfillmentSetIdIndexName = "IDX_service_zone_fulfillment_set_id"
const fulfillmentSetIdIndexStatement = createPsqlIndexStatementHelper({
name: fulfillmentSetIdIndexName,
const FulfillmentSetIdIndex = createPsqlIndexStatementHelper({
tableName: "service_zone",
columns: "fulfillment_set_id",
where: "deleted_at IS NULL",
}).expression
})
@Entity()
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
@@ -59,20 +55,14 @@ export default class ServiceZone {
id: string
@Property({ columnType: "text" })
@Index({
name: nameIndexName,
expression: nameIndexStatement,
})
@NameIndex.MikroORMIndex()
name: string
@Property({ columnType: "jsonb", nullable: true })
metadata: Record<string, unknown> | null = null
@Property({ columnType: "text" })
@Index({
name: fulfillmentSetIdIndexName,
expression: fulfillmentSetIdIndexStatement,
})
@FulfillmentSetIdIndex.MikroORMIndex()
fulfillment_set_id: string
@ManyToOne(() => FulfillmentSet, { persist: false })
@@ -9,7 +9,6 @@ import {
BeforeCreate,
Entity,
Filter,
Index,
ManyToOne,
OnInit,
OptionalProps,
@@ -20,16 +19,17 @@ import ShippingOption from "./shipping-option"
type ShippingOptionRuleOptionalProps = DAL.SoftDeletableEntityDateColumns
// TODO: need some test to see if we continue with this kind of structure or we change it
// More adjustments can appear as I move forward
const deletedAtIndexName = "IDX_shipping_option_rule_deleted_at"
const deletedAtIndexStatement = createPsqlIndexStatementHelper({
name: deletedAtIndexName,
const DeletedAtIndex = createPsqlIndexStatementHelper({
tableName: "shipping_option_rule",
columns: "deleted_at",
where: "deleted_at IS NOT NULL",
}).expression
})
const ShippingOptionIdIndex = createPsqlIndexStatementHelper({
tableName: "shipping_option_rule",
columns: "shipping_option_id",
where: "deleted_at IS NULL",
})
@Entity()
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
@@ -49,9 +49,10 @@ export default class ShippingOptionRule {
value: { value: string | string[] } | null = null
@Property({ columnType: "text" })
@ShippingOptionIdIndex.MikroORMIndex()
shipping_option_id: string
@ManyToOne(() => ShippingOption)
@ManyToOne(() => ShippingOption, { persist: false })
shipping_option: ShippingOption
@Property({
@@ -69,20 +70,19 @@ export default class ShippingOptionRule {
})
updated_at: Date
@Index({
name: deletedAtIndexName,
expression: deletedAtIndexStatement,
})
@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
}
}
@@ -9,7 +9,6 @@ import {
BeforeCreate,
Entity,
Filter,
Index,
OneToOne,
OnInit,
OptionalProps,
@@ -20,21 +19,17 @@ import ShippingOption from "./shipping-option"
type ShippingOptionTypeOptionalProps = DAL.SoftDeletableEntityDateColumns
const deletedAtIndexName = "IDX_shipping_option_type_deleted_at"
const deletedAtIndexStatement = createPsqlIndexStatementHelper({
name: deletedAtIndexName,
const DeletedAtIndex = createPsqlIndexStatementHelper({
tableName: "shipping_option_type",
columns: "deleted_at",
where: "deleted_at IS NOT NULL",
}).expression
})
const shippingOptionIdIndexName = "IDX_shipping_option_type_shipping_option_id"
const shippingOptionIdIndexStatement = createPsqlIndexStatementHelper({
name: shippingOptionIdIndexName,
const ShippingOptionIdIndex = createPsqlIndexStatementHelper({
tableName: "shipping_option_type",
columns: "shipping_option_id",
where: "deleted_at IS NULL",
}).expression
})
@Entity()
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
@@ -54,13 +49,12 @@ export default class ShippingOptionType {
code: string
@Property({ columnType: "text" })
@Index({
name: shippingOptionIdIndexName,
expression: shippingOptionIdIndexStatement,
})
@ShippingOptionIdIndex.MikroORMIndex()
shipping_option_id: string
@OneToOne(() => ShippingOption, (so) => so.shipping_option_type)
@OneToOne(() => ShippingOption, (so) => so.type, {
persist: false,
})
shipping_option: ShippingOption
@Property({
@@ -78,20 +72,19 @@ export default class ShippingOptionType {
})
updated_at: Date
@Index({
name: deletedAtIndexName,
expression: deletedAtIndexStatement,
})
@DeletedAtIndex.MikroORMIndex()
@Property({ columnType: "timestamptz", nullable: true })
deleted_at: Date | null = null
@BeforeCreate()
onCreate() {
this.id = generateEntityId(this.id, "sotype")
this.shipping_option_id ??= this.shipping_option?.id
}
@OnInit()
onInit() {
this.id = generateEntityId(this.id, "sotype")
this.shipping_option_id ??= this.shipping_option?.id
}
}
@@ -8,11 +8,11 @@ import {
import { DAL } from "@medusajs/types"
import {
BeforeCreate,
Cascade,
Collection,
Entity,
Enum,
Filter,
Index,
ManyToOne,
OneToMany,
OneToOne,
@@ -30,46 +30,35 @@ import ShippingProfile from "./shipping-profile"
type ShippingOptionOptionalProps = DAL.SoftDeletableEntityDateColumns
const deletedAtIndexName = "IDX_shipping_option_deleted_at"
const deletedAtIndexStatement = createPsqlIndexStatementHelper({
name: deletedAtIndexName,
const DeletedAtIndex = createPsqlIndexStatementHelper({
tableName: "shipping_option",
columns: "deleted_at",
where: "deleted_at IS NOT NULL",
}).expression
})
const serviceZoneIdIndexName = "IDX_shipping_option_service_zone_id"
const serviceZoneIdIndexStatement = createPsqlIndexStatementHelper({
name: serviceZoneIdIndexName,
const ServiceZoneIdIndex = createPsqlIndexStatementHelper({
tableName: "shipping_option",
columns: "service_zone_id",
where: "deleted_at IS NULL",
}).expression
})
const shippingProfileIdIndexName = "IDX_shipping_option_shipping_profile_id"
const shippingProfileIdIndexStatement = createPsqlIndexStatementHelper({
name: shippingProfileIdIndexName,
const ShippingProfileIdIndex = createPsqlIndexStatementHelper({
tableName: "shipping_option",
columns: "shipping_profile_id",
where: "deleted_at IS NULL",
}).expression
})
const serviceProviderIdIndexName = "IDX_shipping_option_service_provider_id"
const serviceProviderIdIndexStatement = createPsqlIndexStatementHelper({
name: serviceProviderIdIndexName,
const ServiceProviderIdIndex = createPsqlIndexStatementHelper({
tableName: "shipping_option",
columns: "service_provider_id",
where: "deleted_at IS NULL",
}).expression
})
const shippingOptionTypeIdIndexName =
"IDX_shipping_option_shipping_option_type_id"
const shippingOptionTypeIdIndexStatement = createPsqlIndexStatementHelper({
name: shippingOptionTypeIdIndexName,
const ShippingOptionTypeIdIndex = createPsqlIndexStatementHelper({
tableName: "shipping_option",
columns: "shipping_option_type_id",
where: "deleted_at IS NULL",
}).expression
})
@Entity()
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
@@ -88,32 +77,34 @@ export default class ShippingOption {
})
price_type: ShippingOptionPriceType
@Property({ columnType: "text" })
@Index({
name: serviceZoneIdIndexName,
expression: serviceZoneIdIndexStatement,
@ManyToOne(() => ShippingProfile, {
type: "text",
fieldName: "service_zone_id",
mapToPk: true,
})
@ServiceZoneIdIndex.MikroORMIndex()
service_zone_id: string
@Property({ columnType: "text" })
@Index({
name: shippingProfileIdIndexName,
expression: shippingProfileIdIndexStatement,
@ManyToOne(() => ShippingProfile, {
type: "text",
fieldName: "shipping_profile_id",
mapToPk: true,
nullable: true,
})
shipping_profile_id: string
@ShippingProfileIdIndex.MikroORMIndex()
shipping_profile_id: string | null
@Property({ columnType: "text" })
@Index({
name: serviceProviderIdIndexName,
expression: serviceProviderIdIndexStatement,
@ManyToOne(() => ServiceProvider, {
type: "text",
fieldName: "service_provider_id",
mapToPk: true,
nullable: true,
})
@ServiceProviderIdIndex.MikroORMIndex()
service_provider_id: string
@Property({ columnType: "text", nullable: true })
@Index({
name: shippingOptionTypeIdIndexName,
expression: shippingOptionTypeIdIndexStatement,
})
@Property({ columnType: "text", persist: false })
@ShippingOptionTypeIdIndex.MikroORMIndex()
shipping_option_type_id: string | null = null
@Property({ columnType: "jsonb", nullable: true })
@@ -122,21 +113,30 @@ export default class ShippingOption {
@Property({ columnType: "jsonb", nullable: true })
metadata: Record<string, unknown> | null = null
@ManyToOne(() => ServiceZone)
@ManyToOne(() => ServiceZone, { persist: false })
service_zone: ServiceZone
@ManyToOne(() => ShippingProfile)
shipping_profile: ShippingProfile
@ManyToOne(() => ShippingProfile, {
persist: false,
})
shipping_profile: ShippingProfile | null
@ManyToOne(() => ServiceProvider)
service_provider: ServiceProvider
@ManyToOne(() => ServiceProvider, {
persist: false,
})
service_provider: ServiceProvider | null
@OneToOne(() => ShippingOptionType, (so) => so.shipping_option, {
owner: true,
cascade: [Cascade.PERSIST, Cascade.REMOVE, "soft-remove"] as any,
fieldName: "shipping_option_type_id",
})
shipping_option_type: ShippingOptionType
type: ShippingOptionType
@OneToMany(() => ShippingOptionRule, (sor) => sor.shipping_option)
@OneToMany(() => ShippingOptionRule, "shipping_option", {
cascade: [Cascade.PERSIST, "soft-remove"] as any,
orphanRemoval: true,
})
rules = new Collection<ShippingOptionRule>(this)
@OneToMany(() => Fulfillment, (fulfillment) => fulfillment.shipping_option)
@@ -157,20 +157,19 @@ export default class ShippingOption {
})
updated_at: Date
@Index({
name: deletedAtIndexName,
expression: deletedAtIndexStatement,
})
@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
}
}
@@ -10,7 +10,6 @@ import {
Collection,
Entity,
Filter,
Index,
OneToMany,
OnInit,
OptionalProps,
@@ -21,13 +20,18 @@ import ShippingOption from "./shipping-option"
type ShippingProfileOptionalProps = DAL.SoftDeletableEntityDateColumns
const deletedAtIndexName = "IDX_shipping_profile_deleted_at"
const deletedAtIndexStatement = createPsqlIndexStatementHelper({
name: deletedAtIndexName,
const DeletedAtIndex = createPsqlIndexStatementHelper({
tableName: "shipping_profile",
columns: "deleted_at",
where: "deleted_at IS NOT NULL",
}).expression
})
const ShippingProfileTypeIndex = createPsqlIndexStatementHelper({
tableName: "shipping_profile",
columns: "name",
unique: true,
where: "deleted_at IS NULL",
})
@Entity()
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
@@ -37,6 +41,13 @@ export default class ShippingProfile {
@PrimaryKey({ columnType: "text" })
id: string
@Property({ columnType: "text" })
@ShippingProfileTypeIndex.MikroORMIndex()
name: string
@Property({ columnType: "text" })
type: string
@OneToMany(
() => ShippingOption,
(shippingOption) => shippingOption.shipping_profile
@@ -61,10 +72,7 @@ export default class ShippingProfile {
})
updated_at: Date
@Index({
name: deletedAtIndexName,
expression: deletedAtIndexStatement,
})
@DeletedAtIndex.MikroORMIndex()
@Property({ columnType: "timestamptz", nullable: true })
deleted_at: Date | null = null
@@ -34,7 +34,7 @@ const connectionLoader = ModulesSdkUtils.mikroOrmConnectionLoaderFactory({
})
const service = FulfillmentModuleService
const loaders = [containerLoader, connectionLoader] as any
const loaders = [containerLoader, connectionLoader]
export const moduleDefinition: ModuleExports = {
service,
@@ -9,31 +9,46 @@ import {
UpdateFulfillmentSetDTO,
} from "@medusajs/types"
import {
getSetDifference,
InjectManager,
InjectTransactionManager,
MedusaContext,
MedusaError,
ModulesSdkUtils,
promiseAll,
getSetDifference
} from "@medusajs/utils"
import { entityNameToLinkableKeysMap, joinerConfig } from "../joiner-config"
import { FulfillmentSet, GeoZone, ServiceZone, ShippingOption } from "@models"
import {
FulfillmentSet,
GeoZone,
ServiceZone,
ShippingOption,
ShippingProfile,
} from "@models"
const generateMethodForModels = [ServiceZone, ShippingOption, GeoZone]
const generateMethodForModels = [
ServiceZone,
ShippingOption,
GeoZone,
ShippingProfile,
]
type InjectedDependencies = {
baseRepository: DAL.RepositoryService
fulfillmentSetService: ModulesSdkTypes.InternalModuleService<any>
serviceZoneService: ModulesSdkTypes.InternalModuleService<any>
geoZoneService: ModulesSdkTypes.InternalModuleService<any>
shippingProfileService: ModulesSdkTypes.InternalModuleService<any>
shippingOptionService: ModulesSdkTypes.InternalModuleService<any>
}
export default class FulfillmentModuleService<
TEntity extends FulfillmentSet = FulfillmentSet,
TServiceZoneEntity extends ServiceZone = ServiceZone,
TGeoZoneEntity extends GeoZone = GeoZone
TGeoZoneEntity extends GeoZone = GeoZone,
TShippingProfileEntity extends ShippingProfile = ShippingProfile,
TShippingOptionEntity extends ShippingOption = ShippingOption
>
extends ModulesSdkUtils.abstractModuleServiceFactory<
InjectedDependencies,
@@ -43,6 +58,7 @@ export default class FulfillmentModuleService<
ServiceZone: { dto: FulfillmentTypes.ServiceZoneDTO }
ShippingOption: { dto: FulfillmentTypes.ShippingOptionDTO }
GeoZone: { dto: FulfillmentTypes.GeoZoneDTO }
ShippingProfile: { dto: FulfillmentTypes.ShippingProfileDTO }
}
>(FulfillmentSet, generateMethodForModels, entityNameToLinkableKeysMap)
implements IFulfillmentModuleService
@@ -51,6 +67,8 @@ export default class FulfillmentModuleService<
protected readonly fulfillmentSetService_: ModulesSdkTypes.InternalModuleService<TEntity>
protected readonly serviceZoneService_: ModulesSdkTypes.InternalModuleService<TServiceZoneEntity>
protected readonly geoZoneService_: ModulesSdkTypes.InternalModuleService<TGeoZoneEntity>
protected readonly shippingProfileService_: ModulesSdkTypes.InternalModuleService<TShippingProfileEntity>
protected readonly shippingOptionService_: ModulesSdkTypes.InternalModuleService<TShippingOptionEntity>
constructor(
{
@@ -58,6 +76,8 @@ export default class FulfillmentModuleService<
fulfillmentSetService,
serviceZoneService,
geoZoneService,
shippingProfileService,
shippingOptionService,
}: InjectedDependencies,
protected readonly moduleDeclaration: InternalModuleDeclaration
) {
@@ -67,6 +87,8 @@ export default class FulfillmentModuleService<
this.fulfillmentSetService_ = fulfillmentSetService
this.serviceZoneService_ = serviceZoneService
this.geoZoneService_ = geoZoneService
this.shippingProfileService_ = shippingProfileService
this.shippingOptionService_ = shippingOptionService
}
__joinerConfig(): ModuleJoinerConfig {
@@ -179,7 +201,7 @@ export default class FulfillmentModuleService<
sharedContext?: Context
): Promise<FulfillmentTypes.ShippingOptionDTO>
@InjectTransactionManager("baseRepository_")
@InjectManager("baseRepository_")
async createShippingOptions(
data:
| FulfillmentTypes.CreateShippingOptionDTO[]
@@ -188,7 +210,93 @@ export default class FulfillmentModuleService<
): Promise<
FulfillmentTypes.ShippingOptionDTO | FulfillmentTypes.ShippingOptionDTO[]
> {
return []
const createdShippingOptions = await this.createShippingOptions_(
data,
sharedContext
)
return await this.baseRepository_.serialize<
FulfillmentTypes.ShippingOptionDTO | FulfillmentTypes.ShippingOptionDTO[]
>(createdShippingOptions, {
populate: true,
})
}
@InjectTransactionManager("baseRepository_")
async createShippingOptions_(
data:
| FulfillmentTypes.CreateShippingOptionDTO[]
| FulfillmentTypes.CreateShippingOptionDTO,
@MedusaContext() sharedContext: Context = {}
): Promise<TShippingOptionEntity | TShippingOptionEntity[]> {
let data_ = Array.isArray(data) ? data : [data]
if (!data_.length) {
return []
}
const createdShippingOptions = await this.shippingOptionService_.create(
data_,
sharedContext
)
return Array.isArray(data)
? createdShippingOptions
: createdShippingOptions[0]
}
createShippingProfiles(
data: FulfillmentTypes.CreateShippingProfileDTO[],
sharedContext?: Context
): Promise<FulfillmentTypes.ShippingProfileDTO[]>
createShippingProfiles(
data: FulfillmentTypes.CreateShippingProfileDTO,
sharedContext?: Context
): Promise<FulfillmentTypes.ShippingProfileDTO>
@InjectTransactionManager("baseRepository_")
async createShippingProfiles(
data:
| FulfillmentTypes.CreateShippingProfileDTO[]
| FulfillmentTypes.CreateShippingProfileDTO,
@MedusaContext() sharedContext: Context = {}
): Promise<
FulfillmentTypes.ShippingProfileDTO | FulfillmentTypes.ShippingProfileDTO[]
> {
const createdShippingProfiles = await this.createShippingProfiles_(
data,
sharedContext
)
return await this.baseRepository_.serialize<
| FulfillmentTypes.ShippingProfileDTO
| FulfillmentTypes.ShippingProfileDTO[]
>(createdShippingProfiles, {
populate: true,
})
}
@InjectTransactionManager("baseRepository_")
async createShippingProfiles_(
data:
| FulfillmentTypes.CreateShippingProfileDTO[]
| FulfillmentTypes.CreateShippingProfileDTO,
@MedusaContext() sharedContext: Context = {}
): Promise<TShippingProfileEntity[] | TShippingProfileEntity> {
const data_ = Array.isArray(data) ? data : [data]
if (!data_.length) {
return []
}
const createdShippingProfiles = await this.shippingProfileService_.create(
data_,
sharedContext
)
return Array.isArray(data)
? createdShippingProfiles
: createdShippingProfiles[0]
}
createGeoZones(
@@ -473,7 +581,6 @@ export default class FulfillmentModuleService<
serviceZones.map((s) => [s.id, s])
)
const serviceZoneIdsToDelete: string[] = []
const geoZoneIdsToDelete: string[] = []
data_.forEach((serviceZone) => {
@@ -567,6 +674,27 @@ export default class FulfillmentModuleService<
return []
}
updateShippingProfiles(
data: FulfillmentTypes.UpdateShippingProfileDTO[],
sharedContext?: Context
): Promise<FulfillmentTypes.ShippingProfileDTO[]>
updateShippingProfiles(
data: FulfillmentTypes.UpdateShippingProfileDTO,
sharedContext?: Context
): Promise<FulfillmentTypes.ShippingProfileDTO>
@InjectTransactionManager("baseRepository_")
async updateShippingProfiles(
data:
| FulfillmentTypes.UpdateShippingProfileDTO
| FulfillmentTypes.UpdateShippingProfileDTO[],
@MedusaContext() sharedContext: Context = {}
): Promise<
FulfillmentTypes.ShippingProfileDTO | FulfillmentTypes.ShippingProfileDTO[]
> {
return []
}
updateGeoZones(
data: FulfillmentTypes.UpdateGeoZoneDTO[],
sharedContext?: Context