From 57a2562bfc335bc5542762253b57e5bc6d0a233b Mon Sep 17 00:00:00 2001 From: Harminder Virk Date: Tue, 12 Nov 2024 14:55:39 +0530 Subject: [PATCH 001/175] feat: convert MikroORM entities to DML entities --- .../product/src/models/product-category.ts | 238 ++++++----- .../product/src/models/product-collection.ts | 117 +++--- .../product/src/models/product-image.ts | 109 ++--- .../src/models/product-option-value.ts | 133 +++--- .../product/src/models/product-option.ts | 140 +++--- .../modules/product/src/models/product-tag.ts | 104 ++--- .../product/src/models/product-type.ts | 100 +++-- .../product/src/models/product-variant.ts | 346 ++++++++------- .../modules/product/src/models/product.ts | 397 ++++++++++-------- .../product/src/services/product-category.ts | 26 +- .../src/services/product-module-service.ts | 78 ++-- 11 files changed, 973 insertions(+), 815 deletions(-) diff --git a/packages/modules/product/src/models/product-category.ts b/packages/modules/product/src/models/product-category.ts index 8f86be88cb737..d29f8a82efdba 100644 --- a/packages/modules/product/src/models/product-category.ts +++ b/packages/modules/product/src/models/product-category.ts @@ -4,6 +4,7 @@ import { createPsqlIndexStatementHelper, generateEntityId, kebabCase, + model, } from "@medusajs/framework/utils" import { BeforeCreate, @@ -22,119 +23,134 @@ import { import Product from "./product" const categoryHandleIndexName = "IDX_category_handle_unique" -const categoryHandleIndexStatement = createPsqlIndexStatementHelper({ - name: categoryHandleIndexName, - tableName: "product_category", - columns: ["handle"], - unique: true, - where: "deleted_at IS NULL", -}) +// const categoryHandleIndexStatement = createPsqlIndexStatementHelper({ +// name: categoryHandleIndexName, +// tableName: "product_category", +// columns: ["handle"], +// unique: true, +// where: "deleted_at IS NULL", +// }) const categoryMpathIndexName = "IDX_product_category_path" -const categoryMpathIndexStatement = createPsqlIndexStatementHelper({ - name: categoryMpathIndexName, - tableName: "product_category", - columns: ["mpath"], - unique: false, - where: "deleted_at IS NULL", -}) - -categoryMpathIndexStatement.MikroORMIndex() -categoryHandleIndexStatement.MikroORMIndex() -@Entity({ tableName: "product_category" }) -@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions) -class ProductCategory { - @PrimaryKey({ columnType: "text" }) - id!: string - - @Searchable() - @Property({ columnType: "text", nullable: false }) - name?: string - - @Searchable() - @Property({ columnType: "text", default: "", nullable: false }) - description?: string - - @Searchable() - @Property({ columnType: "text", nullable: false }) - handle?: string - - @Property({ columnType: "text", nullable: false }) - mpath?: string - - @Property({ columnType: "boolean", default: false }) - is_active?: boolean - - @Property({ columnType: "boolean", default: false }) - is_internal?: boolean - - @Property({ - columnType: "integer", - nullable: false, - default: 0, - }) - rank: number - - @ManyToOne(() => ProductCategory, { - columnType: "text", - fieldName: "parent_category_id", - nullable: true, - mapToPk: true, - onDelete: "cascade", - }) - parent_category_id?: string | null - - @ManyToOne(() => ProductCategory, { nullable: true, persist: false }) - parent_category?: ProductCategory - - @OneToMany({ - entity: () => ProductCategory, - mappedBy: (productCategory) => productCategory.parent_category, - }) - category_children = new Collection(this) - - @Property({ - onCreate: () => new Date(), - columnType: "timestamptz", - defaultRaw: "now()", +// const categoryMpathIndexStatement = createPsqlIndexStatementHelper({ +// name: categoryMpathIndexName, +// tableName: "product_category", +// columns: ["mpath"], +// unique: false, +// where: "deleted_at IS NULL", +// }) + +const ProductCategoryDML = model + .define("ProductCategory", { + id: model.id().primaryKey(), + name: model.text().searchable(), + description: model.text().searchable().default(""), + handle: model.text().searchable(), + mpath: model.text(), + is_active: model.boolean().default(false), + is_internal: model.boolean().default(false), + rank: model.number().default(0), + metadata: model.json().nullable(), + parent_category: model.belongsTo(() => ProductCategoryDML).nullable(), + category_children: model + .belongsTo(() => ProductCategoryDML, { + mappedBy: "parent_category", + }) + .nullable(), + products: model.manyToMany(() => Product), }) - created_at?: Date - - @Property({ - onCreate: () => new Date(), - onUpdate: () => new Date(), - columnType: "timestamptz", - defaultRaw: "now()", - }) - updated_at?: Date - - @Index({ name: "IDX_product_category_deleted_at" }) - @Property({ columnType: "timestamptz", nullable: true }) - deleted_at?: Date - - @Property({ columnType: "jsonb", nullable: true }) - metadata: Record | null = null - - @ManyToMany(() => Product, (product) => product.categories) - products = new Collection(this) - - @OnInit() - async onInit() { - this.id = generateEntityId(this.id, "pcat") - this.parent_category_id ??= this.parent_category?.id ?? null - } - - @BeforeCreate() - async onCreate(args: EventArgs) { - this.id = generateEntityId(this.id, "pcat") - this.parent_category_id ??= this.parent_category?.id ?? null - - if (!this.handle && this.name) { - this.handle = kebabCase(this.name) - } - - this.mpath = `${this.mpath ? this.mpath + "." : ""}${this.id}` - } + .indexes([ + { + name: categoryMpathIndexName, + on: ["mpath"], + unique: false, + where: "deleted_at IS NULL", + }, + { + name: categoryHandleIndexName, + on: ["handle"], + unique: true, + where: "deleted_at IS NULL", + }, + ]) + +// categoryMpathIndexStatement.MikroORMIndex() +// categoryHandleIndexStatement.MikroORMIndex() +// @Entity({ tableName: "product_category" }) +// @Filter(DALUtils.mikroOrmSoftDeletableFilterOptions) +class ProductCategory { + // @PrimaryKey({ columnType: "text" }) + // id!: string + // @Searchable() + // @Property({ columnType: "text", nullable: false }) + // name?: string + // @Searchable() + // @Property({ columnType: "text", default: "", nullable: false }) + // description?: string + // @Searchable() + // @Property({ columnType: "text", nullable: false }) + // handle?: string + // @Property({ columnType: "text", nullable: false }) + // mpath?: string + // @Property({ columnType: "boolean", default: false }) + // is_active?: boolean + // @Property({ columnType: "boolean", default: false }) + // is_internal?: boolean + // @Property({ + // columnType: "integer", + // nullable: false, + // default: 0, + // }) + // rank: number + // @ManyToOne(() => ProductCategory, { + // columnType: "text", + // fieldName: "parent_category_id", + // nullable: true, + // mapToPk: true, + // onDelete: "cascade", + // }) + // parent_category_id?: string | null + // @ManyToOne(() => ProductCategory, { nullable: true, persist: false }) + // parent_category?: ProductCategory + // @OneToMany({ + // entity: () => ProductCategory, + // mappedBy: (productCategory) => productCategory.parent_category, + // }) + // category_children = new Collection(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: "IDX_product_category_deleted_at" }) + // @Property({ columnType: "timestamptz", nullable: true }) + // deleted_at?: Date + // @Property({ columnType: "jsonb", nullable: true }) + // metadata: Record | null = null + // @ManyToMany(() => Product, (product) => product.categories) + // products = new Collection(this) + // @OnInit() + // async onInit() { + // this.id = generateEntityId(this.id, "pcat") + // this.parent_category_id ??= this.parent_category?.id ?? null + // } + // @BeforeCreate() + // async onCreate(args: EventArgs) { + // this.id = generateEntityId(this.id, "pcat") + // this.parent_category_id ??= this.parent_category?.id ?? null + // if (!this.handle && this.name) { + // this.handle = kebabCase(this.name) + // } + // this.mpath = `${this.mpath ? this.mpath + "." : ""}${this.id}` + // } } -export default ProductCategory +export default ProductCategoryDML diff --git a/packages/modules/product/src/models/product-collection.ts b/packages/modules/product/src/models/product-collection.ts index 87f44b353b04e..84ab985d6b1c9 100644 --- a/packages/modules/product/src/models/product-collection.ts +++ b/packages/modules/product/src/models/product-collection.ts @@ -15,67 +15,76 @@ import { DALUtils, generateEntityId, kebabCase, + model, Searchable, } from "@medusajs/framework/utils" import Product from "./product" const collectionHandleIndexName = "IDX_collection_handle_unique" -const collectionHandleIndexStatement = createPsqlIndexStatementHelper({ - name: collectionHandleIndexName, - tableName: "product_collection", - columns: ["handle"], - unique: true, - where: "deleted_at IS NULL", -}) +// const collectionHandleIndexStatement = createPsqlIndexStatementHelper({ +// name: collectionHandleIndexName, +// tableName: "product_collection", +// columns: ["handle"], +// unique: true, +// where: "deleted_at IS NULL", +// }) -collectionHandleIndexStatement.MikroORMIndex() -@Entity({ tableName: "product_collection" }) -@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions) -class ProductCollection { - @PrimaryKey({ columnType: "text" }) - id!: string - - @Searchable() - @Property({ columnType: "text" }) - title: string - - @Property({ columnType: "text" }) - handle?: string - - @OneToMany(() => Product, (product) => product.collection) - products = new Collection(this) - - @Property({ columnType: "jsonb", nullable: true }) - metadata?: Record | null - - @Property({ - onCreate: () => new Date(), - columnType: "timestamptz", - defaultRaw: "now()", +const ProductCollectionDML = model + .define("ProductCollection", { + id: model.id().primaryKey(), + title: model.text().searchable(), + handle: model.text().nullable(), + metadata: model.json().nullable(), + products: model.hasMany(() => Product), }) - created_at: Date + .indexes([ + { + name: collectionHandleIndexName, + on: ["handle"], + unique: true, + where: "deleted_at IS NULL", + }, + ]) - @Property({ - onCreate: () => new Date(), - onUpdate: () => new Date(), - columnType: "timestamptz", - defaultRaw: "now()", - }) - updated_at: Date - - @Index({ name: "IDX_product_collection_deleted_at" }) - @Property({ columnType: "timestamptz", nullable: true }) - deleted_at?: Date - - @OnInit() - @BeforeCreate() - onInit() { - this.id = generateEntityId(this.id, "pcol") - - if (!this.handle && this.title) { - this.handle = kebabCase(this.title) - } - } +// collectionHandleIndexStatement.MikroORMIndex() +// @Entity({ tableName: "product_collection" }) +// @Filter(DALUtils.mikroOrmSoftDeletableFilterOptions) +class ProductCollection { + // @PrimaryKey({ columnType: "text" }) + // id!: string + // @Searchable() + // @Property({ columnType: "text" }) + // title: string + // @Property({ columnType: "text" }) + // handle?: string + // @OneToMany(() => Product, (product) => product.collection) + // products = new Collection(this) + // @Property({ columnType: "jsonb", nullable: true }) + // metadata?: Record | 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 + // @Index({ name: "IDX_product_collection_deleted_at" }) + // @Property({ columnType: "timestamptz", nullable: true }) + // deleted_at?: Date + // @OnInit() + // @BeforeCreate() + // onInit() { + // this.id = generateEntityId(this.id, "pcol") + // if (!this.handle && this.title) { + // this.handle = kebabCase(this.title) + // } + // } } -export default ProductCollection +export default ProductCollectionDML diff --git a/packages/modules/product/src/models/product-image.ts b/packages/modules/product/src/models/product-image.ts index 5c0baf2445b85..47bf2af24c6d3 100644 --- a/packages/modules/product/src/models/product-image.ts +++ b/packages/modules/product/src/models/product-image.ts @@ -14,62 +14,71 @@ import { DALUtils, createPsqlIndexStatementHelper, generateEntityId, + model, } from "@medusajs/framework/utils" import Product from "./product" const imageUrlIndexName = "IDX_product_image_url" -const imageUrlIndexStatement = createPsqlIndexStatementHelper({ - name: imageUrlIndexName, - tableName: "image", - columns: ["url"], - unique: false, - where: "deleted_at IS NULL", -}) +// const imageUrlIndexStatement = createPsqlIndexStatementHelper({ +// name: imageUrlIndexName, +// tableName: "image", +// columns: ["url"], +// unique: false, +// where: "deleted_at IS NULL", +// }) -imageUrlIndexStatement.MikroORMIndex() -@Entity({ tableName: "image" }) -@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions) -class ProductImage { - @PrimaryKey({ columnType: "text" }) - id!: string - - @Property({ columnType: "text" }) - url: string - - @Property({ columnType: "jsonb", nullable: true }) - metadata?: Record | null - - @Property({ - onCreate: () => new Date(), - columnType: "timestamptz", - defaultRaw: "now()", - }) - created_at: Date - - @Property({ - onCreate: () => new Date(), - onUpdate: () => new Date(), - columnType: "timestamptz", - defaultRaw: "now()", +const ProductImageDML = model + .define("ProductImage", { + id: model.id().primaryKey(), + url: model.text(), + metadata: model.json().nullable(), + products: model.manyToMany(() => Product), }) - updated_at: Date - - @Index({ name: "IDX_product_image_deleted_at" }) - @Property({ columnType: "timestamptz", nullable: true }) - deleted_at?: Date - - @ManyToMany(() => Product, (product) => product.images) - products = new Collection(this) + .indexes([ + { + name: imageUrlIndexName, + on: ["url"], + unique: false, + where: "deleted_at IS NULL", + }, + ]) - @OnInit() - onInit() { - this.id = generateEntityId(this.id, "img") - } - - @BeforeCreate() - onCreate() { - this.id = generateEntityId(this.id, "img") - } +// imageUrlIndexStatement.MikroORMIndex() +// @Entity({ tableName: "image" }) +// @Filter(DALUtils.mikroOrmSoftDeletableFilterOptions) +class ProductImage { + // @PrimaryKey({ columnType: "text" }) + // id!: string + // @Property({ columnType: "text" }) + // url: string + // @Property({ columnType: "jsonb", nullable: true }) + // metadata?: Record | 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 + // @Index({ name: "IDX_product_image_deleted_at" }) + // @Property({ columnType: "timestamptz", nullable: true }) + // deleted_at?: Date + // @ManyToMany(() => Product, (product) => product.images) + // products = new Collection(this) + // @OnInit() + // onInit() { + // this.id = generateEntityId(this.id, "img") + // } + // @BeforeCreate() + // onCreate() { + // this.id = generateEntityId(this.id, "img") + // } } -export default ProductImage +export default ProductImageDML diff --git a/packages/modules/product/src/models/product-option-value.ts b/packages/modules/product/src/models/product-option-value.ts index a3f0486f5f01c..c9e548ed15a99 100644 --- a/packages/modules/product/src/models/product-option-value.ts +++ b/packages/modules/product/src/models/product-option-value.ts @@ -2,6 +2,7 @@ import { DALUtils, createPsqlIndexStatementHelper, generateEntityId, + model, } from "@medusajs/framework/utils" import { BeforeCreate, @@ -18,70 +19,78 @@ import { import { ProductOption, ProductVariant } from "./index" const optionValueOptionIdIndexName = "IDX_option_value_option_id_unique" -const optionValueOptionIdIndexStatement = createPsqlIndexStatementHelper({ - name: optionValueOptionIdIndexName, - tableName: "product_option_value", - columns: ["option_id", "value"], - unique: true, - where: "deleted_at IS NULL", -}) +// const optionValueOptionIdIndexStatement = createPsqlIndexStatementHelper({ +// name: optionValueOptionIdIndexName, +// tableName: "product_option_value", +// columns: ["option_id", "value"], +// unique: true, +// where: "deleted_at IS NULL", +// }) -optionValueOptionIdIndexStatement.MikroORMIndex() -@Entity({ tableName: "product_option_value" }) -@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions) -class ProductOptionValue { - @PrimaryKey({ columnType: "text" }) - id!: string - - @Property({ columnType: "text" }) - value: string - - @ManyToOne(() => ProductOption, { - columnType: "text", - fieldName: "option_id", - mapToPk: true, - nullable: true, - onDelete: "cascade", +const ProductOptionValueDML = model + .define("ProductOptionValue", { + id: model.id().primaryKey(), + value: model.text(), + metadata: model.json().nullable(), + option: model.belongsTo(() => ProductOption).nullable(), + variants: model.manyToMany(() => ProductVariant), }) - option_id: string | null - - @ManyToOne(() => ProductOption, { - nullable: true, - persist: false, - }) - option: ProductOption | null - - @ManyToMany(() => ProductVariant, (variant) => variant.options) - variants = new Collection(this) - - @Property({ columnType: "jsonb", nullable: true }) - metadata?: Record | null + .indexes([ + { + name: optionValueOptionIdIndexName, + on: ["option_id", "value"], + unique: true, + where: "deleted_at IS 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 - - @Index({ name: "IDX_product_option_value_deleted_at" }) - @Property({ columnType: "timestamptz", nullable: true }) - deleted_at?: Date - - @OnInit() - @BeforeCreate() - onInit() { - this.id = generateEntityId(this.id, "optval") - this.option_id ??= this.option?.id ?? null - } +// optionValueOptionIdIndexStatement.MikroORMIndex() +// @Entity({ tableName: "product_option_value" }) +// @Filter(DALUtils.mikroOrmSoftDeletableFilterOptions) +class ProductOptionValue { + // @PrimaryKey({ columnType: "text" }) + // id!: string + // @Property({ columnType: "text" }) + // value: string + // @ManyToOne(() => ProductOption, { + // columnType: "text", + // fieldName: "option_id", + // mapToPk: true, + // nullable: true, + // onDelete: "cascade", + // }) + // option_id: string | null + // @ManyToOne(() => ProductOption, { + // nullable: true, + // persist: false, + // }) + // option: ProductOption | null + // @ManyToMany(() => ProductVariant, (variant) => variant.options) + // variants = new Collection(this) + // @Property({ columnType: "jsonb", nullable: true }) + // metadata?: Record | 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 + // @Index({ name: "IDX_product_option_value_deleted_at" }) + // @Property({ columnType: "timestamptz", nullable: true }) + // deleted_at?: Date + // @OnInit() + // @BeforeCreate() + // onInit() { + // this.id = generateEntityId(this.id, "optval") + // this.option_id ??= this.option?.id ?? null + // } } -export default ProductOptionValue +export default ProductOptionValueDML diff --git a/packages/modules/product/src/models/product-option.ts b/packages/modules/product/src/models/product-option.ts index d75b3bd73f58a..58343e5e4dad7 100644 --- a/packages/modules/product/src/models/product-option.ts +++ b/packages/modules/product/src/models/product-option.ts @@ -3,6 +3,7 @@ import { Searchable, createPsqlIndexStatementHelper, generateEntityId, + model, } from "@medusajs/framework/utils" import { BeforeCreate, @@ -21,73 +22,84 @@ import { Product } from "./index" import ProductOptionValue from "./product-option-value" const optionProductIdTitleIndexName = "IDX_option_product_id_title_unique" -const optionProductIdTitleIndexStatement = createPsqlIndexStatementHelper({ - name: optionProductIdTitleIndexName, - tableName: "product_option", - columns: ["product_id", "title"], - unique: true, - where: "deleted_at IS NULL", -}) +// const optionProductIdTitleIndexStatement = createPsqlIndexStatementHelper({ +// name: optionProductIdTitleIndexName, +// tableName: "product_option", +// columns: ["product_id", "title"], +// unique: true, +// where: "deleted_at IS NULL", +// }) -optionProductIdTitleIndexStatement.MikroORMIndex() -@Entity({ tableName: "product_option" }) -@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions) -class ProductOption { - @PrimaryKey({ columnType: "text" }) - id!: string - - @Searchable() - @Property({ columnType: "text" }) - title: string - - @ManyToOne(() => Product, { - columnType: "text", - fieldName: "product_id", - mapToPk: true, - nullable: true, - onDelete: "cascade", +const ProductOptionDML = model + .define("ProductOption", { + id: model.id().primaryKey(), + title: model.text().searchable(), + metadata: model.json().nullable(), + product: model.belongsTo(() => Product), + values: model.hasMany(() => ProductOptionValue), }) - product_id: string | null - - @ManyToOne(() => Product, { - persist: false, - nullable: true, + .cascades({ + delete: ["values"], }) - product: Product | null - - @OneToMany(() => ProductOptionValue, (value) => value.option, { - cascade: [Cascade.PERSIST, "soft-remove" as any], - }) - values = new Collection(this) - - @Property({ columnType: "jsonb", nullable: true }) - metadata?: Record | null + .indexes([ + { + name: optionProductIdTitleIndexName, + on: ["product_id", "title"], + unique: true, + where: "deleted_at IS 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 - - @Index({ name: "IDX_product_option_deleted_at" }) - @Property({ columnType: "timestamptz", nullable: true }) - deleted_at?: Date - - @OnInit() - @BeforeCreate() - onInit() { - this.id = generateEntityId(this.id, "opt") - this.product_id ??= this.product?.id ?? null - } +// optionProductIdTitleIndexStatement.MikroORMIndex() +// @Entity({ tableName: "product_option" }) +// @Filter(DALUtils.mikroOrmSoftDeletableFilterOptions) +class ProductOption { + // @PrimaryKey({ columnType: "text" }) + // id!: string + // @Searchable() + // @Property({ columnType: "text" }) + // title: string + // @ManyToOne(() => Product, { + // columnType: "text", + // fieldName: "product_id", + // mapToPk: true, + // nullable: true, + // onDelete: "cascade", + // }) + // product_id: string | null + // @ManyToOne(() => Product, { + // persist: false, + // nullable: true, + // }) + // product: Product | null + // @OneToMany(() => ProductOptionValue, (value) => value.option, { + // cascade: [Cascade.PERSIST, "soft-remove" as any], + // }) + // values = new Collection(this) + // @Property({ columnType: "jsonb", nullable: true }) + // metadata?: Record | 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 + // @Index({ name: "IDX_product_option_deleted_at" }) + // @Property({ columnType: "timestamptz", nullable: true }) + // deleted_at?: Date + // @OnInit() + // @BeforeCreate() + // onInit() { + // this.id = generateEntityId(this.id, "opt") + // this.product_id ??= this.product?.id ?? null + // } } -export default ProductOption +export default ProductOptionDML diff --git a/packages/modules/product/src/models/product-tag.ts b/packages/modules/product/src/models/product-tag.ts index 7f1313d3d1571..c03b15108c257 100644 --- a/packages/modules/product/src/models/product-tag.ts +++ b/packages/modules/product/src/models/product-tag.ts @@ -15,59 +15,69 @@ import { Searchable, createPsqlIndexStatementHelper, generateEntityId, + model, } from "@medusajs/framework/utils" import Product from "./product" const tagValueIndexName = "IDX_tag_value_unique" -const tagValueIndexStatement = createPsqlIndexStatementHelper({ - name: tagValueIndexName, - tableName: "product_tag", - columns: ["value"], - unique: true, - where: "deleted_at IS NULL", -}) +// const tagValueIndexStatement = createPsqlIndexStatementHelper({ +// name: tagValueIndexName, +// tableName: "product_tag", +// columns: ["value"], +// unique: true, +// where: "deleted_at IS NULL", +// }) -tagValueIndexStatement.MikroORMIndex() -@Entity({ tableName: "product_tag" }) -@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions) -class ProductTag { - @PrimaryKey({ columnType: "text" }) - id!: string - - @Searchable() - @Property({ columnType: "text" }) - value: string - - @Property({ columnType: "jsonb", nullable: true }) - metadata?: Record | null - - @Property({ - onCreate: () => new Date(), - columnType: "timestamptz", - defaultRaw: "now()", +const ProductTagDML = model + .define("ProductTag", { + id: model.id().primaryKey(), + value: model.text().searchable(), + metadata: model.json().nullable(), + product: model.manyToMany(() => Product), }) - created_at: Date + .indexes([ + { + name: tagValueIndexName, + on: ["value"], + unique: true, + where: "deleted_at IS NULL", + }, + ]) - @Property({ - onCreate: () => new Date(), - onUpdate: () => new Date(), - columnType: "timestamptz", - defaultRaw: "now()", - }) - updated_at: Date - - @Index({ name: "IDX_product_tag_deleted_at" }) - @Property({ columnType: "timestamptz", nullable: true }) - deleted_at?: Date - - @ManyToMany(() => Product, (product) => product.tags) - products = new Collection(this) - - @OnInit() - @BeforeCreate() - onInit() { - this.id = generateEntityId(this.id, "ptag") - } +// tagValueIndexStatement.MikroORMIndex() +// @Entity({ tableName: "product_tag" }) +// @Filter(DALUtils.mikroOrmSoftDeletableFilterOptions) +class ProductTag { + // @PrimaryKey({ columnType: "text" }) + // id!: string + // @Searchable() + // @Property({ columnType: "text" }) + // value: string + // @Property({ columnType: "jsonb", nullable: true }) + // metadata?: Record | 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 + // @Index({ name: "IDX_product_tag_deleted_at" }) + // @Property({ columnType: "timestamptz", nullable: true }) + // deleted_at?: Date + // @ManyToMany(() => Product, (product) => product.tags) + // products = new Collection(this) + // @OnInit() + // @BeforeCreate() + // onInit() { + // this.id = generateEntityId(this.id, "ptag") + // } } -export default ProductTag +export default ProductTagDML diff --git a/packages/modules/product/src/models/product-type.ts b/packages/modules/product/src/models/product-type.ts index 2fd981c2e857e..cc22070813a4a 100644 --- a/packages/modules/product/src/models/product-type.ts +++ b/packages/modules/product/src/models/product-type.ts @@ -13,55 +13,67 @@ import { Searchable, createPsqlIndexStatementHelper, generateEntityId, + model, } from "@medusajs/framework/utils" +import { Product } from "@models" const typeValueIndexName = "IDX_type_value_unique" -const typeValueIndexStatement = createPsqlIndexStatementHelper({ - name: typeValueIndexName, - tableName: "product_type", - columns: ["value"], - unique: true, - where: "deleted_at IS NULL", -}) +// const typeValueIndexStatement = createPsqlIndexStatementHelper({ +// name: typeValueIndexName, +// tableName: "product_type", +// columns: ["value"], +// unique: true, +// where: "deleted_at IS NULL", +// }) -typeValueIndexStatement.MikroORMIndex() -@Entity({ tableName: "product_type" }) -@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions) -class ProductType { - @PrimaryKey({ columnType: "text" }) - id!: string - - @Searchable() - @Property({ columnType: "text" }) - value: string - - @Property({ columnType: "json", nullable: true }) - metadata?: Record | null - - @Property({ - onCreate: () => new Date(), - columnType: "timestamptz", - defaultRaw: "now()", +const ProductTypeDML = model + .define("ProductType", { + id: model.id().primaryKey(), + value: model.text().searchable(), + metadata: model.json().nullable(), + product: model.hasMany(() => Product), }) - created_at: Date + .indexes([ + { + name: typeValueIndexName, + on: ["value"], + unique: true, + where: "deleted_at IS NULL", + }, + ]) - @Property({ - onCreate: () => new Date(), - onUpdate: () => new Date(), - columnType: "timestamptz", - defaultRaw: "now()", - }) - updated_at: Date - - @Index({ name: "IDX_product_type_deleted_at" }) - @Property({ columnType: "timestamptz", nullable: true }) - deleted_at?: Date - - @OnInit() - @BeforeCreate() - onInit() { - this.id = generateEntityId(this.id, "ptyp") - } +// typeValueIndexStatement.MikroORMIndex() +// @Entity({ tableName: "product_type" }) +// @Filter(DALUtils.mikroOrmSoftDeletableFilterOptions) +class ProductType { + // @PrimaryKey({ columnType: "text" }) + // id!: string + // @Searchable() + // @Property({ columnType: "text" }) + // value: string + // @Property({ columnType: "json", nullable: true }) + // metadata?: Record | 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 + // @Index({ name: "IDX_product_type_deleted_at" }) + // @Property({ columnType: "timestamptz", nullable: true }) + // deleted_at?: Date + // @OnInit() + // @BeforeCreate() + // onInit() { + // this.id = generateEntityId(this.id, "ptyp") + // } } -export default ProductType +export default ProductTypeDML diff --git a/packages/modules/product/src/models/product-variant.ts b/packages/modules/product/src/models/product-variant.ts index c52640afc2d42..3408995c474f7 100644 --- a/packages/modules/product/src/models/product-variant.ts +++ b/packages/modules/product/src/models/product-variant.ts @@ -2,6 +2,7 @@ import { createPsqlIndexStatementHelper, DALUtils, generateEntityId, + model, Searchable, } from "@medusajs/framework/utils" import { @@ -19,169 +20,204 @@ import { import { Product, ProductOptionValue } from "@models" const variantSkuIndexName = "IDX_product_variant_sku_unique" -const variantSkuIndexStatement = createPsqlIndexStatementHelper({ - name: variantSkuIndexName, - tableName: "product_variant", - columns: ["sku"], - unique: true, - where: "deleted_at IS NULL", -}) +// const variantSkuIndexStatement = createPsqlIndexStatementHelper({ +// name: variantSkuIndexName, +// tableName: "product_variant", +// columns: ["sku"], +// unique: true, +// where: "deleted_at IS NULL", +// }) const variantBarcodeIndexName = "IDX_product_variant_barcode_unique" -const variantBarcodeIndexStatement = createPsqlIndexStatementHelper({ - name: variantBarcodeIndexName, - tableName: "product_variant", - columns: ["barcode"], - unique: true, - where: "deleted_at IS NULL", -}) +// const variantBarcodeIndexStatement = createPsqlIndexStatementHelper({ +// name: variantBarcodeIndexName, +// tableName: "product_variant", +// columns: ["barcode"], +// unique: true, +// where: "deleted_at IS NULL", +// }) const variantEanIndexName = "IDX_product_variant_ean_unique" -const variantEanIndexStatement = createPsqlIndexStatementHelper({ - name: variantEanIndexName, - tableName: "product_variant", - columns: ["ean"], - unique: true, - where: "deleted_at IS NULL", -}) +// const variantEanIndexStatement = createPsqlIndexStatementHelper({ +// name: variantEanIndexName, +// tableName: "product_variant", +// columns: ["ean"], +// unique: true, +// where: "deleted_at IS NULL", +// }) const variantUpcIndexName = "IDX_product_variant_upc_unique" -const variantUpcIndexStatement = createPsqlIndexStatementHelper({ - name: variantUpcIndexName, - tableName: "product_variant", - columns: ["upc"], - unique: true, - where: "deleted_at IS NULL", -}) +// const variantUpcIndexStatement = createPsqlIndexStatementHelper({ +// name: variantUpcIndexName, +// tableName: "product_variant", +// columns: ["upc"], +// unique: true, +// where: "deleted_at IS NULL", +// }) const variantProductIdIndexName = "IDX_product_variant_product_id" -const variantProductIdIndexStatement = createPsqlIndexStatementHelper({ - name: variantProductIdIndexName, - tableName: "product_variant", - columns: ["product_id"], - unique: false, - where: "deleted_at IS NULL", -}) - -variantProductIdIndexStatement.MikroORMIndex() -variantSkuIndexStatement.MikroORMIndex() -variantBarcodeIndexStatement.MikroORMIndex() -variantEanIndexStatement.MikroORMIndex() -variantUpcIndexStatement.MikroORMIndex() -@Entity({ tableName: "product_variant" }) -@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions) -class ProductVariant { - @PrimaryKey({ columnType: "text" }) - id!: string - - @Searchable() - @Property({ columnType: "text" }) - title: string - - @Searchable() - @Property({ columnType: "text", nullable: true }) - sku?: string | null - - @Searchable() - @Property({ columnType: "text", nullable: true }) - barcode?: string | null - - @Searchable() - @Property({ columnType: "text", nullable: true }) - ean?: string | null - - @Searchable() - @Property({ columnType: "text", nullable: true }) - upc?: string | null - - @Property({ columnType: "boolean", default: false }) - allow_backorder?: boolean = false - - @Property({ columnType: "boolean", default: true }) - manage_inventory?: boolean = true - - @Property({ columnType: "text", nullable: true }) - hs_code?: string | null - - @Property({ columnType: "text", nullable: true }) - origin_country?: string | null - - @Property({ columnType: "text", nullable: true }) - mid_code?: string | null - - @Property({ columnType: "text", nullable: true }) - material?: string | null - - @Property({ columnType: "numeric", nullable: true }) - weight?: number | null - - @Property({ columnType: "numeric", nullable: true }) - length?: number | null - - @Property({ columnType: "numeric", nullable: true }) - height?: number | null - - @Property({ columnType: "numeric", nullable: true }) - width?: number | null - - @Property({ columnType: "jsonb", nullable: true }) - metadata?: Record | null - - @Property({ - columnType: "integer", - nullable: true, - default: 0, - }) - variant_rank?: number | null - - @ManyToOne(() => Product, { - columnType: "text", - nullable: true, - onDelete: "cascade", - fieldName: "product_id", - mapToPk: true, - }) - product_id: string | null - - @ManyToOne(() => Product, { - persist: false, - nullable: true, - }) - product: Product | null - - @ManyToMany(() => ProductOptionValue, "variants", { - owner: true, - pivotTable: "product_variant_option", - joinColumn: "variant_id", - inverseJoinColumn: "option_value_id", - }) - options = new Collection(this) - - @Property({ - onCreate: () => new Date(), - columnType: "timestamptz", - defaultRaw: "now()", - }) - created_at: Date - - @Property({ - onCreate: () => new Date(), - onUpdate: () => new Date(), - columnType: "timestamptz", - defaultRaw: "now()", +// const variantProductIdIndexStatement = createPsqlIndexStatementHelper({ +// name: variantProductIdIndexName, +// tableName: "product_variant", +// columns: ["product_id"], +// unique: false, +// where: "deleted_at IS NULL", +// }) + +const ProductVariantDML = model + .define("ProductVariant", { + id: model.id().primaryKey(), + title: model.text().searchable(), + sku: model.text().searchable().nullable(), + barcode: model.text().searchable().nullable(), + ean: model.text().searchable().nullable(), + upc: model.text().searchable().nullable(), + allow_backorder: model.boolean().default(false), + manage_inventory: model.boolean().default(false), + hs_code: model.text().nullable(), + origin_country: model.text().nullable(), + mid_code: model.text().nullable(), + material: model.text().nullable(), + weight: model.number().nullable(), + length: model.number().nullable(), + height: model.number().nullable(), + width: model.number().nullable(), + metadata: model.json().nullable(), + variant_rank: model.number().default(0).nullable(), + product: model.belongsTo(() => Product).nullable(), + options: model.manyToMany(() => ProductOptionValue, { + pivotTable: "product_variant_option", + }), }) - updated_at: Date - - @Index({ name: "IDX_product_variant_deleted_at" }) - @Property({ columnType: "timestamptz", nullable: true }) - deleted_at?: Date - - @OnInit() - @BeforeCreate() - onInit() { - this.id = generateEntityId(this.id, "variant") - this.product_id ??= this.product?.id ?? null - } + .indexes([ + { + name: variantProductIdIndexName, + on: ["product_id"], + unique: false, + where: "deleted_at IS NULL", + }, + { + name: variantSkuIndexName, + on: ["sku"], + unique: true, + where: "deleted_at IS NULL", + }, + { + name: variantBarcodeIndexName, + on: ["barcode"], + unique: true, + where: "deleted_at IS NULL", + }, + { + name: variantEanIndexName, + on: ["ean"], + unique: true, + where: "deleted_at IS NULL", + }, + { + name: variantUpcIndexName, + on: ["upc"], + unique: true, + where: "deleted_at IS NULL", + }, + ]) + +// variantProductIdIndexStatement.MikroORMIndex() +// variantSkuIndexStatement.MikroORMIndex() +// variantBarcodeIndexStatement.MikroORMIndex() +// variantEanIndexStatement.MikroORMIndex() +// variantUpcIndexStatement.MikroORMIndex() +// @Entity({ tableName: "product_variant" }) +// @Filter(DALUtils.mikroOrmSoftDeletableFilterOptions) +class ProductVariant { + // @PrimaryKey({ columnType: "text" }) + // id!: string + // @Searchable() + // @Property({ columnType: "text" }) + // title: string + // @Searchable() + // @Property({ columnType: "text", nullable: true }) + // sku?: string | null + // @Searchable() + // @Property({ columnType: "text", nullable: true }) + // barcode?: string | null + // @Searchable() + // @Property({ columnType: "text", nullable: true }) + // ean?: string | null + // @Searchable() + // @Property({ columnType: "text", nullable: true }) + // upc?: string | null + // @Property({ columnType: "boolean", default: false }) + // allow_backorder?: boolean = false + // @Property({ columnType: "boolean", default: true }) + // manage_inventory?: boolean = true + // @Property({ columnType: "text", nullable: true }) + // hs_code?: string | null + // @Property({ columnType: "text", nullable: true }) + // origin_country?: string | null + // @Property({ columnType: "text", nullable: true }) + // mid_code?: string | null + // @Property({ columnType: "text", nullable: true }) + // material?: string | null + // @Property({ columnType: "numeric", nullable: true }) + // weight?: number | null + // @Property({ columnType: "numeric", nullable: true }) + // length?: number | null + // @Property({ columnType: "numeric", nullable: true }) + // height?: number | null + // @Property({ columnType: "numeric", nullable: true }) + // width?: number | null + // @Property({ columnType: "jsonb", nullable: true }) + // metadata?: Record | null + // @Property({ + // columnType: "integer", + // nullable: true, + // default: 0, + // }) + // variant_rank?: number | null + // @ManyToOne(() => Product, { + // columnType: "text", + // nullable: true, + // onDelete: "cascade", + // fieldName: "product_id", + // mapToPk: true, + // }) + // product_id: string | null + // @ManyToOne(() => Product, { + // persist: false, + // nullable: true, + // }) + // product: Product | null + // @ManyToMany(() => ProductOptionValue, "variants", { + // owner: true, + // pivotTable: "product_variant_option", + // joinColumn: "variant_id", + // inverseJoinColumn: "option_value_id", + // }) + // options = new Collection(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: "IDX_product_variant_deleted_at" }) + // @Property({ columnType: "timestamptz", nullable: true }) + // deleted_at?: Date + // @OnInit() + // @BeforeCreate() + // onInit() { + // this.id = generateEntityId(this.id, "variant") + // this.product_id ??= this.product?.id ?? null + // } } -export default ProductVariant +export default ProductVariantDML +// export default ProductVariant diff --git a/packages/modules/product/src/models/product.ts b/packages/modules/product/src/models/product.ts index c2f89a39751af..c696fe36a8b52 100644 --- a/packages/modules/product/src/models/product.ts +++ b/packages/modules/product/src/models/product.ts @@ -17,6 +17,7 @@ import { createPsqlIndexStatementHelper, DALUtils, generateEntityId, + model, ProductUtils, Searchable, toHandle, @@ -30,195 +31,223 @@ import ProductType from "./product-type" import ProductVariant from "./product-variant" const productHandleIndexName = "IDX_product_handle_unique" -const productHandleIndexStatement = createPsqlIndexStatementHelper({ - name: productHandleIndexName, - tableName: "product", - columns: ["handle"], - unique: true, - where: "deleted_at IS NULL", -}) +// const productHandleIndexStatement = createPsqlIndexStatementHelper({ +// name: productHandleIndexName, +// tableName: "product", +// columns: ["handle"], +// unique: true, +// where: "deleted_at IS NULL", +// }) const productTypeIndexName = "IDX_product_type_id" -const productTypeIndexStatement = createPsqlIndexStatementHelper({ - name: productTypeIndexName, - tableName: "product", - columns: ["type_id"], - unique: false, - where: "deleted_at IS NULL", -}) +// const productTypeIndexStatement = createPsqlIndexStatementHelper({ +// name: productTypeIndexName, +// tableName: "product", +// columns: ["type_id"], +// unique: false, +// where: "deleted_at IS NULL", +// }) const productCollectionIndexName = "IDX_product_collection_id" -const productCollectionIndexStatement = createPsqlIndexStatementHelper({ - name: productCollectionIndexName, - tableName: "product", - columns: ["collection_id"], - unique: false, - where: "deleted_at IS NULL", -}) - -productTypeIndexStatement.MikroORMIndex() -productCollectionIndexStatement.MikroORMIndex() -productHandleIndexStatement.MikroORMIndex() -@Entity({ tableName: "product" }) -@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions) -class Product { - @PrimaryKey({ columnType: "text" }) - id!: string - - @Searchable() - @Property({ columnType: "text" }) - title: string - - @Property({ columnType: "text" }) - handle?: string - - @Searchable() - @Property({ columnType: "text", nullable: true }) - subtitle?: string | null - - @Searchable() - @Property({ - columnType: "text", - nullable: true, +// const productCollectionIndexStatement = createPsqlIndexStatementHelper({ +// name: productCollectionIndexName, +// tableName: "product", +// columns: ["collection_id"], +// unique: false, +// where: "deleted_at IS NULL", +// }) + +export const ProductDML = model + .define("Product", { + id: model.id().primaryKey(), + title: model.text().searchable(), + handle: model.text().nullable(), + subtitle: model.text().searchable().nullable(), + description: model.text().searchable().nullable(), + is_giftcard: model.boolean().default(false), + status: model + .enum(ProductUtils.ProductStatus) + .default(ProductUtils.ProductStatus.DRAFT), + thumbnail: model.text().nullable(), + weight: model.number().nullable(), + length: model.number().nullable(), + height: model.number().nullable(), + width: model.number().nullable(), + origin_country: model.text().nullable(), + hs_code: model.text().nullable(), + mid_code: model.text().nullable(), + material: model.text().nullable(), + discountable: model.boolean().default(true), + external_id: model.text().nullable(), + metadata: model.json().nullable(), + variants: model.hasMany(() => ProductVariant), + type: model.belongsTo(() => ProductType).nullable(), + tags: model.manyToMany(() => ProductTag), + options: model.hasMany(() => ProductOption), + images: model.manyToMany(() => ProductImage, { + pivotTable: "product_images", + }), + collection: model.belongsTo(() => ProductCollection).nullable(), + categories: model.manyToMany(() => ProductCategory, { + pivotTable: "product_category_product", + }), }) - description?: string | null - - @Property({ columnType: "boolean", default: false }) - is_giftcard!: boolean - - @Enum(() => ProductUtils.ProductStatus) - @Property({ default: ProductUtils.ProductStatus.DRAFT }) - status!: ProductUtils.ProductStatus - - @Property({ columnType: "text", nullable: true }) - thumbnail?: string | null - - @OneToMany(() => ProductOption, (o) => o.product, { - cascade: ["soft-remove"] as any, - }) - options = new Collection(this) - - @Searchable() - @OneToMany(() => ProductVariant, (variant) => variant.product, { - cascade: ["soft-remove"] as any, + .cascades({ + delete: ["variants", "options"], }) - variants = new Collection(this) - - @Property({ columnType: "text", nullable: true }) - weight?: number | null - - @Property({ columnType: "text", nullable: true }) - length?: number | null - - @Property({ columnType: "text", nullable: true }) - height?: number | null - - @Property({ columnType: "text", nullable: true }) - width?: number | null - - @Property({ columnType: "text", nullable: true }) - origin_country?: string | null - - @Property({ columnType: "text", nullable: true }) - hs_code?: string | null - - @Property({ columnType: "text", nullable: true }) - mid_code?: string | null - - @Property({ columnType: "text", nullable: true }) - material?: string | null - - @Searchable() - @ManyToOne(() => ProductCollection, { - columnType: "text", - nullable: true, - fieldName: "collection_id", - mapToPk: true, - onDelete: "set null", - }) - collection_id: string | null - - @ManyToOne(() => ProductCollection, { - nullable: true, - persist: false, - }) - collection: ProductCollection | null - - @ManyToOne(() => ProductType, { - columnType: "text", - nullable: true, - fieldName: "type_id", - mapToPk: true, - onDelete: "set null", - }) - type_id: string | null - - @ManyToOne(() => ProductType, { - nullable: true, - persist: false, - }) - type: ProductType | null - - @ManyToMany(() => ProductTag, "products", { - owner: true, - pivotTable: "product_tags", - index: "IDX_product_tag_id", - }) - tags = new Collection(this) - - @ManyToMany(() => ProductImage, "products", { - owner: true, - pivotTable: "product_images", - joinColumn: "product_id", - inverseJoinColumn: "image_id", - }) - images = new Collection(this) - - @ManyToMany(() => ProductCategory, "products", { - owner: true, - pivotTable: "product_category_product", - }) - categories = new Collection(this) - - @Property({ columnType: "boolean", default: true }) - discountable: boolean - - @Property({ columnType: "text", nullable: true }) - external_id?: string | 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 - - @Index({ name: "IDX_product_deleted_at" }) - @Property({ columnType: "timestamptz", nullable: true }) - deleted_at?: Date - - @Property({ columnType: "jsonb", nullable: true }) - metadata?: Record | null - - @OnInit() - @BeforeCreate() - onInit() { - this.id = generateEntityId(this.id, "prod") - this.type_id ??= this.type?.id ?? null - this.collection_id ??= this.collection?.id ?? null - - if (!this.handle && this.title) { - this.handle = toHandle(this.title) - } - } + .indexes([ + { + name: productHandleIndexName, + on: ["handle"], + unique: true, + where: "deleted_at IS NULL", + }, + { + name: productTypeIndexName, + on: ["type_id"], + unique: false, + where: "deleted_at IS NULL", + }, + { + name: productCollectionIndexName, + on: ["collection_id"], + unique: false, + where: "deleted_at IS NULL", + }, + ]) + +// productTypeIndexStatement.MikroORMIndex() +// productCollectionIndexStatement.MikroORMIndex() +// productHandleIndexStatement.MikroORMIndex() +// @Entity({ tableName: "product" }) +// @Filter(DALUtils.mikroOrmSoftDeletableFilterOptions) +class Product { + // @PrimaryKey({ columnType: "text" }) + // id!: string + // @Searchable() + // @Property({ columnType: "text" }) + // title: string + // @Property({ columnType: "text" }) + // handle?: string + // @Searchable() + // @Property({ columnType: "text", nullable: true }) + // subtitle?: string | null + // @Searchable() + // @Property({ + // columnType: "text", + // nullable: true, + // }) + // description?: string | null + // @Property({ columnType: "boolean", default: false }) + // is_giftcard!: boolean + // @Enum(() => ProductUtils.ProductStatus) + // @Property({ default: ProductUtils.ProductStatus.DRAFT }) + // status!: ProductUtils.ProductStatus + // @Property({ columnType: "text", nullable: true }) + // thumbnail?: string | null + // @OneToMany(() => ProductOption, (o) => o.product, { + // cascade: ["soft-remove"] as any, + // }) + // options = new Collection(this) + // @Searchable() + // @OneToMany(() => ProductVariant, (variant) => variant.product, { + // cascade: ["soft-remove"] as any, + // }) + // variants = new Collection(this) + // @Property({ columnType: "text", nullable: true }) + // weight?: number | null + // @Property({ columnType: "text", nullable: true }) + // length?: number | null + // @Property({ columnType: "text", nullable: true }) + // height?: number | null + // @Property({ columnType: "text", nullable: true }) + // width?: number | null + // @Property({ columnType: "text", nullable: true }) + // origin_country?: string | null + // @Property({ columnType: "text", nullable: true }) + // hs_code?: string | null + // @Property({ columnType: "text", nullable: true }) + // mid_code?: string | null + // @Property({ columnType: "text", nullable: true }) + // material?: string | null + // @Searchable() + // @ManyToOne(() => ProductCollection, { + // columnType: "text", + // nullable: true, + // fieldName: "collection_id", + // mapToPk: true, + // onDelete: "set null", + // }) + // collection_id: string | null + // @ManyToOne(() => ProductCollection, { + // nullable: true, + // persist: false, + // }) + // collection: ProductCollection | null + // @ManyToOne(() => ProductType, { + // columnType: "text", + // nullable: true, + // fieldName: "type_id", + // mapToPk: true, + // onDelete: "set null", + // }) + // type_id: string | null + // @ManyToOne(() => ProductType, { + // nullable: true, + // persist: false, + // }) + // type: ProductType | null + // @ManyToMany(() => ProductTag, "products", { + // owner: true, + // pivotTable: "product_tags", + // index: "IDX_product_tag_id", + // }) + // tags = new Collection(this) + // @ManyToMany(() => ProductImage, "products", { + // owner: true, + // pivotTable: "product_images", + // joinColumn: "product_id", + // inverseJoinColumn: "image_id", + // }) + // images = new Collection(this) + // @ManyToMany(() => ProductCategory, "products", { + // owner: true, + // pivotTable: "product_category_product", + // }) + // categories = new Collection(this) + // @Property({ columnType: "boolean", default: true }) + // discountable: boolean + // @Property({ columnType: "text", nullable: true }) + // external_id?: string | 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 + // @Index({ name: "IDX_product_deleted_at" }) + // @Property({ columnType: "timestamptz", nullable: true }) + // deleted_at?: Date + // @Property({ columnType: "jsonb", nullable: true }) + // metadata?: Record | null + // @OnInit() + // @BeforeCreate() + // onInit() { + // this.id = generateEntityId(this.id, "prod") + // this.type_id ??= this.type?.id ?? null + // this.collection_id ??= this.collection?.id ?? null + // if (!this.handle && this.title) { + // this.handle = toHandle(this.title) + // } + // } } -export default Product +export default ProductDML +// export default Product diff --git a/packages/modules/product/src/services/product-category.ts b/packages/modules/product/src/services/product-category.ts index 720ce64ec7f81..59791bbed8174 100644 --- a/packages/modules/product/src/services/product-category.ts +++ b/packages/modules/product/src/services/product-category.ts @@ -33,7 +33,7 @@ export default class ProductCategoryService { productCategoryId: string, config: FindConfig = {}, @MedusaContext() sharedContext: Context = {} - ): Promise { + ): Promise { if (!isDefined(productCategoryId)) { throw new MedusaError( MedusaError.Types.NOT_FOUND, @@ -41,7 +41,7 @@ export default class ProductCategoryService { ) } - const queryOptions = ModulesSdkUtils.buildQuery( + const queryOptions = ModulesSdkUtils.buildQuery( { id: productCategoryId, }, @@ -67,7 +67,7 @@ export default class ProductCategoryService { ) } - return productCategories[0] as ProductCategory + return productCategories[0] as typeof ProductCategory } @InjectManager("productCategoryRepository_") @@ -75,7 +75,7 @@ export default class ProductCategoryService { filters: ProductTypes.FilterableProductCategoryProps = {}, config: FindConfig = {}, @MedusaContext() sharedContext: Context = {} - ): Promise { + ): Promise<(typeof ProductCategory)[]> { const transformOptions = { includeDescendantsTree: filters?.include_descendants_tree || false, includeAncestorsTree: filters?.include_ancestors_tree || false, @@ -94,7 +94,7 @@ export default class ProductCategoryService { delete filters.q } - const queryOptions = ModulesSdkUtils.buildQuery( + const queryOptions = ModulesSdkUtils.buildQuery( filters, config ) @@ -104,7 +104,7 @@ export default class ProductCategoryService { queryOptions, transformOptions, sharedContext - )) as ProductCategory[] + )) as (typeof ProductCategory)[] } @InjectManager("productCategoryRepository_") @@ -112,7 +112,7 @@ export default class ProductCategoryService { filters: ProductTypes.FilterableProductCategoryProps = {}, config: FindConfig = {}, @MedusaContext() sharedContext: Context = {} - ): Promise<[ProductCategory[], number]> { + ): Promise<[(typeof ProductCategory)[], number]> { const transformOptions = { includeDescendantsTree: filters?.include_descendants_tree || false, includeAncestorsTree: filters?.include_ancestors_tree || false, @@ -131,7 +131,7 @@ export default class ProductCategoryService { delete filters.q } - const queryOptions = ModulesSdkUtils.buildQuery( + const queryOptions = ModulesSdkUtils.buildQuery( filters, config ) @@ -141,27 +141,27 @@ export default class ProductCategoryService { queryOptions, transformOptions, sharedContext - )) as [ProductCategory[], number] + )) as [(typeof ProductCategory)[], number] } @InjectTransactionManager("productCategoryRepository_") async create( data: ProductTypes.CreateProductCategoryDTO[], @MedusaContext() sharedContext: Context = {} - ): Promise { + ): Promise<(typeof ProductCategory)[]> { return (await ( this.productCategoryRepository_ as unknown as ProductCategoryRepository - ).create(data, sharedContext)) as ProductCategory[] + ).create(data, sharedContext)) as (typeof ProductCategory)[] } @InjectTransactionManager("productCategoryRepository_") async update( data: UpdateCategoryInput[], @MedusaContext() sharedContext: Context = {} - ): Promise { + ): Promise<(typeof ProductCategory)[]> { return (await ( this.productCategoryRepository_ as unknown as ProductCategoryRepository - ).update(data, sharedContext)) as ProductCategory[] + ).update(data, sharedContext)) as (typeof ProductCategory)[] } @InjectTransactionManager("productCategoryRepository_") diff --git a/packages/modules/product/src/services/product-module-service.ts b/packages/modules/product/src/services/product-module-service.ts index 628887674ffd7..c30091e120000 100644 --- a/packages/modules/product/src/services/product-module-service.ts +++ b/packages/modules/product/src/services/product-module-service.ts @@ -103,15 +103,31 @@ export default class ProductModuleService implements ProductTypes.IProductModuleService { protected baseRepository_: DAL.RepositoryService - protected readonly productService_: ModulesSdkTypes.IMedusaInternalService - protected readonly productVariantService_: ModulesSdkTypes.IMedusaInternalService + protected readonly productService_: ModulesSdkTypes.IMedusaInternalService< + typeof Product + > + protected readonly productVariantService_: ModulesSdkTypes.IMedusaInternalService< + typeof ProductVariant + > protected readonly productCategoryService_: ProductCategoryService - protected readonly productTagService_: ModulesSdkTypes.IMedusaInternalService - protected readonly productCollectionService_: ModulesSdkTypes.IMedusaInternalService - protected readonly productImageService_: ModulesSdkTypes.IMedusaInternalService - protected readonly productTypeService_: ModulesSdkTypes.IMedusaInternalService - protected readonly productOptionService_: ModulesSdkTypes.IMedusaInternalService - protected readonly productOptionValueService_: ModulesSdkTypes.IMedusaInternalService + protected readonly productTagService_: ModulesSdkTypes.IMedusaInternalService< + typeof ProductTag + > + protected readonly productCollectionService_: ModulesSdkTypes.IMedusaInternalService< + typeof ProductCollection + > + protected readonly productImageService_: ModulesSdkTypes.IMedusaInternalService< + typeof ProductImage + > + protected readonly productTypeService_: ModulesSdkTypes.IMedusaInternalService< + typeof ProductType + > + protected readonly productOptionService_: ModulesSdkTypes.IMedusaInternalService< + typeof ProductOption + > + protected readonly productOptionValueService_: ModulesSdkTypes.IMedusaInternalService< + typeof ProductOptionValue + > protected readonly eventBusModuleService_?: IEventBusModuleService constructor( @@ -186,7 +202,7 @@ export default class ProductModuleService protected async createVariants_( data: ProductTypes.CreateProductVariantDTO[], @MedusaContext() sharedContext: Context = {} - ): Promise { + ): Promise<(typeof ProductVariant)[]> { if (data.some((v) => !v.product_id)) { throw new MedusaError( MedusaError.Types.INVALID_DATA, @@ -262,8 +278,8 @@ export default class ProductModuleService (variant): variant is ProductTypes.CreateProductVariantDTO => !variant.id ) - let created: ProductVariant[] = [] - let updated: ProductVariant[] = [] + let created: (typeof ProductVariant)[] = [] + let updated: (typeof ProductVariant)[] = [] if (forCreate.length) { created = await this.createVariants_(forCreate, sharedContext) @@ -330,7 +346,7 @@ export default class ProductModuleService protected async updateVariants_( data: UpdateProductVariantInput[], @MedusaContext() sharedContext: Context = {} - ): Promise { + ): Promise<(typeof ProductVariant)[]> { // Validation step const variantIdsToUpdate = data.map(({ id }) => id) const variants = await this.productVariantService_.list( @@ -465,8 +481,8 @@ export default class ProductModuleService (tag): tag is ProductTypes.CreateProductTagDTO => !tag.id ) - let created: ProductTag[] = [] - let updated: ProductTag[] = [] + let created: (typeof ProductTag)[] = [] + let updated: (typeof ProductTag)[] = [] if (forCreate.length) { created = await this.productTagService_.create(forCreate, sharedContext) @@ -595,8 +611,8 @@ export default class ProductModuleService (type): type is ProductTypes.CreateProductTypeDTO => !type.id ) - let created: ProductType[] = [] - let updated: ProductType[] = [] + let created: (typeof ProductType)[] = [] + let updated: (typeof ProductType)[] = [] if (forCreate.length) { created = await this.productTypeService_.create(forCreate, sharedContext) @@ -740,8 +756,8 @@ export default class ProductModuleService (option): option is ProductTypes.CreateProductOptionDTO => !option.id ) - let created: ProductOption[] = [] - let updated: ProductOption[] = [] + let created: (typeof ProductOption)[] = [] + let updated: (typeof ProductOption)[] = [] if (forCreate.length) { created = await this.createOptions_(forCreate, sharedContext) @@ -806,7 +822,7 @@ export default class ProductModuleService protected async updateOptions_( data: UpdateProductOptionInput[], @MedusaContext() sharedContext: Context = {} - ): Promise { + ): Promise<(typeof ProductOption)[]> { // Validation step if (data.some((option) => !option.id)) { throw new MedusaError( @@ -915,7 +931,7 @@ export default class ProductModuleService async createCollections_( data: ProductTypes.CreateProductCollectionDTO[], @MedusaContext() sharedContext: Context = {} - ): Promise { + ): Promise<(typeof ProductCollection)[]> { const normalizedInput = data.map( ProductModuleService.normalizeCreateProductCollectionInput ) @@ -960,8 +976,8 @@ export default class ProductModuleService !collection.id ) - let created: ProductCollection[] = [] - let updated: ProductCollection[] = [] + let created: (typeof ProductCollection)[] = [] + let updated: (typeof ProductCollection)[] = [] if (forCreate.length) { created = await this.createCollections_(forCreate, sharedContext) @@ -1055,7 +1071,7 @@ export default class ProductModuleService protected async updateCollections_( data: UpdateCollectionInput[], @MedusaContext() sharedContext: Context = {} - ): Promise { + ): Promise<(typeof ProductCollection)[]> { const normalizedInput = data.map( ProductModuleService.normalizeUpdateProductCollectionInput ) as UpdateCollectionInput[] @@ -1069,7 +1085,7 @@ export default class ProductModuleService sharedContext ) - const collections: ProductCollection[] = [] + const collections: (typeof ProductCollection)[] = [] const updateSelectorAndData = updatedCollections.flatMap( (collectionData) => { @@ -1185,8 +1201,8 @@ export default class ProductModuleService !category.id ) - let created: ProductCategory[] = [] - let updated: ProductCategory[] = [] + let created: (typeof ProductCategory)[] = [] + let updated: (typeof ProductCategory)[] = [] if (forCreate.length) { created = await this.productCategoryService_.create( @@ -1336,8 +1352,8 @@ export default class ProductModuleService (product): product is ProductTypes.CreateProductDTO => !product.id ) - let created: Product[] = [] - let updated: Product[] = [] + let created: (typeof Product)[] = [] + let updated: (typeof Product)[] = [] if (forCreate.length) { created = await this.createProducts_(forCreate, sharedContext) @@ -1424,7 +1440,7 @@ export default class ProductModuleService protected async createProducts_( data: ProductTypes.CreateProductDTO[], @MedusaContext() sharedContext: Context = {} - ): Promise { + ): Promise<(typeof Product)[]> { const normalizedInput = await promiseAll( data.map(async (d) => { const normalized = await this.normalizeCreateProductInput( @@ -1490,7 +1506,7 @@ export default class ProductModuleService protected async updateProducts_( data: UpdateProductInput[], @MedusaContext() sharedContext: Context = {} - ): Promise { + ): Promise<(typeof Product)[]> { const normalizedInput = await promiseAll( data.map(async (d) => { const normalized = await this.normalizeUpdateProductInput( @@ -1750,7 +1766,7 @@ export default class ProductModuleService variants: | ProductTypes.CreateProductVariantDTO[] | ProductTypes.UpdateProductVariantDTO[], - options: ProductOption[] + options: (typeof ProductOption)[] ): | ProductTypes.CreateProductVariantDTO[] | ProductTypes.UpdateProductVariantDTO[] { From 27ea82896b4013c7e2f51d7a360e234c95c685f9 Mon Sep 17 00:00:00 2001 From: Harminder Virk Date: Tue, 12 Nov 2024 18:06:45 +0530 Subject: [PATCH 002/175] feat: wip on repository changes --- packages/core/types/src/dal/index.ts | 8 +-- .../src/dal/mikro-orm/mikro-orm-repository.ts | 53 +++++++++++++------ .../product/src/repositories/product.ts | 10 ++-- 3 files changed, 47 insertions(+), 24 deletions(-) diff --git a/packages/core/types/src/dal/index.ts b/packages/core/types/src/dal/index.ts index aafe8fab742de..7e3a858553359 100644 --- a/packages/core/types/src/dal/index.ts +++ b/packages/core/types/src/dal/index.ts @@ -1,3 +1,4 @@ +import { InferEntityType } from "../dml" import { Dictionary, FilterQuery, Order } from "./utils" export { FilterQuery, OperatorMap } from "./utils" @@ -54,7 +55,7 @@ export interface OptionsQuery { /** * Load strategy (e.g for mikro orm it accept select-in or joined) */ - strategy?: 'select-in' | 'joined' | string & {} + strategy?: "select-in" | "joined" | (string & {}) } /** @@ -66,12 +67,13 @@ export type FindOptions = { /** * The filters to apply on the items. */ - where: FilterQuery & BaseFilterable> + where: FilterQuery> & + BaseFilterable>> /** * The options to apply when retrieving the items. */ - options?: OptionsQuery + options?: OptionsQuery, any> } /** diff --git a/packages/core/utils/src/dal/mikro-orm/mikro-orm-repository.ts b/packages/core/utils/src/dal/mikro-orm/mikro-orm-repository.ts index 16939238fcda8..902f16fa37ad5 100644 --- a/packages/core/utils/src/dal/mikro-orm/mikro-orm-repository.ts +++ b/packages/core/utils/src/dal/mikro-orm/mikro-orm-repository.ts @@ -3,6 +3,7 @@ import { Context, DAL, FilterQuery, + InferEntityType, FilterQuery as InternalFilterQuery, PerformedActions, RepositoryService, @@ -36,8 +37,9 @@ import { import { dbErrorMapper } from "./db-error-mapper" import { mikroOrmSerializer } from "./mikro-orm-serializer" import { mikroOrmUpdateDeletedAtRecursively } from "./utils" +import { DmlEntity, toMikroORMEntity } from "../../dml" -export class MikroOrmBase { +export class MikroOrmBase { readonly manager_: any protected constructor({ manager }) { @@ -91,9 +93,11 @@ export class MikroOrmBase { */ export class MikroOrmBaseRepository - extends MikroOrmBase + extends MikroOrmBase implements RepositoryService { + entity: EntityClass> + constructor(...args: any[]) { // @ts-ignore super(...arguments) @@ -245,13 +249,13 @@ export class MikroOrmBaseRepository findOptions.where = { $and: [findOptions.where, { $or: retrieveConstraintsToApply(q) }], - } as unknown as DAL.FilterQuery + } as unknown as DAL.FindOptions["where"] } } export class MikroOrmBaseTreeRepository< T extends object = object -> extends MikroOrmBase { +> extends MikroOrmBase { constructor() { // @ts-ignore super(...arguments) @@ -286,12 +290,18 @@ export class MikroOrmBaseTreeRepository< } } -export function mikroOrmBaseRepositoryFactory( - entity: any +export function mikroOrmBaseRepositoryFactory( + entity: T ): { new ({ manager }: { manager: any }): MikroOrmBaseRepository } { + const mikroOrmEntity = ( + DmlEntity.isDmlEntity(entity) ? toMikroORMEntity(entity) : entity + ) as EntityClass> + class MikroOrmAbstractBaseRepository_ extends MikroOrmBaseRepository { + entity = mikroOrmEntity + // @ts-ignore constructor(...args: any[]) { // @ts-ignore @@ -315,7 +325,10 @@ export function mikroOrmBaseRepositoryFactory( }) } - async create(data: any[], context?: Context): Promise { + async create( + data: any[], + context?: Context + ): Promise[]> { const manager = this.getActiveManager(context) const entities = data.map((data_) => { @@ -327,7 +340,7 @@ export function mikroOrmBaseRepositoryFactory( manager.persist(entities) - return entities + return entities as InferEntityType[] } /** @@ -350,7 +363,7 @@ export function mikroOrmBaseRepositoryFactory( const relations = manager .getDriver() .getMetadata() - .get(entity.name).relations + .get(this.entity.name).relations // In case an empty array is provided for a collection relation of type m:n, this relation needs to be init in order to be // able to perform an application cascade action. @@ -477,8 +490,9 @@ export function mikroOrmBaseRepositoryFactory( async upsert(data: any[], context: Context = {}): Promise { const manager = this.getActiveManager(context) - const primaryKeys = - MikroOrmAbstractBaseRepository_.retrievePrimaryKeys(entity) + const primaryKeys = MikroOrmAbstractBaseRepository_.retrievePrimaryKeys( + this.entity + ) let primaryKeysCriteria: { [key: string]: any }[] = [] if (primaryKeys.length === 1) { @@ -542,7 +556,7 @@ export function mikroOrmBaseRepositoryFactory( const updatedType = manager.assign(existingEntity, data_) updatedEntities.push(updatedType) } else { - const newEntity = manager.create(entity, data_) + const newEntity = manager.create(this.entity, data_) createdEntities.push(newEntity) } }) @@ -593,7 +607,7 @@ export function mikroOrmBaseRepositoryFactory( const allRelations = manager .getDriver() .getMetadata() - .get(entity.name).relations + .get(this.entity.name).relations const nonexistentRelations = arrayDifference( (config.relations as any) ?? [], @@ -624,7 +638,11 @@ export function mikroOrmBaseRepositoryFactory( ) }) - const mainEntity = this.getEntityWithId(manager, entity.name, entryCopy) + const mainEntity = this.getEntityWithId( + manager, + this.entity.name, + entryCopy + ) reconstructedResponse.push({ ...mainEntity, ...reconstructedEntry }) originalDataMap.set(mainEntity.id, entry) @@ -634,7 +652,7 @@ export function mikroOrmBaseRepositoryFactory( let { orderedEntities: upsertedTopLevelEntities, performedActions: performedActions_, - } = await this.upsertMany_(manager, entity.name, toUpsert) + } = await this.upsertMany_(manager, this.entity.name, toUpsert) this.mergePerformedActions(performedActions, performedActions_) @@ -999,8 +1017,9 @@ export function mikroOrmBaseRepositoryFactory( | (FilterQuery & BaseFilterable>) | (FilterQuery & BaseFilterable>)[] ) { - const primaryKeys = - MikroOrmAbstractBaseRepository_.retrievePrimaryKeys(entity) + const primaryKeys = MikroOrmAbstractBaseRepository_.retrievePrimaryKeys( + this.entity + ) const filterArray = Array.isArray(filters) ? filters : [filters] const normalizedFilters: FilterQuery = { diff --git a/packages/modules/product/src/repositories/product.ts b/packages/modules/product/src/repositories/product.ts index c53db0e0d20d9..caea4951d7536 100644 --- a/packages/modules/product/src/repositories/product.ts +++ b/packages/modules/product/src/repositories/product.ts @@ -1,11 +1,11 @@ import { Product } from "@models" +import { DALUtils } from "@medusajs/framework/utils" import { Context, DAL } from "@medusajs/framework/types" import { SqlEntityManager } from "@mikro-orm/postgresql" -import { DALUtils } from "@medusajs/framework/utils" // eslint-disable-next-line max-len -export class ProductRepository extends DALUtils.mikroOrmBaseRepositoryFactory( +export class ProductRepository extends DALUtils.mikroOrmBaseRepositoryFactory( Product ) { constructor(...args: any[]) { @@ -19,7 +19,9 @@ export class ProductRepository extends DALUtils.mikroOrmBaseRepositoryFactory = { where: {} }, + findOptions: DAL.FindOptions = { + where: {}, + }, context: Context = {} ): Promise { const manager = this.getActiveManager(context) @@ -29,7 +31,7 @@ export class ProductRepository extends DALUtils.mikroOrmBaseRepositoryFactory Date: Tue, 12 Nov 2024 14:52:00 +0100 Subject: [PATCH 003/175] continue repositories and types rework --- packages/core/types/src/dal/index.ts | 4 +- .../core/types/src/dal/repository-service.ts | 65 ++++++---- packages/core/types/src/dal/utils.ts | 40 +++--- .../__tests__/mikro-orm-repository.spec.ts | 6 +- .../src/dal/mikro-orm/mikro-orm-repository.ts | 122 +++++++++++------- .../core/utils/src/modules-sdk/build-query.ts | 18 ++- .../modules-sdk/medusa-internal-service.ts | 4 +- 7 files changed, 159 insertions(+), 100 deletions(-) diff --git a/packages/core/types/src/dal/index.ts b/packages/core/types/src/dal/index.ts index 7e3a858553359..ab99c2b13034b 100644 --- a/packages/core/types/src/dal/index.ts +++ b/packages/core/types/src/dal/index.ts @@ -23,7 +23,7 @@ export interface BaseFilterable { /** * The options to apply when retrieving an item. */ -export interface OptionsQuery { +export interface OptionsQuery { /** * Relations to populate in the retrieved items. */ @@ -73,7 +73,7 @@ export type FindOptions = { /** * The options to apply when retrieving the items. */ - options?: OptionsQuery, any> + options?: OptionsQuery> } /** diff --git a/packages/core/types/src/dal/repository-service.ts b/packages/core/types/src/dal/repository-service.ts index 598c919d4f694..6aae45c990a4e 100644 --- a/packages/core/types/src/dal/repository-service.ts +++ b/packages/core/types/src/dal/repository-service.ts @@ -1,16 +1,23 @@ import { RepositoryTransformOptions } from "../common" import { Context } from "../shared-context" import { - BaseFilterable, - FilterQuery, FilterQuery as InternalFilterQuery, FindOptions, UpsertWithReplaceConfig, } from "./index" +import { EntityClass } from "@mikro-orm/core" +import { IDmlEntity, InferTypeOf } from "../dml" type EntityClassName = string type EntityValues = { id: string }[] +/** + * Either infer the properties from a DML object or from a Mikro orm class prototype. + */ +export type InferRepositoryReturnType = T extends IDmlEntity + ? InferTypeOf + : EntityClass["prototype"] + export type PerformedActions = { created: Record updated: Record @@ -22,7 +29,7 @@ export type PerformedActions = { * This layer helps to separate the business logic (service layer) from accessing the * ORM directly and allows to switch to another ORM without changing the business logic. */ -interface BaseRepositoryService { +interface BaseRepositoryService { transaction( task: (transactionManager: TManager) => Promise, context?: { @@ -42,22 +49,28 @@ interface BaseRepositoryService { ): Promise } -export interface RepositoryService extends BaseRepositoryService { - find(options?: FindOptions, context?: Context): Promise +export interface RepositoryService extends BaseRepositoryService { + find( + options?: FindOptions, + context?: Context + ): Promise[]> findAndCount( options?: FindOptions, context?: Context - ): Promise<[T[], number]> - - create(data: any[], context?: Context): Promise + ): Promise<[InferRepositoryReturnType[], number]> - update(data: { entity; update }[], context?: Context): Promise + create( + data: any[], + context?: Context + ): Promise[]> - delete( - idsOrPKs: FilterQuery & BaseFilterable>, + update( + data: { entity; update }[], context?: Context - ): Promise + ): Promise[]> + + delete(idsOrPKs: FindOptions["where"], context?: Context): Promise /** * Soft delete entities and cascade to related entities if configured. @@ -74,37 +87,45 @@ export interface RepositoryService extends BaseRepositoryService { | InternalFilterQuery | InternalFilterQuery[], context?: Context - ): Promise<[T[], Record]> + ): Promise<[InferRepositoryReturnType[], Record]> restore( idsOrFilter: string[] | InternalFilterQuery, context?: Context - ): Promise<[T[], Record]> + ): Promise<[InferRepositoryReturnType[], Record]> - upsert(data: any[], context?: Context): Promise + upsert( + data: any[], + context?: Context + ): Promise[]> upsertWithReplace( data: any[], - config?: UpsertWithReplaceConfig, + config?: UpsertWithReplaceConfig>, context?: Context - ): Promise<{ entities: T[]; performedActions: PerformedActions }> + ): Promise<{ + entities: InferRepositoryReturnType[] + performedActions: PerformedActions + }> } -export interface TreeRepositoryService - extends BaseRepositoryService { +export interface TreeRepositoryService extends BaseRepositoryService { find( options?: FindOptions, transformOptions?: RepositoryTransformOptions, context?: Context - ): Promise + ): Promise[]> findAndCount( options?: FindOptions, transformOptions?: RepositoryTransformOptions, context?: Context - ): Promise<[T[], number]> + ): Promise<[InferRepositoryReturnType[], number]> - create(data: unknown[], context?: Context): Promise + create( + data: unknown[], + context?: Context + ): Promise[]> delete(ids: string[], context?: Context): Promise } diff --git a/packages/core/types/src/dal/utils.ts b/packages/core/types/src/dal/utils.ts index f99a7e49f4750..90151ec62b99d 100644 --- a/packages/core/types/src/dal/utils.ts +++ b/packages/core/types/src/dal/utils.ts @@ -1,3 +1,5 @@ +import { Constructor } from "../modules-sdk" + type ExpandProperty = T extends (infer U)[] ? NonNullable : NonNullable export type Dictionary = { @@ -84,25 +86,29 @@ type FilterValue = type PrevLimit = [never, 0, 1, 2] +export type FilterQueryProperties = { + [Key in keyof T]?: T[Key] extends + | boolean + | number + | string + | bigint + | symbol + | Date + ? T[Key] | OperatorMap + : T[Key] extends infer U + ? U extends { [x: number]: infer V } + ? V extends object + ? FilterQuery, PrevLimit[Prev]> + : never + : never + : never +} + export type FilterQuery = Prev extends never ? never - : { - [Key in keyof T]?: T[Key] extends - | boolean - | number - | string - | bigint - | symbol - | Date - ? T[Key] | OperatorMap - : T[Key] extends infer U - ? U extends { [x: number]: infer V } - ? V extends object - ? FilterQuery, PrevLimit[Prev]> - : never - : never - : never - } + : T extends Constructor + ? FilterQueryProperties + : FilterQueryProperties declare type QueryOrder = "ASC" | "DESC" | "asc" | "desc" diff --git a/packages/core/utils/src/dal/mikro-orm/integration-tests/__tests__/mikro-orm-repository.spec.ts b/packages/core/utils/src/dal/mikro-orm/integration-tests/__tests__/mikro-orm-repository.spec.ts index 8ffef62387006..2c5f51541f739 100644 --- a/packages/core/utils/src/dal/mikro-orm/integration-tests/__tests__/mikro-orm-repository.spec.ts +++ b/packages/core/utils/src/dal/mikro-orm/integration-tests/__tests__/mikro-orm-repository.spec.ts @@ -120,9 +120,9 @@ class Entity3 { } } -const Entity1Repository = mikroOrmBaseRepositoryFactory(Entity1) -const Entity2Repository = mikroOrmBaseRepositoryFactory(Entity2) -const Entity3Repository = mikroOrmBaseRepositoryFactory(Entity3) +const Entity1Repository = mikroOrmBaseRepositoryFactory(Entity1) +const Entity2Repository = mikroOrmBaseRepositoryFactory(Entity2) +const Entity3Repository = mikroOrmBaseRepositoryFactory(Entity3) describe("mikroOrmRepository", () => { let orm!: MikroORM diff --git a/packages/core/utils/src/dal/mikro-orm/mikro-orm-repository.ts b/packages/core/utils/src/dal/mikro-orm/mikro-orm-repository.ts index 902f16fa37ad5..822c181f9cf9d 100644 --- a/packages/core/utils/src/dal/mikro-orm/mikro-orm-repository.ts +++ b/packages/core/utils/src/dal/mikro-orm/mikro-orm-repository.ts @@ -3,8 +3,9 @@ import { Context, DAL, FilterQuery, - InferEntityType, FilterQuery as InternalFilterQuery, + InferEntityType, + InferRepositoryReturnType, PerformedActions, RepositoryService, RepositoryTransformOptions, @@ -92,7 +93,7 @@ export class MikroOrmBase { * related ones. */ -export class MikroOrmBaseRepository +export class MikroOrmBaseRepository extends MikroOrmBase implements RepositoryService { @@ -148,11 +149,17 @@ export class MikroOrmBaseRepository }) } - create(data: unknown[], context?: Context): Promise { + create( + data: unknown[], + context?: Context + ): Promise[]> { throw new Error("Method not implemented.") } - update(data: { entity; update }[], context?: Context): Promise { + update( + data: { entity; update }[], + context?: Context + ): Promise[]> { throw new Error("Method not implemented.") } @@ -163,28 +170,37 @@ export class MikroOrmBaseRepository throw new Error("Method not implemented.") } - find(options?: DAL.FindOptions, context?: Context): Promise { + find( + options?: DAL.FindOptions, + context?: Context + ): Promise[]> { throw new Error("Method not implemented.") } findAndCount( options?: DAL.FindOptions, context?: Context - ): Promise<[T[], number]> { + ): Promise<[InferRepositoryReturnType[], number]> { throw new Error("Method not implemented.") } - upsert(data: unknown[], context: Context = {}): Promise { + upsert( + data: unknown[], + context: Context = {} + ): Promise[]> { throw new Error("Method not implemented.") } upsertWithReplace( data: unknown[], - config: UpsertWithReplaceConfig = { + config: UpsertWithReplaceConfig> = { relations: [], }, context: Context = {} - ): Promise<{ entities: T[]; performedActions: PerformedActions }> { + ): Promise<{ + entities: InferRepositoryReturnType[] + performedActions: PerformedActions + }> { throw new Error("Method not implemented.") } @@ -192,10 +208,10 @@ export class MikroOrmBaseRepository filters: | string | string[] - | (FilterQuery & BaseFilterable>) - | (FilterQuery & BaseFilterable>)[], + | DAL.FindOptions["where"] + | DAL.FindOptions["where"][], sharedContext: Context = {} - ): Promise<[T[], Record]> { + ): Promise<[InferRepositoryReturnType[], Record]> { const entities = await this.find({ where: filters as any }, sharedContext) const date = new Date() @@ -216,8 +232,8 @@ export class MikroOrmBaseRepository async restore( idsOrFilter: string[] | InternalFilterQuery, sharedContext: Context = {} - ): Promise<[T[], Record]> { - const query = buildQuery(idsOrFilter, { + ): Promise<[InferRepositoryReturnType[], Record]> { + const query = buildQuery(idsOrFilter, { withDeleted: true, }) @@ -290,7 +306,7 @@ export class MikroOrmBaseTreeRepository< } } -export function mikroOrmBaseRepositoryFactory( +export function mikroOrmBaseRepositoryFactory( entity: T ): { new ({ manager }: { manager: any }): MikroOrmBaseRepository @@ -328,7 +344,7 @@ export function mikroOrmBaseRepositoryFactory( async create( data: any[], context?: Context - ): Promise[]> { + ): Promise[]> { const manager = this.getActiveManager(context) const entities = data.map((data_) => { @@ -340,7 +356,7 @@ export function mikroOrmBaseRepositoryFactory( manager.persist(entities) - return entities as InferEntityType[] + return entities as InferRepositoryReturnType[] } /** @@ -410,7 +426,10 @@ export function mikroOrmBaseRepositoryFactory( } } - async update(data: { entity; update }[], context?: Context): Promise { + async update( + data: { entity; update }[], + context?: Context + ): Promise[]> { const manager = this.getActiveManager(context) await this.initManyToManyToDetachAllItemsIfNeeded(data, context) @@ -432,9 +451,9 @@ export function mikroOrmBaseRepositoryFactory( } async find( - options: DAL.FindOptions = { where: {} }, + options: DAL.FindOptions = { where: {} } as DAL.FindOptions, context?: Context - ): Promise { + ): Promise[]> { const manager = this.getActiveManager(context) const findOptions_ = { ...options } @@ -456,17 +475,17 @@ export function mikroOrmBaseRepositoryFactory( findOptions: findOptions_, }) - return await manager.find( + return (await manager.find( entity as EntityName, findOptions_.where as MikroFilterQuery, findOptions_.options as MikroOptions - ) + )) as InferRepositoryReturnType[] } async findAndCount( - findOptions: DAL.FindOptions = { where: {} }, + findOptions: DAL.FindOptions = { where: {} } as DAL.FindOptions, context: Context = {} - ): Promise<[T[], number]> { + ): Promise<[InferRepositoryReturnType[], number]> { const manager = this.getActiveManager(context) const findOptions_ = { ...findOptions } @@ -480,14 +499,17 @@ export function mikroOrmBaseRepositoryFactory( findOptions: findOptions_, }) - return await manager.findAndCount( + return (await manager.findAndCount( entity as EntityName, findOptions_.where as MikroFilterQuery, findOptions_.options as MikroOptions - ) + )) as [InferRepositoryReturnType[], number] } - async upsert(data: any[], context: Context = {}): Promise { + async upsert( + data: any[], + context: Context = {} + ): Promise[]> { const manager = this.getActiveManager(context) const primaryKeys = MikroOrmAbstractBaseRepository_.retrievePrimaryKeys( @@ -511,7 +533,7 @@ export function mikroOrmBaseRepositoryFactory( })) } - let allEntities: T[][] = [] + let allEntities: InferRepositoryReturnType[][] = [] if (primaryKeysCriteria.length) { allEntities = await Promise.all( @@ -527,7 +549,10 @@ export function mikroOrmBaseRepositoryFactory( const existingEntities = allEntities.flat() - const existingEntitiesMap = new Map() + const existingEntitiesMap = new Map< + string, + InferRepositoryReturnType + >() existingEntities.forEach((entity) => { if (entity) { const key = @@ -539,9 +564,9 @@ export function mikroOrmBaseRepositoryFactory( } }) - const upsertedEntities: T[] = [] - const createdEntities: T[] = [] - const updatedEntities: T[] = [] + const upsertedEntities: InferRepositoryReturnType[] = [] + const createdEntities: InferRepositoryReturnType[] = [] + const updatedEntities: InferRepositoryReturnType[] = [] data.forEach((data_) => { // In case the data provided are just strings, then we build an object with the primary key as the key and the data as the valuecd - @@ -556,8 +581,8 @@ export function mikroOrmBaseRepositoryFactory( const updatedType = manager.assign(existingEntity, data_) updatedEntities.push(updatedType) } else { - const newEntity = manager.create(this.entity, data_) - createdEntities.push(newEntity) + const newEntity = manager.create(this.entity, data_) + createdEntities.push(newEntity as InferRepositoryReturnType) } }) @@ -572,7 +597,7 @@ export function mikroOrmBaseRepositoryFactory( } // TODO return the all, created, updated entities - return upsertedEntities + return upsertedEntities as InferRepositoryReturnType[] } // UpsertWithReplace does several things to simplify module implementation. @@ -584,11 +609,14 @@ export function mikroOrmBaseRepositoryFactory( // We only support 1-level depth of upserts. We don't support custom fields on the many-to-many pivot tables for now async upsertWithReplace( data: any[], - config: UpsertWithReplaceConfig = { + config: UpsertWithReplaceConfig> = { relations: [], }, context: Context = {} - ): Promise<{ entities: T[]; performedActions: PerformedActions }> { + ): Promise<{ + entities: InferRepositoryReturnType[] + performedActions: PerformedActions + }> { const performedActions: PerformedActions = { created: {}, updated: {}, @@ -972,10 +1000,10 @@ export function mikroOrmBaseRepositoryFactory( filters: | string | string[] - | (FilterQuery & BaseFilterable>) - | (FilterQuery & BaseFilterable>)[], + | DAL.FindOptions["where"] + | DAL.FindOptions["where"][], sharedContext: Context = {} - ): Promise<[T[], Record]> { + ): Promise<[InferRepositoryReturnType[], Record]> { if (Array.isArray(filters) && !filters.filter(Boolean).length) { return [[], {}] } @@ -993,10 +1021,10 @@ export function mikroOrmBaseRepositoryFactory( filters: | string | string[] - | (FilterQuery & BaseFilterable>) - | (FilterQuery & BaseFilterable>)[], + | DAL.FindOptions["where"] + | DAL.FindOptions["where"][], sharedContext: Context = {} - ): Promise<[T[], Record]> { + ): Promise<[InferRepositoryReturnType[], Record]> { if (Array.isArray(filters) && !filters.filter(Boolean).length) { return [[], {}] } @@ -1014,9 +1042,9 @@ export function mikroOrmBaseRepositoryFactory( filters: | string | string[] - | (FilterQuery & BaseFilterable>) - | (FilterQuery & BaseFilterable>)[] - ) { + | DAL.FindOptions["where"] + | DAL.FindOptions["where"][] + ): DAL.FindOptions["where"] { const primaryKeys = MikroOrmAbstractBaseRepository_.retrievePrimaryKeys( this.entity ) @@ -1033,7 +1061,7 @@ export function mikroOrmBaseRepositoryFactory( }), } - return normalizedFilters + return normalizedFilters as DAL.FindOptions["where"] } } diff --git a/packages/core/utils/src/modules-sdk/build-query.ts b/packages/core/utils/src/modules-sdk/build-query.ts index 63da37fa6ebac..3dbbd22924b6e 100644 --- a/packages/core/utils/src/modules-sdk/build-query.ts +++ b/packages/core/utils/src/modules-sdk/build-query.ts @@ -1,4 +1,4 @@ -import { DAL, FindConfig } from "@medusajs/types" +import { DAL, FindConfig, InferRepositoryReturnType } from "@medusajs/types" import { deduplicate, isObject } from "../common" import { SoftDeletableFilterKey } from "../dal/mikro-orm/mikro-orm-soft-deletable-filter" @@ -10,17 +10,19 @@ type FilterFlags = { withDeleted?: boolean } -export function buildQuery( +export function buildQuery( filters: Record = {}, - config: FindConfig & { primaryKeyFields?: string | string[] } = {} + config: FindConfig> & { + primaryKeyFields?: string | string[] + } = {} ): Required> { - const where: DAL.FilterQuery = {} + const where = {} as DAL.FilterQuery const filterFlags: FilterFlags = {} buildWhere(filters, where, filterFlags) delete config.primaryKeyFields - const findOptions: DAL.OptionsQuery = { + const findOptions: DAL.FindOptions["options"] = { populate: deduplicate(config.relations ?? []), fields: config.select as string[], limit: (Number.isSafeInteger(config.take) && config.take) || undefined, @@ -28,7 +30,9 @@ export function buildQuery( } if (config.order) { - findOptions.orderBy = config.order as DAL.OptionsQuery["orderBy"] + findOptions.orderBy = config.order as Required< + DAL.FindOptions + >["options"]["orderBy"] } if (config.withDeleted || filterFlags.withDeleted) { @@ -50,7 +54,7 @@ export function buildQuery( Object.assign(findOptions, config.options) } - return { where, options: findOptions } + return { where, options: findOptions } as Required> } function buildWhere( diff --git a/packages/core/utils/src/modules-sdk/medusa-internal-service.ts b/packages/core/utils/src/modules-sdk/medusa-internal-service.ts index cdd358c38e28e..3689869adbe48 100644 --- a/packages/core/utils/src/modules-sdk/medusa-internal-service.ts +++ b/packages/core/utils/src/modules-sdk/medusa-internal-service.ts @@ -2,9 +2,9 @@ import { BaseFilterable, Context, FilterQuery, + FilterQuery as InternalFilterQuery, FindConfig, InferEntityType, - FilterQuery as InternalFilterQuery, ModulesSdkTypes, PerformedActions, UpsertWithReplaceConfig, @@ -62,7 +62,7 @@ export function MedusaInternalService< } static applyFreeTextSearchFilter( - filters: FilterQuery, + filters: FilterQuery & { q?: string }, config: FindConfig ): void { if (isDefined(filters?.q)) { From 693c016df48bca98f07a1b259bd801bfd8ac7c6a Mon Sep 17 00:00:00 2001 From: adrien2p Date: Tue, 12 Nov 2024 15:04:30 +0100 Subject: [PATCH 004/175] fix order repository usage --- packages/modules/order/src/repositories/claim.ts | 2 +- packages/modules/order/src/repositories/exchange.ts | 2 +- packages/modules/order/src/repositories/order.ts | 2 +- packages/modules/order/src/repositories/return.ts | 2 +- packages/modules/order/src/utils/base-repository-find.ts | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/modules/order/src/repositories/claim.ts b/packages/modules/order/src/repositories/claim.ts index b24c674ec1c90..142528f4073b9 100644 --- a/packages/modules/order/src/repositories/claim.ts +++ b/packages/modules/order/src/repositories/claim.ts @@ -2,7 +2,7 @@ import { DALUtils } from "@medusajs/framework/utils" import { OrderClaim } from "@models" import { setFindMethods } from "../utils/base-repository-find" -export class OrderClaimRepository extends DALUtils.mikroOrmBaseRepositoryFactory( +export class OrderClaimRepository extends DALUtils.mikroOrmBaseRepositoryFactory( OrderClaim ) {} diff --git a/packages/modules/order/src/repositories/exchange.ts b/packages/modules/order/src/repositories/exchange.ts index f2d7d8228189d..915552bdf9488 100644 --- a/packages/modules/order/src/repositories/exchange.ts +++ b/packages/modules/order/src/repositories/exchange.ts @@ -2,7 +2,7 @@ import { DALUtils } from "@medusajs/framework/utils" import { OrderExchange } from "@models" import { setFindMethods } from "../utils/base-repository-find" -export class OrderExchangeRepository extends DALUtils.mikroOrmBaseRepositoryFactory( +export class OrderExchangeRepository extends DALUtils.mikroOrmBaseRepositoryFactory( OrderExchange ) {} diff --git a/packages/modules/order/src/repositories/order.ts b/packages/modules/order/src/repositories/order.ts index 63e98c58e2617..84fd45ebc7dff 100644 --- a/packages/modules/order/src/repositories/order.ts +++ b/packages/modules/order/src/repositories/order.ts @@ -2,7 +2,7 @@ import { DALUtils } from "@medusajs/framework/utils" import { Order } from "@models" import { setFindMethods } from "../utils/base-repository-find" -export class OrderRepository extends DALUtils.mikroOrmBaseRepositoryFactory( +export class OrderRepository extends DALUtils.mikroOrmBaseRepositoryFactory( Order ) {} diff --git a/packages/modules/order/src/repositories/return.ts b/packages/modules/order/src/repositories/return.ts index 9f5c760d8bc0b..00f407a8198f3 100644 --- a/packages/modules/order/src/repositories/return.ts +++ b/packages/modules/order/src/repositories/return.ts @@ -2,7 +2,7 @@ import { DALUtils } from "@medusajs/framework/utils" import { Return } from "@models" import { setFindMethods } from "../utils/base-repository-find" -export class ReturnRepository extends DALUtils.mikroOrmBaseRepositoryFactory( +export class ReturnRepository extends DALUtils.mikroOrmBaseRepositoryFactory( Return ) {} diff --git a/packages/modules/order/src/utils/base-repository-find.ts b/packages/modules/order/src/utils/base-repository-find.ts index 7bb9a5cbf05ca..7055f57659940 100644 --- a/packages/modules/order/src/utils/base-repository-find.ts +++ b/packages/modules/order/src/utils/base-repository-find.ts @@ -118,7 +118,7 @@ export function setFindMethods(klass: Constructor, entity: any) { klass.prototype.findAndCount = async function findAndCount( this: any, - findOptions: DAL.FindOptions = { where: {} }, + findOptions: DAL.FindOptions = { where: {} } as DAL.FindOptions, context: Context = {} ): Promise<[T[], number]> { const manager = this.getActiveManager(context) From b42b18018ba45027e5d22b5e8fce88962739a954 Mon Sep 17 00:00:00 2001 From: adrien2p Date: Tue, 12 Nov 2024 16:50:29 +0100 Subject: [PATCH 005/175] continue to update product category repository --- .../src/dal/mikro-orm/mikro-orm-repository.ts | 16 +- .../product/src/models/product-category.ts | 171 +++++------ .../product/src/models/product-collection.ts | 95 +++--- .../product/src/models/product-image.ts | 87 +++--- .../src/models/product-option-value.ts | 109 +++---- .../product/src/models/product-option.ts | 117 +++----- .../modules/product/src/models/product-tag.ts | 84 +++--- .../product/src/models/product-type.ts | 78 ++--- .../product/src/models/product-variant.ts | 198 ++++++------- .../modules/product/src/models/product.ts | 279 ++++++++---------- .../src/repositories/product-category.ts | 102 ++++--- 11 files changed, 595 insertions(+), 741 deletions(-) diff --git a/packages/core/utils/src/dal/mikro-orm/mikro-orm-repository.ts b/packages/core/utils/src/dal/mikro-orm/mikro-orm-repository.ts index 822c181f9cf9d..3e03ed8255e62 100644 --- a/packages/core/utils/src/dal/mikro-orm/mikro-orm-repository.ts +++ b/packages/core/utils/src/dal/mikro-orm/mikro-orm-repository.ts @@ -270,7 +270,7 @@ export class MikroOrmBaseRepository } export class MikroOrmBaseTreeRepository< - T extends object = object + const T extends object = object > extends MikroOrmBase { constructor() { // @ts-ignore @@ -281,7 +281,7 @@ export class MikroOrmBaseTreeRepository< options?: DAL.FindOptions, transformOptions?: RepositoryTransformOptions, context?: Context - ): Promise { + ): Promise[]> { throw new Error("Method not implemented.") } @@ -289,15 +289,21 @@ export class MikroOrmBaseTreeRepository< options?: DAL.FindOptions, transformOptions?: RepositoryTransformOptions, context?: Context - ): Promise<[T[], number]> { + ): Promise<[InferRepositoryReturnType[], number]> { throw new Error("Method not implemented.") } - create(data: unknown[], context?: Context): Promise { + create( + data: unknown[], + context?: Context + ): Promise[]> { throw new Error("Method not implemented.") } - update(data: unknown[], context?: Context): Promise { + update( + data: unknown[], + context?: Context + ): Promise[]> { throw new Error("Method not implemented.") } diff --git a/packages/modules/product/src/models/product-category.ts b/packages/modules/product/src/models/product-category.ts index d29f8a82efdba..be684f6205f48 100644 --- a/packages/modules/product/src/models/product-category.ts +++ b/packages/modules/product/src/models/product-category.ts @@ -1,25 +1,4 @@ -import { - DALUtils, - Searchable, - createPsqlIndexStatementHelper, - generateEntityId, - kebabCase, - model, -} from "@medusajs/framework/utils" -import { - BeforeCreate, - Collection, - Entity, - EventArgs, - Filter, - Index, - ManyToMany, - ManyToOne, - OnInit, - OneToMany, - PrimaryKey, - Property, -} from "@mikro-orm/core" +import { model } from "@medusajs/framework/utils" import Product from "./product" const categoryHandleIndexName = "IDX_category_handle_unique" @@ -78,79 +57,79 @@ const ProductCategoryDML = model // categoryHandleIndexStatement.MikroORMIndex() // @Entity({ tableName: "product_category" }) // @Filter(DALUtils.mikroOrmSoftDeletableFilterOptions) -class ProductCategory { - // @PrimaryKey({ columnType: "text" }) - // id!: string - // @Searchable() - // @Property({ columnType: "text", nullable: false }) - // name?: string - // @Searchable() - // @Property({ columnType: "text", default: "", nullable: false }) - // description?: string - // @Searchable() - // @Property({ columnType: "text", nullable: false }) - // handle?: string - // @Property({ columnType: "text", nullable: false }) - // mpath?: string - // @Property({ columnType: "boolean", default: false }) - // is_active?: boolean - // @Property({ columnType: "boolean", default: false }) - // is_internal?: boolean - // @Property({ - // columnType: "integer", - // nullable: false, - // default: 0, - // }) - // rank: number - // @ManyToOne(() => ProductCategory, { - // columnType: "text", - // fieldName: "parent_category_id", - // nullable: true, - // mapToPk: true, - // onDelete: "cascade", - // }) - // parent_category_id?: string | null - // @ManyToOne(() => ProductCategory, { nullable: true, persist: false }) - // parent_category?: ProductCategory - // @OneToMany({ - // entity: () => ProductCategory, - // mappedBy: (productCategory) => productCategory.parent_category, - // }) - // category_children = new Collection(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: "IDX_product_category_deleted_at" }) - // @Property({ columnType: "timestamptz", nullable: true }) - // deleted_at?: Date - // @Property({ columnType: "jsonb", nullable: true }) - // metadata: Record | null = null - // @ManyToMany(() => Product, (product) => product.categories) - // products = new Collection(this) - // @OnInit() - // async onInit() { - // this.id = generateEntityId(this.id, "pcat") - // this.parent_category_id ??= this.parent_category?.id ?? null - // } - // @BeforeCreate() - // async onCreate(args: EventArgs) { - // this.id = generateEntityId(this.id, "pcat") - // this.parent_category_id ??= this.parent_category?.id ?? null - // if (!this.handle && this.name) { - // this.handle = kebabCase(this.name) - // } - // this.mpath = `${this.mpath ? this.mpath + "." : ""}${this.id}` - // } -} +// class ProductCategory { +// @PrimaryKey({ columnType: "text" }) +// id!: string +// @Searchable() +// @Property({ columnType: "text", nullable: false }) +// name?: string +// @Searchable() +// @Property({ columnType: "text", default: "", nullable: false }) +// description?: string +// @Searchable() +// @Property({ columnType: "text", nullable: false }) +// handle?: string +// @Property({ columnType: "text", nullable: false }) +// mpath?: string +// @Property({ columnType: "boolean", default: false }) +// is_active?: boolean +// @Property({ columnType: "boolean", default: false }) +// is_internal?: boolean +// @Property({ +// columnType: "integer", +// nullable: false, +// default: 0, +// }) +// rank: number +// @ManyToOne(() => ProductCategory, { +// columnType: "text", +// fieldName: "parent_category_id", +// nullable: true, +// mapToPk: true, +// onDelete: "cascade", +// }) +// parent_category_id?: string | null +// @ManyToOne(() => ProductCategory, { nullable: true, persist: false }) +// parent_category?: ProductCategory +// @OneToMany({ +// entity: () => ProductCategory, +// mappedBy: (productCategory) => productCategory.parent_category, +// }) +// category_children = new Collection(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: "IDX_product_category_deleted_at" }) +// @Property({ columnType: "timestamptz", nullable: true }) +// deleted_at?: Date +// @Property({ columnType: "jsonb", nullable: true }) +// metadata: Record | null = null +// @ManyToMany(() => Product, (product) => product.categories) +// products = new Collection(this) +// @OnInit() +// async onInit() { +// this.id = generateEntityId(this.id, "pcat") +// this.parent_category_id ??= this.parent_category?.id ?? null +// } +// @BeforeCreate() +// async onCreate(args: EventArgs) { +// this.id = generateEntityId(this.id, "pcat") +// this.parent_category_id ??= this.parent_category?.id ?? null +// if (!this.handle && this.name) { +// this.handle = kebabCase(this.name) +// } +// this.mpath = `${this.mpath ? this.mpath + "." : ""}${this.id}` +// } +// } export default ProductCategoryDML diff --git a/packages/modules/product/src/models/product-collection.ts b/packages/modules/product/src/models/product-collection.ts index 84ab985d6b1c9..f1203080a5481 100644 --- a/packages/modules/product/src/models/product-collection.ts +++ b/packages/modules/product/src/models/product-collection.ts @@ -1,23 +1,4 @@ -import { - BeforeCreate, - Collection, - Entity, - Filter, - Index, - OneToMany, - OnInit, - PrimaryKey, - Property, -} from "@mikro-orm/core" - -import { - createPsqlIndexStatementHelper, - DALUtils, - generateEntityId, - kebabCase, - model, - Searchable, -} from "@medusajs/framework/utils" +import { model } from "@medusajs/framework/utils" import Product from "./product" const collectionHandleIndexName = "IDX_collection_handle_unique" @@ -49,42 +30,42 @@ const ProductCollectionDML = model // collectionHandleIndexStatement.MikroORMIndex() // @Entity({ tableName: "product_collection" }) // @Filter(DALUtils.mikroOrmSoftDeletableFilterOptions) -class ProductCollection { - // @PrimaryKey({ columnType: "text" }) - // id!: string - // @Searchable() - // @Property({ columnType: "text" }) - // title: string - // @Property({ columnType: "text" }) - // handle?: string - // @OneToMany(() => Product, (product) => product.collection) - // products = new Collection(this) - // @Property({ columnType: "jsonb", nullable: true }) - // metadata?: Record | 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 - // @Index({ name: "IDX_product_collection_deleted_at" }) - // @Property({ columnType: "timestamptz", nullable: true }) - // deleted_at?: Date - // @OnInit() - // @BeforeCreate() - // onInit() { - // this.id = generateEntityId(this.id, "pcol") - // if (!this.handle && this.title) { - // this.handle = kebabCase(this.title) - // } - // } -} +// class ProductCollection { +// @PrimaryKey({ columnType: "text" }) +// id!: string +// @Searchable() +// @Property({ columnType: "text" }) +// title: string +// @Property({ columnType: "text" }) +// handle?: string +// @OneToMany(() => Product, (product) => product.collection) +// products = new Collection(this) +// @Property({ columnType: "jsonb", nullable: true }) +// metadata?: Record | 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 +// @Index({ name: "IDX_product_collection_deleted_at" }) +// @Property({ columnType: "timestamptz", nullable: true }) +// deleted_at?: Date +// @OnInit() +// @BeforeCreate() +// onInit() { +// this.id = generateEntityId(this.id, "pcol") +// if (!this.handle && this.title) { +// this.handle = kebabCase(this.title) +// } +// } +// } export default ProductCollectionDML diff --git a/packages/modules/product/src/models/product-image.ts b/packages/modules/product/src/models/product-image.ts index 47bf2af24c6d3..e20c278df73b6 100644 --- a/packages/modules/product/src/models/product-image.ts +++ b/packages/modules/product/src/models/product-image.ts @@ -1,21 +1,4 @@ -import { - BeforeCreate, - Collection, - Entity, - Filter, - Index, - ManyToMany, - OnInit, - PrimaryKey, - Property, -} from "@mikro-orm/core" - -import { - DALUtils, - createPsqlIndexStatementHelper, - generateEntityId, - model, -} from "@medusajs/framework/utils" +import { model } from "@medusajs/framework/utils" import Product from "./product" const imageUrlIndexName = "IDX_product_image_url" @@ -46,39 +29,39 @@ const ProductImageDML = model // imageUrlIndexStatement.MikroORMIndex() // @Entity({ tableName: "image" }) // @Filter(DALUtils.mikroOrmSoftDeletableFilterOptions) -class ProductImage { - // @PrimaryKey({ columnType: "text" }) - // id!: string - // @Property({ columnType: "text" }) - // url: string - // @Property({ columnType: "jsonb", nullable: true }) - // metadata?: Record | 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 - // @Index({ name: "IDX_product_image_deleted_at" }) - // @Property({ columnType: "timestamptz", nullable: true }) - // deleted_at?: Date - // @ManyToMany(() => Product, (product) => product.images) - // products = new Collection(this) - // @OnInit() - // onInit() { - // this.id = generateEntityId(this.id, "img") - // } - // @BeforeCreate() - // onCreate() { - // this.id = generateEntityId(this.id, "img") - // } -} +// class ProductImage { +// @PrimaryKey({ columnType: "text" }) +// id!: string +// @Property({ columnType: "text" }) +// url: string +// @Property({ columnType: "jsonb", nullable: true }) +// metadata?: Record | 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 +// @Index({ name: "IDX_product_image_deleted_at" }) +// @Property({ columnType: "timestamptz", nullable: true }) +// deleted_at?: Date +// @ManyToMany(() => Product, (product) => product.images) +// products = new Collection(this) +// @OnInit() +// onInit() { +// this.id = generateEntityId(this.id, "img") +// } +// @BeforeCreate() +// onCreate() { +// this.id = generateEntityId(this.id, "img") +// } +// } export default ProductImageDML diff --git a/packages/modules/product/src/models/product-option-value.ts b/packages/modules/product/src/models/product-option-value.ts index c9e548ed15a99..4722d618ac084 100644 --- a/packages/modules/product/src/models/product-option-value.ts +++ b/packages/modules/product/src/models/product-option-value.ts @@ -1,21 +1,4 @@ -import { - DALUtils, - createPsqlIndexStatementHelper, - generateEntityId, - model, -} from "@medusajs/framework/utils" -import { - BeforeCreate, - Collection, - Entity, - Filter, - Index, - ManyToMany, - ManyToOne, - OnInit, - PrimaryKey, - Property, -} from "@mikro-orm/core" +import { model } from "@medusajs/framework/utils" import { ProductOption, ProductVariant } from "./index" const optionValueOptionIdIndexName = "IDX_option_value_option_id_unique" @@ -47,50 +30,50 @@ const ProductOptionValueDML = model // optionValueOptionIdIndexStatement.MikroORMIndex() // @Entity({ tableName: "product_option_value" }) // @Filter(DALUtils.mikroOrmSoftDeletableFilterOptions) -class ProductOptionValue { - // @PrimaryKey({ columnType: "text" }) - // id!: string - // @Property({ columnType: "text" }) - // value: string - // @ManyToOne(() => ProductOption, { - // columnType: "text", - // fieldName: "option_id", - // mapToPk: true, - // nullable: true, - // onDelete: "cascade", - // }) - // option_id: string | null - // @ManyToOne(() => ProductOption, { - // nullable: true, - // persist: false, - // }) - // option: ProductOption | null - // @ManyToMany(() => ProductVariant, (variant) => variant.options) - // variants = new Collection(this) - // @Property({ columnType: "jsonb", nullable: true }) - // metadata?: Record | 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 - // @Index({ name: "IDX_product_option_value_deleted_at" }) - // @Property({ columnType: "timestamptz", nullable: true }) - // deleted_at?: Date - // @OnInit() - // @BeforeCreate() - // onInit() { - // this.id = generateEntityId(this.id, "optval") - // this.option_id ??= this.option?.id ?? null - // } -} +// class ProductOptionValue { +// @PrimaryKey({ columnType: "text" }) +// id!: string +// @Property({ columnType: "text" }) +// value: string +// @ManyToOne(() => ProductOption, { +// columnType: "text", +// fieldName: "option_id", +// mapToPk: true, +// nullable: true, +// onDelete: "cascade", +// }) +// option_id: string | null +// @ManyToOne(() => ProductOption, { +// nullable: true, +// persist: false, +// }) +// option: ProductOption | null +// @ManyToMany(() => ProductVariant, (variant) => variant.options) +// variants = new Collection(this) +// @Property({ columnType: "jsonb", nullable: true }) +// metadata?: Record | 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 +// @Index({ name: "IDX_product_option_value_deleted_at" }) +// @Property({ columnType: "timestamptz", nullable: true }) +// deleted_at?: Date +// @OnInit() +// @BeforeCreate() +// onInit() { +// this.id = generateEntityId(this.id, "optval") +// this.option_id ??= this.option?.id ?? null +// } +// } export default ProductOptionValueDML diff --git a/packages/modules/product/src/models/product-option.ts b/packages/modules/product/src/models/product-option.ts index 58343e5e4dad7..9b6ec1b62726f 100644 --- a/packages/modules/product/src/models/product-option.ts +++ b/packages/modules/product/src/models/product-option.ts @@ -1,23 +1,4 @@ -import { - DALUtils, - Searchable, - createPsqlIndexStatementHelper, - generateEntityId, - model, -} from "@medusajs/framework/utils" -import { - BeforeCreate, - Cascade, - Collection, - Entity, - Filter, - Index, - ManyToOne, - OnInit, - OneToMany, - PrimaryKey, - Property, -} from "@mikro-orm/core" +import { model } from "@medusajs/framework/utils" import { Product } from "./index" import ProductOptionValue from "./product-option-value" @@ -53,53 +34,53 @@ const ProductOptionDML = model // optionProductIdTitleIndexStatement.MikroORMIndex() // @Entity({ tableName: "product_option" }) // @Filter(DALUtils.mikroOrmSoftDeletableFilterOptions) -class ProductOption { - // @PrimaryKey({ columnType: "text" }) - // id!: string - // @Searchable() - // @Property({ columnType: "text" }) - // title: string - // @ManyToOne(() => Product, { - // columnType: "text", - // fieldName: "product_id", - // mapToPk: true, - // nullable: true, - // onDelete: "cascade", - // }) - // product_id: string | null - // @ManyToOne(() => Product, { - // persist: false, - // nullable: true, - // }) - // product: Product | null - // @OneToMany(() => ProductOptionValue, (value) => value.option, { - // cascade: [Cascade.PERSIST, "soft-remove" as any], - // }) - // values = new Collection(this) - // @Property({ columnType: "jsonb", nullable: true }) - // metadata?: Record | 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 - // @Index({ name: "IDX_product_option_deleted_at" }) - // @Property({ columnType: "timestamptz", nullable: true }) - // deleted_at?: Date - // @OnInit() - // @BeforeCreate() - // onInit() { - // this.id = generateEntityId(this.id, "opt") - // this.product_id ??= this.product?.id ?? null - // } -} +// class ProductOption { +// @PrimaryKey({ columnType: "text" }) +// id!: string +// @Searchable() +// @Property({ columnType: "text" }) +// title: string +// @ManyToOne(() => Product, { +// columnType: "text", +// fieldName: "product_id", +// mapToPk: true, +// nullable: true, +// onDelete: "cascade", +// }) +// product_id: string | null +// @ManyToOne(() => Product, { +// persist: false, +// nullable: true, +// }) +// product: Product | null +// @OneToMany(() => ProductOptionValue, (value) => value.option, { +// cascade: [Cascade.PERSIST, "soft-remove" as any], +// }) +// values = new Collection(this) +// @Property({ columnType: "jsonb", nullable: true }) +// metadata?: Record | 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 +// @Index({ name: "IDX_product_option_deleted_at" }) +// @Property({ columnType: "timestamptz", nullable: true }) +// deleted_at?: Date +// @OnInit() +// @BeforeCreate() +// onInit() { +// this.id = generateEntityId(this.id, "opt") +// this.product_id ??= this.product?.id ?? null +// } +// } export default ProductOptionDML diff --git a/packages/modules/product/src/models/product-tag.ts b/packages/modules/product/src/models/product-tag.ts index c03b15108c257..25e6d6b7e3437 100644 --- a/packages/modules/product/src/models/product-tag.ts +++ b/packages/modules/product/src/models/product-tag.ts @@ -1,22 +1,4 @@ -import { - BeforeCreate, - Collection, - Entity, - Filter, - Index, - ManyToMany, - OnInit, - PrimaryKey, - Property, -} from "@mikro-orm/core" - -import { - DALUtils, - Searchable, - createPsqlIndexStatementHelper, - generateEntityId, - model, -} from "@medusajs/framework/utils" +import { model } from "@medusajs/framework/utils" import Product from "./product" const tagValueIndexName = "IDX_tag_value_unique" @@ -47,37 +29,37 @@ const ProductTagDML = model // tagValueIndexStatement.MikroORMIndex() // @Entity({ tableName: "product_tag" }) // @Filter(DALUtils.mikroOrmSoftDeletableFilterOptions) -class ProductTag { - // @PrimaryKey({ columnType: "text" }) - // id!: string - // @Searchable() - // @Property({ columnType: "text" }) - // value: string - // @Property({ columnType: "jsonb", nullable: true }) - // metadata?: Record | 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 - // @Index({ name: "IDX_product_tag_deleted_at" }) - // @Property({ columnType: "timestamptz", nullable: true }) - // deleted_at?: Date - // @ManyToMany(() => Product, (product) => product.tags) - // products = new Collection(this) - // @OnInit() - // @BeforeCreate() - // onInit() { - // this.id = generateEntityId(this.id, "ptag") - // } -} +// class ProductTag { +// @PrimaryKey({ columnType: "text" }) +// id!: string +// @Searchable() +// @Property({ columnType: "text" }) +// value: string +// @Property({ columnType: "jsonb", nullable: true }) +// metadata?: Record | 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 +// @Index({ name: "IDX_product_tag_deleted_at" }) +// @Property({ columnType: "timestamptz", nullable: true }) +// deleted_at?: Date +// @ManyToMany(() => Product, (product) => product.tags) +// products = new Collection(this) +// @OnInit() +// @BeforeCreate() +// onInit() { +// this.id = generateEntityId(this.id, "ptag") +// } +// } export default ProductTagDML diff --git a/packages/modules/product/src/models/product-type.ts b/packages/modules/product/src/models/product-type.ts index cc22070813a4a..5385a946c5f3b 100644 --- a/packages/modules/product/src/models/product-type.ts +++ b/packages/modules/product/src/models/product-type.ts @@ -1,20 +1,4 @@ -import { - BeforeCreate, - Entity, - Filter, - Index, - OnInit, - PrimaryKey, - Property, -} from "@mikro-orm/core" - -import { - DALUtils, - Searchable, - createPsqlIndexStatementHelper, - generateEntityId, - model, -} from "@medusajs/framework/utils" +import { model } from "@medusajs/framework/utils" import { Product } from "@models" const typeValueIndexName = "IDX_type_value_unique" @@ -45,35 +29,35 @@ const ProductTypeDML = model // typeValueIndexStatement.MikroORMIndex() // @Entity({ tableName: "product_type" }) // @Filter(DALUtils.mikroOrmSoftDeletableFilterOptions) -class ProductType { - // @PrimaryKey({ columnType: "text" }) - // id!: string - // @Searchable() - // @Property({ columnType: "text" }) - // value: string - // @Property({ columnType: "json", nullable: true }) - // metadata?: Record | 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 - // @Index({ name: "IDX_product_type_deleted_at" }) - // @Property({ columnType: "timestamptz", nullable: true }) - // deleted_at?: Date - // @OnInit() - // @BeforeCreate() - // onInit() { - // this.id = generateEntityId(this.id, "ptyp") - // } -} +// class ProductType { +// @PrimaryKey({ columnType: "text" }) +// id!: string +// @Searchable() +// @Property({ columnType: "text" }) +// value: string +// @Property({ columnType: "json", nullable: true }) +// metadata?: Record | 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 +// @Index({ name: "IDX_product_type_deleted_at" }) +// @Property({ columnType: "timestamptz", nullable: true }) +// deleted_at?: Date +// @OnInit() +// @BeforeCreate() +// onInit() { +// this.id = generateEntityId(this.id, "ptyp") +// } +// } export default ProductTypeDML diff --git a/packages/modules/product/src/models/product-variant.ts b/packages/modules/product/src/models/product-variant.ts index 3408995c474f7..e23297f608f27 100644 --- a/packages/modules/product/src/models/product-variant.ts +++ b/packages/modules/product/src/models/product-variant.ts @@ -1,22 +1,4 @@ -import { - createPsqlIndexStatementHelper, - DALUtils, - generateEntityId, - model, - Searchable, -} from "@medusajs/framework/utils" -import { - BeforeCreate, - Collection, - Entity, - Filter, - Index, - ManyToMany, - ManyToOne, - OnInit, - PrimaryKey, - Property, -} from "@mikro-orm/core" +import { model } from "@medusajs/framework/utils" import { Product, ProductOptionValue } from "@models" const variantSkuIndexName = "IDX_product_variant_sku_unique" @@ -129,95 +111,95 @@ const ProductVariantDML = model // variantUpcIndexStatement.MikroORMIndex() // @Entity({ tableName: "product_variant" }) // @Filter(DALUtils.mikroOrmSoftDeletableFilterOptions) -class ProductVariant { - // @PrimaryKey({ columnType: "text" }) - // id!: string - // @Searchable() - // @Property({ columnType: "text" }) - // title: string - // @Searchable() - // @Property({ columnType: "text", nullable: true }) - // sku?: string | null - // @Searchable() - // @Property({ columnType: "text", nullable: true }) - // barcode?: string | null - // @Searchable() - // @Property({ columnType: "text", nullable: true }) - // ean?: string | null - // @Searchable() - // @Property({ columnType: "text", nullable: true }) - // upc?: string | null - // @Property({ columnType: "boolean", default: false }) - // allow_backorder?: boolean = false - // @Property({ columnType: "boolean", default: true }) - // manage_inventory?: boolean = true - // @Property({ columnType: "text", nullable: true }) - // hs_code?: string | null - // @Property({ columnType: "text", nullable: true }) - // origin_country?: string | null - // @Property({ columnType: "text", nullable: true }) - // mid_code?: string | null - // @Property({ columnType: "text", nullable: true }) - // material?: string | null - // @Property({ columnType: "numeric", nullable: true }) - // weight?: number | null - // @Property({ columnType: "numeric", nullable: true }) - // length?: number | null - // @Property({ columnType: "numeric", nullable: true }) - // height?: number | null - // @Property({ columnType: "numeric", nullable: true }) - // width?: number | null - // @Property({ columnType: "jsonb", nullable: true }) - // metadata?: Record | null - // @Property({ - // columnType: "integer", - // nullable: true, - // default: 0, - // }) - // variant_rank?: number | null - // @ManyToOne(() => Product, { - // columnType: "text", - // nullable: true, - // onDelete: "cascade", - // fieldName: "product_id", - // mapToPk: true, - // }) - // product_id: string | null - // @ManyToOne(() => Product, { - // persist: false, - // nullable: true, - // }) - // product: Product | null - // @ManyToMany(() => ProductOptionValue, "variants", { - // owner: true, - // pivotTable: "product_variant_option", - // joinColumn: "variant_id", - // inverseJoinColumn: "option_value_id", - // }) - // options = new Collection(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: "IDX_product_variant_deleted_at" }) - // @Property({ columnType: "timestamptz", nullable: true }) - // deleted_at?: Date - // @OnInit() - // @BeforeCreate() - // onInit() { - // this.id = generateEntityId(this.id, "variant") - // this.product_id ??= this.product?.id ?? null - // } -} +// class ProductVariant { +// @PrimaryKey({ columnType: "text" }) +// id!: string +// @Searchable() +// @Property({ columnType: "text" }) +// title: string +// @Searchable() +// @Property({ columnType: "text", nullable: true }) +// sku?: string | null +// @Searchable() +// @Property({ columnType: "text", nullable: true }) +// barcode?: string | null +// @Searchable() +// @Property({ columnType: "text", nullable: true }) +// ean?: string | null +// @Searchable() +// @Property({ columnType: "text", nullable: true }) +// upc?: string | null +// @Property({ columnType: "boolean", default: false }) +// allow_backorder?: boolean = false +// @Property({ columnType: "boolean", default: true }) +// manage_inventory?: boolean = true +// @Property({ columnType: "text", nullable: true }) +// hs_code?: string | null +// @Property({ columnType: "text", nullable: true }) +// origin_country?: string | null +// @Property({ columnType: "text", nullable: true }) +// mid_code?: string | null +// @Property({ columnType: "text", nullable: true }) +// material?: string | null +// @Property({ columnType: "numeric", nullable: true }) +// weight?: number | null +// @Property({ columnType: "numeric", nullable: true }) +// length?: number | null +// @Property({ columnType: "numeric", nullable: true }) +// height?: number | null +// @Property({ columnType: "numeric", nullable: true }) +// width?: number | null +// @Property({ columnType: "jsonb", nullable: true }) +// metadata?: Record | null +// @Property({ +// columnType: "integer", +// nullable: true, +// default: 0, +// }) +// variant_rank?: number | null +// @ManyToOne(() => Product, { +// columnType: "text", +// nullable: true, +// onDelete: "cascade", +// fieldName: "product_id", +// mapToPk: true, +// }) +// product_id: string | null +// @ManyToOne(() => Product, { +// persist: false, +// nullable: true, +// }) +// product: Product | null +// @ManyToMany(() => ProductOptionValue, "variants", { +// owner: true, +// pivotTable: "product_variant_option", +// joinColumn: "variant_id", +// inverseJoinColumn: "option_value_id", +// }) +// options = new Collection(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: "IDX_product_variant_deleted_at" }) +// @Property({ columnType: "timestamptz", nullable: true }) +// deleted_at?: Date +// @OnInit() +// @BeforeCreate() +// onInit() { +// this.id = generateEntityId(this.id, "variant") +// this.product_id ??= this.product?.id ?? null +// } +// } export default ProductVariantDML // export default ProductVariant diff --git a/packages/modules/product/src/models/product.ts b/packages/modules/product/src/models/product.ts index c696fe36a8b52..af7930057c372 100644 --- a/packages/modules/product/src/models/product.ts +++ b/packages/modules/product/src/models/product.ts @@ -1,27 +1,4 @@ -import { - BeforeCreate, - Collection, - Entity, - Enum, - Filter, - Index, - ManyToMany, - ManyToOne, - OneToMany, - OnInit, - PrimaryKey, - Property, -} from "@mikro-orm/core" - -import { - createPsqlIndexStatementHelper, - DALUtils, - generateEntityId, - model, - ProductUtils, - Searchable, - toHandle, -} from "@medusajs/framework/utils" +import { model, ProductUtils } from "@medusajs/framework/utils" import ProductCategory from "./product-category" import ProductCollection from "./product-collection" import ProductImage from "./product-image" @@ -121,133 +98,133 @@ export const ProductDML = model // productHandleIndexStatement.MikroORMIndex() // @Entity({ tableName: "product" }) // @Filter(DALUtils.mikroOrmSoftDeletableFilterOptions) -class Product { - // @PrimaryKey({ columnType: "text" }) - // id!: string - // @Searchable() - // @Property({ columnType: "text" }) - // title: string - // @Property({ columnType: "text" }) - // handle?: string - // @Searchable() - // @Property({ columnType: "text", nullable: true }) - // subtitle?: string | null - // @Searchable() - // @Property({ - // columnType: "text", - // nullable: true, - // }) - // description?: string | null - // @Property({ columnType: "boolean", default: false }) - // is_giftcard!: boolean - // @Enum(() => ProductUtils.ProductStatus) - // @Property({ default: ProductUtils.ProductStatus.DRAFT }) - // status!: ProductUtils.ProductStatus - // @Property({ columnType: "text", nullable: true }) - // thumbnail?: string | null - // @OneToMany(() => ProductOption, (o) => o.product, { - // cascade: ["soft-remove"] as any, - // }) - // options = new Collection(this) - // @Searchable() - // @OneToMany(() => ProductVariant, (variant) => variant.product, { - // cascade: ["soft-remove"] as any, - // }) - // variants = new Collection(this) - // @Property({ columnType: "text", nullable: true }) - // weight?: number | null - // @Property({ columnType: "text", nullable: true }) - // length?: number | null - // @Property({ columnType: "text", nullable: true }) - // height?: number | null - // @Property({ columnType: "text", nullable: true }) - // width?: number | null - // @Property({ columnType: "text", nullable: true }) - // origin_country?: string | null - // @Property({ columnType: "text", nullable: true }) - // hs_code?: string | null - // @Property({ columnType: "text", nullable: true }) - // mid_code?: string | null - // @Property({ columnType: "text", nullable: true }) - // material?: string | null - // @Searchable() - // @ManyToOne(() => ProductCollection, { - // columnType: "text", - // nullable: true, - // fieldName: "collection_id", - // mapToPk: true, - // onDelete: "set null", - // }) - // collection_id: string | null - // @ManyToOne(() => ProductCollection, { - // nullable: true, - // persist: false, - // }) - // collection: ProductCollection | null - // @ManyToOne(() => ProductType, { - // columnType: "text", - // nullable: true, - // fieldName: "type_id", - // mapToPk: true, - // onDelete: "set null", - // }) - // type_id: string | null - // @ManyToOne(() => ProductType, { - // nullable: true, - // persist: false, - // }) - // type: ProductType | null - // @ManyToMany(() => ProductTag, "products", { - // owner: true, - // pivotTable: "product_tags", - // index: "IDX_product_tag_id", - // }) - // tags = new Collection(this) - // @ManyToMany(() => ProductImage, "products", { - // owner: true, - // pivotTable: "product_images", - // joinColumn: "product_id", - // inverseJoinColumn: "image_id", - // }) - // images = new Collection(this) - // @ManyToMany(() => ProductCategory, "products", { - // owner: true, - // pivotTable: "product_category_product", - // }) - // categories = new Collection(this) - // @Property({ columnType: "boolean", default: true }) - // discountable: boolean - // @Property({ columnType: "text", nullable: true }) - // external_id?: string | 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 - // @Index({ name: "IDX_product_deleted_at" }) - // @Property({ columnType: "timestamptz", nullable: true }) - // deleted_at?: Date - // @Property({ columnType: "jsonb", nullable: true }) - // metadata?: Record | null - // @OnInit() - // @BeforeCreate() - // onInit() { - // this.id = generateEntityId(this.id, "prod") - // this.type_id ??= this.type?.id ?? null - // this.collection_id ??= this.collection?.id ?? null - // if (!this.handle && this.title) { - // this.handle = toHandle(this.title) - // } - // } -} +// class Product { +// @PrimaryKey({ columnType: "text" }) +// id!: string +// @Searchable() +// @Property({ columnType: "text" }) +// title: string +// @Property({ columnType: "text" }) +// handle?: string +// @Searchable() +// @Property({ columnType: "text", nullable: true }) +// subtitle?: string | null +// @Searchable() +// @Property({ +// columnType: "text", +// nullable: true, +// }) +// description?: string | null +// @Property({ columnType: "boolean", default: false }) +// is_giftcard!: boolean +// @Enum(() => ProductUtils.ProductStatus) +// @Property({ default: ProductUtils.ProductStatus.DRAFT }) +// status!: ProductUtils.ProductStatus +// @Property({ columnType: "text", nullable: true }) +// thumbnail?: string | null +// @OneToMany(() => ProductOption, (o) => o.product, { +// cascade: ["soft-remove"] as any, +// }) +// options = new Collection(this) +// @Searchable() +// @OneToMany(() => ProductVariant, (variant) => variant.product, { +// cascade: ["soft-remove"] as any, +// }) +// variants = new Collection(this) +// @Property({ columnType: "text", nullable: true }) +// weight?: number | null +// @Property({ columnType: "text", nullable: true }) +// length?: number | null +// @Property({ columnType: "text", nullable: true }) +// height?: number | null +// @Property({ columnType: "text", nullable: true }) +// width?: number | null +// @Property({ columnType: "text", nullable: true }) +// origin_country?: string | null +// @Property({ columnType: "text", nullable: true }) +// hs_code?: string | null +// @Property({ columnType: "text", nullable: true }) +// mid_code?: string | null +// @Property({ columnType: "text", nullable: true }) +// material?: string | null +// @Searchable() +// @ManyToOne(() => ProductCollection, { +// columnType: "text", +// nullable: true, +// fieldName: "collection_id", +// mapToPk: true, +// onDelete: "set null", +// }) +// collection_id: string | null +// @ManyToOne(() => ProductCollection, { +// nullable: true, +// persist: false, +// }) +// collection: ProductCollection | null +// @ManyToOne(() => ProductType, { +// columnType: "text", +// nullable: true, +// fieldName: "type_id", +// mapToPk: true, +// onDelete: "set null", +// }) +// type_id: string | null +// @ManyToOne(() => ProductType, { +// nullable: true, +// persist: false, +// }) +// type: ProductType | null +// @ManyToMany(() => ProductTag, "products", { +// owner: true, +// pivotTable: "product_tags", +// index: "IDX_product_tag_id", +// }) +// tags = new Collection(this) +// @ManyToMany(() => ProductImage, "products", { +// owner: true, +// pivotTable: "product_images", +// joinColumn: "product_id", +// inverseJoinColumn: "image_id", +// }) +// images = new Collection(this) +// @ManyToMany(() => ProductCategory, "products", { +// owner: true, +// pivotTable: "product_category_product", +// }) +// categories = new Collection(this) +// @Property({ columnType: "boolean", default: true }) +// discountable: boolean +// @Property({ columnType: "text", nullable: true }) +// external_id?: string | 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 +// @Index({ name: "IDX_product_deleted_at" }) +// @Property({ columnType: "timestamptz", nullable: true }) +// deleted_at?: Date +// @Property({ columnType: "jsonb", nullable: true }) +// metadata?: Record | null +// @OnInit() +// @BeforeCreate() +// onInit() { +// this.id = generateEntityId(this.id, "prod") +// this.type_id ??= this.type?.id ?? null +// this.collection_id ??= this.collection?.id ?? null +// if (!this.handle && this.title) { +// this.handle = toHandle(this.title) +// } +// } +// } export default ProductDML // export default Product diff --git a/packages/modules/product/src/repositories/product-category.ts b/packages/modules/product/src/repositories/product-category.ts index b3374d1aebad0..77388f9a012b6 100644 --- a/packages/modules/product/src/repositories/product-category.ts +++ b/packages/modules/product/src/repositories/product-category.ts @@ -1,12 +1,14 @@ import { Context, DAL, + InferEntityType, ProductCategoryTransformOptions, ProductTypes, } from "@medusajs/framework/types" import { DALUtils, isDefined, MedusaError } from "@medusajs/framework/utils" import { FilterQuery as MikroFilterQuery, + FindOptions, FindOptions as MikroOptions, LoadStrategy, } from "@mikro-orm/core" @@ -15,9 +17,11 @@ import { ProductCategory } from "@models" import { UpdateCategoryInput } from "@types" // eslint-disable-next-line max-len -export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeRepository { +export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeRepository< + typeof ProductCategory +> { buildFindOptions( - findOptions: DAL.FindOptions = { where: {} }, + findOptions: DAL.FindOptions = { where: {} }, familyOptions: ProductCategoryTransformOptions = {} ) { const findOptions_ = { ...findOptions } @@ -67,18 +71,18 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito } async find( - findOptions: DAL.FindOptions = { where: {} }, + findOptions: DAL.FindOptions = { where: {} }, transformOptions: ProductCategoryTransformOptions = {}, context: Context = {} - ): Promise { + ): Promise[]> { const manager = super.getActiveManager(context) const findOptions_ = this.buildFindOptions(findOptions, transformOptions) - const productCategories = await manager.find( - ProductCategory, - findOptions_.where as MikroFilterQuery, - { ...findOptions_.options } as MikroOptions - ) + const productCategories = (await manager.find( + ProductCategory.name, + findOptions_.where, + { ...findOptions_.options } as any // TODO + )) as InferEntityType[] if ( !transformOptions.includeDescendantsTree && @@ -100,7 +104,9 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito return this.sortCategoriesByRank(categoriesTree) } - sortCategoriesByRank(categories: ProductCategory[]): ProductCategory[] { + sortCategoriesByRank( + categories: InferEntityType[] + ): InferEntityType[] { const sortedCategories = categories.sort((a, b) => a.rank - b.rank) for (const category of sortedCategories) { @@ -120,10 +126,10 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito descendants?: boolean ancestors?: boolean }, - productCategories: ProductCategory[], - findOptions: DAL.FindOptions = { where: {} }, + productCategories: InferEntityType[], + findOptions: DAL.FindOptions = { where: {} }, context: Context = {} - ): Promise { + ): Promise[]> { const manager = super.getActiveManager(context) // We dont want to get the relations as we will fetch all the categories and build the tree manually @@ -165,15 +171,15 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito ...findOptions.options, limit: undefined, offset: 0, - } as MikroOptions + } as FindOptions delete where.id delete where.mpath - delete where.parent_category_id + delete where["parent_category_id"] // TODO: Dml should include foreign keys - const categoriesInTree = await this.serialize( - await manager.find(ProductCategory, where, options) - ) + const categoriesInTree = await this.serialize< + InferEntityType[] + >(await manager.find(ProductCategory.name, where, options)) const categoriesById = new Map(categoriesInTree.map((cat) => [cat.id, cat])) @@ -188,7 +194,7 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito const populateChildren = (category, level = 0) => { const categories = categoriesInTree.filter( - (child) => child.parent_category_id === category.id + (child) => child['parent_category_id'] === category.id // TODO: Dml should include foreign keys ) if (include.descendants) { @@ -225,18 +231,18 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito } async findAndCount( - findOptions: DAL.FindOptions = { where: {} }, + findOptions: DAL.FindOptions = { where: {} }, transformOptions: ProductCategoryTransformOptions = {}, context: Context = {} - ): Promise<[ProductCategory[], number]> { + ): Promise<[InferEntityType[], number]> { const manager = super.getActiveManager(context) const findOptions_ = this.buildFindOptions(findOptions, transformOptions) - const [productCategories, count] = await manager.findAndCount( - ProductCategory, + const [productCategories, count] = (await manager.findAndCount( + ProductCategory.name, findOptions_.where as MikroFilterQuery, findOptions_.options as MikroOptions - ) + )) as [InferEntityType[], number] if ( !transformOptions.includeDescendantsTree && @@ -261,21 +267,23 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito async delete(ids: string[], context: Context = {}): Promise { const manager = super.getActiveManager(context) await this.baseDelete(ids, context) - await manager.nativeDelete(ProductCategory, { id: ids }, {}) + await manager.nativeDelete(ProductCategory.name, { id: ids }, {}) } async softDelete( ids: string[], context: Context = {} - ): Promise<[ProductCategory[], Record]> { + ): Promise< + [InferEntityType[], Record] + > { const manager = super.getActiveManager(context) await this.baseDelete(ids, context) const categories = await Promise.all( ids.map(async (id) => { - const productCategory = await manager.findOne(ProductCategory, { + const productCategory = (await manager.findOne(ProductCategory.name, { id, - }) + })) as InferEntityType if (!productCategory) { throw new MedusaError( @@ -296,13 +304,18 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito async restore( ids: string[], context: Context = {} - ): Promise<[ProductCategory[], Record]> { + ): Promise< + [InferEntityType[], Record] + > { const manager = super.getActiveManager(context) const categories = await Promise.all( ids.map(async (id) => { - const productCategory = await manager.findOneOrFail(ProductCategory, { - id, - }) + const productCategory = (await manager.findOneOrFail( + ProductCategory.name, + { + id, + } + )) as InferEntityType manager.assign(productCategory, { deleted_at: null }) return productCategory }) @@ -317,13 +330,13 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito await Promise.all( ids.map(async (id) => { - const productCategory = await manager.findOne( - ProductCategory, + const productCategory = (await manager.findOne( + ProductCategory.name, { id }, { populate: ["category_children"], - } - ) + } as any // TODO + )) as InferEntityType if (!productCategory) { throw new MedusaError( @@ -353,7 +366,7 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito const categories = await Promise.all( data.map(async (entry, i) => { const categoryData: Partial = { ...entry } - const siblingsCount = await manager.count(ProductCategory, { + const siblingsCount = await manager.count(ProductCategory.name, { parent_category_id: categoryData?.parent_category_id || null, }) @@ -387,7 +400,10 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito categoryData.mpath = parentCategory.mpath } - return manager.create(ProductCategory, categoryData as ProductCategory) + return manager.create( + ProductCategory.name, + categoryData as ProductCategory + ) }) ) @@ -403,7 +419,7 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito const categories = await Promise.all( data.map(async (entry, i) => { const categoryData: Partial = { ...entry } - const productCategory = await manager.findOne(ProductCategory, { + const productCategory = await manager.findOne(ProductCategory.name, { id: categoryData.id, }) @@ -452,7 +468,7 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito } // Rerank the siblings in the new parent - const siblingsCount = await manager.count(ProductCategory, { + const siblingsCount = await manager.count(ProductCategory.name, { parent_category_id: categoryData.parent_category_id, }) @@ -479,7 +495,7 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito return productCategory // If only the rank changed, we need to rerank all siblings. } else if (isDefined(categoryData.rank)) { - const siblingsCount = await manager.count(ProductCategory, { + const siblingsCount = await manager.count(ProductCategory.name, { parent_category_id: productCategory.parent_category_id, }) @@ -514,7 +530,7 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito manager: SqlEntityManager, removedSibling: Partial ) { - const affectedSiblings = await manager.find(ProductCategory, { + const affectedSiblings = await manager.find(ProductCategory.name, { parent_category_id: removedSibling.parent_category_id, rank: { $gt: removedSibling.rank }, }) @@ -531,7 +547,7 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito manager: SqlEntityManager, addedSibling: Partial ) { - const affectedSiblings = await manager.find(ProductCategory, { + const affectedSiblings = await manager.find(ProductCategory.name, { parent_category_id: addedSibling.parent_category_id, rank: { $gte: addedSibling.rank }, }) From 34c8b4c9085490050de64919fcfe9ec85508f1a9 Mon Sep 17 00:00:00 2001 From: adrien2p Date: Tue, 12 Nov 2024 17:13:51 +0100 Subject: [PATCH 006/175] Add foreign key as part of the inferred DML type --- packages/core/types/src/dml/index.ts | 28 ++++++++++--------- .../src/repositories/product-category.ts | 19 +++++-------- 2 files changed, 22 insertions(+), 25 deletions(-) diff --git a/packages/core/types/src/dml/index.ts b/packages/core/types/src/dml/index.ts index e53b9196e7f16..75d03284400e4 100644 --- a/packages/core/types/src/dml/index.ts +++ b/packages/core/types/src/dml/index.ts @@ -181,19 +181,21 @@ export type InferManyToManyFields = InferHasManyFields * Inferring the types of the schema fields from the DML * entity */ -export type InferSchemaFields = Prettify<{ - [K in keyof Schema]: Schema[K] extends RelationshipType - ? Schema[K]["type"] extends "belongsTo" - ? InferBelongsToFields - : Schema[K]["type"] extends "hasOne" - ? InferHasOneFields - : Schema[K]["type"] extends "hasMany" - ? InferHasManyFields - : Schema[K]["type"] extends "manyToMany" - ? InferManyToManyFields - : never - : Schema[K]["$dataType"] -}> +export type InferSchemaFields = Prettify< + { + [K in keyof Schema]: Schema[K] extends RelationshipType + ? Schema[K]["type"] extends "belongsTo" + ? InferBelongsToFields + : Schema[K]["type"] extends "hasOne" + ? InferHasOneFields + : Schema[K]["type"] extends "hasMany" + ? InferHasManyFields + : Schema[K]["type"] extends "manyToMany" + ? InferManyToManyFields + : never + : Schema[K]["$dataType"] + } & InferForeignKeys +> /** * Helper to infer the schema type of a DmlEntity diff --git a/packages/modules/product/src/repositories/product-category.ts b/packages/modules/product/src/repositories/product-category.ts index 77388f9a012b6..60f727bd29de5 100644 --- a/packages/modules/product/src/repositories/product-category.ts +++ b/packages/modules/product/src/repositories/product-category.ts @@ -6,12 +6,7 @@ import { ProductTypes, } from "@medusajs/framework/types" import { DALUtils, isDefined, MedusaError } from "@medusajs/framework/utils" -import { - FilterQuery as MikroFilterQuery, - FindOptions, - FindOptions as MikroOptions, - LoadStrategy, -} from "@mikro-orm/core" +import { FindOptions, LoadStrategy } from "@mikro-orm/core" import { SqlEntityManager } from "@mikro-orm/postgresql" import { ProductCategory } from "@models" import { UpdateCategoryInput } from "@types" @@ -82,7 +77,7 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito ProductCategory.name, findOptions_.where, { ...findOptions_.options } as any // TODO - )) as InferEntityType[] + )) as unknown as InferEntityType[] if ( !transformOptions.includeDescendantsTree && @@ -175,7 +170,7 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito delete where.id delete where.mpath - delete where["parent_category_id"] // TODO: Dml should include foreign keys + delete where.parent_category_id const categoriesInTree = await this.serialize< InferEntityType[] @@ -194,7 +189,7 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito const populateChildren = (category, level = 0) => { const categories = categoriesInTree.filter( - (child) => child['parent_category_id'] === category.id // TODO: Dml should include foreign keys + (child) => child.parent_category_id === category.id ) if (include.descendants) { @@ -240,9 +235,9 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito const [productCategories, count] = (await manager.findAndCount( ProductCategory.name, - findOptions_.where as MikroFilterQuery, - findOptions_.options as MikroOptions - )) as [InferEntityType[], number] + findOptions_.where, + findOptions_.options as any + )) as unknown as [InferEntityType[], number] if ( !transformOptions.includeDescendantsTree && From 74f67f0d879d6ad2a57967781b95cfe4ab8d8bab Mon Sep 17 00:00:00 2001 From: adrien2p Date: Tue, 12 Nov 2024 18:02:11 +0100 Subject: [PATCH 007/175] ../../core/types/src/dml/index.ts --- packages/core/types/src/dml/index.ts | 4 +++- .../product/src/repositories/product-category.ts | 14 ++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/packages/core/types/src/dml/index.ts b/packages/core/types/src/dml/index.ts index 75d03284400e4..c74592d2cf0a9 100644 --- a/packages/core/types/src/dml/index.ts +++ b/packages/core/types/src/dml/index.ts @@ -140,7 +140,9 @@ export type InferForeignKeys = { : never : never]: Schema[K] extends { type: infer Type } ? Type extends RelationshipTypes - ? string + ? Schema[K]["$dataType"] extends IDmlEntity | null + ? true + : false : never : never } diff --git a/packages/modules/product/src/repositories/product-category.ts b/packages/modules/product/src/repositories/product-category.ts index 60f727bd29de5..6f20e856cb1c2 100644 --- a/packages/modules/product/src/repositories/product-category.ts +++ b/packages/modules/product/src/repositories/product-category.ts @@ -355,12 +355,14 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito async create( data: ProductTypes.CreateProductCategoryDTO[], context: Context = {} - ): Promise { + ): Promise[]> { const manager = super.getActiveManager(context) const categories = await Promise.all( data.map(async (entry, i) => { - const categoryData: Partial = { ...entry } + const categoryData: Partial> = { + ...entry, + } const siblingsCount = await manager.count(ProductCategory.name, { parent_category_id: categoryData?.parent_category_id || null, }) @@ -381,7 +383,7 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito if (parentCategoryId) { const parentCategory = await manager.findOne( - ProductCategory, + ProductCategory.name, parentCategoryId ) @@ -450,7 +452,7 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito categoryData.mpath = "" } else { const newParentCategory = await manager.findOne( - ProductCategory, + ProductCategory.name, categoryData.parent_category_id ) if (!newParentCategory) { @@ -566,7 +568,7 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito if (originalSibling.rank < updatedSibling.rank) { const siblings = await manager.find( - ProductCategory, + ProductCategory.name, { parent_category_id: originalSibling.parent_category_id, rank: { $gt: originalSibling.rank, $lte: updatedSibling.rank }, @@ -582,7 +584,7 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito manager.persist(updatedSiblings) } else { const siblings = await manager.find( - ProductCategory, + ProductCategory.name, { parent_category_id: originalSibling.parent_category_id, rank: { $gte: updatedSibling.rank, $lt: originalSibling.rank }, From af6ea07f676262d69627a9e9d6fab8c2e3a37ca1 Mon Sep 17 00:00:00 2001 From: adrien2p Date: Tue, 12 Nov 2024 18:02:27 +0100 Subject: [PATCH 008/175] ../../core/types/src/dml/index.ts --- packages/core/types/src/dml/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/core/types/src/dml/index.ts b/packages/core/types/src/dml/index.ts index c74592d2cf0a9..738119fd3f4b0 100644 --- a/packages/core/types/src/dml/index.ts +++ b/packages/core/types/src/dml/index.ts @@ -141,8 +141,8 @@ export type InferForeignKeys = { : never]: Schema[K] extends { type: infer Type } ? Type extends RelationshipTypes ? Schema[K]["$dataType"] extends IDmlEntity | null - ? true - : false + ? string | null + : string : never : never } From 5f57aec05bd098c713786742239191e6d66d5d8c Mon Sep 17 00:00:00 2001 From: Harminder Virk Date: Wed, 13 Nov 2024 12:36:05 +0530 Subject: [PATCH 009/175] fix: relationships mapping --- .../product/src/models/product-category.ts | 8 +++++--- .../product/src/models/product-collection.ts | 4 +++- .../src/models/product-option-value.ts | 10 ++++++++-- .../product/src/models/product-option.ts | 8 ++++++-- .../modules/product/src/models/product-tag.ts | 4 +++- .../product/src/models/product-variant.ts | 7 ++++++- .../modules/product/src/models/product.ts | 20 +++++++++++++++---- 7 files changed, 47 insertions(+), 14 deletions(-) diff --git a/packages/modules/product/src/models/product-category.ts b/packages/modules/product/src/models/product-category.ts index be684f6205f48..6a8c4b676e6be 100644 --- a/packages/modules/product/src/models/product-category.ts +++ b/packages/modules/product/src/models/product-category.ts @@ -30,12 +30,14 @@ const ProductCategoryDML = model is_internal: model.boolean().default(false), rank: model.number().default(0), metadata: model.json().nullable(), - parent_category: model.belongsTo(() => ProductCategoryDML).nullable(), - category_children: model + parent_category: model .belongsTo(() => ProductCategoryDML, { - mappedBy: "parent_category", + mappedBy: "category_children", }) .nullable(), + category_children: model.hasMany(() => ProductCategoryDML, { + mappedBy: "parent_category", + }), products: model.manyToMany(() => Product), }) .indexes([ diff --git a/packages/modules/product/src/models/product-collection.ts b/packages/modules/product/src/models/product-collection.ts index f1203080a5481..9306c50d05cce 100644 --- a/packages/modules/product/src/models/product-collection.ts +++ b/packages/modules/product/src/models/product-collection.ts @@ -16,7 +16,9 @@ const ProductCollectionDML = model title: model.text().searchable(), handle: model.text().nullable(), metadata: model.json().nullable(), - products: model.hasMany(() => Product), + products: model.hasMany(() => Product, { + mappedBy: "collection", + }), }) .indexes([ { diff --git a/packages/modules/product/src/models/product-option-value.ts b/packages/modules/product/src/models/product-option-value.ts index 4722d618ac084..d0264e7174624 100644 --- a/packages/modules/product/src/models/product-option-value.ts +++ b/packages/modules/product/src/models/product-option-value.ts @@ -15,8 +15,14 @@ const ProductOptionValueDML = model id: model.id().primaryKey(), value: model.text(), metadata: model.json().nullable(), - option: model.belongsTo(() => ProductOption).nullable(), - variants: model.manyToMany(() => ProductVariant), + option: model + .belongsTo(() => ProductOption, { + mappedBy: "values", + }) + .nullable(), + variants: model.manyToMany(() => ProductVariant, { + mappedBy: "options", + }), }) .indexes([ { diff --git a/packages/modules/product/src/models/product-option.ts b/packages/modules/product/src/models/product-option.ts index 9b6ec1b62726f..87d73321179de 100644 --- a/packages/modules/product/src/models/product-option.ts +++ b/packages/modules/product/src/models/product-option.ts @@ -16,8 +16,12 @@ const ProductOptionDML = model id: model.id().primaryKey(), title: model.text().searchable(), metadata: model.json().nullable(), - product: model.belongsTo(() => Product), - values: model.hasMany(() => ProductOptionValue), + product: model.belongsTo(() => Product, { + mappedBy: "options", + }), + values: model.hasMany(() => ProductOptionValue, { + mappedBy: "option", + }), }) .cascades({ delete: ["values"], diff --git a/packages/modules/product/src/models/product-tag.ts b/packages/modules/product/src/models/product-tag.ts index 25e6d6b7e3437..2870045f74c09 100644 --- a/packages/modules/product/src/models/product-tag.ts +++ b/packages/modules/product/src/models/product-tag.ts @@ -15,7 +15,9 @@ const ProductTagDML = model id: model.id().primaryKey(), value: model.text().searchable(), metadata: model.json().nullable(), - product: model.manyToMany(() => Product), + product: model.manyToMany(() => Product, { + mappedBy: "tags", + }), }) .indexes([ { diff --git a/packages/modules/product/src/models/product-variant.ts b/packages/modules/product/src/models/product-variant.ts index e23297f608f27..2ea73d3e343ae 100644 --- a/packages/modules/product/src/models/product-variant.ts +++ b/packages/modules/product/src/models/product-variant.ts @@ -66,9 +66,14 @@ const ProductVariantDML = model width: model.number().nullable(), metadata: model.json().nullable(), variant_rank: model.number().default(0).nullable(), - product: model.belongsTo(() => Product).nullable(), + product: model + .belongsTo(() => Product, { + mappedBy: "variants", + }) + .nullable(), options: model.manyToMany(() => ProductOptionValue, { pivotTable: "product_variant_option", + mappedBy: "variants", }), }) .indexes([ diff --git a/packages/modules/product/src/models/product.ts b/packages/modules/product/src/models/product.ts index af7930057c372..3cdc6936bc37b 100644 --- a/packages/modules/product/src/models/product.ts +++ b/packages/modules/product/src/models/product.ts @@ -57,16 +57,28 @@ export const ProductDML = model discountable: model.boolean().default(true), external_id: model.text().nullable(), metadata: model.json().nullable(), - variants: model.hasMany(() => ProductVariant), + variants: model.hasMany(() => ProductVariant, { + mappedBy: "product", + }), type: model.belongsTo(() => ProductType).nullable(), - tags: model.manyToMany(() => ProductTag), - options: model.hasMany(() => ProductOption), + tags: model.manyToMany(() => ProductTag, { + mappedBy: "product", + }), + options: model.hasMany(() => ProductOption, { + mappedBy: "product", + }), images: model.manyToMany(() => ProductImage, { pivotTable: "product_images", + mappedBy: "products", }), - collection: model.belongsTo(() => ProductCollection).nullable(), + collection: model + .belongsTo(() => ProductCollection, { + mappedBy: "products", + }) + .nullable(), categories: model.manyToMany(() => ProductCategory, { pivotTable: "product_category_product", + mappedBy: "products", }), }) .cascades({ From 4a4c9a1b70a7e0c7e1308a0057bb1eb056f4ba7c Mon Sep 17 00:00:00 2001 From: adrien2p Date: Wed, 13 Nov 2024 10:17:07 +0100 Subject: [PATCH 010/175] handle nullable foreign keys types --- packages/core/types/src/dml/index.ts | 25 ++++++++++++++----- .../src/dml/__tests__/entity-builder.spec.ts | 4 +++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/packages/core/types/src/dml/index.ts b/packages/core/types/src/dml/index.ts index 738119fd3f4b0..b9bf19edbcd77 100644 --- a/packages/core/types/src/dml/index.ts +++ b/packages/core/types/src/dml/index.ts @@ -55,6 +55,13 @@ export type RelationshipTypes = | "belongsTo" | "manyToMany" +/** + * Return true if the relationship is nullable + */ +export type IsNullableRelation = T extends () => IDmlEntity | null + ? true + : false + /** * The meta-data returned by the property parse method */ @@ -130,23 +137,29 @@ export interface EntityConstructor extends Function { } /** - * From a IDmlEntity, infer the foreign keys name and type for - * "belongsTo" relation meaning "hasOne" and "ManyToOne" + * Internal separation of the foreign keys retrieval to not have to repeat this loop many times in the type below */ -export type InferForeignKeys = { +export type GetSchemaForeignKeys = { [K in keyof Schema as Schema[K] extends { type: infer Type } - ? Type extends RelationshipTypes + ? Type extends "belongsTo" ? `${K & string}_id` : never : never]: Schema[K] extends { type: infer Type } - ? Type extends RelationshipTypes - ? Schema[K]["$dataType"] extends IDmlEntity | null + ? Type extends "belongsTo" + ? IsNullableRelation extends true ? string | null : string : never : never } +/** + * From a IDmlEntity, infer the foreign keys name and type for + * "belongsTo" relation meaning "hasOne" and "ManyToOne" + */ +export type InferForeignKeys = + GetSchemaForeignKeys extends never ? {} : GetSchemaForeignKeys + /** * Infer fields for a belongsTo relationship */ diff --git a/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts b/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts index 75cd192d5a2a3..2c4b6c27b0442 100644 --- a/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts +++ b/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts @@ -3505,6 +3505,7 @@ describe("Entity builder", () => { email: string isVerified: boolean deleted_at: Date | null + user_id: string user: { id: number username: string @@ -3517,6 +3518,7 @@ describe("Entity builder", () => { email: string isVerified: boolean deleted_at: Date | null + user_id: string user: { id: number username: string @@ -3700,6 +3702,7 @@ describe("Entity builder", () => { email: { email: string isVerified: boolean + user_id: string | null user: { id: number username: string @@ -3710,6 +3713,7 @@ describe("Entity builder", () => { expectTypeOf(new Email()).toMatchTypeOf<{ email: string isVerified: boolean + user_id: string | null user: { id: number username: string From f2c6f7ebe7cbf7d93a899a65f4cc802fea31cdce Mon Sep 17 00:00:00 2001 From: adrien2p Date: Wed, 13 Nov 2024 10:37:32 +0100 Subject: [PATCH 011/175] handle nullable foreign keys types --- packages/core/types/src/dml/index.ts | 16 ++++++---------- .../src/dml/__tests__/entity-builder.spec.ts | 12 +++++++----- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/packages/core/types/src/dml/index.ts b/packages/core/types/src/dml/index.ts index b9bf19edbcd77..fb63af8c161c9 100644 --- a/packages/core/types/src/dml/index.ts +++ b/packages/core/types/src/dml/index.ts @@ -140,16 +140,12 @@ export interface EntityConstructor extends Function { * Internal separation of the foreign keys retrieval to not have to repeat this loop many times in the type below */ export type GetSchemaForeignKeys = { - [K in keyof Schema as Schema[K] extends { type: infer Type } - ? Type extends "belongsTo" - ? `${K & string}_id` - : never - : never]: Schema[K] extends { type: infer Type } - ? Type extends "belongsTo" - ? IsNullableRelation extends true - ? string | null - : string - : never + [K in keyof Schema as Schema[K] extends { type: "belongsTo" } + ? `${K & string}_id` + : never]: Schema[K] extends { type: "belongsTo" } + ? null extends Schema[K]["$dataType"] + ? string | null + : string : never } diff --git a/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts b/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts index 2c4b6c27b0442..d0fbc4f8b54b5 100644 --- a/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts +++ b/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts @@ -992,12 +992,14 @@ describe("Entity builder", () => { }) const User = toMikroORMEntity(user) - expectTypeOf(new User()).toMatchTypeOf<{ + expectTypeOf(new User()).toEqualTypeOf<{ id: number username: string email: string role: "moderator" | "admin" | "guest" deleted_at: Date | null + created_at: Date + updated_at: Date }>() const metaData = MetadataStorage.getMetadataFromDecorator(User) @@ -3505,7 +3507,6 @@ describe("Entity builder", () => { email: string isVerified: boolean deleted_at: Date | null - user_id: string user: { id: number username: string @@ -3513,12 +3514,12 @@ describe("Entity builder", () => { } } }>() + expectTypeOf(new User().email.user_id).toEqualTypeOf() expectTypeOf(new Email()).toMatchTypeOf<{ email: string isVerified: boolean deleted_at: Date | null - user_id: string user: { id: number username: string @@ -3530,6 +3531,7 @@ describe("Entity builder", () => { } } }>() + expectTypeOf(new Email().user_id).toEqualTypeOf() const metaData = MetadataStorage.getMetadataFromDecorator(User) expect(metaData.className).toEqual("User") @@ -3702,18 +3704,17 @@ describe("Entity builder", () => { email: { email: string isVerified: boolean - user_id: string | null user: { id: number username: string } | null } }>() + expectTypeOf(new User().email.user_id).toEqualTypeOf() expectTypeOf(new Email()).toMatchTypeOf<{ email: string isVerified: boolean - user_id: string | null user: { id: number username: string @@ -3723,6 +3724,7 @@ describe("Entity builder", () => { } } | null }>() + expectTypeOf(new Email().user_id).toEqualTypeOf() const metaData = MetadataStorage.getMetadataFromDecorator(User) expect(metaData.className).toEqual("User") From 8e18193412d059bb9ffd3ec9ab9cdac46e4d4490 Mon Sep 17 00:00:00 2001 From: adrien2p Date: Wed, 13 Nov 2024 10:41:26 +0100 Subject: [PATCH 012/175] handle nullable foreign keys types --- packages/core/types/src/dml/index.ts | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/packages/core/types/src/dml/index.ts b/packages/core/types/src/dml/index.ts index fb63af8c161c9..8f7657b3add53 100644 --- a/packages/core/types/src/dml/index.ts +++ b/packages/core/types/src/dml/index.ts @@ -137,9 +137,10 @@ export interface EntityConstructor extends Function { } /** - * Internal separation of the foreign keys retrieval to not have to repeat this loop many times in the type below + * From a IDmlEntity, infer the foreign keys name and type for + * "belongsTo" relation meaning "hasOne" and "ManyToOne" */ -export type GetSchemaForeignKeys = { +export type InferForeignKeys = { [K in keyof Schema as Schema[K] extends { type: "belongsTo" } ? `${K & string}_id` : never]: Schema[K] extends { type: "belongsTo" } @@ -149,13 +150,6 @@ export type GetSchemaForeignKeys = { : never } -/** - * From a IDmlEntity, infer the foreign keys name and type for - * "belongsTo" relation meaning "hasOne" and "ManyToOne" - */ -export type InferForeignKeys = - GetSchemaForeignKeys extends never ? {} : GetSchemaForeignKeys - /** * Infer fields for a belongsTo relationship */ From b28e01648aa7775abfe45f365fec3fe9acdd24ce Mon Sep 17 00:00:00 2001 From: adrien2p Date: Wed, 13 Nov 2024 10:53:29 +0100 Subject: [PATCH 013/175] continue to update product category repository --- .../src/repositories/product-category.ts | 81 +++++++++++-------- 1 file changed, 49 insertions(+), 32 deletions(-) diff --git a/packages/modules/product/src/repositories/product-category.ts b/packages/modules/product/src/repositories/product-category.ts index 6f20e856cb1c2..54a762fe58395 100644 --- a/packages/modules/product/src/repositories/product-category.ts +++ b/packages/modules/product/src/repositories/product-category.ts @@ -73,11 +73,13 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito const manager = super.getActiveManager(context) const findOptions_ = this.buildFindOptions(findOptions, transformOptions) - const productCategories = (await manager.find( + const productCategories = await manager.find< + InferEntityType + >( ProductCategory.name, findOptions_.where, { ...findOptions_.options } as any // TODO - )) as unknown as InferEntityType[] + ) if ( !transformOptions.includeDescendantsTree && @@ -276,9 +278,11 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito const categories = await Promise.all( ids.map(async (id) => { - const productCategory = (await manager.findOne(ProductCategory.name, { + const productCategory = await manager.findOne< + InferEntityType + >(ProductCategory.name, { id, - })) as InferEntityType + }) if (!productCategory) { throw new MedusaError( @@ -305,12 +309,11 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito const manager = super.getActiveManager(context) const categories = await Promise.all( ids.map(async (id) => { - const productCategory = (await manager.findOneOrFail( - ProductCategory.name, - { - id, - } - )) as InferEntityType + const productCategory = await manager.findOneOrFail< + InferEntityType + >(ProductCategory.name, { + id, + }) manager.assign(productCategory, { deleted_at: null }) return productCategory }) @@ -325,13 +328,15 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito await Promise.all( ids.map(async (id) => { - const productCategory = (await manager.findOne( + const productCategory = await manager.findOne< + InferEntityType + >( ProductCategory.name, { id }, { populate: ["category_children"], } as any // TODO - )) as InferEntityType + ) if (!productCategory) { throw new MedusaError( @@ -382,10 +387,9 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito categoryData.parent_category_id ?? categoryData.parent_category?.id if (parentCategoryId) { - const parentCategory = await manager.findOne( - ProductCategory.name, - parentCategoryId - ) + const parentCategory = await manager.findOne< + InferEntityType + >(ProductCategory.name, parentCategoryId) if (!parentCategory) { throw new MedusaError( @@ -397,9 +401,9 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito categoryData.mpath = parentCategory.mpath } - return manager.create( + return manager.create>( ProductCategory.name, - categoryData as ProductCategory + categoryData as unknown as InferEntityType ) }) ) @@ -411,12 +415,16 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito async update( data: UpdateCategoryInput[], context: Context = {} - ): Promise { + ): Promise[]> { const manager = super.getActiveManager(context) const categories = await Promise.all( data.map(async (entry, i) => { - const categoryData: Partial = { ...entry } - const productCategory = await manager.findOne(ProductCategory.name, { + const categoryData: Partial> = { + ...entry, + } + const productCategory = await manager.findOne< + InferEntityType + >(ProductCategory.name, { id: categoryData.id, }) @@ -451,10 +459,9 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito if (categoryData.parent_category_id === null) { categoryData.mpath = "" } else { - const newParentCategory = await manager.findOne( - ProductCategory.name, - categoryData.parent_category_id - ) + const newParentCategory = await manager.findOne< + InferEntityType + >(ProductCategory.name, categoryData.parent_category_id) if (!newParentCategory) { throw new MedusaError( MedusaError.Types.INVALID_ARGUMENT, @@ -504,7 +511,9 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito await this.rerankAllSiblings( manager, productCategory, - categoryData as ProductCategory + categoryData as Partial> & { + rank: number + } ) } @@ -525,9 +534,11 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito protected async rerankSiblingsAfterDeletion( manager: SqlEntityManager, - removedSibling: Partial + removedSibling: Partial> ) { - const affectedSiblings = await manager.find(ProductCategory.name, { + const affectedSiblings = await manager.find< + InferEntityType + >(ProductCategory.name, { parent_category_id: removedSibling.parent_category_id, rank: { $gt: removedSibling.rank }, }) @@ -542,9 +553,11 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito protected async rerankSiblingsAfterCreation( manager: SqlEntityManager, - addedSibling: Partial + addedSibling: Partial> ) { - const affectedSiblings = await manager.find(ProductCategory.name, { + const affectedSiblings = await manager.find< + InferEntityType + >(ProductCategory.name, { parent_category_id: addedSibling.parent_category_id, rank: { $gte: addedSibling.rank }, }) @@ -559,8 +572,12 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito protected async rerankAllSiblings( manager: SqlEntityManager, - originalSibling: Partial & { rank: number }, - updatedSibling: Partial & { rank: number } + originalSibling: Partial> & { + rank: number + }, + updatedSibling: Partial> & { + rank: number + } ) { if (originalSibling.rank === updatedSibling.rank) { return From a6a02c2ded90a00b4433425dba51421d482f18d1 Mon Sep 17 00:00:00 2001 From: adrien2p Date: Wed, 13 Nov 2024 11:28:03 +0100 Subject: [PATCH 014/175] fix all product category repositories issues --- .../modules/product/src/repositories/product-category.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/modules/product/src/repositories/product-category.ts b/packages/modules/product/src/repositories/product-category.ts index 54a762fe58395..6397b5432ed17 100644 --- a/packages/modules/product/src/repositories/product-category.ts +++ b/packages/modules/product/src/repositories/product-category.ts @@ -584,7 +584,9 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito } if (originalSibling.rank < updatedSibling.rank) { - const siblings = await manager.find( + const siblings = await manager.find< + InferEntityType + >( ProductCategory.name, { parent_category_id: originalSibling.parent_category_id, @@ -600,7 +602,9 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito manager.persist(updatedSiblings) } else { - const siblings = await manager.find( + const siblings = await manager.find< + InferEntityType + >( ProductCategory.name, { parent_category_id: originalSibling.parent_category_id, From 7c4685879c04127ca012f4c6cb5125424fa0bb1c Mon Sep 17 00:00:00 2001 From: adrien2p Date: Wed, 13 Nov 2024 13:55:28 +0100 Subject: [PATCH 015/175] fix product category service types --- .../product/src/services/product-category.ts | 41 ++++++++----------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/packages/modules/product/src/services/product-category.ts b/packages/modules/product/src/services/product-category.ts index 59791bbed8174..b97033b75b83e 100644 --- a/packages/modules/product/src/services/product-category.ts +++ b/packages/modules/product/src/services/product-category.ts @@ -2,6 +2,7 @@ import { Context, DAL, FindConfig, + InferEntityType, ProductTypes, } from "@medusajs/framework/types" import { @@ -33,7 +34,7 @@ export default class ProductCategoryService { productCategoryId: string, config: FindConfig = {}, @MedusaContext() sharedContext: Context = {} - ): Promise { + ): Promise> { if (!isDefined(productCategoryId)) { throw new MedusaError( MedusaError.Types.NOT_FOUND, @@ -41,7 +42,7 @@ export default class ProductCategoryService { ) } - const queryOptions = ModulesSdkUtils.buildQuery( + const queryOptions = ModulesSdkUtils.buildQuery( { id: productCategoryId, }, @@ -67,7 +68,7 @@ export default class ProductCategoryService { ) } - return productCategories[0] as typeof ProductCategory + return productCategories[0] } @InjectManager("productCategoryRepository_") @@ -75,7 +76,7 @@ export default class ProductCategoryService { filters: ProductTypes.FilterableProductCategoryProps = {}, config: FindConfig = {}, @MedusaContext() sharedContext: Context = {} - ): Promise<(typeof ProductCategory)[]> { + ): Promise[]> { const transformOptions = { includeDescendantsTree: filters?.include_descendants_tree || false, includeAncestorsTree: filters?.include_ancestors_tree || false, @@ -94,17 +95,14 @@ export default class ProductCategoryService { delete filters.q } - const queryOptions = ModulesSdkUtils.buildQuery( - filters, - config - ) + const queryOptions = ModulesSdkUtils.buildQuery(filters, config) queryOptions.where ??= {} - return (await this.productCategoryRepository_.find( + return await this.productCategoryRepository_.find( queryOptions, transformOptions, sharedContext - )) as (typeof ProductCategory)[] + ) } @InjectManager("productCategoryRepository_") @@ -112,7 +110,7 @@ export default class ProductCategoryService { filters: ProductTypes.FilterableProductCategoryProps = {}, config: FindConfig = {}, @MedusaContext() sharedContext: Context = {} - ): Promise<[(typeof ProductCategory)[], number]> { + ): Promise<[InferEntityType[], number]> { const transformOptions = { includeDescendantsTree: filters?.include_descendants_tree || false, includeAncestorsTree: filters?.include_ancestors_tree || false, @@ -131,37 +129,34 @@ export default class ProductCategoryService { delete filters.q } - const queryOptions = ModulesSdkUtils.buildQuery( - filters, - config - ) + const queryOptions = ModulesSdkUtils.buildQuery(filters, config) queryOptions.where ??= {} - return (await this.productCategoryRepository_.findAndCount( + return await this.productCategoryRepository_.findAndCount( queryOptions, transformOptions, sharedContext - )) as [(typeof ProductCategory)[], number] + ) } @InjectTransactionManager("productCategoryRepository_") async create( data: ProductTypes.CreateProductCategoryDTO[], @MedusaContext() sharedContext: Context = {} - ): Promise<(typeof ProductCategory)[]> { - return (await ( + ): Promise[]> { + return await ( this.productCategoryRepository_ as unknown as ProductCategoryRepository - ).create(data, sharedContext)) as (typeof ProductCategory)[] + ).create(data, sharedContext) } @InjectTransactionManager("productCategoryRepository_") async update( data: UpdateCategoryInput[], @MedusaContext() sharedContext: Context = {} - ): Promise<(typeof ProductCategory)[]> { - return (await ( + ): Promise[]> { + return await ( this.productCategoryRepository_ as unknown as ProductCategoryRepository - ).update(data, sharedContext)) as (typeof ProductCategory)[] + ).update(data, sharedContext) } @InjectTransactionManager("productCategoryRepository_") From 9286e06d84fa98e39e5ee88b02ca3e108b4d6df3 Mon Sep 17 00:00:00 2001 From: adrien2p Date: Wed, 13 Nov 2024 14:02:11 +0100 Subject: [PATCH 016/175] fix product module service types --- .../src/services/product-module-service.ts | 53 ++++++++++--------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/packages/modules/product/src/services/product-module-service.ts b/packages/modules/product/src/services/product-module-service.ts index c30091e120000..662f24ff77d8d 100644 --- a/packages/modules/product/src/services/product-module-service.ts +++ b/packages/modules/product/src/services/product-module-service.ts @@ -2,6 +2,7 @@ import { Context, DAL, IEventBusModuleService, + InferEntityType, InternalModuleDeclaration, ModuleJoinerConfig, ModulesSdkTypes, @@ -202,7 +203,7 @@ export default class ProductModuleService protected async createVariants_( data: ProductTypes.CreateProductVariantDTO[], @MedusaContext() sharedContext: Context = {} - ): Promise<(typeof ProductVariant)[]> { + ): Promise[]> { if (data.some((v) => !v.product_id)) { throw new MedusaError( MedusaError.Types.INVALID_DATA, @@ -278,8 +279,8 @@ export default class ProductModuleService (variant): variant is ProductTypes.CreateProductVariantDTO => !variant.id ) - let created: (typeof ProductVariant)[] = [] - let updated: (typeof ProductVariant)[] = [] + let created: InferEntityType[] = [] + let updated: InferEntityType[] = [] if (forCreate.length) { created = await this.createVariants_(forCreate, sharedContext) @@ -346,7 +347,7 @@ export default class ProductModuleService protected async updateVariants_( data: UpdateProductVariantInput[], @MedusaContext() sharedContext: Context = {} - ): Promise<(typeof ProductVariant)[]> { + ): Promise[]> { // Validation step const variantIdsToUpdate = data.map(({ id }) => id) const variants = await this.productVariantService_.list( @@ -481,8 +482,8 @@ export default class ProductModuleService (tag): tag is ProductTypes.CreateProductTagDTO => !tag.id ) - let created: (typeof ProductTag)[] = [] - let updated: (typeof ProductTag)[] = [] + let created: InferEntityType[] = [] + let updated: InferEntityType[] = [] if (forCreate.length) { created = await this.productTagService_.create(forCreate, sharedContext) @@ -611,8 +612,8 @@ export default class ProductModuleService (type): type is ProductTypes.CreateProductTypeDTO => !type.id ) - let created: (typeof ProductType)[] = [] - let updated: (typeof ProductType)[] = [] + let created: InferEntityType[] = [] + let updated: InferEntityType[] = [] if (forCreate.length) { created = await this.productTypeService_.create(forCreate, sharedContext) @@ -709,7 +710,7 @@ export default class ProductModuleService protected async createOptions_( data: ProductTypes.CreateProductOptionDTO[], @MedusaContext() sharedContext: Context = {} - ): Promise { + ): Promise[]> { if (data.some((v) => !v.product_id)) { throw new MedusaError( MedusaError.Types.INVALID_DATA, @@ -756,8 +757,8 @@ export default class ProductModuleService (option): option is ProductTypes.CreateProductOptionDTO => !option.id ) - let created: (typeof ProductOption)[] = [] - let updated: (typeof ProductOption)[] = [] + let created: InferEntityType[] = [] + let updated: InferEntityType[] = [] if (forCreate.length) { created = await this.createOptions_(forCreate, sharedContext) @@ -822,7 +823,7 @@ export default class ProductModuleService protected async updateOptions_( data: UpdateProductOptionInput[], @MedusaContext() sharedContext: Context = {} - ): Promise<(typeof ProductOption)[]> { + ): Promise[]> { // Validation step if (data.some((option) => !option.id)) { throw new MedusaError( @@ -931,7 +932,7 @@ export default class ProductModuleService async createCollections_( data: ProductTypes.CreateProductCollectionDTO[], @MedusaContext() sharedContext: Context = {} - ): Promise<(typeof ProductCollection)[]> { + ): Promise[]> { const normalizedInput = data.map( ProductModuleService.normalizeCreateProductCollectionInput ) @@ -976,8 +977,8 @@ export default class ProductModuleService !collection.id ) - let created: (typeof ProductCollection)[] = [] - let updated: (typeof ProductCollection)[] = [] + let created: InferEntityType[] = [] + let updated: InferEntityType[] = [] if (forCreate.length) { created = await this.createCollections_(forCreate, sharedContext) @@ -1071,7 +1072,7 @@ export default class ProductModuleService protected async updateCollections_( data: UpdateCollectionInput[], @MedusaContext() sharedContext: Context = {} - ): Promise<(typeof ProductCollection)[]> { + ): Promise[]> { const normalizedInput = data.map( ProductModuleService.normalizeUpdateProductCollectionInput ) as UpdateCollectionInput[] @@ -1085,7 +1086,7 @@ export default class ProductModuleService sharedContext ) - const collections: (typeof ProductCollection)[] = [] + const collections: InferEntityType[] = [] const updateSelectorAndData = updatedCollections.flatMap( (collectionData) => { @@ -1124,7 +1125,7 @@ export default class ProductModuleService collections.push({ ...collectionData, products: productsToUpdate ?? [], - } as ProductCollection) + } as InferEntityType) return result } @@ -1201,8 +1202,8 @@ export default class ProductModuleService !category.id ) - let created: (typeof ProductCategory)[] = [] - let updated: (typeof ProductCategory)[] = [] + let created: InferEntityType[] = [] + let updated: InferEntityType[] = [] if (forCreate.length) { created = await this.productCategoryService_.create( @@ -1352,8 +1353,8 @@ export default class ProductModuleService (product): product is ProductTypes.CreateProductDTO => !product.id ) - let created: (typeof Product)[] = [] - let updated: (typeof Product)[] = [] + let created: InferEntityType[] = [] + let updated: InferEntityType[] = [] if (forCreate.length) { created = await this.createProducts_(forCreate, sharedContext) @@ -1440,7 +1441,7 @@ export default class ProductModuleService protected async createProducts_( data: ProductTypes.CreateProductDTO[], @MedusaContext() sharedContext: Context = {} - ): Promise<(typeof Product)[]> { + ): Promise[]> { const normalizedInput = await promiseAll( data.map(async (d) => { const normalized = await this.normalizeCreateProductInput( @@ -1506,7 +1507,7 @@ export default class ProductModuleService protected async updateProducts_( data: UpdateProductInput[], @MedusaContext() sharedContext: Context = {} - ): Promise<(typeof Product)[]> { + ): Promise[]> { const normalizedInput = await promiseAll( data.map(async (d) => { const normalized = await this.normalizeUpdateProductInput( @@ -1766,7 +1767,7 @@ export default class ProductModuleService variants: | ProductTypes.CreateProductVariantDTO[] | ProductTypes.UpdateProductVariantDTO[], - options: (typeof ProductOption)[] + options: InferEntityType[] ): | ProductTypes.CreateProductVariantDTO[] | ProductTypes.UpdateProductVariantDTO[] { @@ -1839,7 +1840,7 @@ export default class ProductModuleService | ProductTypes.CreateProductVariantDTO | UpdateProductVariantInput ) & { options: { id: string }[]; product_id: string })[], - variants: ProductVariant[] + variants: InferEntityType[] ) { for (const variantData of data) { const existingVariant = variants.find((v) => { From 1db0746c0aa2aaca3a4e2f04def869437a0aad09 Mon Sep 17 00:00:00 2001 From: adrien2p Date: Wed, 13 Nov 2024 14:03:52 +0100 Subject: [PATCH 017/175] fix product module service types --- .../src/services/product-module-service.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/modules/product/src/services/product-module-service.ts b/packages/modules/product/src/services/product-module-service.ts index 662f24ff77d8d..a7fd712dbbd26 100644 --- a/packages/modules/product/src/services/product-module-service.ts +++ b/packages/modules/product/src/services/product-module-service.ts @@ -105,29 +105,29 @@ export default class ProductModuleService { protected baseRepository_: DAL.RepositoryService protected readonly productService_: ModulesSdkTypes.IMedusaInternalService< - typeof Product + InferEntityType > protected readonly productVariantService_: ModulesSdkTypes.IMedusaInternalService< - typeof ProductVariant + InferEntityType > protected readonly productCategoryService_: ProductCategoryService protected readonly productTagService_: ModulesSdkTypes.IMedusaInternalService< - typeof ProductTag + InferEntityType > protected readonly productCollectionService_: ModulesSdkTypes.IMedusaInternalService< - typeof ProductCollection + InferEntityType > protected readonly productImageService_: ModulesSdkTypes.IMedusaInternalService< - typeof ProductImage + InferEntityType > protected readonly productTypeService_: ModulesSdkTypes.IMedusaInternalService< - typeof ProductType + InferEntityType > protected readonly productOptionService_: ModulesSdkTypes.IMedusaInternalService< - typeof ProductOption + InferEntityType > protected readonly productOptionValueService_: ModulesSdkTypes.IMedusaInternalService< - typeof ProductOptionValue + InferEntityType > protected readonly eventBusModuleService_?: IEventBusModuleService From c752d119a5a8dfea26b75112aa38ec892beacf39 Mon Sep 17 00:00:00 2001 From: adrien2p Date: Wed, 13 Nov 2024 15:23:09 +0100 Subject: [PATCH 018/175] fix repository template type --- packages/core/utils/src/dal/mikro-orm/mikro-orm-repository.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/utils/src/dal/mikro-orm/mikro-orm-repository.ts b/packages/core/utils/src/dal/mikro-orm/mikro-orm-repository.ts index 3e03ed8255e62..7f36e470c2250 100644 --- a/packages/core/utils/src/dal/mikro-orm/mikro-orm-repository.ts +++ b/packages/core/utils/src/dal/mikro-orm/mikro-orm-repository.ts @@ -93,7 +93,7 @@ export class MikroOrmBase { * related ones. */ -export class MikroOrmBaseRepository +export class MikroOrmBaseRepository extends MikroOrmBase implements RepositoryService { From ba6bf6eb45742771005baa5ee29fb19e9d6aeec7 Mon Sep 17 00:00:00 2001 From: Harminder Virk Date: Thu, 14 Nov 2024 13:17:20 +0530 Subject: [PATCH 019/175] refactor: use a singleton DMLToMikroORM factory instance Since the MikroORM MetadataStorage is global, we will also have to turn DML to MikroORM entities conversion use a global bucket as well --- .../src/dml/__tests__/entity-builder.spec.ts | 27 +++++++---- .../dml/helpers/create-mikro-orm-entity.ts | 47 +++++++++++++------ 2 files changed, 50 insertions(+), 24 deletions(-) diff --git a/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts b/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts index d0fbc4f8b54b5..0a9f34f162e6d 100644 --- a/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts +++ b/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts @@ -4,14 +4,15 @@ import { DmlEntity } from "../entity" import { model } from "../entity-builder" import { DuplicateIdPropertyError } from "../errors" import { - createMikrORMEntity, - toMikroOrmEntities, toMikroORMEntity, + toMikroOrmEntities, + mikroORMEntityBuilder, } from "../helpers/create-mikro-orm-entity" describe("Entity builder", () => { beforeEach(() => { MetadataStorage.clear() + mikroORMEntityBuilder.clear() }) const defaultColumnMetadata = { @@ -3514,7 +3515,11 @@ describe("Entity builder", () => { } } }>() - expectTypeOf(new User().email.user_id).toEqualTypeOf() + + const userInstance = new User() + expectTypeOf< + (typeof userInstance)["email"]["user_id"] + >().toEqualTypeOf() expectTypeOf(new Email()).toMatchTypeOf<{ email: string @@ -3710,7 +3715,11 @@ describe("Entity builder", () => { } | null } }>() - expectTypeOf(new User().email.user_id).toEqualTypeOf() + + const userInstance = new User() + expectTypeOf<(typeof userInstance)["email"]["user_id"]>().toEqualTypeOf< + string | null + >() expectTypeOf(new Email()).toMatchTypeOf<{ email: string @@ -5299,9 +5308,8 @@ describe("Entity builder", () => { teams: model.manyToMany(() => team, { mappedBy: "users" }), }) - const entityBuilder = createMikrORMEntity() - const Team = entityBuilder(team) - const User = entityBuilder(user) + const Team = toMikroORMEntity(team) + const User = toMikroORMEntity(user) expectTypeOf(new User()).toMatchTypeOf<{ id: number @@ -5489,9 +5497,8 @@ describe("Entity builder", () => { teams: model.manyToMany(() => team, { mappedBy: "users" }), }) - const entityBuilder = createMikrORMEntity() - const Team = entityBuilder(team) - const User = entityBuilder(user) + const Team = toMikroORMEntity(team) + const User = toMikroORMEntity(user) expectTypeOf(new User()).toMatchTypeOf<{ id: number diff --git a/packages/core/utils/src/dml/helpers/create-mikro-orm-entity.ts b/packages/core/utils/src/dml/helpers/create-mikro-orm-entity.ts index 71be269c3401e..54fccd5306ff6 100644 --- a/packages/core/utils/src/dml/helpers/create-mikro-orm-entity.ts +++ b/packages/core/utils/src/dml/helpers/create-mikro-orm-entity.ts @@ -1,4 +1,5 @@ import type { + Constructor, DMLSchema, EntityConstructor, IDmlEntity, @@ -8,12 +9,12 @@ import type { import { Entity, Filter } from "@mikro-orm/core" import { mikroOrmSoftDeletableFilterOptions } from "../../dal" import { DmlEntity } from "../entity" -import { DuplicateIdPropertyError } from "../errors" import { IdProperty } from "../properties/id" -import { applySearchable } from "./entity-builder/apply-searchable" +import { DuplicateIdPropertyError } from "../errors" import { defineProperty } from "./entity-builder/define-property" -import { defineRelationship } from "./entity-builder/define-relationship" +import { applySearchable } from "./entity-builder/apply-searchable" import { parseEntityName } from "./entity-builder/parse-entity-name" +import { defineRelationship } from "./entity-builder/define-relationship" import { applyEntityIndexes, applyIndexes } from "./mikro-orm/apply-indexes" /** @@ -21,7 +22,7 @@ import { applyEntityIndexes, applyIndexes } from "./mikro-orm/apply-indexes" * value is a function that can be used to convert DML entities * to Mikro ORM entities. */ -export function createMikrORMEntity() { +function createMikrORMEntity() { /** * The following property is used to track many to many relationship * between two entities. It is needed because we have to mark one @@ -35,20 +36,21 @@ export function createMikrORMEntity() { * - [user.teams]: true // the teams relationship on user is an owner * - [team.users] // cannot be an owner */ - // TODO: if we use the util toMikroOrmEntities then a new builder will be used each time, lets think about this. Currently if means that with many to many we need to use the same builder - const MANY_TO_MANY_TRACKED_RELATIONS: Record = {} + let MANY_TO_MANY_TRACKED_RELATIONS: Record = {} + let ENTITIES: Record> = {} /** * A helper function to define a Mikro ORM entity from a * DML entity. */ - return function createEntity>( - entity: T - ): Infer { + function createEntity>(entity: T): Infer { class MikroORMEntity {} const { schema, cascades, indexes: entityIndexes = [] } = entity.parse() const { modelName, tableName } = parseEntityName(entity) + if (ENTITIES[modelName]) { + return ENTITIES[modelName] as Infer + } /** * Assigning name to the class constructor, so that it matches @@ -93,12 +95,31 @@ export function createMikrORMEntity() { /** * Converting class to a MikroORM entity */ - return Entity({ tableName })( + const RegisteredEntity = Entity({ tableName })( Filter(mikroOrmSoftDeletableFilterOptions)(MikroORMEntity) ) as Infer + + ENTITIES[modelName] = RegisteredEntity + return RegisteredEntity } + + /** + * Clear the internally tracked entities and relationships + */ + createEntity.clear = function () { + MANY_TO_MANY_TRACKED_RELATIONS = {} + ENTITIES = {} + } + return createEntity } +/** + * Helper function to convert DML entities to MikroORM entity. Use + * "toMikroORMEntity" if you are ensure the input is a DML entity + * or not. + */ +export const mikroORMEntityBuilder = createMikrORMEntity() + /** * Takes a DML entity and returns a Mikro ORM entity otherwise * return the input idempotently @@ -110,7 +131,7 @@ export const toMikroORMEntity = ( let mikroOrmEntity: T | EntityConstructor = entity if (DmlEntity.isDmlEntity(entity)) { - mikroOrmEntity = createMikrORMEntity()(entity) + mikroOrmEntity = mikroORMEntityBuilder(entity) } return mikroOrmEntity as T extends IDmlEntity ? Infer : T @@ -122,11 +143,9 @@ export const toMikroORMEntity = ( * @param entities */ export const toMikroOrmEntities = function (entities: T) { - const entityBuilder = createMikrORMEntity() - return entities.map((entity) => { if (DmlEntity.isDmlEntity(entity)) { - return entityBuilder(entity) + return mikroORMEntityBuilder(entity) } return entity From ce5e4942dbfbaf7b041d8580890da09b633eb87b Mon Sep 17 00:00:00 2001 From: Harminder Virk Date: Thu, 14 Nov 2024 13:18:18 +0530 Subject: [PATCH 020/175] refactor: update product module to use DML in tests --- .../__fixtures__/product/index.ts | 8 ++++---- .../product-categories.spec.ts | 5 +++-- .../product-collections.spec.ts | 5 +++-- .../product-module-service/product-options.spec.ts | 14 +++++++++----- .../product-module-service/product-tags.spec.ts | 9 +++++---- .../product-module-service/product-types.spec.ts | 6 +++--- .../modules/product/src/models/product-type.ts | 4 +++- packages/modules/product/src/models/product.ts | 8 ++++++-- 8 files changed, 36 insertions(+), 23 deletions(-) diff --git a/packages/modules/product/integration-tests/__fixtures__/product/index.ts b/packages/modules/product/integration-tests/__fixtures__/product/index.ts index 6b965abc86179..bcc90bfecfa53 100644 --- a/packages/modules/product/integration-tests/__fixtures__/product/index.ts +++ b/packages/modules/product/integration-tests/__fixtures__/product/index.ts @@ -1,4 +1,4 @@ -import { ProductStatus } from "@medusajs/framework/utils" +import { ProductStatus, toMikroORMEntity } from "@medusajs/framework/utils" import { SqlEntityManager } from "@mikro-orm/postgresql" import { Image, @@ -88,7 +88,7 @@ export async function createTypes( }[] ) { const types: any[] = typesData.map((typesData) => { - return manager.create(ProductType, typesData) + return manager.create(toMikroORMEntity(ProductType), typesData) }) await manager.persistAndFlush(types) @@ -112,7 +112,7 @@ export async function createOptions( }[] ) { const options: any[] = optionsData.map((option) => { - return manager.create(ProductOption, option) + return manager.create(toMikroORMEntity(ProductOption), option) }) await manager.persistAndFlush(options) @@ -125,7 +125,7 @@ export async function createImages( imagesData: string[] ) { const images: any[] = imagesData.map((img) => { - return manager.create(Image, { url: img }) + return manager.create(toMikroORMEntity(Image), { url: img }) }) await manager.persistAndFlush(images) diff --git a/packages/modules/product/integration-tests/__tests__/product-module-service/product-categories.spec.ts b/packages/modules/product/integration-tests/__tests__/product-module-service/product-categories.spec.ts index 210a2c42f65db..86e4dc81b106d 100644 --- a/packages/modules/product/integration-tests/__tests__/product-module-service/product-categories.spec.ts +++ b/packages/modules/product/integration-tests/__tests__/product-module-service/product-categories.spec.ts @@ -5,6 +5,7 @@ import { Modules, ProductEvents, ProductStatus, + toMikroORMEntity, } from "@medusajs/framework/utils" import { Product, ProductCategory } from "@models" import { @@ -31,13 +32,13 @@ moduleIntegrationTestRunner({ beforeEach(async () => { const testManager = await MikroOrmWrapper.forkManager() - productOne = testManager.create(Product, { + productOne = testManager.create(toMikroORMEntity(Product), { id: "product-1", title: "product 1", status: ProductStatus.PUBLISHED, }) - productTwo = testManager.create(Product, { + productTwo = testManager.create(toMikroORMEntity(Product), { id: "product-2", title: "product 2", status: ProductStatus.PUBLISHED, diff --git a/packages/modules/product/integration-tests/__tests__/product-module-service/product-collections.spec.ts b/packages/modules/product/integration-tests/__tests__/product-module-service/product-collections.spec.ts index 2e4fa2bd62d12..feb7fd9f37b88 100644 --- a/packages/modules/product/integration-tests/__tests__/product-module-service/product-collections.spec.ts +++ b/packages/modules/product/integration-tests/__tests__/product-module-service/product-collections.spec.ts @@ -5,6 +5,7 @@ import { Modules, ProductEvents, ProductStatus, + toMikroORMEntity, } from "@medusajs/framework/utils" import { Product, ProductCollection } from "@models" import { @@ -31,13 +32,13 @@ moduleIntegrationTestRunner({ beforeEach(async () => { const testManager = await MikroOrmWrapper.forkManager() - productOne = testManager.create(Product, { + productOne = testManager.create(toMikroORMEntity(Product), { id: "product-1", title: "product 1", status: ProductStatus.PUBLISHED, }) - productTwo = testManager.create(Product, { + productTwo = testManager.create(toMikroORMEntity(Product), { id: "product-2", title: "product 2", status: ProductStatus.PUBLISHED, diff --git a/packages/modules/product/integration-tests/__tests__/product-module-service/product-options.spec.ts b/packages/modules/product/integration-tests/__tests__/product-module-service/product-options.spec.ts index cc3fe9baac491..7df3d70f731c2 100644 --- a/packages/modules/product/integration-tests/__tests__/product-module-service/product-options.spec.ts +++ b/packages/modules/product/integration-tests/__tests__/product-module-service/product-options.spec.ts @@ -1,5 +1,9 @@ import { IProductModuleService } from "@medusajs/framework/types" -import { Modules, ProductStatus } from "@medusajs/framework/utils" +import { + Modules, + ProductStatus, + toMikroORMEntity, +} from "@medusajs/framework/utils" import { Product, ProductOption } from "@models" import { moduleIntegrationTestRunner } from "@medusajs/test-utils" @@ -16,25 +20,25 @@ moduleIntegrationTestRunner({ beforeEach(async () => { const testManager = await MikroOrmWrapper.forkManager() - productOne = testManager.create(Product, { + productOne = testManager.create(toMikroORMEntity(Product), { id: "product-1", title: "product 1", status: ProductStatus.PUBLISHED, }) - productTwo = testManager.create(Product, { + productTwo = testManager.create(toMikroORMEntity(Product), { id: "product-2", title: "product 2", status: ProductStatus.PUBLISHED, }) - optionOne = testManager.create(ProductOption, { + optionOne = testManager.create(toMikroORMEntity(ProductOption), { id: "option-1", title: "option 1", product: productOne, }) - optionTwo = testManager.create(ProductOption, { + optionTwo = testManager.create(toMikroORMEntity(ProductOption), { id: "option-2", title: "option 1", product: productTwo, diff --git a/packages/modules/product/integration-tests/__tests__/product-module-service/product-tags.spec.ts b/packages/modules/product/integration-tests/__tests__/product-module-service/product-tags.spec.ts index d197df4baad6a..f7d805746e1a4 100644 --- a/packages/modules/product/integration-tests/__tests__/product-module-service/product-tags.spec.ts +++ b/packages/modules/product/integration-tests/__tests__/product-module-service/product-tags.spec.ts @@ -5,6 +5,7 @@ import { Modules, ProductEvents, ProductStatus, + toMikroORMEntity, } from "@medusajs/framework/utils" import { Product, ProductTag } from "@models" import { @@ -35,25 +36,25 @@ moduleIntegrationTestRunner({ beforeEach(async () => { const testManager = await MikroOrmWrapper.forkManager() - productOne = testManager.create(Product, { + productOne = testManager.create(toMikroORMEntity(Product), { id: "product-1", title: "product 1", status: ProductStatus.PUBLISHED, }) - productTwo = testManager.create(Product, { + productTwo = testManager.create(toMikroORMEntity(Product), { id: "product-2", title: "product 2", status: ProductStatus.PUBLISHED, }) - tagOne = testManager.create(ProductTag, { + tagOne = testManager.create(toMikroORMEntity(ProductTag), { id: "tag-1", value: "tag 1", products: [productOne], }) - tagTwo = testManager.create(ProductTag, { + tagTwo = testManager.create(toMikroORMEntity(ProductTag), { id: "tag-2", value: "tag", products: [productTwo], diff --git a/packages/modules/product/integration-tests/__tests__/product-module-service/product-types.spec.ts b/packages/modules/product/integration-tests/__tests__/product-module-service/product-types.spec.ts index c33a501ea26cf..28516445251ea 100644 --- a/packages/modules/product/integration-tests/__tests__/product-module-service/product-types.spec.ts +++ b/packages/modules/product/integration-tests/__tests__/product-module-service/product-types.spec.ts @@ -1,7 +1,7 @@ import { IProductModuleService } from "@medusajs/framework/types" import { ProductType } from "@models" import { moduleIntegrationTestRunner } from "@medusajs/test-utils" -import { Modules } from "@medusajs/framework/utils" +import { Modules, toMikroORMEntity } from "@medusajs/framework/utils" jest.setTimeout(30000) @@ -15,12 +15,12 @@ moduleIntegrationTestRunner({ beforeEach(async () => { const testManager = await MikroOrmWrapper.forkManager() - typeOne = testManager.create(ProductType, { + typeOne = testManager.create(toMikroORMEntity(ProductType), { id: "type-1", value: "type 1", }) - typeTwo = testManager.create(ProductType, { + typeTwo = testManager.create(toMikroORMEntity(ProductType), { id: "type-2", value: "type", }) diff --git a/packages/modules/product/src/models/product-type.ts b/packages/modules/product/src/models/product-type.ts index 5385a946c5f3b..dd8d930644c8b 100644 --- a/packages/modules/product/src/models/product-type.ts +++ b/packages/modules/product/src/models/product-type.ts @@ -15,7 +15,9 @@ const ProductTypeDML = model id: model.id().primaryKey(), value: model.text().searchable(), metadata: model.json().nullable(), - product: model.hasMany(() => Product), + product: model.hasMany(() => Product, { + mappedBy: "type", + }), }) .indexes([ { diff --git a/packages/modules/product/src/models/product.ts b/packages/modules/product/src/models/product.ts index 3cdc6936bc37b..e91f88b06dd04 100644 --- a/packages/modules/product/src/models/product.ts +++ b/packages/modules/product/src/models/product.ts @@ -34,7 +34,7 @@ const productCollectionIndexName = "IDX_product_collection_id" // where: "deleted_at IS NULL", // }) -export const ProductDML = model +const ProductDML = model .define("Product", { id: model.id().primaryKey(), title: model.text().searchable(), @@ -60,7 +60,11 @@ export const ProductDML = model variants: model.hasMany(() => ProductVariant, { mappedBy: "product", }), - type: model.belongsTo(() => ProductType).nullable(), + type: model + .belongsTo(() => ProductType, { + mappedBy: "product", + }) + .nullable(), tags: model.manyToMany(() => ProductTag, { mappedBy: "product", }), From 7512300e16a7587ca1092c765eb2bccdcd6dcacc Mon Sep 17 00:00:00 2001 From: Harminder Virk Date: Thu, 14 Nov 2024 13:43:37 +0530 Subject: [PATCH 021/175] wip: tests --- .../product-collections.spec.ts | 4 ++++ .../product-options.spec.ts | 2 ++ .../product-tags.spec.ts | 2 ++ .../modules/product/src/models/product-tag.ts | 19 +++++++++++-------- .../modules/product/src/models/product.ts | 2 +- 5 files changed, 20 insertions(+), 9 deletions(-) diff --git a/packages/modules/product/integration-tests/__tests__/product-module-service/product-collections.spec.ts b/packages/modules/product/integration-tests/__tests__/product-module-service/product-collections.spec.ts index feb7fd9f37b88..73d761b715c72 100644 --- a/packages/modules/product/integration-tests/__tests__/product-module-service/product-collections.spec.ts +++ b/packages/modules/product/integration-tests/__tests__/product-module-service/product-collections.spec.ts @@ -35,12 +35,14 @@ moduleIntegrationTestRunner({ productOne = testManager.create(toMikroORMEntity(Product), { id: "product-1", title: "product 1", + handle: "product-1", status: ProductStatus.PUBLISHED, }) productTwo = testManager.create(toMikroORMEntity(Product), { id: "product-2", title: "product 2", + handle: "product-2", status: ProductStatus.PUBLISHED, }) @@ -48,11 +50,13 @@ moduleIntegrationTestRunner({ { id: "test-1", title: "collection 1", + handle: "collection-1", products: [productOne], }, { id: "test-2", title: "collection", + handle: "collection", products: [productTwo], }, ] diff --git a/packages/modules/product/integration-tests/__tests__/product-module-service/product-options.spec.ts b/packages/modules/product/integration-tests/__tests__/product-module-service/product-options.spec.ts index 7df3d70f731c2..8d7c6952fde8f 100644 --- a/packages/modules/product/integration-tests/__tests__/product-module-service/product-options.spec.ts +++ b/packages/modules/product/integration-tests/__tests__/product-module-service/product-options.spec.ts @@ -23,12 +23,14 @@ moduleIntegrationTestRunner({ productOne = testManager.create(toMikroORMEntity(Product), { id: "product-1", title: "product 1", + handle: "product-1", status: ProductStatus.PUBLISHED, }) productTwo = testManager.create(toMikroORMEntity(Product), { id: "product-2", title: "product 2", + handle: "product-2", status: ProductStatus.PUBLISHED, }) diff --git a/packages/modules/product/integration-tests/__tests__/product-module-service/product-tags.spec.ts b/packages/modules/product/integration-tests/__tests__/product-module-service/product-tags.spec.ts index f7d805746e1a4..b8a91be243994 100644 --- a/packages/modules/product/integration-tests/__tests__/product-module-service/product-tags.spec.ts +++ b/packages/modules/product/integration-tests/__tests__/product-module-service/product-tags.spec.ts @@ -39,12 +39,14 @@ moduleIntegrationTestRunner({ productOne = testManager.create(toMikroORMEntity(Product), { id: "product-1", title: "product 1", + handle: "product-1", status: ProductStatus.PUBLISHED, }) productTwo = testManager.create(toMikroORMEntity(Product), { id: "product-2", title: "product 2", + handle: "product-2", status: ProductStatus.PUBLISHED, }) diff --git a/packages/modules/product/src/models/product-tag.ts b/packages/modules/product/src/models/product-tag.ts index 2870045f74c09..c578954d8c42e 100644 --- a/packages/modules/product/src/models/product-tag.ts +++ b/packages/modules/product/src/models/product-tag.ts @@ -11,14 +11,17 @@ const tagValueIndexName = "IDX_tag_value_unique" // }) const ProductTagDML = model - .define("ProductTag", { - id: model.id().primaryKey(), - value: model.text().searchable(), - metadata: model.json().nullable(), - product: model.manyToMany(() => Product, { - mappedBy: "tags", - }), - }) + .define( + { tableName: "product_tags", name: "ProductTag" }, + { + id: model.id().primaryKey(), + value: model.text().searchable(), + metadata: model.json().nullable(), + products: model.manyToMany(() => Product, { + mappedBy: "tags", + }), + } + ) .indexes([ { name: tagValueIndexName, diff --git a/packages/modules/product/src/models/product.ts b/packages/modules/product/src/models/product.ts index e91f88b06dd04..24e898d825f0b 100644 --- a/packages/modules/product/src/models/product.ts +++ b/packages/modules/product/src/models/product.ts @@ -66,7 +66,7 @@ const ProductDML = model }) .nullable(), tags: model.manyToMany(() => ProductTag, { - mappedBy: "product", + mappedBy: "products", }), options: model.hasMany(() => ProductOption, { mappedBy: "product", From 5c0ad126ec882f8805b93b045e1a07ab1b50dabe Mon Sep 17 00:00:00 2001 From: adrien2p Date: Thu, 14 Nov 2024 10:10:22 +0100 Subject: [PATCH 022/175] WIP product linkable fixes --- .../src/modules-sdk/joiner-config-builder.ts | 15 ++++++- packages/core/utils/src/modules-sdk/module.ts | 11 ++++- .../integration-tests/__tests__/product.ts | 40 +++++++++---------- packages/modules/product/package.json | 2 +- packages/modules/product/src/joiner-config.ts | 2 - .../modules/product/src/models/product.ts | 2 +- 6 files changed, 43 insertions(+), 29 deletions(-) diff --git a/packages/core/utils/src/modules-sdk/joiner-config-builder.ts b/packages/core/utils/src/modules-sdk/joiner-config-builder.ts index ba80eb9033f43..e4401f87de008 100644 --- a/packages/core/utils/src/modules-sdk/joiner-config-builder.ts +++ b/packages/core/utils/src/modules-sdk/joiner-config-builder.ts @@ -342,11 +342,22 @@ export function buildLinkableKeysFromMikroOrmObjects( export function buildLinkConfigFromModelObjects< const ServiceName extends string, const T extends Record> ->(serviceName: ServiceName, models: T): InfersLinksConfig { +>( + serviceName: ServiceName, + models: T, + linkableKeys: Record = {} +): InfersLinksConfig { + // In case some models have been provided to a custom joiner config, the linkable will be limited + // to that set of models. We dont want to expose models that should not be linkable. + const linkableModels = Object.values(linkableKeys) const linkConfig = {} as InfersLinksConfig for (const model of Object.values(models) ?? []) { - if (!DmlEntity.isDmlEntity(model)) { + if ( + !DmlEntity.isDmlEntity(model) || + (linkableModels.length && + !linkableModels.includes(upperCaseFirst(model.name))) + ) { continue } diff --git a/packages/core/utils/src/modules-sdk/module.ts b/packages/core/utils/src/modules-sdk/module.ts index 7e995957dace5..3f96a943159b0 100644 --- a/packages/core/utils/src/modules-sdk/module.ts +++ b/packages/core/utils/src/modules-sdk/module.ts @@ -49,15 +49,22 @@ export function Module< DmlEntity.isDmlEntity(model) ) + // TODO: Custom joiner config should take precedence over the DML auto generated linkable + // Thats in the case of manually providing models in custom joiner config. + // TODO: Add support for non linkable modifier DML object to be skipped from the linkable generation + + const linkableKeys = service.prototype.__joinerConfig().linkableKeys + if (dmlObjects.length) { linkable = buildLinkConfigFromModelObjects( serviceName, - modelObjects + modelObjects, + linkableKeys ) as Linkable } else { linkable = buildLinkConfigFromLinkableKeys( serviceName, - service.prototype.__joinerConfig().linkableKeys + linkableKeys ) as Linkable } } diff --git a/packages/modules/product/integration-tests/__tests__/product.ts b/packages/modules/product/integration-tests/__tests__/product.ts index d1e1b7b9fef4d..f0ae16c28fb59 100644 --- a/packages/modules/product/integration-tests/__tests__/product.ts +++ b/packages/modules/product/integration-tests/__tests__/product.ts @@ -1,4 +1,9 @@ -import { Image, Product, ProductCategory, ProductCollection } from "@models" +import { + Image, + Product, + ProductCategory, + ProductCollection, +} from "../../src/models" import { assignCategoriesToProduct, buildProductOnlyData, @@ -46,21 +51,23 @@ moduleIntegrationTestRunner({ categoryService = moduleService.productCategoryService_ }) - it(`should export the appropriate linkable configuration`, () => { + it.only(`should export the appropriate linkable configuration`, () => { const linkable = Module(Modules.PRODUCT, { service: ProductModuleService, }).linkable - expect(Object.keys(linkable)).toEqual([ - "product", - "productVariant", - "productOption", - "productType", - "productImage", - "productTag", - "productCollection", - "productCategory", - ]) + expect(Object.keys(linkable)).toHaveLength(7) + expect(Object.keys(linkable)).toEqual( + expect.arrayContaining([ + "product", + "productVariant", + "productOption", + "productType", + "productTag", + "productCollection", + "productCategory", + ]) + ) Object.keys(linkable).forEach((key) => { delete linkable[key].toJSON @@ -110,15 +117,6 @@ moduleIntegrationTestRunner({ field: "productType", }, }, - productImage: { - id: { - linkable: "product_image_id", - entity: "ProductImage", - primaryKey: "id", - serviceName: "product", - field: "productImage", - }, - }, productTag: { id: { linkable: "product_tag_id", diff --git a/packages/modules/product/package.json b/packages/modules/product/package.json index 597375739bed6..422941338acd6 100644 --- a/packages/modules/product/package.json +++ b/packages/modules/product/package.json @@ -29,7 +29,7 @@ "resolve:aliases": "tsc --showConfig -p tsconfig.json > tsconfig.resolved.json && tsc-alias -p tsconfig.resolved.json && rimraf tsconfig.resolved.json", "build": "rimraf dist && tsc --build && npm run resolve:aliases", "test": "jest --runInBand --bail --forceExit -- src/**/__tests__/**/*.ts", - "test:integration": "jest --forceExit -- integration-tests/**/__tests__/**/*.ts", + "test:integration": "jest --forceExit -- integration-tests/__tests__/product.ts", "migration:generate": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm migration:generate", "migration:initial": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm migration:create --initial", "migration:create": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm migration:create", diff --git a/packages/modules/product/src/joiner-config.ts b/packages/modules/product/src/joiner-config.ts index f6a60f7f35459..c0d426a8e75df 100644 --- a/packages/modules/product/src/joiner-config.ts +++ b/packages/modules/product/src/joiner-config.ts @@ -8,7 +8,6 @@ import { ProductType, ProductVariant, } from "@models" -import ProductImage from "./models/product-image" import { default as schema } from "./schema" export const joinerConfig = defineJoinerConfig(Modules.PRODUCT, { @@ -18,7 +17,6 @@ export const joinerConfig = defineJoinerConfig(Modules.PRODUCT, { ProductVariant, ProductOption, ProductType, - ProductImage, ProductTag, ProductCollection, ProductCategory, diff --git a/packages/modules/product/src/models/product.ts b/packages/modules/product/src/models/product.ts index 24e898d825f0b..b297e49ec1a2a 100644 --- a/packages/modules/product/src/models/product.ts +++ b/packages/modules/product/src/models/product.ts @@ -38,7 +38,7 @@ const ProductDML = model .define("Product", { id: model.id().primaryKey(), title: model.text().searchable(), - handle: model.text().nullable(), + handle: model.text().nullable(), // TODO: provide a way to compute a value if not provided (default maybe) subtitle: model.text().searchable().nullable(), description: model.text().searchable().nullable(), is_giftcard: model.boolean().default(false), From e6ec08690d3bfc041e94e306ec43420fa879a569 Mon Sep 17 00:00:00 2001 From: adrien2p Date: Thu, 14 Nov 2024 12:16:23 +0100 Subject: [PATCH 023/175] continue type fixing and start test fixing --- .../src/modules-sdk/joiner-config-builder.ts | 41 +++++++++++- .../integration-tests/__tests__/product.ts | 66 ++++++++++--------- .../product/src/models/product-category.ts | 8 +-- .../product/src/models/product-collection.ts | 4 +- .../product/src/models/product-image.ts | 4 +- .../src/models/product-option-value.ts | 4 +- .../product/src/models/product-option.ts | 4 +- .../modules/product/src/models/product-tag.ts | 4 +- .../product/src/models/product-type.ts | 4 +- .../product/src/models/product-variant.ts | 4 +- .../modules/product/src/models/product.ts | 4 +- .../product/src/repositories/product.ts | 5 ++ 12 files changed, 97 insertions(+), 55 deletions(-) diff --git a/packages/core/utils/src/modules-sdk/joiner-config-builder.ts b/packages/core/utils/src/modules-sdk/joiner-config-builder.ts index e4401f87de008..3684001c996f1 100644 --- a/packages/core/utils/src/modules-sdk/joiner-config-builder.ts +++ b/packages/core/utils/src/modules-sdk/joiner-config-builder.ts @@ -353,15 +353,17 @@ export function buildLinkConfigFromModelObjects< const linkConfig = {} as InfersLinksConfig for (const model of Object.values(models) ?? []) { + const classLikeModelName = upperCaseFirst(model.name) + if ( !DmlEntity.isDmlEntity(model) || - (linkableModels.length && - !linkableModels.includes(upperCaseFirst(model.name))) + (linkableModels.length && !linkableModels.includes(classLikeModelName)) ) { continue } const schema = model.schema + // @ts-ignore const modelLinkConfig = (linkConfig[lowerCaseFirst(model.name)] ??= { toJSON: function () { @@ -389,10 +391,43 @@ export function buildLinkConfigFromModelObjects< primaryKey: property, serviceName, field: lowerCaseFirst(model.name), - entity: upperCaseFirst(model.name), + entity: classLikeModelName, } } } + + // Merge existing custom linkable keys configuration + const linkableKeysPerModel = Object.entries(linkableKeys).reduce( + (acc, [key, entityName]) => { + acc[entityName] ??= [] + acc[entityName].push(key) + return acc + }, + {} + ) + + for (const linkableKey of linkableKeysPerModel[classLikeModelName] ?? []) { + const snakeCasedModelName = camelToSnakeCase(toCamelCase(model.name)) + + // Linkable keys by default are prepared with snake cased model name _id + // So to be able to compare only the property we have to remove the first part + const inferredReferenceProperty = linkableKey.replace( + `${snakeCasedModelName}_`, + "" + ) + + if (modelLinkConfig[inferredReferenceProperty]) { + continue + } + + modelLinkConfig[linkableKey] = { + linkable: linkableKey, + primaryKey: linkableKey, + serviceName, + field: lowerCaseFirst(model.name), + entity: upperCaseFirst(model.name), + } + } } return linkConfig as InfersLinksConfig diff --git a/packages/modules/product/integration-tests/__tests__/product.ts b/packages/modules/product/integration-tests/__tests__/product.ts index f0ae16c28fb59..e498820c99d42 100644 --- a/packages/modules/product/integration-tests/__tests__/product.ts +++ b/packages/modules/product/integration-tests/__tests__/product.ts @@ -13,12 +13,17 @@ import { createProductVariants, } from "../__fixtures__/product" -import { IProductModuleService, ProductDTO } from "@medusajs/framework/types" +import { + InferEntityType, + IProductModuleService, + ProductDTO, +} from "@medusajs/framework/types" import { Module, Modules, ProductStatus, kebabCase, + toMikroORMEntity, } from "@medusajs/framework/utils" import { SqlEntityManager } from "@mikro-orm/postgresql" import { @@ -32,6 +37,7 @@ import { productsData, variantsData, } from "../__fixtures__/product/data" +import ProductImage from "../../src/models/product-image" jest.setTimeout(30000) @@ -51,7 +57,7 @@ moduleIntegrationTestRunner({ categoryService = moduleService.productCategoryService_ }) - it.only(`should export the appropriate linkable configuration`, () => { + it(`should export the appropriate linkable configuration`, () => { const linkable = Module(Modules.PRODUCT, { service: ProductModuleService, }).linkable @@ -149,14 +155,14 @@ moduleIntegrationTestRunner({ describe("Product Service", () => { let testManager: SqlEntityManager - let products!: Product[] - let productOne: Product - let categories!: ProductCategory[] + let products!: InferEntityType[] + let productOne: InferEntityType + let categories!: InferEntityType[] describe("retrieve", () => { beforeEach(async () => { testManager = await MikroOrmWrapper.forkManager() - productOne = testManager.create(Product, { + productOne = testManager.create(toMikroORMEntity(Product), { id: "product-1", title: "product 1", status: ProductStatus.PUBLISHED, @@ -203,7 +209,7 @@ moduleIntegrationTestRunner({ }) describe("create", function () { - let images: Image[] = [] + let images: InferEntityType[] = [] beforeEach(async () => { testManager = await MikroOrmWrapper.forkManager() @@ -243,13 +249,13 @@ moduleIntegrationTestRunner({ }) describe("update", function () { - let images: Image[] = [] + let images: InferEntityType[] = [] beforeEach(async () => { testManager = await MikroOrmWrapper.forkManager() images = await createImages(testManager, ["image-1", "image-2"]) - productOne = testManager.create(Product, { + productOne = testManager.create(toMikroORMEntity(Product), { id: "product-1", title: "product 1", status: ProductStatus.PUBLISHED, @@ -454,23 +460,23 @@ moduleIntegrationTestRunner({ }) describe("relation: categories", () => { - let workingProduct: Product - let workingCategory: ProductCategory + let workingProduct: InferEntityType + let workingCategory: InferEntityType beforeEach(async () => { testManager = await MikroOrmWrapper.forkManager() products = await createProductAndTags(testManager, productsData) - workingProduct = products.find((p) => p.id === "test-1") as Product + workingProduct = products.find((p) => p.id === "test-1")! categories = [] for (const entry of categoriesData) { categories.push((await categoryService.create([entry]))[0]) } workingCategory = (await testManager.findOne( - ProductCategory, + toMikroORMEntity(ProductCategory), "category-1" - )) as ProductCategory + ))! workingProduct = await assignCategoriesToProduct( testManager, @@ -496,9 +502,7 @@ moduleIntegrationTestRunner({ } ) - const product = products.find( - (p) => p.id === workingProduct.id - ) as unknown as Product + const product = products.find((p) => p.id === workingProduct.id)! expect(product).toEqual( expect.objectContaining({ @@ -553,10 +557,10 @@ moduleIntegrationTestRunner({ }) describe("relation: collections", () => { - let workingProduct: Product - let workingProductTwo: Product - let workingCollection: ProductCollection - let workingCollectionTwo: ProductCollection + let workingProduct: InferEntityType + let workingProductTwo: InferEntityType + let workingCollection: InferEntityType + let workingCollectionTwo: InferEntityType const collectionData = [ { id: "test-1", @@ -571,14 +575,14 @@ moduleIntegrationTestRunner({ beforeEach(async () => { testManager = await MikroOrmWrapper.forkManager() await createCollections(testManager, collectionData) - workingCollection = (await testManager.findOne( - ProductCollection, + workingCollection = await testManager.findOne( + toMikroORMEntity(ProductCollection), "test-1" - )) as ProductCollection + ) workingCollectionTwo = (await testManager.findOne( - ProductCollection, + toMikroORMEntity(ProductCollection), "test-2" - )) as ProductCollection + ))! products = await createProductAndTags(testManager, [ { @@ -594,10 +598,8 @@ moduleIntegrationTestRunner({ }, ]) - workingProduct = products.find((p) => p.id === "test-1") as Product - workingProductTwo = products.find( - (p) => p.id === "test-2" - ) as Product + workingProduct = products.find((p) => p.id === "test-1")! + workingProductTwo = products.find((p) => p.id === "test-2")! }) it("should filter by collection relation and scope fields", async () => { @@ -738,7 +740,7 @@ moduleIntegrationTestRunner({ }) describe("softDelete", function () { - let images: Image[] = [] + let images: InferEntityType[] = [] beforeEach(async () => { testManager = await MikroOrmWrapper.forkManager() @@ -773,7 +775,7 @@ moduleIntegrationTestRunner({ }) describe("restore", function () { - let images: Image[] = [] + let images: InferEntityType[] = [] beforeEach(async () => { testManager = await MikroOrmWrapper.forkManager() diff --git a/packages/modules/product/src/models/product-category.ts b/packages/modules/product/src/models/product-category.ts index 6a8c4b676e6be..887fba5552726 100644 --- a/packages/modules/product/src/models/product-category.ts +++ b/packages/modules/product/src/models/product-category.ts @@ -19,7 +19,7 @@ const categoryMpathIndexName = "IDX_product_category_path" // where: "deleted_at IS NULL", // }) -const ProductCategoryDML = model +const ProductCategory = model .define("ProductCategory", { id: model.id().primaryKey(), name: model.text().searchable(), @@ -31,11 +31,11 @@ const ProductCategoryDML = model rank: model.number().default(0), metadata: model.json().nullable(), parent_category: model - .belongsTo(() => ProductCategoryDML, { + .belongsTo(() => ProductCategory, { mappedBy: "category_children", }) .nullable(), - category_children: model.hasMany(() => ProductCategoryDML, { + category_children: model.hasMany(() => ProductCategory, { mappedBy: "parent_category", }), products: model.manyToMany(() => Product), @@ -134,4 +134,4 @@ const ProductCategoryDML = model // } // } -export default ProductCategoryDML +export default ProductCategory diff --git a/packages/modules/product/src/models/product-collection.ts b/packages/modules/product/src/models/product-collection.ts index 9306c50d05cce..8932434273f6a 100644 --- a/packages/modules/product/src/models/product-collection.ts +++ b/packages/modules/product/src/models/product-collection.ts @@ -10,7 +10,7 @@ const collectionHandleIndexName = "IDX_collection_handle_unique" // where: "deleted_at IS NULL", // }) -const ProductCollectionDML = model +const ProductCollection = model .define("ProductCollection", { id: model.id().primaryKey(), title: model.text().searchable(), @@ -70,4 +70,4 @@ const ProductCollectionDML = model // } // } -export default ProductCollectionDML +export default ProductCollection diff --git a/packages/modules/product/src/models/product-image.ts b/packages/modules/product/src/models/product-image.ts index e20c278df73b6..5bbf61a72aa76 100644 --- a/packages/modules/product/src/models/product-image.ts +++ b/packages/modules/product/src/models/product-image.ts @@ -10,7 +10,7 @@ const imageUrlIndexName = "IDX_product_image_url" // where: "deleted_at IS NULL", // }) -const ProductImageDML = model +const ProductImage = model .define("ProductImage", { id: model.id().primaryKey(), url: model.text(), @@ -64,4 +64,4 @@ const ProductImageDML = model // } // } -export default ProductImageDML +export default ProductImage diff --git a/packages/modules/product/src/models/product-option-value.ts b/packages/modules/product/src/models/product-option-value.ts index d0264e7174624..1e23b08cbf675 100644 --- a/packages/modules/product/src/models/product-option-value.ts +++ b/packages/modules/product/src/models/product-option-value.ts @@ -10,7 +10,7 @@ const optionValueOptionIdIndexName = "IDX_option_value_option_id_unique" // where: "deleted_at IS NULL", // }) -const ProductOptionValueDML = model +const ProductOptionValue = model .define("ProductOptionValue", { id: model.id().primaryKey(), value: model.text(), @@ -82,4 +82,4 @@ const ProductOptionValueDML = model // } // } -export default ProductOptionValueDML +export default ProductOptionValue diff --git a/packages/modules/product/src/models/product-option.ts b/packages/modules/product/src/models/product-option.ts index 87d73321179de..a67ce2791e19d 100644 --- a/packages/modules/product/src/models/product-option.ts +++ b/packages/modules/product/src/models/product-option.ts @@ -11,7 +11,7 @@ const optionProductIdTitleIndexName = "IDX_option_product_id_title_unique" // where: "deleted_at IS NULL", // }) -const ProductOptionDML = model +const ProductOption = model .define("ProductOption", { id: model.id().primaryKey(), title: model.text().searchable(), @@ -87,4 +87,4 @@ const ProductOptionDML = model // } // } -export default ProductOptionDML +export default ProductOption diff --git a/packages/modules/product/src/models/product-tag.ts b/packages/modules/product/src/models/product-tag.ts index c578954d8c42e..31faa6c38eaf1 100644 --- a/packages/modules/product/src/models/product-tag.ts +++ b/packages/modules/product/src/models/product-tag.ts @@ -10,7 +10,7 @@ const tagValueIndexName = "IDX_tag_value_unique" // where: "deleted_at IS NULL", // }) -const ProductTagDML = model +const ProductTag = model .define( { tableName: "product_tags", name: "ProductTag" }, { @@ -67,4 +67,4 @@ const ProductTagDML = model // } // } -export default ProductTagDML +export default ProductTag diff --git a/packages/modules/product/src/models/product-type.ts b/packages/modules/product/src/models/product-type.ts index dd8d930644c8b..77db70aa4e202 100644 --- a/packages/modules/product/src/models/product-type.ts +++ b/packages/modules/product/src/models/product-type.ts @@ -10,7 +10,7 @@ const typeValueIndexName = "IDX_type_value_unique" // where: "deleted_at IS NULL", // }) -const ProductTypeDML = model +const ProductType = model .define("ProductType", { id: model.id().primaryKey(), value: model.text().searchable(), @@ -62,4 +62,4 @@ const ProductTypeDML = model // } // } -export default ProductTypeDML +export default ProductType diff --git a/packages/modules/product/src/models/product-variant.ts b/packages/modules/product/src/models/product-variant.ts index 2ea73d3e343ae..482ad26810ab3 100644 --- a/packages/modules/product/src/models/product-variant.ts +++ b/packages/modules/product/src/models/product-variant.ts @@ -46,7 +46,7 @@ const variantProductIdIndexName = "IDX_product_variant_product_id" // where: "deleted_at IS NULL", // }) -const ProductVariantDML = model +const ProductVariant = model .define("ProductVariant", { id: model.id().primaryKey(), title: model.text().searchable(), @@ -206,5 +206,5 @@ const ProductVariantDML = model // } // } -export default ProductVariantDML +export default ProductVariant // export default ProductVariant diff --git a/packages/modules/product/src/models/product.ts b/packages/modules/product/src/models/product.ts index b297e49ec1a2a..da4ebf0be9230 100644 --- a/packages/modules/product/src/models/product.ts +++ b/packages/modules/product/src/models/product.ts @@ -34,7 +34,7 @@ const productCollectionIndexName = "IDX_product_collection_id" // where: "deleted_at IS NULL", // }) -const ProductDML = model +const Product = model .define("Product", { id: model.id().primaryKey(), title: model.text().searchable(), @@ -242,5 +242,5 @@ const ProductDML = model // } // } -export default ProductDML +export default Product // export default Product diff --git a/packages/modules/product/src/repositories/product.ts b/packages/modules/product/src/repositories/product.ts index caea4951d7536..656cd5e8c20db 100644 --- a/packages/modules/product/src/repositories/product.ts +++ b/packages/modules/product/src/repositories/product.ts @@ -13,6 +13,11 @@ export class ProductRepository extends DALUtils.mikroOrmBaseRepositoryFactory( super(...arguments) } + // TODO: temporary fix until the DML support something like default on create for the handle as the example + async create(data: any[], context: Context = {}) { + return await super.create(data, context) + } + /** * In order to be able to have a strict not in categories, and prevent a product * to be return in the case it also belongs to other categories, we need to From 7334c338e44cb92c27eeabcdb88e5f1d67d92a70 Mon Sep 17 00:00:00 2001 From: Harminder Virk Date: Thu, 14 Nov 2024 17:15:26 +0530 Subject: [PATCH 024/175] test: fix more tests --- .../__fixtures__/product/data/products.ts | 3 +++ .../__fixtures__/product/index.ts | 13 +++++++------ .../integration-tests/__tests__/product.ts | 4 ++++ .../modules/product/src/models/product-image.ts | 15 +++++++++------ .../modules/product/src/models/product-tag.ts | 2 +- .../modules/product/src/repositories/product.ts | 9 +++++++-- 6 files changed, 31 insertions(+), 15 deletions(-) diff --git a/packages/modules/product/integration-tests/__fixtures__/product/data/products.ts b/packages/modules/product/integration-tests/__fixtures__/product/data/products.ts index 56556967eeae8..a4f3485777c81 100644 --- a/packages/modules/product/integration-tests/__fixtures__/product/data/products.ts +++ b/packages/modules/product/integration-tests/__fixtures__/product/data/products.ts @@ -4,6 +4,7 @@ export const productsData = [ { id: "test-1", title: "product 1", + handle: "product-1", status: ProductStatus.PUBLISHED, tags: [ { @@ -15,6 +16,7 @@ export const productsData = [ { id: "test-2", title: "product", + handle: "product", status: ProductStatus.PUBLISHED, tags: [ { @@ -26,6 +28,7 @@ export const productsData = [ { id: "test-3", title: "product 3", + handle: "product-3", status: ProductStatus.PUBLISHED, tags: [ { diff --git a/packages/modules/product/integration-tests/__fixtures__/product/index.ts b/packages/modules/product/integration-tests/__fixtures__/product/index.ts index bcc90bfecfa53..2c5445011e5d8 100644 --- a/packages/modules/product/integration-tests/__fixtures__/product/index.ts +++ b/packages/modules/product/integration-tests/__fixtures__/product/index.ts @@ -10,6 +10,7 @@ import { } from "@models" import ProductOption from "../../../src/models/product-option" +import { InferEntityType } from "@medusajs/types" export * from "./data/create-product" @@ -24,7 +25,7 @@ export async function createProductAndTags( }[] ) { const products: any[] = data.map((productData) => { - return manager.create(Product, productData) + return manager.create(toMikroORMEntity(Product), productData) }) await manager.persistAndFlush(products) @@ -42,7 +43,7 @@ export async function createProductAndTypes( }[] ) { const products: any[] = data.map((productData) => { - return manager.create(Product, productData) + return manager.create(toMikroORMEntity(Product), productData) }) await manager.persistAndFlush(products) @@ -55,7 +56,7 @@ export async function createProductVariants( data: any[] ) { const variants: any[] = data.map((variantsData) => { - return manager.create(ProductVariant, variantsData) + return manager.create(toMikroORMEntity(ProductVariant), variantsData) }) await manager.persistAndFlush(variants) @@ -72,7 +73,7 @@ export async function createCollections( }[] ) { const collections: any[] = collectionData.map((collectionData) => { - return manager.create(ProductCollection, collectionData) + return manager.create(toMikroORMEntity(ProductCollection), collectionData) }) await manager.persistAndFlush(collections) @@ -135,8 +136,8 @@ export async function createImages( export async function assignCategoriesToProduct( manager: SqlEntityManager, - product: Product, - categories: ProductCategory[] + product: InferEntityType, + categories: InferEntityType[] ) { product.categories.add(categories) diff --git a/packages/modules/product/integration-tests/__tests__/product.ts b/packages/modules/product/integration-tests/__tests__/product.ts index e498820c99d42..28305859092da 100644 --- a/packages/modules/product/integration-tests/__tests__/product.ts +++ b/packages/modules/product/integration-tests/__tests__/product.ts @@ -165,6 +165,7 @@ moduleIntegrationTestRunner({ productOne = testManager.create(toMikroORMEntity(Product), { id: "product-1", title: "product 1", + handle: "product-1", status: ProductStatus.PUBLISHED, }) @@ -258,6 +259,7 @@ moduleIntegrationTestRunner({ productOne = testManager.create(toMikroORMEntity(Product), { id: "product-1", title: "product 1", + handle: "product-1", status: ProductStatus.PUBLISHED, }) @@ -565,10 +567,12 @@ moduleIntegrationTestRunner({ { id: "test-1", title: "col 1", + handle: "col-1", }, { id: "test-2", title: "col 2", + handle: "col-2", }, ] diff --git a/packages/modules/product/src/models/product-image.ts b/packages/modules/product/src/models/product-image.ts index 5bbf61a72aa76..e52c124fc9722 100644 --- a/packages/modules/product/src/models/product-image.ts +++ b/packages/modules/product/src/models/product-image.ts @@ -11,12 +11,15 @@ const imageUrlIndexName = "IDX_product_image_url" // }) const ProductImage = model - .define("ProductImage", { - id: model.id().primaryKey(), - url: model.text(), - metadata: model.json().nullable(), - products: model.manyToMany(() => Product), - }) + .define( + { tableName: "image", name: "ProductImage" }, + { + id: model.id().primaryKey(), + url: model.text(), + metadata: model.json().nullable(), + products: model.manyToMany(() => Product), + } + ) .indexes([ { name: imageUrlIndexName, diff --git a/packages/modules/product/src/models/product-tag.ts b/packages/modules/product/src/models/product-tag.ts index 31faa6c38eaf1..d53d9249d07a5 100644 --- a/packages/modules/product/src/models/product-tag.ts +++ b/packages/modules/product/src/models/product-tag.ts @@ -12,7 +12,7 @@ const tagValueIndexName = "IDX_tag_value_unique" const ProductTag = model .define( - { tableName: "product_tags", name: "ProductTag" }, + { tableName: "product_tag", name: "ProductTag" }, { id: model.id().primaryKey(), value: model.text().searchable(), diff --git a/packages/modules/product/src/repositories/product.ts b/packages/modules/product/src/repositories/product.ts index 656cd5e8c20db..707f3159cb6f3 100644 --- a/packages/modules/product/src/repositories/product.ts +++ b/packages/modules/product/src/repositories/product.ts @@ -1,6 +1,6 @@ import { Product } from "@models" -import { DALUtils } from "@medusajs/framework/utils" +import { DALUtils, toHandle } from "@medusajs/framework/utils" import { Context, DAL } from "@medusajs/framework/types" import { SqlEntityManager } from "@mikro-orm/postgresql" @@ -15,7 +15,12 @@ export class ProductRepository extends DALUtils.mikroOrmBaseRepositoryFactory( // TODO: temporary fix until the DML support something like default on create for the handle as the example async create(data: any[], context: Context = {}) { - return await super.create(data, context) + return await super.create( + data.map((row) => { + return { handle: toHandle(row.title), ...row } + }), + context + ) } /** From 19ac9d4c84865c9cb775b91bce64ac21b9cc53fe Mon Sep 17 00:00:00 2001 From: adrien2p Date: Thu, 14 Nov 2024 14:43:26 +0100 Subject: [PATCH 025/175] fix repository --- .../utils/src/dal/mikro-orm/mikro-orm-repository.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/core/utils/src/dal/mikro-orm/mikro-orm-repository.ts b/packages/core/utils/src/dal/mikro-orm/mikro-orm-repository.ts index 7f36e470c2250..3c5982674e03f 100644 --- a/packages/core/utils/src/dal/mikro-orm/mikro-orm-repository.ts +++ b/packages/core/utils/src/dal/mikro-orm/mikro-orm-repository.ts @@ -38,7 +38,7 @@ import { import { dbErrorMapper } from "./db-error-mapper" import { mikroOrmSerializer } from "./mikro-orm-serializer" import { mikroOrmUpdateDeletedAtRecursively } from "./utils" -import { DmlEntity, toMikroORMEntity } from "../../dml" +import { toMikroORMEntity } from "../../dml" export class MikroOrmBase { readonly manager_: any @@ -317,9 +317,9 @@ export function mikroOrmBaseRepositoryFactory( ): { new ({ manager }: { manager: any }): MikroOrmBaseRepository } { - const mikroOrmEntity = ( - DmlEntity.isDmlEntity(entity) ? toMikroORMEntity(entity) : entity - ) as EntityClass> + const mikroOrmEntity = toMikroORMEntity(entity) as EntityClass< + InferEntityType + > class MikroOrmAbstractBaseRepository_ extends MikroOrmBaseRepository { entity = mikroOrmEntity @@ -482,7 +482,7 @@ export function mikroOrmBaseRepositoryFactory( }) return (await manager.find( - entity as EntityName, + this.entity as EntityName, findOptions_.where as MikroFilterQuery, findOptions_.options as MikroOptions )) as InferRepositoryReturnType[] From 7f4fd67f6904e009c8806bbb547345c814fc4ec6 Mon Sep 17 00:00:00 2001 From: adrien2p Date: Thu, 14 Nov 2024 15:44:01 +0100 Subject: [PATCH 026/175] fix pivot table computaion + fix mikro orm repository --- .../src/dal/mikro-orm/mikro-orm-repository.ts | 18 +- .../src/dml/__tests__/entity-builder.spec.ts | 154 ++++++++++++++++++ .../entity-builder/define-relationship.ts | 2 +- 3 files changed, 162 insertions(+), 12 deletions(-) diff --git a/packages/core/utils/src/dal/mikro-orm/mikro-orm-repository.ts b/packages/core/utils/src/dal/mikro-orm/mikro-orm-repository.ts index 3c5982674e03f..80e251e5e0b77 100644 --- a/packages/core/utils/src/dal/mikro-orm/mikro-orm-repository.ts +++ b/packages/core/utils/src/dal/mikro-orm/mikro-orm-repository.ts @@ -3,9 +3,9 @@ import { Context, DAL, FilterQuery, - FilterQuery as InternalFilterQuery, InferEntityType, InferRepositoryReturnType, + FilterQuery as InternalFilterQuery, PerformedActions, RepositoryService, RepositoryTransformOptions, @@ -17,11 +17,10 @@ import { EntityName, EntityProperty, EntitySchema, + LoadStrategy, FilterQuery as MikroFilterQuery, FindOptions as MikroOptions, - LoadStrategy, ReferenceType, - RequiredEntityData, } from "@mikro-orm/core" import { SqlEntityManager } from "@mikro-orm/postgresql" import { @@ -30,6 +29,7 @@ import { MedusaError, promiseAll, } from "../../common" +import { toMikroORMEntity } from "../../dml" import { buildQuery } from "../../modules-sdk/build-query" import { getSoftDeletedCascadedEntitiesIdsMappedBy, @@ -38,7 +38,6 @@ import { import { dbErrorMapper } from "./db-error-mapper" import { mikroOrmSerializer } from "./mikro-orm-serializer" import { mikroOrmUpdateDeletedAtRecursively } from "./utils" -import { toMikroORMEntity } from "../../dml" export class MikroOrmBase { readonly manager_: any @@ -354,10 +353,7 @@ export function mikroOrmBaseRepositoryFactory( const manager = this.getActiveManager(context) const entities = data.map((data_) => { - return manager.create( - entity as EntityName, - data_ as RequiredEntityData - ) + return manager.create(this.entity, data_) }) manager.persist(entities) @@ -453,7 +449,7 @@ export function mikroOrmBaseRepositoryFactory( context?: Context ): Promise { const manager = this.getActiveManager(context) - await manager.nativeDelete(entity as EntityName, filters as any) + await manager.nativeDelete(this.entity, filters) } async find( @@ -506,8 +502,8 @@ export function mikroOrmBaseRepositoryFactory( }) return (await manager.findAndCount( - entity as EntityName, - findOptions_.where as MikroFilterQuery, + this.entity, + findOptions_.where, findOptions_.options as MikroOptions )) as [InferRepositoryReturnType[], number] } diff --git a/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts b/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts index 0a9f34f162e6d..862447f7d9d3e 100644 --- a/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts +++ b/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts @@ -5875,6 +5875,160 @@ describe("Entity builder", () => { }) }) + test("should compute the pivot table name correctly", () => { + const team = model.define("teamSquad", { + id: model.number(), + name: model.text(), + users: model.manyToMany(() => user), + }) + + const user = model.define("RandomUser", { + id: model.number(), + username: model.text(), + teams: model.manyToMany(() => team, { + mappedBy: "users", + }), + }) + + const User = toMikroORMEntity(user) + const Team = toMikroORMEntity(team) + + const metaData = MetadataStorage.getMetadataFromDecorator(User) + expect(metaData.className).toEqual("RandomUser") + expect(metaData.path).toEqual("RandomUser") + expect(metaData.properties).toEqual({ + id: { + reference: "scalar", + type: "number", + columnType: "integer", + name: "id", + fieldName: "id", + nullable: false, + getter: false, + setter: false, + }, + username: { + reference: "scalar", + type: "string", + columnType: "text", + name: "username", + fieldName: "username", + nullable: false, + getter: false, + setter: false, + }, + teams: { + reference: "m:n", + name: "teams", + entity: "TeamSquad", + pivotTable: "random_user_team_squads", + mappedBy: "users", + }, + created_at: { + reference: "scalar", + type: "date", + columnType: "timestamptz", + name: "created_at", + fieldName: "created_at", + defaultRaw: "now()", + onCreate: expect.any(Function), + nullable: false, + getter: false, + setter: false, + }, + updated_at: { + reference: "scalar", + type: "date", + columnType: "timestamptz", + name: "updated_at", + fieldName: "updated_at", + defaultRaw: "now()", + onCreate: expect.any(Function), + onUpdate: expect.any(Function), + nullable: false, + getter: false, + setter: false, + }, + deleted_at: { + reference: "scalar", + type: "date", + columnType: "timestamptz", + name: "deleted_at", + fieldName: "deleted_at", + nullable: true, + getter: false, + setter: false, + }, + }) + + const teamMetaData = MetadataStorage.getMetadataFromDecorator(Team) + expect(teamMetaData.className).toEqual("TeamSquad") + expect(teamMetaData.path).toEqual("TeamSquad") + expect(teamMetaData.properties).toEqual({ + id: { + reference: "scalar", + type: "number", + columnType: "integer", + name: "id", + fieldName: "id", + nullable: false, + getter: false, + setter: false, + }, + name: { + reference: "scalar", + type: "string", + columnType: "text", + name: "name", + fieldName: "name", + nullable: false, + getter: false, + setter: false, + }, + users: { + reference: "m:n", + name: "users", + entity: "RandomUser", + pivotTable: "random_user_team_squads", + }, + created_at: { + reference: "scalar", + type: "date", + columnType: "timestamptz", + name: "created_at", + fieldName: "created_at", + defaultRaw: "now()", + onCreate: expect.any(Function), + nullable: false, + getter: false, + setter: false, + }, + updated_at: { + reference: "scalar", + type: "date", + columnType: "timestamptz", + name: "updated_at", + fieldName: "updated_at", + defaultRaw: "now()", + onCreate: expect.any(Function), + onUpdate: expect.any(Function), + nullable: false, + getter: false, + setter: false, + }, + deleted_at: { + reference: "scalar", + type: "date", + columnType: "timestamptz", + name: "deleted_at", + fieldName: "deleted_at", + nullable: true, + getter: false, + setter: false, + }, + }) + }) + test("define custom pivot table name", () => { const team = model.define("team", { id: model.number(), diff --git a/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts b/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts index fdf8c392c3cfc..65e316dccd2b3 100644 --- a/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts +++ b/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts @@ -381,7 +381,7 @@ export function defineManyToManyRelationship( */ pivotTableName = relationship.options.pivotTable ?? - [MikroORMEntity.name.toLowerCase(), relatedModelName.toLowerCase()] + [MikroORMEntity.name, relatedModelName] .sort() .map((token, index) => { if (index === 1) { From 8d53b32a92879f97a653a0137430101d5d08e97b Mon Sep 17 00:00:00 2001 From: adrien2p Date: Thu, 14 Nov 2024 18:24:10 +0100 Subject: [PATCH 027/175] fix many to many management and configuration --- .../dml/helpers/create-mikro-orm-entity.ts | 2 +- .../entity-builder/define-relationship.ts | 127 +++++++++++++----- .../integration-tests/__tests__/enum.spec.ts | 6 +- .../__tests__/has-one-belongs-to.spec.ts | 6 +- .../__tests__/many-to-many.spec.ts | 30 +++-- .../__tests__/many-to-one.spec.ts | 6 +- .../__tests__/migrations-generate.spec.ts | 3 +- .../integration-tests/__tests__/product.ts | 2 +- .../modules/product/src/models/product.ts | 2 + 9 files changed, 131 insertions(+), 53 deletions(-) diff --git a/packages/core/utils/src/dml/helpers/create-mikro-orm-entity.ts b/packages/core/utils/src/dml/helpers/create-mikro-orm-entity.ts index 54fccd5306ff6..8432dcf291b4e 100644 --- a/packages/core/utils/src/dml/helpers/create-mikro-orm-entity.ts +++ b/packages/core/utils/src/dml/helpers/create-mikro-orm-entity.ts @@ -86,7 +86,7 @@ function createMikrORMEntity() { applyIndexes(MikroORMEntity, tableName, field) applySearchable(MikroORMEntity, field) } else { - defineRelationship(MikroORMEntity, field, cascades, context) + defineRelationship(MikroORMEntity, entity, field, cascades, context) } }) diff --git a/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts b/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts index 65e316dccd2b3..2d0da25ca94af 100644 --- a/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts +++ b/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts @@ -27,36 +27,36 @@ type Context = { MANY_TO_MANY_TRACKED_RELATIONS: Record } -/** - * Validates a many to many relationship without mappedBy and checks if the other side of the relationship is defined and possesses mappedBy. - * @param MikroORMEntity - * @param relationship - * @param relatedEntity - * @param relatedModelName - */ -function validateManyToManyRelationshipWithoutMappedBy({ - MikroORMEntity, +function retrieveOtherSideRelationship({ relationship, relatedEntity, relatedModelName, + entity, }: { - MikroORMEntity: EntityConstructor relationship: RelationshipMetadata relatedEntity: DmlEntity< Record | RelationshipType>, any > relatedModelName: string + entity: DmlEntity }) { + if (relationship.mappedBy) { + return relatedEntity.parse().schema[ + relationship.mappedBy + ] as RelationshipType + } + /** * Since we don't have the information about the other side of the * relationship, we will try to find all the other side many to many that refers to the current entity. * If there is any, we will try to find if at least one of them has a mappedBy. */ - const potentialOtherSides = Object.entries(relatedEntity.schema) + const potentialOtherSide = Object.entries(relatedEntity.schema) .filter(([, propConfig]) => DmlManyToMany.isManyToMany(propConfig)) - .filter(([prop, propConfig]) => { + .find(([prop, propConfig]) => { const parsedProp = propConfig.parse(prop) as RelationshipMetadata + const relatedEntity = typeof parsedProp.entity === "function" ? parsedProp.entity() @@ -68,21 +68,54 @@ function validateManyToManyRelationshipWithoutMappedBy({ ) } - return parseEntityName(relatedEntity).modelName === MikroORMEntity.name - }) as unknown as [string, RelationshipType][] - - if (potentialOtherSides.length) { - const hasMappedBy = potentialOtherSides.some( - ([, propConfig]) => !!propConfig.parse("").mappedBy - ) - if (!hasMappedBy) { - throw new Error( - `Invalid relationship reference for "${MikroORMEntity.name}.${relationship.name}". "mappedBy" should be defined on one side or the other.` + return ( + parsedProp.mappedBy === relationship.name && + parseEntityName(relatedEntity).modelName === + parseEntityName(entity).modelName ) - } - } else { + }) as unknown as [string, RelationshipType] + + return potentialOtherSide?.[1] +} + +/** + * Validates a many to many relationship without mappedBy and checks if the other side of the relationship is defined and possesses mappedBy. + * @param MikroORMEntity + * @param relationship + * @param relatedEntity + * @param relatedModelName + */ +function validateManyToManyRelationshipWithoutMappedBy({ + MikroORMEntity, + relationship, + relatedEntity, + relatedModelName, + entity, +}: { + MikroORMEntity: EntityConstructor + relationship: RelationshipMetadata + relatedEntity: DmlEntity< + Record | RelationshipType>, + any + > + relatedModelName: string + entity: DmlEntity +}) { + /** + * Since we don't have the information about the other side of the + * relationship, we will try to find all the other side many to many that refers to the current entity. + * If there is any, we will try to find if at least one of them has a mappedBy. + */ + const potentialOtherSide = retrieveOtherSideRelationship({ + relationship, + relatedEntity, + relatedModelName, + entity, + }) + + if (!potentialOtherSide) { throw new Error( - `Invalid relationship reference for "${MikroORMEntity.name}.${relationship.name}". The other side of the relationship is missing.` + `Invalid relationship reference for "${MikroORMEntity.name}.${relationship.name}". "mappedBy" should be defined on one side or the other.` ) } } @@ -289,6 +322,7 @@ export function defineBelongsToRelationship( */ export function defineManyToManyRelationship( MikroORMEntity: EntityConstructor, + entity: DmlEntity, relationship: RelationshipMetadata, relatedEntity: DmlEntity< Record | RelationshipType>, @@ -296,27 +330,41 @@ export function defineManyToManyRelationship( >, { relatedModelName, + relatedTableName, pgSchema, - }: { relatedModelName: string; pgSchema: string | undefined }, + }: { + relatedModelName: string + pgSchema: string | undefined + relatedTableName: string + }, { MANY_TO_MANY_TRACKED_RELATIONS }: Context ) { let mappedBy = relationship.mappedBy let inversedBy: undefined | string let pivotEntityName: undefined | string let pivotTableName: undefined | string + let joinColumn: undefined | string = relationship.options.joinColumn + let inverseJoinColumn: undefined | string = + relationship.options.inverseJoinColumn + + const otherSideRelationship = retrieveOtherSideRelationship({ + relationship, + relatedEntity, + relatedModelName, + entity, + }) /** * Validating other side of relationship when mapped by is defined */ if (mappedBy) { - const otherSideRelation = relatedEntity.parse().schema[mappedBy] - if (!otherSideRelation) { + if (!otherSideRelationship) { throw new Error( `Missing property "${mappedBy}" on "${relatedModelName}" entity. Make sure to define it as a relationship` ) } - if (!DmlManyToMany.isManyToMany(otherSideRelation)) { + if (!DmlManyToMany.isManyToMany(otherSideRelationship)) { throw new Error( `Invalid relationship reference for "${mappedBy}" on "${relatedModelName}" entity. Make sure to define a manyToMany relationship` ) @@ -330,7 +378,7 @@ export function defineManyToManyRelationship( * - Otherwise, we will track ourselves as the owner. */ if ( - otherSideRelation.parse(mappedBy).mappedBy && + otherSideRelationship.parse(mappedBy).mappedBy && MANY_TO_MANY_TRACKED_RELATIONS[`${relatedModelName}.${mappedBy}`] ) { inversedBy = mappedBy @@ -346,6 +394,7 @@ export function defineManyToManyRelationship( relationship, relatedEntity, relatedModelName, + entity, }) } @@ -371,6 +420,7 @@ export function defineManyToManyRelationship( } if (!pivotEntityName) { + const { tableName } = parseEntityName(entity) /** * Pivot table name is created as follows (when not explicitly provided) * @@ -381,17 +431,24 @@ export function defineManyToManyRelationship( */ pivotTableName = relationship.options.pivotTable ?? - [MikroORMEntity.name, relatedModelName] + otherSideRelationship.parse("").options.pivotTable ?? + [tableName, relatedTableName] .sort() .map((token, index) => { if (index === 1) { - return pluralize(camelToSnakeCase(token)) + return pluralize(token) } - return camelToSnakeCase(token) + return token }) .join("_") } + if (!joinColumn || !inverseJoinColumn) { + const otherSideRelationshipOptions = otherSideRelationship.parse("").options + joinColumn ??= otherSideRelationshipOptions.joinColumn + inverseJoinColumn ??= otherSideRelationshipOptions.inverseJoinColumn + } + ManyToMany({ entity: relatedModelName, ...(pivotTableName @@ -404,6 +461,8 @@ export function defineManyToManyRelationship( ...(pivotEntityName ? { pivotEntity: pivotEntityName } : {}), ...(mappedBy ? { mappedBy: mappedBy as any } : {}), ...(inversedBy ? { inversedBy: inversedBy as any } : {}), + ...(joinColumn ? { joinColumn } : {}), + ...(inverseJoinColumn ? { inverseJoinColumn } : {}), })(MikroORMEntity.prototype, relationship.name) } @@ -412,6 +471,7 @@ export function defineManyToManyRelationship( */ export function defineRelationship( MikroORMEntity: EntityConstructor, + entity: DmlEntity, relationship: RelationshipMetadata, cascades: EntityCascades, context: Context @@ -482,6 +542,7 @@ export function defineRelationship( case "manyToMany": defineManyToManyRelationship( MikroORMEntity, + entity, relationship, relatedEntity, relatedEntityInfo, diff --git a/packages/core/utils/src/dml/integration-tests/__tests__/enum.spec.ts b/packages/core/utils/src/dml/integration-tests/__tests__/enum.spec.ts index dd36df9defa76..8cbddb5b33c35 100644 --- a/packages/core/utils/src/dml/integration-tests/__tests__/enum.spec.ts +++ b/packages/core/utils/src/dml/integration-tests/__tests__/enum.spec.ts @@ -4,7 +4,10 @@ import { MikroORM, } from "@mikro-orm/core" import { model } from "../../entity-builder" -import { toMikroOrmEntities } from "../../helpers/create-mikro-orm-entity" +import { + mikroORMEntityBuilder, + toMikroOrmEntities, +} from "../../helpers/create-mikro-orm-entity" import { createDatabase, dropDatabase } from "pg-god" import { CustomTsMigrationGenerator, mikroOrmSerializer } from "../../../dal" import { EntityConstructor } from "@medusajs/types" @@ -28,6 +31,7 @@ describe("EntityBuilder | enum", () => { beforeEach(async () => { MetadataStorage.clear() + mikroORMEntityBuilder.clear() const user = model.define("user", { id: model.id().primaryKey(), diff --git a/packages/core/utils/src/dml/integration-tests/__tests__/has-one-belongs-to.spec.ts b/packages/core/utils/src/dml/integration-tests/__tests__/has-one-belongs-to.spec.ts index 17a8ea6b2f36a..eab1935f02291 100644 --- a/packages/core/utils/src/dml/integration-tests/__tests__/has-one-belongs-to.spec.ts +++ b/packages/core/utils/src/dml/integration-tests/__tests__/has-one-belongs-to.spec.ts @@ -1,6 +1,9 @@ import { MetadataStorage, MikroORM } from "@mikro-orm/core" import { model } from "../../entity-builder" -import { toMikroOrmEntities } from "../../helpers/create-mikro-orm-entity" +import { + mikroORMEntityBuilder, + toMikroOrmEntities, +} from "../../helpers/create-mikro-orm-entity" import { createDatabase, dropDatabase } from "pg-god" import { CustomTsMigrationGenerator, mikroOrmSerializer } from "../../../dal" import { EntityConstructor } from "@medusajs/types" @@ -24,6 +27,7 @@ describe("hasOne - belongTo", () => { beforeEach(async () => { MetadataStorage.clear() + mikroORMEntityBuilder.clear() const team = model.define("team", { id: model.id().primaryKey(), diff --git a/packages/core/utils/src/dml/integration-tests/__tests__/many-to-many.spec.ts b/packages/core/utils/src/dml/integration-tests/__tests__/many-to-many.spec.ts index 36e47099c5bec..15c0d33a2bb0a 100644 --- a/packages/core/utils/src/dml/integration-tests/__tests__/many-to-many.spec.ts +++ b/packages/core/utils/src/dml/integration-tests/__tests__/many-to-many.spec.ts @@ -1,6 +1,9 @@ import { MetadataStorage, MikroORM } from "@mikro-orm/core" import { model } from "../../entity-builder" -import { toMikroOrmEntities } from "../../helpers/create-mikro-orm-entity" +import { + mikroORMEntityBuilder, + toMikroOrmEntities, +} from "../../helpers/create-mikro-orm-entity" import { createDatabase, dropDatabase } from "pg-god" import { CustomTsMigrationGenerator, mikroOrmSerializer } from "../../../dal" import { EntityConstructor } from "@medusajs/types" @@ -8,6 +11,8 @@ import { pgGodCredentials } from "../utils" import { FileSystem } from "../../../common" import { join } from "path" +jest.setTimeout(300000) + export const fileSystem = new FileSystem( join(__dirname, "../../integration-tests-migrations-many-to-many") ) @@ -27,6 +32,7 @@ describe("manyToMany - manyToMany", () => { beforeEach(async () => { MetadataStorage.clear() + mikroORMEntityBuilder.clear() const team = model.define("team", { id: model.id().primaryKey(), @@ -192,31 +198,25 @@ describe("manyToMany - manyToMany", () => { }) it(`should fail to load the dml's if both side of the relation are missing the mappedBy options`, () => { + mikroORMEntityBuilder.clear() + const team = model.define("team", { id: model.id().primaryKey(), name: model.text(), users: model.manyToMany(() => user, { - pivotEntity: () => squad, + pivot_table: "team_users", }), }) - const squad = model.define("teamUsers", { - id: model.id().primaryKey(), - user: model.belongsTo(() => user, { mappedBy: "squads" }), - squad: model.belongsTo(() => team, { mappedBy: "users" }), - }) - const user = model.define("user", { id: model.id().primaryKey(), username: model.text(), - squads: model.manyToMany(() => team, { - pivotEntity: () => squad, - }), + squads: model.manyToMany(() => team), }) let error!: Error try { - ;[User, Squad, Team] = toMikroOrmEntities([user, squad, team]) + ;[User, Team] = toMikroOrmEntities([user, team]) } catch (e) { error = e } @@ -227,7 +227,9 @@ describe("manyToMany - manyToMany", () => { ) }) - it(`should fail to load the dml's if the relation is defined only on one side`, () => { + it.only(`should fail to load the dml's if the relation is defined only on one side`, () => { + mikroORMEntityBuilder.clear() + const team = model.define("team", { id: model.id().primaryKey(), name: model.text(), @@ -248,7 +250,7 @@ describe("manyToMany - manyToMany", () => { expect(error).toBeTruthy() expect(error.message).toEqual( - 'Invalid relationship reference for "Team.users". The other side of the relationship is missing.' + 'Invalid relationship reference for "Team.users". "mappedBy" should be defined on one side or the other.' ) }) }) diff --git a/packages/core/utils/src/dml/integration-tests/__tests__/many-to-one.spec.ts b/packages/core/utils/src/dml/integration-tests/__tests__/many-to-one.spec.ts index 07a4c7cf1e221..a44ce4826d71e 100644 --- a/packages/core/utils/src/dml/integration-tests/__tests__/many-to-one.spec.ts +++ b/packages/core/utils/src/dml/integration-tests/__tests__/many-to-one.spec.ts @@ -1,6 +1,9 @@ import { MetadataStorage, MikroORM } from "@mikro-orm/core" import { model } from "../../entity-builder" -import { toMikroOrmEntities } from "../../helpers/create-mikro-orm-entity" +import { + mikroORMEntityBuilder, + toMikroOrmEntities, +} from "../../helpers/create-mikro-orm-entity" import { createDatabase, dropDatabase } from "pg-god" import { CustomTsMigrationGenerator, @@ -30,6 +33,7 @@ describe("manyToOne - belongTo", () => { beforeEach(async () => { MetadataStorage.clear() + mikroORMEntityBuilder.clear() const team = model.define("team", { id: model.id().primaryKey(), diff --git a/packages/core/utils/src/migrations/integration-tests/__tests__/migrations-generate.spec.ts b/packages/core/utils/src/migrations/integration-tests/__tests__/migrations-generate.spec.ts index b6fb09f245361..c95f2ded476ba 100644 --- a/packages/core/utils/src/migrations/integration-tests/__tests__/migrations-generate.spec.ts +++ b/packages/core/utils/src/migrations/integration-tests/__tests__/migrations-generate.spec.ts @@ -4,7 +4,7 @@ import { MetadataStorage } from "@mikro-orm/core" import { Migrations } from "../../index" import { FileSystem } from "../../../common" -import { DmlEntity, model } from "../../../dml" +import { DmlEntity, mikroORMEntityBuilder, model } from "../../../dml" import { defineMikroOrmCliConfig } from "../../../modules-sdk" const DB_HOST = process.env.DB_HOST ?? "localhost" @@ -29,6 +29,7 @@ describe("Generate migrations", () => { afterEach(async () => { await fs.cleanup() MetadataStorage.clear() + mikroORMEntityBuilder.clear() }, 300 * 1000) test("generate migrations for a single entity", async () => { diff --git a/packages/modules/product/integration-tests/__tests__/product.ts b/packages/modules/product/integration-tests/__tests__/product.ts index 28305859092da..de05545dd3959 100644 --- a/packages/modules/product/integration-tests/__tests__/product.ts +++ b/packages/modules/product/integration-tests/__tests__/product.ts @@ -218,7 +218,7 @@ moduleIntegrationTestRunner({ images = await createImages(testManager, ["image-1"]) }) - it("should create a product", async () => { + it.only("should create a product", async () => { const data = buildProductOnlyData({ images, thumbnail: images[0].url, diff --git a/packages/modules/product/src/models/product.ts b/packages/modules/product/src/models/product.ts index da4ebf0be9230..ba90840544820 100644 --- a/packages/modules/product/src/models/product.ts +++ b/packages/modules/product/src/models/product.ts @@ -74,6 +74,8 @@ const Product = model images: model.manyToMany(() => ProductImage, { pivotTable: "product_images", mappedBy: "products", + joinColumn: "product_id", + inverseJoinColumn: "image_id", }), collection: model .belongsTo(() => ProductCollection, { From ddb994ae12800911ccc968347812f551c0764187 Mon Sep 17 00:00:00 2001 From: adrien2p Date: Thu, 14 Nov 2024 18:32:50 +0100 Subject: [PATCH 028/175] fix many to many management and configuration --- .../utils/src/dml/helpers/entity-builder/define-relationship.ts | 1 + packages/modules/product/integration-tests/__tests__/product.ts | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts b/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts index 2d0da25ca94af..98fe5a570334d 100644 --- a/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts +++ b/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts @@ -450,6 +450,7 @@ export function defineManyToManyRelationship( } ManyToMany({ + owner: !!relationship.options.pivotTable, // TODO: need clarification and discussion in order to infer it differently instead entity: relatedModelName, ...(pivotTableName ? { diff --git a/packages/modules/product/integration-tests/__tests__/product.ts b/packages/modules/product/integration-tests/__tests__/product.ts index de05545dd3959..28305859092da 100644 --- a/packages/modules/product/integration-tests/__tests__/product.ts +++ b/packages/modules/product/integration-tests/__tests__/product.ts @@ -218,7 +218,7 @@ moduleIntegrationTestRunner({ images = await createImages(testManager, ["image-1"]) }) - it.only("should create a product", async () => { + it("should create a product", async () => { const data = buildProductOnlyData({ images, thumbnail: images[0].url, From dd5f67ee5ebed8611d74bfeae5e09f207b01f62e Mon Sep 17 00:00:00 2001 From: adrien2p Date: Fri, 15 Nov 2024 09:37:53 +0100 Subject: [PATCH 029/175] fix many to many management and configuration --- packages/core/utils/src/dml/entity-builder.ts | 8 ++++++++ .../product/integration-tests/__tests__/product.ts | 2 +- packages/modules/product/src/models/product.ts | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/core/utils/src/dml/entity-builder.ts b/packages/core/utils/src/dml/entity-builder.ts index c6aa9ce3fc579..ac4396d7ebf15 100644 --- a/packages/core/utils/src/dml/entity-builder.ts +++ b/packages/core/utils/src/dml/entity-builder.ts @@ -56,6 +56,14 @@ export type ManyToManyOptions = RelationshipOptions & * @ignore */ pivotEntity?: never + /** + * The column name in the pivot table that for the current entity + */ + joinColumn?: string + /** + * The column name in the pivot table for the opposite entity + */ + inverseJoinColumn?: string } | { /** diff --git a/packages/modules/product/integration-tests/__tests__/product.ts b/packages/modules/product/integration-tests/__tests__/product.ts index 28305859092da..d0a10b4d86286 100644 --- a/packages/modules/product/integration-tests/__tests__/product.ts +++ b/packages/modules/product/integration-tests/__tests__/product.ts @@ -390,7 +390,7 @@ moduleIntegrationTestRunner({ await service.softDelete([products[0].id]) }) - it("should list all products that are not deleted", async () => { + it.only("should list all products that are not deleted", async () => { const products = await service.list() expect(products).toHaveLength(2) diff --git a/packages/modules/product/src/models/product.ts b/packages/modules/product/src/models/product.ts index ba90840544820..feabc47c3fa13 100644 --- a/packages/modules/product/src/models/product.ts +++ b/packages/modules/product/src/models/product.ts @@ -67,6 +67,7 @@ const Product = model .nullable(), tags: model.manyToMany(() => ProductTag, { mappedBy: "products", + pivot_table: "product_tags", }), options: model.hasMany(() => ProductOption, { mappedBy: "product", From f77402d8576fefbe6c55ad21d2291b76cfc722bd Mon Sep 17 00:00:00 2001 From: adrien2p Date: Fri, 15 Nov 2024 09:43:57 +0100 Subject: [PATCH 030/175] update product tag relation configuration --- packages/modules/product/integration-tests/__tests__/product.ts | 2 +- packages/modules/product/src/models/product.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/modules/product/integration-tests/__tests__/product.ts b/packages/modules/product/integration-tests/__tests__/product.ts index d0a10b4d86286..28305859092da 100644 --- a/packages/modules/product/integration-tests/__tests__/product.ts +++ b/packages/modules/product/integration-tests/__tests__/product.ts @@ -390,7 +390,7 @@ moduleIntegrationTestRunner({ await service.softDelete([products[0].id]) }) - it.only("should list all products that are not deleted", async () => { + it("should list all products that are not deleted", async () => { const products = await service.list() expect(products).toHaveLength(2) diff --git a/packages/modules/product/src/models/product.ts b/packages/modules/product/src/models/product.ts index feabc47c3fa13..fb46f98cf0cc2 100644 --- a/packages/modules/product/src/models/product.ts +++ b/packages/modules/product/src/models/product.ts @@ -67,7 +67,7 @@ const Product = model .nullable(), tags: model.manyToMany(() => ProductTag, { mappedBy: "products", - pivot_table: "product_tags", + pivotTable: "product_tags", }), options: model.hasMany(() => ProductOption, { mappedBy: "product", From ec677fbd7c4278e1ec61661e82df6ed4fd766a3a Mon Sep 17 00:00:00 2001 From: adrien2p Date: Fri, 15 Nov 2024 11:21:53 +0100 Subject: [PATCH 031/175] Introduce experimental dml hooks to fix some issues with categories --- packages/core/utils/src/dml/entity.ts | 30 +++++++++++++++++++ .../dml/helpers/create-mikro-orm-entity.ts | 27 +++++++++++++++-- .../entity-builder/define-relationship.ts | 9 +++--- .../__fixtures__/product/data/categories.ts | 3 ++ .../integration-tests/__tests__/product.ts | 2 +- .../product/src/models/product-category.ts | 10 +++++++ .../modules/product/src/models/product-tag.ts | 4 +-- 7 files changed, 74 insertions(+), 11 deletions(-) diff --git a/packages/core/utils/src/dml/entity.ts b/packages/core/utils/src/dml/entity.ts index ab0f4931be9f7..15923d63acb5c 100644 --- a/packages/core/utils/src/dml/entity.ts +++ b/packages/core/utils/src/dml/entity.ts @@ -6,6 +6,7 @@ import { IDmlEntity, IDmlEntityConfig, InferDmlEntityNameFromConfig, + InferSchemaFields, QueryCondition, } from "@medusajs/types" import { isObject, isString, toCamelCase } from "../common" @@ -14,6 +15,14 @@ import { BelongsTo } from "./relations/belongs-to" const IsDmlEntity = Symbol.for("isDmlEntity") +/** + * @experimental + * need to be moved after RFV + */ +type Hooks = { + creating?: (entity: InferSchemaFields) => void +} + function extractNameAndTableName( nameOrConfig: Config ) { @@ -69,6 +78,13 @@ export class DmlEntity< #cascades: EntityCascades = {} #indexes: EntityIndex[] = [] + /** + * @experimental + * TODO: Write RFC about this, for now it is unstable and mainly + * for test purposes + */ + #hooks: Hooks = {} + constructor(nameOrConfig: TConfig, schema: Schema) { const { name, tableName } = extractNameAndTableName(nameOrConfig) this.schema = schema @@ -96,6 +112,7 @@ export class DmlEntity< schema: DMLSchema cascades: EntityCascades indexes: EntityIndex[] + hooks: Hooks } { return { name: this.name, @@ -103,6 +120,7 @@ export class DmlEntity< schema: this.schema, cascades: this.#cascades, indexes: this.#indexes, + hooks: this.#hooks, } } @@ -234,4 +252,16 @@ export class DmlEntity< this.#indexes = indexes as EntityIndex[] return this } + + /** + * @experimental + * TODO: Write RFC about this, for now it is unstable and mainly + * for test purposes + * @param hooks + * @returns + */ + hooks(hooks: Hooks): this { + this.#hooks = hooks + return this + } } diff --git a/packages/core/utils/src/dml/helpers/create-mikro-orm-entity.ts b/packages/core/utils/src/dml/helpers/create-mikro-orm-entity.ts index 8432dcf291b4e..e5501c934d43f 100644 --- a/packages/core/utils/src/dml/helpers/create-mikro-orm-entity.ts +++ b/packages/core/utils/src/dml/helpers/create-mikro-orm-entity.ts @@ -6,7 +6,7 @@ import type { Infer, PropertyType, } from "@medusajs/types" -import { Entity, Filter } from "@mikro-orm/core" +import { BeforeCreate, Entity, Filter } from "@mikro-orm/core" import { mikroOrmSoftDeletableFilterOptions } from "../../dal" import { DmlEntity } from "../entity" import { IdProperty } from "../properties/id" @@ -16,6 +16,7 @@ import { applySearchable } from "./entity-builder/apply-searchable" import { parseEntityName } from "./entity-builder/parse-entity-name" import { defineRelationship } from "./entity-builder/define-relationship" import { applyEntityIndexes, applyIndexes } from "./mikro-orm/apply-indexes" +import { camelToSnakeCase } from "../../common" /** * Factory function to create the mikro orm entity builder. The return @@ -46,7 +47,12 @@ function createMikrORMEntity() { function createEntity>(entity: T): Infer { class MikroORMEntity {} - const { schema, cascades, indexes: entityIndexes = [] } = entity.parse() + const { + schema, + cascades, + indexes: entityIndexes = [], + hooks = {}, + } = entity.parse() const { modelName, tableName } = parseEntityName(entity) if (ENTITIES[modelName]) { return ENTITIES[modelName] as Infer @@ -92,6 +98,23 @@ function createMikrORMEntity() { applyEntityIndexes(MikroORMEntity, tableName, entityIndexes) + /** + * @experimental + * TODO: Write RFC about this, for now it is unstable and should be moved + * to `applyHooks` + */ + for (const [hookName, hook] of Object.entries(hooks)) { + if (hookName === "creating") { + const hookMethodName = "beforeCreate_" + camelToSnakeCase(modelName) + const hookWrapper = function (this: MikroORMEntity) { + return hook(this as any) + } + + MikroORMEntity.prototype[hookMethodName] = hookWrapper + BeforeCreate()(MikroORMEntity.prototype, hookMethodName) + } + } + /** * Converting class to a MikroORM entity */ diff --git a/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts b/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts index 98fe5a570334d..a54aa14674b51 100644 --- a/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts +++ b/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts @@ -27,7 +27,7 @@ type Context = { MANY_TO_MANY_TRACKED_RELATIONS: Record } -function retrieveOtherSideRelationship({ +function retrieveOtherSideRelationshipMAnyToMany({ relationship, relatedEntity, relatedModelName, @@ -106,7 +106,7 @@ function validateManyToManyRelationshipWithoutMappedBy({ * relationship, we will try to find all the other side many to many that refers to the current entity. * If there is any, we will try to find if at least one of them has a mappedBy. */ - const potentialOtherSide = retrieveOtherSideRelationship({ + const potentialOtherSide = retrieveOtherSideRelationshipMAnyToMany({ relationship, relatedEntity, relatedModelName, @@ -228,7 +228,7 @@ export function defineBelongsToRelationship( } this[relationship.name] ??= this[foreignKeyName] - this[foreignKeyName] ??= this[relationship.name]?.id + this[foreignKeyName] ??= this[relationship.name]?.id ?? null } /** @@ -255,7 +255,6 @@ export function defineBelongsToRelationship( nullable: relationship.nullable, onDelete: shouldCascade ? "cascade" : undefined, })(MikroORMEntity.prototype, foreignKeyName) - ForeignKey()(MikroORMEntity.prototype, foreignKeyName) if (DmlManyToMany.isManyToMany(otherSideRelation)) { Property({ @@ -347,7 +346,7 @@ export function defineManyToManyRelationship( let inverseJoinColumn: undefined | string = relationship.options.inverseJoinColumn - const otherSideRelationship = retrieveOtherSideRelationship({ + const otherSideRelationship = retrieveOtherSideRelationshipMAnyToMany({ relationship, relatedEntity, relatedModelName, diff --git a/packages/modules/product/integration-tests/__fixtures__/product/data/categories.ts b/packages/modules/product/integration-tests/__fixtures__/product/data/categories.ts index 65bb62c5ad1cc..fd51ee3cd8286 100644 --- a/packages/modules/product/integration-tests/__fixtures__/product/data/categories.ts +++ b/packages/modules/product/integration-tests/__fixtures__/product/data/categories.ts @@ -2,16 +2,19 @@ export const categoriesData = [ { id: "category-0", name: "category 0", + handle: "category-0", parent_category_id: null, }, { id: "category-1", name: "category 1", + handle: "category-1", parent_category_id: "category-0", }, { id: "category-1-a", name: "category 1 a", + handle: "category-1-a", parent_category_id: "category-1", }, ] diff --git a/packages/modules/product/integration-tests/__tests__/product.ts b/packages/modules/product/integration-tests/__tests__/product.ts index 28305859092da..e7e878bdeb7d4 100644 --- a/packages/modules/product/integration-tests/__tests__/product.ts +++ b/packages/modules/product/integration-tests/__tests__/product.ts @@ -39,7 +39,7 @@ import { } from "../__fixtures__/product/data" import ProductImage from "../../src/models/product-image" -jest.setTimeout(30000) +jest.setTimeout(300000) type Service = IProductModuleService & { productService_: ProductService diff --git a/packages/modules/product/src/models/product-category.ts b/packages/modules/product/src/models/product-category.ts index 887fba5552726..6ac81d72d8ebf 100644 --- a/packages/modules/product/src/models/product-category.ts +++ b/packages/modules/product/src/models/product-category.ts @@ -40,6 +40,16 @@ const ProductCategory = model }), products: model.manyToMany(() => Product), }) + .hooks({ + creating: (productCategory) => { + productCategory.mpath = `${ + productCategory.mpath ? productCategory.mpath + "." : "" + }${productCategory.id}` + }, + }) + .cascades({ + delete: ["category_children"], + }) .indexes([ { name: categoryMpathIndexName, diff --git a/packages/modules/product/src/models/product-tag.ts b/packages/modules/product/src/models/product-tag.ts index d53d9249d07a5..cde449458f44d 100644 --- a/packages/modules/product/src/models/product-tag.ts +++ b/packages/modules/product/src/models/product-tag.ts @@ -17,9 +17,7 @@ const ProductTag = model id: model.id().primaryKey(), value: model.text().searchable(), metadata: model.json().nullable(), - products: model.manyToMany(() => Product, { - mappedBy: "tags", - }), + products: model.manyToMany(() => Product), } ) .indexes([ From c750b81961bf5db1dc4deab6670106c4e57051ed Mon Sep 17 00:00:00 2001 From: adrien2p Date: Fri, 15 Nov 2024 11:44:48 +0100 Subject: [PATCH 032/175] more fixes --- .../integration-tests/__tests__/product.ts | 16 +++++++++++++--- packages/modules/product/src/models/product.ts | 7 ++++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/packages/modules/product/integration-tests/__tests__/product.ts b/packages/modules/product/integration-tests/__tests__/product.ts index e7e878bdeb7d4..ba7017fb62c15 100644 --- a/packages/modules/product/integration-tests/__tests__/product.ts +++ b/packages/modules/product/integration-tests/__tests__/product.ts @@ -613,7 +613,12 @@ moduleIntegrationTestRunner({ collection_id: workingCollection.id, }, { - select: ["title", "collection.title"], + select: [ + "title", + "handle", + "collection.title", + "collection.handle", + ], relations: ["collection"], } ) @@ -643,7 +648,12 @@ moduleIntegrationTestRunner({ collection_id: [workingCollection.id, workingCollectionTwo.id], }, { - select: ["title", "collection.title"], + select: [ + "title", + "handle", + "collection.title", + "collection.handle", + ], relations: ["collection"], } ) @@ -752,7 +762,7 @@ moduleIntegrationTestRunner({ images = await createImages(testManager, ["image-1"]) }) - it("should soft delete a product", async () => { + it.only("should soft delete a product", async () => { const data = buildProductOnlyData({ images, thumbnail: images[0].url, diff --git a/packages/modules/product/src/models/product.ts b/packages/modules/product/src/models/product.ts index fb46f98cf0cc2..8d841939bf4ba 100644 --- a/packages/modules/product/src/models/product.ts +++ b/packages/modules/product/src/models/product.ts @@ -1,4 +1,4 @@ -import { model, ProductUtils } from "@medusajs/framework/utils" +import { model, ProductUtils, toHandle } from "@medusajs/framework/utils" import ProductCategory from "./product-category" import ProductCollection from "./product-collection" import ProductImage from "./product-image" @@ -91,6 +91,11 @@ const Product = model .cascades({ delete: ["variants", "options"], }) + .hooks({ + creating: (product) => { + product.handle ??= product.title ? toHandle(product.title) : null + }, + }) .indexes([ { name: productHandleIndexName, From 25ac61ce407e57a9bcd45d1de1a1b51558d76ee8 Mon Sep 17 00:00:00 2001 From: adrien2p Date: Fri, 15 Nov 2024 12:37:08 +0100 Subject: [PATCH 033/175] fix product tests --- packages/modules/product/integration-tests/__tests__/product.ts | 2 +- packages/modules/product/src/models/product-variant.ts | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/modules/product/integration-tests/__tests__/product.ts b/packages/modules/product/integration-tests/__tests__/product.ts index ba7017fb62c15..7040cb9b23dce 100644 --- a/packages/modules/product/integration-tests/__tests__/product.ts +++ b/packages/modules/product/integration-tests/__tests__/product.ts @@ -762,7 +762,7 @@ moduleIntegrationTestRunner({ images = await createImages(testManager, ["image-1"]) }) - it.only("should soft delete a product", async () => { + it("should soft delete a product", async () => { const data = buildProductOnlyData({ images, thumbnail: images[0].url, diff --git a/packages/modules/product/src/models/product-variant.ts b/packages/modules/product/src/models/product-variant.ts index 482ad26810ab3..80d026b5dd912 100644 --- a/packages/modules/product/src/models/product-variant.ts +++ b/packages/modules/product/src/models/product-variant.ts @@ -74,6 +74,8 @@ const ProductVariant = model options: model.manyToMany(() => ProductOptionValue, { pivotTable: "product_variant_option", mappedBy: "variants", + joinColumn: "variant_id", + inverseJoinColumn: "option_value_id", }), }) .indexes([ From bb8aaed5d0806e37c817056dd2d25b7bd9411b73 Mon Sep 17 00:00:00 2001 From: adrien2p Date: Fri, 15 Nov 2024 12:40:23 +0100 Subject: [PATCH 034/175] add missing id prefixes --- packages/modules/product/src/models/product-category.ts | 2 +- packages/modules/product/src/models/product-collection.ts | 2 +- packages/modules/product/src/models/product-image.ts | 2 +- packages/modules/product/src/models/product-option-value.ts | 2 +- packages/modules/product/src/models/product-option.ts | 2 +- packages/modules/product/src/models/product-tag.ts | 2 +- packages/modules/product/src/models/product-type.ts | 2 +- packages/modules/product/src/models/product-variant.ts | 2 +- packages/modules/product/src/models/product.ts | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/modules/product/src/models/product-category.ts b/packages/modules/product/src/models/product-category.ts index 6ac81d72d8ebf..9dd3457e90e47 100644 --- a/packages/modules/product/src/models/product-category.ts +++ b/packages/modules/product/src/models/product-category.ts @@ -21,7 +21,7 @@ const categoryMpathIndexName = "IDX_product_category_path" const ProductCategory = model .define("ProductCategory", { - id: model.id().primaryKey(), + id: model.id({ prefix: "pcat" }).primaryKey(), name: model.text().searchable(), description: model.text().searchable().default(""), handle: model.text().searchable(), diff --git a/packages/modules/product/src/models/product-collection.ts b/packages/modules/product/src/models/product-collection.ts index 8932434273f6a..53e4e3ebb82a4 100644 --- a/packages/modules/product/src/models/product-collection.ts +++ b/packages/modules/product/src/models/product-collection.ts @@ -12,7 +12,7 @@ const collectionHandleIndexName = "IDX_collection_handle_unique" const ProductCollection = model .define("ProductCollection", { - id: model.id().primaryKey(), + id: model.id({ prefix: "pcol" }).primaryKey(), title: model.text().searchable(), handle: model.text().nullable(), metadata: model.json().nullable(), diff --git a/packages/modules/product/src/models/product-image.ts b/packages/modules/product/src/models/product-image.ts index e52c124fc9722..31735c7a11ab5 100644 --- a/packages/modules/product/src/models/product-image.ts +++ b/packages/modules/product/src/models/product-image.ts @@ -14,7 +14,7 @@ const ProductImage = model .define( { tableName: "image", name: "ProductImage" }, { - id: model.id().primaryKey(), + id: model.id({ prefix: "img" }).primaryKey(), url: model.text(), metadata: model.json().nullable(), products: model.manyToMany(() => Product), diff --git a/packages/modules/product/src/models/product-option-value.ts b/packages/modules/product/src/models/product-option-value.ts index 1e23b08cbf675..3b466dc9ecd8b 100644 --- a/packages/modules/product/src/models/product-option-value.ts +++ b/packages/modules/product/src/models/product-option-value.ts @@ -12,7 +12,7 @@ const optionValueOptionIdIndexName = "IDX_option_value_option_id_unique" const ProductOptionValue = model .define("ProductOptionValue", { - id: model.id().primaryKey(), + id: model.id({ prefix: "optval" }).primaryKey(), value: model.text(), metadata: model.json().nullable(), option: model diff --git a/packages/modules/product/src/models/product-option.ts b/packages/modules/product/src/models/product-option.ts index a67ce2791e19d..1a7644936935f 100644 --- a/packages/modules/product/src/models/product-option.ts +++ b/packages/modules/product/src/models/product-option.ts @@ -13,7 +13,7 @@ const optionProductIdTitleIndexName = "IDX_option_product_id_title_unique" const ProductOption = model .define("ProductOption", { - id: model.id().primaryKey(), + id: model.id({ prefix: "opt" }).primaryKey(), title: model.text().searchable(), metadata: model.json().nullable(), product: model.belongsTo(() => Product, { diff --git a/packages/modules/product/src/models/product-tag.ts b/packages/modules/product/src/models/product-tag.ts index cde449458f44d..e5e3ff5359872 100644 --- a/packages/modules/product/src/models/product-tag.ts +++ b/packages/modules/product/src/models/product-tag.ts @@ -14,7 +14,7 @@ const ProductTag = model .define( { tableName: "product_tag", name: "ProductTag" }, { - id: model.id().primaryKey(), + id: model.id({ prefix: "ptag" }).primaryKey(), value: model.text().searchable(), metadata: model.json().nullable(), products: model.manyToMany(() => Product), diff --git a/packages/modules/product/src/models/product-type.ts b/packages/modules/product/src/models/product-type.ts index 77db70aa4e202..eec3c3fd89f62 100644 --- a/packages/modules/product/src/models/product-type.ts +++ b/packages/modules/product/src/models/product-type.ts @@ -12,7 +12,7 @@ const typeValueIndexName = "IDX_type_value_unique" const ProductType = model .define("ProductType", { - id: model.id().primaryKey(), + id: model.id({ prefix: "ptyp" }).primaryKey(), value: model.text().searchable(), metadata: model.json().nullable(), product: model.hasMany(() => Product, { diff --git a/packages/modules/product/src/models/product-variant.ts b/packages/modules/product/src/models/product-variant.ts index 80d026b5dd912..5cc6f37b9f05c 100644 --- a/packages/modules/product/src/models/product-variant.ts +++ b/packages/modules/product/src/models/product-variant.ts @@ -48,7 +48,7 @@ const variantProductIdIndexName = "IDX_product_variant_product_id" const ProductVariant = model .define("ProductVariant", { - id: model.id().primaryKey(), + id: model.id({ prefix: "variant" }).primaryKey(), title: model.text().searchable(), sku: model.text().searchable().nullable(), barcode: model.text().searchable().nullable(), diff --git a/packages/modules/product/src/models/product.ts b/packages/modules/product/src/models/product.ts index 8d841939bf4ba..b69be9d2e3f1e 100644 --- a/packages/modules/product/src/models/product.ts +++ b/packages/modules/product/src/models/product.ts @@ -36,7 +36,7 @@ const productCollectionIndexName = "IDX_product_collection_id" const Product = model .define("Product", { - id: model.id().primaryKey(), + id: model.id({ prefix: "prod" }).primaryKey(), title: model.text().searchable(), handle: model.text().nullable(), // TODO: provide a way to compute a value if not provided (default maybe) subtitle: model.text().searchable().nullable(), From 17fef8c90cdb567a95d9c6b64360034a0869e7c6 Mon Sep 17 00:00:00 2001 From: adrien2p Date: Fri, 15 Nov 2024 12:53:22 +0100 Subject: [PATCH 035/175] fix product category handle management --- packages/modules/product/src/models/product-category.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/modules/product/src/models/product-category.ts b/packages/modules/product/src/models/product-category.ts index 9dd3457e90e47..993dd4545afbb 100644 --- a/packages/modules/product/src/models/product-category.ts +++ b/packages/modules/product/src/models/product-category.ts @@ -1,4 +1,4 @@ -import { model } from "@medusajs/framework/utils" +import { kebabCase, model } from "@medusajs/framework/utils" import Product from "./product" const categoryHandleIndexName = "IDX_category_handle_unique" @@ -45,6 +45,13 @@ const ProductCategory = model productCategory.mpath = `${ productCategory.mpath ? productCategory.mpath + "." : "" }${productCategory.id}` + + /** + * TODO: A validation step might need to exists, maybe at the service level or the repository level + */ + productCategory.handle ??= kebabCase( + productCategory.name ?? productCategory.id // TODO: There seems to be a bug with model configuration where both properties are optional but non nullable. + ) }, }) .cascades({ From b80e090d8835daa9214c9b2f527e6b08746279b4 Mon Sep 17 00:00:00 2001 From: Harminder Virk Date: Fri, 15 Nov 2024 17:56:17 +0530 Subject: [PATCH 036/175] test: fix more failing tests --- .../product-module-service/product-options.spec.ts | 2 +- packages/modules/product/package.json | 2 +- .../modules/product/src/models/product-collection.ts | 9 ++++++++- packages/modules/product/src/models/product-option.ts | 5 +++++ packages/modules/product/src/models/product-tag.ts | 4 +++- 5 files changed, 18 insertions(+), 4 deletions(-) diff --git a/packages/modules/product/integration-tests/__tests__/product-module-service/product-options.spec.ts b/packages/modules/product/integration-tests/__tests__/product-module-service/product-options.spec.ts index 8d7c6952fde8f..67c934342b85d 100644 --- a/packages/modules/product/integration-tests/__tests__/product-module-service/product-options.spec.ts +++ b/packages/modules/product/integration-tests/__tests__/product-module-service/product-options.spec.ts @@ -204,7 +204,7 @@ moduleIntegrationTestRunner({ it("should return requested attributes when requested through config", async () => { const option = await service.retrieveProductOption(optionOne.id, { - select: ["id", "product.title"], + select: ["id", "product.handle", "product.title"], relations: ["product"], }) diff --git a/packages/modules/product/package.json b/packages/modules/product/package.json index 422941338acd6..b735b47ff7647 100644 --- a/packages/modules/product/package.json +++ b/packages/modules/product/package.json @@ -29,7 +29,7 @@ "resolve:aliases": "tsc --showConfig -p tsconfig.json > tsconfig.resolved.json && tsc-alias -p tsconfig.resolved.json && rimraf tsconfig.resolved.json", "build": "rimraf dist && tsc --build && npm run resolve:aliases", "test": "jest --runInBand --bail --forceExit -- src/**/__tests__/**/*.ts", - "test:integration": "jest --forceExit -- integration-tests/__tests__/product.ts", + "test:integration": "jest --forceExit -- integration-tests/__tests__/**/*.spec.ts", "migration:generate": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm migration:generate", "migration:initial": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm migration:create --initial", "migration:create": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm migration:create", diff --git a/packages/modules/product/src/models/product-collection.ts b/packages/modules/product/src/models/product-collection.ts index 53e4e3ebb82a4..2d24476de0159 100644 --- a/packages/modules/product/src/models/product-collection.ts +++ b/packages/modules/product/src/models/product-collection.ts @@ -1,4 +1,4 @@ -import { model } from "@medusajs/framework/utils" +import { kebabCase, model } from "@medusajs/framework/utils" import Product from "./product" const collectionHandleIndexName = "IDX_collection_handle_unique" @@ -20,6 +20,13 @@ const ProductCollection = model mappedBy: "collection", }), }) + .hooks({ + creating(productCollection) { + productCollection.handle ??= productCollection.title + ? kebabCase(productCollection.title) + : null + }, + }) .indexes([ { name: collectionHandleIndexName, diff --git a/packages/modules/product/src/models/product-option.ts b/packages/modules/product/src/models/product-option.ts index 1a7644936935f..bcbdfca5d6a5a 100644 --- a/packages/modules/product/src/models/product-option.ts +++ b/packages/modules/product/src/models/product-option.ts @@ -26,6 +26,11 @@ const ProductOption = model .cascades({ delete: ["values"], }) + .hooks({ + creating(productOption) { + productOption.product_id ??= productOption.product?.id ?? null + }, + }) .indexes([ { name: optionProductIdTitleIndexName, diff --git a/packages/modules/product/src/models/product-tag.ts b/packages/modules/product/src/models/product-tag.ts index e5e3ff5359872..e4ec355f56761 100644 --- a/packages/modules/product/src/models/product-tag.ts +++ b/packages/modules/product/src/models/product-tag.ts @@ -17,7 +17,9 @@ const ProductTag = model id: model.id({ prefix: "ptag" }).primaryKey(), value: model.text().searchable(), metadata: model.json().nullable(), - products: model.manyToMany(() => Product), + products: model.manyToMany(() => Product, { + mappedBy: "tags", + }), } ) .indexes([ From 3ab6945f6f32c4536c2292520f7c6ad5b0653b8a Mon Sep 17 00:00:00 2001 From: Harminder Virk Date: Fri, 15 Nov 2024 18:23:48 +0530 Subject: [PATCH 037/175] test: make it all green --- .../src/dml/helpers/entity-builder/define-relationship.ts | 2 +- packages/modules/product/package.json | 2 +- packages/modules/product/src/models/product-category.ts | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts b/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts index a54aa14674b51..e17c00762d49d 100644 --- a/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts +++ b/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts @@ -227,7 +227,7 @@ export function defineBelongsToRelationship( return } - this[relationship.name] ??= this[foreignKeyName] + // this[relationship.name] ??= this[foreignKeyName] this[foreignKeyName] ??= this[relationship.name]?.id ?? null } diff --git a/packages/modules/product/package.json b/packages/modules/product/package.json index b735b47ff7647..1a89121b7c4aa 100644 --- a/packages/modules/product/package.json +++ b/packages/modules/product/package.json @@ -29,7 +29,7 @@ "resolve:aliases": "tsc --showConfig -p tsconfig.json > tsconfig.resolved.json && tsc-alias -p tsconfig.resolved.json && rimraf tsconfig.resolved.json", "build": "rimraf dist && tsc --build && npm run resolve:aliases", "test": "jest --runInBand --bail --forceExit -- src/**/__tests__/**/*.ts", - "test:integration": "jest --forceExit -- integration-tests/__tests__/**/*.spec.ts", + "test:integration": "jest --forceExit -- integration-tests/__tests__/**/*.ts", "migration:generate": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm migration:generate", "migration:initial": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm migration:create --initial", "migration:create": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm migration:create", diff --git a/packages/modules/product/src/models/product-category.ts b/packages/modules/product/src/models/product-category.ts index 993dd4545afbb..c524fbf98c074 100644 --- a/packages/modules/product/src/models/product-category.ts +++ b/packages/modules/product/src/models/product-category.ts @@ -38,7 +38,9 @@ const ProductCategory = model category_children: model.hasMany(() => ProductCategory, { mappedBy: "parent_category", }), - products: model.manyToMany(() => Product), + products: model.manyToMany(() => Product, { + mappedBy: "categories", + }), }) .hooks({ creating: (productCategory) => { From f9e75c8ec3e6a8323ed30e1e95d9c537fbf6ba22 Mon Sep 17 00:00:00 2001 From: Harminder Virk Date: Tue, 19 Nov 2024 15:20:11 +0530 Subject: [PATCH 038/175] test: fix breaking tests --- .../src/dml/__tests__/entity-builder.spec.ts | 64 ++++++++++++------- .../entity-builder/define-relationship.ts | 23 ++++++- 2 files changed, 63 insertions(+), 24 deletions(-) diff --git a/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts b/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts index 5a9a982cea174..01aa4986f6320 100644 --- a/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts +++ b/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts @@ -2843,7 +2843,7 @@ describe("Entity builder", () => { nullable: false, onDelete: undefined, reference: "m:1", - isForeignKey: true, + // isForeignKey: true, }, ...defaultColumnMetadata, }) @@ -2869,11 +2869,11 @@ describe("Entity builder", () => { 'CREATE UNIQUE INDEX IF NOT EXISTS "IDX_unique-name" ON "user" (organization, account, group_id) WHERE deleted_at IS NULL', name: "IDX_unique-name", }, - { - expression: - 'CREATE INDEX IF NOT EXISTS "IDX_user_group_id" ON "user" (group_id) WHERE deleted_at IS NULL', - name: "IDX_user_group_id", - }, + // { + // expression: + // 'CREATE INDEX IF NOT EXISTS "IDX_user_group_id" ON "user" (group_id) WHERE deleted_at IS NULL', + // name: "IDX_user_group_id", + // }, ]) }) @@ -2950,11 +2950,11 @@ describe("Entity builder", () => { 'CREATE INDEX IF NOT EXISTS "IDX_user_account_group_id" ON "user" (account, group_id) WHERE is_owner IS TRUE AND deleted_at IS NULL', name: "IDX_user_account_group_id", }, - { - expression: - 'CREATE INDEX IF NOT EXISTS "IDX_user_group_id" ON "user" (group_id) WHERE deleted_at IS NULL', - name: "IDX_user_group_id", - }, + // { + // expression: + // 'CREATE INDEX IF NOT EXISTS "IDX_user_group_id" ON "user" (group_id) WHERE deleted_at IS NULL', + // name: "IDX_user_group_id", + // }, ]) }) @@ -3016,11 +3016,11 @@ describe("Entity builder", () => { const metaData = MetadataStorage.getMetadataFromDecorator(User) expect(metaData.indexes).toEqual([ - { - expression: - 'CREATE INDEX IF NOT EXISTS "IDX_user_group_id" ON "user" (group_id) WHERE deleted_at IS NULL', - name: "IDX_user_group_id", - }, + // { + // expression: + // 'CREATE INDEX IF NOT EXISTS "IDX_user_group_id" ON "user" (group_id) WHERE deleted_at IS NULL', + // name: "IDX_user_group_id", + // }, ]) const Setting = toMikroORMEntity(setting) @@ -3443,7 +3443,7 @@ describe("Entity builder", () => { nullable: false, onDelete: "cascade", reference: "m:1", - isForeignKey: true, + // isForeignKey: true, }, created_at: { reference: "scalar", @@ -4033,7 +4033,7 @@ describe("Entity builder", () => { mapToPk: true, fieldName: "user_id", nullable: false, - isForeignKey: true, + // isForeignKey: true, }, created_at: { reference: "scalar", @@ -4222,7 +4222,7 @@ describe("Entity builder", () => { mapToPk: true, fieldName: "user_id", nullable: true, - isForeignKey: true, + // isForeignKey: true, }, created_at: { reference: "scalar", @@ -4784,7 +4784,7 @@ describe("Entity builder", () => { mapToPk: true, nullable: false, onDelete: undefined, - isForeignKey: true, + // isForeignKey: true, }, children: { cascade: undefined, @@ -5022,6 +5022,7 @@ describe("Entity builder", () => { reference: "m:n", name: "teams", entity: "Team", + owner: true, pivotTable: "team_users", mappedBy: "users", }, @@ -5090,6 +5091,7 @@ describe("Entity builder", () => { reference: "m:n", name: "users", entity: "User", + owner: false, pivotTable: "team_users", }, created_at: { @@ -5200,6 +5202,7 @@ describe("Entity builder", () => { reference: "m:n", name: "teams", entity: "Team", + owner: true, pivotTable: "team_users", mappedBy: "users", }, @@ -5268,6 +5271,7 @@ describe("Entity builder", () => { reference: "m:n", name: "users", entity: "User", + owner: false, pivotTable: "team_users", }, created_at: { @@ -5412,6 +5416,7 @@ describe("Entity builder", () => { reference: "m:n", name: "teams", entity: "Team", + owner: true, pivotTable: "team_users", mappedBy: "users", }, @@ -5480,6 +5485,7 @@ describe("Entity builder", () => { reference: "m:n", name: "users", entity: "User", + owner: false, pivotTable: "team_users", /** * The other side should be inversed in order for Mikro ORM @@ -5595,6 +5601,7 @@ describe("Entity builder", () => { reference: "m:n", name: "teams", entity: "Team", + owner: false, pivotTable: "team_users", /** * The other side should be inversed in order for Mikro ORM @@ -5667,6 +5674,7 @@ describe("Entity builder", () => { reference: "m:n", name: "users", entity: "User", + owner: true, pivotTable: "team_users", mappedBy: "teams", }, @@ -5796,6 +5804,7 @@ describe("Entity builder", () => { reference: "m:n", name: "teams", entity: "Team", + owner: false, pivotTable: "team_users", /** * The other side should be inversed in order for Mikro ORM @@ -5807,6 +5816,7 @@ describe("Entity builder", () => { reference: "m:n", name: "activeTeams", entity: "Team", + owner: false, pivotTable: "team_users", inversedBy: "activeTeamsUsers", }, @@ -5875,6 +5885,7 @@ describe("Entity builder", () => { reference: "m:n", name: "users", entity: "User", + owner: true, pivotTable: "team_users", mappedBy: "teams", }, @@ -5882,6 +5893,7 @@ describe("Entity builder", () => { reference: "m:n", name: "activeTeamsUsers", entity: "User", + owner: true, pivotTable: "team_users", mappedBy: "activeTeams", }, @@ -5996,6 +6008,7 @@ describe("Entity builder", () => { reference: "m:n", name: "teams", entity: "Team", + owner: true, pivotTable: "platform.team_users", mappedBy: "users", }, @@ -6065,6 +6078,7 @@ describe("Entity builder", () => { reference: "m:n", name: "users", entity: "User", + owner: false, pivotTable: "platform.team_users", }, created_at: { @@ -6151,6 +6165,7 @@ describe("Entity builder", () => { reference: "m:n", name: "teams", entity: "TeamSquad", + owner: true, pivotTable: "random_user_team_squads", mappedBy: "users", }, @@ -6219,6 +6234,7 @@ describe("Entity builder", () => { reference: "m:n", name: "users", entity: "RandomUser", + owner: false, pivotTable: "random_user_team_squads", }, created_at: { @@ -6334,6 +6350,7 @@ describe("Entity builder", () => { reference: "m:n", name: "teams", entity: "Team", + owner: true, pivotTable: "users_teams", mappedBy: "users", }, @@ -6401,6 +6418,7 @@ describe("Entity builder", () => { users: { reference: "m:n", name: "users", + owner: false, entity: "User", pivotTable: "users_teams", }, @@ -6518,7 +6536,7 @@ describe("Entity builder", () => { mapToPk: true, fieldName: "user_id", nullable: false, - isForeignKey: true, + // isForeignKey: true, }, user: { reference: "scalar", @@ -6537,7 +6555,7 @@ describe("Entity builder", () => { mapToPk: true, fieldName: "team_id", nullable: false, - isForeignKey: true, + // isForeignKey: true, }, team: { reference: "scalar", @@ -6613,6 +6631,7 @@ describe("Entity builder", () => { reference: "m:n", name: "teams", entity: "Team", + owner: true, pivotEntity: "TeamUsers", mappedBy: "users", }, @@ -6681,6 +6700,7 @@ describe("Entity builder", () => { reference: "m:n", name: "users", entity: "User", + owner: false, pivotEntity: "TeamUsers", }, created_at: { diff --git a/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts b/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts index e17c00762d49d..81c1c76852fa1 100644 --- a/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts +++ b/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts @@ -420,6 +420,9 @@ export function defineManyToManyRelationship( if (!pivotEntityName) { const { tableName } = parseEntityName(entity) + let tableNameWithoutSchema: string + let relatedTableNameWithoutSchema: string + /** * Pivot table name is created as follows (when not explicitly provided) * @@ -428,10 +431,25 @@ export function defineManyToManyRelationship( * - Converting them from camelCase to snake_case. * - And finally pluralizing the second entity name. */ + + let [schema, ...tableTokens] = tableName.split(".") + if (!tableTokens.length) { + tableNameWithoutSchema = schema + } else { + tableNameWithoutSchema = tableTokens.join(".") + } + + const [relatedSchema, ...relatedTableTokens] = relatedTableName.split(".") + if (!relatedTableTokens.length) { + relatedTableNameWithoutSchema = relatedSchema + } else { + relatedTableNameWithoutSchema = relatedTableTokens.join(".") + } + pivotTableName = relationship.options.pivotTable ?? otherSideRelationship.parse("").options.pivotTable ?? - [tableName, relatedTableName] + [tableNameWithoutSchema, relatedTableNameWithoutSchema] .sort() .map((token, index) => { if (index === 1) { @@ -449,7 +467,8 @@ export function defineManyToManyRelationship( } ManyToMany({ - owner: !!relationship.options.pivotTable, // TODO: need clarification and discussion in order to infer it differently instead + owner: !!mappedBy, + // !!relationship.options.pivotTable, // TODO: need clarification and discussion in order to infer it differently instead entity: relatedModelName, ...(pivotTableName ? { From 8975cfb3c6c44ab76e6d5f92d22c03ebae17576d Mon Sep 17 00:00:00 2001 From: Harminder Virk Date: Tue, 19 Nov 2024 17:09:06 +0530 Subject: [PATCH 039/175] fix: build issues --- .../core/utils/src/dal/mikro-orm/mikro-orm-repository.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/core/utils/src/dal/mikro-orm/mikro-orm-repository.ts b/packages/core/utils/src/dal/mikro-orm/mikro-orm-repository.ts index 80e251e5e0b77..1b21c6a9eb2b5 100644 --- a/packages/core/utils/src/dal/mikro-orm/mikro-orm-repository.ts +++ b/packages/core/utils/src/dal/mikro-orm/mikro-orm-repository.ts @@ -3,6 +3,7 @@ import { Context, DAL, FilterQuery, + FindOptions, InferEntityType, InferRepositoryReturnType, FilterQuery as InternalFilterQuery, @@ -162,10 +163,7 @@ export class MikroOrmBaseRepository throw new Error("Method not implemented.") } - delete( - idsOrPKs: FilterQuery & BaseFilterable>, - context?: Context - ): Promise { + delete(idsOrPKs: FindOptions["where"], context?: Context): Promise { throw new Error("Method not implemented.") } @@ -445,7 +443,7 @@ export function mikroOrmBaseRepositoryFactory( } async delete( - filters: FilterQuery & BaseFilterable>, + filters: FindOptions["where"], context?: Context ): Promise { const manager = this.getActiveManager(context) From 09ad1774f93e1773e36e9fce1ad3a366bea64c53 Mon Sep 17 00:00:00 2001 From: Harminder Virk Date: Tue, 19 Nov 2024 17:14:45 +0530 Subject: [PATCH 040/175] fix: build issues --- packages/core/utils/src/dal/mikro-orm/mikro-orm-repository.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/core/utils/src/dal/mikro-orm/mikro-orm-repository.ts b/packages/core/utils/src/dal/mikro-orm/mikro-orm-repository.ts index 1b21c6a9eb2b5..836f86ab19540 100644 --- a/packages/core/utils/src/dal/mikro-orm/mikro-orm-repository.ts +++ b/packages/core/utils/src/dal/mikro-orm/mikro-orm-repository.ts @@ -1,5 +1,4 @@ import { - BaseFilterable, Context, DAL, FilterQuery, From 7b981abd8adf008f843709fcfa2b5ecd97feace7 Mon Sep 17 00:00:00 2001 From: Harminder Virk Date: Tue, 19 Nov 2024 20:48:07 +0530 Subject: [PATCH 041/175] fix: more breaking tests --- packages/core/utils/package.json | 2 +- .../dml/helpers/entity-builder/define-relationship.ts | 10 +++++----- .../integration-tests/__tests__/many-to-many.spec.ts | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/core/utils/package.json b/packages/core/utils/package.json index 0503b1de24b42..e7db15501f95b 100644 --- a/packages/core/utils/package.json +++ b/packages/core/utils/package.json @@ -69,7 +69,7 @@ "scripts": { "build": "rimraf dist && tsc --build", "watch": "tsc --build --watch", - "test": "jest --silent=false --bail --maxWorkers=50% --forceExit --testPathIgnorePatterns='/integration-tests/' -- src/**/__tests__/**/*.ts", + "test": "jest --silent --bail --maxWorkers=50% --forceExit --testPathIgnorePatterns='/integration-tests/' -- src/**/__tests__/**/*.ts", "test:integration": "jest --silent --bail --runInBand --forceExit -- src/**/integration-tests/__tests__/**/*.ts" } } diff --git a/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts b/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts index 81c1c76852fa1..dc094bb9d8056 100644 --- a/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts +++ b/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts @@ -15,13 +15,13 @@ import { Property, rel, } from "@mikro-orm/core" -import { camelToSnakeCase, pluralize } from "../../../common" -import { ForeignKey } from "../../../dal/mikro-orm/decorators/foreign-key" import { DmlEntity } from "../../entity" -import { HasMany } from "../../relations/has-many" import { HasOne } from "../../relations/has-one" -import { ManyToMany as DmlManyToMany } from "../../relations/many-to-many" +import { HasMany } from "../../relations/has-many" import { parseEntityName } from "./parse-entity-name" +import { camelToSnakeCase, pluralize } from "../../../common" +import { ForeignKey } from "../../../dal/mikro-orm/decorators/foreign-key" +import { ManyToMany as DmlManyToMany } from "../../relations/many-to-many" type Context = { MANY_TO_MANY_TRACKED_RELATIONS: Record @@ -479,7 +479,7 @@ export function defineManyToManyRelationship( : {}), ...(pivotEntityName ? { pivotEntity: pivotEntityName } : {}), ...(mappedBy ? { mappedBy: mappedBy as any } : {}), - ...(inversedBy ? { inversedBy: inversedBy as any } : {}), + ...(inversedBy ? { mappedBy: inversedBy as any } : {}), ...(joinColumn ? { joinColumn } : {}), ...(inverseJoinColumn ? { inverseJoinColumn } : {}), })(MikroORMEntity.prototype, relationship.name) diff --git a/packages/core/utils/src/dml/integration-tests/__tests__/many-to-many.spec.ts b/packages/core/utils/src/dml/integration-tests/__tests__/many-to-many.spec.ts index 15c0d33a2bb0a..2b405dcd7612c 100644 --- a/packages/core/utils/src/dml/integration-tests/__tests__/many-to-many.spec.ts +++ b/packages/core/utils/src/dml/integration-tests/__tests__/many-to-many.spec.ts @@ -1,3 +1,4 @@ +import { join } from "path" import { MetadataStorage, MikroORM } from "@mikro-orm/core" import { model } from "../../entity-builder" import { @@ -9,7 +10,6 @@ import { CustomTsMigrationGenerator, mikroOrmSerializer } from "../../../dal" import { EntityConstructor } from "@medusajs/types" import { pgGodCredentials } from "../utils" import { FileSystem } from "../../../common" -import { join } from "path" jest.setTimeout(300000) @@ -227,7 +227,7 @@ describe("manyToMany - manyToMany", () => { ) }) - it.only(`should fail to load the dml's if the relation is defined only on one side`, () => { + it(`should fail to load the dml's if the relation is defined only on one side`, () => { mikroORMEntityBuilder.clear() const team = model.define("team", { From 348b53d00dce6a2f551c48d58910a005bf46c102 Mon Sep 17 00:00:00 2001 From: Harminder Virk Date: Tue, 19 Nov 2024 21:26:37 +0530 Subject: [PATCH 042/175] refactor: fix issues after merge --- .../src/repositories/product-category.ts | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/packages/modules/product/src/repositories/product-category.ts b/packages/modules/product/src/repositories/product-category.ts index dbdd74ce1407f..d868ee98aab84 100644 --- a/packages/modules/product/src/repositories/product-category.ts +++ b/packages/modules/product/src/repositories/product-category.ts @@ -130,7 +130,9 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito ancestors?: boolean }, productCategories: InferEntityType[], - findOptions: DAL.FindOptions = { where: {} }, + findOptions: DAL.FindOptions & { + serialize?: boolean + } = { where: {} }, context: Context = {} ): Promise[]> { const { serialize = true } = findOptions @@ -178,7 +180,7 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito ...findOptions.options, limit: undefined, offset: 0, - } as FindOptions + } as MikroOptions delete where.id delete where.mpath @@ -434,11 +436,11 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito const categoryData: Partial> = { ...entry, } - const productCategory = await manager.findOne< + let productCategory = await manager.findOne< InferEntityType >(ProductCategory.name, { id: categoryData.id, - })) as ProductCategory + }) if (!productCategory) { throw new MedusaError( @@ -487,10 +489,7 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito const newParentCategory = await manager.findOne< InferEntityType - >( - ProductCategory, - categoryData.parent_category_id - ) + >(ProductCategory, categoryData.parent_category_id) if (!newParentCategory) { throw new MedusaError( @@ -509,7 +508,7 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito ) function updateMpathRecursively( - category: ProductCategory, + category: InferEntityType, newBaseMpath: string ) { const newMpath = `${newBaseMpath}.${category.id}` From f589f7cd2cfa5c9cbf5f119617e5de44eef35a40 Mon Sep 17 00:00:00 2001 From: Harminder Virk Date: Tue, 19 Nov 2024 21:33:28 +0530 Subject: [PATCH 043/175] refactor: fix issues after merge --- packages/core/types/src/dml/index.ts | 3 ++- .../product/src/repositories/product-category.ts | 15 +++++---------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/packages/core/types/src/dml/index.ts b/packages/core/types/src/dml/index.ts index 0c3c15fdf4d94..ab802efbd90fe 100644 --- a/packages/core/types/src/dml/index.ts +++ b/packages/core/types/src/dml/index.ts @@ -202,7 +202,8 @@ export type InferSchemaFields = Prettify< ? InferManyToManyFields : never : Schema[K]["$dataType"] - } & InferForeignKeys> + } & InferForeignKeys +> /** * Helper to infer the schema type of a DmlEntity diff --git a/packages/modules/product/src/repositories/product-category.ts b/packages/modules/product/src/repositories/product-category.ts index d868ee98aab84..286ddd9b9bc86 100644 --- a/packages/modules/product/src/repositories/product-category.ts +++ b/packages/modules/product/src/repositories/product-category.ts @@ -6,13 +6,7 @@ import { ProductTypes, } from "@medusajs/framework/types" import { DALUtils, isDefined, MedusaError } from "@medusajs/framework/utils" -import { - EntityDTO, - LoadStrategy, - FilterQuery as MikroFilterQuery, - FindOptions as MikroOptions, - RequiredEntityData, -} from "@mikro-orm/core" +import { LoadStrategy, FindOptions as MikroOptions } from "@mikro-orm/core" import { SqlEntityManager } from "@mikro-orm/postgresql" import { ProductCategory } from "@models" import { UpdateCategoryInput } from "@types" @@ -487,9 +481,10 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito ) )[0] - const newParentCategory = await manager.findOne< - InferEntityType - >(ProductCategory, categoryData.parent_category_id) + const newParentCategory = await manager.findOne( + ProductCategory, + categoryData.parent_category_id + ) if (!newParentCategory) { throw new MedusaError( From 6452a649e6d7eae39f5a044312235e56e93c2332 Mon Sep 17 00:00:00 2001 From: Harminder Virk Date: Wed, 20 Nov 2024 11:37:50 +0530 Subject: [PATCH 044/175] refactor: surpress types error --- .../utils/src/dal/mikro-orm/mikro-orm-repository.ts | 2 +- .../product/src/repositories/product-category.ts | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/core/utils/src/dal/mikro-orm/mikro-orm-repository.ts b/packages/core/utils/src/dal/mikro-orm/mikro-orm-repository.ts index 836f86ab19540..c4281adfe9822 100644 --- a/packages/core/utils/src/dal/mikro-orm/mikro-orm-repository.ts +++ b/packages/core/utils/src/dal/mikro-orm/mikro-orm-repository.ts @@ -501,7 +501,7 @@ export function mikroOrmBaseRepositoryFactory( return (await manager.findAndCount( this.entity, findOptions_.where, - findOptions_.options as MikroOptions + findOptions_.options as any // MikroOptions )) as [InferRepositoryReturnType[], number] } diff --git a/packages/modules/product/src/repositories/product-category.ts b/packages/modules/product/src/repositories/product-category.ts index 286ddd9b9bc86..a93c110225e66 100644 --- a/packages/modules/product/src/repositories/product-category.ts +++ b/packages/modules/product/src/repositories/product-category.ts @@ -182,9 +182,9 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito const categoriesInTree = serialize ? await this.serialize[]>( - await manager.find(ProductCategory, where, options) + await manager.find(ProductCategory as any, where, options) ) - : await manager.find(ProductCategory, where, options) + : await manager.find(ProductCategory as any, where, options) const categoriesById = new Map(categoriesInTree.map((cat) => [cat.id, cat])) @@ -482,7 +482,7 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito )[0] const newParentCategory = await manager.findOne( - ProductCategory, + ProductCategory as any, categoryData.parent_category_id ) @@ -509,7 +509,7 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito const newMpath = `${newBaseMpath}.${category.id}` category.mpath = newMpath for (let child of category.category_children) { - child = manager.getReference(ProductCategory, child.id) + child = manager.getReference(ProductCategory as any, child.id) manager.assign( child, categoryDataChildrenMap.get(child.id) ?? {} @@ -518,7 +518,10 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito } } - updateMpathRecursively(productCategory!, newParentCategory.mpath!) + updateMpathRecursively( + productCategory!, + (newParentCategory as any).mpath! + ) // categoryData.mpath = `${newParentCategory.mpath}.${productCategory.id}` } From f5ebc5dbae4bb22080ea9ef011cf06151da807d4 Mon Sep 17 00:00:00 2001 From: Harminder Virk Date: Wed, 20 Nov 2024 11:52:56 +0530 Subject: [PATCH 045/175] test: fix DML failing tests --- .../src/dml/__tests__/entity-builder.spec.ts | 20 ++++--------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts b/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts index 01aa4986f6320..11ae31349b998 100644 --- a/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts +++ b/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts @@ -5487,11 +5487,7 @@ describe("Entity builder", () => { entity: "User", owner: false, pivotTable: "team_users", - /** - * The other side should be inversed in order for Mikro ORM - * to work. Both sides cannot have mappedBy. - */ - inversedBy: "teams", + mappedBy: "teams", }, created_at: { reference: "scalar", @@ -5603,11 +5599,7 @@ describe("Entity builder", () => { entity: "Team", owner: false, pivotTable: "team_users", - /** - * The other side should be inversed in order for Mikro ORM - * to work. Both sides cannot have mappedBy. - */ - inversedBy: "users", + mappedBy: "users", }, created_at: { reference: "scalar", @@ -5806,11 +5798,7 @@ describe("Entity builder", () => { entity: "Team", owner: false, pivotTable: "team_users", - /** - * The other side should be inversed in order for Mikro ORM - * to work. Both sides cannot have mappedBy. - */ - inversedBy: "users", + mappedBy: "users", }, activeTeams: { reference: "m:n", @@ -5818,7 +5806,7 @@ describe("Entity builder", () => { entity: "Team", owner: false, pivotTable: "team_users", - inversedBy: "activeTeamsUsers", + mappedBy: "activeTeamsUsers", }, created_at: { reference: "scalar", From 3aac6142560e2a2a366a4e94d874dc98959f107d Mon Sep 17 00:00:00 2001 From: adrien2p Date: Wed, 20 Nov 2024 13:46:25 +0100 Subject: [PATCH 046/175] improve many to many inference + tests --- .../entity-builder/define-relationship.ts | 99 ++++++++++--------- .../__tests__/many-to-many.spec.ts | 77 ++++++++++++++- .../integration-tests/__tests__/product.ts | 25 ++--- 3 files changed, 141 insertions(+), 60 deletions(-) diff --git a/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts b/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts index dc094bb9d8056..88982b3044dfb 100644 --- a/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts +++ b/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts @@ -27,7 +27,7 @@ type Context = { MANY_TO_MANY_TRACKED_RELATIONS: Record } -function retrieveOtherSideRelationshipMAnyToMany({ +function retrieveOtherSideRelationshipManyToMany({ relationship, relatedEntity, relatedModelName, @@ -40,11 +40,12 @@ function retrieveOtherSideRelationshipMAnyToMany({ > relatedModelName: string entity: DmlEntity -}) { +}): [string, RelationshipType] { if (relationship.mappedBy) { - return relatedEntity.parse().schema[ - relationship.mappedBy - ] as RelationshipType + return [ + relationship.mappedBy, + relatedEntity.parse().schema[relationship.mappedBy], + ] as [string, RelationshipType] } /** @@ -54,7 +55,7 @@ function retrieveOtherSideRelationshipMAnyToMany({ */ const potentialOtherSide = Object.entries(relatedEntity.schema) .filter(([, propConfig]) => DmlManyToMany.isManyToMany(propConfig)) - .find(([prop, propConfig]) => { + .filter(([prop, propConfig]) => { const parsedProp = propConfig.parse(prop) as RelationshipMetadata const relatedEntity = @@ -69,13 +70,21 @@ function retrieveOtherSideRelationshipMAnyToMany({ } return ( - parsedProp.mappedBy === relationship.name && + (parsedProp.mappedBy === relationship.name && + parseEntityName(relatedEntity).modelName === + parseEntityName(entity).modelName) || parseEntityName(relatedEntity).modelName === parseEntityName(entity).modelName ) - }) as unknown as [string, RelationshipType] + }) as unknown as [string, RelationshipType][] + + if (potentialOtherSide.length > 1) { + throw new Error( + `Invalid relationship reference for "${entity.name}.${relationship.name}". Make sure to set the mappedBy property on one side or the other or both.` + ) + } - return potentialOtherSide?.[1] + return potentialOtherSide[0] ?? [] } /** @@ -106,7 +115,7 @@ function validateManyToManyRelationshipWithoutMappedBy({ * relationship, we will try to find all the other side many to many that refers to the current entity. * If there is any, we will try to find if at least one of them has a mappedBy. */ - const potentialOtherSide = retrieveOtherSideRelationshipMAnyToMany({ + const [, potentialOtherSide] = retrieveOtherSideRelationshipManyToMany({ relationship, relatedEntity, relatedModelName, @@ -346,12 +355,13 @@ export function defineManyToManyRelationship( let inverseJoinColumn: undefined | string = relationship.options.inverseJoinColumn - const otherSideRelationship = retrieveOtherSideRelationshipMAnyToMany({ - relationship, - relatedEntity, - relatedModelName, - entity, - }) + const [otherSideRelationshipProperty, otherSideRelationship] = + retrieveOtherSideRelationshipManyToMany({ + relationship, + relatedEntity, + relatedModelName, + entity, + }) /** * Validating other side of relationship when mapped by is defined @@ -368,25 +378,6 @@ export function defineManyToManyRelationship( `Invalid relationship reference for "${mappedBy}" on "${relatedModelName}" entity. Make sure to define a manyToMany relationship` ) } - - /** - * Check if the other side has defined a mapped by and if that - * mapping is already tracked as the owner. - * - * - If yes, we will inverse our mapped by - * - Otherwise, we will track ourselves as the owner. - */ - if ( - otherSideRelationship.parse(mappedBy).mappedBy && - MANY_TO_MANY_TRACKED_RELATIONS[`${relatedModelName}.${mappedBy}`] - ) { - inversedBy = mappedBy - mappedBy = undefined - } else { - MANY_TO_MANY_TRACKED_RELATIONS[ - `${MikroORMEntity.name}.${relationship.name}` - ] = true - } } else { validateManyToManyRelationshipWithoutMappedBy({ MikroORMEntity, @@ -397,6 +388,10 @@ export function defineManyToManyRelationship( }) } + MANY_TO_MANY_TRACKED_RELATIONS[ + `${MikroORMEntity.name}.${relationship.name}` + ] = true + /** * Validating pivot entity when it is defined and computing * its name @@ -460,15 +455,32 @@ export function defineManyToManyRelationship( .join("_") } - if (!joinColumn || !inverseJoinColumn) { - const otherSideRelationshipOptions = otherSideRelationship.parse("").options - joinColumn ??= otherSideRelationshipOptions.joinColumn - inverseJoinColumn ??= otherSideRelationshipOptions.inverseJoinColumn - } + // if (!joinColumn || !inverseJoinColumn) { + // const otherSideRelationshipOptions = otherSideRelationship.parse("").options + // joinColumn ??= otherSideRelationshipOptions.joinColumn + // inverseJoinColumn ??= otherSideRelationshipOptions.inverseJoinColumn + // } + + const otherSideRelationOptions = otherSideRelationship.parse("").options + + const isOwner = + !!joinColumn || + !!inverseJoinColumn || + !!relationship.options.pivotTable || + // We cant infer it from the current entity so lets look at the otherside configuration as well to make a choice + (!otherSideRelationOptions.pivotTable && + !otherSideRelationOptions.joinColumn && + !otherSideRelationOptions.inverseJoinColumn && + !MANY_TO_MANY_TRACKED_RELATIONS[ + `${relatedModelName}.${otherSideRelationshipProperty}` + ]) + + const mappedByProp = isOwner ? "inversedBy" : "mappedBy" + const mappedByPropValue = + mappedBy ?? inversedBy ?? otherSideRelationshipProperty ManyToMany({ - owner: !!mappedBy, - // !!relationship.options.pivotTable, // TODO: need clarification and discussion in order to infer it differently instead + owner: isOwner, entity: relatedModelName, ...(pivotTableName ? { @@ -478,8 +490,7 @@ export function defineManyToManyRelationship( } : {}), ...(pivotEntityName ? { pivotEntity: pivotEntityName } : {}), - ...(mappedBy ? { mappedBy: mappedBy as any } : {}), - ...(inversedBy ? { mappedBy: inversedBy as any } : {}), + ...({ [mappedByProp]: mappedByPropValue } as any), ...(joinColumn ? { joinColumn } : {}), ...(inverseJoinColumn ? { inverseJoinColumn } : {}), })(MikroORMEntity.prototype, relationship.name) diff --git a/packages/core/utils/src/dml/integration-tests/__tests__/many-to-many.spec.ts b/packages/core/utils/src/dml/integration-tests/__tests__/many-to-many.spec.ts index 2b405dcd7612c..0e4753049fd7e 100644 --- a/packages/core/utils/src/dml/integration-tests/__tests__/many-to-many.spec.ts +++ b/packages/core/utils/src/dml/integration-tests/__tests__/many-to-many.spec.ts @@ -197,7 +197,7 @@ describe("manyToMany - manyToMany", () => { }) }) - it(`should fail to load the dml's if both side of the relation are missing the mappedBy options`, () => { + it(`should not fail to load the dml's if both side of the relation are missing the mappedBy options`, () => { mikroORMEntityBuilder.clear() const team = model.define("team", { @@ -214,16 +214,85 @@ describe("manyToMany - manyToMany", () => { squads: model.manyToMany(() => team), }) + ;[User, Team] = toMikroOrmEntities([user, team]) + + const teamMetaData = MetadataStorage.getMetadataFromDecorator(Team) + expect((teamMetaData.properties as any).users.mappedBy).toBe("squads") + expect((teamMetaData.properties as any).users.owner).toBe(false) + + const userMetaData = MetadataStorage.getMetadataFromDecorator(User) + expect((userMetaData.properties as any).squads.mappedBy).not.toBeDefined() + expect((userMetaData.properties as any).squads.inversedBy).toBe("users") + expect((userMetaData.properties as any).squads.owner).toBe(true) + }) + + it(`should load the dml's correclty when both side of the relation are specifying the mappedBy options without pivot table`, () => { + mikroORMEntityBuilder.clear() + + const team = model.define("team", { + id: model.id().primaryKey(), + name: model.text(), + users: model.manyToMany(() => user, { + mappedBy: "squads", + }), + }) + + const user = model.define("user", { + id: model.id().primaryKey(), + username: model.text(), + squads: model.manyToMany(() => team, { + mappedBy: "users", + }), + }) + + let [User, Team] = toMikroOrmEntities([user, team]) + + const teamMetaData = MetadataStorage.getMetadataFromDecorator(Team) + expect((teamMetaData.properties as any).users.mappedBy).toBe("squads") + expect((teamMetaData.properties as any).users.owner).toBe(false) + expect((teamMetaData.properties as any).users.pivotTable).toBe("team_users") + + const userMetaData = MetadataStorage.getMetadataFromDecorator(User) + expect((userMetaData.properties as any).squads.mappedBy).not.toBeDefined() + expect((userMetaData.properties as any).squads.inversedBy).toBe("users") + expect((userMetaData.properties as any).squads.owner).toBe(true) + expect((userMetaData.properties as any).squads.pivotTable).toBe( + "team_users" + ) + }) + + it(`should fail to load the dml's if both side of the relation are missing the mappedBy options and multiple relations points to the same entity`, () => { + mikroORMEntityBuilder.clear() + + const team = model.define("team", { + id: model.id().primaryKey(), + name: model.text(), + users: model.manyToMany(() => user, { + pivot_table: "team_users", + }), + users2: model.manyToMany(() => user, { + pivot_table: "team_users2", + }), + }) + + const user = model.define("user", { + id: model.id().primaryKey(), + username: model.text(), + squads: model.manyToMany(() => team), + squads2: model.manyToMany(() => team), + }) + let error!: Error + try { ;[User, Team] = toMikroOrmEntities([user, team]) } catch (e) { error = e } - expect(error).toBeTruthy() - expect(error.message).toEqual( - 'Invalid relationship reference for "User.squads". "mappedBy" should be defined on one side or the other.' + expect(error).toBeDefined() + expect(error?.message).toEqual( + 'Invalid relationship reference for "user.squads". Make sure to set the mappedBy property on one side or the other or both.' ) }) diff --git a/packages/modules/product/integration-tests/__tests__/product.ts b/packages/modules/product/integration-tests/__tests__/product.ts index 859fda5a4398c..0528d6e32844f 100644 --- a/packages/modules/product/integration-tests/__tests__/product.ts +++ b/packages/modules/product/integration-tests/__tests__/product.ts @@ -62,18 +62,19 @@ moduleIntegrationTestRunner({ service: ProductModuleService, }).linkable - expect(Object.keys(linkable)).toHaveLength(7) - expect(Object.keys(linkable)).toEqual([ - "product", - "productVariant", - "productOption", - "productOptionValue", - "productType", - "productImage", - "productTag", - "productCollection", - "productCategory", - ]) + expect(Object.keys(linkable)).toHaveLength(8) + expect(Object.keys(linkable)).toEqual( + expect.arrayContaining([ + "product", + "productVariant", + "productOption", + "productOptionValue", + "productType", + "productTag", + "productCollection", + "productCategory", + ]) + ) Object.keys(linkable).forEach((key) => { delete linkable[key].toJSON From 7241d91418c03cdfed54c99e74c66f59b0b1589b Mon Sep 17 00:00:00 2001 From: adrien2p Date: Wed, 20 Nov 2024 15:08:53 +0100 Subject: [PATCH 047/175] Wip fix columns from product entity --- packages/modules/product/src/models/product.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/modules/product/src/models/product.ts b/packages/modules/product/src/models/product.ts index b69be9d2e3f1e..659165223018f 100644 --- a/packages/modules/product/src/models/product.ts +++ b/packages/modules/product/src/models/product.ts @@ -38,7 +38,7 @@ const Product = model .define("Product", { id: model.id({ prefix: "prod" }).primaryKey(), title: model.text().searchable(), - handle: model.text().nullable(), // TODO: provide a way to compute a value if not provided (default maybe) + handle: model.text(), subtitle: model.text().searchable().nullable(), description: model.text().searchable().nullable(), is_giftcard: model.boolean().default(false), @@ -93,7 +93,7 @@ const Product = model }) .hooks({ creating: (product) => { - product.handle ??= product.title ? toHandle(product.title) : null + product.handle ??= toHandle(product.title) }, }) .indexes([ From 2ced83b49451cbb9bff3711a1e83b5a2fedce2e9 Mon Sep 17 00:00:00 2001 From: adrien2p Date: Wed, 20 Nov 2024 16:03:38 +0100 Subject: [PATCH 048/175] remove product model before create hook and manage handle validation and transformation at the service level --- .../product/data/create-product.ts | 8 ++++++-- .../product-categories.spec.ts | 2 ++ .../product-module-service/products.spec.ts | 19 +++++++++---------- .../modules/product/src/models/product.ts | 7 +------ .../product/src/repositories/product.ts | 12 +----------- .../src/services/product-module-service.ts | 11 +++++++++++ 6 files changed, 30 insertions(+), 29 deletions(-) diff --git a/packages/modules/product/integration-tests/__fixtures__/product/data/create-product.ts b/packages/modules/product/integration-tests/__fixtures__/product/data/create-product.ts index e62291063fa28..99ce5839c5de0 100644 --- a/packages/modules/product/integration-tests/__fixtures__/product/data/create-product.ts +++ b/packages/modules/product/integration-tests/__fixtures__/product/data/create-product.ts @@ -1,10 +1,11 @@ import { ProductTypes } from "@medusajs/framework/types" -import { ProductStatus } from "@medusajs/framework/utils" +import { ProductStatus, toHandle } from "@medusajs/framework/utils" import { Image } from "@models" import faker from "faker" export const buildProductOnlyData = ({ title, + handle, description, subtitle, is_giftcard, @@ -14,6 +15,7 @@ export const buildProductOnlyData = ({ status, }: { title?: string + handle?: string description?: string subtitle?: string is_giftcard?: boolean @@ -22,8 +24,10 @@ export const buildProductOnlyData = ({ images?: { id?: string; url: string }[] status?: ProductStatus } = {}) => { + title ??= faker.commerce.productName() return { - title: title ?? faker.commerce.productName(), + title, + handle: handle ?? toHandle(title!), description: description ?? faker.commerce.productName(), subtitle: subtitle ?? faker.commerce.productName(), is_giftcard: is_giftcard ?? false, diff --git a/packages/modules/product/integration-tests/__tests__/product-module-service/product-categories.spec.ts b/packages/modules/product/integration-tests/__tests__/product-module-service/product-categories.spec.ts index 86e4dc81b106d..d3016d4734546 100644 --- a/packages/modules/product/integration-tests/__tests__/product-module-service/product-categories.spec.ts +++ b/packages/modules/product/integration-tests/__tests__/product-module-service/product-categories.spec.ts @@ -35,12 +35,14 @@ moduleIntegrationTestRunner({ productOne = testManager.create(toMikroORMEntity(Product), { id: "product-1", title: "product 1", + handle: "product-1", status: ProductStatus.PUBLISHED, }) productTwo = testManager.create(toMikroORMEntity(Product), { id: "product-2", title: "product 2", + handle: "product-2", status: ProductStatus.PUBLISHED, }) diff --git a/packages/modules/product/integration-tests/__tests__/product-module-service/products.spec.ts b/packages/modules/product/integration-tests/__tests__/product-module-service/products.spec.ts index fbfecddd4c799..3a22caa65b176 100644 --- a/packages/modules/product/integration-tests/__tests__/product-module-service/products.spec.ts +++ b/packages/modules/product/integration-tests/__tests__/product-module-service/products.spec.ts @@ -124,7 +124,6 @@ moduleIntegrationTestRunner({ productCategoryTwo = categories[1] productOne = service.createProducts({ - id: "product-1", title: "product 1", status: ProductStatus.PUBLISHED, options: [ @@ -135,7 +134,6 @@ moduleIntegrationTestRunner({ ], variants: [ { - id: "variant-1", title: "variant 1", options: { "opt-title": "val-1" }, }, @@ -143,12 +141,11 @@ moduleIntegrationTestRunner({ }) productTwo = service.createProducts({ - id: "product-2", title: "product 2", status: ProductStatus.PUBLISHED, - categories: [{ id: productCategoryOne.id }], collection_id: productCollectionOne.id, - tags: [{ id: tags[0].id }], + category_ids: [productCategoryOne.id], + tag_ids: [tags[0].id], options: [ { title: "size", @@ -161,7 +158,6 @@ moduleIntegrationTestRunner({ ], variants: [ { - id: "variant-2", title: "variant 2", options: { size: "large", @@ -169,7 +165,6 @@ moduleIntegrationTestRunner({ }, }, { - id: "variant-3", title: "variant 3", options: { size: "small", @@ -388,11 +383,11 @@ moduleIntegrationTestRunner({ const existingVariant1 = product.variants.find( (v) => v.title === "new variant 1" - ) + )! const existingVariant2 = product.variants.find( (v) => v.title === "new variant 2" - ) + )! await service.upsertProductVariants([ { @@ -792,10 +787,14 @@ moduleIntegrationTestRunner({ }) it("should do a partial update on the options of a variant successfully", async () => { + const variantToUpdate = productTwo.variants.find( + (variant) => variant.title === "variant 3" + )! + await service.updateProducts(productTwo.id, { variants: [ { - id: "variant-3", + id: variantToUpdate.id, options: { size: "small", color: "blue" }, }, ], diff --git a/packages/modules/product/src/models/product.ts b/packages/modules/product/src/models/product.ts index 659165223018f..9d7315f1e86c1 100644 --- a/packages/modules/product/src/models/product.ts +++ b/packages/modules/product/src/models/product.ts @@ -1,4 +1,4 @@ -import { model, ProductUtils, toHandle } from "@medusajs/framework/utils" +import { model, ProductUtils } from "@medusajs/framework/utils" import ProductCategory from "./product-category" import ProductCollection from "./product-collection" import ProductImage from "./product-image" @@ -91,11 +91,6 @@ const Product = model .cascades({ delete: ["variants", "options"], }) - .hooks({ - creating: (product) => { - product.handle ??= toHandle(product.title) - }, - }) .indexes([ { name: productHandleIndexName, diff --git a/packages/modules/product/src/repositories/product.ts b/packages/modules/product/src/repositories/product.ts index 707f3159cb6f3..3b44d82a745b4 100644 --- a/packages/modules/product/src/repositories/product.ts +++ b/packages/modules/product/src/repositories/product.ts @@ -1,7 +1,7 @@ import { Product } from "@models" -import { DALUtils, toHandle } from "@medusajs/framework/utils" import { Context, DAL } from "@medusajs/framework/types" +import { DALUtils } from "@medusajs/framework/utils" import { SqlEntityManager } from "@mikro-orm/postgresql" // eslint-disable-next-line max-len @@ -13,16 +13,6 @@ export class ProductRepository extends DALUtils.mikroOrmBaseRepositoryFactory( super(...arguments) } - // TODO: temporary fix until the DML support something like default on create for the handle as the example - async create(data: any[], context: Context = {}) { - return await super.create( - data.map((row) => { - return { handle: toHandle(row.title), ...row } - }), - context - ) - } - /** * In order to be able to have a strict not in categories, and prevent a product * to be return in the case it also belongs to other categories, we need to diff --git a/packages/modules/product/src/services/product-module-service.ts b/packages/modules/product/src/services/product-module-service.ts index a7fd712dbbd26..375025ae5591e 100644 --- a/packages/modules/product/src/services/product-module-service.ts +++ b/packages/modules/product/src/services/product-module-service.ts @@ -1628,6 +1628,13 @@ export default class ProductModuleService ) { this.validateProductPayload(productData) + if (!productData.title) { + throw new MedusaError( + MedusaError.Types.INVALID_DATA, + `Product title is required` + ) + } + const options = productData.options const missingOptionsVariants: string[] = [] @@ -1690,6 +1697,10 @@ export default class ProductModuleService productData.discountable = false } + if (!productData.handle && productData.title) { + productData.handle = toHandle(productData.title) + } + if (productData.options?.length) { const dbOptions = await this.productOptionService_.list( { product_id: productData.id }, From 09551c3abbc55c3321277b869d21445936b21825 Mon Sep 17 00:00:00 2001 From: Harminder Virk Date: Thu, 21 Nov 2024 13:39:26 +0530 Subject: [PATCH 049/175] test: fix breaking unit tests --- .../src/dml/__tests__/entity-builder.spec.ts | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts b/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts index 3182e485950ba..1433276563a2b 100644 --- a/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts +++ b/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts @@ -5127,7 +5127,7 @@ describe("Entity builder", () => { entity: "Team", owner: true, pivotTable: "team_users", - mappedBy: "users", + inversedBy: "users", }, created_at: { reference: "scalar", @@ -5193,6 +5193,7 @@ describe("Entity builder", () => { users: { reference: "m:n", name: "users", + mappedBy: "teams", entity: "User", owner: false, pivotTable: "team_users", @@ -5307,7 +5308,7 @@ describe("Entity builder", () => { entity: "Team", owner: true, pivotTable: "team_users", - mappedBy: "users", + inversedBy: "users", }, created_at: { reference: "scalar", @@ -5375,6 +5376,7 @@ describe("Entity builder", () => { name: "users", entity: "User", owner: false, + mappedBy: "teams", pivotTable: "team_users", }, created_at: { @@ -5521,7 +5523,7 @@ describe("Entity builder", () => { entity: "Team", owner: true, pivotTable: "team_users", - mappedBy: "users", + inversedBy: "users", }, created_at: { reference: "scalar", @@ -5771,7 +5773,7 @@ describe("Entity builder", () => { entity: "User", owner: true, pivotTable: "team_users", - mappedBy: "teams", + inversedBy: "teams", }, created_at: { reference: "scalar", @@ -5978,7 +5980,7 @@ describe("Entity builder", () => { entity: "User", owner: true, pivotTable: "team_users", - mappedBy: "teams", + inversedBy: "teams", }, activeTeamsUsers: { reference: "m:n", @@ -5986,7 +5988,7 @@ describe("Entity builder", () => { entity: "User", owner: true, pivotTable: "team_users", - mappedBy: "activeTeams", + inversedBy: "activeTeams", }, created_at: { reference: "scalar", @@ -6101,7 +6103,7 @@ describe("Entity builder", () => { entity: "Team", owner: true, pivotTable: "platform.team_users", - mappedBy: "users", + inversedBy: "users", }, created_at: { reference: "scalar", @@ -6170,6 +6172,7 @@ describe("Entity builder", () => { name: "users", entity: "User", owner: false, + mappedBy: "teams", pivotTable: "platform.team_users", }, created_at: { @@ -6258,7 +6261,7 @@ describe("Entity builder", () => { entity: "TeamSquad", owner: true, pivotTable: "random_user_team_squads", - mappedBy: "users", + inversedBy: "users", }, created_at: { reference: "scalar", @@ -6326,6 +6329,7 @@ describe("Entity builder", () => { name: "users", entity: "RandomUser", owner: false, + mappedBy: "teams", pivotTable: "random_user_team_squads", }, created_at: { @@ -6370,9 +6374,7 @@ describe("Entity builder", () => { const team = model.define("team", { id: model.number(), name: model.text(), - users: model.manyToMany(() => user, { - pivotTable: "users_teams", - }), + users: model.manyToMany(() => user), }) const user = model.define("user", { @@ -6443,7 +6445,7 @@ describe("Entity builder", () => { entity: "Team", owner: true, pivotTable: "users_teams", - mappedBy: "users", + inversedBy: "users", }, created_at: { reference: "scalar", @@ -6511,6 +6513,7 @@ describe("Entity builder", () => { name: "users", owner: false, entity: "User", + mappedBy: "teams", pivotTable: "users_teams", }, created_at: { @@ -6724,7 +6727,7 @@ describe("Entity builder", () => { entity: "Team", owner: true, pivotEntity: "TeamUsers", - mappedBy: "users", + inversedBy: "users", }, created_at: { reference: "scalar", @@ -6792,6 +6795,7 @@ describe("Entity builder", () => { name: "users", entity: "User", owner: false, + mappedBy: "teams", pivotEntity: "TeamUsers", }, created_at: { From ed8d0ec7c4b6e70af11a6f7f315f775c272e6e83 Mon Sep 17 00:00:00 2001 From: Harminder Virk Date: Thu, 21 Nov 2024 14:27:01 +0530 Subject: [PATCH 050/175] fix: product module service to not update handle on product update --- .../http/__tests__/product/admin/product.spec.ts | 2 +- .../modules/product/src/services/product-module-service.ts | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/integration-tests/http/__tests__/product/admin/product.spec.ts b/integration-tests/http/__tests__/product/admin/product.spec.ts index bc6d52e593819..4bb9ea93bb9a6 100644 --- a/integration-tests/http/__tests__/product/admin/product.spec.ts +++ b/integration-tests/http/__tests__/product/admin/product.spec.ts @@ -1463,7 +1463,7 @@ medusaIntegrationTestRunner({ ) }) - it("updates a product (update prices, tags, update status, delete collection, delete type, replaces images)", async () => { + it.only("updates a product (update prices, tags, update status, delete collection, delete type, replaces images)", async () => { const payload = { collection_id: null, title: "Test an update", diff --git a/packages/modules/product/src/services/product-module-service.ts b/packages/modules/product/src/services/product-module-service.ts index 375025ae5591e..4f49d995edec0 100644 --- a/packages/modules/product/src/services/product-module-service.ts +++ b/packages/modules/product/src/services/product-module-service.ts @@ -1697,10 +1697,6 @@ export default class ProductModuleService productData.discountable = false } - if (!productData.handle && productData.title) { - productData.handle = toHandle(productData.title) - } - if (productData.options?.length) { const dbOptions = await this.productOptionService_.list( { product_id: productData.id }, From 06b1b28b9208e008135d950bf28469228fdf140d Mon Sep 17 00:00:00 2001 From: adrien2p Date: Thu, 21 Nov 2024 11:11:47 +0100 Subject: [PATCH 051/175] fix define link and joiner config --- .../core/utils/src/modules-sdk/define-link.ts | 1 + .../src/modules-sdk/joiner-config-builder.ts | 31 +++++++++++++++---- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/packages/core/utils/src/modules-sdk/define-link.ts b/packages/core/utils/src/modules-sdk/define-link.ts index 7d215b3234d7d..6ecc1c432dc33 100644 --- a/packages/core/utils/src/modules-sdk/define-link.ts +++ b/packages/core/utils/src/modules-sdk/define-link.ts @@ -314,6 +314,7 @@ ${serviceBObj.module}: { const isModuleAPrimaryKeyValid = moduleAPrimaryKeys.includes(serviceAPrimaryKey) + if (!isModuleAPrimaryKeyValid) { throw new Error( `Primary key ${serviceAPrimaryKey} is not defined on service ${serviceAObj.module}` diff --git a/packages/core/utils/src/modules-sdk/joiner-config-builder.ts b/packages/core/utils/src/modules-sdk/joiner-config-builder.ts index 3684001c996f1..b071284f22ec5 100644 --- a/packages/core/utils/src/modules-sdk/joiner-config-builder.ts +++ b/packages/core/utils/src/modules-sdk/joiner-config-builder.ts @@ -165,13 +165,22 @@ export function defineJoinerConfig( } linkableKeys = mergedLinkableKeys - if (!primaryKeys && modelDefinitions.size) { + /** + * Merge custom primary keys from the joiner config with the infered primary keys + * from the models. + * + * TODO: Maybe worth looking into the real needs for primary keys. + * It can happen that we could just remove that but we need to investigate (looking at the + * lookups from the remote joiner to identify which entity a property refers to) + */ + primaryKeys ??= [] + if (modelDefinitions.size) { const linkConfig = buildLinkConfigFromModelObjects( serviceName, Object.fromEntries(modelDefinitions) ) - primaryKeys = deduplicate( + const inferedPrimaryKeysFromLinkable = deduplicate( Object.values(linkConfig).flatMap((entityLinkConfig) => { return (Object.values(entityLinkConfig as any) as any[]) .filter((linkableConfig) => isObject(linkableConfig)) @@ -181,6 +190,8 @@ export function defineJoinerConfig( }) }) ) + + primaryKeys.push(...inferedPrimaryKeysFromLinkable) } // TODO: In the context of DML add a validation on primary keys and linkable keys if the consumer provide them manually. follow up pr @@ -364,17 +375,22 @@ export function buildLinkConfigFromModelObjects< const schema = model.schema - // @ts-ignore + /** + * When using a linkable, if a specific linkable property is not specified, the toJSON + * function will be called and return the first linkable available for this model. + */ const modelLinkConfig = (linkConfig[lowerCaseFirst(model.name)] ??= { toJSON: function () { const linkables = Object.entries(this) .filter(([name]) => name !== "toJSON") .map(([, object]) => object) - const lastIndex = linkables.length - 1 - return linkables[lastIndex] + return linkables[0] }, }) + /** + * Build all linkable properties for the model + */ for (const [property, value] of Object.entries(schema)) { if (BaseRelationship.isRelationship(value)) { continue @@ -396,7 +412,10 @@ export function buildLinkConfigFromModelObjects< } } - // Merge existing custom linkable keys configuration + /** + * If the joiner config specify some custom linkable keys, we merge them with the + * existing linkable keys infered from the model above. + */ const linkableKeysPerModel = Object.entries(linkableKeys).reduce( (acc, [key, entityName]) => { acc[entityName] ??= [] From 933ea9a4c424930bb2611200b83b5b6ed5fbd25b Mon Sep 17 00:00:00 2001 From: Harminder Virk Date: Thu, 21 Nov 2024 16:24:00 +0530 Subject: [PATCH 052/175] test: fix joiner config test --- .../src/modules-sdk/__tests__/joiner-config-builder.spec.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/core/utils/src/modules-sdk/__tests__/joiner-config-builder.spec.ts b/packages/core/utils/src/modules-sdk/__tests__/joiner-config-builder.spec.ts index a0cfdd5450ec7..bc8a9d5de87ee 100644 --- a/packages/core/utils/src/modules-sdk/__tests__/joiner-config-builder.spec.ts +++ b/packages/core/utils/src/modules-sdk/__tests__/joiner-config-builder.spec.ts @@ -298,7 +298,8 @@ describe("joiner-config-builder", () => { expect(joinerConfig).toEqual({ serviceName: Modules.FULFILLMENT, - primaryKeys: ["id"], + // primaryKeys: ["id"], + primaryKeys: [], schema: "", linkableKeys: { fulfillment_set_id: FulfillmentSet.name, @@ -333,7 +334,8 @@ describe("joiner-config-builder", () => { expect(joinerConfig).toEqual({ serviceName: Modules.FULFILLMENT, - primaryKeys: ["id"], + // primaryKeys: ["id"], + primaryKeys: [], schema: expect.any(String), linkableKeys: { fulfillment_set_id: FulfillmentSet.name, From 79301f2ff57f119bd66483a643710f731016b867 Mon Sep 17 00:00:00 2001 From: Harminder Virk Date: Thu, 21 Nov 2024 17:07:35 +0530 Subject: [PATCH 053/175] test: fix joiner config test --- .../src/loaders/utils/__tests__/load-internal.spec.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/core/modules-sdk/src/loaders/utils/__tests__/load-internal.spec.ts b/packages/core/modules-sdk/src/loaders/utils/__tests__/load-internal.spec.ts index f28a7fd2f9f0c..dab13230afd70 100644 --- a/packages/core/modules-sdk/src/loaders/utils/__tests__/load-internal.spec.ts +++ b/packages/core/modules-sdk/src/loaders/utils/__tests__/load-internal.spec.ts @@ -239,7 +239,8 @@ describe("load internal", () => { expect(generatedJoinerConfig).toEqual({ serviceName: "module-without-joiner-config", - primaryKeys: ["id"], + // primaryKeys: ["id"], + primaryKeys: [], linkableKeys: { entity2_id: "Entity2", entity_model_id: "EntityModel", @@ -316,7 +317,8 @@ describe("load internal", () => { expect(generatedJoinerConfig).toEqual({ serviceName: "module-service", - primaryKeys: ["id"], + // primaryKeys: ["id"], + primaryKeys: [], linkableKeys: {}, schema: "", alias: [ From 52c214b5bc5564319930a96f4af499a8d8303c72 Mon Sep 17 00:00:00 2001 From: adrien2p Date: Thu, 21 Nov 2024 14:45:17 +0100 Subject: [PATCH 054/175] fix joiner config primary keys --- .../utils/__tests__/load-internal.spec.ts | 6 ++--- .../__tests__/joiner-config-builder.spec.ts | 6 ++--- .../src/modules-sdk/joiner-config-builder.ts | 27 +++++++++---------- 3 files changed, 16 insertions(+), 23 deletions(-) diff --git a/packages/core/modules-sdk/src/loaders/utils/__tests__/load-internal.spec.ts b/packages/core/modules-sdk/src/loaders/utils/__tests__/load-internal.spec.ts index dab13230afd70..f28a7fd2f9f0c 100644 --- a/packages/core/modules-sdk/src/loaders/utils/__tests__/load-internal.spec.ts +++ b/packages/core/modules-sdk/src/loaders/utils/__tests__/load-internal.spec.ts @@ -239,8 +239,7 @@ describe("load internal", () => { expect(generatedJoinerConfig).toEqual({ serviceName: "module-without-joiner-config", - // primaryKeys: ["id"], - primaryKeys: [], + primaryKeys: ["id"], linkableKeys: { entity2_id: "Entity2", entity_model_id: "EntityModel", @@ -317,8 +316,7 @@ describe("load internal", () => { expect(generatedJoinerConfig).toEqual({ serviceName: "module-service", - // primaryKeys: ["id"], - primaryKeys: [], + primaryKeys: ["id"], linkableKeys: {}, schema: "", alias: [ diff --git a/packages/core/utils/src/modules-sdk/__tests__/joiner-config-builder.spec.ts b/packages/core/utils/src/modules-sdk/__tests__/joiner-config-builder.spec.ts index bc8a9d5de87ee..a0cfdd5450ec7 100644 --- a/packages/core/utils/src/modules-sdk/__tests__/joiner-config-builder.spec.ts +++ b/packages/core/utils/src/modules-sdk/__tests__/joiner-config-builder.spec.ts @@ -298,8 +298,7 @@ describe("joiner-config-builder", () => { expect(joinerConfig).toEqual({ serviceName: Modules.FULFILLMENT, - // primaryKeys: ["id"], - primaryKeys: [], + primaryKeys: ["id"], schema: "", linkableKeys: { fulfillment_set_id: FulfillmentSet.name, @@ -334,8 +333,7 @@ describe("joiner-config-builder", () => { expect(joinerConfig).toEqual({ serviceName: Modules.FULFILLMENT, - // primaryKeys: ["id"], - primaryKeys: [], + primaryKeys: ["id"], schema: expect.any(String), linkableKeys: { fulfillment_set_id: FulfillmentSet.name, diff --git a/packages/core/utils/src/modules-sdk/joiner-config-builder.ts b/packages/core/utils/src/modules-sdk/joiner-config-builder.ts index b071284f22ec5..5f7246627be0c 100644 --- a/packages/core/utils/src/modules-sdk/joiner-config-builder.ts +++ b/packages/core/utils/src/modules-sdk/joiner-config-builder.ts @@ -9,7 +9,6 @@ import * as path from "path" import { dirname, join, normalize } from "path" import { camelToSnakeCase, - deduplicate, getCallerFilePath, isObject, lowerCaseFirst, @@ -173,32 +172,30 @@ export function defineJoinerConfig( * It can happen that we could just remove that but we need to investigate (looking at the * lookups from the remote joiner to identify which entity a property refers to) */ - primaryKeys ??= [] + primaryKeys ??= ["id"] + const finalPrimaryKeys = new Set(primaryKeys) if (modelDefinitions.size) { const linkConfig = buildLinkConfigFromModelObjects( serviceName, Object.fromEntries(modelDefinitions) ) - const inferedPrimaryKeysFromLinkable = deduplicate( - Object.values(linkConfig).flatMap((entityLinkConfig) => { - return (Object.values(entityLinkConfig as any) as any[]) - .filter((linkableConfig) => isObject(linkableConfig)) - .map((linkableConfig) => { - // @ts-ignore - return linkableConfig.primaryKey - }) - }) - ) - - primaryKeys.push(...inferedPrimaryKeysFromLinkable) + Object.values(linkConfig).flatMap((entityLinkConfig) => { + return Object.values( + entityLinkConfig as Record + ) + .filter((linkableConfig) => isObject(linkableConfig)) + .forEach((linkableConfig) => { + finalPrimaryKeys.add(linkableConfig.primaryKey) + }) + }) } // TODO: In the context of DML add a validation on primary keys and linkable keys if the consumer provide them manually. follow up pr return { serviceName, - primaryKeys: primaryKeys ?? ["id"], + primaryKeys, schema, linkableKeys: linkableKeys, alias: [ From 9c0d566860f5b13212fde120660a76ccedfabadd Mon Sep 17 00:00:00 2001 From: adrien2p Date: Thu, 21 Nov 2024 15:10:07 +0100 Subject: [PATCH 055/175] Fix joiner config builder --- packages/core/utils/src/modules-sdk/joiner-config-builder.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/core/utils/src/modules-sdk/joiner-config-builder.ts b/packages/core/utils/src/modules-sdk/joiner-config-builder.ts index 5f7246627be0c..d2ab83e236a34 100644 --- a/packages/core/utils/src/modules-sdk/joiner-config-builder.ts +++ b/packages/core/utils/src/modules-sdk/joiner-config-builder.ts @@ -191,6 +191,8 @@ export function defineJoinerConfig( }) } + primaryKeys.push(...Array.from(finalPrimaryKeys)) + // TODO: In the context of DML add a validation on primary keys and linkable keys if the consumer provide them manually. follow up pr return { From 4986cae6700a0cd025cc8c1e34d2ed901c72714d Mon Sep 17 00:00:00 2001 From: adrien2p Date: Thu, 21 Nov 2024 15:28:58 +0100 Subject: [PATCH 056/175] Fix joiner config builder --- .../src/modules-sdk/__tests__/joiner-config-builder.spec.ts | 2 +- packages/core/utils/src/modules-sdk/joiner-config-builder.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/core/utils/src/modules-sdk/__tests__/joiner-config-builder.spec.ts b/packages/core/utils/src/modules-sdk/__tests__/joiner-config-builder.spec.ts index a0cfdd5450ec7..e7e93dfc5d64a 100644 --- a/packages/core/utils/src/modules-sdk/__tests__/joiner-config-builder.spec.ts +++ b/packages/core/utils/src/modules-sdk/__tests__/joiner-config-builder.spec.ts @@ -282,7 +282,7 @@ describe("joiner-config-builder", () => { }) }) - it.only("should return a full joiner configuration with custom aliases overriding defaults", () => { + it("should return a full joiner configuration with custom aliases overriding defaults", () => { const joinerConfig = defineJoinerConfig(Modules.FULFILLMENT, { models: [FulfillmentSet], alias: [ diff --git a/packages/core/utils/src/modules-sdk/joiner-config-builder.ts b/packages/core/utils/src/modules-sdk/joiner-config-builder.ts index d2ab83e236a34..8c5809b6fbbba 100644 --- a/packages/core/utils/src/modules-sdk/joiner-config-builder.ts +++ b/packages/core/utils/src/modules-sdk/joiner-config-builder.ts @@ -172,7 +172,7 @@ export function defineJoinerConfig( * It can happen that we could just remove that but we need to investigate (looking at the * lookups from the remote joiner to identify which entity a property refers to) */ - primaryKeys ??= ["id"] + primaryKeys ??= [] const finalPrimaryKeys = new Set(primaryKeys) if (modelDefinitions.size) { const linkConfig = buildLinkConfigFromModelObjects( @@ -191,7 +191,7 @@ export function defineJoinerConfig( }) } - primaryKeys.push(...Array.from(finalPrimaryKeys)) + primaryKeys = Array.from(finalPrimaryKeys.add("id")) // TODO: In the context of DML add a validation on primary keys and linkable keys if the consumer provide them manually. follow up pr From c2914c635902ffc8e4e283a772191930fc7d8c16 Mon Sep 17 00:00:00 2001 From: Harminder Virk Date: Fri, 22 Nov 2024 12:40:42 +0530 Subject: [PATCH 057/175] test: remove only modifier from test --- integration-tests/http/__tests__/product/admin/product.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration-tests/http/__tests__/product/admin/product.spec.ts b/integration-tests/http/__tests__/product/admin/product.spec.ts index 4bb9ea93bb9a6..bc6d52e593819 100644 --- a/integration-tests/http/__tests__/product/admin/product.spec.ts +++ b/integration-tests/http/__tests__/product/admin/product.spec.ts @@ -1463,7 +1463,7 @@ medusaIntegrationTestRunner({ ) }) - it.only("updates a product (update prices, tags, update status, delete collection, delete type, replaces images)", async () => { + it("updates a product (update prices, tags, update status, delete collection, delete type, replaces images)", async () => { const payload = { collection_id: null, title: "Test an update", From d033343482197c9154007b1e1e76d39d27cf2336 Mon Sep 17 00:00:00 2001 From: Harminder Virk Date: Fri, 22 Nov 2024 13:52:44 +0530 Subject: [PATCH 058/175] refactor: remove hooks usage from product collection --- .../integration-tests/__fixtures__/product/index.ts | 9 ++++++++- .../modules/product/src/models/product-collection.ts | 10 ++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/modules/product/integration-tests/__fixtures__/product/index.ts b/packages/modules/product/integration-tests/__fixtures__/product/index.ts index 2c5445011e5d8..0fa2ddfedffb3 100644 --- a/packages/modules/product/integration-tests/__fixtures__/product/index.ts +++ b/packages/modules/product/integration-tests/__fixtures__/product/index.ts @@ -1,4 +1,8 @@ -import { ProductStatus, toMikroORMEntity } from "@medusajs/framework/utils" +import { + kebabCase, + ProductStatus, + toMikroORMEntity, +} from "@medusajs/framework/utils" import { SqlEntityManager } from "@mikro-orm/postgresql" import { Image, @@ -73,6 +77,9 @@ export async function createCollections( }[] ) { const collections: any[] = collectionData.map((collectionData) => { + if (!collectionData.handle && collectionData.title) { + collectionData.handle = kebabCase(collectionData.title) + } return manager.create(toMikroORMEntity(ProductCollection), collectionData) }) diff --git a/packages/modules/product/src/models/product-collection.ts b/packages/modules/product/src/models/product-collection.ts index 2d24476de0159..a5ebcbb1670e3 100644 --- a/packages/modules/product/src/models/product-collection.ts +++ b/packages/modules/product/src/models/product-collection.ts @@ -1,4 +1,5 @@ -import { kebabCase, model } from "@medusajs/framework/utils" +// import { kebabCase, model } from "@medusajs/framework/utils" +import { model } from "@medusajs/framework/utils" import Product from "./product" const collectionHandleIndexName = "IDX_collection_handle_unique" @@ -20,13 +21,6 @@ const ProductCollection = model mappedBy: "collection", }), }) - .hooks({ - creating(productCollection) { - productCollection.handle ??= productCollection.title - ? kebabCase(productCollection.title) - : null - }, - }) .indexes([ { name: collectionHandleIndexName, From e5bf1c8fdecab9f8935f38173ed4928f625376b9 Mon Sep 17 00:00:00 2001 From: Harminder Virk Date: Fri, 22 Nov 2024 14:09:41 +0530 Subject: [PATCH 059/175] refactor: remove hooks usage from product-option --- packages/modules/product/src/models/product-option.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/packages/modules/product/src/models/product-option.ts b/packages/modules/product/src/models/product-option.ts index bcbdfca5d6a5a..1a7644936935f 100644 --- a/packages/modules/product/src/models/product-option.ts +++ b/packages/modules/product/src/models/product-option.ts @@ -26,11 +26,6 @@ const ProductOption = model .cascades({ delete: ["values"], }) - .hooks({ - creating(productOption) { - productOption.product_id ??= productOption.product?.id ?? null - }, - }) .indexes([ { name: optionProductIdTitleIndexName, From 819b4c139d2199ed132bbce057c32cad3f938815 Mon Sep 17 00:00:00 2001 From: Harminder Virk Date: Fri, 22 Nov 2024 14:44:07 +0530 Subject: [PATCH 060/175] refactor: remove hooks usage for computing category handle --- .../product-category/data/index.ts | 23 ++++++++++++++++--- .../__tests__/product-category.ts | 4 ++++ .../product/src/models/product-category.ts | 15 ++++++------ .../src/services/product-module-service.ts | 7 +++++- 4 files changed, 38 insertions(+), 11 deletions(-) diff --git a/packages/modules/product/integration-tests/__fixtures__/product-category/data/index.ts b/packages/modules/product/integration-tests/__fixtures__/product-category/data/index.ts index 43ef9965e711f..ee27eed260fa4 100644 --- a/packages/modules/product/integration-tests/__fixtures__/product-category/data/index.ts +++ b/packages/modules/product/integration-tests/__fixtures__/product-category/data/index.ts @@ -1,3 +1,5 @@ +import { kebabCase } from "@medusajs/framework/utils" + export const productCategoriesData = [ { id: "category-0", @@ -25,7 +27,12 @@ export const productCategoriesData = [ name: "category 1 b 1", parent_category_id: "category-1-b", }, -] +].map((entry) => { + return { + handle: kebabCase(entry.name), + ...entry, + } +}) export const productCategoriesRankData = [ { @@ -64,7 +71,12 @@ export const productCategoriesRankData = [ parent_category_id: "category-0-0", rank: 2, }, -] +].map((entry) => { + return { + handle: kebabCase(entry.name), + ...entry, + } +}) export const eletronicsCategoriesData = [ { @@ -188,4 +200,9 @@ export const eletronicsCategoriesData = [ name: "Mini Models", parent_category_id: "iphones", }, -] +].map((entry) => { + return { + handle: kebabCase(entry.name), + ...entry, + } +}) diff --git a/packages/modules/product/integration-tests/__tests__/product-category.ts b/packages/modules/product/integration-tests/__tests__/product-category.ts index 0adaabf2f7380..5187fab228a83 100644 --- a/packages/modules/product/integration-tests/__tests__/product-category.ts +++ b/packages/modules/product/integration-tests/__tests__/product-category.ts @@ -879,6 +879,7 @@ moduleIntegrationTestRunner({ await service.create([ { name: "New Category", + handle: "new-category", parent_category_id: null, }, ]) @@ -904,11 +905,13 @@ moduleIntegrationTestRunner({ await service.create([ { name: "New Category", + handle: "new-category", parent_category_id: null, rank: 0, }, { name: "New Category 2", + handle: "new-category-2", parent_category_id: null, }, ]) @@ -932,6 +935,7 @@ moduleIntegrationTestRunner({ await service.create([ { name: "New Category 2.1", + handle: "new-category-2-1", parent_category_id: productCategoryNew.id, }, ]) diff --git a/packages/modules/product/src/models/product-category.ts b/packages/modules/product/src/models/product-category.ts index c524fbf98c074..931b6f28c40a8 100644 --- a/packages/modules/product/src/models/product-category.ts +++ b/packages/modules/product/src/models/product-category.ts @@ -1,4 +1,5 @@ -import { kebabCase, model } from "@medusajs/framework/utils" +// import { kebabCase, model } from "@medusajs/framework/utils" +import { model } from "@medusajs/framework/utils" import Product from "./product" const categoryHandleIndexName = "IDX_category_handle_unique" @@ -48,12 +49,12 @@ const ProductCategory = model productCategory.mpath ? productCategory.mpath + "." : "" }${productCategory.id}` - /** - * TODO: A validation step might need to exists, maybe at the service level or the repository level - */ - productCategory.handle ??= kebabCase( - productCategory.name ?? productCategory.id // TODO: There seems to be a bug with model configuration where both properties are optional but non nullable. - ) + // /** + // * TODO: A validation step might need to exists, maybe at the service level or the repository level + // */ + // productCategory.handle ??= kebabCase( + // productCategory.name ?? productCategory.id // TODO: There seems to be a bug with model configuration where both properties are optional but non nullable. + // ) }, }) .cascades({ diff --git a/packages/modules/product/src/services/product-module-service.ts b/packages/modules/product/src/services/product-module-service.ts index 4f49d995edec0..ea215c8691c6d 100644 --- a/packages/modules/product/src/services/product-module-service.ts +++ b/packages/modules/product/src/services/product-module-service.ts @@ -1155,7 +1155,12 @@ export default class ProductModuleService ): Promise< ProductTypes.ProductCategoryDTO[] | ProductTypes.ProductCategoryDTO > { - const input = Array.isArray(data) ? data : [data] + const input = (Array.isArray(data) ? data : [data]).map( + (productCategory) => { + productCategory.handle ??= kebabCase(productCategory.name) + return productCategory + } + ) const categories = await this.productCategoryService_.create( input, From b127543981aa474fadc82d1eef01b03fb0570026 Mon Sep 17 00:00:00 2001 From: Harminder Virk Date: Fri, 22 Nov 2024 15:34:58 +0530 Subject: [PATCH 061/175] refactor: remove hooks usage from productCategory model --- .../product/src/models/product-category.ts | 14 ----------- .../src/repositories/product-category.ts | 24 +++++++++++++++---- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/packages/modules/product/src/models/product-category.ts b/packages/modules/product/src/models/product-category.ts index 931b6f28c40a8..e6c8766de7667 100644 --- a/packages/modules/product/src/models/product-category.ts +++ b/packages/modules/product/src/models/product-category.ts @@ -43,20 +43,6 @@ const ProductCategory = model mappedBy: "categories", }), }) - .hooks({ - creating: (productCategory) => { - productCategory.mpath = `${ - productCategory.mpath ? productCategory.mpath + "." : "" - }${productCategory.id}` - - // /** - // * TODO: A validation step might need to exists, maybe at the service level or the repository level - // */ - // productCategory.handle ??= kebabCase( - // productCategory.name ?? productCategory.id // TODO: There seems to be a bug with model configuration where both properties are optional but non nullable. - // ) - }, - }) .cascades({ delete: ["category_children"], }) diff --git a/packages/modules/product/src/repositories/product-category.ts b/packages/modules/product/src/repositories/product-category.ts index a93c110225e66..6b590c76684f5 100644 --- a/packages/modules/product/src/repositories/product-category.ts +++ b/packages/modules/product/src/repositories/product-category.ts @@ -391,11 +391,13 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito } // Set the base mpath if the category has a parent. The model `create` hook will append the own id to the base mpath. + let parentCategory: InferEntityType | null = + null const parentCategoryId = categoryData.parent_category_id ?? categoryData.parent_category?.id if (parentCategoryId) { - const parentCategory = await manager.findOne< + parentCategory = await manager.findOne< InferEntityType >(ProductCategory.name, parentCategoryId) @@ -405,14 +407,28 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito `Parent category with id: '${parentCategoryId}' does not exist` ) } - - categoryData.mpath = parentCategory.mpath } - return manager.create>( + const result = await manager.create< + InferEntityType + >( ProductCategory.name, categoryData as unknown as InferEntityType ) + + /** + * Since "mpath" calculation relies on the id of the created + * category, we have to compute it after calling manager.create. So + * that we can access the "category.id" which is under the hood + * defined by DML. + */ + manager.assign(result, { + mpath: parentCategory + ? `${parentCategory.mpath}.${result.id}` + : result.id, + }) + + return result }) ) From 4094dda2a25163fb7bdce188b7b1016d13c6db5f Mon Sep 17 00:00:00 2001 From: Harminder Virk Date: Fri, 22 Nov 2024 15:43:40 +0530 Subject: [PATCH 062/175] refactor: remove hooks from DML --- packages/core/utils/src/dml/entity.ts | 30 ----------------- .../utils/src/dml/helpers/create-graphql.ts | 2 +- .../dml/helpers/create-mikro-orm-entity.ts | 32 +++---------------- 3 files changed, 6 insertions(+), 58 deletions(-) diff --git a/packages/core/utils/src/dml/entity.ts b/packages/core/utils/src/dml/entity.ts index 15923d63acb5c..ab0f4931be9f7 100644 --- a/packages/core/utils/src/dml/entity.ts +++ b/packages/core/utils/src/dml/entity.ts @@ -6,7 +6,6 @@ import { IDmlEntity, IDmlEntityConfig, InferDmlEntityNameFromConfig, - InferSchemaFields, QueryCondition, } from "@medusajs/types" import { isObject, isString, toCamelCase } from "../common" @@ -15,14 +14,6 @@ import { BelongsTo } from "./relations/belongs-to" const IsDmlEntity = Symbol.for("isDmlEntity") -/** - * @experimental - * need to be moved after RFV - */ -type Hooks = { - creating?: (entity: InferSchemaFields) => void -} - function extractNameAndTableName( nameOrConfig: Config ) { @@ -78,13 +69,6 @@ export class DmlEntity< #cascades: EntityCascades = {} #indexes: EntityIndex[] = [] - /** - * @experimental - * TODO: Write RFC about this, for now it is unstable and mainly - * for test purposes - */ - #hooks: Hooks = {} - constructor(nameOrConfig: TConfig, schema: Schema) { const { name, tableName } = extractNameAndTableName(nameOrConfig) this.schema = schema @@ -112,7 +96,6 @@ export class DmlEntity< schema: DMLSchema cascades: EntityCascades indexes: EntityIndex[] - hooks: Hooks } { return { name: this.name, @@ -120,7 +103,6 @@ export class DmlEntity< schema: this.schema, cascades: this.#cascades, indexes: this.#indexes, - hooks: this.#hooks, } } @@ -252,16 +234,4 @@ export class DmlEntity< this.#indexes = indexes as EntityIndex[] return this } - - /** - * @experimental - * TODO: Write RFC about this, for now it is unstable and mainly - * for test purposes - * @param hooks - * @returns - */ - hooks(hooks: Hooks): this { - this.#hooks = hooks - return this - } } diff --git a/packages/core/utils/src/dml/helpers/create-graphql.ts b/packages/core/utils/src/dml/helpers/create-graphql.ts index b89b9a5dc35c1..915a53babd13c 100644 --- a/packages/core/utils/src/dml/helpers/create-graphql.ts +++ b/packages/core/utils/src/dml/helpers/create-graphql.ts @@ -1,8 +1,8 @@ import type { PropertyType } from "@medusajs/types" import { DmlEntity } from "../entity" import { parseEntityName } from "./entity-builder/parse-entity-name" -import { getGraphQLAttributeFromDMLPropety } from "./graphql-builder/get-attribute" import { setGraphQLRelationship } from "./graphql-builder/set-relationship" +import { getGraphQLAttributeFromDMLPropety } from "./graphql-builder/get-attribute" export function generateGraphQLFromEntity>( entity: T diff --git a/packages/core/utils/src/dml/helpers/create-mikro-orm-entity.ts b/packages/core/utils/src/dml/helpers/create-mikro-orm-entity.ts index 77956384aa2ac..0acae5b23e482 100644 --- a/packages/core/utils/src/dml/helpers/create-mikro-orm-entity.ts +++ b/packages/core/utils/src/dml/helpers/create-mikro-orm-entity.ts @@ -6,12 +6,12 @@ import type { Infer, PropertyType, } from "@medusajs/types" -import { BeforeCreate, Entity, Filter } from "@mikro-orm/core" -import { camelToSnakeCase } from "../../common" -import { mikroOrmSoftDeletableFilterOptions } from "../../dal" +import { Entity, Filter } from "@mikro-orm/core" + import { DmlEntity } from "../entity" -import { DuplicateIdPropertyError } from "../errors" import { IdProperty } from "../properties/id" +import { DuplicateIdPropertyError } from "../errors" +import { mikroOrmSoftDeletableFilterOptions } from "../../dal" import { applySearchable } from "./entity-builder/apply-searchable" import { defineProperty } from "./entity-builder/define-property" import { defineRelationship } from "./entity-builder/define-relationship" @@ -47,12 +47,7 @@ function createMikrORMEntity() { function createEntity>(entity: T): Infer { class MikroORMEntity {} - const { - schema, - cascades, - indexes: entityIndexes = [], - hooks = {}, - } = entity.parse() + const { schema, cascades, indexes: entityIndexes = [] } = entity.parse() const { modelName, tableName } = parseEntityName(entity) if (ENTITIES[modelName]) { return ENTITIES[modelName] as Infer @@ -99,23 +94,6 @@ function createMikrORMEntity() { applyEntityIndexes(MikroORMEntity, tableName, entityIndexes) - /** - * @experimental - * TODO: Write RFC about this, for now it is unstable and should be moved - * to `applyHooks` - */ - for (const [hookName, hook] of Object.entries(hooks)) { - if (hookName === "creating") { - const hookMethodName = "beforeCreate_" + camelToSnakeCase(modelName) - const hookWrapper = function (this: MikroORMEntity) { - return hook(this as any) - } - - MikroORMEntity.prototype[hookMethodName] = hookWrapper - BeforeCreate()(MikroORMEntity.prototype, hookMethodName) - } - } - /** * Converting class to a MikroORM entity */ From b38f85eb3776cfd15df6b462e4e1cf9f7fdad313 Mon Sep 17 00:00:00 2001 From: Harminder Virk Date: Fri, 22 Nov 2024 16:08:32 +0530 Subject: [PATCH 063/175] refactor: remove cruft --- .../product/src/models/product-category.ts | 102 +--------- .../product/src/models/product-collection.ts | 53 +----- .../product/src/models/product-image.ts | 49 +---- .../src/models/product-option-value.ts | 60 +----- .../product/src/models/product-option.ts | 63 +------ .../modules/product/src/models/product-tag.ts | 47 +---- .../product/src/models/product-type.ts | 45 +---- .../product/src/models/product-variant.ts | 153 +-------------- .../modules/product/src/models/product.ts | 176 +----------------- 9 files changed, 21 insertions(+), 727 deletions(-) diff --git a/packages/modules/product/src/models/product-category.ts b/packages/modules/product/src/models/product-category.ts index e6c8766de7667..a80badde66245 100644 --- a/packages/modules/product/src/models/product-category.ts +++ b/packages/modules/product/src/models/product-category.ts @@ -1,25 +1,6 @@ -// import { kebabCase, model } from "@medusajs/framework/utils" import { model } from "@medusajs/framework/utils" import Product from "./product" -const categoryHandleIndexName = "IDX_category_handle_unique" -// const categoryHandleIndexStatement = createPsqlIndexStatementHelper({ -// name: categoryHandleIndexName, -// tableName: "product_category", -// columns: ["handle"], -// unique: true, -// where: "deleted_at IS NULL", -// }) - -const categoryMpathIndexName = "IDX_product_category_path" -// const categoryMpathIndexStatement = createPsqlIndexStatementHelper({ -// name: categoryMpathIndexName, -// tableName: "product_category", -// columns: ["mpath"], -// unique: false, -// where: "deleted_at IS NULL", -// }) - const ProductCategory = model .define("ProductCategory", { id: model.id({ prefix: "pcat" }).primaryKey(), @@ -48,96 +29,17 @@ const ProductCategory = model }) .indexes([ { - name: categoryMpathIndexName, + name: "IDX_product_category_path", on: ["mpath"], unique: false, where: "deleted_at IS NULL", }, { - name: categoryHandleIndexName, + name: "IDX_category_handle_unique", on: ["handle"], unique: true, where: "deleted_at IS NULL", }, ]) -// categoryMpathIndexStatement.MikroORMIndex() -// categoryHandleIndexStatement.MikroORMIndex() -// @Entity({ tableName: "product_category" }) -// @Filter(DALUtils.mikroOrmSoftDeletableFilterOptions) -// class ProductCategory { -// @PrimaryKey({ columnType: "text" }) -// id!: string -// @Searchable() -// @Property({ columnType: "text", nullable: false }) -// name?: string -// @Searchable() -// @Property({ columnType: "text", default: "", nullable: false }) -// description?: string -// @Searchable() -// @Property({ columnType: "text", nullable: false }) -// handle?: string -// @Property({ columnType: "text", nullable: false }) -// mpath?: string -// @Property({ columnType: "boolean", default: false }) -// is_active?: boolean -// @Property({ columnType: "boolean", default: false }) -// is_internal?: boolean -// @Property({ -// columnType: "integer", -// nullable: false, -// default: 0, -// }) -// rank: number -// @ManyToOne(() => ProductCategory, { -// columnType: "text", -// fieldName: "parent_category_id", -// nullable: true, -// mapToPk: true, -// onDelete: "cascade", -// }) -// parent_category_id?: string | null -// @ManyToOne(() => ProductCategory, { nullable: true, persist: false }) -// parent_category?: ProductCategory -// @OneToMany({ -// entity: () => ProductCategory, -// mappedBy: (productCategory) => productCategory.parent_category, -// }) -// category_children = new Collection(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: "IDX_product_category_deleted_at" }) -// @Property({ columnType: "timestamptz", nullable: true }) -// deleted_at?: Date -// @Property({ columnType: "jsonb", nullable: true }) -// metadata: Record | null = null -// @ManyToMany(() => Product, (product) => product.categories) -// products = new Collection(this) -// @OnInit() -// async onInit() { -// this.id = generateEntityId(this.id, "pcat") -// this.parent_category_id ??= this.parent_category?.id ?? null -// } -// @BeforeCreate() -// async onCreate(args: EventArgs) { -// this.id = generateEntityId(this.id, "pcat") -// this.parent_category_id ??= this.parent_category?.id ?? null -// if (!this.handle && this.name) { -// this.handle = kebabCase(this.name) -// } -// this.mpath = `${this.mpath ? this.mpath + "." : ""}${this.id}` -// } -// } - export default ProductCategory diff --git a/packages/modules/product/src/models/product-collection.ts b/packages/modules/product/src/models/product-collection.ts index a5ebcbb1670e3..e58fa20b113ae 100644 --- a/packages/modules/product/src/models/product-collection.ts +++ b/packages/modules/product/src/models/product-collection.ts @@ -1,16 +1,6 @@ -// import { kebabCase, model } from "@medusajs/framework/utils" import { model } from "@medusajs/framework/utils" import Product from "./product" -const collectionHandleIndexName = "IDX_collection_handle_unique" -// const collectionHandleIndexStatement = createPsqlIndexStatementHelper({ -// name: collectionHandleIndexName, -// tableName: "product_collection", -// columns: ["handle"], -// unique: true, -// where: "deleted_at IS NULL", -// }) - const ProductCollection = model .define("ProductCollection", { id: model.id({ prefix: "pcol" }).primaryKey(), @@ -23,52 +13,11 @@ const ProductCollection = model }) .indexes([ { - name: collectionHandleIndexName, + name: "IDX_collection_handle_unique", on: ["handle"], unique: true, where: "deleted_at IS NULL", }, ]) -// collectionHandleIndexStatement.MikroORMIndex() -// @Entity({ tableName: "product_collection" }) -// @Filter(DALUtils.mikroOrmSoftDeletableFilterOptions) -// class ProductCollection { -// @PrimaryKey({ columnType: "text" }) -// id!: string -// @Searchable() -// @Property({ columnType: "text" }) -// title: string -// @Property({ columnType: "text" }) -// handle?: string -// @OneToMany(() => Product, (product) => product.collection) -// products = new Collection(this) -// @Property({ columnType: "jsonb", nullable: true }) -// metadata?: Record | 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 -// @Index({ name: "IDX_product_collection_deleted_at" }) -// @Property({ columnType: "timestamptz", nullable: true }) -// deleted_at?: Date -// @OnInit() -// @BeforeCreate() -// onInit() { -// this.id = generateEntityId(this.id, "pcol") -// if (!this.handle && this.title) { -// this.handle = kebabCase(this.title) -// } -// } -// } - export default ProductCollection diff --git a/packages/modules/product/src/models/product-image.ts b/packages/modules/product/src/models/product-image.ts index 31735c7a11ab5..f2e30a6acc849 100644 --- a/packages/modules/product/src/models/product-image.ts +++ b/packages/modules/product/src/models/product-image.ts @@ -1,15 +1,6 @@ import { model } from "@medusajs/framework/utils" import Product from "./product" -const imageUrlIndexName = "IDX_product_image_url" -// const imageUrlIndexStatement = createPsqlIndexStatementHelper({ -// name: imageUrlIndexName, -// tableName: "image", -// columns: ["url"], -// unique: false, -// where: "deleted_at IS NULL", -// }) - const ProductImage = model .define( { tableName: "image", name: "ProductImage" }, @@ -22,49 +13,11 @@ const ProductImage = model ) .indexes([ { - name: imageUrlIndexName, + name: "IDX_product_image_url", on: ["url"], unique: false, where: "deleted_at IS NULL", }, ]) -// imageUrlIndexStatement.MikroORMIndex() -// @Entity({ tableName: "image" }) -// @Filter(DALUtils.mikroOrmSoftDeletableFilterOptions) -// class ProductImage { -// @PrimaryKey({ columnType: "text" }) -// id!: string -// @Property({ columnType: "text" }) -// url: string -// @Property({ columnType: "jsonb", nullable: true }) -// metadata?: Record | 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 -// @Index({ name: "IDX_product_image_deleted_at" }) -// @Property({ columnType: "timestamptz", nullable: true }) -// deleted_at?: Date -// @ManyToMany(() => Product, (product) => product.images) -// products = new Collection(this) -// @OnInit() -// onInit() { -// this.id = generateEntityId(this.id, "img") -// } -// @BeforeCreate() -// onCreate() { -// this.id = generateEntityId(this.id, "img") -// } -// } - export default ProductImage diff --git a/packages/modules/product/src/models/product-option-value.ts b/packages/modules/product/src/models/product-option-value.ts index 3b466dc9ecd8b..21e0aa7461191 100644 --- a/packages/modules/product/src/models/product-option-value.ts +++ b/packages/modules/product/src/models/product-option-value.ts @@ -1,15 +1,6 @@ import { model } from "@medusajs/framework/utils" import { ProductOption, ProductVariant } from "./index" -const optionValueOptionIdIndexName = "IDX_option_value_option_id_unique" -// const optionValueOptionIdIndexStatement = createPsqlIndexStatementHelper({ -// name: optionValueOptionIdIndexName, -// tableName: "product_option_value", -// columns: ["option_id", "value"], -// unique: true, -// where: "deleted_at IS NULL", -// }) - const ProductOptionValue = model .define("ProductOptionValue", { id: model.id({ prefix: "optval" }).primaryKey(), @@ -26,60 +17,11 @@ const ProductOptionValue = model }) .indexes([ { - name: optionValueOptionIdIndexName, + name: "IDX_option_value_option_id_unique", on: ["option_id", "value"], unique: true, where: "deleted_at IS NULL", }, ]) -// optionValueOptionIdIndexStatement.MikroORMIndex() -// @Entity({ tableName: "product_option_value" }) -// @Filter(DALUtils.mikroOrmSoftDeletableFilterOptions) -// class ProductOptionValue { -// @PrimaryKey({ columnType: "text" }) -// id!: string -// @Property({ columnType: "text" }) -// value: string -// @ManyToOne(() => ProductOption, { -// columnType: "text", -// fieldName: "option_id", -// mapToPk: true, -// nullable: true, -// onDelete: "cascade", -// }) -// option_id: string | null -// @ManyToOne(() => ProductOption, { -// nullable: true, -// persist: false, -// }) -// option: ProductOption | null -// @ManyToMany(() => ProductVariant, (variant) => variant.options) -// variants = new Collection(this) -// @Property({ columnType: "jsonb", nullable: true }) -// metadata?: Record | 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 -// @Index({ name: "IDX_product_option_value_deleted_at" }) -// @Property({ columnType: "timestamptz", nullable: true }) -// deleted_at?: Date -// @OnInit() -// @BeforeCreate() -// onInit() { -// this.id = generateEntityId(this.id, "optval") -// this.option_id ??= this.option?.id ?? null -// } -// } - export default ProductOptionValue diff --git a/packages/modules/product/src/models/product-option.ts b/packages/modules/product/src/models/product-option.ts index 1a7644936935f..553209193a840 100644 --- a/packages/modules/product/src/models/product-option.ts +++ b/packages/modules/product/src/models/product-option.ts @@ -2,15 +2,6 @@ import { model } from "@medusajs/framework/utils" import { Product } from "./index" import ProductOptionValue from "./product-option-value" -const optionProductIdTitleIndexName = "IDX_option_product_id_title_unique" -// const optionProductIdTitleIndexStatement = createPsqlIndexStatementHelper({ -// name: optionProductIdTitleIndexName, -// tableName: "product_option", -// columns: ["product_id", "title"], -// unique: true, -// where: "deleted_at IS NULL", -// }) - const ProductOption = model .define("ProductOption", { id: model.id({ prefix: "opt" }).primaryKey(), @@ -28,63 +19,11 @@ const ProductOption = model }) .indexes([ { - name: optionProductIdTitleIndexName, + name: "IDX_option_product_id_title_unique", on: ["product_id", "title"], unique: true, where: "deleted_at IS NULL", }, ]) -// optionProductIdTitleIndexStatement.MikroORMIndex() -// @Entity({ tableName: "product_option" }) -// @Filter(DALUtils.mikroOrmSoftDeletableFilterOptions) -// class ProductOption { -// @PrimaryKey({ columnType: "text" }) -// id!: string -// @Searchable() -// @Property({ columnType: "text" }) -// title: string -// @ManyToOne(() => Product, { -// columnType: "text", -// fieldName: "product_id", -// mapToPk: true, -// nullable: true, -// onDelete: "cascade", -// }) -// product_id: string | null -// @ManyToOne(() => Product, { -// persist: false, -// nullable: true, -// }) -// product: Product | null -// @OneToMany(() => ProductOptionValue, (value) => value.option, { -// cascade: [Cascade.PERSIST, "soft-remove" as any], -// }) -// values = new Collection(this) -// @Property({ columnType: "jsonb", nullable: true }) -// metadata?: Record | 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 -// @Index({ name: "IDX_product_option_deleted_at" }) -// @Property({ columnType: "timestamptz", nullable: true }) -// deleted_at?: Date -// @OnInit() -// @BeforeCreate() -// onInit() { -// this.id = generateEntityId(this.id, "opt") -// this.product_id ??= this.product?.id ?? null -// } -// } - export default ProductOption diff --git a/packages/modules/product/src/models/product-tag.ts b/packages/modules/product/src/models/product-tag.ts index e4ec355f56761..864d5d695cec9 100644 --- a/packages/modules/product/src/models/product-tag.ts +++ b/packages/modules/product/src/models/product-tag.ts @@ -1,15 +1,6 @@ import { model } from "@medusajs/framework/utils" import Product from "./product" -const tagValueIndexName = "IDX_tag_value_unique" -// const tagValueIndexStatement = createPsqlIndexStatementHelper({ -// name: tagValueIndexName, -// tableName: "product_tag", -// columns: ["value"], -// unique: true, -// where: "deleted_at IS NULL", -// }) - const ProductTag = model .define( { tableName: "product_tag", name: "ProductTag" }, @@ -24,47 +15,11 @@ const ProductTag = model ) .indexes([ { - name: tagValueIndexName, + name: "tagValueIndexName", on: ["value"], unique: true, where: "deleted_at IS NULL", }, ]) -// tagValueIndexStatement.MikroORMIndex() -// @Entity({ tableName: "product_tag" }) -// @Filter(DALUtils.mikroOrmSoftDeletableFilterOptions) -// class ProductTag { -// @PrimaryKey({ columnType: "text" }) -// id!: string -// @Searchable() -// @Property({ columnType: "text" }) -// value: string -// @Property({ columnType: "jsonb", nullable: true }) -// metadata?: Record | 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 -// @Index({ name: "IDX_product_tag_deleted_at" }) -// @Property({ columnType: "timestamptz", nullable: true }) -// deleted_at?: Date -// @ManyToMany(() => Product, (product) => product.tags) -// products = new Collection(this) -// @OnInit() -// @BeforeCreate() -// onInit() { -// this.id = generateEntityId(this.id, "ptag") -// } -// } - export default ProductTag diff --git a/packages/modules/product/src/models/product-type.ts b/packages/modules/product/src/models/product-type.ts index eec3c3fd89f62..904c9ee6c0684 100644 --- a/packages/modules/product/src/models/product-type.ts +++ b/packages/modules/product/src/models/product-type.ts @@ -1,15 +1,6 @@ import { model } from "@medusajs/framework/utils" import { Product } from "@models" -const typeValueIndexName = "IDX_type_value_unique" -// const typeValueIndexStatement = createPsqlIndexStatementHelper({ -// name: typeValueIndexName, -// tableName: "product_type", -// columns: ["value"], -// unique: true, -// where: "deleted_at IS NULL", -// }) - const ProductType = model .define("ProductType", { id: model.id({ prefix: "ptyp" }).primaryKey(), @@ -21,45 +12,11 @@ const ProductType = model }) .indexes([ { - name: typeValueIndexName, + name: "IDX_type_value_unique", on: ["value"], unique: true, where: "deleted_at IS NULL", }, ]) -// typeValueIndexStatement.MikroORMIndex() -// @Entity({ tableName: "product_type" }) -// @Filter(DALUtils.mikroOrmSoftDeletableFilterOptions) -// class ProductType { -// @PrimaryKey({ columnType: "text" }) -// id!: string -// @Searchable() -// @Property({ columnType: "text" }) -// value: string -// @Property({ columnType: "json", nullable: true }) -// metadata?: Record | 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 -// @Index({ name: "IDX_product_type_deleted_at" }) -// @Property({ columnType: "timestamptz", nullable: true }) -// deleted_at?: Date -// @OnInit() -// @BeforeCreate() -// onInit() { -// this.id = generateEntityId(this.id, "ptyp") -// } -// } - export default ProductType diff --git a/packages/modules/product/src/models/product-variant.ts b/packages/modules/product/src/models/product-variant.ts index 5cc6f37b9f05c..1f3694c22e95c 100644 --- a/packages/modules/product/src/models/product-variant.ts +++ b/packages/modules/product/src/models/product-variant.ts @@ -1,51 +1,6 @@ import { model } from "@medusajs/framework/utils" import { Product, ProductOptionValue } from "@models" -const variantSkuIndexName = "IDX_product_variant_sku_unique" -// const variantSkuIndexStatement = createPsqlIndexStatementHelper({ -// name: variantSkuIndexName, -// tableName: "product_variant", -// columns: ["sku"], -// unique: true, -// where: "deleted_at IS NULL", -// }) - -const variantBarcodeIndexName = "IDX_product_variant_barcode_unique" -// const variantBarcodeIndexStatement = createPsqlIndexStatementHelper({ -// name: variantBarcodeIndexName, -// tableName: "product_variant", -// columns: ["barcode"], -// unique: true, -// where: "deleted_at IS NULL", -// }) - -const variantEanIndexName = "IDX_product_variant_ean_unique" -// const variantEanIndexStatement = createPsqlIndexStatementHelper({ -// name: variantEanIndexName, -// tableName: "product_variant", -// columns: ["ean"], -// unique: true, -// where: "deleted_at IS NULL", -// }) - -const variantUpcIndexName = "IDX_product_variant_upc_unique" -// const variantUpcIndexStatement = createPsqlIndexStatementHelper({ -// name: variantUpcIndexName, -// tableName: "product_variant", -// columns: ["upc"], -// unique: true, -// where: "deleted_at IS NULL", -// }) - -const variantProductIdIndexName = "IDX_product_variant_product_id" -// const variantProductIdIndexStatement = createPsqlIndexStatementHelper({ -// name: variantProductIdIndexName, -// tableName: "product_variant", -// columns: ["product_id"], -// unique: false, -// where: "deleted_at IS NULL", -// }) - const ProductVariant = model .define("ProductVariant", { id: model.id({ prefix: "variant" }).primaryKey(), @@ -80,133 +35,35 @@ const ProductVariant = model }) .indexes([ { - name: variantProductIdIndexName, + name: "IDX_product_variant_product_id", on: ["product_id"], unique: false, where: "deleted_at IS NULL", }, { - name: variantSkuIndexName, + name: "IDX_product_variant_sku_unique", on: ["sku"], unique: true, where: "deleted_at IS NULL", }, { - name: variantBarcodeIndexName, + name: "IDX_product_variant_barcode_unique", on: ["barcode"], unique: true, where: "deleted_at IS NULL", }, { - name: variantEanIndexName, + name: "IDX_product_variant_ean_unique", on: ["ean"], unique: true, where: "deleted_at IS NULL", }, { - name: variantUpcIndexName, + name: "IDX_product_variant_upc_unique", on: ["upc"], unique: true, where: "deleted_at IS NULL", }, ]) -// variantProductIdIndexStatement.MikroORMIndex() -// variantSkuIndexStatement.MikroORMIndex() -// variantBarcodeIndexStatement.MikroORMIndex() -// variantEanIndexStatement.MikroORMIndex() -// variantUpcIndexStatement.MikroORMIndex() -// @Entity({ tableName: "product_variant" }) -// @Filter(DALUtils.mikroOrmSoftDeletableFilterOptions) -// class ProductVariant { -// @PrimaryKey({ columnType: "text" }) -// id!: string -// @Searchable() -// @Property({ columnType: "text" }) -// title: string -// @Searchable() -// @Property({ columnType: "text", nullable: true }) -// sku?: string | null -// @Searchable() -// @Property({ columnType: "text", nullable: true }) -// barcode?: string | null -// @Searchable() -// @Property({ columnType: "text", nullable: true }) -// ean?: string | null -// @Searchable() -// @Property({ columnType: "text", nullable: true }) -// upc?: string | null -// @Property({ columnType: "boolean", default: false }) -// allow_backorder?: boolean = false -// @Property({ columnType: "boolean", default: true }) -// manage_inventory?: boolean = true -// @Property({ columnType: "text", nullable: true }) -// hs_code?: string | null -// @Property({ columnType: "text", nullable: true }) -// origin_country?: string | null -// @Property({ columnType: "text", nullable: true }) -// mid_code?: string | null -// @Property({ columnType: "text", nullable: true }) -// material?: string | null -// @Property({ columnType: "numeric", nullable: true }) -// weight?: number | null -// @Property({ columnType: "numeric", nullable: true }) -// length?: number | null -// @Property({ columnType: "numeric", nullable: true }) -// height?: number | null -// @Property({ columnType: "numeric", nullable: true }) -// width?: number | null -// @Property({ columnType: "jsonb", nullable: true }) -// metadata?: Record | null -// @Property({ -// columnType: "integer", -// nullable: true, -// default: 0, -// }) -// variant_rank?: number | null -// @ManyToOne(() => Product, { -// columnType: "text", -// nullable: true, -// onDelete: "cascade", -// fieldName: "product_id", -// mapToPk: true, -// }) -// product_id: string | null -// @ManyToOne(() => Product, { -// persist: false, -// nullable: true, -// }) -// product: Product | null -// @ManyToMany(() => ProductOptionValue, "variants", { -// owner: true, -// pivotTable: "product_variant_option", -// joinColumn: "variant_id", -// inverseJoinColumn: "option_value_id", -// }) -// options = new Collection(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: "IDX_product_variant_deleted_at" }) -// @Property({ columnType: "timestamptz", nullable: true }) -// deleted_at?: Date -// @OnInit() -// @BeforeCreate() -// onInit() { -// this.id = generateEntityId(this.id, "variant") -// this.product_id ??= this.product?.id ?? null -// } -// } - export default ProductVariant -// export default ProductVariant diff --git a/packages/modules/product/src/models/product.ts b/packages/modules/product/src/models/product.ts index 9d7315f1e86c1..a018a85051986 100644 --- a/packages/modules/product/src/models/product.ts +++ b/packages/modules/product/src/models/product.ts @@ -1,38 +1,12 @@ import { model, ProductUtils } from "@medusajs/framework/utils" -import ProductCategory from "./product-category" -import ProductCollection from "./product-collection" -import ProductImage from "./product-image" -import ProductOption from "./product-option" + import ProductTag from "./product-tag" import ProductType from "./product-type" +import ProductImage from "./product-image" +import ProductOption from "./product-option" import ProductVariant from "./product-variant" - -const productHandleIndexName = "IDX_product_handle_unique" -// const productHandleIndexStatement = createPsqlIndexStatementHelper({ -// name: productHandleIndexName, -// tableName: "product", -// columns: ["handle"], -// unique: true, -// where: "deleted_at IS NULL", -// }) - -const productTypeIndexName = "IDX_product_type_id" -// const productTypeIndexStatement = createPsqlIndexStatementHelper({ -// name: productTypeIndexName, -// tableName: "product", -// columns: ["type_id"], -// unique: false, -// where: "deleted_at IS NULL", -// }) - -const productCollectionIndexName = "IDX_product_collection_id" -// const productCollectionIndexStatement = createPsqlIndexStatementHelper({ -// name: productCollectionIndexName, -// tableName: "product", -// columns: ["collection_id"], -// unique: false, -// where: "deleted_at IS NULL", -// }) +import ProductCategory from "./product-category" +import ProductCollection from "./product-collection" const Product = model .define("Product", { @@ -93,157 +67,23 @@ const Product = model }) .indexes([ { - name: productHandleIndexName, + name: "IDX_product_handle_unique", on: ["handle"], unique: true, where: "deleted_at IS NULL", }, { - name: productTypeIndexName, + name: "IDX_product_type_id", on: ["type_id"], unique: false, where: "deleted_at IS NULL", }, { - name: productCollectionIndexName, + name: "IDX_product_collection_id", on: ["collection_id"], unique: false, where: "deleted_at IS NULL", }, ]) -// productTypeIndexStatement.MikroORMIndex() -// productCollectionIndexStatement.MikroORMIndex() -// productHandleIndexStatement.MikroORMIndex() -// @Entity({ tableName: "product" }) -// @Filter(DALUtils.mikroOrmSoftDeletableFilterOptions) -// class Product { -// @PrimaryKey({ columnType: "text" }) -// id!: string -// @Searchable() -// @Property({ columnType: "text" }) -// title: string -// @Property({ columnType: "text" }) -// handle?: string -// @Searchable() -// @Property({ columnType: "text", nullable: true }) -// subtitle?: string | null -// @Searchable() -// @Property({ -// columnType: "text", -// nullable: true, -// }) -// description?: string | null -// @Property({ columnType: "boolean", default: false }) -// is_giftcard!: boolean -// @Enum(() => ProductUtils.ProductStatus) -// @Property({ default: ProductUtils.ProductStatus.DRAFT }) -// status!: ProductUtils.ProductStatus -// @Property({ columnType: "text", nullable: true }) -// thumbnail?: string | null -// @OneToMany(() => ProductOption, (o) => o.product, { -// cascade: ["soft-remove"] as any, -// }) -// options = new Collection(this) -// @Searchable() -// @OneToMany(() => ProductVariant, (variant) => variant.product, { -// cascade: ["soft-remove"] as any, -// }) -// variants = new Collection(this) -// @Property({ columnType: "text", nullable: true }) -// weight?: number | null -// @Property({ columnType: "text", nullable: true }) -// length?: number | null -// @Property({ columnType: "text", nullable: true }) -// height?: number | null -// @Property({ columnType: "text", nullable: true }) -// width?: number | null -// @Property({ columnType: "text", nullable: true }) -// origin_country?: string | null -// @Property({ columnType: "text", nullable: true }) -// hs_code?: string | null -// @Property({ columnType: "text", nullable: true }) -// mid_code?: string | null -// @Property({ columnType: "text", nullable: true }) -// material?: string | null -// @Searchable() -// @ManyToOne(() => ProductCollection, { -// columnType: "text", -// nullable: true, -// fieldName: "collection_id", -// mapToPk: true, -// onDelete: "set null", -// }) -// collection_id: string | null -// @ManyToOne(() => ProductCollection, { -// nullable: true, -// persist: false, -// }) -// collection: ProductCollection | null -// @ManyToOne(() => ProductType, { -// columnType: "text", -// nullable: true, -// fieldName: "type_id", -// mapToPk: true, -// onDelete: "set null", -// }) -// type_id: string | null -// @ManyToOne(() => ProductType, { -// nullable: true, -// persist: false, -// }) -// type: ProductType | null -// @ManyToMany(() => ProductTag, "products", { -// owner: true, -// pivotTable: "product_tags", -// index: "IDX_product_tag_id", -// }) -// tags = new Collection(this) -// @ManyToMany(() => ProductImage, "products", { -// owner: true, -// pivotTable: "product_images", -// joinColumn: "product_id", -// inverseJoinColumn: "image_id", -// }) -// images = new Collection(this) -// @ManyToMany(() => ProductCategory, "products", { -// owner: true, -// pivotTable: "product_category_product", -// }) -// categories = new Collection(this) -// @Property({ columnType: "boolean", default: true }) -// discountable: boolean -// @Property({ columnType: "text", nullable: true }) -// external_id?: string | 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 -// @Index({ name: "IDX_product_deleted_at" }) -// @Property({ columnType: "timestamptz", nullable: true }) -// deleted_at?: Date -// @Property({ columnType: "jsonb", nullable: true }) -// metadata?: Record | null -// @OnInit() -// @BeforeCreate() -// onInit() { -// this.id = generateEntityId(this.id, "prod") -// this.type_id ??= this.type?.id ?? null -// this.collection_id ??= this.collection?.id ?? null -// if (!this.handle && this.title) { -// this.handle = toHandle(this.title) -// } -// } -// } - export default Product -// export default Product From ccd5d9b5aed50c2baf3977b2d8e93103da237cd9 Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Fri, 22 Nov 2024 09:02:14 -0300 Subject: [PATCH 064/175] order dml --- packages/modules/order/src/models/address.ts | 127 ++----- .../order/src/models/adjustment-line.ts | 55 --- .../order/src/models/claim-item-image.ts | 117 ++---- .../modules/order/src/models/claim-item.ts | 175 +++------ packages/modules/order/src/models/claim.ts | 232 ++++-------- .../modules/order/src/models/exchange-item.ts | 152 ++------ packages/modules/order/src/models/exchange.ts | 222 ++++-------- .../order/src/models/line-item-adjustment.ts | 60 ++- .../order/src/models/line-item-tax-line.ts | 67 +--- .../modules/order/src/models/line-item.ts | 250 ++++--------- .../order/src/models/order-change-action.ts | 326 ++++------------- .../modules/order/src/models/order-change.ts | 342 +++++------------- .../modules/order/src/models/order-item.ts | 245 ++++--------- .../order/src/models/order-shipping-method.ts | 267 ++++---------- .../modules/order/src/models/order-summary.ts | 137 ++----- packages/modules/order/src/models/order.ts | 321 ++++++---------- .../modules/order/src/models/return-item.ts | 203 +++-------- .../modules/order/src/models/return-reason.ts | 152 +++----- packages/modules/order/src/models/return.ts | 261 ++++--------- .../src/models/shipping-method-adjustment.ts | 60 ++- .../src/models/shipping-method-tax-line.ts | 60 ++- .../order/src/models/shipping-method.ts | 140 ++----- packages/modules/order/src/models/tax-line.ts | 51 --- .../modules/order/src/models/transaction.ts | 292 ++++----------- 24 files changed, 1155 insertions(+), 3159 deletions(-) delete mode 100644 packages/modules/order/src/models/adjustment-line.ts delete mode 100644 packages/modules/order/src/models/tax-line.ts diff --git a/packages/modules/order/src/models/address.ts b/packages/modules/order/src/models/address.ts index a4cbc3bdf46f0..6ef2e0c102dc9 100644 --- a/packages/modules/order/src/models/address.ts +++ b/packages/modules/order/src/models/address.ts @@ -1,100 +1,29 @@ -import { DAL } from "@medusajs/framework/types" -import { - createPsqlIndexStatementHelper, - generateEntityId, - Searchable, -} from "@medusajs/framework/utils" -import { - BeforeCreate, - Entity, - OnInit, - OptionalProps, - PrimaryKey, - Property, -} from "@mikro-orm/core" - -type OptionalAddressProps = DAL.ModelDateColumns - -const CustomerIdIndex = createPsqlIndexStatementHelper({ - tableName: "order_address", - columns: "customer_id", -}) - -@Entity({ tableName: "order_address" }) -export default class OrderAddress { - [OptionalProps]: OptionalAddressProps - - @PrimaryKey({ columnType: "text" }) - id!: string - - @Property({ columnType: "text", nullable: true }) - @CustomerIdIndex.MikroORMIndex() - customer_id: string | null = null - - @Searchable() - @Property({ columnType: "text", nullable: true }) - company: string | null = null - - @Searchable() - @Property({ columnType: "text", nullable: true }) - first_name: string | null = null - - @Searchable() - @Property({ columnType: "text", nullable: true }) - last_name: string | null = null - - @Searchable() - @Property({ columnType: "text", nullable: true }) - address_1: string | null = null - - @Searchable() - @Property({ columnType: "text", nullable: true }) - address_2: string | null = null - - @Searchable() - @Property({ columnType: "text", nullable: true }) - city: string | null = null - - @Property({ columnType: "text", nullable: true }) - country_code: string | null = null - - @Searchable() - @Property({ columnType: "text", nullable: true }) - province: string | null = null - - @Searchable() - @Property({ columnType: "text", nullable: true }) - postal_code: string | null = null - - @Searchable() - @Property({ columnType: "text", nullable: true }) - phone: string | null = null - - @Property({ columnType: "jsonb", nullable: true }) - metadata: Record | null = null - - @Property({ - onCreate: () => new Date(), - columnType: "timestamptz", - defaultRaw: "now()", - }) - created_at: Date - - @Property({ - onCreate: () => new Date(), - onUpdate: () => new Date(), - columnType: "timestamptz", - defaultRaw: "now()", +import { model } from "@medusajs/framework/utils" + +const CustomerIdIndex = "IDX_order_address_customer_id" + +const OrderAddress = model + .define("OrderAddress", { + id: model.id({ prefix: "ordaddr" }).primaryKey(), + customer_id: model.text().nullable(), + company: model.text().searchable().nullable(), + first_name: model.text().searchable().nullable(), + last_name: model.text().searchable().nullable(), + address_1: model.text().searchable().nullable(), + address_2: model.text().searchable().nullable(), + city: model.text().searchable().nullable(), + country_code: model.text().nullable(), + province: model.text().searchable().nullable(), + postal_code: model.text().searchable().nullable(), + phone: model.text().searchable().nullable(), + metadata: model.json().nullable(), }) - updated_at: Date - - @BeforeCreate() - onCreate() { - this.id = generateEntityId(this.id, "ordaddr") - } - - @OnInit() - onInit() { - this.id = generateEntityId(this.id, "ordaddr") - } -} + .indexes([ + { + name: CustomerIdIndex, + on: ["customer_id"], + unique: false, + }, + ]) + +export default OrderAddress diff --git a/packages/modules/order/src/models/adjustment-line.ts b/packages/modules/order/src/models/adjustment-line.ts deleted file mode 100644 index 567051ec5d80d..0000000000000 --- a/packages/modules/order/src/models/adjustment-line.ts +++ /dev/null @@ -1,55 +0,0 @@ -import { BigNumberRawValue, DAL } from "@medusajs/framework/types" -import { BigNumber, MikroOrmBigNumberProperty } from "@medusajs/framework/utils" -import { OptionalProps, PrimaryKey, Property } from "@mikro-orm/core" - -type OptionalAdjustmentLineProps = DAL.ModelDateColumns - -/** - * As per the Mikro ORM docs, superclasses should use the abstract class definition - * Source: https://mikro-orm.io/docs/inheritance-mapping - */ -export default abstract class AdjustmentLine { - [OptionalProps]: OptionalAdjustmentLineProps - - @PrimaryKey({ columnType: "text" }) - id: string - - @Property({ columnType: "text", nullable: true }) - description: string | null = null - - @Property({ - columnType: "text", - nullable: true, - }) - promotion_id: string | null = null - - @Property({ columnType: "text", nullable: true }) - code: string | null = null - - @MikroOrmBigNumberProperty() - amount: BigNumber | number - - @Property({ columnType: "jsonb" }) - raw_amount: BigNumberRawValue - - @Property({ columnType: "text", nullable: true }) - provider_id: string | 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 }) - deleted_at: Date | null = null -} diff --git a/packages/modules/order/src/models/claim-item-image.ts b/packages/modules/order/src/models/claim-item-image.ts index 3c6d1f3264cb2..fbb7e09d040e6 100644 --- a/packages/modules/order/src/models/claim-item-image.ts +++ b/packages/modules/order/src/models/claim-item-image.ts @@ -1,92 +1,31 @@ -import { DAL } from "@medusajs/framework/types" -import { - DALUtils, - createPsqlIndexStatementHelper, - generateEntityId, -} from "@medusajs/framework/utils" -import { - BeforeCreate, - Entity, - Filter, - ManyToOne, - OnInit, - OptionalProps, - PrimaryKey, - Property, - Rel, -} from "@mikro-orm/core" +import { model } from "@medusajs/framework/utils" import ClaimItem from "./claim-item" -type OptionalClaimItemImageProps = DAL.ModelDateColumns - -const ClaimItemImageDeletedAtIndex = createPsqlIndexStatementHelper({ - tableName: "order_claim_item_image", - columns: "deleted_at", - where: "deleted_at IS NOT NULL", -}) - -const ClaimItemIdIndex = createPsqlIndexStatementHelper({ - tableName: "order_claim_item_image", - columns: ["claim_item_id"], - where: "deleted_at IS NOT NULL", -}) - -@Entity({ tableName: "order_claim_item_image" }) -@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions) -export default class OrderClaimItemImage { - [OptionalProps]?: OptionalClaimItemImageProps - - @PrimaryKey({ columnType: "text" }) - id: string - - @ManyToOne({ - entity: () => ClaimItem, - mapToPk: true, - fieldName: "claim_item_id", - columnType: "text", - }) - @ClaimItemIdIndex.MikroORMIndex() - claim_item_id: string - - @ManyToOne(() => ClaimItem, { - persist: false, - }) - item: Rel - - @Property({ columnType: "text" }) - url: string - - @Property({ columnType: "jsonb", nullable: true }) - metadata: Record | null = null - - @Property({ - onCreate: () => new Date(), - columnType: "timestamptz", - defaultRaw: "now()", - }) - created_at: Date - - @Property({ - onCreate: () => new Date(), - onUpdate: () => new Date(), - columnType: "timestamptz", - defaultRaw: "now()", +const ClaimItemImageDeletedAtIndex = "IDX_order_claim_item_image_deleted_at" +const ClaimItemIdIndex = "IDX_order_claim_item_image_claim_item_id" + +const OrderClaimItemImage = model + .define("OrderClaimItemImage", { + id: model.id({ prefix: "climg" }).primaryKey(), + claim_item: model.belongsTo(() => ClaimItem, { + mappedBy: "images", + }), + url: model.text(), + metadata: model.json().nullable(), }) - updated_at: Date - - @Property({ columnType: "timestamptz", nullable: true }) - @ClaimItemImageDeletedAtIndex.MikroORMIndex() - deleted_at: Date | null = null - - @BeforeCreate() - onCreate() { - this.id = generateEntityId(this.id, "climg") - this.claim_item_id ??= this.item?.id - } - - @OnInit() - onInit() { - this.id = generateEntityId(this.id, "climg") - this.claim_item_id ??= this.item?.id - } -} + .indexes([ + { + name: ClaimItemImageDeletedAtIndex, + on: ["deleted_at"], + unique: false, + where: "deleted_at IS NOT NULL", + }, + { + name: ClaimItemIdIndex, + on: ["claim_item_id"], + unique: false, + where: "deleted_at IS NOT NULL", + }, + ]) + +export default OrderClaimItemImage diff --git a/packages/modules/order/src/models/claim-item.ts b/packages/modules/order/src/models/claim-item.ts index fe90bc20f118e..80006f95c7705 100644 --- a/packages/modules/order/src/models/claim-item.ts +++ b/packages/modules/order/src/models/claim-item.ts @@ -1,135 +1,50 @@ -import { BigNumberRawValue, DAL } from "@medusajs/framework/types" -import { - ClaimReason, - MikroOrmBigNumberProperty, - createPsqlIndexStatementHelper, - generateEntityId, -} from "@medusajs/framework/utils" -import { - BeforeCreate, - Cascade, - Collection, - Entity, - Enum, - ManyToOne, - OnInit, - OneToMany, - OptionalProps, - PrimaryKey, - Property, - Rel, -} from "@mikro-orm/core" +import { ClaimReason, model } from "@medusajs/framework/utils" import Claim from "./claim" import OrderClaimItemImage from "./claim-item-image" import OrderLineItem from "./line-item" -type OptionalLineItemProps = DAL.ModelDateColumns - -const tableName = "order_claim_item" -const ClaimIdIndex = createPsqlIndexStatementHelper({ - tableName, - columns: "claim_id", - where: "deleted_at IS NOT NULL", -}) - -const ItemIdIndex = createPsqlIndexStatementHelper({ - tableName, - columns: "item_id", - where: "deleted_at IS NOT NULL", -}) - -const DeletedAtIndex = createPsqlIndexStatementHelper({ - tableName, - columns: "deleted_at", - where: "deleted_at IS NOT NULL", -}) - -@Entity({ tableName }) -export default class OrderClaimItem { - [OptionalProps]?: OptionalLineItemProps - - @PrimaryKey({ columnType: "text" }) - id: string - - @OneToMany(() => OrderClaimItemImage, (ci) => ci.item, { - cascade: [Cascade.PERSIST, Cascade.REMOVE], - }) - images = new Collection>(this) - - @Enum({ items: () => ClaimReason, nullable: true }) - reason: Rel | null = null - - @MikroOrmBigNumberProperty() - quantity: Number | number - - @Property({ columnType: "jsonb" }) - raw_quantity: BigNumberRawValue - - @ManyToOne(() => Claim, { - columnType: "text", - fieldName: "claim_id", - mapToPk: true, - onDelete: "cascade", +const ClaimIdIndex = "IDX_order_claim_item_claim_id" +const ItemIdIndex = "IDX_order_claim_item_item_id" +const DeletedAtIndex = "IDX_order_claim_item_deleted_at" + +const OrderClaimItem = model + .define("OrderClaimItem", { + id: model.id({ prefix: "claitem" }).primaryKey(), + images: model.hasMany(() => OrderClaimItemImage, { + mappedBy: "item", + }), + reason: model.enum(ClaimReason).nullable(), + quantity: model.bigNumber(), + raw_quantity: model.json(), + claim: model.belongsTo(() => Claim, { + mappedBy: "items", + }), + item: model.belongsTo(() => OrderLineItem, { + mappedBy: "items", + }), + is_additional_item: model.boolean().default(false), + note: model.text().nullable(), + metadata: model.json().nullable(), }) - @ClaimIdIndex.MikroORMIndex() - claim_id: string - - @ManyToOne(() => Claim, { - persist: false, - }) - claim: Rel - - @ManyToOne({ - entity: () => OrderLineItem, - fieldName: "item_id", - mapToPk: true, - columnType: "text", - }) - @ItemIdIndex.MikroORMIndex() - item_id: string - - @ManyToOne(() => OrderLineItem, { - persist: false, - }) - item: Rel - - @Property({ columnType: "boolean", default: false }) - is_additional_item: boolean = false - - @Property({ columnType: "text", nullable: true }) - note: string - - @Property({ columnType: "jsonb", nullable: true }) - metadata: Record | 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 }) - @DeletedAtIndex.MikroORMIndex() - deleted_at: Date | null = null - - @BeforeCreate() - onCreate() { - this.id = generateEntityId(this.id, "claitem") - this.claim_id ??= this.claim?.id - } - - @OnInit() - onInit() { - this.id = generateEntityId(this.id, "claitem") - this.claim_id ??= this.claim?.id - } -} + .indexes([ + { + name: ClaimIdIndex, + on: ["claim_id"], + unique: false, + where: "deleted_at IS NOT NULL", + }, + { + name: ItemIdIndex, + on: ["item_id"], + unique: false, + where: "deleted_at IS NOT NULL", + }, + { + name: DeletedAtIndex, + on: ["deleted_at"], + unique: false, + where: "deleted_at IS NOT NULL", + }, + ]) + +export default OrderClaimItem diff --git a/packages/modules/order/src/models/claim.ts b/packages/modules/order/src/models/claim.ts index 983993098156b..8e05c100d5098 100644 --- a/packages/modules/order/src/models/claim.ts +++ b/packages/modules/order/src/models/claim.ts @@ -1,173 +1,73 @@ -import { BigNumberRawValue, DAL } from "@medusajs/framework/types" -import { - BigNumber, - ClaimType, - DALUtils, - MikroOrmBigNumberProperty, - createPsqlIndexStatementHelper, - generateEntityId, -} from "@medusajs/framework/utils" -import { - BeforeCreate, - Cascade, - Collection, - Entity, - Enum, - Filter, - ManyToOne, - OnInit, - OneToMany, - OneToOne, - OptionalProps, - PrimaryKey, - Property, - Rel, -} from "@mikro-orm/core" +import { ClaimType, model } from "@medusajs/framework/utils" import ClaimItem from "./claim-item" import Order from "./order" import OrderShipping from "./order-shipping-method" import Return from "./return" import OrderTransaction from "./transaction" -type OptionalOrderClaimProps = DAL.ModelDateColumns - -const DisplayIdIndex = createPsqlIndexStatementHelper({ - tableName: "order_claim", - columns: "display_id", - where: "deleted_at IS NOT NULL", -}) - -const OrderClaimDeletedAtIndex = createPsqlIndexStatementHelper({ - tableName: "order_claim", - columns: "deleted_at", - where: "deleted_at IS NOT NULL", -}) - -const OrderIdIndex = createPsqlIndexStatementHelper({ - tableName: "order_claim", - columns: ["order_id"], - where: "deleted_at IS NOT NULL", -}) - -const ReturnIdIndex = createPsqlIndexStatementHelper({ - tableName: "order_claim", - columns: "return_id", - where: "return_id IS NOT NULL AND deleted_at IS NOT NULL", -}) - -@Entity({ tableName: "order_claim" }) -@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions) -export default class OrderClaim { - [OptionalProps]?: OptionalOrderClaimProps - - @PrimaryKey({ columnType: "text" }) - id: string - - @ManyToOne({ - entity: () => Order, - mapToPk: true, - fieldName: "order_id", - columnType: "text", - }) - @OrderIdIndex.MikroORMIndex() - order_id: string - - @ManyToOne(() => Order, { - persist: false, - }) - order: Rel - - @OneToOne({ - entity: () => Return, - mappedBy: (ret) => ret.claim, - fieldName: "return_id", - nullable: true, - owner: true, - }) - return: Rel - - @Property({ columnType: "text", nullable: true }) - @ReturnIdIndex.MikroORMIndex() - return_id: string | null = null - - @Property({ - columnType: "integer", - }) - order_version: number - - @Property({ autoincrement: true, primary: false }) - @DisplayIdIndex.MikroORMIndex() - display_id: number - - @Enum({ items: () => ClaimType }) - type: Rel - - @Property({ columnType: "boolean", nullable: true }) - no_notification: boolean | null = null - - @MikroOrmBigNumberProperty({ - nullable: true, +const DisplayIdIndex = "IDX_order_claim_display_id" +const OrderClaimDeletedAtIndex = "IDX_order_claim_deleted_at" +const OrderIdIndex = "IDX_order_claim_order_id" +const ReturnIdIndex = "IDX_order_claim_return_id" + +const OrderClaim = model + .define("OrderClaim", { + id: model.id({ prefix: "claim" }).primaryKey(), + order: model.belongsTo(() => Order, { + mappedBy: "claims", + }), + return: model + .belongsTo(() => Return, { + mappedBy: "claim", + }) + .nullable(), + order_version: model.number(), + display_id: model.number(), // TODO: auto increment + type: model.enum(ClaimType), + no_notification: model.boolean().nullable(), + refund_amount: model.bigNumber().nullable(), + raw_refund_amount: model.json(), + additional_items: model.hasMany(() => ClaimItem, { + mappedBy: "claim", + }), + claim_items: model.hasMany(() => ClaimItem, { + mappedBy: "claim", + }), + shipping_methods: model.hasMany(() => OrderShipping, { + mappedBy: "claim", + }), + transactions: model.hasMany(() => OrderTransaction, { + mappedBy: "claim", + }), + created_by: model.text().nullable(), + canceled_at: model.dateTime().nullable(), + metadata: model.json().nullable(), }) - refund_amount: BigNumber | number - - @Property({ columnType: "jsonb", nullable: true }) - raw_refund_amount: BigNumberRawValue - - @OneToMany(() => ClaimItem, (item) => item.claim, { - cascade: [Cascade.PERSIST], - }) - additional_items = new Collection>(this) - - @OneToMany(() => ClaimItem, (item) => item.claim, { - cascade: [Cascade.PERSIST], - }) - claim_items = new Collection>(this) - - @OneToMany(() => OrderShipping, (shippingMethod) => shippingMethod.claim, { - cascade: [Cascade.PERSIST], - }) - shipping_methods = new Collection>(this) - - @OneToMany(() => OrderTransaction, (transaction) => transaction.claim, { - cascade: [Cascade.PERSIST], - }) - transactions = new Collection(this) - - @Property({ columnType: "text", nullable: true }) - created_by: string | null = null - - @Property({ columnType: "jsonb", nullable: true }) - metadata: Record | 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 }) - @OrderClaimDeletedAtIndex.MikroORMIndex() - deleted_at: Date | null = null - - @Property({ columnType: "timestamptz", nullable: true }) - canceled_at: Date | null = null - - @BeforeCreate() - onCreate() { - this.id = generateEntityId(this.id, "claim") - } - - @OnInit() - onInit() { - this.id = generateEntityId(this.id, "claim") - } -} + .indexes([ + { + name: DisplayIdIndex, + on: ["display_id"], + unique: false, + where: "deleted_at IS NOT NULL", + }, + { + name: OrderClaimDeletedAtIndex, + on: ["deleted_at"], + unique: false, + where: "deleted_at IS NOT NULL", + }, + { + name: OrderIdIndex, + on: ["order_id"], + unique: false, + where: "deleted_at IS NOT NULL", + }, + { + name: ReturnIdIndex, + on: ["return_id"], + unique: false, + where: "return_id IS NOT NULL AND deleted_at IS NOT NULL", + }, + ]) + +export default OrderClaim diff --git a/packages/modules/order/src/models/exchange-item.ts b/packages/modules/order/src/models/exchange-item.ts index 9564d39b8440a..d226f85128c98 100644 --- a/packages/modules/order/src/models/exchange-item.ts +++ b/packages/modules/order/src/models/exchange-item.ts @@ -1,116 +1,44 @@ -import { BigNumberRawValue, DAL } from "@medusajs/framework/types" -import { - MikroOrmBigNumberProperty, - createPsqlIndexStatementHelper, - generateEntityId, -} from "@medusajs/framework/utils" -import { - BeforeCreate, - Entity, - ManyToOne, - OnInit, - OptionalProps, - PrimaryKey, - Property, -} from "@mikro-orm/core" +import { model } from "@medusajs/framework/utils" import Exchange from "./exchange" import OrderLineItem from "./line-item" -type OptionalLineItemProps = DAL.ModelDateColumns - -const ExchangeIdIndex = createPsqlIndexStatementHelper({ - tableName: "order_exchange_item", - columns: "exchange_id", - where: "deleted_at IS NOT NULL", -}) - -const ItemIdIndex = createPsqlIndexStatementHelper({ - tableName: "order_exchange_item", - columns: "item_id", - where: "deleted_at IS NOT NULL", -}) - -const DeletedAtIndex = createPsqlIndexStatementHelper({ - tableName: "order_claim_item_image", - columns: "deleted_at", - where: "deleted_at IS NOT NULL", -}) - -@Entity({ tableName: "order_exchange_item" }) -export default class OrderExchangeItem { - [OptionalProps]?: OptionalLineItemProps - - @PrimaryKey({ columnType: "text" }) - id: string - - @MikroOrmBigNumberProperty() - quantity: Number | number - - @Property({ columnType: "jsonb" }) - raw_quantity: BigNumberRawValue - - @ManyToOne(() => Exchange, { - columnType: "text", - fieldName: "exchange_id", - mapToPk: true, - onDelete: "cascade", - }) - @ExchangeIdIndex.MikroORMIndex() - exchange_id: string - - @ManyToOne(() => Exchange, { - persist: false, - }) - exchange: Exchange - - @ManyToOne({ - entity: () => OrderLineItem, - fieldName: "item_id", - mapToPk: true, - columnType: "text", +const ExchangeIdIndex = "IDX_order_exchange_item_exchange_id" +const ItemIdIndex = "IDX_order_exchange_item_item_id" +const DeletedAtIndex = "IDX_order_exchange_item_deleted_at" + +const OrderExchangeItem = model + .define("OrderExchangeItem", { + id: model.id({ prefix: "oexcitem" }).primaryKey(), + quantity: model.bigNumber(), + raw_quantity: model.json(), + exchange: model.belongsTo(() => Exchange, { + mappedBy: "items", + }), + item: model.belongsTo(() => OrderLineItem, { + mappedBy: "items", + }), + note: model.text().nullable(), + metadata: model.json().nullable(), }) - @ItemIdIndex.MikroORMIndex() - item_id: string - - @ManyToOne(() => OrderLineItem, { - persist: false, - }) - item: OrderLineItem - - @Property({ columnType: "text", nullable: true }) - note: string - - @Property({ columnType: "jsonb", nullable: true }) - metadata: Record | 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 }) - @DeletedAtIndex.MikroORMIndex() - deleted_at: Date | null = null - - @BeforeCreate() - onCreate() { - this.id = generateEntityId(this.id, "oexcitem") - this.exchange_id ??= this.exchange?.id - } - - @OnInit() - onInit() { - this.id = generateEntityId(this.id, "oexcitem") - this.exchange_id ??= this.exchange?.id - } -} + .indexes([ + { + name: ExchangeIdIndex, + on: ["exchange_id"], + unique: false, + where: "deleted_at IS NOT NULL", + }, + { + name: ItemIdIndex, + on: ["item_id"], + unique: false, + where: "deleted_at IS NOT NULL", + }, + { + name: DeletedAtIndex, + on: ["deleted_at"], + unique: false, + where: "deleted_at IS NOT NULL", + }, + ]) + +export default OrderExchangeItem diff --git a/packages/modules/order/src/models/exchange.ts b/packages/modules/order/src/models/exchange.ts index 34fb61abd6947..350823cdc903a 100644 --- a/packages/modules/order/src/models/exchange.ts +++ b/packages/modules/order/src/models/exchange.ts @@ -1,165 +1,69 @@ -import { BigNumberRawValue, DAL } from "@medusajs/framework/types" -import { - BigNumber, - DALUtils, - MikroOrmBigNumberProperty, - createPsqlIndexStatementHelper, - generateEntityId, -} from "@medusajs/framework/utils" -import { - BeforeCreate, - Cascade, - Collection, - Entity, - Filter, - ManyToOne, - OnInit, - OneToMany, - OneToOne, - OptionalProps, - PrimaryKey, - Property, - Rel, -} from "@mikro-orm/core" +import { model } from "@medusajs/framework/utils" import { OrderExchangeItem, OrderTransaction } from "@models" import Order from "./order" import OrderShipping from "./order-shipping-method" import Return from "./return" -type OptionalOrderExchangeProps = DAL.ModelDateColumns - -const DisplayIdIndex = createPsqlIndexStatementHelper({ - tableName: "order_exchange", - columns: "display_id", - where: "deleted_at IS NOT NULL", -}) - -const OrderExchangeDeletedAtIndex = createPsqlIndexStatementHelper({ - tableName: "order_exchange", - columns: "deleted_at", - where: "deleted_at IS NOT NULL", -}) - -const OrderIdIndex = createPsqlIndexStatementHelper({ - tableName: "order_exchange", - columns: ["order_id"], - where: "deleted_at IS NOT NULL", -}) - -const ReturnIdIndex = createPsqlIndexStatementHelper({ - tableName: "order_exchange", - columns: "return_id", - where: "return_id IS NOT NULL AND deleted_at IS NOT NULL", -}) - -@Entity({ tableName: "order_exchange" }) -@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions) -export default class OrderExchange { - [OptionalProps]?: OptionalOrderExchangeProps - - @PrimaryKey({ columnType: "text" }) - id: string - - @ManyToOne({ - entity: () => Order, - mapToPk: true, - fieldName: "order_id", - columnType: "text", - }) - @OrderIdIndex.MikroORMIndex() - order_id: string - - @ManyToOne(() => Order, { - persist: false, - }) - order: Rel - - @OneToOne({ - entity: () => Return, - mappedBy: (ret) => ret.exchange, - fieldName: "return_id", - nullable: true, - owner: true, - }) - return: Rel - - @Property({ columnType: "text", nullable: true }) - @ReturnIdIndex.MikroORMIndex() - return_id: string | null = null - - @Property({ - columnType: "integer", - }) - order_version: number - - @Property({ autoincrement: true, primary: false }) - @DisplayIdIndex.MikroORMIndex() - display_id: number - - @Property({ columnType: "boolean", nullable: true }) - no_notification: boolean | null = null - - @MikroOrmBigNumberProperty({ - nullable: true, +const DisplayIdIndex = "IDX_order_exchange_display_id" +const OrderExchangeDeletedAtIndex = "IDX_order_exchange_deleted_at" +const OrderIdIndex = "IDX_order_exchange_order_id" +const ReturnIdIndex = "IDX_order_exchange_return_id" + +const OrderExchange = model + .define("OrderExchange", { + id: model.id({ prefix: "oexc" }).primaryKey(), + order: model.belongsTo(() => Order, { + mappedBy: "exchanges", + }), + return: model + .belongsTo(() => Return, { + mappedBy: "exchange", + }) + .nullable(), + order_version: model.number(), + display_id: model.number(), + no_notification: model.boolean().nullable(), + difference_due: model.bigNumber().nullable(), + raw_difference_due: model.json(), + allow_backorder: model.boolean().default(false), + additional_items: model.hasMany(() => OrderExchangeItem, { + mappedBy: "exchange", + }), + shipping_methods: model.hasMany(() => OrderShipping, { + mappedBy: "exchange", + }), + transactions: model.hasMany(() => OrderTransaction, { + mappedBy: "exchange", + }), + created_by: model.text().nullable(), + metadata: model.json().nullable(), + canceled_at: model.dateTime().nullable(), }) - difference_due: BigNumber | number - - @Property({ columnType: "jsonb", nullable: true }) - raw_difference_due: BigNumberRawValue - - @Property({ columnType: "boolean", default: false }) - allow_backorder: boolean = false - - @OneToMany(() => OrderExchangeItem, (item) => item.exchange, { - cascade: [Cascade.PERSIST], - }) - additional_items = new Collection>(this) - - @OneToMany(() => OrderShipping, (shippingMethod) => shippingMethod.exchange, { - cascade: [Cascade.PERSIST], - }) - shipping_methods = new Collection>(this) - - @OneToMany(() => OrderTransaction, (transaction) => transaction.exchange, { - cascade: [Cascade.PERSIST], - }) - transactions = new Collection(this) - - @Property({ columnType: "text", nullable: true }) - created_by: string | null = null - - @Property({ columnType: "jsonb", nullable: true }) - metadata: Record | 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 }) - @OrderExchangeDeletedAtIndex.MikroORMIndex() - deleted_at: Date | null = null - - @Property({ columnType: "timestamptz", nullable: true }) - canceled_at: Date | null = null - - @BeforeCreate() - onCreate() { - this.id = generateEntityId(this.id, "oexc") - } - - @OnInit() - onInit() { - this.id = generateEntityId(this.id, "oexc") - } -} + .indexes([ + { + name: DisplayIdIndex, + on: ["display_id"], + unique: false, + where: "deleted_at IS NOT NULL", + }, + { + name: OrderExchangeDeletedAtIndex, + on: ["deleted_at"], + unique: false, + where: "deleted_at IS NOT NULL", + }, + { + name: OrderIdIndex, + on: ["order_id"], + unique: false, + where: "deleted_at IS NOT NULL", + }, + { + name: ReturnIdIndex, + on: ["return_id"], + unique: false, + where: "return_id IS NOT NULL AND deleted_at IS NOT NULL", + }, + ]) + +export default OrderExchange diff --git a/packages/modules/order/src/models/line-item-adjustment.ts b/packages/modules/order/src/models/line-item-adjustment.ts index 3fe70618a574b..e60a20c68c81f 100644 --- a/packages/modules/order/src/models/line-item-adjustment.ts +++ b/packages/modules/order/src/models/line-item-adjustment.ts @@ -1,42 +1,26 @@ -import { - createPsqlIndexStatementHelper, - generateEntityId, -} from "@medusajs/framework/utils" -import { BeforeCreate, Entity, ManyToOne, OnInit, Rel } from "@mikro-orm/core" -import AdjustmentLine from "./adjustment-line" +import { model } from "@medusajs/framework/utils" import OrderLineItem from "./line-item" -const ItemIdIndex = createPsqlIndexStatementHelper({ - tableName: "order_line_item_adjustment", - columns: "item_id", -}) - -@Entity({ tableName: "order_line_item_adjustment" }) -export default class OrderLineItemAdjustment extends AdjustmentLine { - @ManyToOne(() => OrderLineItem, { - persist: false, - }) - item: Rel - - @ManyToOne({ - entity: () => OrderLineItem, - columnType: "text", - fieldName: "item_id", - onDelete: "cascade", - mapToPk: true, +const OrderLineItemAdjustment = model + .define("OrderLineItemAdjustment", { + id: model.id({ prefix: "ordliadj" }).primaryKey(), + description: model.text().nullable(), + promotion_id: model.text().nullable(), + code: model.text().nullable(), + amount: model.bigNumber(), + raw_amount: model.json(), + provider_id: model.text().nullable(), + item: model.belongsTo(() => OrderLineItem, { + mappedBy: "adjustments", + }), + item_id: model.text(), }) - @ItemIdIndex.MikroORMIndex() - item_id: string - - @BeforeCreate() - onCreate() { - this.id = generateEntityId(this.id, "ordliadj") - this.item_id ??= this.item?.id - } + .indexes([ + { + name: "ItemIdIndex", + on: ["item_id"], + unique: false, + }, + ]) - @OnInit() - onInit() { - this.id = generateEntityId(this.id, "ordliadj") - this.item_id ??= this.item?.id - } -} +export default OrderLineItemAdjustment diff --git a/packages/modules/order/src/models/line-item-tax-line.ts b/packages/modules/order/src/models/line-item-tax-line.ts index 4770cb4532d82..869af50d6bf5c 100644 --- a/packages/modules/order/src/models/line-item-tax-line.ts +++ b/packages/modules/order/src/models/line-item-tax-line.ts @@ -1,50 +1,23 @@ -import { - createPsqlIndexStatementHelper, - generateEntityId, -} from "@medusajs/framework/utils" -import { - BeforeCreate, - Cascade, - Entity, - ManyToOne, - OnInit, - Rel, -} from "@mikro-orm/core" -import OrderLineItem from "./line-item" -import TaxLine from "./tax-line" +import { model } from "@medusajs/framework/utils" -const ItemIdIndex = createPsqlIndexStatementHelper({ - tableName: "order_line_item_tax_line", - columns: "item_id", -}) - -@Entity({ tableName: "order_line_item_tax_line" }) -export default class OrderLineItemTaxLine extends TaxLine { - @ManyToOne(() => OrderLineItem, { - fieldName: "item_id", - persist: false, - }) - item: Rel - - @ManyToOne({ - entity: () => OrderLineItem, - columnType: "text", - fieldName: "item_id", - cascade: [Cascade.PERSIST, Cascade.REMOVE], - mapToPk: true, +const OrderLineItemTaxLine = model + .define("OrderLineItemTaxLine", { + id: model.id({ prefix: "ordlitxl" }).primaryKey(), + description: model.text().nullable(), + tax_rate_id: model.text().nullable(), + code: model.text(), + rate: model.bigNumber(), + raw_rate: model.json(), + provider_id: model.text().nullable(), + item: model.belongsTo(() => "OrderLineItem", { mappedBy: "tax_lines" }), + item_id: model.text(), }) - @ItemIdIndex.MikroORMIndex() - item_id: string - - @BeforeCreate() - onCreate() { - this.id = generateEntityId(this.id, "ordlitxl") - this.item_id ??= this.item?.id - } + .indexes([ + { + name: "ItemIdIndex", + on: ["item_id"], + unique: false, + }, + ]) - @OnInit() - onInit() { - this.id = generateEntityId(this.id, "ordlitxl") - this.item_id ??= this.item?.id - } -} +export default OrderLineItemTaxLine diff --git a/packages/modules/order/src/models/line-item.ts b/packages/modules/order/src/models/line-item.ts index 401d00f5ffbb8..fb54486fae2d9 100644 --- a/packages/modules/order/src/models/line-item.ts +++ b/packages/modules/order/src/models/line-item.ts @@ -1,186 +1,72 @@ -import { BigNumberRawValue, DAL } from "@medusajs/framework/types" -import { - BigNumber, - DALUtils, - MikroOrmBigNumberProperty, - createPsqlIndexStatementHelper, - generateEntityId, -} from "@medusajs/framework/utils" -import { - BeforeCreate, - Cascade, - Collection, - Entity, - Filter, - OnInit, - OneToMany, - OptionalProps, - PrimaryKey, - Property, - Rel, -} from "@mikro-orm/core" +import { model } from "@medusajs/framework/utils" import OrderLineItemAdjustment from "./line-item-adjustment" import OrderLineItemTaxLine from "./line-item-tax-line" -type OptionalLineItemProps = DAL.ModelDateColumns - -const DeletedAtIndex = createPsqlIndexStatementHelper({ - tableName: "order_line_item", - columns: "deleted_at", - where: "deleted_at IS NOT NULL", -}) - -const ProductIdIndex = createPsqlIndexStatementHelper({ - tableName: "order_line_item", - columns: "product_id", - where: "deleted_at IS NOT NULL", -}) - -const ProductTypeIdIndex = createPsqlIndexStatementHelper({ - name: "IDX_line_item_product_type_id", - tableName: "order_line_item", - columns: "product_type_id", - where: "deleted_at IS NOT NULL AND product_type_id IS NOT NULL", -}).MikroORMIndex - -const VariantIdIndex = createPsqlIndexStatementHelper({ - tableName: "order_line_item", - columns: "variant_id", - where: "deleted_at IS NOT NULL", -}) - -@Entity({ tableName: "order_line_item" }) -@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions) -export default class OrderLineItem { - [OptionalProps]?: OptionalLineItemProps - - @PrimaryKey({ columnType: "text" }) - id: string - - @Property({ columnType: "text" }) - title: string - - @Property({ columnType: "text", nullable: true }) - subtitle: string | null = null - - @Property({ columnType: "text", nullable: true }) - thumbnail: string | null = null - - @Property({ - columnType: "text", - nullable: true, - }) - @VariantIdIndex.MikroORMIndex() - variant_id: string | null = null - - @Property({ - columnType: "text", - nullable: true, +const DeletedAtIndex = "IDX_order_line_item_deleted_at" +const ProductIdIndex = "IDX_order_line_item_product_id" +const ProductTypeIdIndex = "IDX_line_item_product_type_id" +const VariantIdIndex = "IDX_order_line_item_variant_id" + +const OrderLineItem = model + .define("OrderLineItem", { + id: model.id({ prefix: "ordli" }).primaryKey(), + title: model.text(), + subtitle: model.text().nullable(), + thumbnail: model.text().nullable(), + variant_id: model.text().nullable(), + product_id: model.text().nullable(), + product_title: model.text().nullable(), + product_description: model.text().nullable(), + product_subtitle: model.text().nullable(), + product_type: model.text().nullable(), + product_type_id: model.text().nullable(), + product_collection: model.text().nullable(), + product_handle: model.text().nullable(), + variant_sku: model.text().nullable(), + variant_barcode: model.text().nullable(), + variant_title: model.text().nullable(), + variant_option_values: model.json().nullable(), + requires_shipping: model.boolean().default(true), + is_discountable: model.boolean().default(true), + is_tax_inclusive: model.boolean().default(false), + compare_at_unit_price: model.bigNumber().nullable(), + raw_compare_at_unit_price: model.json().nullable(), + unit_price: model.bigNumber(), + raw_unit_price: model.json(), + is_custom_price: model.boolean().default(false), + tax_lines: model.hasMany(() => OrderLineItemTaxLine, { + mappedBy: "item", + }), + adjustments: model.hasMany(() => OrderLineItemAdjustment, { + mappedBy: "item", + }), + metadata: model.json().nullable(), }) - @ProductIdIndex.MikroORMIndex() - product_id: string | null = null - - @Property({ columnType: "text", nullable: true }) - product_title: string | null = null - - @Property({ columnType: "text", nullable: true }) - product_description: string | null = null - - @Property({ columnType: "text", nullable: true }) - product_subtitle: string | null = null - - @Property({ columnType: "text", nullable: true }) - product_type: string | null = null - - @ProductTypeIdIndex() - @Property({ columnType: "text", nullable: true }) - product_type_id: string | null = null - - @Property({ columnType: "text", nullable: true }) - product_collection: string | null = null - - @Property({ columnType: "text", nullable: true }) - product_handle: string | null = null - - @Property({ columnType: "text", nullable: true }) - variant_sku: string | null = null - - @Property({ columnType: "text", nullable: true }) - variant_barcode: string | null = null - - @Property({ columnType: "text", nullable: true }) - variant_title: string | null = null - - @Property({ columnType: "jsonb", nullable: true }) - variant_option_values: Record | null = null - - @Property({ columnType: "boolean" }) - requires_shipping: boolean = true - - @Property({ columnType: "boolean" }) - is_discountable: boolean = true - - @Property({ columnType: "boolean" }) - is_tax_inclusive: boolean = false - - @MikroOrmBigNumberProperty({ - nullable: true, - }) - compare_at_unit_price?: BigNumber | number | null = null - - @Property({ columnType: "jsonb", nullable: true }) - raw_compare_at_unit_price: BigNumberRawValue | null = null - - @MikroOrmBigNumberProperty({ - nullable: true, - }) - unit_price: BigNumber | number - - @Property({ columnType: "jsonb" }) - raw_unit_price: BigNumberRawValue - - @Property({ columnType: "boolean", default: false }) - is_custom_price: boolean = false - - @OneToMany(() => OrderLineItemTaxLine, (taxLine) => taxLine.item, { - cascade: [Cascade.PERSIST, "soft-remove" as Cascade], - }) - tax_lines = new Collection>(this) - - @OneToMany(() => OrderLineItemAdjustment, (adjustment) => adjustment.item, { - cascade: [Cascade.PERSIST, "soft-remove" as Cascade], - }) - adjustments = new Collection>(this) - - @Property({ columnType: "jsonb", nullable: true }) - metadata: Record | 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 }) - @DeletedAtIndex.MikroORMIndex() - deleted_at: Date | null = null - - @BeforeCreate() - onCreate() { - this.id = generateEntityId(this.id, "ordli") - } - - @OnInit() - onInit() { - this.id = generateEntityId(this.id, "ordli") - } -} + .indexes([ + { + name: DeletedAtIndex, + on: ["deleted_at"], + unique: false, + where: "deleted_at IS NOT NULL", + }, + { + name: ProductIdIndex, + on: ["product_id"], + unique: false, + where: "deleted_at IS NOT NULL", + }, + { + name: ProductTypeIdIndex, + on: ["product_type_id"], + unique: false, + where: "deleted_at IS NOT NULL AND product_type_id IS NOT NULL", + }, + { + name: VariantIdIndex, + on: ["variant_id"], + unique: false, + where: "deleted_at IS NOT NULL", + }, + ]) + +export default OrderLineItem diff --git a/packages/modules/order/src/models/order-change-action.ts b/packages/modules/order/src/models/order-change-action.ts index 70fb16a5e3125..9f4d39523098f 100644 --- a/packages/modules/order/src/models/order-change-action.ts +++ b/packages/modules/order/src/models/order-change-action.ts @@ -1,251 +1,75 @@ -import { BigNumberRawValue, DAL } from "@medusajs/framework/types" -import { - BigNumber, - DALUtils, - MikroOrmBigNumberProperty, - createPsqlIndexStatementHelper, - generateEntityId, -} from "@medusajs/framework/utils" -import { - BeforeCreate, - Entity, - Filter, - ManyToOne, - OnInit, - OptionalProps, - PrimaryKey, - Property, - Rel, -} from "@mikro-orm/core" -import OrderClaim from "./claim" -import OrderExchange from "./exchange" -import Order from "./order" -import OrderChange from "./order-change" -import Return from "./return" - -type OptionalLineItemProps = DAL.ModelDateColumns - -const OrderChangeIdIndex = createPsqlIndexStatementHelper({ - tableName: "order_change_action", - columns: "order_change_id", - where: "deleted_at IS NOT NULL", -}) - -const OrderIdIndex = createPsqlIndexStatementHelper({ - tableName: "order_change_action", - columns: "order_id", - where: "deleted_at IS NOT NULL", -}) - -const ReturnIdIndex = createPsqlIndexStatementHelper({ - tableName: "order_change_action", - columns: "return_id", - where: "return_id IS NOT NULL AND deleted_at IS NOT NULL", -}) - -const OrderClaimIdIndex = createPsqlIndexStatementHelper({ - tableName: "order_change_action", - columns: "claim_id", - where: "claim_id IS NOT NULL AND deleted_at IS NOT NULL", -}) - -const OrderExchangeIdIndex = createPsqlIndexStatementHelper({ - tableName: "order_change_action", - columns: "exchange_id", - where: "exchange_id IS NOT NULL AND deleted_at IS NOT NULL", -}) - -const DeletedAtIndex = createPsqlIndexStatementHelper({ - tableName: "order_change_action", - columns: "deleted_at", - where: "deleted_at IS NOT NULL", -}) - -const ActionOrderingIndex = createPsqlIndexStatementHelper({ - tableName: "order_change_action", - columns: "ordering", - where: "deleted_at IS NOT NULL", -}) - -@Entity({ tableName: "order_change_action" }) -@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions) -export default class OrderChangeAction { - [OptionalProps]?: OptionalLineItemProps - - @PrimaryKey({ columnType: "text" }) - id: string - - @Property({ columnType: "integer", autoincrement: true }) - @ActionOrderingIndex.MikroORMIndex() - ordering: number - - @ManyToOne({ - entity: () => Order, - columnType: "text", - fieldName: "order_id", - onDelete: "cascade", - mapToPk: true, - nullable: true, - }) - @OrderIdIndex.MikroORMIndex() - order_id: string | null = null - - @ManyToOne(() => Order, { - persist: false, - nullable: true, - }) - order: Rel | null = null - - @ManyToOne({ - entity: () => Return, - mapToPk: true, - fieldName: "return_id", - columnType: "text", - nullable: true, - }) - @ReturnIdIndex.MikroORMIndex() - return_id: string | null = null - - @ManyToOne(() => Return, { - persist: false, - nullable: true, - }) - return: Return - - @ManyToOne({ - entity: () => OrderClaim, - mapToPk: true, - fieldName: "claim_id", - columnType: "text", - nullable: true, - }) - @OrderClaimIdIndex.MikroORMIndex() - claim_id: string | null = null - - @ManyToOne(() => OrderClaim, { - persist: false, - nullable: true, - }) - claim: OrderClaim - - @ManyToOne({ - entity: () => OrderExchange, - mapToPk: true, - fieldName: "exchange_id", - columnType: "text", - nullable: true, - }) - @OrderExchangeIdIndex.MikroORMIndex() - exchange_id: string | null = null - - @ManyToOne(() => OrderExchange, { - persist: false, - nullable: true, - }) - exchange: OrderExchange - - @Property({ columnType: "integer", nullable: true }) - version: number | null = null - - @ManyToOne({ - entity: () => OrderChange, - columnType: "text", - fieldName: "order_change_id", - onDelete: "cascade", - mapToPk: true, - nullable: true, - }) - @OrderChangeIdIndex.MikroORMIndex() - order_change_id: string | null - - @ManyToOne(() => OrderChange, { - persist: false, - nullable: true, - }) - order_change: Rel | null = null - - @Property({ - columnType: "text", - nullable: true, - }) - reference: string | null = null - - @Property({ - columnType: "text", - nullable: true, - }) - reference_id: string | null = null - - @Property({ columnType: "text" }) - action: string - - @Property({ columnType: "jsonb" }) - details: Record = {} - - @MikroOrmBigNumberProperty({ nullable: true }) - amount: BigNumber | number | null = null - - @Property({ columnType: "jsonb", nullable: true }) - raw_amount: BigNumberRawValue | null = null - - @Property({ - columnType: "text", - nullable: true, - }) - internal_note: string | null = null - - @Property({ - columnType: "boolean", - defaultRaw: "false", - }) - applied: boolean = false - - @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, "ordchact") - this.order_id ??= this.order?.id ?? this.order_change?.order_id ?? null - this.claim_id ??= this.claim?.id ?? this.order_change?.claim_id ?? null - this.exchange_id ??= - this.exchange?.id ?? this.order_change?.exchange_id ?? null - this.order_change_id ??= this.order_change?.id ?? null - this.version ??= this.order_change?.version ?? null - - if (!this.claim_id && !this.exchange_id) { - this.return_id ??= this.return?.id ?? this.order_change?.return_id ?? null - } - } - - @OnInit() - onInit() { - this.id = generateEntityId(this.id, "ordchact") - this.order_id ??= this.order?.id ?? this.order_change?.order_id ?? null - this.claim_id ??= this.claim?.id ?? this.order_change?.claim_id ?? null - this.exchange_id ??= - this.exchange?.id ?? this.order_change?.exchange_id ?? null - this.order_change_id ??= this.order_change?.id ?? null - this.version ??= this.order_change?.version ?? null - - if (!this.claim_id && !this.exchange_id) { - this.return_id ??= this.return?.id ?? this.order_change?.return_id ?? null - } - } -} +import { model } from "@medusajs/framework/utils" + +const OrderChangeIdIndex = "IDX_order_change_action_order_change_id" +const OrderIdIndex = "IDX_order_change_action_order_id" +const ReturnIdIndex = "IDX_order_change_action_return_id" +const OrderClaimIdIndex = "IDX_order_change_action_claim_id" +const OrderExchangeIdIndex = "IDX_order_change_action_exchange_id" +const DeletedAtIndex = "IDX_order_change_action_deleted_at" +const ActionOrderingIndex = "IDX_order_change_action_ordering" + +const OrderChangeAction = model + .define("OrderChangeAction", { + id: model.id({ prefix: "ordchact" }).primaryKey(), + ordering: model.number(), + order_id: model.text().nullable(), + return_id: model.text().nullable(), + claim_id: model.text().nullable(), + exchange_id: model.text().nullable(), + version: model.number().nullable(), + order_change_id: model.text().nullable(), + reference: model.text().nullable(), + reference_id: model.text().nullable(), + action: model.text(), + details: model.json(), + amount: model.bigNumber().nullable(), + raw_amount: model.json().nullable(), + internal_note: model.text().nullable(), + applied: model.boolean().default(false), + }) + .indexes([ + { + name: OrderChangeIdIndex, + on: ["order_change_id"], + unique: false, + where: "deleted_at IS NOT NULL", + }, + { + name: OrderIdIndex, + on: ["order_id"], + unique: false, + where: "deleted_at IS NOT NULL", + }, + { + name: ReturnIdIndex, + on: ["return_id"], + unique: false, + where: "return_id IS NOT NULL AND deleted_at IS NOT NULL", + }, + { + name: OrderClaimIdIndex, + on: ["claim_id"], + unique: false, + where: "claim_id IS NOT NULL AND deleted_at IS NOT NULL", + }, + { + name: OrderExchangeIdIndex, + on: ["exchange_id"], + unique: false, + where: "exchange_id IS NOT NULL AND deleted_at IS NOT NULL", + }, + { + name: DeletedAtIndex, + on: ["deleted_at"], + unique: false, + where: "deleted_at IS NOT NULL", + }, + { + name: ActionOrderingIndex, + on: ["ordering"], + unique: false, + where: "deleted_at IS NOT NULL", + }, + ]) + +export default OrderChangeAction diff --git a/packages/modules/order/src/models/order-change.ts b/packages/modules/order/src/models/order-change.ts index efa172e7a4fef..fe0cab2199d26 100644 --- a/packages/modules/order/src/models/order-change.ts +++ b/packages/modules/order/src/models/order-change.ts @@ -1,252 +1,102 @@ -import { DAL } from "@medusajs/framework/types" -import { - createPsqlIndexStatementHelper, - DALUtils, - generateEntityId, - OrderChangeStatus, -} from "@medusajs/framework/utils" -import { - BeforeCreate, - Cascade, - Collection, - Entity, - Enum, - Filter, - ManyToOne, - OneToMany, - OnInit, - OptionalProps, - PrimaryKey, - Property, - Rel, -} from "@mikro-orm/core" -import {} from "@types" +import { model, OrderChangeStatus } from "@medusajs/framework/utils" import OrderClaim from "./claim" import OrderExchange from "./exchange" import Order from "./order" import OrderChangeAction from "./order-change-action" import Return from "./return" -type OptionalLineItemProps = DAL.ModelDateColumns - -const OrderIdIndex = createPsqlIndexStatementHelper({ - tableName: "order_change", - columns: "order_id", - where: "deleted_at IS NOT NULL", -}) - -const ReturnIdIndex = createPsqlIndexStatementHelper({ - tableName: "order_change", - columns: "return_id", - where: "return_id IS NOT NULL AND deleted_at IS NOT NULL", -}) - -const OrderClaimIdIndex = createPsqlIndexStatementHelper({ - tableName: "order_change", - columns: "claim_id", - where: "claim_id IS NOT NULL AND deleted_at IS NOT NULL", -}) - -const OrderExchangeIdIndex = createPsqlIndexStatementHelper({ - tableName: "order_change", - columns: "exchange_id", - where: "exchange_id IS NOT NULL AND deleted_at IS NOT NULL", -}) - -const OrderChangeStatusIndex = createPsqlIndexStatementHelper({ - tableName: "order_change", - columns: "status", - where: "deleted_at IS NOT NULL", -}) - -const DeletedAtIndex = createPsqlIndexStatementHelper({ - tableName: "order_change", - columns: "deleted_at", - where: "deleted_at IS NOT NULL", -}) - -const VersionIndex = createPsqlIndexStatementHelper({ - tableName: "order_change", - columns: ["order_id", "version"], - where: "deleted_at IS NOT NULL", -}) - -@Entity({ tableName: "order_change" }) -@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions) -@VersionIndex.MikroORMIndex() -export default class OrderChange { - [OptionalProps]?: OptionalLineItemProps - - @PrimaryKey({ columnType: "text" }) - id: string - - @ManyToOne({ - entity: () => Order, - columnType: "text", - fieldName: "order_id", - onDelete: "cascade", - mapToPk: true, - }) - @OrderIdIndex.MikroORMIndex() - order_id: string - - @ManyToOne(() => Order, { - persist: false, - }) - order: Rel - - @ManyToOne({ - entity: () => Return, - mapToPk: true, - fieldName: "return_id", - columnType: "text", - nullable: true, - }) - @ReturnIdIndex.MikroORMIndex() - return_id: string | null = null - - @ManyToOne(() => Return, { - persist: false, - nullable: true, - }) - return: Rel - - @ManyToOne({ - entity: () => OrderClaim, - mapToPk: true, - fieldName: "claim_id", - columnType: "text", - nullable: true, - }) - @OrderClaimIdIndex.MikroORMIndex() - claim_id: string | null = null - - @ManyToOne(() => OrderClaim, { - persist: false, - nullable: true, - }) - claim: OrderClaim - - @ManyToOne({ - entity: () => OrderExchange, - mapToPk: true, - fieldName: "exchange_id", - columnType: "text", - nullable: true, - }) - @OrderExchangeIdIndex.MikroORMIndex() - exchange_id: string | null = null - - @ManyToOne(() => OrderExchange, { - persist: false, - nullable: true, - }) - exchange: OrderExchange - - @Property({ columnType: "integer" }) - @VersionIndex.MikroORMIndex() - version: number - - @Property({ columnType: "text", nullable: true }) - change_type: string | null = null - - @OneToMany(() => OrderChangeAction, (action) => action.order_change, { - cascade: [Cascade.PERSIST, "soft-remove" as Cascade], - }) - actions = new Collection>(this) - - @Property({ - columnType: "text", - nullable: true, - }) - description: string | null = null - - @Enum({ items: () => OrderChangeStatus, default: OrderChangeStatus.PENDING }) - @OrderChangeStatusIndex.MikroORMIndex() - status: OrderChangeStatus = OrderChangeStatus.PENDING - - @Property({ columnType: "text", nullable: true }) - internal_note: string | null = null - - @Property({ columnType: "text", nullable: true }) - created_by: string // customer, user, third party, etc. - - @Property({ columnType: "text", nullable: true }) - requested_by: string | null = null // customer or user ID - - @Property({ - columnType: "timestamptz", - nullable: true, - }) - requested_at: Date | null = null - - @Property({ columnType: "text", nullable: true }) - confirmed_by: string | null = null // customer or user ID - - @Property({ - columnType: "timestamptz", - nullable: true, - }) - confirmed_at: Date | null = null - - @Property({ columnType: "text", nullable: true }) - declined_by: string | null = null // customer or user ID - - @Property({ columnType: "text", nullable: true }) - declined_reason: string | null = null - - @Property({ columnType: "jsonb", nullable: true }) - metadata: Record | null = null - - @Property({ - columnType: "timestamptz", - nullable: true, - }) - declined_at?: Date - - @Property({ columnType: "text", nullable: true }) - canceled_by: string | null = null - - @Property({ - columnType: "timestamptz", - nullable: true, - }) - canceled_at?: Date | 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 }) - @DeletedAtIndex.MikroORMIndex() - deleted_at: Date | null = null - - @BeforeCreate() - onCreate() { - this.id = generateEntityId(this.id, "ordch") - this.order_id ??= this.order?.id - this.return_id ??= this.return?.id - this.claim_id ??= this.claim?.id - this.exchange_id ??= this.exchange?.id - } - - @OnInit() - onInit() { - this.id = generateEntityId(this.id, "ordch") - this.order_id ??= this.order?.id - this.return_id ??= this.return?.id - this.claim_id ??= this.claim?.id - this.exchange_id ??= this.exchange?.id - } -} +const OrderIdIndex = "IDX_order_change_order_id" +const ReturnIdIndex = "IDX_order_change_return_id" +const OrderClaimIdIndex = "IDX_order_change_claim_id" +const OrderExchangeIdIndex = "IDX_order_change_exchange_id" +const OrderChangeStatusIndex = "IDX_order_change_status" +const DeletedAtIndex = "IDX_order_change_deleted_at" +const VersionIndex = "IDX_order_change_version" + +const OrderChange = model + .define("OrderChange", { + id: model.id({ prefix: "ordch" }).primaryKey(), + order: model.belongsTo(() => Order, { + mappedBy: "changes", + }), + return: model + .belongsTo(() => Return, { + mappedBy: "order_changes", + }) + .nullable(), + claim: model + .belongsTo(() => OrderClaim, { + mappedBy: "order_changes", + }) + .nullable(), + exchange: model + .belongsTo(() => OrderExchange, { + mappedBy: "order_changes", + }) + .nullable(), + version: model.number(), + change_type: model.text().nullable(), + actions: model.hasMany(() => OrderChangeAction, { + mappedBy: "order_change", + }), + description: model.text().nullable(), + status: model.enum(OrderChangeStatus).default(OrderChangeStatus.PENDING), + internal_note: model.text().nullable(), + created_by: model.text(), + requested_by: model.text().nullable(), + requested_at: model.dateTime().nullable(), + confirmed_by: model.text().nullable(), + confirmed_at: model.dateTime().nullable(), + declined_by: model.text().nullable(), + declined_reason: model.text().nullable(), + metadata: model.json().nullable(), + declined_at: model.dateTime().nullable(), + canceled_by: model.text().nullable(), + canceled_at: model.dateTime().nullable(), + }) + .indexes([ + { + name: OrderIdIndex, + on: ["order_id"], + unique: false, + where: "deleted_at IS NOT NULL", + }, + { + name: ReturnIdIndex, + on: ["return_id"], + unique: false, + where: "return_id IS NOT NULL AND deleted_at IS NOT NULL", + }, + { + name: OrderClaimIdIndex, + on: ["claim_id"], + unique: false, + where: "claim_id IS NOT NULL AND deleted_at IS NOT NULL", + }, + { + name: OrderExchangeIdIndex, + on: ["exchange_id"], + unique: false, + where: "exchange_id IS NOT NULL AND deleted_at IS NOT NULL", + }, + { + name: OrderChangeStatusIndex, + on: ["status"], + unique: false, + where: "deleted_at IS NOT NULL", + }, + { + name: DeletedAtIndex, + on: ["deleted_at"], + unique: false, + where: "deleted_at IS NOT NULL", + }, + { + name: VersionIndex, + on: ["order_id", "version"], + unique: false, + where: "deleted_at IS NOT NULL", + }, + ]) + +export default OrderChange diff --git a/packages/modules/order/src/models/order-item.ts b/packages/modules/order/src/models/order-item.ts index 4844274d1edf2..5988b52055ad9 100644 --- a/packages/modules/order/src/models/order-item.ts +++ b/packages/modules/order/src/models/order-item.ts @@ -1,184 +1,69 @@ -import { BigNumberRawValue, DAL } from "@medusajs/framework/types" -import { - BigNumber, - MikroOrmBigNumberProperty, - createPsqlIndexStatementHelper, - generateEntityId, -} from "@medusajs/framework/utils" -import { - BeforeCreate, - Entity, - ManyToOne, - OnInit, - OptionalProps, - PrimaryKey, - Property, - Rel, -} from "@mikro-orm/core" +import { model } from "@medusajs/framework/utils" import OrderLineItem from "./line-item" import Order from "./order" -type OptionalLineItemProps = DAL.ModelDateColumns - -const tableName = "order_item" -const OrderIdIndex = createPsqlIndexStatementHelper({ - tableName, - columns: ["order_id"], - where: "deleted_at IS NOT NULL", -}) - -const OrderVersionIndex = createPsqlIndexStatementHelper({ - tableName, - columns: ["version"], - where: "deleted_at IS NOT NULL", -}) - -const ItemIdIndex = createPsqlIndexStatementHelper({ - tableName, - columns: ["item_id"], - where: "deleted_at IS NOT NULL", -}) - -const DeletedAtIndex = createPsqlIndexStatementHelper({ - tableName, - columns: "deleted_at", - where: "deleted_at IS NOT NULL", -}) - -@Entity({ tableName }) -export default class OrderItem { - [OptionalProps]?: OptionalLineItemProps - - @PrimaryKey({ columnType: "text" }) - id: string - - @ManyToOne({ - entity: () => Order, - mapToPk: true, - fieldName: "order_id", - columnType: "text", - }) - @OrderIdIndex.MikroORMIndex() - order_id: string - - @ManyToOne(() => Order, { - persist: false, - }) - order: Rel - - @Property({ columnType: "integer" }) - @OrderVersionIndex.MikroORMIndex() - version: number - - @ManyToOne({ - entity: () => OrderLineItem, - fieldName: "item_id", - mapToPk: true, - columnType: "text", - }) - @ItemIdIndex.MikroORMIndex() - item_id: string - - @ManyToOne(() => OrderLineItem, { - persist: false, - }) - item: Rel - - @MikroOrmBigNumberProperty({ nullable: true }) - unit_price: BigNumber | number | null = null - - @Property({ columnType: "jsonb", nullable: true }) - raw_unit_price: BigNumberRawValue | null = null - - @MikroOrmBigNumberProperty({ nullable: true }) - compare_at_unit_price: BigNumber | number | null = null - - @Property({ columnType: "jsonb", nullable: true }) - raw_compare_at_unit_price: BigNumberRawValue | null = null - - @MikroOrmBigNumberProperty() - quantity: BigNumber | number - - @Property({ columnType: "jsonb" }) - raw_quantity: BigNumberRawValue - - @MikroOrmBigNumberProperty() - fulfilled_quantity: BigNumber | number = 0 - - @Property({ columnType: "jsonb" }) - raw_fulfilled_quantity: BigNumberRawValue - - @MikroOrmBigNumberProperty() - delivered_quantity: BigNumber | number = 0 - - @Property({ columnType: "jsonb" }) - raw_delivered_quantity: BigNumberRawValue - - @MikroOrmBigNumberProperty() - shipped_quantity: BigNumber | number = 0 - - @Property({ columnType: "jsonb" }) - raw_shipped_quantity: BigNumberRawValue - - @MikroOrmBigNumberProperty() - return_requested_quantity: BigNumber | number = 0 - - @Property({ columnType: "jsonb" }) - raw_return_requested_quantity: BigNumberRawValue - - @MikroOrmBigNumberProperty() - return_received_quantity: BigNumber | number = 0 - - @Property({ columnType: "jsonb" }) - raw_return_received_quantity: BigNumberRawValue - - @MikroOrmBigNumberProperty() - return_dismissed_quantity: BigNumber | number = 0 - - @Property({ columnType: "jsonb" }) - raw_return_dismissed_quantity: BigNumberRawValue - - @MikroOrmBigNumberProperty() - written_off_quantity: BigNumber | number = 0 - - @Property({ columnType: "jsonb" }) - raw_written_off_quantity: BigNumberRawValue - - @Property({ columnType: "jsonb", nullable: true }) - metadata: Record | null = null - - @Property({ - onCreate: () => new Date(), - columnType: "timestamptz", - defaultRaw: "now()", +const OrderIdIndex = "IDX_order_item_order_id" +const OrderVersionIndex = "IDX_order_item_version" +const ItemIdIndex = "IDX_order_item_item_id" +const DeletedAtIndex = "IDX_order_item_deleted_at" + +const OrderItem = model + .define("OrderItem", { + id: model.id({ prefix: "orditem" }).primaryKey(), + order: model.belongsTo(() => Order, { + mappedBy: "items", + }), + version: model.number(), + item: model.belongsTo(() => OrderLineItem, { + mappedBy: "items", + }), + unit_price: model.bigNumber().nullable(), + raw_unit_price: model.json().nullable(), + compare_at_unit_price: model.bigNumber().nullable(), + raw_compare_at_unit_price: model.json().nullable(), + quantity: model.bigNumber(), + raw_quantity: model.json(), + fulfilled_quantity: model.bigNumber().default(0), + raw_fulfilled_quantity: model.json(), + delivered_quantity: model.bigNumber().default(0), + raw_delivered_quantity: model.json(), + shipped_quantity: model.bigNumber().default(0), + raw_shipped_quantity: model.json(), + return_requested_quantity: model.bigNumber().default(0), + raw_return_requested_quantity: model.json(), + return_received_quantity: model.bigNumber().default(0), + raw_return_received_quantity: model.json(), + return_dismissed_quantity: model.bigNumber().default(0), + raw_return_dismissed_quantity: model.json(), + written_off_quantity: model.bigNumber().default(0), + raw_written_off_quantity: model.json(), + metadata: model.json().nullable(), }) - 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, "orditem") - this.order_id ??= this.order?.id - this.item_id ??= this.item?.id - this.version ??= this.order?.version - } - - @OnInit() - onInit() { - this.id = generateEntityId(this.id, "orditem") - this.order_id ??= this.order?.id - this.item_id ??= this.item?.id - this.version ??= this.order?.version - } -} + .indexes([ + { + name: OrderIdIndex, + on: ["order_id"], + unique: false, + where: "deleted_at IS NOT NULL", + }, + { + name: OrderVersionIndex, + on: ["version"], + unique: false, + where: "deleted_at IS NOT NULL", + }, + { + name: ItemIdIndex, + on: ["item_id"], + unique: false, + where: "deleted_at IS NOT NULL", + }, + { + name: DeletedAtIndex, + on: ["deleted_at"], + unique: false, + where: "deleted_at IS NOT NULL", + }, + ]) + +export default OrderItem diff --git a/packages/modules/order/src/models/order-shipping-method.ts b/packages/modules/order/src/models/order-shipping-method.ts index 98d85cb9cfaa5..319efc0b9b4fc 100644 --- a/packages/modules/order/src/models/order-shipping-method.ts +++ b/packages/modules/order/src/models/order-shipping-method.ts @@ -1,194 +1,87 @@ -import { DAL } from "@medusajs/framework/types" -import { - createPsqlIndexStatementHelper, - generateEntityId, -} from "@medusajs/framework/utils" -import { - BeforeCreate, - Entity, - ManyToOne, - OnInit, - OptionalProps, - PrimaryKey, - Property, - Rel, -} from "@mikro-orm/core" +import { model } from "@medusajs/framework/utils" import Claim from "./claim" import Exchange from "./exchange" import Order from "./order" import Return from "./return" import OrderShippingMethod from "./shipping-method" -type OptionalShippingMethodProps = DAL.ModelDateColumns - -const tableName = "order_shipping" -const OrderIdIndex = createPsqlIndexStatementHelper({ - tableName, - columns: ["order_id"], - where: "deleted_at IS NOT NULL", -}) - -const ReturnIdIndex = createPsqlIndexStatementHelper({ - tableName, - columns: "return_id", - where: "return_id IS NOT NULL AND deleted_at IS NOT NULL", -}) - -const ExchangeIdIndex = createPsqlIndexStatementHelper({ - tableName, - columns: ["exchange_id"], - where: "exchange_id IS NOT NULL AND deleted_at IS NOT NULL", -}) - -const ClaimIdIndex = createPsqlIndexStatementHelper({ - tableName, - columns: ["claim_id"], - where: "claim_id IS NOT NULL AND deleted_at IS NOT NULL", -}) - -const OrderVersionIndex = createPsqlIndexStatementHelper({ - tableName, - columns: ["version"], - where: "deleted_at IS NOT NULL", -}) - -const ItemIdIndex = createPsqlIndexStatementHelper({ - tableName, - columns: ["shipping_method_id"], - where: "deleted_at IS NOT NULL", -}) - -const DeletedAtIndex = createPsqlIndexStatementHelper({ - tableName, - columns: "deleted_at", - where: "deleted_at IS NOT NULL", -}) - -@Entity({ tableName }) -export default class OrderShipping { - [OptionalProps]?: OptionalShippingMethodProps - - @PrimaryKey({ columnType: "text" }) - id: string - - @ManyToOne({ - entity: () => Order, - mapToPk: true, - fieldName: "order_id", - columnType: "text", - }) - @OrderIdIndex.MikroORMIndex() - order_id: string - - @ManyToOne(() => Order, { - persist: false, - }) - order: Rel - - @ManyToOne({ - entity: () => Return, - mapToPk: true, - fieldName: "return_id", - columnType: "text", - nullable: true, - }) - @ReturnIdIndex.MikroORMIndex() - return_id: string | null = null - - @ManyToOne(() => Return, { - persist: false, - nullable: true, - }) - return: Rel - - @ManyToOne({ - entity: () => Exchange, - mapToPk: true, - fieldName: "exchange_id", - columnType: "text", - nullable: true, +const OrderIdIndex = "IDX_order_shipping_order_id" +const ReturnIdIndex = "IDX_order_shipping_return_id" +const ExchangeIdIndex = "IDX_order_shipping_exchange_id" +const ClaimIdIndex = "IDX_order_shipping_claim_id" +const OrderVersionIndex = "IDX_order_shipping_version" +const ItemIdIndex = "IDX_order_shipping_shipping_method_id" +const DeletedAtIndex = "IDX_order_shipping_deleted_at" + +const OrderShipping = model + .define("OrderShipping", { + id: model.id({ prefix: "ordspmv" }).primaryKey(), + order: model.belongsTo(() => Order, { + mappedBy: "shippings", + }), + return: model + .belongsTo(() => Return, { + mappedBy: "order_shippings", + }) + .nullable(), + exchange: model + .belongsTo(() => Exchange, { + mappedBy: "order_shippings", + }) + .nullable(), + claim: model + .belongsTo(() => Claim, { + mappedBy: "order_shippings", + }) + .nullable(), + version: model.number(), + shipping_method: model.belongsTo(() => OrderShippingMethod, { + mappedBy: "order_shippings", + }), }) - @ExchangeIdIndex.MikroORMIndex() - exchange_id: string | null - - @ManyToOne(() => Exchange, { - persist: false, - nullable: true, - }) - exchange: Rel - - @ManyToOne({ - entity: () => Claim, - mapToPk: true, - fieldName: "claim_id", - columnType: "text", - nullable: true, - }) - @ClaimIdIndex.MikroORMIndex() - claim_id: string | null - - @ManyToOne(() => Claim, { - persist: false, - nullable: true, - }) - claim: Rel - - @Property({ columnType: "integer" }) - @OrderVersionIndex.MikroORMIndex() - version: number - - @ManyToOne({ - entity: () => OrderShippingMethod, - fieldName: "shipping_method_id", - mapToPk: true, - columnType: "text", - }) - @ItemIdIndex.MikroORMIndex() - shipping_method_id: string - - @ManyToOne(() => OrderShippingMethod, { - persist: false, - }) - shipping_method: Rel - - @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, "ordspmv") - this.order_id ??= this.order?.id - this.return_id ??= this.return?.id - this.claim_id ??= this.claim?.id - this.exchange_id ??= this.exchange?.id - this.shipping_method_id ??= this.shipping_method?.id - this.version ??= this.order?.version - } - - @OnInit() - onInit() { - this.id = generateEntityId(this.id, "ordspmv") - this.order_id ??= this.order?.id - this.return_id ??= this.return?.id - this.claim_id ??= this.claim?.id - this.exchange_id ??= this.exchange?.id - this.shipping_method_id ??= this.shipping_method?.id - this.version ??= this.order?.version - } -} + .indexes([ + { + name: OrderIdIndex, + on: ["order_id"], + unique: false, + where: "deleted_at IS NOT NULL", + }, + { + name: ReturnIdIndex, + on: ["return_id"], + unique: false, + where: "return_id IS NOT NULL AND deleted_at IS NOT NULL", + }, + { + name: ExchangeIdIndex, + on: ["exchange_id"], + unique: false, + where: "exchange_id IS NOT NULL AND deleted_at IS NOT NULL", + }, + { + name: ClaimIdIndex, + on: ["claim_id"], + unique: false, + where: "claim_id IS NOT NULL AND deleted_at IS NOT NULL", + }, + { + name: OrderVersionIndex, + on: ["version"], + unique: false, + where: "deleted_at IS NOT NULL", + }, + { + name: ItemIdIndex, + on: ["shipping_method_id"], + unique: false, + where: "deleted_at IS NOT NULL", + }, + { + name: DeletedAtIndex, + on: ["deleted_at"], + unique: false, + where: "deleted_at IS NOT NULL", + }, + ]) + +export default OrderShipping diff --git a/packages/modules/order/src/models/order-summary.ts b/packages/modules/order/src/models/order-summary.ts index dd843b9d7f2bc..2d9fe5fe45d13 100644 --- a/packages/modules/order/src/models/order-summary.ts +++ b/packages/modules/order/src/models/order-summary.ts @@ -1,112 +1,31 @@ -import { - BigNumber, - createPsqlIndexStatementHelper, - generateEntityId, -} from "@medusajs/framework/utils" -import { - BeforeCreate, - Entity, - ManyToOne, - OnInit, - PrimaryKey, - Property, - Rel, -} from "@mikro-orm/core" +import { model } from "@medusajs/framework/utils" import Order from "./order" -type OrderSummaryTotals = { - total: BigNumber - subtotal: BigNumber - total_tax: BigNumber - - ordered_total: BigNumber - fulfilled_total: BigNumber - returned_total: BigNumber - return_request_total: BigNumber - write_off_total: BigNumber - projected_total: BigNumber - - net_total: BigNumber - net_subtotal: BigNumber - net_total_tax: BigNumber - - balance: BigNumber - - paid_total: BigNumber - refunded_total: BigNumber -} - -const tableName = "order_summary" - -const OrderIdVersionIndex = createPsqlIndexStatementHelper({ - tableName, - columns: ["order_id", "version"], - where: "deleted_at IS NOT NULL", -}) - -const DeletedAtIndex = createPsqlIndexStatementHelper({ - tableName, - columns: "deleted_at", - where: "deleted_at IS NOT NULL", -}) - -@Entity({ tableName }) -@OrderIdVersionIndex.MikroORMIndex() -export default class OrderSummary { - @PrimaryKey({ columnType: "text" }) - id: string - - @ManyToOne({ - entity: () => Order, - columnType: "text", - fieldName: "order_id", - mapToPk: true, - onDelete: "cascade", - }) - order_id: string - - @ManyToOne(() => Order, { - persist: false, +const OrderIdVersionIndex = "IDX_order_summary_order_id_version" +const DeletedAtIndex = "IDX_order_summary_deleted_at" + +const OrderSummary = model + .define("OrderSummary", { + id: model.id({ prefix: "ordsum" }).primaryKey(), + order: model.belongsTo(() => Order, { + mappedBy: "summaries", + }), + version: model.number().default(1), + totals: model.json(), }) - order: Rel - - @Property({ - columnType: "integer", - defaultRaw: "1", - }) - version: number = 1 - - @Property({ columnType: "jsonb" }) - totals: OrderSummaryTotals | null = {} as OrderSummaryTotals - - @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, "ordsum") - this.order_id ??= this.order?.id - } - - @OnInit() - onInit() { - this.id = generateEntityId(this.id, "ordsum") - this.order_id ??= this.order?.id - } -} + .indexes([ + { + name: OrderIdVersionIndex, + on: ["order_id", "version"], + unique: false, + where: "deleted_at IS NOT NULL", + }, + { + name: DeletedAtIndex, + on: ["deleted_at"], + unique: false, + where: "deleted_at IS NOT NULL", + }, + ]) + +export default OrderSummary diff --git a/packages/modules/order/src/models/order.ts b/packages/modules/order/src/models/order.ts index 283e60fcec940..6c42ba0fef196 100644 --- a/packages/modules/order/src/models/order.ts +++ b/packages/modules/order/src/models/order.ts @@ -1,224 +1,111 @@ -import { DAL } from "@medusajs/framework/types" -import { - OrderStatus, - Searchable, - createPsqlIndexStatementHelper, - generateEntityId, -} from "@medusajs/framework/utils" -import { - BeforeCreate, - Cascade, - Collection, - Entity, - Enum, - ManyToOne, - OnInit, - OneToMany, - OptionalProps, - PrimaryKey, - Property, - Rel, -} from "@mikro-orm/core" +import { model, OrderStatus } from "@medusajs/framework/utils" import OrderAddress from "./address" import OrderItem from "./order-item" import OrderShipping from "./order-shipping-method" import OrderSummary from "./order-summary" import OrderTransaction from "./transaction" -type OptionalOrderProps = - | "shipping_address" - | "billing_address" - | DAL.ModelDateColumns - -const DisplayIdIndex = createPsqlIndexStatementHelper({ - tableName: "order", - columns: "display_id", - where: "deleted_at IS NOT NULL", -}) - -const RegionIdIndex = createPsqlIndexStatementHelper({ - tableName: "order", - columns: "region_id", - where: "deleted_at IS NOT NULL", -}) - -const CustomerIdIndex = createPsqlIndexStatementHelper({ - tableName: "order", - columns: "customer_id", - where: "deleted_at IS NOT NULL", -}) - -const SalesChannelIdIndex = createPsqlIndexStatementHelper({ - tableName: "order", - columns: "customer_id", - where: "deleted_at IS NOT NULL", -}) - -const OrderDeletedAtIndex = createPsqlIndexStatementHelper({ - tableName: "order", - columns: "deleted_at", - where: "deleted_at IS NOT NULL", -}) - -const CurrencyCodeIndex = createPsqlIndexStatementHelper({ - tableName: "order", - columns: "currency_code", - where: "deleted_at IS NOT NULL", -}) - -const ShippingAddressIdIndex = createPsqlIndexStatementHelper({ - tableName: "order", - columns: "shipping_address_id", - where: "deleted_at IS NOT NULL", -}) - -const BillingAddressIdIndex = createPsqlIndexStatementHelper({ - tableName: "order", - columns: "billing_address_id", - where: "deleted_at IS NOT NULL", -}) - -const IsDraftOrderIndex = createPsqlIndexStatementHelper({ - tableName: "order", - columns: "is_draft_order", - where: "deleted_at IS NOT NULL", -}) - -@Entity({ tableName: "order" }) -export default class Order { - [OptionalProps]?: OptionalOrderProps - - @PrimaryKey({ columnType: "text" }) - id: string - - @Searchable() - @Property({ autoincrement: true, primary: false }) - @DisplayIdIndex.MikroORMIndex() - display_id: number - - @Property({ - columnType: "text", - nullable: true, - }) - @RegionIdIndex.MikroORMIndex() - region_id: string | null = null - - @Property({ - columnType: "text", - nullable: true, - }) - @CustomerIdIndex.MikroORMIndex() - customer_id: string | null = null - - @Property({ - columnType: "integer", - defaultRaw: "1", - }) - version: number = 1 - - @Property({ - columnType: "text", - nullable: true, - }) - @SalesChannelIdIndex.MikroORMIndex() - sales_channel_id: string | null = null - - @Enum({ items: () => OrderStatus, default: OrderStatus.PENDING }) - status: OrderStatus - - @Property({ - columnType: "boolean", - }) - @IsDraftOrderIndex.MikroORMIndex() - is_draft_order: boolean = false - - @Searchable() - @Property({ columnType: "text", nullable: true }) - email: string | null = null - - @Property({ columnType: "text" }) - @CurrencyCodeIndex.MikroORMIndex() - currency_code: string - - @Property({ columnType: "text", nullable: true }) - @ShippingAddressIdIndex.MikroORMIndex() - shipping_address_id?: string | null - - @ManyToOne({ - entity: () => OrderAddress, - fieldName: "shipping_address_id", - nullable: true, - cascade: [Cascade.PERSIST], - }) - shipping_address?: Rel | null - - @Property({ columnType: "text", nullable: true }) - @BillingAddressIdIndex.MikroORMIndex() - billing_address_id?: string | null - - @ManyToOne({ - entity: () => OrderAddress, - fieldName: "billing_address_id", - nullable: true, - cascade: [Cascade.PERSIST], - }) - billing_address?: Rel | null - - @Property({ columnType: "boolean", nullable: true }) - no_notification: boolean | null = null - - @OneToMany(() => OrderSummary, (summary) => summary.order, { - cascade: [Cascade.PERSIST], - }) - summary = new Collection>(this) - - @Property({ columnType: "jsonb", nullable: true }) - metadata: Record | null = null - - @OneToMany(() => OrderItem, (itemDetail) => itemDetail.order, { - cascade: [Cascade.PERSIST], +const DisplayIdIndex = "IDX_order_display_id" +const RegionIdIndex = "IDX_order_region_id" +const CustomerIdIndex = "IDX_order_customer_id" +const SalesChannelIdIndex = "IDX_order_sales_channel_id" +const OrderDeletedAtIndex = "IDX_order_deleted_at" +const CurrencyCodeIndex = "IDX_order_currency_code" +const ShippingAddressIdIndex = "IDX_order_shipping_address_id" +const BillingAddressIdIndex = "IDX_order_billing_address_id" +const IsDraftOrderIndex = "IDX_order_is_draft_order" + +const Order = model + .define("Order", { + id: model.id({ prefix: "order" }).primaryKey(), + display_id: model.number(), // TODO: numberic .searchable() + region_id: model.text().nullable(), + customer_id: model.text().nullable(), + version: model.number().default(1), + sales_channel_id: model.text().nullable(), + status: model.enum(OrderStatus).default(OrderStatus.PENDING), + is_draft_order: model.boolean().default(false), + email: model.text().searchable().nullable(), + currency_code: model.text(), + shipping_address_id: model.text().nullable(), + shipping_address: model.belongsTo(() => OrderAddress, { + mappedBy: "shipping_orders", + }), + billing_address_id: model.text().nullable(), + billing_address: model.belongsTo(() => OrderAddress, { + mappedBy: "billing_orders", + }), + no_notification: model.boolean().nullable(), + summary: model.hasMany(() => OrderSummary, { + mappedBy: "order", + }), + metadata: model.json().nullable(), + items: model.hasMany(() => OrderItem, { + mappedBy: "order", + }), + shipping_methods: model.hasMany(() => OrderShipping, { + mappedBy: "order", + }), + transactions: model.hasMany(() => OrderTransaction, { + mappedBy: "order", + }), + canceled_at: model.dateTime().nullable(), }) - items = new Collection>(this) - - @OneToMany(() => OrderShipping, (shippingMethod) => shippingMethod.order, { - cascade: [Cascade.PERSIST], - }) - shipping_methods = new Collection>(this) - - @OneToMany(() => OrderTransaction, (transaction) => transaction.order, { - cascade: [Cascade.PERSIST], - }) - transactions = new Collection>(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 - - @Property({ columnType: "timestamptz", nullable: true }) - @OrderDeletedAtIndex.MikroORMIndex() - deleted_at: Date | null = null - - @Property({ columnType: "timestamptz", nullable: true }) - canceled_at: Date | null = null - - @BeforeCreate() - onCreate() { - this.id = generateEntityId(this.id, "order") - } - - @OnInit() - onInit() { - this.id = generateEntityId(this.id, "order") - } -} + .indexes([ + { + name: DisplayIdIndex, + on: ["display_id"], + unique: false, + where: "deleted_at IS NOT NULL", + }, + { + name: RegionIdIndex, + on: ["region_id"], + unique: false, + where: "deleted_at IS NOT NULL", + }, + { + name: CustomerIdIndex, + on: ["customer_id"], + unique: false, + where: "deleted_at IS NOT NULL", + }, + { + name: SalesChannelIdIndex, + on: ["sales_channel_id"], + unique: false, + where: "deleted_at IS NOT NULL", + }, + { + name: OrderDeletedAtIndex, + on: ["deleted_at"], + unique: false, + where: "deleted_at IS NOT NULL", + }, + { + name: CurrencyCodeIndex, + on: ["currency_code"], + unique: false, + where: "deleted_at IS NOT NULL", + }, + { + name: ShippingAddressIdIndex, + on: ["shipping_address_id"], + unique: false, + where: "deleted_at IS NOT NULL", + }, + { + name: BillingAddressIdIndex, + on: ["billing_address_id"], + unique: false, + where: "deleted_at IS NOT NULL", + }, + { + name: IsDraftOrderIndex, + on: ["is_draft_order"], + unique: false, + where: "deleted_at IS NOT NULL", + }, + ]) + +export default Order diff --git a/packages/modules/order/src/models/return-item.ts b/packages/modules/order/src/models/return-item.ts index a0e78dd9d6b64..fde30bd001996 100644 --- a/packages/modules/order/src/models/return-item.ts +++ b/packages/modules/order/src/models/return-item.ts @@ -1,150 +1,61 @@ -import { BigNumberRawValue, DAL } from "@medusajs/framework/types" -import { - MikroOrmBigNumberProperty, - createPsqlIndexStatementHelper, - generateEntityId, -} from "@medusajs/framework/utils" -import { - BeforeCreate, - Entity, - ManyToOne, - OnInit, - OptionalProps, - PrimaryKey, - Property, -} from "@mikro-orm/core" +import { model } from "@medusajs/framework/utils" import OrderLineItem from "./line-item" import Return from "./return" import ReturnReason from "./return-reason" -type OptionalLineItemProps = DAL.ModelDateColumns - -const tableName = "return_item" -const ReturnIdIndex = createPsqlIndexStatementHelper({ - tableName, - columns: "return_id", - where: "deleted_at IS NOT NULL", -}) - -const ReturnReasonIdIndex = createPsqlIndexStatementHelper({ - tableName, - columns: "reason_id", - where: "deleted_at IS NOT NULL", -}) - -const ItemIdIndex = createPsqlIndexStatementHelper({ - tableName, - columns: "item_id", - where: "deleted_at IS NOT NULL", -}) - -const DeletedAtIndex = createPsqlIndexStatementHelper({ - tableName, - columns: "deleted_at", - where: "deleted_at IS NOT NULL", -}) - -@Entity({ tableName }) -export default class ReturnItem { - [OptionalProps]?: OptionalLineItemProps - - @PrimaryKey({ columnType: "text" }) - id: string - - @ManyToOne(() => ReturnReason, { - columnType: "text", - fieldName: "reason_id", - mapToPk: true, - nullable: true, - }) - @ReturnReasonIdIndex.MikroORMIndex() - reason_id: string | null = null - - @ManyToOne(() => ReturnReason, { - persist: false, - }) - reason: ReturnReason - - @MikroOrmBigNumberProperty() - quantity: Number | number - - @Property({ columnType: "jsonb" }) - raw_quantity: BigNumberRawValue - - @MikroOrmBigNumberProperty() - received_quantity: Number | number = 0 - - @Property({ columnType: "jsonb" }) - raw_received_quantity: BigNumberRawValue - - @MikroOrmBigNumberProperty() - damaged_quantity: Number | number = 0 - - @Property({ columnType: "jsonb" }) - raw_damaged_quantity: BigNumberRawValue - - @ManyToOne(() => Return, { - columnType: "text", - fieldName: "return_id", - mapToPk: true, - onDelete: "cascade", - }) - @ReturnIdIndex.MikroORMIndex() - return_id: string - - @ManyToOne(() => Return, { - persist: false, - }) - return: Return - - @ManyToOne({ - entity: () => OrderLineItem, - fieldName: "item_id", - mapToPk: true, - columnType: "text", - }) - @ItemIdIndex.MikroORMIndex() - item_id: string - - @ManyToOne(() => OrderLineItem, { - persist: false, - }) - item: OrderLineItem - - @Property({ columnType: "text", nullable: true }) - note: string - - @Property({ columnType: "jsonb", nullable: true }) - metadata: Record | 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 }) - @DeletedAtIndex.MikroORMIndex() - deleted_at: Date | null = null - - @BeforeCreate() - onCreate() { - this.id = generateEntityId(this.id, "retitem") - this.return_id ??= this.return?.id - } - - @OnInit() - onInit() { - this.id = generateEntityId(this.id, "retitem") - this.return_id ??= this.return?.id - } -} +const ReturnIdIndex = "IDX_return_item_return_id" +const ReturnReasonIdIndex = "IDX_return_item_reason_id" +const ItemIdIndex = "IDX_return_item_item_id" +const DeletedAtIndex = "IDX_return_item_deleted_at" + +const ReturnItem = model + .define("ReturnItem", { + id: model.id({ prefix: "retitem" }).primaryKey(), + reason: model + .belongsTo(() => ReturnReason, { + mappedBy: "return_items", + }) + .nullable(), + quantity: model.bigNumber(), + raw_quantity: model.json(), + received_quantity: model.bigNumber().default(0), + raw_received_quantity: model.json(), + damaged_quantity: model.bigNumber().default(0), + raw_damaged_quantity: model.json(), + return: model.belongsTo(() => Return, { + mappedBy: "return_items", + }), + item: model.belongsTo(() => OrderLineItem, { + mappedBy: "return_items", + }), + note: model.text().nullable(), + metadata: model.json().nullable(), + }) + .indexes([ + { + name: ReturnIdIndex, + on: ["return_id"], + unique: false, + where: "deleted_at IS NOT NULL", + }, + { + name: ReturnReasonIdIndex, + on: ["reason_id"], + unique: false, + where: "deleted_at IS NOT NULL", + }, + { + name: ItemIdIndex, + on: ["item_id"], + unique: false, + where: "deleted_at IS NOT NULL", + }, + { + name: DeletedAtIndex, + on: ["deleted_at"], + unique: false, + where: "deleted_at IS NOT NULL", + }, + ]) + +export default ReturnItem diff --git a/packages/modules/order/src/models/return-reason.ts b/packages/modules/order/src/models/return-reason.ts index 9bd52a28a04aa..c679b3d6a49b6 100644 --- a/packages/modules/order/src/models/return-reason.ts +++ b/packages/modules/order/src/models/return-reason.ts @@ -1,111 +1,43 @@ -import { DAL } from "@medusajs/framework/types" -import { - DALUtils, - Searchable, - createPsqlIndexStatementHelper, - generateEntityId, -} from "@medusajs/framework/utils" -import { - BeforeCreate, - Cascade, - Entity, - Filter, - ManyToOne, - OnInit, - OneToMany, - OptionalProps, - PrimaryKey, - Property, - Rel, -} from "@mikro-orm/core" - -const DeletedAtIndex = createPsqlIndexStatementHelper({ - tableName: "return_reason", - columns: "deleted_at", - where: "deleted_at IS NOT NULL", -}) - -const ValueIndex = createPsqlIndexStatementHelper({ - tableName: "return_reason", - columns: "value", - where: "deleted_at IS NOT NULL", -}) - -const ParentIndex = createPsqlIndexStatementHelper({ - tableName: "return_reason", - columns: "parent_return_reason_id", - where: "deleted_at IS NOT NULL", -}) - -type OptionalOrderProps = "parent_return_reason" | DAL.ModelDateColumns - -@Entity({ tableName: "return_reason" }) -@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions) -export default class ReturnReason { - [OptionalProps]?: OptionalOrderProps - - @PrimaryKey({ columnType: "text" }) - id: string - - @Searchable() - @Property({ columnType: "text" }) - @ValueIndex.MikroORMIndex() - value: string - - @Searchable() - @Property({ columnType: "text" }) - label: string - - @Property({ columnType: "text", nullable: true }) - description: string | null = null - - @Property({ columnType: "text", nullable: true }) - @ParentIndex.MikroORMIndex() - parent_return_reason_id?: string | null - - @ManyToOne({ - entity: () => ReturnReason, - fieldName: "parent_return_reason_id", - nullable: true, - cascade: [Cascade.PERSIST], +import { model } from "@medusajs/framework/utils" + +const DeletedAtIndex = "IDX_return_reason_deleted_at" +const ValueIndex = "IDX_return_reason_value" +const ParentIndex = "IDX_return_reason_parent_return_reason_id" + +const ReturnReason = model + .define("ReturnReason", { + id: model.id({ prefix: "rr" }).primaryKey(), + value: model.text().searchable(), + label: model.text().searchable(), + description: model.text().nullable(), + parent_return_reason_id: model.text().nullable(), + parent_return_reason: model.belongsTo(() => ReturnReason, { + mappedBy: "return_reason_children", + }), + return_reason_children: model.hasMany(() => ReturnReason, { + mappedBy: "parent_return_reason", + }), + metadata: model.json().nullable(), }) - parent_return_reason?: Rel | null - @OneToMany( - () => ReturnReason, - (return_reason) => return_reason.parent_return_reason, - { cascade: [Cascade.PERSIST] } - ) - return_reason_children: Rel[] - - @Property({ columnType: "jsonb", nullable: true }) - metadata: Record | 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 }) - @DeletedAtIndex.MikroORMIndex() - deleted_at: Date | null = null - - @BeforeCreate() - onCreate() { - this.id = generateEntityId(this.id, "rr") - } - - @OnInit() - onInit() { - this.id = generateEntityId(this.id, "rr") - } -} + .indexes([ + { + name: DeletedAtIndex, + on: ["deleted_at"], + unique: false, + where: "deleted_at IS NOT NULL", + }, + { + name: ValueIndex, + on: ["value"], + unique: false, + where: "deleted_at IS NOT NULL", + }, + { + name: ParentIndex, + on: ["parent_return_reason_id"], + unique: false, + where: "deleted_at IS NOT NULL", + }, + ]) + +export default ReturnReason diff --git a/packages/modules/order/src/models/return.ts b/packages/modules/order/src/models/return.ts index 65bfaf42012a4..d8f76eb5ce7a7 100644 --- a/packages/modules/order/src/models/return.ts +++ b/packages/modules/order/src/models/return.ts @@ -1,192 +1,83 @@ -import { BigNumberRawValue, DAL } from "@medusajs/framework/types" -import { - BigNumber, - DALUtils, - MikroOrmBigNumberProperty, - ReturnStatus, - createPsqlIndexStatementHelper, - generateEntityId, -} from "@medusajs/framework/utils" -import { - BeforeCreate, - Cascade, - Collection, - Entity, - Enum, - Filter, - ManyToOne, - OnInit, - OneToMany, - OneToOne, - OptionalProps, - PrimaryKey, - Property, - Rel, -} from "@mikro-orm/core" +import { model, ReturnStatus } from "@medusajs/framework/utils" import { OrderTransaction, ReturnItem } from "@models" import Claim from "./claim" import Exchange from "./exchange" import Order from "./order" import OrderShipping from "./order-shipping-method" -type OptionalReturnProps = DAL.ModelDateColumns - -const DisplayIdIndex = createPsqlIndexStatementHelper({ - tableName: "return", - columns: "display_id", - where: "deleted_at IS NOT NULL", -}) - -const ReturnDeletedAtIndex = createPsqlIndexStatementHelper({ - tableName: "return", - columns: "deleted_at", - where: "deleted_at IS NOT NULL", -}) - -const OrderIdIndex = createPsqlIndexStatementHelper({ - tableName: "return", - columns: ["order_id"], - where: "deleted_at IS NOT NULL", -}) - -const ExchangeIdIndex = createPsqlIndexStatementHelper({ - tableName: "return", - columns: ["exchange_id"], - where: "exchange_id IS NOT NULL AND deleted_at IS NOT NULL", -}) - -const ClaimIdIndex = createPsqlIndexStatementHelper({ - tableName: "return", - columns: ["claim_id"], - where: "claim_id IS NOT NULL AND deleted_at IS NOT NULL", -}) - -@Entity({ tableName: "return" }) -@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions) -export default class Return { - [OptionalProps]?: OptionalReturnProps - - @PrimaryKey({ columnType: "text" }) - id: string - - @ManyToOne({ - entity: () => Order, - mapToPk: true, - fieldName: "order_id", - columnType: "text", - }) - @OrderIdIndex.MikroORMIndex() - order_id: string - - @ManyToOne(() => Order, { - persist: false, - }) - order: Rel - - @OneToOne({ - entity: () => Exchange, - fieldName: "exchange_id", - nullable: true, - }) - exchange: Rel - - @Property({ columnType: "text", nullable: true }) - @ExchangeIdIndex.MikroORMIndex() - exchange_id: string | null = null - - @OneToOne({ - entity: () => Claim, - fieldName: "claim_id", - nullable: true, +const DisplayIdIndex = "IDX_return_display_id" +const ReturnDeletedAtIndex = "IDX_return_deleted_at" +const OrderIdIndex = "IDX_return_order_id" +const ExchangeIdIndex = "IDX_return_exchange_id" +const ClaimIdIndex = "IDX_return_claim_id" + +const Return = model + .define("Return", { + id: model.id({ prefix: "return" }).primaryKey(), + order: model.belongsTo(() => Order, { + mappedBy: "returns", + }), + exchange_id: model.text().nullable(), + exchange: model.belongsTo(() => Exchange, { + mappedBy: "return", + }), + claim_id: model.text().nullable(), + claim: model.belongsTo(() => Claim, { + mappedBy: "return", + }), + order_version: model.number(), + display_id: model.number(), + status: model.enum(ReturnStatus).default(ReturnStatus.OPEN), + location_id: model.text().nullable(), + no_notification: model.boolean().nullable(), + refund_amount: model.bigNumber().nullable(), + raw_refund_amount: model.json(), + items: model.hasMany(() => ReturnItem, { + mappedBy: "return", + }), + shipping_methods: model.hasMany(() => OrderShipping, { + mappedBy: "return", + }), + transactions: model.hasMany(() => OrderTransaction, { + mappedBy: "return", + }), + created_by: model.text().nullable(), + metadata: model.json().nullable(), + requested_at: model.dateTime().nullable(), + received_at: model.dateTime().nullable(), + canceled_at: model.dateTime().nullable(), }) - claim: Rel - - @Property({ columnType: "text", nullable: true }) - @ClaimIdIndex.MikroORMIndex() - claim_id: string | null = null - - @Property({ - columnType: "integer", - }) - order_version: number - - @Property({ autoincrement: true, primary: false }) - @DisplayIdIndex.MikroORMIndex() - display_id: number - - @Enum({ items: () => ReturnStatus, default: ReturnStatus.OPEN }) - status: ReturnStatus = ReturnStatus.OPEN - - @Property({ columnType: "text", nullable: true }) - location_id: string | null = null - - @Property({ columnType: "boolean", nullable: true }) - no_notification: boolean | null = null - - @MikroOrmBigNumberProperty({ - nullable: true, - }) - refund_amount: BigNumber | number - - @Property({ columnType: "jsonb", nullable: true }) - raw_refund_amount: BigNumberRawValue - - @OneToMany(() => ReturnItem, (itemDetail) => itemDetail.return, { - cascade: [Cascade.PERSIST], - }) - items = new Collection>(this) - - @OneToMany(() => OrderShipping, (shippingMethod) => shippingMethod.return, { - cascade: [Cascade.PERSIST], - }) - shipping_methods = new Collection(this) - - @OneToMany(() => OrderTransaction, (transaction) => transaction.return, { - cascade: [Cascade.PERSIST], - }) - transactions = new Collection(this) - - @Property({ columnType: "text", nullable: true }) - created_by: string | null = null - - @Property({ columnType: "jsonb", nullable: true }) - metadata: Record | 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 }) - @ReturnDeletedAtIndex.MikroORMIndex() - deleted_at: Date | null = null - - @Property({ columnType: "timestamptz", nullable: true }) - requested_at: Date | null = null - - @Property({ columnType: "timestamptz", nullable: true }) - received_at: Date | null = null - - @Property({ columnType: "timestamptz", nullable: true }) - canceled_at: Date | null = null - - @BeforeCreate() - onCreate() { - this.id = generateEntityId(this.id, "return") - } - - @OnInit() - onInit() { - this.id = generateEntityId(this.id, "return") - } -} + .indexes([ + { + name: DisplayIdIndex, + on: ["display_id"], + unique: false, + where: "deleted_at IS NOT NULL", + }, + { + name: ReturnDeletedAtIndex, + on: ["deleted_at"], + unique: false, + where: "deleted_at IS NOT NULL", + }, + { + name: OrderIdIndex, + on: ["order_id"], + unique: false, + where: "deleted_at IS NOT NULL", + }, + { + name: ExchangeIdIndex, + on: ["exchange_id"], + unique: false, + where: "exchange_id IS NOT NULL AND deleted_at IS NOT NULL", + }, + { + name: ClaimIdIndex, + on: ["claim_id"], + unique: false, + where: "claim_id IS NOT NULL AND deleted_at IS NOT NULL", + }, + ]) + +export default Return diff --git a/packages/modules/order/src/models/shipping-method-adjustment.ts b/packages/modules/order/src/models/shipping-method-adjustment.ts index 525869435598e..5c57f255a7e07 100644 --- a/packages/modules/order/src/models/shipping-method-adjustment.ts +++ b/packages/modules/order/src/models/shipping-method-adjustment.ts @@ -1,42 +1,26 @@ -import { - createPsqlIndexStatementHelper, - generateEntityId, -} from "@medusajs/framework/utils" -import { BeforeCreate, Entity, ManyToOne, OnInit, Rel } from "@mikro-orm/core" -import AdjustmentLine from "./adjustment-line" +import { model } from "@medusajs/framework/utils" import OrderShippingMethod from "./shipping-method" -const ShippingMethodIdIdIndex = createPsqlIndexStatementHelper({ - tableName: "order_shipping_method_adjustment", - columns: "shipping_method_id", -}) - -@Entity({ tableName: "order_shipping_method_adjustment" }) -export default class OrderShippingMethodAdjustment extends AdjustmentLine { - @ManyToOne(() => OrderShippingMethod, { - persist: false, - }) - shipping_method: Rel - - @ManyToOne({ - entity: () => OrderShippingMethod, - columnType: "text", - fieldName: "shipping_method_id", - mapToPk: true, - onDelete: "cascade", +const OrderShippingMethodAdjustment = model + .define("OrderShippingMethodAdjustment", { + id: model.id({ prefix: "ordsmadj" }).primaryKey(), + description: model.text().nullable(), + promotion_id: model.text().nullable(), + code: model.text().nullable(), + amount: model.bigNumber(), + raw_amount: model.json(), + provider_id: model.text().nullable(), + shipping_method: model.belongsTo(() => OrderShippingMethod, { + mappedBy: "adjustments", + }), + shipping_method_id: model.text(), }) - @ShippingMethodIdIdIndex.MikroORMIndex() - shipping_method_id: string - - @BeforeCreate() - onCreate() { - this.id = generateEntityId(this.id, "ordsmadj") - this.shipping_method_id ??= this.shipping_method?.id - } + .indexes([ + { + name: "ShippingMethodIdIdIndex", + on: ["shipping_method_id"], + unique: false, + }, + ]) - @OnInit() - onInit() { - this.id = generateEntityId(this.id, "ordsmadj") - this.shipping_method_id ??= this.shipping_method?.id - } -} +export default OrderShippingMethodAdjustment diff --git a/packages/modules/order/src/models/shipping-method-tax-line.ts b/packages/modules/order/src/models/shipping-method-tax-line.ts index 1afba00809bdb..43e134cb04b7a 100644 --- a/packages/modules/order/src/models/shipping-method-tax-line.ts +++ b/packages/modules/order/src/models/shipping-method-tax-line.ts @@ -1,42 +1,28 @@ -import { - createPsqlIndexStatementHelper, - generateEntityId, -} from "@medusajs/framework/utils" -import { BeforeCreate, Entity, ManyToOne, OnInit, Rel } from "@mikro-orm/core" +import { model } from "@medusajs/framework/utils" import OrderShippingMethod from "./shipping-method" -import TaxLine from "./tax-line" -const ShippingMethodIdIdIndex = createPsqlIndexStatementHelper({ - tableName: "order_shipping_method_tax_line", - columns: "shipping_method_id", -}) +const ShippingMethodIdIndex = + "IDX_order_shipping_method_tax_line_shipping_method_id" -@Entity({ tableName: "order_shipping_method_tax_line" }) -export default class OrderShippingMethodTaxLine extends TaxLine { - @ManyToOne(() => OrderShippingMethod, { - persist: false, +const OrderShippingMethodTaxLine = model + .define("OrderShippingMethodTaxLine", { + id: model.id({ prefix: "ordsmtxl" }).primaryKey(), + description: model.text().nullable(), + tax_rate_id: model.text().nullable(), + code: model.text(), + rate: model.bigNumber(), + raw_rate: model.json(), + provider_id: model.text().nullable(), + shipping_method: model.belongsTo(() => OrderShippingMethod, { + mappedBy: "tax_lines", + }), }) - shipping_method: Rel + .indexes([ + { + name: ShippingMethodIdIndex, + on: ["shipping_method_id"], + unique: false, + }, + ]) - @ManyToOne({ - entity: () => OrderShippingMethod, - fieldName: "shipping_method_id", - columnType: "text", - mapToPk: true, - onDelete: "cascade", - }) - @ShippingMethodIdIdIndex.MikroORMIndex() - shipping_method_id: string - - @BeforeCreate() - onCreate() { - this.id = generateEntityId(this.id, "ordsmtxl") - this.shipping_method_id ??= this.shipping_method?.id - } - - @OnInit() - onInit() { - this.id = generateEntityId(this.id, "ordsmtxl") - this.shipping_method_id ??= this.shipping_method?.id - } -} +export default OrderShippingMethodTaxLine diff --git a/packages/modules/order/src/models/shipping-method.ts b/packages/modules/order/src/models/shipping-method.ts index 8c9207bbbb1fa..e1c090f49ee65 100644 --- a/packages/modules/order/src/models/shipping-method.ts +++ b/packages/modules/order/src/models/shipping-method.ts @@ -1,118 +1,34 @@ -import { BigNumberRawValue } from "@medusajs/framework/types" -import { - BigNumber, - createPsqlIndexStatementHelper, - DALUtils, - generateEntityId, - MikroOrmBigNumberProperty, -} from "@medusajs/framework/utils" -import { - BeforeCreate, - Cascade, - Collection, - Entity, - Filter, - OneToMany, - OnInit, - PrimaryKey, - Property, - Rel, -} from "@mikro-orm/core" +import { model } from "@medusajs/framework/utils" import OrderShippingMethodAdjustment from "./shipping-method-adjustment" import OrderShippingMethodTaxLine from "./shipping-method-tax-line" -const DeletedAtIndex = createPsqlIndexStatementHelper({ - tableName: "order_shipping_method", - columns: "deleted_at", - where: "deleted_at IS NOT NULL", -}) - -const ShippingOptionIdIndex = createPsqlIndexStatementHelper({ - tableName: "order_shipping_method", - columns: "shipping_option_id", - where: "deleted_at IS NOT NULL", -}) - -@Entity({ tableName: "order_shipping_method" }) -@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions) -export default class OrderShippingMethod { - @PrimaryKey({ columnType: "text" }) - id: string - - @Property({ columnType: "text" }) - name: string - - @Property({ columnType: "jsonb", nullable: true }) - description: string | null = null - - @MikroOrmBigNumberProperty() - amount: BigNumber | number - - @Property({ columnType: "jsonb" }) - raw_amount: BigNumberRawValue - - @Property({ columnType: "boolean" }) - is_tax_inclusive: boolean = false - - @Property({ columnType: "boolean", default: false }) - is_custom_amount: boolean = false - - @Property({ - columnType: "text", - nullable: true, +const ShippingOptionIdIndex = "IDX_order_shipping_method_shipping_option_id" + +const OrderShippingMethod = model + .define("OrderShippingMethod", { + id: model.id({ prefix: "ordsm" }).primaryKey(), + name: model.text(), + description: model.json().nullable(), + amount: model.bigNumber(), + raw_amount: model.json(), + is_tax_inclusive: model.boolean().default(false), + is_custom_amount: model.boolean().default(false), + shipping_option_id: model.text().nullable(), + data: model.json().nullable(), + metadata: model.json().nullable(), + tax_lines: model.hasMany(() => OrderShippingMethodTaxLine, { + mappedBy: "shipping_method", + }), + adjustments: model.hasMany(() => OrderShippingMethodAdjustment, { + mappedBy: "shipping_method", + }), }) - @ShippingOptionIdIndex.MikroORMIndex() - shipping_option_id: string | null = null - - @Property({ columnType: "jsonb", nullable: true }) - data: Record | null = null - - @Property({ columnType: "jsonb", nullable: true }) - metadata: Record | null = null - - @OneToMany( - () => OrderShippingMethodTaxLine, - (taxLine) => taxLine.shipping_method, + .indexes([ { - cascade: [Cascade.PERSIST, "soft-remove" as Cascade], - } - ) - tax_lines = new Collection>(this) - - @OneToMany( - () => OrderShippingMethodAdjustment, - (adjustment) => adjustment.shipping_method, - { - cascade: [Cascade.PERSIST, "soft-remove" as Cascade], - } - ) - adjustments = new Collection>(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 - - @Property({ columnType: "timestamptz", nullable: true }) - @DeletedAtIndex.MikroORMIndex() - deleted_at: Date | null = null + name: ShippingOptionIdIndex, + on: ["shipping_option_id"], + unique: false, + }, + ]) - @BeforeCreate() - onCreate() { - this.id = generateEntityId(this.id, "ordsm") - } - @OnInit() - onInit() { - this.id = generateEntityId(this.id, "ordsm") - } -} +export default OrderShippingMethod diff --git a/packages/modules/order/src/models/tax-line.ts b/packages/modules/order/src/models/tax-line.ts deleted file mode 100644 index 2be617fda95d1..0000000000000 --- a/packages/modules/order/src/models/tax-line.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { BigNumberRawValue } from "@medusajs/framework/types" -import { BigNumber, MikroOrmBigNumberProperty } from "@medusajs/framework/utils" -import { PrimaryKey, Property } from "@mikro-orm/core" - -/** - * As per the Mikro ORM docs, superclasses should use the abstract class definition - * Source: https://mikro-orm.io/docs/inheritance-mapping - */ -export default abstract class TaxLine { - @PrimaryKey({ columnType: "text" }) - id: string - - @Property({ columnType: "text", nullable: true }) - description?: string | null - - @Property({ - columnType: "text", - nullable: true, - }) - tax_rate_id?: string | null - - @Property({ columnType: "text" }) - code: string - - @MikroOrmBigNumberProperty() - rate: BigNumber | number - - @Property({ columnType: "jsonb" }) - raw_rate: BigNumberRawValue - - @Property({ columnType: "text", nullable: true }) - provider_id?: string | 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 }) - deleted_at: Date | null = null -} diff --git a/packages/modules/order/src/models/transaction.ts b/packages/modules/order/src/models/transaction.ts index 42ca89608c469..659038ef595d4 100644 --- a/packages/modules/order/src/models/transaction.ts +++ b/packages/modules/order/src/models/transaction.ts @@ -1,214 +1,80 @@ -import { BigNumberRawValue, DAL } from "@medusajs/framework/types" -import { - BigNumber, - DALUtils, - MikroOrmBigNumberProperty, - createPsqlIndexStatementHelper, - generateEntityId, -} from "@medusajs/framework/utils" -import { - BeforeCreate, - Entity, - Filter, - ManyToOne, - OnInit, - OptionalProps, - PrimaryKey, - Property, - Rel, -} from "@mikro-orm/core" -import Claim from "./claim" -import Exchange from "./exchange" -import Order from "./order" -import Return from "./return" - -type OptionalLineItemProps = DAL.ModelDateColumns - -const tableName = "order_transaction" - -const ReferenceIdIndex = createPsqlIndexStatementHelper({ - tableName, - columns: "reference_id", - where: "deleted_at IS NOT NULL", -}) - -const OrderIdIndex = createPsqlIndexStatementHelper({ - tableName, - columns: "order_id", - where: "deleted_at IS NOT NULL", -}) - -const ReturnIdIndex = createPsqlIndexStatementHelper({ - tableName, - columns: "return_id", - where: "return_id IS NOT NULL AND deleted_at IS NOT NULL", -}) - -const ExchangeIdIndex = createPsqlIndexStatementHelper({ - tableName, - columns: ["exchange_id"], - where: "exchange_id IS NOT NULL AND deleted_at IS NOT NULL", -}) - -const ClaimIdIndex = createPsqlIndexStatementHelper({ - tableName, - columns: ["claim_id"], - where: "claim_id IS NOT NULL AND deleted_at IS NOT NULL", -}) - -const CurrencyCodeIndex = createPsqlIndexStatementHelper({ - tableName, - columns: "currency_code", - where: "deleted_at IS NOT NULL", -}) - -const DeletedAtIndex = createPsqlIndexStatementHelper({ - tableName, - columns: "deleted_at", - where: "deleted_at IS NOT NULL", -}) - -const OrderIdVersionIndex = createPsqlIndexStatementHelper({ - tableName, - columns: ["order_id", "version"], - where: "deleted_at IS NOT NULL", -}) - -@Entity({ tableName }) -@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions) -@OrderIdVersionIndex.MikroORMIndex() -export default class OrderTransaction { - [OptionalProps]?: OptionalLineItemProps - - @PrimaryKey({ columnType: "text" }) - id: string - - @ManyToOne({ - entity: () => Order, - columnType: "text", - fieldName: "order_id", - onDelete: "cascade", - mapToPk: true, - }) - @OrderIdIndex.MikroORMIndex() - order_id: string - - @ManyToOne(() => Order, { - persist: false, - }) - order: Rel - - @ManyToOne({ - entity: () => Return, - mapToPk: true, - fieldName: "return_id", - columnType: "text", - nullable: true, +import { model } from "@medusajs/framework/utils" + +const OrderTransaction = model + .define("OrderTransaction", { + id: model.id({ prefix: "ordtrx" }).primaryKey(), + order_id: model.text(), + order: model.belongsTo(() => "Order", { + mappedBy: "transactions", + }), + return_id: model.text().nullable(), + return: model.belongsTo(() => "Return", { + mappedBy: "transactions", + }), + exchange_id: model.text().nullable(), + exchange: model.belongsTo(() => "Exchange", { + mappedBy: "transactions", + }), + claim_id: model.text().nullable(), + claim: model.belongsTo(() => "Claim", { + mappedBy: "transactions", + }), + version: model.number().default(1), + amount: model.bigNumber(), + raw_amount: model.json(), + currency_code: model.text(), + reference: model.text().nullable(), + reference_id: model.text().nullable(), }) - @ReturnIdIndex.MikroORMIndex() - return_id: string | null = null - - @ManyToOne(() => Return, { - persist: false, - nullable: true, - }) - return: Rel - - @ManyToOne({ - entity: () => Exchange, - mapToPk: true, - fieldName: "exchange_id", - columnType: "text", - nullable: true, - }) - @ExchangeIdIndex.MikroORMIndex() - exchange_id: string | null - - @ManyToOne(() => Exchange, { - persist: false, - nullable: true, - }) - exchange: Rel - - @ManyToOne({ - entity: () => Claim, - mapToPk: true, - fieldName: "claim_id", - columnType: "text", - nullable: true, - }) - @ClaimIdIndex.MikroORMIndex() - claim_id: string | null - - @ManyToOne(() => Claim, { - persist: false, - nullable: true, - }) - claim: Rel - - @Property({ - columnType: "integer", - defaultRaw: "1", - }) - version: number = 1 - - @MikroOrmBigNumberProperty() - amount: BigNumber | number - - @Property({ columnType: "jsonb" }) - raw_amount: BigNumberRawValue - - @Property({ columnType: "text" }) - @CurrencyCodeIndex.MikroORMIndex() - currency_code: string - - @Property({ - columnType: "text", - nullable: true, - }) - reference: string | null = null - - @Property({ - columnType: "text", - nullable: true, - }) - @ReferenceIdIndex.MikroORMIndex() - reference_id: string | 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 }) - @DeletedAtIndex.MikroORMIndex() - deleted_at: Date | null = null - - @BeforeCreate() - onCreate() { - this.id = generateEntityId(this.id, "ordtrx") - this.order_id ??= this.order?.id - this.return_id ??= this.return?.id - this.claim_id ??= this.claim?.id - this.exchange_id ??= this.exchange?.id - } - - @OnInit() - onInit() { - this.id = generateEntityId(this.id, "ordtrx") - this.order_id ??= this.order?.id - this.return_id ??= this.return?.id - this.claim_id ??= this.claim?.id - this.exchange_id ??= this.exchange?.id - } -} + .indexes([ + { + name: "ReferenceIdIndex", + on: ["reference_id"], + unique: false, + where: "deleted_at IS NOT NULL", + }, + { + name: "OrderIdIndex", + on: ["order_id"], + unique: false, + where: "deleted_at IS NOT NULL", + }, + { + name: "ReturnIdIndex", + on: ["return_id"], + unique: false, + where: "return_id IS NOT NULL AND deleted_at IS NOT NULL", + }, + { + name: "ExchangeIdIndex", + on: ["exchange_id"], + unique: false, + where: "exchange_id IS NOT NULL AND deleted_at IS NOT NULL", + }, + { + name: "ClaimIdIndex", + on: ["claim_id"], + unique: false, + where: "claim_id IS NOT NULL AND deleted_at IS NOT NULL", + }, + { + name: "CurrencyCodeIndex", + on: ["currency_code"], + unique: false, + where: "deleted_at IS NOT NULL", + }, + { + name: "DeletedAtIndex", + on: ["deleted_at"], + unique: false, + where: "deleted_at IS NOT NULL", + }, + { + name: "OrderIdVersionIndex", + on: ["order_id", "version"], + unique: false, + where: "deleted_at IS NOT NULL", + }, + ]) + +export default OrderTransaction From b700c631df1cae748ad0d04f5885260fcc658ad2 Mon Sep 17 00:00:00 2001 From: adrien2p Date: Fri, 22 Nov 2024 13:25:22 +0100 Subject: [PATCH 065/175] cleanup --- packages/core/types/src/dml/index.ts | 5 +---- .../core/utils/src/dml/__tests__/entity-builder.spec.ts | 2 +- .../dml/integration-tests/__tests__/many-to-many.spec.ts | 2 +- .../__tests__/migrations-generate.spec.ts | 4 +++- packages/modules/product/src/models/product-tag.ts | 2 +- .../modules/product/src/repositories/product-category.ts | 9 ++++----- 6 files changed, 11 insertions(+), 13 deletions(-) diff --git a/packages/core/types/src/dml/index.ts b/packages/core/types/src/dml/index.ts index 4f87937e3c44a..7e2cff4f50784 100644 --- a/packages/core/types/src/dml/index.ts +++ b/packages/core/types/src/dml/index.ts @@ -189,10 +189,7 @@ export type InferManyToManyFields = InferHasManyFields */ export type InferSchemaFields = Prettify< { - // Omit optional properties to manage them separately and mark them as optional - [K in keyof Schema as undefined extends Schema[K]["$dataType"] - ? never - : K]: Schema[K] extends RelationshipType + [K in keyof Schema]: Schema[K] extends RelationshipType ? Schema[K]["type"] extends "belongsTo" ? InferBelongsToFields : Schema[K]["type"] extends "hasOne" diff --git a/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts b/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts index 1433276563a2b..a333507c2fd0e 100644 --- a/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts +++ b/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts @@ -2972,7 +2972,7 @@ describe("Entity builder", () => { 'CREATE UNIQUE INDEX IF NOT EXISTS "IDX_unique-name" ON "user" (organization, account, group_id) WHERE deleted_at IS NULL', name: "IDX_unique-name", }, - // { + ] // { // expression: // 'CREATE INDEX IF NOT EXISTS "IDX_user_group_id" ON "user" (group_id) WHERE deleted_at IS NULL', // name: "IDX_user_group_id", diff --git a/packages/core/utils/src/dml/integration-tests/__tests__/many-to-many.spec.ts b/packages/core/utils/src/dml/integration-tests/__tests__/many-to-many.spec.ts index 0e4753049fd7e..cfece63b5c11e 100644 --- a/packages/core/utils/src/dml/integration-tests/__tests__/many-to-many.spec.ts +++ b/packages/core/utils/src/dml/integration-tests/__tests__/many-to-many.spec.ts @@ -11,7 +11,7 @@ import { EntityConstructor } from "@medusajs/types" import { pgGodCredentials } from "../utils" import { FileSystem } from "../../../common" -jest.setTimeout(300000) +jest.setTimeout(30000) export const fileSystem = new FileSystem( join(__dirname, "../../integration-tests-migrations-many-to-many") diff --git a/packages/core/utils/src/migrations/integration-tests/__tests__/migrations-generate.spec.ts b/packages/core/utils/src/migrations/integration-tests/__tests__/migrations-generate.spec.ts index c95f2ded476ba..1005cc6e83751 100644 --- a/packages/core/utils/src/migrations/integration-tests/__tests__/migrations-generate.spec.ts +++ b/packages/core/utils/src/migrations/integration-tests/__tests__/migrations-generate.spec.ts @@ -7,6 +7,8 @@ import { FileSystem } from "../../../common" import { DmlEntity, mikroORMEntityBuilder, model } from "../../../dml" import { defineMikroOrmCliConfig } from "../../../modules-sdk" +jest.setTimeout(30000) + const DB_HOST = process.env.DB_HOST ?? "localhost" const DB_USERNAME = process.env.DB_USERNAME ?? "" const DB_PASSWORD = process.env.DB_PASSWORD ?? " " @@ -30,7 +32,7 @@ describe("Generate migrations", () => { await fs.cleanup() MetadataStorage.clear() mikroORMEntityBuilder.clear() - }, 300 * 1000) + }) test("generate migrations for a single entity", async () => { const User = model.define("User", { diff --git a/packages/modules/product/src/models/product-tag.ts b/packages/modules/product/src/models/product-tag.ts index 864d5d695cec9..e3a7389a9a6a4 100644 --- a/packages/modules/product/src/models/product-tag.ts +++ b/packages/modules/product/src/models/product-tag.ts @@ -15,7 +15,7 @@ const ProductTag = model ) .indexes([ { - name: "tagValueIndexName", + name: "IDX_tag_value_unique", on: ["value"], unique: true, where: "deleted_at IS NULL", diff --git a/packages/modules/product/src/repositories/product-category.ts b/packages/modules/product/src/repositories/product-category.ts index 6b590c76684f5..d559841ee2d29 100644 --- a/packages/modules/product/src/repositories/product-category.ts +++ b/packages/modules/product/src/repositories/product-category.ts @@ -497,10 +497,9 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito ) )[0] - const newParentCategory = await manager.findOne( - ProductCategory as any, - categoryData.parent_category_id - ) + const newParentCategory = await manager.findOne< + InferEntityType + >(ProductCategory.name, categoryData.parent_category_id) if (!newParentCategory) { throw new MedusaError( @@ -525,7 +524,7 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito const newMpath = `${newBaseMpath}.${category.id}` category.mpath = newMpath for (let child of category.category_children) { - child = manager.getReference(ProductCategory as any, child.id) + child = manager.getReference(ProductCategory.name, child.id) manager.assign( child, categoryDataChildrenMap.get(child.id) ?? {} From 21ab7a10bcbefbac25ad88fe72ae33811462b7de Mon Sep 17 00:00:00 2001 From: adrien2p Date: Fri, 22 Nov 2024 13:47:55 +0100 Subject: [PATCH 066/175] re add foerign key indexes --- .../src/dml/__tests__/entity-builder.spec.ts | 45 +++++++------------ .../entity-builder/define-relationship.ts | 27 ++++++++--- .../dml/helpers/mikro-orm/apply-indexes.ts | 30 +------------ 3 files changed, 39 insertions(+), 63 deletions(-) diff --git a/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts b/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts index a333507c2fd0e..186a121850f32 100644 --- a/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts +++ b/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts @@ -4,9 +4,9 @@ import { DmlEntity } from "../entity" import { model } from "../entity-builder" import { DuplicateIdPropertyError } from "../errors" import { + mikroORMEntityBuilder, toMikroORMEntity, toMikroOrmEntities, - mikroORMEntityBuilder, } from "../helpers/create-mikro-orm-entity" describe("Entity builder", () => { @@ -2822,7 +2822,6 @@ describe("Entity builder", () => { reference: "scalar", setter: false, type: "string", - isForeignKey: true, persist: false, }, created_at: { @@ -2946,12 +2945,16 @@ describe("Entity builder", () => { nullable: false, onDelete: undefined, reference: "m:1", - // isForeignKey: true, }, ...defaultColumnMetadata, }) expect(metaData.indexes).toEqual([ + { + expression: + 'CREATE INDEX IF NOT EXISTS "IDX_user_group_id" ON "user" (group_id) WHERE deleted_at IS NULL', + name: "IDX_user_group_id", + }, { expression: 'CREATE UNIQUE INDEX IF NOT EXISTS "IDX_user_email_account_unique" ON "user" (email, account) WHERE deleted_at IS NULL', @@ -2972,11 +2975,6 @@ describe("Entity builder", () => { 'CREATE UNIQUE INDEX IF NOT EXISTS "IDX_unique-name" ON "user" (organization, account, group_id) WHERE deleted_at IS NULL', name: "IDX_unique-name", }, - ] // { - // expression: - // 'CREATE INDEX IF NOT EXISTS "IDX_user_group_id" ON "user" (group_id) WHERE deleted_at IS NULL', - // name: "IDX_user_group_id", - // }, ]) }) @@ -3028,6 +3026,11 @@ describe("Entity builder", () => { ) expect(metaData.indexes).toEqual([ + { + expression: + 'CREATE INDEX IF NOT EXISTS "IDX_user_group_id" ON "user" (group_id) WHERE deleted_at IS NULL', + name: "IDX_user_group_id", + }, { expression: 'CREATE INDEX IF NOT EXISTS "IDX_user_organization_account" ON "user" (organization, account) WHERE email IS NOT NULL AND deleted_at IS NULL', @@ -3053,11 +3056,6 @@ describe("Entity builder", () => { 'CREATE INDEX IF NOT EXISTS "IDX_user_account_group_id" ON "user" (account, group_id) WHERE is_owner IS TRUE AND deleted_at IS NULL', name: "IDX_user_account_group_id", }, - // { - // expression: - // 'CREATE INDEX IF NOT EXISTS "IDX_user_group_id" ON "user" (group_id) WHERE deleted_at IS NULL', - // name: "IDX_user_group_id", - // }, ]) }) @@ -3119,11 +3117,11 @@ describe("Entity builder", () => { const metaData = MetadataStorage.getMetadataFromDecorator(User) expect(metaData.indexes).toEqual([ - // { - // expression: - // 'CREATE INDEX IF NOT EXISTS "IDX_user_group_id" ON "user" (group_id) WHERE deleted_at IS NULL', - // name: "IDX_user_group_id", - // }, + { + expression: + 'CREATE INDEX IF NOT EXISTS "IDX_user_group_id" ON "user" (group_id) WHERE deleted_at IS NULL', + name: "IDX_user_group_id", + }, ]) const Setting = toMikroORMEntity(setting) @@ -3546,7 +3544,6 @@ describe("Entity builder", () => { nullable: false, onDelete: "cascade", reference: "m:1", - // isForeignKey: true, }, created_at: { reference: "scalar", @@ -3749,7 +3746,6 @@ describe("Entity builder", () => { name: "user_id", getter: false, setter: false, - isForeignKey: true, persist: false, }, created_at: { @@ -3946,7 +3942,6 @@ describe("Entity builder", () => { name: "user_id", getter: false, setter: false, - isForeignKey: true, persist: false, }, created_at: { @@ -4136,7 +4131,6 @@ describe("Entity builder", () => { mapToPk: true, fieldName: "user_id", nullable: false, - // isForeignKey: true, }, created_at: { reference: "scalar", @@ -4325,7 +4319,6 @@ describe("Entity builder", () => { mapToPk: true, fieldName: "user_id", nullable: true, - // isForeignKey: true, }, created_at: { reference: "scalar", @@ -4581,7 +4574,6 @@ describe("Entity builder", () => { name: "user_id", getter: false, setter: false, - isForeignKey: true, persist: false, }, created_at: { @@ -4780,7 +4772,6 @@ describe("Entity builder", () => { name: "user_id", getter: false, setter: false, - isForeignKey: true, persist: false, }, created_at: { @@ -4887,7 +4878,6 @@ describe("Entity builder", () => { mapToPk: true, nullable: false, onDelete: undefined, - // isForeignKey: true, }, children: { cascade: undefined, @@ -4998,7 +4988,6 @@ describe("Entity builder", () => { name: "parent_id", type: "string", columnType: "text", - isForeignKey: true, persist: false, reference: "scalar", getter: false, @@ -6630,7 +6619,6 @@ describe("Entity builder", () => { mapToPk: true, fieldName: "user_id", nullable: false, - // isForeignKey: true, }, user: { reference: "scalar", @@ -6649,7 +6637,6 @@ describe("Entity builder", () => { mapToPk: true, fieldName: "team_id", nullable: false, - // isForeignKey: true, }, team: { reference: "scalar", diff --git a/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts b/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts index 88982b3044dfb..cf40a68b63a6f 100644 --- a/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts +++ b/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts @@ -15,13 +15,14 @@ import { Property, rel, } from "@mikro-orm/core" -import { DmlEntity } from "../../entity" -import { HasOne } from "../../relations/has-one" -import { HasMany } from "../../relations/has-many" -import { parseEntityName } from "./parse-entity-name" import { camelToSnakeCase, pluralize } from "../../../common" import { ForeignKey } from "../../../dal/mikro-orm/decorators/foreign-key" +import { DmlEntity } from "../../entity" +import { HasMany } from "../../relations/has-many" +import { HasOne } from "../../relations/has-one" import { ManyToMany as DmlManyToMany } from "../../relations/many-to-many" +import { applyEntityIndexes } from "../mikro-orm/apply-indexes" +import { parseEntityName } from "./parse-entity-name" type Context = { MANY_TO_MANY_TRACKED_RELATIONS: Record @@ -182,6 +183,7 @@ export function defineHasManyRelationship( */ export function defineBelongsToRelationship( MikroORMEntity: EntityConstructor, + entity: DmlEntity, relationship: RelationshipMetadata, relatedEntity: DmlEntity< Record | RelationshipType>, @@ -280,6 +282,13 @@ export function defineBelongsToRelationship( })(MikroORMEntity.prototype, relationship.name) } + const { tableName } = parseEntityName(entity) + applyEntityIndexes(MikroORMEntity, tableName, [ + { + on: [foreignKeyName], + where: "deleted_at IS NULL", + }, + ]) applyForeignKeyAssignationHooks(foreignKeyName) return } @@ -311,7 +320,14 @@ export function defineBelongsToRelationship( nullable: relationship.nullable, persist: false, })(MikroORMEntity.prototype, foreignKeyName) - ForeignKey()(MikroORMEntity.prototype, foreignKeyName) + + const { tableName } = parseEntityName(entity) + applyEntityIndexes(MikroORMEntity, tableName, [ + { + on: [foreignKeyName], + where: "deleted_at IS NULL", + }, + ]) applyForeignKeyAssignationHooks(foreignKeyName) return @@ -564,6 +580,7 @@ export function defineRelationship( case "belongsTo": defineBelongsToRelationship( MikroORMEntity, + entity, relationship, relatedEntity, relatedEntityInfo diff --git a/packages/core/utils/src/dml/helpers/mikro-orm/apply-indexes.ts b/packages/core/utils/src/dml/helpers/mikro-orm/apply-indexes.ts index 4acd61c719328..f6b43f7da4d66 100644 --- a/packages/core/utils/src/dml/helpers/mikro-orm/apply-indexes.ts +++ b/packages/core/utils/src/dml/helpers/mikro-orm/apply-indexes.ts @@ -3,7 +3,6 @@ import { EntityIndex, PropertyMetadata, } from "@medusajs/types" -import { MetadataStorage } from "@mikro-orm/core" import { createPsqlIndexStatementHelper } from "../../../common" import { validateIndexFields } from "../mikro-orm/build-indexes" @@ -38,8 +37,7 @@ export function applyEntityIndexes( tableName: string, entityIndexes: EntityIndex[] = [] ) { - const foreignKeyIndexes = applyForeignKeyIndexes(MikroORMEntity) - const indexes = [...entityIndexes, ...foreignKeyIndexes] + const indexes = [...entityIndexes] indexes.forEach((index) => { validateIndexFields(MikroORMEntity, index) @@ -55,29 +53,3 @@ export function applyEntityIndexes( entityIndexStatement.MikroORMIndex()(MikroORMEntity) }) } - -/* - When a "oneToMany" relationship is found on the MikroORM entity, we create an index by default - on the foreign key property. -*/ -function applyForeignKeyIndexes(MikroORMEntity: EntityConstructor) { - const foreignKeyIndexes: EntityIndex[] = [] - - for (const foreignKey of getEntityForeignKeys(MikroORMEntity)) { - foreignKeyIndexes.push({ - on: [foreignKey], - where: "deleted_at IS NULL", - }) - } - - return foreignKeyIndexes -} - -function getEntityForeignKeys(MikroORMEntity: EntityConstructor) { - const properties = - MetadataStorage.getMetadataFromDecorator(MikroORMEntity).properties - - return Object.keys(properties).filter( - (propertyName) => properties[propertyName].isForeignKey - ) -} From f9b906879c1459711a714f027157c2c2cf14d3ae Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Fri, 22 Nov 2024 10:17:33 -0300 Subject: [PATCH 067/175] wip --- .../order/src/models/claim-item-image.ts | 7 +-- .../modules/order/src/models/claim-item.ts | 10 ++-- packages/modules/order/src/models/claim.ts | 21 +++----- .../modules/order/src/models/exchange-item.ts | 10 ++-- packages/modules/order/src/models/exchange.ts | 21 +++----- .../order/src/models/line-item-tax-line.ts | 5 +- .../modules/order/src/models/line-item.ts | 13 ++--- .../order/src/models/order-change-action.ts | 22 +++----- .../modules/order/src/models/order-change.ts | 22 +++----- .../modules/order/src/models/order-item.ts | 13 ++--- .../order/src/models/order-shipping-method.ts | 30 ++++------- .../modules/order/src/models/order-summary.ts | 9 ++-- packages/modules/order/src/models/order.ts | 51 +++++++++---------- .../modules/order/src/models/return-item.ts | 13 ++--- .../modules/order/src/models/return-reason.ts | 10 ++-- packages/modules/order/src/models/return.ts | 18 ++----- .../src/models/shipping-method-adjustment.ts | 2 +- .../src/models/shipping-method-tax-line.ts | 5 +- .../order/src/models/shipping-method.ts | 4 +- .../modules/order/src/models/transaction.ts | 16 +++--- 20 files changed, 109 insertions(+), 193 deletions(-) diff --git a/packages/modules/order/src/models/claim-item-image.ts b/packages/modules/order/src/models/claim-item-image.ts index fbb7e09d040e6..eb6714739500c 100644 --- a/packages/modules/order/src/models/claim-item-image.ts +++ b/packages/modules/order/src/models/claim-item-image.ts @@ -1,9 +1,6 @@ import { model } from "@medusajs/framework/utils" import ClaimItem from "./claim-item" -const ClaimItemImageDeletedAtIndex = "IDX_order_claim_item_image_deleted_at" -const ClaimItemIdIndex = "IDX_order_claim_item_image_claim_item_id" - const OrderClaimItemImage = model .define("OrderClaimItemImage", { id: model.id({ prefix: "climg" }).primaryKey(), @@ -15,13 +12,13 @@ const OrderClaimItemImage = model }) .indexes([ { - name: ClaimItemImageDeletedAtIndex, + name: "IDX_order_claim_item_image_deleted_at", on: ["deleted_at"], unique: false, where: "deleted_at IS NOT NULL", }, { - name: ClaimItemIdIndex, + name: "IDX_order_claim_item_image_claim_item_id", on: ["claim_item_id"], unique: false, where: "deleted_at IS NOT NULL", diff --git a/packages/modules/order/src/models/claim-item.ts b/packages/modules/order/src/models/claim-item.ts index 80006f95c7705..ef573f2d3a85c 100644 --- a/packages/modules/order/src/models/claim-item.ts +++ b/packages/modules/order/src/models/claim-item.ts @@ -3,10 +3,6 @@ import Claim from "./claim" import OrderClaimItemImage from "./claim-item-image" import OrderLineItem from "./line-item" -const ClaimIdIndex = "IDX_order_claim_item_claim_id" -const ItemIdIndex = "IDX_order_claim_item_item_id" -const DeletedAtIndex = "IDX_order_claim_item_deleted_at" - const OrderClaimItem = model .define("OrderClaimItem", { id: model.id({ prefix: "claitem" }).primaryKey(), @@ -28,19 +24,19 @@ const OrderClaimItem = model }) .indexes([ { - name: ClaimIdIndex, + name: "IDX_order_claim_item_claim_id", on: ["claim_id"], unique: false, where: "deleted_at IS NOT NULL", }, { - name: ItemIdIndex, + name: "IDX_order_claim_item_item_id", on: ["item_id"], unique: false, where: "deleted_at IS NOT NULL", }, { - name: DeletedAtIndex, + name: "IDX_order_claim_item_deleted_at", on: ["deleted_at"], unique: false, where: "deleted_at IS NOT NULL", diff --git a/packages/modules/order/src/models/claim.ts b/packages/modules/order/src/models/claim.ts index 8e05c100d5098..1fcdaf87ec632 100644 --- a/packages/modules/order/src/models/claim.ts +++ b/packages/modules/order/src/models/claim.ts @@ -5,22 +5,15 @@ import OrderShipping from "./order-shipping-method" import Return from "./return" import OrderTransaction from "./transaction" -const DisplayIdIndex = "IDX_order_claim_display_id" -const OrderClaimDeletedAtIndex = "IDX_order_claim_deleted_at" -const OrderIdIndex = "IDX_order_claim_order_id" -const ReturnIdIndex = "IDX_order_claim_return_id" - const OrderClaim = model .define("OrderClaim", { id: model.id({ prefix: "claim" }).primaryKey(), order: model.belongsTo(() => Order, { mappedBy: "claims", }), - return: model - .belongsTo(() => Return, { - mappedBy: "claim", - }) - .nullable(), + return: model.hasMany(() => Return, { + mappedBy: "claim", + }), order_version: model.number(), display_id: model.number(), // TODO: auto increment type: model.enum(ClaimType), @@ -45,25 +38,25 @@ const OrderClaim = model }) .indexes([ { - name: DisplayIdIndex, + name: "IDX_order_claim_display_id", on: ["display_id"], unique: false, where: "deleted_at IS NOT NULL", }, { - name: OrderClaimDeletedAtIndex, + name: "IDX_order_claim_deleted_at", on: ["deleted_at"], unique: false, where: "deleted_at IS NOT NULL", }, { - name: OrderIdIndex, + name: "IDX_order_claim_order_id", on: ["order_id"], unique: false, where: "deleted_at IS NOT NULL", }, { - name: ReturnIdIndex, + name: "IDX_order_claim_return_id", on: ["return_id"], unique: false, where: "return_id IS NOT NULL AND deleted_at IS NOT NULL", diff --git a/packages/modules/order/src/models/exchange-item.ts b/packages/modules/order/src/models/exchange-item.ts index d226f85128c98..8708cc365b7ec 100644 --- a/packages/modules/order/src/models/exchange-item.ts +++ b/packages/modules/order/src/models/exchange-item.ts @@ -2,10 +2,6 @@ import { model } from "@medusajs/framework/utils" import Exchange from "./exchange" import OrderLineItem from "./line-item" -const ExchangeIdIndex = "IDX_order_exchange_item_exchange_id" -const ItemIdIndex = "IDX_order_exchange_item_item_id" -const DeletedAtIndex = "IDX_order_exchange_item_deleted_at" - const OrderExchangeItem = model .define("OrderExchangeItem", { id: model.id({ prefix: "oexcitem" }).primaryKey(), @@ -22,19 +18,19 @@ const OrderExchangeItem = model }) .indexes([ { - name: ExchangeIdIndex, + name: "IDX_order_exchange_item_exchange_id", on: ["exchange_id"], unique: false, where: "deleted_at IS NOT NULL", }, { - name: ItemIdIndex, + name: "IDX_order_exchange_item_item_id", on: ["item_id"], unique: false, where: "deleted_at IS NOT NULL", }, { - name: DeletedAtIndex, + name: "IDX_order_exchange_item_deleted_at", on: ["deleted_at"], unique: false, where: "deleted_at IS NOT NULL", diff --git a/packages/modules/order/src/models/exchange.ts b/packages/modules/order/src/models/exchange.ts index 350823cdc903a..5fc993aa9476e 100644 --- a/packages/modules/order/src/models/exchange.ts +++ b/packages/modules/order/src/models/exchange.ts @@ -4,22 +4,15 @@ import Order from "./order" import OrderShipping from "./order-shipping-method" import Return from "./return" -const DisplayIdIndex = "IDX_order_exchange_display_id" -const OrderExchangeDeletedAtIndex = "IDX_order_exchange_deleted_at" -const OrderIdIndex = "IDX_order_exchange_order_id" -const ReturnIdIndex = "IDX_order_exchange_return_id" - const OrderExchange = model .define("OrderExchange", { id: model.id({ prefix: "oexc" }).primaryKey(), order: model.belongsTo(() => Order, { mappedBy: "exchanges", }), - return: model - .belongsTo(() => Return, { - mappedBy: "exchange", - }) - .nullable(), + return: model.hasMany(() => Return, { + mappedBy: "exchange", + }), order_version: model.number(), display_id: model.number(), no_notification: model.boolean().nullable(), @@ -41,25 +34,25 @@ const OrderExchange = model }) .indexes([ { - name: DisplayIdIndex, + name: "IDX_order_exchange_display_id", on: ["display_id"], unique: false, where: "deleted_at IS NOT NULL", }, { - name: OrderExchangeDeletedAtIndex, + name: "IDX_order_exchange_deleted_at", on: ["deleted_at"], unique: false, where: "deleted_at IS NOT NULL", }, { - name: OrderIdIndex, + name: "IDX_order_exchange_order_id", on: ["order_id"], unique: false, where: "deleted_at IS NOT NULL", }, { - name: ReturnIdIndex, + name: "IDX_order_exchange_return_id", on: ["return_id"], unique: false, where: "return_id IS NOT NULL AND deleted_at IS NOT NULL", diff --git a/packages/modules/order/src/models/line-item-tax-line.ts b/packages/modules/order/src/models/line-item-tax-line.ts index 869af50d6bf5c..e7021c65621af 100644 --- a/packages/modules/order/src/models/line-item-tax-line.ts +++ b/packages/modules/order/src/models/line-item-tax-line.ts @@ -1,4 +1,5 @@ import { model } from "@medusajs/framework/utils" +import OrderLineItem from "./line-item" const OrderLineItemTaxLine = model .define("OrderLineItemTaxLine", { @@ -9,7 +10,9 @@ const OrderLineItemTaxLine = model rate: model.bigNumber(), raw_rate: model.json(), provider_id: model.text().nullable(), - item: model.belongsTo(() => "OrderLineItem", { mappedBy: "tax_lines" }), + item: model.belongsTo(() => OrderLineItem, { + mappedBy: "tax_lines", + }), item_id: model.text(), }) .indexes([ diff --git a/packages/modules/order/src/models/line-item.ts b/packages/modules/order/src/models/line-item.ts index fb54486fae2d9..e6a2df4dd9ec4 100644 --- a/packages/modules/order/src/models/line-item.ts +++ b/packages/modules/order/src/models/line-item.ts @@ -2,11 +2,6 @@ import { model } from "@medusajs/framework/utils" import OrderLineItemAdjustment from "./line-item-adjustment" import OrderLineItemTaxLine from "./line-item-tax-line" -const DeletedAtIndex = "IDX_order_line_item_deleted_at" -const ProductIdIndex = "IDX_order_line_item_product_id" -const ProductTypeIdIndex = "IDX_line_item_product_type_id" -const VariantIdIndex = "IDX_order_line_item_variant_id" - const OrderLineItem = model .define("OrderLineItem", { id: model.id({ prefix: "ordli" }).primaryKey(), @@ -44,25 +39,25 @@ const OrderLineItem = model }) .indexes([ { - name: DeletedAtIndex, + name: "IDX_order_line_item_deleted_at", on: ["deleted_at"], unique: false, where: "deleted_at IS NOT NULL", }, { - name: ProductIdIndex, + name: "IDX_order_line_item_product_id", on: ["product_id"], unique: false, where: "deleted_at IS NOT NULL", }, { - name: ProductTypeIdIndex, + name: "IDX_line_item_product_type_id", on: ["product_type_id"], unique: false, where: "deleted_at IS NOT NULL AND product_type_id IS NOT NULL", }, { - name: VariantIdIndex, + name: "IDX_order_line_item_variant_id", on: ["variant_id"], unique: false, where: "deleted_at IS NOT NULL", diff --git a/packages/modules/order/src/models/order-change-action.ts b/packages/modules/order/src/models/order-change-action.ts index 9f4d39523098f..5fc54ba384b16 100644 --- a/packages/modules/order/src/models/order-change-action.ts +++ b/packages/modules/order/src/models/order-change-action.ts @@ -1,13 +1,5 @@ import { model } from "@medusajs/framework/utils" -const OrderChangeIdIndex = "IDX_order_change_action_order_change_id" -const OrderIdIndex = "IDX_order_change_action_order_id" -const ReturnIdIndex = "IDX_order_change_action_return_id" -const OrderClaimIdIndex = "IDX_order_change_action_claim_id" -const OrderExchangeIdIndex = "IDX_order_change_action_exchange_id" -const DeletedAtIndex = "IDX_order_change_action_deleted_at" -const ActionOrderingIndex = "IDX_order_change_action_ordering" - const OrderChangeAction = model .define("OrderChangeAction", { id: model.id({ prefix: "ordchact" }).primaryKey(), @@ -29,43 +21,43 @@ const OrderChangeAction = model }) .indexes([ { - name: OrderChangeIdIndex, + name: "IDX_order_change_action_order_change_id", on: ["order_change_id"], unique: false, where: "deleted_at IS NOT NULL", }, { - name: OrderIdIndex, + name: "IDX_order_change_action_order_id", on: ["order_id"], unique: false, where: "deleted_at IS NOT NULL", }, { - name: ReturnIdIndex, + name: "IDX_order_change_action_return_id", on: ["return_id"], unique: false, where: "return_id IS NOT NULL AND deleted_at IS NOT NULL", }, { - name: OrderClaimIdIndex, + name: "IDX_order_change_action_claim_id", on: ["claim_id"], unique: false, where: "claim_id IS NOT NULL AND deleted_at IS NOT NULL", }, { - name: OrderExchangeIdIndex, + name: "IDX_order_change_action_exchange_id", on: ["exchange_id"], unique: false, where: "exchange_id IS NOT NULL AND deleted_at IS NOT NULL", }, { - name: DeletedAtIndex, + name: "IDX_order_change_action_deleted_at", on: ["deleted_at"], unique: false, where: "deleted_at IS NOT NULL", }, { - name: ActionOrderingIndex, + name: "IDX_order_change_action_ordering", on: ["ordering"], unique: false, where: "deleted_at IS NOT NULL", diff --git a/packages/modules/order/src/models/order-change.ts b/packages/modules/order/src/models/order-change.ts index fe0cab2199d26..595909c172ee8 100644 --- a/packages/modules/order/src/models/order-change.ts +++ b/packages/modules/order/src/models/order-change.ts @@ -5,14 +5,6 @@ import Order from "./order" import OrderChangeAction from "./order-change-action" import Return from "./return" -const OrderIdIndex = "IDX_order_change_order_id" -const ReturnIdIndex = "IDX_order_change_return_id" -const OrderClaimIdIndex = "IDX_order_change_claim_id" -const OrderExchangeIdIndex = "IDX_order_change_exchange_id" -const OrderChangeStatusIndex = "IDX_order_change_status" -const DeletedAtIndex = "IDX_order_change_deleted_at" -const VersionIndex = "IDX_order_change_version" - const OrderChange = model .define("OrderChange", { id: model.id({ prefix: "ordch" }).primaryKey(), @@ -56,43 +48,43 @@ const OrderChange = model }) .indexes([ { - name: OrderIdIndex, + name: "IDX_order_change_order_id", on: ["order_id"], unique: false, where: "deleted_at IS NOT NULL", }, { - name: ReturnIdIndex, + name: "IDX_order_change_return_id", on: ["return_id"], unique: false, where: "return_id IS NOT NULL AND deleted_at IS NOT NULL", }, { - name: OrderClaimIdIndex, + name: "IDX_order_change_claim_id", on: ["claim_id"], unique: false, where: "claim_id IS NOT NULL AND deleted_at IS NOT NULL", }, { - name: OrderExchangeIdIndex, + name: "IDX_order_change_exchange_id", on: ["exchange_id"], unique: false, where: "exchange_id IS NOT NULL AND deleted_at IS NOT NULL", }, { - name: OrderChangeStatusIndex, + name: "IDX_order_change_status", on: ["status"], unique: false, where: "deleted_at IS NOT NULL", }, { - name: DeletedAtIndex, + name: "IDX_order_change_deleted_at", on: ["deleted_at"], unique: false, where: "deleted_at IS NOT NULL", }, { - name: VersionIndex, + name: "IDX_order_change_version", on: ["order_id", "version"], unique: false, where: "deleted_at IS NOT NULL", diff --git a/packages/modules/order/src/models/order-item.ts b/packages/modules/order/src/models/order-item.ts index 5988b52055ad9..902f85f8a9140 100644 --- a/packages/modules/order/src/models/order-item.ts +++ b/packages/modules/order/src/models/order-item.ts @@ -2,11 +2,6 @@ import { model } from "@medusajs/framework/utils" import OrderLineItem from "./line-item" import Order from "./order" -const OrderIdIndex = "IDX_order_item_order_id" -const OrderVersionIndex = "IDX_order_item_version" -const ItemIdIndex = "IDX_order_item_item_id" -const DeletedAtIndex = "IDX_order_item_deleted_at" - const OrderItem = model .define("OrderItem", { id: model.id({ prefix: "orditem" }).primaryKey(), @@ -41,25 +36,25 @@ const OrderItem = model }) .indexes([ { - name: OrderIdIndex, + name: "IDX_order_item_order_id", on: ["order_id"], unique: false, where: "deleted_at IS NOT NULL", }, { - name: OrderVersionIndex, + name: "IDX_order_item_version", on: ["version"], unique: false, where: "deleted_at IS NOT NULL", }, { - name: ItemIdIndex, + name: "IDX_order_item_item_id", on: ["item_id"], unique: false, where: "deleted_at IS NOT NULL", }, { - name: DeletedAtIndex, + name: "IDX_order_item_deleted_at", on: ["deleted_at"], unique: false, where: "deleted_at IS NOT NULL", diff --git a/packages/modules/order/src/models/order-shipping-method.ts b/packages/modules/order/src/models/order-shipping-method.ts index 319efc0b9b4fc..0762bdd155809 100644 --- a/packages/modules/order/src/models/order-shipping-method.ts +++ b/packages/modules/order/src/models/order-shipping-method.ts @@ -5,14 +5,6 @@ import Order from "./order" import Return from "./return" import OrderShippingMethod from "./shipping-method" -const OrderIdIndex = "IDX_order_shipping_order_id" -const ReturnIdIndex = "IDX_order_shipping_return_id" -const ExchangeIdIndex = "IDX_order_shipping_exchange_id" -const ClaimIdIndex = "IDX_order_shipping_claim_id" -const OrderVersionIndex = "IDX_order_shipping_version" -const ItemIdIndex = "IDX_order_shipping_shipping_method_id" -const DeletedAtIndex = "IDX_order_shipping_deleted_at" - const OrderShipping = model .define("OrderShipping", { id: model.id({ prefix: "ordspmv" }).primaryKey(), @@ -21,63 +13,63 @@ const OrderShipping = model }), return: model .belongsTo(() => Return, { - mappedBy: "order_shippings", + mappedBy: "shipping_methods", }) .nullable(), exchange: model .belongsTo(() => Exchange, { - mappedBy: "order_shippings", + mappedBy: "shipping_methods", }) .nullable(), claim: model .belongsTo(() => Claim, { - mappedBy: "order_shippings", + mappedBy: "shipping_methods", }) .nullable(), version: model.number(), shipping_method: model.belongsTo(() => OrderShippingMethod, { - mappedBy: "order_shippings", + mappedBy: "shipping_methods", }), }) .indexes([ { - name: OrderIdIndex, + name: "IDX_order_shipping_order_id", on: ["order_id"], unique: false, where: "deleted_at IS NOT NULL", }, { - name: ReturnIdIndex, + name: "IDX_order_shipping_return_id", on: ["return_id"], unique: false, where: "return_id IS NOT NULL AND deleted_at IS NOT NULL", }, { - name: ExchangeIdIndex, + name: "IDX_order_shipping_exchange_id", on: ["exchange_id"], unique: false, where: "exchange_id IS NOT NULL AND deleted_at IS NOT NULL", }, { - name: ClaimIdIndex, + name: "IDX_order_shipping_claim_id", on: ["claim_id"], unique: false, where: "claim_id IS NOT NULL AND deleted_at IS NOT NULL", }, { - name: OrderVersionIndex, + name: "IDX_order_shipping_version", on: ["version"], unique: false, where: "deleted_at IS NOT NULL", }, { - name: ItemIdIndex, + name: "IDX_order_shipping_shipping_method_id", on: ["shipping_method_id"], unique: false, where: "deleted_at IS NOT NULL", }, { - name: DeletedAtIndex, + name: "IDX_order_shipping_deleted_at", on: ["deleted_at"], unique: false, where: "deleted_at IS NOT NULL", diff --git a/packages/modules/order/src/models/order-summary.ts b/packages/modules/order/src/models/order-summary.ts index 2d9fe5fe45d13..bd52054387420 100644 --- a/packages/modules/order/src/models/order-summary.ts +++ b/packages/modules/order/src/models/order-summary.ts @@ -1,27 +1,24 @@ import { model } from "@medusajs/framework/utils" import Order from "./order" -const OrderIdVersionIndex = "IDX_order_summary_order_id_version" -const DeletedAtIndex = "IDX_order_summary_deleted_at" - const OrderSummary = model .define("OrderSummary", { id: model.id({ prefix: "ordsum" }).primaryKey(), order: model.belongsTo(() => Order, { - mappedBy: "summaries", + mappedBy: "summary", }), version: model.number().default(1), totals: model.json(), }) .indexes([ { - name: OrderIdVersionIndex, + name: "IDX_order_summary_order_id_version", on: ["order_id", "version"], unique: false, where: "deleted_at IS NOT NULL", }, { - name: DeletedAtIndex, + name: "IDX_order_summary_deleted_at", on: ["deleted_at"], unique: false, where: "deleted_at IS NOT NULL", diff --git a/packages/modules/order/src/models/order.ts b/packages/modules/order/src/models/order.ts index 6c42ba0fef196..92cffff7933c8 100644 --- a/packages/modules/order/src/models/order.ts +++ b/packages/modules/order/src/models/order.ts @@ -1,20 +1,13 @@ import { model, OrderStatus } from "@medusajs/framework/utils" import OrderAddress from "./address" +import OrderClaim from "./claim" +import OrderExchange from "./exchange" import OrderItem from "./order-item" import OrderShipping from "./order-shipping-method" import OrderSummary from "./order-summary" +import Return from "./return" import OrderTransaction from "./transaction" -const DisplayIdIndex = "IDX_order_display_id" -const RegionIdIndex = "IDX_order_region_id" -const CustomerIdIndex = "IDX_order_customer_id" -const SalesChannelIdIndex = "IDX_order_sales_channel_id" -const OrderDeletedAtIndex = "IDX_order_deleted_at" -const CurrencyCodeIndex = "IDX_order_currency_code" -const ShippingAddressIdIndex = "IDX_order_shipping_address_id" -const BillingAddressIdIndex = "IDX_order_billing_address_id" -const IsDraftOrderIndex = "IDX_order_is_draft_order" - const Order = model .define("Order", { id: model.id({ prefix: "order" }).primaryKey(), @@ -27,14 +20,8 @@ const Order = model is_draft_order: model.boolean().default(false), email: model.text().searchable().nullable(), currency_code: model.text(), - shipping_address_id: model.text().nullable(), - shipping_address: model.belongsTo(() => OrderAddress, { - mappedBy: "shipping_orders", - }), - billing_address_id: model.text().nullable(), - billing_address: model.belongsTo(() => OrderAddress, { - mappedBy: "billing_orders", - }), + shipping_address: model.belongsTo(() => OrderAddress), + billing_address: model.belongsTo(() => OrderAddress), no_notification: model.boolean().nullable(), summary: model.hasMany(() => OrderSummary, { mappedBy: "order", @@ -50,58 +37,68 @@ const Order = model mappedBy: "order", }), canceled_at: model.dateTime().nullable(), + + exchanges: model.hasMany(() => OrderExchange, { + mappedBy: "order", + }), + claims: model.hasMany(() => OrderClaim, { + mappedBy: "order", + }), + returns: model.hasMany(() => Return, { + mappedBy: "order", + }), }) .indexes([ { - name: DisplayIdIndex, + name: "IDX_order_display_id", on: ["display_id"], unique: false, where: "deleted_at IS NOT NULL", }, { - name: RegionIdIndex, + name: "IDX_order_region_id", on: ["region_id"], unique: false, where: "deleted_at IS NOT NULL", }, { - name: CustomerIdIndex, + name: "IDX_order_customer_id", on: ["customer_id"], unique: false, where: "deleted_at IS NOT NULL", }, { - name: SalesChannelIdIndex, + name: "IDX_order_sales_channel_id", on: ["sales_channel_id"], unique: false, where: "deleted_at IS NOT NULL", }, { - name: OrderDeletedAtIndex, + name: "IDX_order_deleted_at", on: ["deleted_at"], unique: false, where: "deleted_at IS NOT NULL", }, { - name: CurrencyCodeIndex, + name: "IDX_order_currency_code", on: ["currency_code"], unique: false, where: "deleted_at IS NOT NULL", }, { - name: ShippingAddressIdIndex, + name: "IDX_order_shipping_address_id", on: ["shipping_address_id"], unique: false, where: "deleted_at IS NOT NULL", }, { - name: BillingAddressIdIndex, + name: "IDX_order_billing_address_id", on: ["billing_address_id"], unique: false, where: "deleted_at IS NOT NULL", }, { - name: IsDraftOrderIndex, + name: "IDX_order_is_draft_order", on: ["is_draft_order"], unique: false, where: "deleted_at IS NOT NULL", diff --git a/packages/modules/order/src/models/return-item.ts b/packages/modules/order/src/models/return-item.ts index fde30bd001996..530b0a5351bfd 100644 --- a/packages/modules/order/src/models/return-item.ts +++ b/packages/modules/order/src/models/return-item.ts @@ -3,11 +3,6 @@ import OrderLineItem from "./line-item" import Return from "./return" import ReturnReason from "./return-reason" -const ReturnIdIndex = "IDX_return_item_return_id" -const ReturnReasonIdIndex = "IDX_return_item_reason_id" -const ItemIdIndex = "IDX_return_item_item_id" -const DeletedAtIndex = "IDX_return_item_deleted_at" - const ReturnItem = model .define("ReturnItem", { id: model.id({ prefix: "retitem" }).primaryKey(), @@ -33,25 +28,25 @@ const ReturnItem = model }) .indexes([ { - name: ReturnIdIndex, + name: "IDX_return_item_return_id", on: ["return_id"], unique: false, where: "deleted_at IS NOT NULL", }, { - name: ReturnReasonIdIndex, + name: "IDX_return_item_reason_id", on: ["reason_id"], unique: false, where: "deleted_at IS NOT NULL", }, { - name: ItemIdIndex, + name: "IDX_return_item_item_id", on: ["item_id"], unique: false, where: "deleted_at IS NOT NULL", }, { - name: DeletedAtIndex, + name: "IDX_return_item_deleted_at", on: ["deleted_at"], unique: false, where: "deleted_at IS NOT NULL", diff --git a/packages/modules/order/src/models/return-reason.ts b/packages/modules/order/src/models/return-reason.ts index c679b3d6a49b6..176b855f04c25 100644 --- a/packages/modules/order/src/models/return-reason.ts +++ b/packages/modules/order/src/models/return-reason.ts @@ -1,9 +1,5 @@ import { model } from "@medusajs/framework/utils" -const DeletedAtIndex = "IDX_return_reason_deleted_at" -const ValueIndex = "IDX_return_reason_value" -const ParentIndex = "IDX_return_reason_parent_return_reason_id" - const ReturnReason = model .define("ReturnReason", { id: model.id({ prefix: "rr" }).primaryKey(), @@ -21,19 +17,19 @@ const ReturnReason = model }) .indexes([ { - name: DeletedAtIndex, + name: "IDX_return_reason_deleted_at", on: ["deleted_at"], unique: false, where: "deleted_at IS NOT NULL", }, { - name: ValueIndex, + name: "IDX_return_reason_value", on: ["value"], unique: false, where: "deleted_at IS NOT NULL", }, { - name: ParentIndex, + name: "IDX_return_reason_parent_return_reason_id", on: ["parent_return_reason_id"], unique: false, where: "deleted_at IS NOT NULL", diff --git a/packages/modules/order/src/models/return.ts b/packages/modules/order/src/models/return.ts index d8f76eb5ce7a7..96f46ccedac91 100644 --- a/packages/modules/order/src/models/return.ts +++ b/packages/modules/order/src/models/return.ts @@ -5,23 +5,15 @@ import Exchange from "./exchange" import Order from "./order" import OrderShipping from "./order-shipping-method" -const DisplayIdIndex = "IDX_return_display_id" -const ReturnDeletedAtIndex = "IDX_return_deleted_at" -const OrderIdIndex = "IDX_return_order_id" -const ExchangeIdIndex = "IDX_return_exchange_id" -const ClaimIdIndex = "IDX_return_claim_id" - const Return = model .define("Return", { id: model.id({ prefix: "return" }).primaryKey(), order: model.belongsTo(() => Order, { mappedBy: "returns", }), - exchange_id: model.text().nullable(), exchange: model.belongsTo(() => Exchange, { mappedBy: "return", }), - claim_id: model.text().nullable(), claim: model.belongsTo(() => Claim, { mappedBy: "return", }), @@ -49,31 +41,31 @@ const Return = model }) .indexes([ { - name: DisplayIdIndex, + name: "IDX_return_display_id", on: ["display_id"], unique: false, where: "deleted_at IS NOT NULL", }, { - name: ReturnDeletedAtIndex, + name: "IDX_return_deleted_at", on: ["deleted_at"], unique: false, where: "deleted_at IS NOT NULL", }, { - name: OrderIdIndex, + name: "IDX_return_order_id", on: ["order_id"], unique: false, where: "deleted_at IS NOT NULL", }, { - name: ExchangeIdIndex, + name: "IDX_return_exchange_id", on: ["exchange_id"], unique: false, where: "exchange_id IS NOT NULL AND deleted_at IS NOT NULL", }, { - name: ClaimIdIndex, + name: "IDX_return_claim_id", on: ["claim_id"], unique: false, where: "claim_id IS NOT NULL AND deleted_at IS NOT NULL", diff --git a/packages/modules/order/src/models/shipping-method-adjustment.ts b/packages/modules/order/src/models/shipping-method-adjustment.ts index 5c57f255a7e07..6e1366c2e345c 100644 --- a/packages/modules/order/src/models/shipping-method-adjustment.ts +++ b/packages/modules/order/src/models/shipping-method-adjustment.ts @@ -17,7 +17,7 @@ const OrderShippingMethodAdjustment = model }) .indexes([ { - name: "ShippingMethodIdIdIndex", + name: "IDX_order_shipping_method_adjustment_shipping_method_id", on: ["shipping_method_id"], unique: false, }, diff --git a/packages/modules/order/src/models/shipping-method-tax-line.ts b/packages/modules/order/src/models/shipping-method-tax-line.ts index 43e134cb04b7a..56ca93a355375 100644 --- a/packages/modules/order/src/models/shipping-method-tax-line.ts +++ b/packages/modules/order/src/models/shipping-method-tax-line.ts @@ -1,9 +1,6 @@ import { model } from "@medusajs/framework/utils" import OrderShippingMethod from "./shipping-method" -const ShippingMethodIdIndex = - "IDX_order_shipping_method_tax_line_shipping_method_id" - const OrderShippingMethodTaxLine = model .define("OrderShippingMethodTaxLine", { id: model.id({ prefix: "ordsmtxl" }).primaryKey(), @@ -19,7 +16,7 @@ const OrderShippingMethodTaxLine = model }) .indexes([ { - name: ShippingMethodIdIndex, + name: "IDX_order_shipping_method_tax_line_shipping_method_id", on: ["shipping_method_id"], unique: false, }, diff --git a/packages/modules/order/src/models/shipping-method.ts b/packages/modules/order/src/models/shipping-method.ts index e1c090f49ee65..e9de38874d2d5 100644 --- a/packages/modules/order/src/models/shipping-method.ts +++ b/packages/modules/order/src/models/shipping-method.ts @@ -2,8 +2,6 @@ import { model } from "@medusajs/framework/utils" import OrderShippingMethodAdjustment from "./shipping-method-adjustment" import OrderShippingMethodTaxLine from "./shipping-method-tax-line" -const ShippingOptionIdIndex = "IDX_order_shipping_method_shipping_option_id" - const OrderShippingMethod = model .define("OrderShippingMethod", { id: model.id({ prefix: "ordsm" }).primaryKey(), @@ -25,7 +23,7 @@ const OrderShippingMethod = model }) .indexes([ { - name: ShippingOptionIdIndex, + name: "IDX_order_shipping_method_shipping_option_id", on: ["shipping_option_id"], unique: false, }, diff --git a/packages/modules/order/src/models/transaction.ts b/packages/modules/order/src/models/transaction.ts index 659038ef595d4..63199a078531e 100644 --- a/packages/modules/order/src/models/transaction.ts +++ b/packages/modules/order/src/models/transaction.ts @@ -28,49 +28,49 @@ const OrderTransaction = model }) .indexes([ { - name: "ReferenceIdIndex", + name: "IDX_order_transaction_reference_id", on: ["reference_id"], unique: false, where: "deleted_at IS NOT NULL", }, { - name: "OrderIdIndex", + name: "IDX_order_transaction_order_id", on: ["order_id"], unique: false, where: "deleted_at IS NOT NULL", }, { - name: "ReturnIdIndex", + name: "IDX_order_transaction_return_id", on: ["return_id"], unique: false, where: "return_id IS NOT NULL AND deleted_at IS NOT NULL", }, { - name: "ExchangeIdIndex", + name: "IDX_order_transaction_exchange_id", on: ["exchange_id"], unique: false, where: "exchange_id IS NOT NULL AND deleted_at IS NOT NULL", }, { - name: "ClaimIdIndex", + name: "IDX_order_transaction_claim_id", on: ["claim_id"], unique: false, where: "claim_id IS NOT NULL AND deleted_at IS NOT NULL", }, { - name: "CurrencyCodeIndex", + name: "IDX_order_transaction_currency_code", on: ["currency_code"], unique: false, where: "deleted_at IS NOT NULL", }, { - name: "DeletedAtIndex", + name: "IDX_order_transaction_deleted_at", on: ["deleted_at"], unique: false, where: "deleted_at IS NOT NULL", }, { - name: "OrderIdVersionIndex", + name: "IDX_order_transaction_order_id_version", on: ["order_id", "version"], unique: false, where: "deleted_at IS NOT NULL", From 4a831fdbd9c6aaaa3b3e76c179b90683e7582ff4 Mon Sep 17 00:00:00 2001 From: Harminder Virk Date: Fri, 22 Nov 2024 18:50:07 +0530 Subject: [PATCH 068/175] chore: remove unused types --- .../utils/src/dml/helpers/entity-builder/define-relationship.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts b/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts index cf40a68b63a6f..b7966fcb2945e 100644 --- a/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts +++ b/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts @@ -16,7 +16,6 @@ import { rel, } from "@mikro-orm/core" import { camelToSnakeCase, pluralize } from "../../../common" -import { ForeignKey } from "../../../dal/mikro-orm/decorators/foreign-key" import { DmlEntity } from "../../entity" import { HasMany } from "../../relations/has-many" import { HasOne } from "../../relations/has-one" From 6ae6099f1095d3d460d8488517e72b4daa2e0976 Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Fri, 22 Nov 2024 10:21:34 -0300 Subject: [PATCH 069/175] wip --- packages/modules/order/src/models/line-item-adjustment.ts | 1 - packages/modules/order/src/models/line-item-tax-line.ts | 1 - 2 files changed, 2 deletions(-) diff --git a/packages/modules/order/src/models/line-item-adjustment.ts b/packages/modules/order/src/models/line-item-adjustment.ts index e60a20c68c81f..bef5ab8ca20fd 100644 --- a/packages/modules/order/src/models/line-item-adjustment.ts +++ b/packages/modules/order/src/models/line-item-adjustment.ts @@ -13,7 +13,6 @@ const OrderLineItemAdjustment = model item: model.belongsTo(() => OrderLineItem, { mappedBy: "adjustments", }), - item_id: model.text(), }) .indexes([ { diff --git a/packages/modules/order/src/models/line-item-tax-line.ts b/packages/modules/order/src/models/line-item-tax-line.ts index e7021c65621af..426daa9f03958 100644 --- a/packages/modules/order/src/models/line-item-tax-line.ts +++ b/packages/modules/order/src/models/line-item-tax-line.ts @@ -13,7 +13,6 @@ const OrderLineItemTaxLine = model item: model.belongsTo(() => OrderLineItem, { mappedBy: "tax_lines", }), - item_id: model.text(), }) .indexes([ { From f6143e1c84b0fdae7c4a8bbb50f8227f0400d314 Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Fri, 22 Nov 2024 10:30:58 -0300 Subject: [PATCH 070/175] changes --- packages/modules/order/src/models/claim.ts | 2 ++ packages/modules/order/src/models/exchange.ts | 3 ++- packages/modules/order/src/models/line-item.ts | 5 +++++ packages/modules/order/src/models/order-change.ts | 6 +++--- packages/modules/order/src/models/order.ts | 2 ++ packages/modules/order/src/models/return.ts | 3 ++- 6 files changed, 16 insertions(+), 5 deletions(-) diff --git a/packages/modules/order/src/models/claim.ts b/packages/modules/order/src/models/claim.ts index 1fcdaf87ec632..862d4b6617a3a 100644 --- a/packages/modules/order/src/models/claim.ts +++ b/packages/modules/order/src/models/claim.ts @@ -1,6 +1,7 @@ import { ClaimType, model } from "@medusajs/framework/utils" import ClaimItem from "./claim-item" import Order from "./order" +import OrderChange from "./order-change" import OrderShipping from "./order-shipping-method" import Return from "./return" import OrderTransaction from "./transaction" @@ -32,6 +33,7 @@ const OrderClaim = model transactions: model.hasMany(() => OrderTransaction, { mappedBy: "claim", }), + changes: model.hasMany(() => OrderChange), created_by: model.text().nullable(), canceled_at: model.dateTime().nullable(), metadata: model.json().nullable(), diff --git a/packages/modules/order/src/models/exchange.ts b/packages/modules/order/src/models/exchange.ts index 5fc993aa9476e..df16d2d450e5e 100644 --- a/packages/modules/order/src/models/exchange.ts +++ b/packages/modules/order/src/models/exchange.ts @@ -1,5 +1,5 @@ import { model } from "@medusajs/framework/utils" -import { OrderExchangeItem, OrderTransaction } from "@models" +import { OrderChange, OrderExchangeItem, OrderTransaction } from "@models" import Order from "./order" import OrderShipping from "./order-shipping-method" import Return from "./return" @@ -28,6 +28,7 @@ const OrderExchange = model transactions: model.hasMany(() => OrderTransaction, { mappedBy: "exchange", }), + changes: model.hasMany(() => OrderChange), created_by: model.text().nullable(), metadata: model.json().nullable(), canceled_at: model.dateTime().nullable(), diff --git a/packages/modules/order/src/models/line-item.ts b/packages/modules/order/src/models/line-item.ts index e6a2df4dd9ec4..4e799d79b720e 100644 --- a/packages/modules/order/src/models/line-item.ts +++ b/packages/modules/order/src/models/line-item.ts @@ -1,6 +1,7 @@ import { model } from "@medusajs/framework/utils" import OrderLineItemAdjustment from "./line-item-adjustment" import OrderLineItemTaxLine from "./line-item-tax-line" +import OrderItem from "./order-item" const OrderLineItem = model .define("OrderLineItem", { @@ -36,6 +37,10 @@ const OrderLineItem = model mappedBy: "item", }), metadata: model.json().nullable(), + + items: model.hasMany(() => OrderItem, { + mappedBy: "item", + }), }) .indexes([ { diff --git a/packages/modules/order/src/models/order-change.ts b/packages/modules/order/src/models/order-change.ts index 595909c172ee8..53953a2eca29a 100644 --- a/packages/modules/order/src/models/order-change.ts +++ b/packages/modules/order/src/models/order-change.ts @@ -13,17 +13,17 @@ const OrderChange = model }), return: model .belongsTo(() => Return, { - mappedBy: "order_changes", + mappedBy: "changes", }) .nullable(), claim: model .belongsTo(() => OrderClaim, { - mappedBy: "order_changes", + mappedBy: "changes", }) .nullable(), exchange: model .belongsTo(() => OrderExchange, { - mappedBy: "order_changes", + mappedBy: "changes", }) .nullable(), version: model.number(), diff --git a/packages/modules/order/src/models/order.ts b/packages/modules/order/src/models/order.ts index 92cffff7933c8..643ad0f844c07 100644 --- a/packages/modules/order/src/models/order.ts +++ b/packages/modules/order/src/models/order.ts @@ -2,6 +2,7 @@ import { model, OrderStatus } from "@medusajs/framework/utils" import OrderAddress from "./address" import OrderClaim from "./claim" import OrderExchange from "./exchange" +import OrderChange from "./order-change" import OrderItem from "./order-item" import OrderShipping from "./order-shipping-method" import OrderSummary from "./order-summary" @@ -47,6 +48,7 @@ const Order = model returns: model.hasMany(() => Return, { mappedBy: "order", }), + changes: model.hasMany(() => OrderChange), }) .indexes([ { diff --git a/packages/modules/order/src/models/return.ts b/packages/modules/order/src/models/return.ts index 96f46ccedac91..1d4275b4ab186 100644 --- a/packages/modules/order/src/models/return.ts +++ b/packages/modules/order/src/models/return.ts @@ -1,5 +1,5 @@ import { model, ReturnStatus } from "@medusajs/framework/utils" -import { OrderTransaction, ReturnItem } from "@models" +import { OrderChange, OrderTransaction, ReturnItem } from "@models" import Claim from "./claim" import Exchange from "./exchange" import Order from "./order" @@ -33,6 +33,7 @@ const Return = model transactions: model.hasMany(() => OrderTransaction, { mappedBy: "return", }), + changes: model.hasMany(() => OrderChange), created_by: model.text().nullable(), metadata: model.json().nullable(), requested_at: model.dateTime().nullable(), From a4555d10d372e103439871201b388e20a7f9d442 Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Fri, 22 Nov 2024 10:47:52 -0300 Subject: [PATCH 071/175] rm raw --- packages/modules/order/src/models/claim-item.ts | 1 - packages/modules/order/src/models/claim.ts | 1 - .../modules/order/src/models/exchange-item.ts | 1 - packages/modules/order/src/models/exchange.ts | 1 - .../order/src/models/line-item-adjustment.ts | 1 - .../order/src/models/line-item-tax-line.ts | 1 - packages/modules/order/src/models/line-item.ts | 2 -- .../order/src/models/order-change-action.ts | 1 - packages/modules/order/src/models/order-item.ts | 10 ---------- .../modules/order/src/models/return-item.ts | 3 --- packages/modules/order/src/models/return.ts | 11 +++++------ .../src/models/shipping-method-adjustment.ts | 1 - .../src/models/shipping-method-tax-line.ts | 1 - .../modules/order/src/models/shipping-method.ts | 1 - .../modules/order/src/models/transaction.ts | 17 ++++++++--------- 15 files changed, 13 insertions(+), 40 deletions(-) diff --git a/packages/modules/order/src/models/claim-item.ts b/packages/modules/order/src/models/claim-item.ts index ef573f2d3a85c..8f5547c097448 100644 --- a/packages/modules/order/src/models/claim-item.ts +++ b/packages/modules/order/src/models/claim-item.ts @@ -11,7 +11,6 @@ const OrderClaimItem = model }), reason: model.enum(ClaimReason).nullable(), quantity: model.bigNumber(), - raw_quantity: model.json(), claim: model.belongsTo(() => Claim, { mappedBy: "items", }), diff --git a/packages/modules/order/src/models/claim.ts b/packages/modules/order/src/models/claim.ts index 862d4b6617a3a..6b40415d3337a 100644 --- a/packages/modules/order/src/models/claim.ts +++ b/packages/modules/order/src/models/claim.ts @@ -20,7 +20,6 @@ const OrderClaim = model type: model.enum(ClaimType), no_notification: model.boolean().nullable(), refund_amount: model.bigNumber().nullable(), - raw_refund_amount: model.json(), additional_items: model.hasMany(() => ClaimItem, { mappedBy: "claim", }), diff --git a/packages/modules/order/src/models/exchange-item.ts b/packages/modules/order/src/models/exchange-item.ts index 8708cc365b7ec..eb6ce6e6de556 100644 --- a/packages/modules/order/src/models/exchange-item.ts +++ b/packages/modules/order/src/models/exchange-item.ts @@ -6,7 +6,6 @@ const OrderExchangeItem = model .define("OrderExchangeItem", { id: model.id({ prefix: "oexcitem" }).primaryKey(), quantity: model.bigNumber(), - raw_quantity: model.json(), exchange: model.belongsTo(() => Exchange, { mappedBy: "items", }), diff --git a/packages/modules/order/src/models/exchange.ts b/packages/modules/order/src/models/exchange.ts index df16d2d450e5e..a11b6f20d6236 100644 --- a/packages/modules/order/src/models/exchange.ts +++ b/packages/modules/order/src/models/exchange.ts @@ -17,7 +17,6 @@ const OrderExchange = model display_id: model.number(), no_notification: model.boolean().nullable(), difference_due: model.bigNumber().nullable(), - raw_difference_due: model.json(), allow_backorder: model.boolean().default(false), additional_items: model.hasMany(() => OrderExchangeItem, { mappedBy: "exchange", diff --git a/packages/modules/order/src/models/line-item-adjustment.ts b/packages/modules/order/src/models/line-item-adjustment.ts index bef5ab8ca20fd..fb6065f70f434 100644 --- a/packages/modules/order/src/models/line-item-adjustment.ts +++ b/packages/modules/order/src/models/line-item-adjustment.ts @@ -8,7 +8,6 @@ const OrderLineItemAdjustment = model promotion_id: model.text().nullable(), code: model.text().nullable(), amount: model.bigNumber(), - raw_amount: model.json(), provider_id: model.text().nullable(), item: model.belongsTo(() => OrderLineItem, { mappedBy: "adjustments", diff --git a/packages/modules/order/src/models/line-item-tax-line.ts b/packages/modules/order/src/models/line-item-tax-line.ts index 426daa9f03958..d4a8e70bbddad 100644 --- a/packages/modules/order/src/models/line-item-tax-line.ts +++ b/packages/modules/order/src/models/line-item-tax-line.ts @@ -8,7 +8,6 @@ const OrderLineItemTaxLine = model tax_rate_id: model.text().nullable(), code: model.text(), rate: model.bigNumber(), - raw_rate: model.json(), provider_id: model.text().nullable(), item: model.belongsTo(() => OrderLineItem, { mappedBy: "tax_lines", diff --git a/packages/modules/order/src/models/line-item.ts b/packages/modules/order/src/models/line-item.ts index 4e799d79b720e..d251fe7c001c0 100644 --- a/packages/modules/order/src/models/line-item.ts +++ b/packages/modules/order/src/models/line-item.ts @@ -26,9 +26,7 @@ const OrderLineItem = model is_discountable: model.boolean().default(true), is_tax_inclusive: model.boolean().default(false), compare_at_unit_price: model.bigNumber().nullable(), - raw_compare_at_unit_price: model.json().nullable(), unit_price: model.bigNumber(), - raw_unit_price: model.json(), is_custom_price: model.boolean().default(false), tax_lines: model.hasMany(() => OrderLineItemTaxLine, { mappedBy: "item", diff --git a/packages/modules/order/src/models/order-change-action.ts b/packages/modules/order/src/models/order-change-action.ts index 5fc54ba384b16..3d0bbba3b25fb 100644 --- a/packages/modules/order/src/models/order-change-action.ts +++ b/packages/modules/order/src/models/order-change-action.ts @@ -15,7 +15,6 @@ const OrderChangeAction = model action: model.text(), details: model.json(), amount: model.bigNumber().nullable(), - raw_amount: model.json().nullable(), internal_note: model.text().nullable(), applied: model.boolean().default(false), }) diff --git a/packages/modules/order/src/models/order-item.ts b/packages/modules/order/src/models/order-item.ts index 902f85f8a9140..81aa9b72dde33 100644 --- a/packages/modules/order/src/models/order-item.ts +++ b/packages/modules/order/src/models/order-item.ts @@ -13,25 +13,15 @@ const OrderItem = model mappedBy: "items", }), unit_price: model.bigNumber().nullable(), - raw_unit_price: model.json().nullable(), compare_at_unit_price: model.bigNumber().nullable(), - raw_compare_at_unit_price: model.json().nullable(), quantity: model.bigNumber(), - raw_quantity: model.json(), fulfilled_quantity: model.bigNumber().default(0), - raw_fulfilled_quantity: model.json(), delivered_quantity: model.bigNumber().default(0), - raw_delivered_quantity: model.json(), shipped_quantity: model.bigNumber().default(0), - raw_shipped_quantity: model.json(), return_requested_quantity: model.bigNumber().default(0), - raw_return_requested_quantity: model.json(), return_received_quantity: model.bigNumber().default(0), - raw_return_received_quantity: model.json(), return_dismissed_quantity: model.bigNumber().default(0), - raw_return_dismissed_quantity: model.json(), written_off_quantity: model.bigNumber().default(0), - raw_written_off_quantity: model.json(), metadata: model.json().nullable(), }) .indexes([ diff --git a/packages/modules/order/src/models/return-item.ts b/packages/modules/order/src/models/return-item.ts index 530b0a5351bfd..5bf42f7e285a4 100644 --- a/packages/modules/order/src/models/return-item.ts +++ b/packages/modules/order/src/models/return-item.ts @@ -12,11 +12,8 @@ const ReturnItem = model }) .nullable(), quantity: model.bigNumber(), - raw_quantity: model.json(), received_quantity: model.bigNumber().default(0), - raw_received_quantity: model.json(), damaged_quantity: model.bigNumber().default(0), - raw_damaged_quantity: model.json(), return: model.belongsTo(() => Return, { mappedBy: "return_items", }), diff --git a/packages/modules/order/src/models/return.ts b/packages/modules/order/src/models/return.ts index 1d4275b4ab186..7d1344013c34c 100644 --- a/packages/modules/order/src/models/return.ts +++ b/packages/modules/order/src/models/return.ts @@ -1,13 +1,10 @@ import { model, ReturnStatus } from "@medusajs/framework/utils" -import { OrderChange, OrderTransaction, ReturnItem } from "@models" -import Claim from "./claim" -import Exchange from "./exchange" -import Order from "./order" -import OrderShipping from "./order-shipping-method" +import { OrderChange, OrderTransaction } from "@models" const Return = model .define("Return", { id: model.id({ prefix: "return" }).primaryKey(), + /* order: model.belongsTo(() => Order, { mappedBy: "returns", }), @@ -17,19 +14,21 @@ const Return = model claim: model.belongsTo(() => Claim, { mappedBy: "return", }), + */ order_version: model.number(), display_id: model.number(), status: model.enum(ReturnStatus).default(ReturnStatus.OPEN), location_id: model.text().nullable(), no_notification: model.boolean().nullable(), refund_amount: model.bigNumber().nullable(), - raw_refund_amount: model.json(), + /* items: model.hasMany(() => ReturnItem, { mappedBy: "return", }), shipping_methods: model.hasMany(() => OrderShipping, { mappedBy: "return", }), + */ transactions: model.hasMany(() => OrderTransaction, { mappedBy: "return", }), diff --git a/packages/modules/order/src/models/shipping-method-adjustment.ts b/packages/modules/order/src/models/shipping-method-adjustment.ts index 6e1366c2e345c..a3cdc172d29ae 100644 --- a/packages/modules/order/src/models/shipping-method-adjustment.ts +++ b/packages/modules/order/src/models/shipping-method-adjustment.ts @@ -8,7 +8,6 @@ const OrderShippingMethodAdjustment = model promotion_id: model.text().nullable(), code: model.text().nullable(), amount: model.bigNumber(), - raw_amount: model.json(), provider_id: model.text().nullable(), shipping_method: model.belongsTo(() => OrderShippingMethod, { mappedBy: "adjustments", diff --git a/packages/modules/order/src/models/shipping-method-tax-line.ts b/packages/modules/order/src/models/shipping-method-tax-line.ts index 56ca93a355375..f1630eaf920c4 100644 --- a/packages/modules/order/src/models/shipping-method-tax-line.ts +++ b/packages/modules/order/src/models/shipping-method-tax-line.ts @@ -8,7 +8,6 @@ const OrderShippingMethodTaxLine = model tax_rate_id: model.text().nullable(), code: model.text(), rate: model.bigNumber(), - raw_rate: model.json(), provider_id: model.text().nullable(), shipping_method: model.belongsTo(() => OrderShippingMethod, { mappedBy: "tax_lines", diff --git a/packages/modules/order/src/models/shipping-method.ts b/packages/modules/order/src/models/shipping-method.ts index e9de38874d2d5..3fc6bfc4dde23 100644 --- a/packages/modules/order/src/models/shipping-method.ts +++ b/packages/modules/order/src/models/shipping-method.ts @@ -8,7 +8,6 @@ const OrderShippingMethod = model name: model.text(), description: model.json().nullable(), amount: model.bigNumber(), - raw_amount: model.json(), is_tax_inclusive: model.boolean().default(false), is_custom_amount: model.boolean().default(false), shipping_option_id: model.text().nullable(), diff --git a/packages/modules/order/src/models/transaction.ts b/packages/modules/order/src/models/transaction.ts index 63199a078531e..319fea0ae7506 100644 --- a/packages/modules/order/src/models/transaction.ts +++ b/packages/modules/order/src/models/transaction.ts @@ -1,27 +1,26 @@ import { model } from "@medusajs/framework/utils" +import OrderClaim from "./claim" +import OrderExchange from "./exchange" +import Order from "./order" +import Return from "./return" const OrderTransaction = model .define("OrderTransaction", { id: model.id({ prefix: "ordtrx" }).primaryKey(), - order_id: model.text(), - order: model.belongsTo(() => "Order", { + order: model.belongsTo(() => Order, { mappedBy: "transactions", }), - return_id: model.text().nullable(), - return: model.belongsTo(() => "Return", { + return: model.belongsTo(() => Return, { mappedBy: "transactions", }), - exchange_id: model.text().nullable(), - exchange: model.belongsTo(() => "Exchange", { + exchange: model.belongsTo(() => OrderExchange, { mappedBy: "transactions", }), - claim_id: model.text().nullable(), - claim: model.belongsTo(() => "Claim", { + claim: model.belongsTo(() => OrderClaim, { mappedBy: "transactions", }), version: model.number().default(1), amount: model.bigNumber(), - raw_amount: model.json(), currency_code: model.text(), reference: model.text().nullable(), reference_id: model.text().nullable(), From b816d56e077ef7e43b8a16a3d5bc051d1f256272 Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Fri, 22 Nov 2024 11:24:17 -0300 Subject: [PATCH 072/175] autoincrement --- packages/core/types/src/dml/index.ts | 1 + .../__tests__/autoincrement-property.spec.ts | 20 +++++++++ packages/core/utils/src/dml/entity-builder.ts | 21 ++++++++++ .../helpers/entity-builder/define-property.ts | 19 ++++++++- .../utils/src/dml/properties/autoincrement.ts | 41 +++++++++++++++++++ packages/modules/order/src/models/claim.ts | 2 +- packages/modules/order/src/models/exchange.ts | 2 +- .../order/src/models/order-change-action.ts | 2 +- packages/modules/order/src/models/order.ts | 2 +- packages/modules/order/src/models/return.ts | 12 +++--- 10 files changed, 110 insertions(+), 12 deletions(-) create mode 100644 packages/core/utils/src/dml/__tests__/autoincrement-property.spec.ts create mode 100644 packages/core/utils/src/dml/properties/autoincrement.ts diff --git a/packages/core/types/src/dml/index.ts b/packages/core/types/src/dml/index.ts index 4f87937e3c44a..52614dba47023 100644 --- a/packages/core/types/src/dml/index.ts +++ b/packages/core/types/src/dml/index.ts @@ -41,6 +41,7 @@ export type KnownDataTypes = | "enum" | "number" | "bigNumber" + | "bigSerial" | "dateTime" | "array" | "json" diff --git a/packages/core/utils/src/dml/__tests__/autoincrement-property.spec.ts b/packages/core/utils/src/dml/__tests__/autoincrement-property.spec.ts new file mode 100644 index 0000000000000..498d060e8d07a --- /dev/null +++ b/packages/core/utils/src/dml/__tests__/autoincrement-property.spec.ts @@ -0,0 +1,20 @@ +import { expectTypeOf } from "expect-type" +import { AutoIncrementProperty } from "../properties/autoincrement" + +describe("Autoincrement property", () => { + test("create autoincrement property type", () => { + const property = new AutoIncrementProperty() + + expectTypeOf(property["$dataType"]).toEqualTypeOf() + expect(property.parse("display_id")).toEqual({ + fieldName: "display_id", + dataType: { + name: "bigSerial", + options: {}, + }, + nullable: false, + indexes: [], + relationships: [], + }) + }) +}) diff --git a/packages/core/utils/src/dml/entity-builder.ts b/packages/core/utils/src/dml/entity-builder.ts index ac4396d7ebf15..0860b8d016c46 100644 --- a/packages/core/utils/src/dml/entity-builder.ts +++ b/packages/core/utils/src/dml/entity-builder.ts @@ -13,6 +13,7 @@ import { DMLSchemaDefaults, } from "./helpers/entity-builder/create-default-properties" import { ArrayProperty } from "./properties/array" +import { AutoIncrementProperty } from "./properties/autoincrement" import { BigNumberProperty } from "./properties/big-number" import { BooleanProperty } from "./properties/boolean" import { DateTimeProperty } from "./properties/date-time" @@ -239,6 +240,26 @@ export class EntityBuilder { return new BigNumberProperty() } + /** + * This method defines an autoincrement property. + * + * @example + * import { model } from "@medusajs/framework/utils" + * + * const MyCustom = model.define("my_custom", { + * serial_id: model.autoincrement(), + * // ... + * }) + * + * export default MyCustom + * + * @customNamespace Property + */ + + autoincrement() { + return new AutoIncrementProperty() + } + /** * This method defines an array of strings property. * diff --git a/packages/core/utils/src/dml/helpers/entity-builder/define-property.ts b/packages/core/utils/src/dml/helpers/entity-builder/define-property.ts index 13fd90d7c0ff2..5429e76c21c39 100644 --- a/packages/core/utils/src/dml/helpers/entity-builder/define-property.ts +++ b/packages/core/utils/src/dml/helpers/entity-builder/define-property.ts @@ -4,8 +4,6 @@ import { PropertyMetadata, PropertyType, } from "@medusajs/types" -import { MikroOrmBigNumberProperty } from "../../../dal" -import { generateEntityId, isDefined } from "../../../common" import { ArrayType, BeforeCreate, @@ -15,6 +13,8 @@ import { Property, Utils, } from "@mikro-orm/core" +import { generateEntityId, isDefined } from "../../../common" +import { MikroOrmBigNumberProperty } from "../../../dal" import { PrimaryKeyModifier } from "../../properties/primary-key" /** @@ -31,6 +31,7 @@ const COLUMN_TYPES: { dateTime: "timestamptz", number: "integer", bigNumber: "numeric", + bigSerial: "bigserial", text: "text", json: "jsonb", array: "array", @@ -50,6 +51,7 @@ const PROPERTY_TYPES: { dateTime: "date", number: "number", bigNumber: "number", + bigSerial: "number", text: "string", json: "any", array: "string[]", @@ -235,6 +237,19 @@ export function defineProperty( return } + /** + * Handling bigSerial property separately to set the column type + */ + if (field.dataType.name === "bigSerial") { + Property({ + columnType: "bigserial", + type: "number", + nullable: field.nullable, + fieldName: field.fieldName, + })(MikroORMEntity.prototype, field.fieldName) + return + } + /** * Define rest of properties */ diff --git a/packages/core/utils/src/dml/properties/autoincrement.ts b/packages/core/utils/src/dml/properties/autoincrement.ts new file mode 100644 index 0000000000000..ce25a78c73661 --- /dev/null +++ b/packages/core/utils/src/dml/properties/autoincrement.ts @@ -0,0 +1,41 @@ +import { BaseProperty } from "./base" +import { PrimaryKeyModifier } from "./primary-key" + +/** + * The AutoIncrementProperty is used to define a bigserial + * property + */ +export class AutoIncrementProperty extends BaseProperty { + protected dataType: { + name: "bigSerial" + options: {} + } + + /** + * This method indicates that the property is the data model's primary key. + * + * @example + * import { model } from "@medusajs/framework/utils" + * + * const Product = model.define("Product", { + * id: model.autoincrement().primaryKey(), + * // ... + * }) + * + * export default Product + * + * @customNamespace Property Configuration Methods + */ + primaryKey() { + return new PrimaryKeyModifier(this) + } + + constructor(options?: { primaryKey?: boolean }) { + super() + + this.dataType = { + name: "bigSerial", + options: { ...options }, + } + } +} diff --git a/packages/modules/order/src/models/claim.ts b/packages/modules/order/src/models/claim.ts index 6b40415d3337a..42796b4f31988 100644 --- a/packages/modules/order/src/models/claim.ts +++ b/packages/modules/order/src/models/claim.ts @@ -16,7 +16,7 @@ const OrderClaim = model mappedBy: "claim", }), order_version: model.number(), - display_id: model.number(), // TODO: auto increment + display_id: model.autoincrement(), type: model.enum(ClaimType), no_notification: model.boolean().nullable(), refund_amount: model.bigNumber().nullable(), diff --git a/packages/modules/order/src/models/exchange.ts b/packages/modules/order/src/models/exchange.ts index a11b6f20d6236..aef594f0a14cb 100644 --- a/packages/modules/order/src/models/exchange.ts +++ b/packages/modules/order/src/models/exchange.ts @@ -14,7 +14,7 @@ const OrderExchange = model mappedBy: "exchange", }), order_version: model.number(), - display_id: model.number(), + display_id: model.autoincrement(), no_notification: model.boolean().nullable(), difference_due: model.bigNumber().nullable(), allow_backorder: model.boolean().default(false), diff --git a/packages/modules/order/src/models/order-change-action.ts b/packages/modules/order/src/models/order-change-action.ts index 3d0bbba3b25fb..c3527cd0f9d6e 100644 --- a/packages/modules/order/src/models/order-change-action.ts +++ b/packages/modules/order/src/models/order-change-action.ts @@ -3,7 +3,7 @@ import { model } from "@medusajs/framework/utils" const OrderChangeAction = model .define("OrderChangeAction", { id: model.id({ prefix: "ordchact" }).primaryKey(), - ordering: model.number(), + ordering: model.autoincrement(), order_id: model.text().nullable(), return_id: model.text().nullable(), claim_id: model.text().nullable(), diff --git a/packages/modules/order/src/models/order.ts b/packages/modules/order/src/models/order.ts index 643ad0f844c07..b146e36bcc818 100644 --- a/packages/modules/order/src/models/order.ts +++ b/packages/modules/order/src/models/order.ts @@ -12,7 +12,7 @@ import OrderTransaction from "./transaction" const Order = model .define("Order", { id: model.id({ prefix: "order" }).primaryKey(), - display_id: model.number(), // TODO: numberic .searchable() + display_id: model.autoincrement(), region_id: model.text().nullable(), customer_id: model.text().nullable(), version: model.number().default(1), diff --git a/packages/modules/order/src/models/return.ts b/packages/modules/order/src/models/return.ts index 7d1344013c34c..9f83281f6f909 100644 --- a/packages/modules/order/src/models/return.ts +++ b/packages/modules/order/src/models/return.ts @@ -1,10 +1,13 @@ import { model, ReturnStatus } from "@medusajs/framework/utils" -import { OrderChange, OrderTransaction } from "@models" +import { OrderChange, OrderTransaction, ReturnItem } from "@models" +import Claim from "./claim" +import Exchange from "./exchange" +import Order from "./order" +import OrderShipping from "./order-shipping-method" const Return = model .define("Return", { id: model.id({ prefix: "return" }).primaryKey(), - /* order: model.belongsTo(() => Order, { mappedBy: "returns", }), @@ -14,21 +17,18 @@ const Return = model claim: model.belongsTo(() => Claim, { mappedBy: "return", }), - */ order_version: model.number(), - display_id: model.number(), + display_id: model.autoincrement(), status: model.enum(ReturnStatus).default(ReturnStatus.OPEN), location_id: model.text().nullable(), no_notification: model.boolean().nullable(), refund_amount: model.bigNumber().nullable(), - /* items: model.hasMany(() => ReturnItem, { mappedBy: "return", }), shipping_methods: model.hasMany(() => OrderShipping, { mappedBy: "return", }), - */ transactions: model.hasMany(() => OrderTransaction, { mappedBy: "return", }), From 27b3a4fd7db90391221fd0339dda87458ef790f6 Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Fri, 22 Nov 2024 11:45:23 -0300 Subject: [PATCH 073/175] wip --- packages/core/utils/src/dml/properties/index.ts | 1 + packages/modules/order/src/models/order-shipping-method.ts | 2 +- packages/modules/order/src/models/return-reason.ts | 4 ++++ .../modules/order/src/models/shipping-method-adjustment.ts | 1 - packages/modules/order/src/models/shipping-method.ts | 4 ++++ packages/modules/order/src/utils/apply-order-changes.ts | 4 ++-- 6 files changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/core/utils/src/dml/properties/index.ts b/packages/core/utils/src/dml/properties/index.ts index 9c55e703660a0..5d85ca547ca93 100644 --- a/packages/core/utils/src/dml/properties/index.ts +++ b/packages/core/utils/src/dml/properties/index.ts @@ -1,4 +1,5 @@ export * from "./array" +export * from "./autoincrement" export * from "./base" export * from "./big-number" export * from "./boolean" diff --git a/packages/modules/order/src/models/order-shipping-method.ts b/packages/modules/order/src/models/order-shipping-method.ts index 0762bdd155809..e1bc26a14c958 100644 --- a/packages/modules/order/src/models/order-shipping-method.ts +++ b/packages/modules/order/src/models/order-shipping-method.ts @@ -9,7 +9,7 @@ const OrderShipping = model .define("OrderShipping", { id: model.id({ prefix: "ordspmv" }).primaryKey(), order: model.belongsTo(() => Order, { - mappedBy: "shippings", + mappedBy: "shipping_methods", }), return: model .belongsTo(() => Return, { diff --git a/packages/modules/order/src/models/return-reason.ts b/packages/modules/order/src/models/return-reason.ts index 176b855f04c25..89a565f6fe87c 100644 --- a/packages/modules/order/src/models/return-reason.ts +++ b/packages/modules/order/src/models/return-reason.ts @@ -1,4 +1,5 @@ import { model } from "@medusajs/framework/utils" +import ReturnItem from "./return-item" const ReturnReason = model .define("ReturnReason", { @@ -13,6 +14,9 @@ const ReturnReason = model return_reason_children: model.hasMany(() => ReturnReason, { mappedBy: "parent_return_reason", }), + return_items: model.hasMany(() => ReturnItem, { + mappedBy: "reason", + }), metadata: model.json().nullable(), }) .indexes([ diff --git a/packages/modules/order/src/models/shipping-method-adjustment.ts b/packages/modules/order/src/models/shipping-method-adjustment.ts index a3cdc172d29ae..f7c3c5f5bf36f 100644 --- a/packages/modules/order/src/models/shipping-method-adjustment.ts +++ b/packages/modules/order/src/models/shipping-method-adjustment.ts @@ -12,7 +12,6 @@ const OrderShippingMethodAdjustment = model shipping_method: model.belongsTo(() => OrderShippingMethod, { mappedBy: "adjustments", }), - shipping_method_id: model.text(), }) .indexes([ { diff --git a/packages/modules/order/src/models/shipping-method.ts b/packages/modules/order/src/models/shipping-method.ts index 3fc6bfc4dde23..c3edd9b9e2ecc 100644 --- a/packages/modules/order/src/models/shipping-method.ts +++ b/packages/modules/order/src/models/shipping-method.ts @@ -1,4 +1,5 @@ import { model } from "@medusajs/framework/utils" +import OrderShipping from "./order-shipping-method" import OrderShippingMethodAdjustment from "./shipping-method-adjustment" import OrderShippingMethodTaxLine from "./shipping-method-tax-line" @@ -19,6 +20,9 @@ const OrderShippingMethod = model adjustments: model.hasMany(() => OrderShippingMethodAdjustment, { mappedBy: "shipping_method", }), + shipping_methods: model.hasMany(() => OrderShipping, { + mappedBy: "shipping_method", + }), }) .indexes([ { diff --git a/packages/modules/order/src/utils/apply-order-changes.ts b/packages/modules/order/src/utils/apply-order-changes.ts index 4d095d84b28d3..3b198070e8f96 100644 --- a/packages/modules/order/src/utils/apply-order-changes.ts +++ b/packages/modules/order/src/utils/apply-order-changes.ts @@ -22,8 +22,8 @@ export function applyChangesToOrder( addActionReferenceToObject?: boolean } ) { - const itemsToUpsert: OrderItem[] = [] - const shippingMethodsToUpsert: OrderShippingMethod[] = [] + const itemsToUpsert: (typeof OrderItem)[] = [] + const shippingMethodsToUpsert: (typeof OrderShippingMethod)[] = [] const summariesToUpsert: any[] = [] const orderToUpdate: any[] = [] From 02c08be5d877780a617bfb5e76f50e2a04044164 Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Fri, 22 Nov 2024 14:19:13 -0300 Subject: [PATCH 074/175] rel --- packages/modules/order/src/models/claim-item.ts | 2 +- .../modules/order/src/models/exchange-item.ts | 4 ++-- packages/modules/order/src/models/line-item.ts | 15 +++++++++++++-- .../order/src/models/order-shipping-method.ts | 2 +- .../modules/order/src/models/order-summary.ts | 4 ++-- packages/modules/order/src/models/order.ts | 2 +- packages/modules/order/src/models/return-item.ts | 2 +- 7 files changed, 21 insertions(+), 10 deletions(-) diff --git a/packages/modules/order/src/models/claim-item.ts b/packages/modules/order/src/models/claim-item.ts index 8f5547c097448..95c21a4967e7a 100644 --- a/packages/modules/order/src/models/claim-item.ts +++ b/packages/modules/order/src/models/claim-item.ts @@ -15,7 +15,7 @@ const OrderClaimItem = model mappedBy: "items", }), item: model.belongsTo(() => OrderLineItem, { - mappedBy: "items", + mappedBy: "claim_items", }), is_additional_item: model.boolean().default(false), note: model.text().nullable(), diff --git a/packages/modules/order/src/models/exchange-item.ts b/packages/modules/order/src/models/exchange-item.ts index eb6ce6e6de556..2f9db9aa6c5c9 100644 --- a/packages/modules/order/src/models/exchange-item.ts +++ b/packages/modules/order/src/models/exchange-item.ts @@ -7,10 +7,10 @@ const OrderExchangeItem = model id: model.id({ prefix: "oexcitem" }).primaryKey(), quantity: model.bigNumber(), exchange: model.belongsTo(() => Exchange, { - mappedBy: "items", + mappedBy: "additional_items", }), item: model.belongsTo(() => OrderLineItem, { - mappedBy: "items", + mappedBy: "exchange_items", }), note: model.text().nullable(), metadata: model.json().nullable(), diff --git a/packages/modules/order/src/models/line-item.ts b/packages/modules/order/src/models/line-item.ts index d251fe7c001c0..59e3e2e3e1156 100644 --- a/packages/modules/order/src/models/line-item.ts +++ b/packages/modules/order/src/models/line-item.ts @@ -1,7 +1,10 @@ import { model } from "@medusajs/framework/utils" +import OrderClaimItem from "./claim-item" +import OrderExchangeItem from "./exchange-item" import OrderLineItemAdjustment from "./line-item-adjustment" import OrderLineItemTaxLine from "./line-item-tax-line" import OrderItem from "./order-item" +import ReturnItem from "./return-item" const OrderLineItem = model .define("OrderLineItem", { @@ -28,17 +31,25 @@ const OrderLineItem = model compare_at_unit_price: model.bigNumber().nullable(), unit_price: model.bigNumber(), is_custom_price: model.boolean().default(false), + metadata: model.json().nullable(), tax_lines: model.hasMany(() => OrderLineItemTaxLine, { mappedBy: "item", }), adjustments: model.hasMany(() => OrderLineItemAdjustment, { mappedBy: "item", }), - metadata: model.json().nullable(), - items: model.hasMany(() => OrderItem, { mappedBy: "item", }), + return_items: model.hasMany(() => ReturnItem, { + mappedBy: "item", + }), + claim_items: model.hasMany(() => OrderClaimItem, { + mappedBy: "item", + }), + exchange_items: model.hasMany(() => OrderExchangeItem, { + mappedBy: "item", + }), }) .indexes([ { diff --git a/packages/modules/order/src/models/order-shipping-method.ts b/packages/modules/order/src/models/order-shipping-method.ts index e1bc26a14c958..e2fde15d31a02 100644 --- a/packages/modules/order/src/models/order-shipping-method.ts +++ b/packages/modules/order/src/models/order-shipping-method.ts @@ -8,6 +8,7 @@ import OrderShippingMethod from "./shipping-method" const OrderShipping = model .define("OrderShipping", { id: model.id({ prefix: "ordspmv" }).primaryKey(), + version: model.number(), order: model.belongsTo(() => Order, { mappedBy: "shipping_methods", }), @@ -26,7 +27,6 @@ const OrderShipping = model mappedBy: "shipping_methods", }) .nullable(), - version: model.number(), shipping_method: model.belongsTo(() => OrderShippingMethod, { mappedBy: "shipping_methods", }), diff --git a/packages/modules/order/src/models/order-summary.ts b/packages/modules/order/src/models/order-summary.ts index bd52054387420..90a4c9efdd12d 100644 --- a/packages/modules/order/src/models/order-summary.ts +++ b/packages/modules/order/src/models/order-summary.ts @@ -4,11 +4,11 @@ import Order from "./order" const OrderSummary = model .define("OrderSummary", { id: model.id({ prefix: "ordsum" }).primaryKey(), + version: model.number().default(1), + totals: model.json(), order: model.belongsTo(() => Order, { mappedBy: "summary", }), - version: model.number().default(1), - totals: model.json(), }) .indexes([ { diff --git a/packages/modules/order/src/models/order.ts b/packages/modules/order/src/models/order.ts index b146e36bcc818..68f2e2f55a567 100644 --- a/packages/modules/order/src/models/order.ts +++ b/packages/modules/order/src/models/order.ts @@ -24,10 +24,10 @@ const Order = model shipping_address: model.belongsTo(() => OrderAddress), billing_address: model.belongsTo(() => OrderAddress), no_notification: model.boolean().nullable(), + metadata: model.json().nullable(), summary: model.hasMany(() => OrderSummary, { mappedBy: "order", }), - metadata: model.json().nullable(), items: model.hasMany(() => OrderItem, { mappedBy: "order", }), diff --git a/packages/modules/order/src/models/return-item.ts b/packages/modules/order/src/models/return-item.ts index 5bf42f7e285a4..baf5a39f35fb6 100644 --- a/packages/modules/order/src/models/return-item.ts +++ b/packages/modules/order/src/models/return-item.ts @@ -15,7 +15,7 @@ const ReturnItem = model received_quantity: model.bigNumber().default(0), damaged_quantity: model.bigNumber().default(0), return: model.belongsTo(() => Return, { - mappedBy: "return_items", + mappedBy: "items", }), item: model.belongsTo(() => OrderLineItem, { mappedBy: "return_items", From bfe67029f03c22d090ca99146b6c82637a266732 Mon Sep 17 00:00:00 2001 From: Harminder Virk Date: Mon, 25 Nov 2024 12:32:16 +0530 Subject: [PATCH 075/175] refactor: cleanup --- .../helpers/entity-builder/define-relationship.ts | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts b/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts index b7966fcb2945e..fd86676d7871c 100644 --- a/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts +++ b/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts @@ -237,7 +237,6 @@ export function defineBelongsToRelationship( return } - // this[relationship.name] ??= this[foreignKeyName] this[foreignKeyName] ??= this[relationship.name]?.id ?? null } @@ -470,19 +469,16 @@ export function defineManyToManyRelationship( .join("_") } - // if (!joinColumn || !inverseJoinColumn) { - // const otherSideRelationshipOptions = otherSideRelationship.parse("").options - // joinColumn ??= otherSideRelationshipOptions.joinColumn - // inverseJoinColumn ??= otherSideRelationshipOptions.inverseJoinColumn - // } - const otherSideRelationOptions = otherSideRelationship.parse("").options const isOwner = !!joinColumn || !!inverseJoinColumn || !!relationship.options.pivotTable || - // We cant infer it from the current entity so lets look at the otherside configuration as well to make a choice + /** + * We can't infer it from the current entity so lets + * look at the otherside configuration as well to make a choice + */ (!otherSideRelationOptions.pivotTable && !otherSideRelationOptions.joinColumn && !otherSideRelationOptions.inverseJoinColumn && From 974be36e33daac2b372fe43a562db17650bb2332 Mon Sep 17 00:00:00 2001 From: adrien2p Date: Mon, 25 Nov 2024 10:13:14 +0100 Subject: [PATCH 076/175] migration and models configuration adjustments --- .../dml/helpers/create-mikro-orm-entity.ts | 5 +- .../helpers/entity-builder/define-property.ts | 39 +- .../migrations/.snapshot-medusa-product.json | 356 ++++++++++++------ .../src/migrations/Migration20241125090957.ts | 173 +++++++++ .../product/src/models/product-collection.ts | 2 +- .../product/src/models/product-variant.ts | 2 +- .../modules/product/src/models/product.ts | 8 +- 7 files changed, 461 insertions(+), 124 deletions(-) create mode 100644 packages/modules/product/src/migrations/Migration20241125090957.ts diff --git a/packages/core/utils/src/dml/helpers/create-mikro-orm-entity.ts b/packages/core/utils/src/dml/helpers/create-mikro-orm-entity.ts index 0acae5b23e482..a599da2546ece 100644 --- a/packages/core/utils/src/dml/helpers/create-mikro-orm-entity.ts +++ b/packages/core/utils/src/dml/helpers/create-mikro-orm-entity.ts @@ -83,7 +83,10 @@ function createMikrORMEntity() { hasIdAlreadyDefined = true } - defineProperty(MikroORMEntity, name, property as PropertyType) + defineProperty(MikroORMEntity, property as PropertyType, { + propertyName: name, + tableName, + }) applyIndexes(MikroORMEntity, tableName, field) applySearchable(MikroORMEntity, field) } else { diff --git a/packages/core/utils/src/dml/helpers/entity-builder/define-property.ts b/packages/core/utils/src/dml/helpers/entity-builder/define-property.ts index 13fd90d7c0ff2..15a5962732315 100644 --- a/packages/core/utils/src/dml/helpers/entity-builder/define-property.ts +++ b/packages/core/utils/src/dml/helpers/entity-builder/define-property.ts @@ -16,6 +16,7 @@ import { Utils, } from "@mikro-orm/core" import { PrimaryKeyModifier } from "../../properties/primary-key" +import { applyEntityIndexes } from "../mikro-orm/apply-indexes" /** * DML entity data types to PostgreSQL data types via @@ -64,7 +65,8 @@ const PROPERTY_TYPES: { const SPECIAL_PROPERTIES: { [propertyName: string]: ( MikroORMEntity: EntityConstructor, - field: PropertyMetadata + field: PropertyMetadata, + tableName: string ) => void } = { created_at: (MikroORMEntity, field) => { @@ -88,6 +90,21 @@ const SPECIAL_PROPERTIES: { onUpdate: () => new Date(), })(MikroORMEntity.prototype, field.fieldName) }, + deleted_at: (MikroORMEntity, field, tableName) => { + Property({ + columnType: "timestamptz", + type: "date", + nullable: true, + fieldName: field.fieldName, + })(MikroORMEntity.prototype, field.fieldName) + + applyEntityIndexes(MikroORMEntity, tableName, [ + { + on: ["deleted_at"], + where: "deleted_at IS NULL", + }, + ]) + }, } /** @@ -95,8 +112,8 @@ const SPECIAL_PROPERTIES: { */ export function defineProperty( MikroORMEntity: EntityConstructor, - propertyName: string, - property: PropertyType + property: PropertyType, + { tableName, propertyName }: { tableName: string; propertyName: string } ) { const field = property.parse(propertyName) /** @@ -112,18 +129,18 @@ export function defineProperty( } if (SPECIAL_PROPERTIES[field.fieldName]) { - SPECIAL_PROPERTIES[field.fieldName](MikroORMEntity, field) + SPECIAL_PROPERTIES[field.fieldName](MikroORMEntity, field, tableName) return } - /** - * Defining an big number property - * A big number property always comes with a raw_{{ fieldName }} column - * where the config of the bigNumber is set. - * The `raw_` field is generated during DML schema generation as a json - * dataType. - */ if (field.dataType.name === "bigNumber") { + /** + * Defining an big number property + * A big number property always comes with a raw_{{ fieldName }} column + * where the config of the bigNumber is set. + * The `raw_` field is generated during DML schema generation as a json + * dataType. + */ MikroOrmBigNumberProperty({ nullable: field.nullable, fieldName: field.fieldName, diff --git a/packages/modules/product/src/migrations/.snapshot-medusa-product.json b/packages/modules/product/src/migrations/.snapshot-medusa-product.json index 93d23dfb7769f..3327db9d40844 100644 --- a/packages/modules/product/src/migrations/.snapshot-medusa-product.json +++ b/packages/modules/product/src/migrations/.snapshot-medusa-product.json @@ -82,6 +82,15 @@ "default": "0", "mappedType": "integer" }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "json" + }, "parent_category_id": { "name": "parent_category_id", "type": "text", @@ -122,28 +131,42 @@ "nullable": true, "length": 6, "mappedType": "datetime" - }, - "metadata": { - "name": "metadata", - "type": "jsonb", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "json" } }, "name": "product_category", "schema": "public", "indexes": [ { - "columnNames": [ - "deleted_at" - ], + "keyName": "IDX_product_category_parent_category_id", + "columnNames": [], "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_product_category_parent_category_id\" ON \"product_category\" (parent_category_id) WHERE deleted_at IS NULL" + }, + { "keyName": "IDX_product_category_deleted_at", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_product_category_deleted_at\" ON \"product_category\" (deleted_at) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_product_category_path", + "columnNames": [], + "composite": false, "primary": false, - "unique": false + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_product_category_path\" ON \"product_category\" (mpath) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_category_handle_unique", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE UNIQUE INDEX IF NOT EXISTS \"IDX_category_handle_unique\" ON \"product_category\" (handle) WHERE deleted_at IS NULL" }, { "keyName": "product_category_pkey", @@ -247,13 +270,20 @@ "schema": "public", "indexes": [ { - "columnNames": [ - "deleted_at" - ], - "composite": false, "keyName": "IDX_product_collection_deleted_at", + "columnNames": [], + "composite": false, "primary": false, - "unique": false + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_product_collection_deleted_at\" ON \"product_collection\" (deleted_at) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_collection_handle_unique", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE UNIQUE INDEX IF NOT EXISTS \"IDX_collection_handle_unique\" ON \"product_collection\" (handle) WHERE deleted_at IS NULL" }, { "keyName": "product_collection_pkey", @@ -334,13 +364,20 @@ "schema": "public", "indexes": [ { - "columnNames": [ - "deleted_at" - ], + "keyName": "IDX_image_deleted_at", + "columnNames": [], "composite": false, - "keyName": "IDX_product_image_deleted_at", "primary": false, - "unique": false + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_image_deleted_at\" ON \"image\" (deleted_at) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_product_image_url", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_product_image_url\" ON \"image\" (url) WHERE deleted_at IS NULL" }, { "keyName": "image_pkey", @@ -421,13 +458,20 @@ "schema": "public", "indexes": [ { - "columnNames": [ - "deleted_at" - ], - "composite": false, "keyName": "IDX_product_tag_deleted_at", + "columnNames": [], + "composite": false, "primary": false, - "unique": false + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_product_tag_deleted_at\" ON \"product_tag\" (deleted_at) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_tag_value_unique", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE UNIQUE INDEX IF NOT EXISTS \"IDX_tag_value_unique\" ON \"product_tag\" (value) WHERE deleted_at IS NULL" }, { "keyName": "product_tag_pkey", @@ -464,7 +508,7 @@ }, "metadata": { "name": "metadata", - "type": "json", + "type": "jsonb", "unsigned": false, "autoincrement": false, "primary": false, @@ -508,13 +552,20 @@ "schema": "public", "indexes": [ { - "columnNames": [ - "deleted_at" - ], - "composite": false, "keyName": "IDX_product_type_deleted_at", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_product_type_deleted_at\" ON \"product_type\" (deleted_at) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_type_value_unique", + "columnNames": [], + "composite": false, "primary": false, - "unique": false + "unique": false, + "expression": "CREATE UNIQUE INDEX IF NOT EXISTS \"IDX_type_value_unique\" ON \"product_type\" (value) WHERE deleted_at IS NULL" }, { "keyName": "product_type_pkey", @@ -593,6 +644,7 @@ "autoincrement": false, "primary": false, "nullable": false, + "default": "'draft'", "enumItems": [ "draft", "proposed", @@ -682,8 +734,18 @@ "nullable": true, "mappedType": "text" }, - "collection_id": { - "name": "collection_id", + "discountable": { + "name": "discountable", + "type": "boolean", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "default": "true", + "mappedType": "boolean" + }, + "external_id": { + "name": "external_id", "type": "text", "unsigned": false, "autoincrement": false, @@ -691,27 +753,26 @@ "nullable": true, "mappedType": "text" }, - "type_id": { - "name": "type_id", - "type": "text", + "metadata": { + "name": "metadata", + "type": "jsonb", "unsigned": false, "autoincrement": false, "primary": false, "nullable": true, - "mappedType": "text" + "mappedType": "json" }, - "discountable": { - "name": "discountable", - "type": "boolean", + "type_id": { + "name": "type_id", + "type": "text", "unsigned": false, "autoincrement": false, "primary": false, - "nullable": false, - "default": "true", - "mappedType": "boolean" + "nullable": true, + "mappedType": "text" }, - "external_id": { - "name": "external_id", + "collection_id": { + "name": "collection_id", "type": "text", "unsigned": false, "autoincrement": false, @@ -750,28 +811,42 @@ "nullable": true, "length": 6, "mappedType": "datetime" - }, - "metadata": { - "name": "metadata", - "type": "jsonb", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "json" } }, "name": "product", "schema": "public", "indexes": [ { - "columnNames": [ - "deleted_at" - ], + "keyName": "IDX_product_type_id", + "columnNames": [], "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_product_type_id\" ON \"product\" (type_id) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_product_collection_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_product_collection_id\" ON \"product\" (collection_id) WHERE deleted_at IS NULL" + }, + { "keyName": "IDX_product_deleted_at", + "columnNames": [], + "composite": false, "primary": false, - "unique": false + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_product_deleted_at\" ON \"product\" (deleted_at) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_product_handle_unique", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE UNIQUE INDEX IF NOT EXISTS \"IDX_product_handle_unique\" ON \"product\" (handle) WHERE deleted_at IS NULL" }, { "keyName": "product_pkey", @@ -785,29 +860,29 @@ ], "checks": [], "foreignKeys": { - "product_collection_id_foreign": { - "constraintName": "product_collection_id_foreign", + "product_type_id_foreign": { + "constraintName": "product_type_id_foreign", "columnNames": [ - "collection_id" + "type_id" ], "localTableName": "public.product", "referencedColumnNames": [ "id" ], - "referencedTableName": "public.product_collection", + "referencedTableName": "public.product_type", "deleteRule": "set null", "updateRule": "cascade" }, - "product_type_id_foreign": { - "constraintName": "product_type_id_foreign", + "product_collection_id_foreign": { + "constraintName": "product_collection_id_foreign", "columnNames": [ - "type_id" + "collection_id" ], "localTableName": "public.product", "referencedColumnNames": [ "id" ], - "referencedTableName": "public.product_type", + "referencedTableName": "public.product_collection", "deleteRule": "set null", "updateRule": "cascade" } @@ -833,15 +908,6 @@ "nullable": false, "mappedType": "text" }, - "product_id": { - "name": "product_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, "metadata": { "name": "metadata", "type": "jsonb", @@ -851,6 +917,15 @@ "nullable": true, "mappedType": "json" }, + "product_id": { + "name": "product_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, "created_at": { "name": "created_at", "type": "timestamptz", @@ -888,13 +963,28 @@ "schema": "public", "indexes": [ { - "columnNames": [ - "deleted_at" - ], + "keyName": "IDX_product_option_product_id", + "columnNames": [], "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_product_option_product_id\" ON \"product_option\" (product_id) WHERE deleted_at IS NULL" + }, + { "keyName": "IDX_product_option_deleted_at", + "columnNames": [], + "composite": false, "primary": false, - "unique": false + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_product_option_deleted_at\" ON \"product_option\" (deleted_at) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_option_product_id_title_unique", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE UNIQUE INDEX IF NOT EXISTS \"IDX_option_product_id_title_unique\" ON \"product_option\" (product_id, title) WHERE deleted_at IS NULL" }, { "keyName": "product_option_pkey", @@ -943,23 +1033,23 @@ "nullable": false, "mappedType": "text" }, - "option_id": { - "name": "option_id", - "type": "text", + "metadata": { + "name": "metadata", + "type": "jsonb", "unsigned": false, "autoincrement": false, "primary": false, "nullable": true, - "mappedType": "text" + "mappedType": "json" }, - "metadata": { - "name": "metadata", - "type": "jsonb", + "option_id": { + "name": "option_id", + "type": "text", "unsigned": false, "autoincrement": false, "primary": false, "nullable": true, - "mappedType": "json" + "mappedType": "text" }, "created_at": { "name": "created_at", @@ -998,13 +1088,28 @@ "schema": "public", "indexes": [ { - "columnNames": [ - "deleted_at" - ], + "keyName": "IDX_product_option_value_option_id", + "columnNames": [], "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_product_option_value_option_id\" ON \"product_option_value\" (option_id) WHERE deleted_at IS NULL" + }, + { "keyName": "IDX_product_option_value_deleted_at", + "columnNames": [], + "composite": false, "primary": false, - "unique": false + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_product_option_value_deleted_at\" ON \"product_option_value\" (deleted_at) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_option_value_option_id_unique", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE UNIQUE INDEX IF NOT EXISTS \"IDX_option_value_option_id_unique\" ON \"product_option_value\" (option_id, value) WHERE deleted_at IS NULL" }, { "keyName": "product_option_value_pkey", @@ -1342,39 +1447,39 @@ }, "weight": { "name": "weight", - "type": "numeric", + "type": "integer", "unsigned": false, "autoincrement": false, "primary": false, "nullable": true, - "mappedType": "decimal" + "mappedType": "integer" }, "length": { "name": "length", - "type": "numeric", + "type": "integer", "unsigned": false, "autoincrement": false, "primary": false, "nullable": true, - "mappedType": "decimal" + "mappedType": "integer" }, "height": { "name": "height", - "type": "numeric", + "type": "integer", "unsigned": false, "autoincrement": false, "primary": false, "nullable": true, - "mappedType": "decimal" + "mappedType": "integer" }, "width": { "name": "width", - "type": "numeric", + "type": "integer", "unsigned": false, "autoincrement": false, "primary": false, "nullable": true, - "mappedType": "decimal" + "mappedType": "integer" }, "metadata": { "name": "metadata", @@ -1441,13 +1546,52 @@ "schema": "public", "indexes": [ { - "columnNames": [ - "deleted_at" - ], + "keyName": "IDX_product_variant_product_id", + "columnNames": [], "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_product_variant_product_id\" ON \"product_variant\" (product_id) WHERE deleted_at IS NULL" + }, + { "keyName": "IDX_product_variant_deleted_at", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_product_variant_deleted_at\" ON \"product_variant\" (deleted_at) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_product_variant_sku_unique", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE UNIQUE INDEX IF NOT EXISTS \"IDX_product_variant_sku_unique\" ON \"product_variant\" (sku) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_product_variant_barcode_unique", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE UNIQUE INDEX IF NOT EXISTS \"IDX_product_variant_barcode_unique\" ON \"product_variant\" (barcode) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_product_variant_ean_unique", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE UNIQUE INDEX IF NOT EXISTS \"IDX_product_variant_ean_unique\" ON \"product_variant\" (ean) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_product_variant_upc_unique", + "columnNames": [], + "composite": false, "primary": false, - "unique": false + "unique": false, + "expression": "CREATE UNIQUE INDEX IF NOT EXISTS \"IDX_product_variant_upc_unique\" ON \"product_variant\" (upc) WHERE deleted_at IS NULL" }, { "keyName": "product_variant_pkey", diff --git a/packages/modules/product/src/migrations/Migration20241125090957.ts b/packages/modules/product/src/migrations/Migration20241125090957.ts new file mode 100644 index 0000000000000..f203486e9b457 --- /dev/null +++ b/packages/modules/product/src/migrations/Migration20241125090957.ts @@ -0,0 +1,173 @@ +import { Migration } from "@mikro-orm/migrations" + +export class Migration20241125090957 extends Migration { + async up(): Promise { + this.addSql( + 'alter table if exists "product" drop constraint if exists "product_status_check";' + ) + + this.addSql( + 'CREATE INDEX IF NOT EXISTS "IDX_product_category_parent_category_id" ON "product_category" (parent_category_id) WHERE deleted_at IS NULL;' + ) + this.addSql( + 'CREATE INDEX IF NOT EXISTS "IDX_product_category_path" ON "product_category" (mpath) WHERE deleted_at IS NULL;' + ) + this.addSql( + 'CREATE UNIQUE INDEX IF NOT EXISTS "IDX_category_handle_unique" ON "product_category" (handle) WHERE deleted_at IS NULL;' + ) + + this.addSql( + 'CREATE UNIQUE INDEX IF NOT EXISTS "IDX_collection_handle_unique" ON "product_collection" (handle) WHERE deleted_at IS NULL;' + ) + + this.addSql('drop index if exists "IDX_product_image_deleted_at";') + this.addSql( + 'CREATE INDEX IF NOT EXISTS "IDX_image_deleted_at" ON "image" (deleted_at) WHERE deleted_at IS NULL;' + ) + this.addSql( + 'CREATE INDEX IF NOT EXISTS "IDX_product_image_url" ON "image" (url) WHERE deleted_at IS NULL;' + ) + + this.addSql( + 'CREATE UNIQUE INDEX IF NOT EXISTS "IDX_tag_value_unique" ON "product_tag" (value) WHERE deleted_at IS NULL;' + ) + + this.addSql( + 'CREATE UNIQUE INDEX IF NOT EXISTS "IDX_type_value_unique" ON "product_type" (value) WHERE deleted_at IS NULL;' + ) + + this.addSql( + 'alter table if exists "product" alter column "status" type text using ("status"::text);' + ) + this.addSql( + "alter table if exists \"product\" add constraint \"product_status_check\" check (\"status\" in ('draft', 'proposed', 'published', 'rejected'));" + ) + this.addSql( + 'alter table if exists "product" alter column "status" set default \'draft\';' + ) + this.addSql( + 'CREATE INDEX IF NOT EXISTS "IDX_product_type_id" ON "product" (type_id) WHERE deleted_at IS NULL;' + ) + this.addSql( + 'CREATE INDEX IF NOT EXISTS "IDX_product_collection_id" ON "product" (collection_id) WHERE deleted_at IS NULL;' + ) + this.addSql( + 'CREATE UNIQUE INDEX IF NOT EXISTS "IDX_product_handle_unique" ON "product" (handle) WHERE deleted_at IS NULL;' + ) + + this.addSql( + 'alter table if exists "product_option" alter column "product_id" type text using ("product_id"::text);' + ) + this.addSql( + 'alter table if exists "product_option" alter column "product_id" set not null;' + ) + this.addSql( + 'CREATE INDEX IF NOT EXISTS "IDX_product_option_product_id" ON "product_option" (product_id) WHERE deleted_at IS NULL;' + ) + this.addSql( + 'CREATE UNIQUE INDEX IF NOT EXISTS "IDX_option_product_id_title_unique" ON "product_option" (product_id, title) WHERE deleted_at IS NULL;' + ) + + this.addSql( + 'CREATE INDEX IF NOT EXISTS "IDX_product_option_value_option_id" ON "product_option_value" (option_id) WHERE deleted_at IS NULL;' + ) + this.addSql( + 'CREATE UNIQUE INDEX IF NOT EXISTS "IDX_option_value_option_id_unique" ON "product_option_value" (option_id, value) WHERE deleted_at IS NULL;' + ) + + this.addSql( + 'alter table if exists "product_variant" alter column "weight" type integer using ("weight"::integer);' + ) + this.addSql( + 'alter table if exists "product_variant" alter column "length" type integer using ("length"::integer);' + ) + this.addSql( + 'alter table if exists "product_variant" alter column "height" type integer using ("height"::integer);' + ) + this.addSql( + 'alter table if exists "product_variant" alter column "width" type integer using ("width"::integer);' + ) + this.addSql( + 'CREATE INDEX IF NOT EXISTS "IDX_product_variant_product_id" ON "product_variant" (product_id) WHERE deleted_at IS NULL;' + ) + this.addSql( + 'CREATE UNIQUE INDEX IF NOT EXISTS "IDX_product_variant_sku_unique" ON "product_variant" (sku) WHERE deleted_at IS NULL;' + ) + this.addSql( + 'CREATE UNIQUE INDEX IF NOT EXISTS "IDX_product_variant_barcode_unique" ON "product_variant" (barcode) WHERE deleted_at IS NULL;' + ) + this.addSql( + 'CREATE UNIQUE INDEX IF NOT EXISTS "IDX_product_variant_ean_unique" ON "product_variant" (ean) WHERE deleted_at IS NULL;' + ) + this.addSql( + 'CREATE UNIQUE INDEX IF NOT EXISTS "IDX_product_variant_upc_unique" ON "product_variant" (upc) WHERE deleted_at IS NULL;' + ) + } + + async down(): Promise { + this.addSql( + 'alter table if exists "product" drop constraint if exists "product_status_check";' + ) + + this.addSql( + 'drop index if exists "IDX_product_category_parent_category_id";' + ) + this.addSql('drop index if exists "IDX_product_category_path";') + this.addSql('drop index if exists "IDX_category_handle_unique";') + + this.addSql('drop index if exists "IDX_collection_handle_unique";') + + this.addSql('drop index if exists "IDX_image_deleted_at";') + this.addSql('drop index if exists "IDX_product_image_url";') + this.addSql( + 'create index if not exists "IDX_product_image_deleted_at" on "image" ("deleted_at");' + ) + + this.addSql('drop index if exists "IDX_tag_value_unique";') + + this.addSql('drop index if exists "IDX_type_value_unique";') + + this.addSql( + 'alter table if exists "product" alter column "status" drop default;' + ) + this.addSql( + 'alter table if exists "product" alter column "status" type text using ("status"::text);' + ) + this.addSql( + "alter table if exists \"product\" add constraint \"product_status_check\" check (\"status\" in ('draft', 'proposed', 'published', 'rejected'));" + ) + this.addSql('drop index if exists "IDX_product_type_id";') + this.addSql('drop index if exists "IDX_product_collection_id";') + this.addSql('drop index if exists "IDX_product_handle_unique";') + + this.addSql( + 'alter table if exists "product_option" alter column "product_id" type text using ("product_id"::text);' + ) + this.addSql( + 'alter table if exists "product_option" alter column "product_id" drop not null;' + ) + this.addSql('drop index if exists "IDX_product_option_product_id";') + this.addSql('drop index if exists "IDX_option_product_id_title_unique";') + + this.addSql('drop index if exists "IDX_product_option_value_option_id";') + this.addSql('drop index if exists "IDX_option_value_option_id_unique";') + + this.addSql( + 'alter table if exists "product_variant" alter column "weight" type numeric using ("weight"::numeric);' + ) + this.addSql( + 'alter table if exists "product_variant" alter column "length" type numeric using ("length"::numeric);' + ) + this.addSql( + 'alter table if exists "product_variant" alter column "height" type numeric using ("height"::numeric);' + ) + this.addSql( + 'alter table if exists "product_variant" alter column "width" type numeric using ("width"::numeric);' + ) + this.addSql('drop index if exists "IDX_product_variant_product_id";') + this.addSql('drop index if exists "IDX_product_variant_sku_unique";') + this.addSql('drop index if exists "IDX_product_variant_barcode_unique";') + this.addSql('drop index if exists "IDX_product_variant_ean_unique";') + this.addSql('drop index if exists "IDX_product_variant_upc_unique";') + } +} diff --git a/packages/modules/product/src/models/product-collection.ts b/packages/modules/product/src/models/product-collection.ts index e58fa20b113ae..36905e64b784d 100644 --- a/packages/modules/product/src/models/product-collection.ts +++ b/packages/modules/product/src/models/product-collection.ts @@ -5,7 +5,7 @@ const ProductCollection = model .define("ProductCollection", { id: model.id({ prefix: "pcol" }).primaryKey(), title: model.text().searchable(), - handle: model.text().nullable(), + handle: model.text(), metadata: model.json().nullable(), products: model.hasMany(() => Product, { mappedBy: "collection", diff --git a/packages/modules/product/src/models/product-variant.ts b/packages/modules/product/src/models/product-variant.ts index 1f3694c22e95c..b5e203f98ab63 100644 --- a/packages/modules/product/src/models/product-variant.ts +++ b/packages/modules/product/src/models/product-variant.ts @@ -10,7 +10,7 @@ const ProductVariant = model ean: model.text().searchable().nullable(), upc: model.text().searchable().nullable(), allow_backorder: model.boolean().default(false), - manage_inventory: model.boolean().default(false), + manage_inventory: model.boolean().default(true), hs_code: model.text().nullable(), origin_country: model.text().nullable(), mid_code: model.text().nullable(), diff --git a/packages/modules/product/src/models/product.ts b/packages/modules/product/src/models/product.ts index a018a85051986..69ed7cf1dc2dc 100644 --- a/packages/modules/product/src/models/product.ts +++ b/packages/modules/product/src/models/product.ts @@ -20,10 +20,10 @@ const Product = model .enum(ProductUtils.ProductStatus) .default(ProductUtils.ProductStatus.DRAFT), thumbnail: model.text().nullable(), - weight: model.number().nullable(), - length: model.number().nullable(), - height: model.number().nullable(), - width: model.number().nullable(), + weight: model.text().nullable(), + length: model.text().nullable(), + height: model.text().nullable(), + width: model.text().nullable(), origin_country: model.text().nullable(), hs_code: model.text().nullable(), mid_code: model.text().nullable(), From dc29b25556b1f644aeb1e1d89c73e93c4004e551 Mon Sep 17 00:00:00 2001 From: adrien2p Date: Mon, 25 Nov 2024 11:06:28 +0100 Subject: [PATCH 077/175] cleanup --- .../migrations/.snapshot-medusa-product.json | 227 +++++++++++++----- .../product/src/models/product-image.ts | 1 + .../modules/product/src/models/product.ts | 2 +- 3 files changed, 167 insertions(+), 63 deletions(-) diff --git a/packages/modules/product/src/migrations/.snapshot-medusa-product.json b/packages/modules/product/src/migrations/.snapshot-medusa-product.json index d89c496f05bae..15cd6347d033d 100644 --- a/packages/modules/product/src/migrations/.snapshot-medusa-product.json +++ b/packages/modules/product/src/migrations/.snapshot-medusa-product.json @@ -1,5 +1,7 @@ { - "namespaces": ["public"], + "namespaces": [ + "public" + ], "name": "public", "tables": [ { @@ -168,7 +170,9 @@ }, { "keyName": "product_category_pkey", - "columnNames": ["id"], + "columnNames": [ + "id" + ], "composite": false, "primary": true, "unique": true @@ -178,9 +182,13 @@ "foreignKeys": { "product_category_parent_category_id_foreign": { "constraintName": "product_category_parent_category_id_foreign", - "columnNames": ["parent_category_id"], + "columnNames": [ + "parent_category_id" + ], "localTableName": "public.product_category", - "referencedColumnNames": ["id"], + "referencedColumnNames": [ + "id" + ], "referencedTableName": "public.product_category", "deleteRule": "cascade", "updateRule": "cascade" @@ -279,7 +287,9 @@ }, { "keyName": "product_collection_pkey", - "columnNames": ["id"], + "columnNames": [ + "id" + ], "composite": false, "primary": true, "unique": true @@ -371,7 +381,9 @@ }, { "keyName": "product_tag_pkey", - "columnNames": ["id"], + "columnNames": [ + "id" + ], "composite": false, "primary": true, "unique": true @@ -463,7 +475,9 @@ }, { "keyName": "product_type_pkey", - "columnNames": ["id"], + "columnNames": [ + "id" + ], "composite": false, "primary": true, "unique": true @@ -537,7 +551,12 @@ "primary": false, "nullable": false, "default": "'draft'", - "enumItems": ["draft", "proposed", "published", "rejected"], + "enumItems": [ + "draft", + "proposed", + "published", + "rejected" + ], "mappedType": "enum" }, "thumbnail": { @@ -737,7 +756,9 @@ }, { "keyName": "product_pkey", - "columnNames": ["id"], + "columnNames": [ + "id" + ], "composite": false, "primary": true, "unique": true @@ -747,18 +768,26 @@ "foreignKeys": { "product_type_id_foreign": { "constraintName": "product_type_id_foreign", - "columnNames": ["type_id"], + "columnNames": [ + "type_id" + ], "localTableName": "public.product", - "referencedColumnNames": ["id"], + "referencedColumnNames": [ + "id" + ], "referencedTableName": "public.product_type", "deleteRule": "set null", "updateRule": "cascade" }, "product_collection_id_foreign": { "constraintName": "product_collection_id_foreign", - "columnNames": ["collection_id"], + "columnNames": [ + "collection_id" + ], "localTableName": "public.product", - "referencedColumnNames": ["id"], + "referencedColumnNames": [ + "id" + ], "referencedTableName": "public.product_collection", "deleteRule": "set null", "updateRule": "cascade" @@ -865,7 +894,9 @@ }, { "keyName": "product_option_pkey", - "columnNames": ["id"], + "columnNames": [ + "id" + ], "composite": false, "primary": true, "unique": true @@ -875,9 +906,13 @@ "foreignKeys": { "product_option_product_id_foreign": { "constraintName": "product_option_product_id_foreign", - "columnNames": ["product_id"], + "columnNames": [ + "product_id" + ], "localTableName": "public.product_option", - "referencedColumnNames": ["id"], + "referencedColumnNames": [ + "id" + ], "referencedTableName": "public.product", "deleteRule": "cascade", "updateRule": "cascade" @@ -984,7 +1019,9 @@ }, { "keyName": "product_option_value_pkey", - "columnNames": ["id"], + "columnNames": [ + "id" + ], "composite": false, "primary": true, "unique": true @@ -994,9 +1031,13 @@ "foreignKeys": { "product_option_value_option_id_foreign": { "constraintName": "product_option_value_option_id_foreign", - "columnNames": ["option_id"], + "columnNames": [ + "option_id" + ], "localTableName": "public.product_option_value", - "referencedColumnNames": ["id"], + "referencedColumnNames": [ + "id" + ], "referencedTableName": "public.product_option", "deleteRule": "cascade", "updateRule": "cascade" @@ -1032,6 +1073,25 @@ "nullable": true, "mappedType": "json" }, + "rank": { + "name": "rank", + "type": "integer", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "default": "0", + "mappedType": "integer" + }, + "product_id": { + "name": "product_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, "created_at": { "name": "created_at", "type": "timestamptz", @@ -1063,40 +1123,40 @@ "nullable": true, "length": 6, "mappedType": "datetime" - }, - "rank": { - "name": "rank", - "type": "integer", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "default": "0", - "mappedType": "integer" - }, - "product_id": { - "name": "product_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "text" } }, "name": "image", "schema": "public", "indexes": [ { - "columnNames": ["deleted_at"], + "keyName": "IDX_image_product_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_image_product_id\" ON \"image\" (product_id) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_image_deleted_at", + "columnNames": [], "composite": false, - "keyName": "IDX_product_image_deleted_at", "primary": false, - "unique": false + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_image_deleted_at\" ON \"image\" (deleted_at) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_product_image_url", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_product_image_url\" ON \"image\" (url) WHERE deleted_at IS NULL" }, { "keyName": "image_pkey", - "columnNames": ["id"], + "columnNames": [ + "id" + ], "composite": false, "primary": true, "unique": true @@ -1106,9 +1166,13 @@ "foreignKeys": { "image_product_id_foreign": { "constraintName": "image_product_id_foreign", - "columnNames": ["product_id"], + "columnNames": [ + "product_id" + ], "localTableName": "public.image", - "referencedColumnNames": ["id"], + "referencedColumnNames": [ + "id" + ], "referencedTableName": "public.product", "deleteRule": "cascade", "updateRule": "cascade" @@ -1141,7 +1205,10 @@ "indexes": [ { "keyName": "product_tags_pkey", - "columnNames": ["product_id", "product_tag_id"], + "columnNames": [ + "product_id", + "product_tag_id" + ], "composite": true, "primary": true, "unique": true @@ -1151,18 +1218,26 @@ "foreignKeys": { "product_tags_product_id_foreign": { "constraintName": "product_tags_product_id_foreign", - "columnNames": ["product_id"], + "columnNames": [ + "product_id" + ], "localTableName": "public.product_tags", - "referencedColumnNames": ["id"], + "referencedColumnNames": [ + "id" + ], "referencedTableName": "public.product", "deleteRule": "cascade", "updateRule": "cascade" }, "product_tags_product_tag_id_foreign": { "constraintName": "product_tags_product_tag_id_foreign", - "columnNames": ["product_tag_id"], + "columnNames": [ + "product_tag_id" + ], "localTableName": "public.product_tags", - "referencedColumnNames": ["id"], + "referencedColumnNames": [ + "id" + ], "referencedTableName": "public.product_tag", "deleteRule": "cascade", "updateRule": "cascade" @@ -1195,7 +1270,10 @@ "indexes": [ { "keyName": "product_category_product_pkey", - "columnNames": ["product_id", "product_category_id"], + "columnNames": [ + "product_id", + "product_category_id" + ], "composite": true, "primary": true, "unique": true @@ -1205,18 +1283,26 @@ "foreignKeys": { "product_category_product_product_id_foreign": { "constraintName": "product_category_product_product_id_foreign", - "columnNames": ["product_id"], + "columnNames": [ + "product_id" + ], "localTableName": "public.product_category_product", - "referencedColumnNames": ["id"], + "referencedColumnNames": [ + "id" + ], "referencedTableName": "public.product", "deleteRule": "cascade", "updateRule": "cascade" }, "product_category_product_product_category_id_foreign": { "constraintName": "product_category_product_product_category_id_foreign", - "columnNames": ["product_category_id"], + "columnNames": [ + "product_category_id" + ], "localTableName": "public.product_category_product", - "referencedColumnNames": ["id"], + "referencedColumnNames": [ + "id" + ], "referencedTableName": "public.product_category", "deleteRule": "cascade", "updateRule": "cascade" @@ -1485,7 +1571,9 @@ }, { "keyName": "product_variant_pkey", - "columnNames": ["id"], + "columnNames": [ + "id" + ], "composite": false, "primary": true, "unique": true @@ -1495,9 +1583,13 @@ "foreignKeys": { "product_variant_product_id_foreign": { "constraintName": "product_variant_product_id_foreign", - "columnNames": ["product_id"], + "columnNames": [ + "product_id" + ], "localTableName": "public.product_variant", - "referencedColumnNames": ["id"], + "referencedColumnNames": [ + "id" + ], "referencedTableName": "public.product", "deleteRule": "cascade", "updateRule": "cascade" @@ -1530,7 +1622,10 @@ "indexes": [ { "keyName": "product_variant_option_pkey", - "columnNames": ["variant_id", "option_value_id"], + "columnNames": [ + "variant_id", + "option_value_id" + ], "composite": true, "primary": true, "unique": true @@ -1540,18 +1635,26 @@ "foreignKeys": { "product_variant_option_variant_id_foreign": { "constraintName": "product_variant_option_variant_id_foreign", - "columnNames": ["variant_id"], + "columnNames": [ + "variant_id" + ], "localTableName": "public.product_variant_option", - "referencedColumnNames": ["id"], + "referencedColumnNames": [ + "id" + ], "referencedTableName": "public.product_variant", "deleteRule": "cascade", "updateRule": "cascade" }, "product_variant_option_option_value_id_foreign": { "constraintName": "product_variant_option_option_value_id_foreign", - "columnNames": ["option_value_id"], + "columnNames": [ + "option_value_id" + ], "localTableName": "public.product_variant_option", - "referencedColumnNames": ["id"], + "referencedColumnNames": [ + "id" + ], "referencedTableName": "public.product_option_value", "deleteRule": "cascade", "updateRule": "cascade" diff --git a/packages/modules/product/src/models/product-image.ts b/packages/modules/product/src/models/product-image.ts index e9ca158c8a952..0b605ec051cfd 100644 --- a/packages/modules/product/src/models/product-image.ts +++ b/packages/modules/product/src/models/product-image.ts @@ -8,6 +8,7 @@ const ProductImage = model id: model.id({ prefix: "img" }).primaryKey(), url: model.text(), metadata: model.json().nullable(), + rank: model.number().default(0), product: model.belongsTo(() => Product, { mappedBy: "images", }), diff --git a/packages/modules/product/src/models/product.ts b/packages/modules/product/src/models/product.ts index 30b01ce834ced..f56c5d27c6213 100644 --- a/packages/modules/product/src/models/product.ts +++ b/packages/modules/product/src/models/product.ts @@ -60,7 +60,7 @@ const Product = model }), }) .cascades({ - delete: ["variants", "options"], + delete: ["variants", "options", "images"], }) .indexes([ { From 7938a5fad9337dd512d49ae9dccab1f63d87db7d Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Mon, 25 Nov 2024 07:43:30 -0300 Subject: [PATCH 078/175] number searchable --- .../core/utils/src/dml/properties/number.ts | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/packages/core/utils/src/dml/properties/number.ts b/packages/core/utils/src/dml/properties/number.ts index a541bd3783224..36affe4d5af31 100644 --- a/packages/core/utils/src/dml/properties/number.ts +++ b/packages/core/utils/src/dml/properties/number.ts @@ -8,7 +8,10 @@ import { PrimaryKeyModifier } from "./primary-key" export class NumberProperty extends BaseProperty { protected dataType: { name: "number" - options: {} + options: { + primaryKey?: boolean + searchable?: boolean + } } /** @@ -30,6 +33,27 @@ export class NumberProperty extends BaseProperty { return new PrimaryKeyModifier(this) } + /** + * This method indicates that a number property is searchable. + * + * @example + * import { model } from "@medusajs/framework/utils" + * + * const MyCustom = model.define("my_custom", { + * name: model.number().searchable(), + * // ... + * }) + * + * export default MyCustom + * + * @customNamespace Property Configuration Methods + */ + searchable() { + this.dataType.options.searchable = true + + return this + } + constructor(options?: { primaryKey?: boolean }) { super() From e0d3ac0705b8f4dc991f54eb80288d91061d81f8 Mon Sep 17 00:00:00 2001 From: adrien2p Date: Mon, 25 Nov 2024 12:36:38 +0100 Subject: [PATCH 079/175] fix random ordering --- .../__tests__/product-category.ts | 51 ++++++++++++++----- .../src/repositories/product-category.ts | 11 ++-- 2 files changed, 44 insertions(+), 18 deletions(-) diff --git a/packages/modules/product/integration-tests/__tests__/product-category.ts b/packages/modules/product/integration-tests/__tests__/product-category.ts index 5187fab228a83..d94586c7172b1 100644 --- a/packages/modules/product/integration-tests/__tests__/product-category.ts +++ b/packages/modules/product/integration-tests/__tests__/product-category.ts @@ -190,12 +190,14 @@ moduleIntegrationTestRunner({ mpath: "category-0.category-1.category-1-a", parent_category_id: "category-1", category_children: [], + rank: 0, }, { id: "category-1-b", handle: "category-1-b", mpath: "category-0.category-1.category-1-b", parent_category_id: "category-1", + rank: 1, category_children: [ expect.objectContaining({ id: "category-1-b-1", @@ -235,8 +237,10 @@ moduleIntegrationTestRunner({ mpath: "electronics.computers.laptops.gaming-laptops.high-performance.4k-gaming", parent_category_id: "high-performance", + rank: 1, parent_category: expect.objectContaining({ id: "high-performance", + rank: 1, parent_category_id: "gaming-laptops", handle: "high-performance-gaming-laptops", mpath: @@ -245,6 +249,7 @@ moduleIntegrationTestRunner({ id: "gaming-laptops", handle: "gaming-laptops", mpath: "electronics.computers.laptops.gaming-laptops", + rank: 0, parent_category_id: "laptops", parent_category: expect.objectContaining({ id: "laptops", @@ -296,6 +301,7 @@ moduleIntegrationTestRunner({ handle: "gaming-laptops", mpath: "electronics.computers.laptops.gaming-laptops", parent_category_id: "laptops", + rank: 0, category_children: [ expect.objectContaining({ id: "budget-gaming", @@ -304,6 +310,7 @@ moduleIntegrationTestRunner({ "electronics.computers.laptops.gaming-laptops.budget-gaming", parent_category_id: "gaming-laptops", category_children: [], + rank: 0, }), expect.objectContaining({ id: "high-performance", @@ -311,6 +318,7 @@ moduleIntegrationTestRunner({ mpath: "electronics.computers.laptops.gaming-laptops.high-performance", parent_category_id: "gaming-laptops", + rank: 1, category_children: expect.arrayContaining([ expect.objectContaining({ id: "vr-ready", @@ -319,6 +327,7 @@ moduleIntegrationTestRunner({ "electronics.computers.laptops.gaming-laptops.high-performance.vr-ready", parent_category_id: "high-performance", category_children: [], + rank: 0, }), expect.objectContaining({ id: "4k-gaming", @@ -327,6 +336,7 @@ moduleIntegrationTestRunner({ "electronics.computers.laptops.gaming-laptops.high-performance.4k-gaming", parent_category_id: "high-performance", category_children: [], + rank: 1, }), ]), }), @@ -421,12 +431,15 @@ moduleIntegrationTestRunner({ handle: "category-1-a", mpath: "category-0.category-1.category-1-a", parent_category_id: "category-1", + rank: 0, parent_category: expect.objectContaining({ id: "category-1", handle: "category-1", mpath: "category-0.category-1", parent_category_id: "category-0", + rank: 0, parent_category: expect.objectContaining({ + rank: 0, id: "category-0", handle: "category-0", mpath: "category-0", @@ -440,17 +453,20 @@ moduleIntegrationTestRunner({ handle: "category-1-b", mpath: "category-0.category-1.category-1-b", parent_category_id: "category-1", + rank: 1, parent_category: expect.objectContaining({ id: "category-1", handle: "category-1", mpath: "category-0.category-1", parent_category_id: "category-0", + rank: 0, parent_category: expect.objectContaining({ id: "category-0", handle: "category-0", mpath: "category-0", parent_category_id: null, parent_category: null, + rank: 0, }), }), }, @@ -475,17 +491,20 @@ moduleIntegrationTestRunner({ handle: "category-1-a", mpath: "category-0.category-1.category-1-a", parent_category_id: "category-1", + rank: 0, parent_category: expect.objectContaining({ id: "category-1", handle: "category-1", mpath: "category-0.category-1", parent_category_id: "category-0", + rank: 0, parent_category: expect.objectContaining({ id: "category-0", handle: "category-0", mpath: "category-0", parent_category_id: null, parent_category: null, + rank: 0, }), }), category_children: [], @@ -495,17 +514,20 @@ moduleIntegrationTestRunner({ handle: "category-1-b", mpath: "category-0.category-1.category-1-b", parent_category_id: "category-1", + rank: 1, parent_category: expect.objectContaining({ id: "category-1", handle: "category-1", mpath: "category-0.category-1", parent_category_id: "category-0", + rank: 0, parent_category: expect.objectContaining({ id: "category-0", handle: "category-0", mpath: "category-0", parent_category_id: null, parent_category: null, + rank: 0, }), }), category_children: [ @@ -514,6 +536,7 @@ moduleIntegrationTestRunner({ handle: "category-1-b-1", mpath: "category-0.category-1.category-1-b.category-1-b-1", parent_category_id: "category-1-b", + rank: 0, }), ], }, @@ -1183,15 +1206,15 @@ moduleIntegrationTestRunner({ "electronics.computers.desktops.gaming-desktops.laptops.gaming-laptops.high-performance", category_children: [ expect.objectContaining({ - id: "4k-gaming", + id: "vr-ready", mpath: - "electronics.computers.desktops.gaming-desktops.laptops.gaming-laptops.high-performance.4k-gaming", + "electronics.computers.desktops.gaming-desktops.laptops.gaming-laptops.high-performance.vr-ready", parent_category_id: "high-performance", }), expect.objectContaining({ - id: "vr-ready", + id: "4k-gaming", mpath: - "electronics.computers.desktops.gaming-desktops.laptops.gaming-laptops.high-performance.vr-ready", + "electronics.computers.desktops.gaming-desktops.laptops.gaming-laptops.high-performance.4k-gaming", parent_category_id: "high-performance", }), ], @@ -1204,6 +1227,12 @@ moduleIntegrationTestRunner({ "electronics.computers.desktops.gaming-desktops.laptops.ultrabooks", parent_category_id: "laptops", category_children: [ + expect.objectContaining({ + id: "thin-light", + mpath: + "electronics.computers.desktops.gaming-desktops.laptops.ultrabooks.thin-light", + parent_category_id: "ultrabooks", + }), expect.objectContaining({ id: "convertible-ultrabooks", mpath: @@ -1211,25 +1240,19 @@ moduleIntegrationTestRunner({ parent_category_id: "ultrabooks", category_children: [ expect.objectContaining({ - id: "detachable-ultrabooks", + id: "touchscreen-ultrabooks", mpath: - "electronics.computers.desktops.gaming-desktops.laptops.ultrabooks.convertible-ultrabooks.detachable-ultrabooks", + "electronics.computers.desktops.gaming-desktops.laptops.ultrabooks.convertible-ultrabooks.touchscreen-ultrabooks", parent_category_id: "convertible-ultrabooks", }), expect.objectContaining({ - id: "touchscreen-ultrabooks", + id: "detachable-ultrabooks", mpath: - "electronics.computers.desktops.gaming-desktops.laptops.ultrabooks.convertible-ultrabooks.touchscreen-ultrabooks", + "electronics.computers.desktops.gaming-desktops.laptops.ultrabooks.convertible-ultrabooks.detachable-ultrabooks", parent_category_id: "convertible-ultrabooks", }), ], }), - expect.objectContaining({ - id: "thin-light", - mpath: - "electronics.computers.desktops.gaming-desktops.laptops.ultrabooks.thin-light", - parent_category_id: "ultrabooks", - }), ], }), ], diff --git a/packages/modules/product/src/repositories/product-category.ts b/packages/modules/product/src/repositories/product-category.ts index d559841ee2d29..48292985cf134 100644 --- a/packages/modules/product/src/repositories/product-category.ts +++ b/packages/modules/product/src/repositories/product-category.ts @@ -20,12 +20,15 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito familyOptions: ProductCategoryTransformOptions = {} ) { const findOptions_ = { ...findOptions } - findOptions_.options ??= { - orderBy: { rank: "ASC" }, + findOptions_.options.orderBy = { + id: "ASC", + rank: "ASC", + ...findOptions_.options.orderBy, } const fields = (findOptions_.options.fields ??= []) const populate = (findOptions_.options.populate ??= []) + fields.push("rank") // Ref: Building descendants // mpath and parent_category_id needs to be added to the query for the tree building to be done accurately @@ -182,9 +185,9 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito const categoriesInTree = serialize ? await this.serialize[]>( - await manager.find(ProductCategory as any, where, options) + await manager.find(ProductCategory.name, where, options) ) - : await manager.find(ProductCategory as any, where, options) + : await manager.find(ProductCategory.name, where, options) const categoriesById = new Map(categoriesInTree.map((cat) => [cat.id, cat])) From 6cc267b06a9d8bc2e727c8440a4305658273a10a Mon Sep 17 00:00:00 2001 From: adrien2p Date: Mon, 25 Nov 2024 12:42:59 +0100 Subject: [PATCH 080/175] fix --- packages/modules/product/src/repositories/product-category.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/modules/product/src/repositories/product-category.ts b/packages/modules/product/src/repositories/product-category.ts index 48292985cf134..e6f1429ff7d29 100644 --- a/packages/modules/product/src/repositories/product-category.ts +++ b/packages/modules/product/src/repositories/product-category.ts @@ -20,6 +20,7 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito familyOptions: ProductCategoryTransformOptions = {} ) { const findOptions_ = { ...findOptions } + findOptions_.options ??= {} findOptions_.options.orderBy = { id: "ASC", rank: "ASC", @@ -28,7 +29,6 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito const fields = (findOptions_.options.fields ??= []) const populate = (findOptions_.options.populate ??= []) - fields.push("rank") // Ref: Building descendants // mpath and parent_category_id needs to be added to the query for the tree building to be done accurately From 7c1631a4d79cc7f94df185774d7472835eef2739 Mon Sep 17 00:00:00 2001 From: Harminder Virk Date: Mon, 25 Nov 2024 18:58:35 +0530 Subject: [PATCH 081/175] test: fix product-category tests --- .../__tests__/product-category.ts | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/packages/modules/product/integration-tests/__tests__/product-category.ts b/packages/modules/product/integration-tests/__tests__/product-category.ts index d94586c7172b1..38a0d3b07aa51 100644 --- a/packages/modules/product/integration-tests/__tests__/product-category.ts +++ b/packages/modules/product/integration-tests/__tests__/product-category.ts @@ -175,7 +175,7 @@ moduleIntegrationTestRunner({ include_descendants_tree: true, }, { - select: ["id", "handle"], + select: ["id", "handle", "rank"], } ) @@ -222,7 +222,7 @@ moduleIntegrationTestRunner({ include_ancestors_tree: true, }, { - select: ["id", "handle"], + select: ["id", "handle", "rank"], } ) @@ -287,7 +287,7 @@ moduleIntegrationTestRunner({ include_descendants_tree: true, }, { - select: ["id", "handle"], + select: ["id", "handle", "rank"], } ) @@ -417,7 +417,7 @@ moduleIntegrationTestRunner({ include_ancestors_tree: true, }, { - select: ["id", "handle"], + select: ["id", "handle", "rank"], } ) @@ -481,7 +481,7 @@ moduleIntegrationTestRunner({ include_ancestors_tree: true, }, { - select: ["id", "handle"], + select: ["id", "handle", "rank"], } ) @@ -1206,15 +1206,15 @@ moduleIntegrationTestRunner({ "electronics.computers.desktops.gaming-desktops.laptops.gaming-laptops.high-performance", category_children: [ expect.objectContaining({ - id: "vr-ready", + id: "4k-gaming", mpath: - "electronics.computers.desktops.gaming-desktops.laptops.gaming-laptops.high-performance.vr-ready", + "electronics.computers.desktops.gaming-desktops.laptops.gaming-laptops.high-performance.4k-gaming", parent_category_id: "high-performance", }), expect.objectContaining({ - id: "4k-gaming", + id: "vr-ready", mpath: - "electronics.computers.desktops.gaming-desktops.laptops.gaming-laptops.high-performance.4k-gaming", + "electronics.computers.desktops.gaming-desktops.laptops.gaming-laptops.high-performance.vr-ready", parent_category_id: "high-performance", }), ], @@ -1227,12 +1227,6 @@ moduleIntegrationTestRunner({ "electronics.computers.desktops.gaming-desktops.laptops.ultrabooks", parent_category_id: "laptops", category_children: [ - expect.objectContaining({ - id: "thin-light", - mpath: - "electronics.computers.desktops.gaming-desktops.laptops.ultrabooks.thin-light", - parent_category_id: "ultrabooks", - }), expect.objectContaining({ id: "convertible-ultrabooks", mpath: @@ -1240,19 +1234,25 @@ moduleIntegrationTestRunner({ parent_category_id: "ultrabooks", category_children: [ expect.objectContaining({ - id: "touchscreen-ultrabooks", + id: "detachable-ultrabooks", mpath: - "electronics.computers.desktops.gaming-desktops.laptops.ultrabooks.convertible-ultrabooks.touchscreen-ultrabooks", + "electronics.computers.desktops.gaming-desktops.laptops.ultrabooks.convertible-ultrabooks.detachable-ultrabooks", parent_category_id: "convertible-ultrabooks", }), expect.objectContaining({ - id: "detachable-ultrabooks", + id: "touchscreen-ultrabooks", mpath: - "electronics.computers.desktops.gaming-desktops.laptops.ultrabooks.convertible-ultrabooks.detachable-ultrabooks", + "electronics.computers.desktops.gaming-desktops.laptops.ultrabooks.convertible-ultrabooks.touchscreen-ultrabooks", parent_category_id: "convertible-ultrabooks", }), ], }), + expect.objectContaining({ + id: "thin-light", + mpath: + "electronics.computers.desktops.gaming-desktops.laptops.ultrabooks.thin-light", + parent_category_id: "ultrabooks", + }), ], }), ], From 206254f1a3a68b21cb271e4273c51844f7512a43 Mon Sep 17 00:00:00 2001 From: Harminder Virk Date: Mon, 25 Nov 2024 19:02:47 +0530 Subject: [PATCH 082/175] test: update breaking DML tests --- .../src/dml/__tests__/entity-builder.spec.ts | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts b/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts index 186a121850f32..144d5590071ea 100644 --- a/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts +++ b/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts @@ -1942,6 +1942,11 @@ describe("Entity builder", () => { expression: 'CREATE UNIQUE INDEX IF NOT EXISTS "IDX_user_email_unique" ON "user" (email) WHERE deleted_at IS NULL', }, + { + expression: + 'CREATE INDEX IF NOT EXISTS "IDX_user_deleted_at" ON "user" (deleted_at) WHERE deleted_at IS NULL', + name: "IDX_user_deleted_at", + }, ]) expect(metaData.filters).toEqual({ @@ -2053,6 +2058,11 @@ describe("Entity builder", () => { expression: 'CREATE UNIQUE INDEX IF NOT EXISTS "IDX_user_email_unique" ON "platform"."user" (email) WHERE deleted_at IS NULL', }, + { + expression: + 'CREATE INDEX IF NOT EXISTS "IDX_user_deleted_at" ON "platform"."user" (deleted_at) WHERE deleted_at IS NULL', + name: "IDX_user_deleted_at", + }, ]) expect(metaData.filters).toEqual({ @@ -2163,6 +2173,11 @@ describe("Entity builder", () => { expression: 'CREATE UNIQUE INDEX IF NOT EXISTS "IDX_user_myEmail_unique" ON "user" (myEmail) WHERE deleted_at IS NULL', }, + { + expression: + 'CREATE INDEX IF NOT EXISTS "IDX_user_deleted_at" ON "user" (deleted_at) WHERE deleted_at IS NULL', + name: "IDX_user_deleted_at", + }, ]) expect(metaData.filters).toEqual({ @@ -2955,6 +2970,11 @@ describe("Entity builder", () => { 'CREATE INDEX IF NOT EXISTS "IDX_user_group_id" ON "user" (group_id) WHERE deleted_at IS NULL', name: "IDX_user_group_id", }, + { + expression: + 'CREATE INDEX IF NOT EXISTS "IDX_user_deleted_at" ON "user" (deleted_at) WHERE deleted_at IS NULL', + name: "IDX_user_deleted_at", + }, { expression: 'CREATE UNIQUE INDEX IF NOT EXISTS "IDX_user_email_account_unique" ON "user" (email, account) WHERE deleted_at IS NULL', @@ -3031,6 +3051,11 @@ describe("Entity builder", () => { 'CREATE INDEX IF NOT EXISTS "IDX_user_group_id" ON "user" (group_id) WHERE deleted_at IS NULL', name: "IDX_user_group_id", }, + { + expression: + 'CREATE INDEX IF NOT EXISTS "IDX_user_deleted_at" ON "user" (deleted_at) WHERE deleted_at IS NULL', + name: "IDX_user_deleted_at", + }, { expression: 'CREATE INDEX IF NOT EXISTS "IDX_user_organization_account" ON "user" (organization, account) WHERE email IS NOT NULL AND deleted_at IS NULL', @@ -3122,6 +3147,11 @@ describe("Entity builder", () => { 'CREATE INDEX IF NOT EXISTS "IDX_user_group_id" ON "user" (group_id) WHERE deleted_at IS NULL', name: "IDX_user_group_id", }, + { + expression: + 'CREATE INDEX IF NOT EXISTS "IDX_user_deleted_at" ON "user" (deleted_at) WHERE deleted_at IS NULL', + name: "IDX_user_deleted_at", + }, ]) const Setting = toMikroORMEntity(setting) @@ -3133,6 +3163,11 @@ describe("Entity builder", () => { 'CREATE INDEX IF NOT EXISTS "IDX_setting_user_id" ON "setting" (user_id) WHERE deleted_at IS NULL', name: "IDX_setting_user_id", }, + { + expression: + 'CREATE INDEX IF NOT EXISTS "IDX_setting_deleted_at" ON "setting" (deleted_at) WHERE deleted_at IS NULL', + name: "IDX_setting_deleted_at", + }, ]) }) }) From 35b15915dca8d15c379a38a5a183ce33e25f7596 Mon Sep 17 00:00:00 2001 From: Harminder Virk Date: Mon, 25 Nov 2024 20:08:05 +0530 Subject: [PATCH 083/175] test: array assertion to not care about ordering --- .../__tests__/product/admin/product.spec.ts | 47 ++++++++++--------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/integration-tests/http/__tests__/product/admin/product.spec.ts b/integration-tests/http/__tests__/product/admin/product.spec.ts index e7e90014a4c88..b662f3fa482d9 100644 --- a/integration-tests/http/__tests__/product/admin/product.spec.ts +++ b/integration-tests/http/__tests__/product/admin/product.spec.ts @@ -74,7 +74,8 @@ medusaIntegrationTestRunner({ // BREAKING: Type input changed from {type: {value: string}} to {type_id: string} type_id: baseType.id, tags: [{ id: baseTag1.id }, { id: baseTag2.id }], - images: [{ + images: [ + { url: "image-one", }, { @@ -139,7 +140,6 @@ medusaIntegrationTestRunner({ ]) ) }) - it("returns a list of products with all statuses when no status or invalid status is provided", async () => { const res = await api @@ -991,7 +991,10 @@ medusaIntegrationTestRunner({ }) it("should get a product with images ordered by rank", async () => { - const res = await api.get(`/admin/products/${baseProduct.id}`, adminHeaders) + const res = await api.get( + `/admin/products/${baseProduct.id}`, + adminHeaders + ) expect(res.data.product.images).toEqual( expect.arrayContaining([ @@ -1975,24 +1978,26 @@ medusaIntegrationTestRunner({ ) expect(res.status).toEqual(200) - expect(res.data.products).toEqual([ - expect.objectContaining({ - id: baseProduct.id, - sales_channels: expect.arrayContaining([ - expect.objectContaining({ - id: salesChannel.id, - }), - ]), - }), - expect.objectContaining({ - id: proposedProduct.id, - sales_channels: expect.arrayContaining([ - expect.objectContaining({ - id: salesChannel.id, - }), - ]), - }), - ]) + expect(res.data.products).toEqual( + expect.arrayContaining([ + expect.objectContaining({ + id: baseProduct.id, + sales_channels: expect.arrayContaining([ + expect.objectContaining({ + id: salesChannel.id, + }), + ]), + }), + expect.objectContaining({ + id: proposedProduct.id, + sales_channels: expect.arrayContaining([ + expect.objectContaining({ + id: salesChannel.id, + }), + ]), + }), + ]) + ) await api.post( `/admin/products/${proposedProduct.id}`, From 9fb05499db2d90b50d73af23d5f73f43ae996278 Mon Sep 17 00:00:00 2001 From: Harminder Virk Date: Mon, 25 Nov 2024 20:15:48 +0530 Subject: [PATCH 084/175] fix: temporarily apply id ordering for products --- .../__tests__/product/admin/product.spec.ts | 38 +++++++++---------- .../src/services/product-module-service.ts | 15 +++++--- 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/integration-tests/http/__tests__/product/admin/product.spec.ts b/integration-tests/http/__tests__/product/admin/product.spec.ts index b662f3fa482d9..4a09504938f63 100644 --- a/integration-tests/http/__tests__/product/admin/product.spec.ts +++ b/integration-tests/http/__tests__/product/admin/product.spec.ts @@ -1978,26 +1978,24 @@ medusaIntegrationTestRunner({ ) expect(res.status).toEqual(200) - expect(res.data.products).toEqual( - expect.arrayContaining([ - expect.objectContaining({ - id: baseProduct.id, - sales_channels: expect.arrayContaining([ - expect.objectContaining({ - id: salesChannel.id, - }), - ]), - }), - expect.objectContaining({ - id: proposedProduct.id, - sales_channels: expect.arrayContaining([ - expect.objectContaining({ - id: salesChannel.id, - }), - ]), - }), - ]) - ) + expect(res.data.products).toEqual([ + expect.objectContaining({ + id: baseProduct.id, + sales_channels: expect.arrayContaining([ + expect.objectContaining({ + id: salesChannel.id, + }), + ]), + }), + expect.objectContaining({ + id: proposedProduct.id, + sales_channels: expect.arrayContaining([ + expect.objectContaining({ + id: salesChannel.id, + }), + ]), + }), + ]) await api.post( `/admin/products/${proposedProduct.id}`, diff --git a/packages/modules/product/src/services/product-module-service.ts b/packages/modules/product/src/services/product-module-service.ts index 6cb7cbeaa7db0..c11b3824ab0b0 100644 --- a/packages/modules/product/src/services/product-module-service.ts +++ b/packages/modules/product/src/services/product-module-service.ts @@ -229,11 +229,16 @@ export default class ProductModuleService ...config, order: { ...config?.order, - ...(hasImagesRelation ? { - images: { - rank: "ASC", - }, - } : {}), + ...{ + id: "ASC", + }, + ...(hasImagesRelation + ? { + images: { + rank: "ASC", + }, + } + : {}), }, } } From 1374b9ba8d8d56ab214cd3b3af7ecf193dd8ed62 Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Mon, 25 Nov 2024 16:37:44 -0300 Subject: [PATCH 085/175] types --- .../src/services/actions/create-claim.ts | 6 +- .../src/services/actions/create-exchange.ts | 4 +- .../src/services/order-module-service.ts | 156 ++++++++++-------- .../order/src/services/order-service.ts | 13 +- .../order/src/utils/apply-order-changes.ts | 2 +- 5 files changed, 104 insertions(+), 77 deletions(-) diff --git a/packages/modules/order/src/services/actions/create-claim.ts b/packages/modules/order/src/services/actions/create-claim.ts index 6782806e6cb9d..f68a6ae3ba6d8 100644 --- a/packages/modules/order/src/services/actions/create-claim.ts +++ b/packages/modules/order/src/services/actions/create-claim.ts @@ -67,7 +67,7 @@ function createClaimAndReturnItems( returnReference, actions ) { - const returnItems: ReturnItem[] = [] + const returnItems: (typeof ReturnItem)[] = [] const claimItems = data.claim_items?.map((item) => { actions.push({ action: ChangeActionType.WRITE_OFF_ITEM, @@ -108,8 +108,8 @@ async function processAdditionalItems( sharedContext ) { const itemsToAdd: any[] = [] - const additionalNewItems: OrderClaimItem[] = [] - const additionalItems: OrderClaimItem[] = [] + const additionalNewItems: (typeof OrderClaimItem)[] = [] + const additionalItems: (typeof OrderClaimItem)[] = [] data.additional_items?.forEach((item) => { const hasItem = item.id ? order.items.find((o) => o.item.id === item.id) diff --git a/packages/modules/order/src/services/actions/create-exchange.ts b/packages/modules/order/src/services/actions/create-exchange.ts index 97c95c103e5c5..3e8ad2f54a5af 100644 --- a/packages/modules/order/src/services/actions/create-exchange.ts +++ b/packages/modules/order/src/services/actions/create-exchange.ts @@ -75,8 +75,8 @@ async function processAdditionalItems( sharedContext ) { const itemsToAdd: any[] = [] - const additionalNewItems: OrderExchangeItem[] = [] - const additionalItems: OrderExchangeItem[] = [] + const additionalNewItems: (typeof OrderExchangeItem)[] = [] + const additionalItems: (typeof OrderExchangeItem)[] = [] data.additional_items?.forEach((item) => { const hasItem = item.id ? order.items.find((o) => o.item.id === item.id) diff --git a/packages/modules/order/src/services/order-module-service.ts b/packages/modules/order/src/services/order-module-service.ts index 409974daf892d..ccece88f668eb 100644 --- a/packages/modules/order/src/services/order-module-service.ts +++ b/packages/modules/order/src/services/order-module-service.ts @@ -4,6 +4,7 @@ import { DAL, FilterableOrderReturnReasonProps, FindConfig, + InferEntityType, InternalModuleDeclaration, IOrderModuleService, ModuleJoinerConfig, @@ -134,30 +135,7 @@ const generateMethodForModels = { } // TODO: rm template args here, keep it for later to not collide with carlos work at least as little as possible -export default class OrderModuleService< - TOrder extends Order = Order, - TAddress extends OrderAddress = OrderAddress, - TLineItem extends OrderLineItem = OrderLineItem, - TLineItemAdjustment extends OrderLineItemAdjustment = OrderLineItemAdjustment, - TLineItemTaxLine extends OrderLineItemTaxLine = OrderLineItemTaxLine, - TOrderShippingMethodAdjustment extends OrderShippingMethodAdjustment = OrderShippingMethodAdjustment, - TOrderShippingMethodTaxLine extends OrderShippingMethodTaxLine = OrderShippingMethodTaxLine, - TOrderShippingMethod extends OrderShippingMethod = OrderShippingMethod, - TOrderTransaction extends OrderTransaction = OrderTransaction, - TOrderChange extends OrderChange = OrderChange, - TOrderChangeAction extends OrderChangeAction = OrderChangeAction, - TOrderItem extends OrderItem = OrderItem, - TOrderSummary extends OrderSummary = OrderSummary, - TOrderShipping extends OrderShipping = OrderShipping, - TReturnReason extends ReturnReason = ReturnReason, - TReturn extends Return = Return, - TReturnItem extends ReturnItem = ReturnItem, - TClaim extends OrderClaim = OrderClaim, - TClaimItem extends OrderClaimItem = OrderClaimItem, - TClaimItemImage extends OrderClaimItemImage = OrderClaimItemImage, - TExchange extends OrderExchange = OrderExchange, - TExchangeItem extends OrderExchangeItem = OrderExchangeItem - > +export default class OrderModuleService extends ModulesSdkUtils.MedusaService<{ Order: { dto: OrderTypes.OrderDTO } OrderAddress: { dto: OrderTypes.OrderAddressDTO } @@ -190,27 +168,69 @@ export default class OrderModuleService< { protected baseRepository_: DAL.RepositoryService protected orderService_: OrderService - protected orderAddressService_: ModulesSdkTypes.IMedusaInternalService - protected orderLineItemService_: ModulesSdkTypes.IMedusaInternalService - protected orderShippingMethodAdjustmentService_: ModulesSdkTypes.IMedusaInternalService - protected orderShippingMethodService_: ModulesSdkTypes.IMedusaInternalService - protected orderLineItemAdjustmentService_: ModulesSdkTypes.IMedusaInternalService - protected orderLineItemTaxLineService_: ModulesSdkTypes.IMedusaInternalService - protected orderShippingMethodTaxLineService_: ModulesSdkTypes.IMedusaInternalService - protected orderTransactionService_: ModulesSdkTypes.IMedusaInternalService - protected orderChangeService_: ModulesSdkTypes.IMedusaInternalService - protected orderChangeActionService_: ModulesSdkTypes.IMedusaInternalService - protected orderItemService_: ModulesSdkTypes.IMedusaInternalService - protected orderSummaryService_: ModulesSdkTypes.IMedusaInternalService - protected orderShippingService_: ModulesSdkTypes.IMedusaInternalService - protected returnReasonService_: ModulesSdkTypes.IMedusaInternalService - protected returnService_: ModulesSdkTypes.IMedusaInternalService - protected returnItemService_: ModulesSdkTypes.IMedusaInternalService - protected orderClaimService_: ModulesSdkTypes.IMedusaInternalService - protected orderClaimItemService_: ModulesSdkTypes.IMedusaInternalService - protected orderClaimItemImageService_: ModulesSdkTypes.IMedusaInternalService - protected orderExchangeService_: ModulesSdkTypes.IMedusaInternalService - protected orderExchangeItemService_: ModulesSdkTypes.IMedusaInternalService + protected orderAddressService_: ModulesSdkTypes.IMedusaInternalService< + InferEntityType + > + protected orderLineItemService_: ModulesSdkTypes.IMedusaInternalService< + InferEntityType + > + protected orderShippingMethodAdjustmentService_: ModulesSdkTypes.IMedusaInternalService< + InferEntityType + > + protected orderShippingMethodService_: ModulesSdkTypes.IMedusaInternalService< + InferEntityType + > + protected orderLineItemAdjustmentService_: ModulesSdkTypes.IMedusaInternalService< + InferEntityType + > + protected orderLineItemTaxLineService_: ModulesSdkTypes.IMedusaInternalService< + InferEntityType + > + protected orderShippingMethodTaxLineService_: ModulesSdkTypes.IMedusaInternalService< + InferEntityType + > + protected orderTransactionService_: ModulesSdkTypes.IMedusaInternalService< + InferEntityType + > + protected orderChangeService_: ModulesSdkTypes.IMedusaInternalService< + InferEntityType + > + protected orderChangeActionService_: ModulesSdkTypes.IMedusaInternalService< + InferEntityType + > + protected orderItemService_: ModulesSdkTypes.IMedusaInternalService< + InferEntityType + > + protected orderSummaryService_: ModulesSdkTypes.IMedusaInternalService< + InferEntityType + > + protected orderShippingService_: ModulesSdkTypes.IMedusaInternalService< + InferEntityType + > + protected returnReasonService_: ModulesSdkTypes.IMedusaInternalService< + InferEntityType + > + protected returnService_: ModulesSdkTypes.IMedusaInternalService< + InferEntityType + > + protected returnItemService_: ModulesSdkTypes.IMedusaInternalService< + InferEntityType + > + protected orderClaimService_: ModulesSdkTypes.IMedusaInternalService< + InferEntityType + > + protected orderClaimItemService_: ModulesSdkTypes.IMedusaInternalService< + InferEntityType + > + protected orderClaimItemImageService_: ModulesSdkTypes.IMedusaInternalService< + InferEntityType + > + protected orderExchangeService_: ModulesSdkTypes.IMedusaInternalService< + InferEntityType + > + protected orderExchangeItemService_: ModulesSdkTypes.IMedusaInternalService< + InferEntityType + > constructor( { @@ -637,7 +657,7 @@ export default class OrderModuleService< ) { const lineItemsToCreate: CreateOrderLineItemDTO[] = [] - const createdOrders: Order[] = [] + const createdOrders: (typeof Order)[] = [] for (const { items, shipping_methods, ...order } of data) { const ord = order as any @@ -789,7 +809,7 @@ export default class OrderModuleService< | OrderTypes.CreateOrderLineItemDTO, @MedusaContext() sharedContext: Context = {} ): Promise { - let items: OrderLineItem[] = [] + let items: InferEntityType[] = [] if (isString(orderIdOrData)) { items = await this.createOrderLineItems_( orderIdOrData, @@ -835,7 +855,7 @@ export default class OrderModuleService< orderId: string, items: OrderTypes.CreateOrderLineItemDTO[], @MedusaContext() sharedContext: Context = {} - ): Promise { + ): Promise[]> { const order = await this.retrieveOrder( orderId, { select: ["id", "version"] }, @@ -857,7 +877,7 @@ export default class OrderModuleService< protected async createOrderLineItemsBulk_( data: CreateOrderLineItemDTO[], @MedusaContext() sharedContext: Context = {} - ): Promise { + ): Promise[]> { const orderItemToCreate: CreateOrderItemDTO[] = [] const lineItems = await this.orderLineItemService_.create( @@ -912,7 +932,7 @@ export default class OrderModuleService< | Partial, @MedusaContext() sharedContext: Context = {} ): Promise { - let items: OrderLineItem[] = [] + let items: InferEntityType[] = [] if (isString(lineItemIdOrDataOrSelector)) { const item = await this.updateOrderLineItem_( lineItemIdOrDataOrSelector, @@ -955,7 +975,7 @@ export default class OrderModuleService< lineItemId: string, data: Partial, @MedusaContext() sharedContext: Context = {} - ): Promise { + ): Promise> { const [item] = await this.orderLineItemService_.update( [{ id: lineItemId, ...data }], sharedContext @@ -980,7 +1000,7 @@ export default class OrderModuleService< protected async updateOrderLineItemsWithSelector_( updates: OrderTypes.UpdateOrderLineItemWithSelectorDTO[], @MedusaContext() sharedContext: Context = {} - ): Promise { + ): Promise[]> { let toUpdate: UpdateOrderLineItemDTO[] = [] const detailsToUpdate: UpdateOrderItemWithSelectorDTO[] = [] for (const { selector, data } of updates) { @@ -1034,7 +1054,7 @@ export default class OrderModuleService< | Partial, @MedusaContext() sharedContext: Context = {} ): Promise { - let items: OrderItem[] = [] + let items: InferEntityType[] = [] if (isString(orderItemIdOrDataOrSelector)) { const item = await this.updateOrderItem_( orderItemIdOrDataOrSelector, @@ -1074,7 +1094,7 @@ export default class OrderModuleService< orderItemId: string, data: Partial, @MedusaContext() sharedContext: Context = {} - ): Promise { + ): Promise> { const [detail] = await this.orderItemService_.update( [{ id: orderItemId, ...data }], sharedContext @@ -1087,7 +1107,7 @@ export default class OrderModuleService< protected async updateOrderItemWithSelector_( updates: OrderTypes.UpdateOrderItemWithSelectorDTO[], @MedusaContext() sharedContext: Context = {} - ): Promise { + ): Promise[]> { let toUpdate: UpdateOrderItemDTO[] = [] for (const { selector, data } of updates) { const details = await this.listOrderItems( @@ -1131,7 +1151,7 @@ export default class OrderModuleService< ): Promise< OrderTypes.OrderShippingMethodDTO[] | OrderTypes.OrderShippingMethodDTO > { - let methods: OrderShippingMethod[] + let methods: InferEntityType[] if (isString(orderIdOrData)) { methods = await this.createOrderShippingMethods_( orderIdOrData, @@ -1181,7 +1201,7 @@ export default class OrderModuleService< orderId: string, data: CreateOrderShippingMethodDTO[], @MedusaContext() sharedContext: Context = {} - ): Promise { + ): Promise[]> { const order = await this.retrieveOrder( orderId, { select: ["id", "version"] }, @@ -1210,7 +1230,7 @@ export default class OrderModuleService< version: number }[], @MedusaContext() sharedContext: Context = {} - ): Promise { + ): Promise[]> { const sm = await this.orderShippingService_.create( data as unknown as CreateOrderShippingMethodDTO[], sharedContext @@ -1293,7 +1313,7 @@ export default class OrderModuleService< adjustments?: OrderTypes.CreateOrderLineItemAdjustmentDTO[], @MedusaContext() sharedContext: Context = {} ): Promise { - let addedAdjustments: OrderLineItemAdjustment[] = [] + let addedAdjustments: InferEntityType[] = [] if (isString(orderIdOrData)) { const order = await this.retrieveOrder( orderIdOrData, @@ -1466,7 +1486,9 @@ export default class OrderModuleService< | OrderTypes.OrderShippingMethodAdjustmentDTO[] | OrderTypes.OrderShippingMethodAdjustmentDTO > { - let addedAdjustments: OrderShippingMethodAdjustment[] = [] + let addedAdjustments: InferEntityType< + typeof OrderShippingMethodAdjustment + >[] = [] if (isString(orderIdOrData)) { const order = await this.retrieveOrder( orderIdOrData, @@ -1546,7 +1568,7 @@ export default class OrderModuleService< ): Promise< OrderTypes.OrderLineItemTaxLineDTO[] | OrderTypes.OrderLineItemTaxLineDTO > { - let addedTaxLines: OrderLineItemTaxLine[] + let addedTaxLines: InferEntityType[] if (isString(orderIdOrData)) { const lines = Array.isArray(taxLines) ? taxLines : [taxLines] @@ -1658,7 +1680,7 @@ export default class OrderModuleService< | OrderTypes.OrderShippingMethodTaxLineDTO[] | OrderTypes.OrderShippingMethodTaxLineDTO > { - let addedTaxLines: OrderShippingMethodTaxLine[] + let addedTaxLines: InferEntityType[] if (isString(orderIdOrData)) { const lines = Array.isArray(taxLines) ? taxLines : [taxLines] @@ -1900,7 +1922,7 @@ export default class OrderModuleService< protected async createOrderChange_( data: CreateOrderChangeDTO | CreateOrderChangeDTO[], @MedusaContext() sharedContext?: Context - ): Promise { + ): Promise[]> { const dataArr = Array.isArray(data) ? data : [data] const orderIds: string[] = [] const dataMap: Record = {} @@ -2280,7 +2302,7 @@ export default class OrderModuleService< ) return await this.applyOrderChanges_( - changes as ApplyOrderChangeDTO[], + changes as unknown as ApplyOrderChangeDTO[], sharedContext ) } @@ -2694,7 +2716,8 @@ export default class OrderModuleService< | OrderTypes.CreateOrderChangeActionDTO[], @MedusaContext() sharedContext?: Context ): Promise< - OrderTypes.OrderChangeActionDTO | OrderTypes.OrderChangeActionDTO[] + | InferEntityType + | InferEntityType[] > { let dataArr = Array.isArray(data) ? data : [data] @@ -2728,7 +2751,8 @@ export default class OrderModuleService< const actions = (await this.orderChangeActionService_.create( dataArr, sharedContext - )) as OrderTypes.OrderChangeActionDTO[] + )) as InferEntityType[] + return Array.isArray(data) ? actions : actions[0] } diff --git a/packages/modules/order/src/services/order-service.ts b/packages/modules/order/src/services/order-service.ts index 2254d0373b925..515a1157597e9 100644 --- a/packages/modules/order/src/services/order-service.ts +++ b/packages/modules/order/src/services/order-service.ts @@ -2,6 +2,7 @@ import { Context, DAL, FindConfig, + InferEntityType, OrderTypes, RepositoryService, } from "@medusajs/framework/types" @@ -19,9 +20,11 @@ type InjectedDependencies = { export default class OrderService extends ModulesSdkUtils.MedusaInternalService< InjectedDependencies, - Order + InferEntityType >(Order) { - protected readonly orderRepository_: RepositoryService + protected readonly orderRepository_: RepositoryService< + InferEntityType + > constructor(container: InjectedDependencies) { // @ts-ignore @@ -35,10 +38,10 @@ export default class OrderService extends ModulesSdkUtils.MedusaInternalService< version: number, config: FindConfig = {}, @MedusaContext() sharedContext: Context = {} - ): Promise { - const queryConfig = ModulesSdkUtils.buildQuery( + ): Promise { + const queryConfig = ModulesSdkUtils.buildQuery( { id, items: { version } }, - { ...config, take: 1 } + { ...config, take: 1 } as any ) const [result] = await this.orderRepository_.find( queryConfig, diff --git a/packages/modules/order/src/utils/apply-order-changes.ts b/packages/modules/order/src/utils/apply-order-changes.ts index 3b198070e8f96..0a6e1fe9cfd02 100644 --- a/packages/modules/order/src/utils/apply-order-changes.ts +++ b/packages/modules/order/src/utils/apply-order-changes.ts @@ -86,7 +86,7 @@ export function applyChangesToOrder( return_dismissed_quantity: orderItem.return_dismissed_quantity ?? 0, written_off_quantity: orderItem.written_off_quantity ?? 0, metadata: orderItem.metadata, - } as OrderItem) + } as any) } const orderSummary = order.summary as any From abc7d7a66da8e507dfc5df9ae678e2a5125d7feb Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Tue, 26 Nov 2024 08:52:18 -0300 Subject: [PATCH 086/175] wip --- packages/modules/order/src/models/claim-item.ts | 4 ++-- packages/modules/order/src/models/claim.ts | 1 + packages/modules/order/src/models/exchange-item.ts | 4 ++-- packages/modules/order/src/models/exchange.ts | 13 +++++++------ .../order/src/models/line-item-adjustment.ts | 2 +- .../modules/order/src/models/line-item-tax-line.ts | 2 +- packages/modules/order/src/models/line-item.ts | 12 ++++++------ packages/modules/order/src/models/order-change.ts | 8 ++++---- packages/modules/order/src/models/order-item.ts | 4 ++-- .../order/src/models/order-shipping-method.ts | 10 +++++----- packages/modules/order/src/models/order-summary.ts | 2 +- packages/modules/order/src/models/order.ts | 4 ++-- packages/modules/order/src/models/return-item.ts | 6 +++--- packages/modules/order/src/models/return.ts | 14 +++++++------- .../order/src/services/actions/create-claim.ts | 9 +++++---- .../order/src/services/actions/create-exchange.ts | 9 +++++---- .../order/src/services/order-module-service.ts | 7 ++----- 17 files changed, 56 insertions(+), 55 deletions(-) diff --git a/packages/modules/order/src/models/claim-item.ts b/packages/modules/order/src/models/claim-item.ts index 95c21a4967e7a..c19a6d305ab6a 100644 --- a/packages/modules/order/src/models/claim-item.ts +++ b/packages/modules/order/src/models/claim-item.ts @@ -11,10 +11,10 @@ const OrderClaimItem = model }), reason: model.enum(ClaimReason).nullable(), quantity: model.bigNumber(), - claim: model.belongsTo(() => Claim, { + claim: model.belongsTo(() => Claim, { mappedBy: "items", }), - item: model.belongsTo(() => OrderLineItem, { + item: model.belongsTo(() => OrderLineItem, { mappedBy: "claim_items", }), is_additional_item: model.boolean().default(false), diff --git a/packages/modules/order/src/models/claim.ts b/packages/modules/order/src/models/claim.ts index 42796b4f31988..ff09fde5c82cf 100644 --- a/packages/modules/order/src/models/claim.ts +++ b/packages/modules/order/src/models/claim.ts @@ -12,6 +12,7 @@ const OrderClaim = model order: model.belongsTo(() => Order, { mappedBy: "claims", }), + return_id: model.text().nullable(), return: model.hasMany(() => Return, { mappedBy: "claim", }), diff --git a/packages/modules/order/src/models/exchange-item.ts b/packages/modules/order/src/models/exchange-item.ts index 2f9db9aa6c5c9..edad090434e04 100644 --- a/packages/modules/order/src/models/exchange-item.ts +++ b/packages/modules/order/src/models/exchange-item.ts @@ -6,10 +6,10 @@ const OrderExchangeItem = model .define("OrderExchangeItem", { id: model.id({ prefix: "oexcitem" }).primaryKey(), quantity: model.bigNumber(), - exchange: model.belongsTo(() => Exchange, { + exchange: model.belongsTo(() => Exchange, { mappedBy: "additional_items", }), - item: model.belongsTo(() => OrderLineItem, { + item: model.belongsTo(() => OrderLineItem, { mappedBy: "exchange_items", }), note: model.text().nullable(), diff --git a/packages/modules/order/src/models/exchange.ts b/packages/modules/order/src/models/exchange.ts index aef594f0a14cb..853b14733d579 100644 --- a/packages/modules/order/src/models/exchange.ts +++ b/packages/modules/order/src/models/exchange.ts @@ -7,10 +7,11 @@ import Return from "./return" const OrderExchange = model .define("OrderExchange", { id: model.id({ prefix: "oexc" }).primaryKey(), - order: model.belongsTo(() => Order, { + order: model.belongsTo(() => Order, { mappedBy: "exchanges", }), - return: model.hasMany(() => Return, { + return_id: model.text().nullable(), + return: model.hasMany(() => Return, { mappedBy: "exchange", }), order_version: model.number(), @@ -18,16 +19,16 @@ const OrderExchange = model no_notification: model.boolean().nullable(), difference_due: model.bigNumber().nullable(), allow_backorder: model.boolean().default(false), - additional_items: model.hasMany(() => OrderExchangeItem, { + additional_items: model.hasMany(() => OrderExchangeItem, { mappedBy: "exchange", }), - shipping_methods: model.hasMany(() => OrderShipping, { + shipping_methods: model.hasMany(() => OrderShipping, { mappedBy: "exchange", }), - transactions: model.hasMany(() => OrderTransaction, { + transactions: model.hasMany(() => OrderTransaction, { mappedBy: "exchange", }), - changes: model.hasMany(() => OrderChange), + changes: model.hasMany(() => OrderChange), created_by: model.text().nullable(), metadata: model.json().nullable(), canceled_at: model.dateTime().nullable(), diff --git a/packages/modules/order/src/models/line-item-adjustment.ts b/packages/modules/order/src/models/line-item-adjustment.ts index fb6065f70f434..7007967a5f6b4 100644 --- a/packages/modules/order/src/models/line-item-adjustment.ts +++ b/packages/modules/order/src/models/line-item-adjustment.ts @@ -9,7 +9,7 @@ const OrderLineItemAdjustment = model code: model.text().nullable(), amount: model.bigNumber(), provider_id: model.text().nullable(), - item: model.belongsTo(() => OrderLineItem, { + item: model.belongsTo(() => OrderLineItem, { mappedBy: "adjustments", }), }) diff --git a/packages/modules/order/src/models/line-item-tax-line.ts b/packages/modules/order/src/models/line-item-tax-line.ts index d4a8e70bbddad..2466a0f2e21da 100644 --- a/packages/modules/order/src/models/line-item-tax-line.ts +++ b/packages/modules/order/src/models/line-item-tax-line.ts @@ -9,7 +9,7 @@ const OrderLineItemTaxLine = model code: model.text(), rate: model.bigNumber(), provider_id: model.text().nullable(), - item: model.belongsTo(() => OrderLineItem, { + item: model.belongsTo(() => OrderLineItem, { mappedBy: "tax_lines", }), }) diff --git a/packages/modules/order/src/models/line-item.ts b/packages/modules/order/src/models/line-item.ts index 59e3e2e3e1156..4319056156d6e 100644 --- a/packages/modules/order/src/models/line-item.ts +++ b/packages/modules/order/src/models/line-item.ts @@ -32,22 +32,22 @@ const OrderLineItem = model unit_price: model.bigNumber(), is_custom_price: model.boolean().default(false), metadata: model.json().nullable(), - tax_lines: model.hasMany(() => OrderLineItemTaxLine, { + tax_lines: model.hasMany(() => OrderLineItemTaxLine, { mappedBy: "item", }), - adjustments: model.hasMany(() => OrderLineItemAdjustment, { + adjustments: model.hasMany(() => OrderLineItemAdjustment, { mappedBy: "item", }), - items: model.hasMany(() => OrderItem, { + items: model.hasMany(() => OrderItem, { mappedBy: "item", }), - return_items: model.hasMany(() => ReturnItem, { + return_items: model.hasMany(() => ReturnItem, { mappedBy: "item", }), - claim_items: model.hasMany(() => OrderClaimItem, { + claim_items: model.hasMany(() => OrderClaimItem, { mappedBy: "item", }), - exchange_items: model.hasMany(() => OrderExchangeItem, { + exchange_items: model.hasMany(() => OrderExchangeItem, { mappedBy: "item", }), }) diff --git a/packages/modules/order/src/models/order-change.ts b/packages/modules/order/src/models/order-change.ts index 53953a2eca29a..ff6c37143ef94 100644 --- a/packages/modules/order/src/models/order-change.ts +++ b/packages/modules/order/src/models/order-change.ts @@ -8,21 +8,21 @@ import Return from "./return" const OrderChange = model .define("OrderChange", { id: model.id({ prefix: "ordch" }).primaryKey(), - order: model.belongsTo(() => Order, { + order: model.belongsTo(() => Order, { mappedBy: "changes", }), return: model - .belongsTo(() => Return, { + .belongsTo(() => Return, { mappedBy: "changes", }) .nullable(), claim: model - .belongsTo(() => OrderClaim, { + .belongsTo(() => OrderClaim, { mappedBy: "changes", }) .nullable(), exchange: model - .belongsTo(() => OrderExchange, { + .belongsTo(() => OrderExchange, { mappedBy: "changes", }) .nullable(), diff --git a/packages/modules/order/src/models/order-item.ts b/packages/modules/order/src/models/order-item.ts index 81aa9b72dde33..0a276d7791f52 100644 --- a/packages/modules/order/src/models/order-item.ts +++ b/packages/modules/order/src/models/order-item.ts @@ -5,11 +5,11 @@ import Order from "./order" const OrderItem = model .define("OrderItem", { id: model.id({ prefix: "orditem" }).primaryKey(), - order: model.belongsTo(() => Order, { + order: model.belongsTo(() => Order, { mappedBy: "items", }), version: model.number(), - item: model.belongsTo(() => OrderLineItem, { + item: model.belongsTo(() => OrderLineItem, { mappedBy: "items", }), unit_price: model.bigNumber().nullable(), diff --git a/packages/modules/order/src/models/order-shipping-method.ts b/packages/modules/order/src/models/order-shipping-method.ts index e2fde15d31a02..307f497b9e44d 100644 --- a/packages/modules/order/src/models/order-shipping-method.ts +++ b/packages/modules/order/src/models/order-shipping-method.ts @@ -9,25 +9,25 @@ const OrderShipping = model .define("OrderShipping", { id: model.id({ prefix: "ordspmv" }).primaryKey(), version: model.number(), - order: model.belongsTo(() => Order, { + order: model.belongsTo(() => Order, { mappedBy: "shipping_methods", }), return: model - .belongsTo(() => Return, { + .belongsTo(() => Return, { mappedBy: "shipping_methods", }) .nullable(), exchange: model - .belongsTo(() => Exchange, { + .belongsTo(() => Exchange, { mappedBy: "shipping_methods", }) .nullable(), claim: model - .belongsTo(() => Claim, { + .belongsTo(() => Claim, { mappedBy: "shipping_methods", }) .nullable(), - shipping_method: model.belongsTo(() => OrderShippingMethod, { + shipping_method: model.belongsTo(() => OrderShippingMethod, { mappedBy: "shipping_methods", }), }) diff --git a/packages/modules/order/src/models/order-summary.ts b/packages/modules/order/src/models/order-summary.ts index 90a4c9efdd12d..39ee4f8d2d639 100644 --- a/packages/modules/order/src/models/order-summary.ts +++ b/packages/modules/order/src/models/order-summary.ts @@ -6,7 +6,7 @@ const OrderSummary = model id: model.id({ prefix: "ordsum" }).primaryKey(), version: model.number().default(1), totals: model.json(), - order: model.belongsTo(() => Order, { + order: model.belongsTo(() => Order, { mappedBy: "summary", }), }) diff --git a/packages/modules/order/src/models/order.ts b/packages/modules/order/src/models/order.ts index 68f2e2f55a567..d16baf5cb09b5 100644 --- a/packages/modules/order/src/models/order.ts +++ b/packages/modules/order/src/models/order.ts @@ -21,8 +21,8 @@ const Order = model is_draft_order: model.boolean().default(false), email: model.text().searchable().nullable(), currency_code: model.text(), - shipping_address: model.belongsTo(() => OrderAddress), - billing_address: model.belongsTo(() => OrderAddress), + shipping_address: model.belongsTo(() => OrderAddress), + billing_address: model.belongsTo(() => OrderAddress), no_notification: model.boolean().nullable(), metadata: model.json().nullable(), summary: model.hasMany(() => OrderSummary, { diff --git a/packages/modules/order/src/models/return-item.ts b/packages/modules/order/src/models/return-item.ts index baf5a39f35fb6..8fd9d12754625 100644 --- a/packages/modules/order/src/models/return-item.ts +++ b/packages/modules/order/src/models/return-item.ts @@ -7,17 +7,17 @@ const ReturnItem = model .define("ReturnItem", { id: model.id({ prefix: "retitem" }).primaryKey(), reason: model - .belongsTo(() => ReturnReason, { + .belongsTo(() => ReturnReason, { mappedBy: "return_items", }) .nullable(), quantity: model.bigNumber(), received_quantity: model.bigNumber().default(0), damaged_quantity: model.bigNumber().default(0), - return: model.belongsTo(() => Return, { + return: model.belongsTo(() => Return, { mappedBy: "items", }), - item: model.belongsTo(() => OrderLineItem, { + item: model.belongsTo(() => OrderLineItem, { mappedBy: "return_items", }), note: model.text().nullable(), diff --git a/packages/modules/order/src/models/return.ts b/packages/modules/order/src/models/return.ts index 9f83281f6f909..7d420e208bf95 100644 --- a/packages/modules/order/src/models/return.ts +++ b/packages/modules/order/src/models/return.ts @@ -8,13 +8,13 @@ import OrderShipping from "./order-shipping-method" const Return = model .define("Return", { id: model.id({ prefix: "return" }).primaryKey(), - order: model.belongsTo(() => Order, { + order: model.belongsTo(() => Order, { mappedBy: "returns", }), - exchange: model.belongsTo(() => Exchange, { + exchange: model.belongsTo(() => Exchange, { mappedBy: "return", }), - claim: model.belongsTo(() => Claim, { + claim: model.belongsTo(() => Claim, { mappedBy: "return", }), order_version: model.number(), @@ -23,16 +23,16 @@ const Return = model location_id: model.text().nullable(), no_notification: model.boolean().nullable(), refund_amount: model.bigNumber().nullable(), - items: model.hasMany(() => ReturnItem, { + items: model.hasMany(() => ReturnItem, { mappedBy: "return", }), - shipping_methods: model.hasMany(() => OrderShipping, { + shipping_methods: model.hasMany(() => OrderShipping, { mappedBy: "return", }), - transactions: model.hasMany(() => OrderTransaction, { + transactions: model.hasMany(() => OrderTransaction, { mappedBy: "return", }), - changes: model.hasMany(() => OrderChange), + changes: model.hasMany(() => OrderChange), created_by: model.text().nullable(), metadata: model.json().nullable(), requested_at: model.dateTime().nullable(), diff --git a/packages/modules/order/src/services/actions/create-claim.ts b/packages/modules/order/src/services/actions/create-claim.ts index f68a6ae3ba6d8..4f260c8d32691 100644 --- a/packages/modules/order/src/services/actions/create-claim.ts +++ b/packages/modules/order/src/services/actions/create-claim.ts @@ -11,6 +11,7 @@ import { getShippingMethodsTotals, isString, promiseAll, + toMikroORMEntity, } from "@medusajs/framework/utils" import { OrderClaim, OrderClaimItem, Return, ReturnItem } from "@models" @@ -108,8 +109,8 @@ async function processAdditionalItems( sharedContext ) { const itemsToAdd: any[] = [] - const additionalNewItems: (typeof OrderClaimItem)[] = [] - const additionalItems: (typeof OrderClaimItem)[] = [] + const additionalNewItems: any[] = [] + const additionalItems: any[] = [] data.additional_items?.forEach((item) => { const hasItem = item.id ? order.items.find((o) => o.item.id === item.id) @@ -131,7 +132,7 @@ async function processAdditionalItems( }) additionalItems.push( - em.create(OrderClaimItem, { + em.create(toMikroORMEntity(OrderClaimItem), { item_id: item.id, quantity: item.quantity, note: item.note, @@ -143,7 +144,7 @@ async function processAdditionalItems( itemsToAdd.push(item) additionalNewItems.push( - em.create(OrderClaimItem, { + em.create(toMikroORMEntity(OrderClaimItem), { quantity: item.quantity, unit_price: item.unit_price, note: item.note, diff --git a/packages/modules/order/src/services/actions/create-exchange.ts b/packages/modules/order/src/services/actions/create-exchange.ts index 3e8ad2f54a5af..5af2d864d66a6 100644 --- a/packages/modules/order/src/services/actions/create-exchange.ts +++ b/packages/modules/order/src/services/actions/create-exchange.ts @@ -10,6 +10,7 @@ import { getShippingMethodsTotals, isString, promiseAll, + toMikroORMEntity, } from "@medusajs/framework/utils" import { OrderExchange, OrderExchangeItem, Return, ReturnItem } from "@models" @@ -75,8 +76,8 @@ async function processAdditionalItems( sharedContext ) { const itemsToAdd: any[] = [] - const additionalNewItems: (typeof OrderExchangeItem)[] = [] - const additionalItems: (typeof OrderExchangeItem)[] = [] + const additionalNewItems: any[] = [] + const additionalItems: any[] = [] data.additional_items?.forEach((item) => { const hasItem = item.id ? order.items.find((o) => o.item.id === item.id) @@ -98,7 +99,7 @@ async function processAdditionalItems( }) additionalItems.push( - em.create(OrderExchangeItem, { + em.create(toMikroORMEntity(OrderExchangeItem), { item_id: item.id, quantity: item.quantity, note: item.note, @@ -110,7 +111,7 @@ async function processAdditionalItems( itemsToAdd.push(item) additionalNewItems.push( - em.create(OrderExchangeItem, { + em.create(toMikroORMEntity(OrderExchangeItem), { quantity: item.quantity, unit_price: item.unit_price, note: item.note, diff --git a/packages/modules/order/src/services/order-module-service.ts b/packages/modules/order/src/services/order-module-service.ts index ccece88f668eb..1c16e4bea868a 100644 --- a/packages/modules/order/src/services/order-module-service.ts +++ b/packages/modules/order/src/services/order-module-service.ts @@ -1230,11 +1230,8 @@ export default class OrderModuleService version: number }[], @MedusaContext() sharedContext: Context = {} - ): Promise[]> { - const sm = await this.orderShippingService_.create( - data as unknown as CreateOrderShippingMethodDTO[], - sharedContext - ) + ): Promise> { + const sm = await this.orderShippingService_.create(data, sharedContext) return sm.map((s) => s.shipping_method) } From eb693fe1aec6872c7fbaf2f7974ab422d4dff594 Mon Sep 17 00:00:00 2001 From: adrien2p Date: Tue, 26 Nov 2024 15:12:16 +0100 Subject: [PATCH 087/175] WIP type improvements --- .../src/dml/__tests__/entity-builder.spec.ts | 35 +++++++++++++++---- packages/core/utils/src/dml/entity-builder.ts | 32 ++++++++++++----- packages/core/utils/src/dml/relations/base.ts | 8 +++++ .../modules/order/src/models/claim-item.ts | 4 +-- .../modules/order/src/models/exchange-item.ts | 4 +-- packages/modules/order/src/models/exchange.ts | 12 +++---- .../order/src/models/line-item-adjustment.ts | 2 +- .../order/src/models/line-item-tax-line.ts | 2 +- .../modules/order/src/models/line-item.ts | 12 +++---- .../modules/order/src/models/order-change.ts | 8 ++--- .../modules/order/src/models/order-item.ts | 4 +-- .../order/src/models/order-shipping-method.ts | 10 +++--- .../modules/order/src/models/order-summary.ts | 2 +- packages/modules/order/src/models/order.ts | 4 +-- .../modules/order/src/models/return-item.ts | 6 ++-- packages/modules/order/src/models/return.ts | 14 ++++---- 16 files changed, 103 insertions(+), 56 deletions(-) diff --git a/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts b/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts index 144d5590071ea..1c894bad6bd94 100644 --- a/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts +++ b/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts @@ -3837,7 +3837,7 @@ describe("Entity builder", () => { const User = toMikroORMEntity(user) const Email = toMikroORMEntity(email) - expectTypeOf(new User()).toMatchTypeOf<{ + expectTypeOf(new User()).toEqualTypeOf<{ id: number username: string email: { @@ -3846,16 +3846,27 @@ describe("Entity builder", () => { user: { id: number username: string - } | null + email: any + created_at: Date + updated_at: Date + deleted_at: Date | null + } + created_at: Date + updated_at: Date + deleted_at: Date | null + user_id: string | null } - }>() + created_at: Date + updated_at: Date + deleted_at: Date | null + }>({} as any) const userInstance = new User() expectTypeOf<(typeof userInstance)["email"]["user_id"]>().toEqualTypeOf< string | null >() - expectTypeOf(new Email()).toMatchTypeOf<{ + expectTypeOf(new Email()).toEqualTypeOf<{ email: string isVerified: boolean user: { @@ -3864,9 +3875,21 @@ describe("Entity builder", () => { email: { email: string isVerified: boolean + user: any + created_at: Date + updated_at: Date + deleted_at: Date | null + user_id: string | null } - } | null - }>() + created_at: Date + updated_at: Date + deleted_at: Date | null + } + created_at: Date + updated_at: Date + deleted_at: Date | null + user_id: string | null + }>({} as any) expectTypeOf(new Email().user_id).toEqualTypeOf() const metaData = MetadataStorage.getMetadataFromDecorator(User) diff --git a/packages/core/utils/src/dml/entity-builder.ts b/packages/core/utils/src/dml/entity-builder.ts index 0860b8d016c46..e8654b0a5b7b4 100644 --- a/packages/core/utils/src/dml/entity-builder.ts +++ b/packages/core/utils/src/dml/entity-builder.ts @@ -2,6 +2,7 @@ import { DMLSchema, IDmlEntityConfig, RelationshipOptions, + RelationshipType, } from "@medusajs/types" import { DmlEntity } from "./entity" import { @@ -27,6 +28,27 @@ import { HasMany } from "./relations/has-many" import { HasOne } from "./relations/has-one" import { ManyToMany } from "./relations/many-to-many" +export type Cleanup = { + [K in keyof T]: K extends Exclusion[number] + ? unknown + : T[K] extends RelationshipType + ? null extends RelationResolver + ? RelationshipType< + | (() => Cleanup< + RelationResolver extends () => infer Relation ? Relation : false, + [K & string, ...Exclusion] + >) + | null + > + : RelationshipType< + () => Cleanup< + RelationResolver extends () => infer Relation ? Relation : false, + [K & string, ...Exclusion] + > + > + : T[K] +} + /** * The implicit properties added by EntityBuilder in every schema */ @@ -121,20 +143,14 @@ export class EntityBuilder { define( nameOrConfig: TConfig, schema: Schema - ): DmlEntity< - Schema & DMLSchemaWithBigNumber & DMLSchemaDefaults, - TConfig - > { + ): DmlEntity & DMLSchemaDefaults, TConfig> { this.#disallowImplicitProperties(schema) return new DmlEntity(nameOrConfig, { ...schema, ...createBigNumberProperties(schema), ...createDefaultProperties(), - }) as unknown as DmlEntity< - Schema & DMLSchemaWithBigNumber & DMLSchemaDefaults, - TConfig - > + }) as unknown as DmlEntity & DMLSchemaDefaults, TConfig> } /** diff --git a/packages/core/utils/src/dml/relations/base.ts b/packages/core/utils/src/dml/relations/base.ts index e29e74f2058c6..bc1c109e0a06a 100644 --- a/packages/core/utils/src/dml/relations/base.ts +++ b/packages/core/utils/src/dml/relations/base.ts @@ -5,6 +5,14 @@ import { RelationshipTypes, } from "@medusajs/types" +// type Cleanup = { +// [K in keyof T as K extends Exclusion[number] +// ? never +// : K]: T[K] extends RelationshipType +// ? RelationResolver extends () => infer Relation ? RelationshipCleanup +// : T[K] +// } + export const IsRelationship = Symbol.for("isRelationship") /** diff --git a/packages/modules/order/src/models/claim-item.ts b/packages/modules/order/src/models/claim-item.ts index c19a6d305ab6a..95c21a4967e7a 100644 --- a/packages/modules/order/src/models/claim-item.ts +++ b/packages/modules/order/src/models/claim-item.ts @@ -11,10 +11,10 @@ const OrderClaimItem = model }), reason: model.enum(ClaimReason).nullable(), quantity: model.bigNumber(), - claim: model.belongsTo(() => Claim, { + claim: model.belongsTo(() => Claim, { mappedBy: "items", }), - item: model.belongsTo(() => OrderLineItem, { + item: model.belongsTo(() => OrderLineItem, { mappedBy: "claim_items", }), is_additional_item: model.boolean().default(false), diff --git a/packages/modules/order/src/models/exchange-item.ts b/packages/modules/order/src/models/exchange-item.ts index edad090434e04..2f9db9aa6c5c9 100644 --- a/packages/modules/order/src/models/exchange-item.ts +++ b/packages/modules/order/src/models/exchange-item.ts @@ -6,10 +6,10 @@ const OrderExchangeItem = model .define("OrderExchangeItem", { id: model.id({ prefix: "oexcitem" }).primaryKey(), quantity: model.bigNumber(), - exchange: model.belongsTo(() => Exchange, { + exchange: model.belongsTo(() => Exchange, { mappedBy: "additional_items", }), - item: model.belongsTo(() => OrderLineItem, { + item: model.belongsTo(() => OrderLineItem, { mappedBy: "exchange_items", }), note: model.text().nullable(), diff --git a/packages/modules/order/src/models/exchange.ts b/packages/modules/order/src/models/exchange.ts index 853b14733d579..f19ecfa27626f 100644 --- a/packages/modules/order/src/models/exchange.ts +++ b/packages/modules/order/src/models/exchange.ts @@ -7,11 +7,11 @@ import Return from "./return" const OrderExchange = model .define("OrderExchange", { id: model.id({ prefix: "oexc" }).primaryKey(), - order: model.belongsTo(() => Order, { + order: model.belongsTo(() => Order, { mappedBy: "exchanges", }), return_id: model.text().nullable(), - return: model.hasMany(() => Return, { + return: model.hasMany(() => Return, { mappedBy: "exchange", }), order_version: model.number(), @@ -19,16 +19,16 @@ const OrderExchange = model no_notification: model.boolean().nullable(), difference_due: model.bigNumber().nullable(), allow_backorder: model.boolean().default(false), - additional_items: model.hasMany(() => OrderExchangeItem, { + additional_items: model.hasMany(() => OrderExchangeItem, { mappedBy: "exchange", }), - shipping_methods: model.hasMany(() => OrderShipping, { + shipping_methods: model.hasMany(() => OrderShipping, { mappedBy: "exchange", }), - transactions: model.hasMany(() => OrderTransaction, { + transactions: model.hasMany(() => OrderTransaction, { mappedBy: "exchange", }), - changes: model.hasMany(() => OrderChange), + changes: model.hasMany(() => OrderChange), created_by: model.text().nullable(), metadata: model.json().nullable(), canceled_at: model.dateTime().nullable(), diff --git a/packages/modules/order/src/models/line-item-adjustment.ts b/packages/modules/order/src/models/line-item-adjustment.ts index 7007967a5f6b4..fb6065f70f434 100644 --- a/packages/modules/order/src/models/line-item-adjustment.ts +++ b/packages/modules/order/src/models/line-item-adjustment.ts @@ -9,7 +9,7 @@ const OrderLineItemAdjustment = model code: model.text().nullable(), amount: model.bigNumber(), provider_id: model.text().nullable(), - item: model.belongsTo(() => OrderLineItem, { + item: model.belongsTo(() => OrderLineItem, { mappedBy: "adjustments", }), }) diff --git a/packages/modules/order/src/models/line-item-tax-line.ts b/packages/modules/order/src/models/line-item-tax-line.ts index 2466a0f2e21da..d4a8e70bbddad 100644 --- a/packages/modules/order/src/models/line-item-tax-line.ts +++ b/packages/modules/order/src/models/line-item-tax-line.ts @@ -9,7 +9,7 @@ const OrderLineItemTaxLine = model code: model.text(), rate: model.bigNumber(), provider_id: model.text().nullable(), - item: model.belongsTo(() => OrderLineItem, { + item: model.belongsTo(() => OrderLineItem, { mappedBy: "tax_lines", }), }) diff --git a/packages/modules/order/src/models/line-item.ts b/packages/modules/order/src/models/line-item.ts index 4319056156d6e..59e3e2e3e1156 100644 --- a/packages/modules/order/src/models/line-item.ts +++ b/packages/modules/order/src/models/line-item.ts @@ -32,22 +32,22 @@ const OrderLineItem = model unit_price: model.bigNumber(), is_custom_price: model.boolean().default(false), metadata: model.json().nullable(), - tax_lines: model.hasMany(() => OrderLineItemTaxLine, { + tax_lines: model.hasMany(() => OrderLineItemTaxLine, { mappedBy: "item", }), - adjustments: model.hasMany(() => OrderLineItemAdjustment, { + adjustments: model.hasMany(() => OrderLineItemAdjustment, { mappedBy: "item", }), - items: model.hasMany(() => OrderItem, { + items: model.hasMany(() => OrderItem, { mappedBy: "item", }), - return_items: model.hasMany(() => ReturnItem, { + return_items: model.hasMany(() => ReturnItem, { mappedBy: "item", }), - claim_items: model.hasMany(() => OrderClaimItem, { + claim_items: model.hasMany(() => OrderClaimItem, { mappedBy: "item", }), - exchange_items: model.hasMany(() => OrderExchangeItem, { + exchange_items: model.hasMany(() => OrderExchangeItem, { mappedBy: "item", }), }) diff --git a/packages/modules/order/src/models/order-change.ts b/packages/modules/order/src/models/order-change.ts index ff6c37143ef94..53953a2eca29a 100644 --- a/packages/modules/order/src/models/order-change.ts +++ b/packages/modules/order/src/models/order-change.ts @@ -8,21 +8,21 @@ import Return from "./return" const OrderChange = model .define("OrderChange", { id: model.id({ prefix: "ordch" }).primaryKey(), - order: model.belongsTo(() => Order, { + order: model.belongsTo(() => Order, { mappedBy: "changes", }), return: model - .belongsTo(() => Return, { + .belongsTo(() => Return, { mappedBy: "changes", }) .nullable(), claim: model - .belongsTo(() => OrderClaim, { + .belongsTo(() => OrderClaim, { mappedBy: "changes", }) .nullable(), exchange: model - .belongsTo(() => OrderExchange, { + .belongsTo(() => OrderExchange, { mappedBy: "changes", }) .nullable(), diff --git a/packages/modules/order/src/models/order-item.ts b/packages/modules/order/src/models/order-item.ts index 0a276d7791f52..81aa9b72dde33 100644 --- a/packages/modules/order/src/models/order-item.ts +++ b/packages/modules/order/src/models/order-item.ts @@ -5,11 +5,11 @@ import Order from "./order" const OrderItem = model .define("OrderItem", { id: model.id({ prefix: "orditem" }).primaryKey(), - order: model.belongsTo(() => Order, { + order: model.belongsTo(() => Order, { mappedBy: "items", }), version: model.number(), - item: model.belongsTo(() => OrderLineItem, { + item: model.belongsTo(() => OrderLineItem, { mappedBy: "items", }), unit_price: model.bigNumber().nullable(), diff --git a/packages/modules/order/src/models/order-shipping-method.ts b/packages/modules/order/src/models/order-shipping-method.ts index 307f497b9e44d..e2fde15d31a02 100644 --- a/packages/modules/order/src/models/order-shipping-method.ts +++ b/packages/modules/order/src/models/order-shipping-method.ts @@ -9,25 +9,25 @@ const OrderShipping = model .define("OrderShipping", { id: model.id({ prefix: "ordspmv" }).primaryKey(), version: model.number(), - order: model.belongsTo(() => Order, { + order: model.belongsTo(() => Order, { mappedBy: "shipping_methods", }), return: model - .belongsTo(() => Return, { + .belongsTo(() => Return, { mappedBy: "shipping_methods", }) .nullable(), exchange: model - .belongsTo(() => Exchange, { + .belongsTo(() => Exchange, { mappedBy: "shipping_methods", }) .nullable(), claim: model - .belongsTo(() => Claim, { + .belongsTo(() => Claim, { mappedBy: "shipping_methods", }) .nullable(), - shipping_method: model.belongsTo(() => OrderShippingMethod, { + shipping_method: model.belongsTo(() => OrderShippingMethod, { mappedBy: "shipping_methods", }), }) diff --git a/packages/modules/order/src/models/order-summary.ts b/packages/modules/order/src/models/order-summary.ts index 39ee4f8d2d639..90a4c9efdd12d 100644 --- a/packages/modules/order/src/models/order-summary.ts +++ b/packages/modules/order/src/models/order-summary.ts @@ -6,7 +6,7 @@ const OrderSummary = model id: model.id({ prefix: "ordsum" }).primaryKey(), version: model.number().default(1), totals: model.json(), - order: model.belongsTo(() => Order, { + order: model.belongsTo(() => Order, { mappedBy: "summary", }), }) diff --git a/packages/modules/order/src/models/order.ts b/packages/modules/order/src/models/order.ts index d16baf5cb09b5..68f2e2f55a567 100644 --- a/packages/modules/order/src/models/order.ts +++ b/packages/modules/order/src/models/order.ts @@ -21,8 +21,8 @@ const Order = model is_draft_order: model.boolean().default(false), email: model.text().searchable().nullable(), currency_code: model.text(), - shipping_address: model.belongsTo(() => OrderAddress), - billing_address: model.belongsTo(() => OrderAddress), + shipping_address: model.belongsTo(() => OrderAddress), + billing_address: model.belongsTo(() => OrderAddress), no_notification: model.boolean().nullable(), metadata: model.json().nullable(), summary: model.hasMany(() => OrderSummary, { diff --git a/packages/modules/order/src/models/return-item.ts b/packages/modules/order/src/models/return-item.ts index 8fd9d12754625..baf5a39f35fb6 100644 --- a/packages/modules/order/src/models/return-item.ts +++ b/packages/modules/order/src/models/return-item.ts @@ -7,17 +7,17 @@ const ReturnItem = model .define("ReturnItem", { id: model.id({ prefix: "retitem" }).primaryKey(), reason: model - .belongsTo(() => ReturnReason, { + .belongsTo(() => ReturnReason, { mappedBy: "return_items", }) .nullable(), quantity: model.bigNumber(), received_quantity: model.bigNumber().default(0), damaged_quantity: model.bigNumber().default(0), - return: model.belongsTo(() => Return, { + return: model.belongsTo(() => Return, { mappedBy: "items", }), - item: model.belongsTo(() => OrderLineItem, { + item: model.belongsTo(() => OrderLineItem, { mappedBy: "return_items", }), note: model.text().nullable(), diff --git a/packages/modules/order/src/models/return.ts b/packages/modules/order/src/models/return.ts index 7d420e208bf95..9f83281f6f909 100644 --- a/packages/modules/order/src/models/return.ts +++ b/packages/modules/order/src/models/return.ts @@ -8,13 +8,13 @@ import OrderShipping from "./order-shipping-method" const Return = model .define("Return", { id: model.id({ prefix: "return" }).primaryKey(), - order: model.belongsTo(() => Order, { + order: model.belongsTo(() => Order, { mappedBy: "returns", }), - exchange: model.belongsTo(() => Exchange, { + exchange: model.belongsTo(() => Exchange, { mappedBy: "return", }), - claim: model.belongsTo(() => Claim, { + claim: model.belongsTo(() => Claim, { mappedBy: "return", }), order_version: model.number(), @@ -23,16 +23,16 @@ const Return = model location_id: model.text().nullable(), no_notification: model.boolean().nullable(), refund_amount: model.bigNumber().nullable(), - items: model.hasMany(() => ReturnItem, { + items: model.hasMany(() => ReturnItem, { mappedBy: "return", }), - shipping_methods: model.hasMany(() => OrderShipping, { + shipping_methods: model.hasMany(() => OrderShipping, { mappedBy: "return", }), - transactions: model.hasMany(() => OrderTransaction, { + transactions: model.hasMany(() => OrderTransaction, { mappedBy: "return", }), - changes: model.hasMany(() => OrderChange), + changes: model.hasMany(() => OrderChange), created_by: model.text().nullable(), metadata: model.json().nullable(), requested_at: model.dateTime().nullable(), From 558042bf29709a17e6464c42ed59808b0590fbd5 Mon Sep 17 00:00:00 2001 From: adrien2p Date: Tue, 26 Nov 2024 17:08:01 +0100 Subject: [PATCH 088/175] update order models --- packages/core/utils/src/dml/entity-builder.ts | 33 +++------- packages/core/utils/src/dml/entity.ts | 50 +++++++++++++++- packages/core/utils/src/dml/index.ts | 2 + packages/modules/order/src/models/address.ts | 4 +- .../order/src/models/claim-item-image.ts | 15 +++-- .../modules/order/src/models/claim-item.ts | 23 +++---- packages/modules/order/src/models/claim.ts | 58 +++++++++++------- .../modules/order/src/models/exchange-item.ts | 12 ++-- packages/modules/order/src/models/exchange.ts | 43 +++++++------ packages/modules/order/src/models/index.ts | 44 +++++++------- .../order/src/models/line-item-adjustment.ts | 8 +-- .../order/src/models/line-item-tax-line.ts | 8 +-- .../modules/order/src/models/line-item.ts | 56 ++++++++++------- .../order/src/models/order-change-action.ts | 4 +- .../modules/order/src/models/order-change.ts | 31 +++++----- .../modules/order/src/models/order-item.ts | 12 ++-- .../order/src/models/order-shipping-method.ts | 31 +++++----- .../modules/order/src/models/order-summary.ts | 8 +-- packages/modules/order/src/models/order.ts | 60 +++++++++++-------- .../modules/order/src/models/return-item.ts | 16 ++--- .../modules/order/src/models/return-reason.ts | 26 ++++---- packages/modules/order/src/models/return.ts | 38 +++++++----- .../src/models/shipping-method-adjustment.ts | 15 +++-- .../src/models/shipping-method-tax-line.ts | 15 +++-- .../order/src/models/shipping-method.ts | 37 +++++++----- .../modules/order/src/models/transaction.ts | 20 +++---- 26 files changed, 393 insertions(+), 276 deletions(-) diff --git a/packages/core/utils/src/dml/entity-builder.ts b/packages/core/utils/src/dml/entity-builder.ts index e8654b0a5b7b4..be2fdc8796497 100644 --- a/packages/core/utils/src/dml/entity-builder.ts +++ b/packages/core/utils/src/dml/entity-builder.ts @@ -28,27 +28,6 @@ import { HasMany } from "./relations/has-many" import { HasOne } from "./relations/has-one" import { ManyToMany } from "./relations/many-to-many" -export type Cleanup = { - [K in keyof T]: K extends Exclusion[number] - ? unknown - : T[K] extends RelationshipType - ? null extends RelationResolver - ? RelationshipType< - | (() => Cleanup< - RelationResolver extends () => infer Relation ? Relation : false, - [K & string, ...Exclusion] - >) - | null - > - : RelationshipType< - () => Cleanup< - RelationResolver extends () => infer Relation ? Relation : false, - [K & string, ...Exclusion] - > - > - : T[K] -} - /** * The implicit properties added by EntityBuilder in every schema */ @@ -143,14 +122,20 @@ export class EntityBuilder { define( nameOrConfig: TConfig, schema: Schema - ): DmlEntity & DMLSchemaDefaults, TConfig> { + ): DmlEntity< + DMLSchemaWithBigNumber & DMLSchemaDefaults & Schema, + TConfig + > { this.#disallowImplicitProperties(schema) - return new DmlEntity(nameOrConfig, { + return new DmlEntity(nameOrConfig, { ...schema, ...createBigNumberProperties(schema), ...createDefaultProperties(), - }) as unknown as DmlEntity & DMLSchemaDefaults, TConfig> + } as any) as DmlEntity< + DMLSchemaWithBigNumber & DMLSchemaDefaults & Schema, + TConfig + > } /** diff --git a/packages/core/utils/src/dml/entity.ts b/packages/core/utils/src/dml/entity.ts index ab0f4931be9f7..fe83f7f016fc6 100644 --- a/packages/core/utils/src/dml/entity.ts +++ b/packages/core/utils/src/dml/entity.ts @@ -6,12 +6,60 @@ import { IDmlEntity, IDmlEntityConfig, InferDmlEntityNameFromConfig, + Prettify, QueryCondition, + RelationshipType, } from "@medusajs/types" import { isObject, isString, toCamelCase } from "../common" import { transformIndexWhere } from "./helpers/entity-builder/build-indexes" +import { + HasMany, + HasOne, + ManyToMany, + RelationNullableModifier, +} from "./relations" import { BelongsTo } from "./relations/belongs-to" +// TODO: Might need to remove it, it was to run some tests. +// But we are blocked by circular references in the relation resolver +export type CleanupSchemaCiruclarRef< + T, + Exclusion extends string[] = [] +> = Prettify<{ + [K in keyof T]: K extends Exclusion[number] + ? Omit + : T[K] extends RelationNullableModifier + ? R extends () => infer RV + ? RelationNullableModifier< + () => CleanupSchemaCiruclarRef, + RelationshipType< + () => CleanupSchemaCiruclarRef + > + > + : never + : T[K] extends HasOne + ? R extends () => infer RV + ? HasOne<() => CleanupSchemaCiruclarRef> + : never + : T[K] extends BelongsTo + ? R extends () => infer RV + ? BelongsTo< + () => CleanupSchemaCiruclarRef + > + : never + : T[K] extends HasMany + ? R extends () => infer RV + ? HasMany<() => CleanupSchemaCiruclarRef> + : never + : T[K] extends ManyToMany + ? R extends () => infer RV + ? ManyToMany< + () => CleanupSchemaCiruclarRef + > + : never + : T[K] +}> + const IsDmlEntity = Symbol.for("isDmlEntity") function extractNameAndTableName( @@ -56,7 +104,7 @@ function extractNameAndTableName( * name, its schema and relationships. */ export class DmlEntity< - Schema extends DMLSchema, + const Schema extends DMLSchema, const TConfig extends IDmlEntityConfig > implements IDmlEntity { diff --git a/packages/core/utils/src/dml/index.ts b/packages/core/utils/src/dml/index.ts index 59ed09397612a..a99e40fb5c349 100644 --- a/packages/core/utils/src/dml/index.ts +++ b/packages/core/utils/src/dml/index.ts @@ -4,3 +4,5 @@ export * from "./helpers/entity-builder/index" export * from "./helpers/create-mikro-orm-entity" export * from "./relations/index" export * from "./properties/index" + +export * from "./helpers/entity-builder/index" diff --git a/packages/modules/order/src/models/address.ts b/packages/modules/order/src/models/address.ts index 6ef2e0c102dc9..368819b1270c8 100644 --- a/packages/modules/order/src/models/address.ts +++ b/packages/modules/order/src/models/address.ts @@ -2,7 +2,7 @@ import { model } from "@medusajs/framework/utils" const CustomerIdIndex = "IDX_order_address_customer_id" -const OrderAddress = model +const _OrderAddress = model .define("OrderAddress", { id: model.id({ prefix: "ordaddr" }).primaryKey(), customer_id: model.text().nullable(), @@ -26,4 +26,4 @@ const OrderAddress = model }, ]) -export default OrderAddress +export const OrderAddress = _OrderAddress diff --git a/packages/modules/order/src/models/claim-item-image.ts b/packages/modules/order/src/models/claim-item-image.ts index eb6714739500c..152eca0128491 100644 --- a/packages/modules/order/src/models/claim-item-image.ts +++ b/packages/modules/order/src/models/claim-item-image.ts @@ -1,12 +1,15 @@ import { model } from "@medusajs/framework/utils" -import ClaimItem from "./claim-item" +import { OrderClaimItem } from "./claim-item" -const OrderClaimItemImage = model +const _OrderClaimItemImage = model .define("OrderClaimItemImage", { id: model.id({ prefix: "climg" }).primaryKey(), - claim_item: model.belongsTo(() => ClaimItem, { - mappedBy: "images", - }), + claim_item: model.belongsTo<() => typeof OrderClaimItem>( + () => OrderClaimItem, + { + mappedBy: "images", + } + ), url: model.text(), metadata: model.json().nullable(), }) @@ -25,4 +28,4 @@ const OrderClaimItemImage = model }, ]) -export default OrderClaimItemImage +export const OrderClaimItemImage = _OrderClaimItemImage diff --git a/packages/modules/order/src/models/claim-item.ts b/packages/modules/order/src/models/claim-item.ts index 95c21a4967e7a..052edb2489852 100644 --- a/packages/modules/order/src/models/claim-item.ts +++ b/packages/modules/order/src/models/claim-item.ts @@ -1,20 +1,23 @@ import { ClaimReason, model } from "@medusajs/framework/utils" -import Claim from "./claim" -import OrderClaimItemImage from "./claim-item-image" -import OrderLineItem from "./line-item" +import { OrderClaim } from "./claim" +import { OrderClaimItemImage } from "./claim-item-image" +import { OrderLineItem } from "./line-item" -const OrderClaimItem = model +const _OrderClaimItem = model .define("OrderClaimItem", { id: model.id({ prefix: "claitem" }).primaryKey(), - images: model.hasMany(() => OrderClaimItemImage, { - mappedBy: "item", - }), + images: model.hasMany<() => typeof OrderClaimItemImage>( + () => OrderClaimItemImage, + { + mappedBy: "item", + } + ), reason: model.enum(ClaimReason).nullable(), quantity: model.bigNumber(), - claim: model.belongsTo(() => Claim, { + claim: model.belongsTo<() => typeof OrderClaim>(() => OrderClaim, { mappedBy: "items", }), - item: model.belongsTo(() => OrderLineItem, { + item: model.belongsTo<() => typeof OrderLineItem>(() => OrderLineItem, { mappedBy: "claim_items", }), is_additional_item: model.boolean().default(false), @@ -42,4 +45,4 @@ const OrderClaimItem = model }, ]) -export default OrderClaimItem +export const OrderClaimItem = _OrderClaimItem diff --git a/packages/modules/order/src/models/claim.ts b/packages/modules/order/src/models/claim.ts index ff09fde5c82cf..19c8be12810e5 100644 --- a/packages/modules/order/src/models/claim.ts +++ b/packages/modules/order/src/models/claim.ts @@ -1,19 +1,19 @@ import { ClaimType, model } from "@medusajs/framework/utils" -import ClaimItem from "./claim-item" -import Order from "./order" -import OrderChange from "./order-change" -import OrderShipping from "./order-shipping-method" -import Return from "./return" -import OrderTransaction from "./transaction" +import { OrderClaimItem } from "./claim-item" +import { Order } from "./order" +import { OrderChange } from "./order-change" +import { OrderShipping } from "./order-shipping-method" +import { Return } from "./return" +import { OrderTransaction } from "./transaction" -const OrderClaim = model +const _OrderClaim = model .define("OrderClaim", { id: model.id({ prefix: "claim" }).primaryKey(), - order: model.belongsTo(() => Order, { + order: model.belongsTo<() => typeof Order>(() => Order, { mappedBy: "claims", }), return_id: model.text().nullable(), - return: model.hasMany(() => Return, { + return: model.hasMany<() => typeof Return>(() => Return, { mappedBy: "claim", }), order_version: model.number(), @@ -21,19 +21,31 @@ const OrderClaim = model type: model.enum(ClaimType), no_notification: model.boolean().nullable(), refund_amount: model.bigNumber().nullable(), - additional_items: model.hasMany(() => ClaimItem, { - mappedBy: "claim", - }), - claim_items: model.hasMany(() => ClaimItem, { - mappedBy: "claim", - }), - shipping_methods: model.hasMany(() => OrderShipping, { - mappedBy: "claim", - }), - transactions: model.hasMany(() => OrderTransaction, { - mappedBy: "claim", - }), - changes: model.hasMany(() => OrderChange), + additional_items: model.hasMany<() => typeof OrderClaimItem>( + () => OrderClaimItem, + { + mappedBy: "claim", + } + ), + claim_items: model.hasMany<() => typeof OrderClaimItem>( + () => OrderClaimItem, + { + mappedBy: "claim", + } + ), + shipping_methods: model.hasMany<() => typeof OrderShipping>( + () => OrderShipping, + { + mappedBy: "claim", + } + ), + transactions: model.hasMany<() => typeof OrderTransaction>( + () => OrderTransaction, + { + mappedBy: "claim", + } + ), + changes: model.hasMany<() => typeof OrderChange>(() => OrderChange), created_by: model.text().nullable(), canceled_at: model.dateTime().nullable(), metadata: model.json().nullable(), @@ -65,4 +77,4 @@ const OrderClaim = model }, ]) -export default OrderClaim +export const OrderClaim = _OrderClaim diff --git a/packages/modules/order/src/models/exchange-item.ts b/packages/modules/order/src/models/exchange-item.ts index 2f9db9aa6c5c9..43e238aba78c7 100644 --- a/packages/modules/order/src/models/exchange-item.ts +++ b/packages/modules/order/src/models/exchange-item.ts @@ -1,15 +1,15 @@ import { model } from "@medusajs/framework/utils" -import Exchange from "./exchange" -import OrderLineItem from "./line-item" +import { OrderExchange } from "./exchange" +import { OrderLineItem } from "./line-item" -const OrderExchangeItem = model +const _OrderExchangeItem = model .define("OrderExchangeItem", { id: model.id({ prefix: "oexcitem" }).primaryKey(), quantity: model.bigNumber(), - exchange: model.belongsTo(() => Exchange, { + exchange: model.belongsTo<() => typeof OrderExchange>(() => OrderExchange, { mappedBy: "additional_items", }), - item: model.belongsTo(() => OrderLineItem, { + item: model.belongsTo<() => typeof OrderLineItem>(() => OrderLineItem, { mappedBy: "exchange_items", }), note: model.text().nullable(), @@ -36,4 +36,4 @@ const OrderExchangeItem = model }, ]) -export default OrderExchangeItem +export const OrderExchangeItem = _OrderExchangeItem diff --git a/packages/modules/order/src/models/exchange.ts b/packages/modules/order/src/models/exchange.ts index f19ecfa27626f..d9e3b48096c9e 100644 --- a/packages/modules/order/src/models/exchange.ts +++ b/packages/modules/order/src/models/exchange.ts @@ -1,17 +1,17 @@ import { model } from "@medusajs/framework/utils" import { OrderChange, OrderExchangeItem, OrderTransaction } from "@models" -import Order from "./order" -import OrderShipping from "./order-shipping-method" -import Return from "./return" +import { Order } from "./order" +import { OrderShipping } from "./order-shipping-method" +import { Return } from "./return" -const OrderExchange = model +const _OrderExchange = model .define("OrderExchange", { id: model.id({ prefix: "oexc" }).primaryKey(), - order: model.belongsTo(() => Order, { + order: model.belongsTo<() => typeof Order>(() => Order, { mappedBy: "exchanges", }), return_id: model.text().nullable(), - return: model.hasMany(() => Return, { + return: model.hasMany<() => typeof Return>(() => Return, { mappedBy: "exchange", }), order_version: model.number(), @@ -19,16 +19,25 @@ const OrderExchange = model no_notification: model.boolean().nullable(), difference_due: model.bigNumber().nullable(), allow_backorder: model.boolean().default(false), - additional_items: model.hasMany(() => OrderExchangeItem, { - mappedBy: "exchange", - }), - shipping_methods: model.hasMany(() => OrderShipping, { - mappedBy: "exchange", - }), - transactions: model.hasMany(() => OrderTransaction, { - mappedBy: "exchange", - }), - changes: model.hasMany(() => OrderChange), + additional_items: model.hasMany<() => typeof OrderExchangeItem>( + () => OrderExchangeItem, + { + mappedBy: "exchange", + } + ), + shipping_methods: model.hasMany<() => typeof OrderShipping>( + () => OrderShipping, + { + mappedBy: "exchange", + } + ), + transactions: model.hasMany<() => typeof OrderTransaction>( + () => OrderTransaction, + { + mappedBy: "exchange", + } + ), + changes: model.hasMany<() => typeof OrderChange>(() => OrderChange), created_by: model.text().nullable(), metadata: model.json().nullable(), canceled_at: model.dateTime().nullable(), @@ -60,4 +69,4 @@ const OrderExchange = model }, ]) -export default OrderExchange +export const OrderExchange = _OrderExchange diff --git a/packages/modules/order/src/models/index.ts b/packages/modules/order/src/models/index.ts index 8262fb98d1e69..2acec1bad6234 100644 --- a/packages/modules/order/src/models/index.ts +++ b/packages/modules/order/src/models/index.ts @@ -1,22 +1,22 @@ -export { default as OrderAddress } from "./address" -export { default as OrderClaim } from "./claim" -export { default as OrderClaimItem } from "./claim-item" -export { default as OrderClaimItemImage } from "./claim-item-image" -export { default as OrderExchange } from "./exchange" -export { default as OrderExchangeItem } from "./exchange-item" -export { default as OrderLineItem } from "./line-item" -export { default as OrderLineItemAdjustment } from "./line-item-adjustment" -export { default as OrderLineItemTaxLine } from "./line-item-tax-line" -export { default as Order } from "./order" -export { default as OrderChange } from "./order-change" -export { default as OrderChangeAction } from "./order-change-action" -export { default as OrderItem } from "./order-item" -export { default as OrderShipping } from "./order-shipping-method" -export { default as OrderSummary } from "./order-summary" -export { default as Return } from "./return" -export { default as ReturnItem } from "./return-item" -export { default as ReturnReason } from "./return-reason" -export { default as OrderShippingMethod } from "./shipping-method" -export { default as OrderShippingMethodAdjustment } from "./shipping-method-adjustment" -export { default as OrderShippingMethodTaxLine } from "./shipping-method-tax-line" -export { default as OrderTransaction } from "./transaction" +export { OrderAddress } from "./address" +export { OrderClaim } from "./claim" +export { OrderClaimItem } from "./claim-item" +export { OrderClaimItemImage } from "./claim-item-image" +export { OrderExchangeItem } from "./exchange-item" +export { OrderExchange } from "./exchange" +export { OrderLineItem } from "./line-item" +export { OrderLineItemAdjustment } from "./line-item-adjustment" +export { OrderLineItemTaxLine } from "./line-item-tax-line" +export { Order } from "./order" +export { OrderChange } from "./order-change" +export { OrderChangeAction } from "./order-change-action" +export { OrderItem } from "./order-item" +export { OrderShipping } from "./order-shipping-method" +export { OrderSummary } from "./order-summary" +export { Return } from "./return" +export { ReturnItem } from "./return-item" +export { ReturnReason } from "./return-reason" +export { OrderShippingMethod } from "./shipping-method" +export { OrderShippingMethodAdjustment } from "./shipping-method-adjustment" +export { OrderShippingMethodTaxLine } from "./shipping-method-tax-line" +export { OrderTransaction } from "./transaction" diff --git a/packages/modules/order/src/models/line-item-adjustment.ts b/packages/modules/order/src/models/line-item-adjustment.ts index fb6065f70f434..bcc32a8af4f75 100644 --- a/packages/modules/order/src/models/line-item-adjustment.ts +++ b/packages/modules/order/src/models/line-item-adjustment.ts @@ -1,7 +1,7 @@ import { model } from "@medusajs/framework/utils" -import OrderLineItem from "./line-item" +import { OrderLineItem } from "./line-item" -const OrderLineItemAdjustment = model +const _OrderLineItemAdjustment = model .define("OrderLineItemAdjustment", { id: model.id({ prefix: "ordliadj" }).primaryKey(), description: model.text().nullable(), @@ -9,7 +9,7 @@ const OrderLineItemAdjustment = model code: model.text().nullable(), amount: model.bigNumber(), provider_id: model.text().nullable(), - item: model.belongsTo(() => OrderLineItem, { + item: model.belongsTo<() => typeof OrderLineItem>(() => OrderLineItem, { mappedBy: "adjustments", }), }) @@ -21,4 +21,4 @@ const OrderLineItemAdjustment = model }, ]) -export default OrderLineItemAdjustment +export const OrderLineItemAdjustment = _OrderLineItemAdjustment diff --git a/packages/modules/order/src/models/line-item-tax-line.ts b/packages/modules/order/src/models/line-item-tax-line.ts index d4a8e70bbddad..f8158723634e2 100644 --- a/packages/modules/order/src/models/line-item-tax-line.ts +++ b/packages/modules/order/src/models/line-item-tax-line.ts @@ -1,7 +1,7 @@ import { model } from "@medusajs/framework/utils" -import OrderLineItem from "./line-item" +import { OrderLineItem } from "./line-item" -const OrderLineItemTaxLine = model +const _OrderLineItemTaxLine = model .define("OrderLineItemTaxLine", { id: model.id({ prefix: "ordlitxl" }).primaryKey(), description: model.text().nullable(), @@ -9,7 +9,7 @@ const OrderLineItemTaxLine = model code: model.text(), rate: model.bigNumber(), provider_id: model.text().nullable(), - item: model.belongsTo(() => OrderLineItem, { + item: model.belongsTo<() => typeof OrderLineItem>(() => OrderLineItem, { mappedBy: "tax_lines", }), }) @@ -21,4 +21,4 @@ const OrderLineItemTaxLine = model }, ]) -export default OrderLineItemTaxLine +export const OrderLineItemTaxLine = _OrderLineItemTaxLine diff --git a/packages/modules/order/src/models/line-item.ts b/packages/modules/order/src/models/line-item.ts index 59e3e2e3e1156..1e7c61524ef9a 100644 --- a/packages/modules/order/src/models/line-item.ts +++ b/packages/modules/order/src/models/line-item.ts @@ -1,12 +1,12 @@ import { model } from "@medusajs/framework/utils" -import OrderClaimItem from "./claim-item" -import OrderExchangeItem from "./exchange-item" -import OrderLineItemAdjustment from "./line-item-adjustment" -import OrderLineItemTaxLine from "./line-item-tax-line" -import OrderItem from "./order-item" -import ReturnItem from "./return-item" +import { OrderClaimItem } from "./claim-item" +import { OrderExchangeItem } from "./exchange-item" +import { OrderLineItemAdjustment } from "./line-item-adjustment" +import { OrderLineItemTaxLine } from "./line-item-tax-line" +import { OrderItem } from "./order-item" +import { ReturnItem } from "./return-item" -const OrderLineItem = model +const _OrderLineItem = model .define("OrderLineItem", { id: model.id({ prefix: "ordli" }).primaryKey(), title: model.text(), @@ -32,24 +32,36 @@ const OrderLineItem = model unit_price: model.bigNumber(), is_custom_price: model.boolean().default(false), metadata: model.json().nullable(), - tax_lines: model.hasMany(() => OrderLineItemTaxLine, { + tax_lines: model.hasMany<() => typeof OrderLineItemTaxLine>( + () => OrderLineItemTaxLine, + { + mappedBy: "item", + } + ), + adjustments: model.hasMany<() => typeof OrderLineItemAdjustment>( + () => OrderLineItemAdjustment, + { + mappedBy: "item", + } + ), + items: model.hasMany<() => typeof OrderItem>(() => OrderItem, { mappedBy: "item", }), - adjustments: model.hasMany(() => OrderLineItemAdjustment, { - mappedBy: "item", - }), - items: model.hasMany(() => OrderItem, { - mappedBy: "item", - }), - return_items: model.hasMany(() => ReturnItem, { - mappedBy: "item", - }), - claim_items: model.hasMany(() => OrderClaimItem, { - mappedBy: "item", - }), - exchange_items: model.hasMany(() => OrderExchangeItem, { + return_items: model.hasMany<() => typeof ReturnItem>(() => ReturnItem, { mappedBy: "item", }), + claim_items: model.hasMany<() => typeof OrderClaimItem>( + () => OrderClaimItem, + { + mappedBy: "item", + } + ), + exchange_items: model.hasMany<() => typeof OrderExchangeItem>( + () => OrderExchangeItem, + { + mappedBy: "item", + } + ), }) .indexes([ { @@ -78,4 +90,4 @@ const OrderLineItem = model }, ]) -export default OrderLineItem +export const OrderLineItem = _OrderLineItem diff --git a/packages/modules/order/src/models/order-change-action.ts b/packages/modules/order/src/models/order-change-action.ts index c3527cd0f9d6e..0ae713c78d9bb 100644 --- a/packages/modules/order/src/models/order-change-action.ts +++ b/packages/modules/order/src/models/order-change-action.ts @@ -1,6 +1,6 @@ import { model } from "@medusajs/framework/utils" -const OrderChangeAction = model +const _OrderChangeAction = model .define("OrderChangeAction", { id: model.id({ prefix: "ordchact" }).primaryKey(), ordering: model.autoincrement(), @@ -63,4 +63,4 @@ const OrderChangeAction = model }, ]) -export default OrderChangeAction +export const OrderChangeAction = _OrderChangeAction diff --git a/packages/modules/order/src/models/order-change.ts b/packages/modules/order/src/models/order-change.ts index 53953a2eca29a..91c050aa2540d 100644 --- a/packages/modules/order/src/models/order-change.ts +++ b/packages/modules/order/src/models/order-change.ts @@ -1,36 +1,39 @@ import { model, OrderChangeStatus } from "@medusajs/framework/utils" -import OrderClaim from "./claim" -import OrderExchange from "./exchange" -import Order from "./order" -import OrderChangeAction from "./order-change-action" -import Return from "./return" +import { OrderClaim } from "./claim" +import { OrderExchange } from "./exchange" +import { Order } from "./order" +import { OrderChangeAction } from "./order-change-action" +import { Return } from "./return" -const OrderChange = model +const _OrderChange = model .define("OrderChange", { id: model.id({ prefix: "ordch" }).primaryKey(), - order: model.belongsTo(() => Order, { + order: model.belongsTo<() => typeof Order>(() => Order, { mappedBy: "changes", }), return: model - .belongsTo(() => Return, { + .belongsTo<() => typeof Return>(() => Return, { mappedBy: "changes", }) .nullable(), claim: model - .belongsTo(() => OrderClaim, { + .belongsTo<() => typeof OrderClaim>(() => OrderClaim, { mappedBy: "changes", }) .nullable(), exchange: model - .belongsTo(() => OrderExchange, { + .belongsTo<() => typeof OrderExchange>(() => OrderExchange, { mappedBy: "changes", }) .nullable(), version: model.number(), change_type: model.text().nullable(), - actions: model.hasMany(() => OrderChangeAction, { - mappedBy: "order_change", - }), + actions: model.hasMany<() => typeof OrderChangeAction>( + () => OrderChangeAction, + { + mappedBy: "order_change", + } + ), description: model.text().nullable(), status: model.enum(OrderChangeStatus).default(OrderChangeStatus.PENDING), internal_note: model.text().nullable(), @@ -91,4 +94,4 @@ const OrderChange = model }, ]) -export default OrderChange +export const OrderChange = _OrderChange diff --git a/packages/modules/order/src/models/order-item.ts b/packages/modules/order/src/models/order-item.ts index 81aa9b72dde33..a2e7a773f73b8 100644 --- a/packages/modules/order/src/models/order-item.ts +++ b/packages/modules/order/src/models/order-item.ts @@ -1,15 +1,15 @@ import { model } from "@medusajs/framework/utils" -import OrderLineItem from "./line-item" -import Order from "./order" +import { OrderLineItem } from "./line-item" +import { Order } from "./order" -const OrderItem = model +const _OrderItem = model .define("OrderItem", { id: model.id({ prefix: "orditem" }).primaryKey(), - order: model.belongsTo(() => Order, { + order: model.belongsTo<() => typeof Order>(() => Order, { mappedBy: "items", }), version: model.number(), - item: model.belongsTo(() => OrderLineItem, { + item: model.belongsTo<() => typeof OrderLineItem>(() => OrderLineItem, { mappedBy: "items", }), unit_price: model.bigNumber().nullable(), @@ -51,4 +51,4 @@ const OrderItem = model }, ]) -export default OrderItem +export const OrderItem = _OrderItem diff --git a/packages/modules/order/src/models/order-shipping-method.ts b/packages/modules/order/src/models/order-shipping-method.ts index e2fde15d31a02..a4c3a9e18ec05 100644 --- a/packages/modules/order/src/models/order-shipping-method.ts +++ b/packages/modules/order/src/models/order-shipping-method.ts @@ -1,35 +1,38 @@ import { model } from "@medusajs/framework/utils" -import Claim from "./claim" -import Exchange from "./exchange" -import Order from "./order" -import Return from "./return" -import OrderShippingMethod from "./shipping-method" +import { OrderClaim } from "./claim" +import { OrderExchange } from "./exchange" +import { Order } from "./order" +import { Return } from "./return" +import { OrderShippingMethod } from "./shipping-method" -const OrderShipping = model +const _OrderShipping = model .define("OrderShipping", { id: model.id({ prefix: "ordspmv" }).primaryKey(), version: model.number(), - order: model.belongsTo(() => Order, { + order: model.belongsTo<() => typeof Order>(() => Order, { mappedBy: "shipping_methods", }), return: model - .belongsTo(() => Return, { + .belongsTo<() => typeof Return>(() => Return, { mappedBy: "shipping_methods", }) .nullable(), exchange: model - .belongsTo(() => Exchange, { + .belongsTo<() => typeof OrderExchange>(() => OrderExchange, { mappedBy: "shipping_methods", }) .nullable(), claim: model - .belongsTo(() => Claim, { + .belongsTo<() => typeof OrderClaim>(() => OrderClaim, { mappedBy: "shipping_methods", }) .nullable(), - shipping_method: model.belongsTo(() => OrderShippingMethod, { - mappedBy: "shipping_methods", - }), + shipping_method: model.belongsTo<() => typeof OrderShippingMethod>( + () => OrderShippingMethod, + { + mappedBy: "shipping_methods", + } + ), }) .indexes([ { @@ -76,4 +79,4 @@ const OrderShipping = model }, ]) -export default OrderShipping +export const OrderShipping = _OrderShipping diff --git a/packages/modules/order/src/models/order-summary.ts b/packages/modules/order/src/models/order-summary.ts index 90a4c9efdd12d..607d97d8e58c4 100644 --- a/packages/modules/order/src/models/order-summary.ts +++ b/packages/modules/order/src/models/order-summary.ts @@ -1,12 +1,12 @@ import { model } from "@medusajs/framework/utils" -import Order from "./order" +import { Order } from "./order" -const OrderSummary = model +const _OrderSummary = model .define("OrderSummary", { id: model.id({ prefix: "ordsum" }).primaryKey(), version: model.number().default(1), totals: model.json(), - order: model.belongsTo(() => Order, { + order: model.belongsTo<() => typeof Order>(() => Order, { mappedBy: "summary", }), }) @@ -25,4 +25,4 @@ const OrderSummary = model }, ]) -export default OrderSummary +export const OrderSummary = _OrderSummary diff --git a/packages/modules/order/src/models/order.ts b/packages/modules/order/src/models/order.ts index 68f2e2f55a567..e1695e49bd597 100644 --- a/packages/modules/order/src/models/order.ts +++ b/packages/modules/order/src/models/order.ts @@ -1,15 +1,15 @@ import { model, OrderStatus } from "@medusajs/framework/utils" -import OrderAddress from "./address" -import OrderClaim from "./claim" -import OrderExchange from "./exchange" -import OrderChange from "./order-change" -import OrderItem from "./order-item" -import OrderShipping from "./order-shipping-method" -import OrderSummary from "./order-summary" -import Return from "./return" -import OrderTransaction from "./transaction" +import { OrderAddress } from "./address" +import { OrderClaim } from "./claim" +import { OrderExchange } from "./exchange" +import { OrderChange } from "./order-change" +import { OrderItem } from "./order-item" +import { OrderShipping } from "./order-shipping-method" +import { OrderSummary } from "./order-summary" +import { Return } from "./return" +import { OrderTransaction } from "./transaction" -const Order = model +const _Order = model .define("Order", { id: model.id({ prefix: "order" }).primaryKey(), display_id: model.autoincrement(), @@ -21,34 +21,44 @@ const Order = model is_draft_order: model.boolean().default(false), email: model.text().searchable().nullable(), currency_code: model.text(), - shipping_address: model.belongsTo(() => OrderAddress), - billing_address: model.belongsTo(() => OrderAddress), + shipping_address: model.belongsTo<() => typeof OrderAddress>( + () => OrderAddress + ), + billing_address: model.belongsTo<() => typeof OrderAddress>( + () => OrderAddress + ), no_notification: model.boolean().nullable(), metadata: model.json().nullable(), - summary: model.hasMany(() => OrderSummary, { + summary: model.hasMany<() => typeof OrderSummary>(() => OrderSummary, { mappedBy: "order", }), - items: model.hasMany(() => OrderItem, { - mappedBy: "order", - }), - shipping_methods: model.hasMany(() => OrderShipping, { - mappedBy: "order", - }), - transactions: model.hasMany(() => OrderTransaction, { + items: model.hasMany<() => typeof OrderItem>(() => OrderItem, { mappedBy: "order", }), + shipping_methods: model.hasMany<() => typeof OrderShipping>( + () => OrderShipping, + { + mappedBy: "order", + } + ), + transactions: model.hasMany<() => typeof OrderTransaction>( + () => OrderTransaction, + { + mappedBy: "order", + } + ), canceled_at: model.dateTime().nullable(), - exchanges: model.hasMany(() => OrderExchange, { + exchanges: model.hasMany<() => typeof OrderExchange>(() => OrderExchange, { mappedBy: "order", }), - claims: model.hasMany(() => OrderClaim, { + claims: model.hasMany<() => typeof OrderClaim>(() => OrderClaim, { mappedBy: "order", }), - returns: model.hasMany(() => Return, { + returns: model.hasMany<() => typeof Return>(() => Return, { mappedBy: "order", }), - changes: model.hasMany(() => OrderChange), + changes: model.hasMany<() => typeof OrderChange>(() => OrderChange), }) .indexes([ { @@ -107,4 +117,4 @@ const Order = model }, ]) -export default Order +export const Order = _Order diff --git a/packages/modules/order/src/models/return-item.ts b/packages/modules/order/src/models/return-item.ts index baf5a39f35fb6..d7f0024b4df95 100644 --- a/packages/modules/order/src/models/return-item.ts +++ b/packages/modules/order/src/models/return-item.ts @@ -1,23 +1,23 @@ import { model } from "@medusajs/framework/utils" -import OrderLineItem from "./line-item" -import Return from "./return" -import ReturnReason from "./return-reason" +import { OrderLineItem } from "./line-item" +import { Return } from "./return" +import { ReturnReason } from "./return-reason" -const ReturnItem = model +const _ReturnItem = model .define("ReturnItem", { id: model.id({ prefix: "retitem" }).primaryKey(), reason: model - .belongsTo(() => ReturnReason, { + .belongsTo<() => typeof ReturnReason>(() => ReturnReason, { mappedBy: "return_items", }) .nullable(), quantity: model.bigNumber(), received_quantity: model.bigNumber().default(0), damaged_quantity: model.bigNumber().default(0), - return: model.belongsTo(() => Return, { + return: model.belongsTo<() => typeof Return>(() => Return, { mappedBy: "items", }), - item: model.belongsTo(() => OrderLineItem, { + item: model.belongsTo<() => typeof OrderLineItem>(() => OrderLineItem, { mappedBy: "return_items", }), note: model.text().nullable(), @@ -50,4 +50,4 @@ const ReturnItem = model }, ]) -export default ReturnItem +export const ReturnItem = _ReturnItem diff --git a/packages/modules/order/src/models/return-reason.ts b/packages/modules/order/src/models/return-reason.ts index 89a565f6fe87c..effdbb2b217aa 100644 --- a/packages/modules/order/src/models/return-reason.ts +++ b/packages/modules/order/src/models/return-reason.ts @@ -1,20 +1,26 @@ import { model } from "@medusajs/framework/utils" -import ReturnItem from "./return-item" +import { ReturnItem } from "./return-item" -const ReturnReason = model +const _ReturnReason = model .define("ReturnReason", { id: model.id({ prefix: "rr" }).primaryKey(), value: model.text().searchable(), label: model.text().searchable(), description: model.text().nullable(), parent_return_reason_id: model.text().nullable(), - parent_return_reason: model.belongsTo(() => ReturnReason, { - mappedBy: "return_reason_children", - }), - return_reason_children: model.hasMany(() => ReturnReason, { - mappedBy: "parent_return_reason", - }), - return_items: model.hasMany(() => ReturnItem, { + parent_return_reason: model.belongsTo<() => typeof _ReturnReason>( + () => _ReturnReason, + { + mappedBy: "return_reason_children", + } + ), + return_reason_children: model.hasMany<() => typeof _ReturnReason>( + () => _ReturnReason, + { + mappedBy: "parent_return_reason", + } + ), + return_items: model.hasMany<() => typeof ReturnItem>(() => ReturnItem, { mappedBy: "reason", }), metadata: model.json().nullable(), @@ -40,4 +46,4 @@ const ReturnReason = model }, ]) -export default ReturnReason +export const ReturnReason = _ReturnReason diff --git a/packages/modules/order/src/models/return.ts b/packages/modules/order/src/models/return.ts index 9f83281f6f909..5a31a56b894ef 100644 --- a/packages/modules/order/src/models/return.ts +++ b/packages/modules/order/src/models/return.ts @@ -1,20 +1,20 @@ import { model, ReturnStatus } from "@medusajs/framework/utils" import { OrderChange, OrderTransaction, ReturnItem } from "@models" -import Claim from "./claim" -import Exchange from "./exchange" -import Order from "./order" -import OrderShipping from "./order-shipping-method" +import { OrderClaim } from "./claim" +import { OrderExchange } from "./exchange" +import { Order } from "./order" +import { OrderShipping } from "./order-shipping-method" -const Return = model +const _Return = model .define("Return", { id: model.id({ prefix: "return" }).primaryKey(), - order: model.belongsTo(() => Order, { + order: model.belongsTo<() => typeof Order>(() => Order, { mappedBy: "returns", }), - exchange: model.belongsTo(() => Exchange, { + exchange: model.belongsTo<() => typeof OrderExchange>(() => OrderExchange, { mappedBy: "return", }), - claim: model.belongsTo(() => Claim, { + claim: model.belongsTo<() => typeof OrderClaim>(() => OrderClaim, { mappedBy: "return", }), order_version: model.number(), @@ -26,13 +26,19 @@ const Return = model items: model.hasMany(() => ReturnItem, { mappedBy: "return", }), - shipping_methods: model.hasMany(() => OrderShipping, { - mappedBy: "return", - }), - transactions: model.hasMany(() => OrderTransaction, { - mappedBy: "return", - }), - changes: model.hasMany(() => OrderChange), + shipping_methods: model.hasMany<() => typeof OrderShipping>( + () => OrderShipping, + { + mappedBy: "return", + } + ), + transactions: model.hasMany<() => typeof OrderTransaction>( + () => OrderTransaction, + { + mappedBy: "return", + } + ), + changes: model.hasMany<() => typeof OrderChange>(() => OrderChange), created_by: model.text().nullable(), metadata: model.json().nullable(), requested_at: model.dateTime().nullable(), @@ -72,4 +78,4 @@ const Return = model }, ]) -export default Return +export const Return = _Return diff --git a/packages/modules/order/src/models/shipping-method-adjustment.ts b/packages/modules/order/src/models/shipping-method-adjustment.ts index f7c3c5f5bf36f..01fa946b4430e 100644 --- a/packages/modules/order/src/models/shipping-method-adjustment.ts +++ b/packages/modules/order/src/models/shipping-method-adjustment.ts @@ -1,7 +1,7 @@ import { model } from "@medusajs/framework/utils" -import OrderShippingMethod from "./shipping-method" +import { OrderShippingMethod } from "./shipping-method" -const OrderShippingMethodAdjustment = model +const _OrderShippingMethodAdjustment = model .define("OrderShippingMethodAdjustment", { id: model.id({ prefix: "ordsmadj" }).primaryKey(), description: model.text().nullable(), @@ -9,9 +9,12 @@ const OrderShippingMethodAdjustment = model code: model.text().nullable(), amount: model.bigNumber(), provider_id: model.text().nullable(), - shipping_method: model.belongsTo(() => OrderShippingMethod, { - mappedBy: "adjustments", - }), + shipping_method: model.belongsTo<() => typeof OrderShippingMethod>( + () => OrderShippingMethod, + { + mappedBy: "adjustments", + } + ), }) .indexes([ { @@ -21,4 +24,4 @@ const OrderShippingMethodAdjustment = model }, ]) -export default OrderShippingMethodAdjustment +export const OrderShippingMethodAdjustment = _OrderShippingMethodAdjustment diff --git a/packages/modules/order/src/models/shipping-method-tax-line.ts b/packages/modules/order/src/models/shipping-method-tax-line.ts index f1630eaf920c4..e49a9668504ff 100644 --- a/packages/modules/order/src/models/shipping-method-tax-line.ts +++ b/packages/modules/order/src/models/shipping-method-tax-line.ts @@ -1,7 +1,7 @@ import { model } from "@medusajs/framework/utils" -import OrderShippingMethod from "./shipping-method" +import { OrderShippingMethod } from "./shipping-method" -const OrderShippingMethodTaxLine = model +const _OrderShippingMethodTaxLine = model .define("OrderShippingMethodTaxLine", { id: model.id({ prefix: "ordsmtxl" }).primaryKey(), description: model.text().nullable(), @@ -9,9 +9,12 @@ const OrderShippingMethodTaxLine = model code: model.text(), rate: model.bigNumber(), provider_id: model.text().nullable(), - shipping_method: model.belongsTo(() => OrderShippingMethod, { - mappedBy: "tax_lines", - }), + shipping_method: model.belongsTo<() => typeof OrderShippingMethod>( + () => OrderShippingMethod, + { + mappedBy: "tax_lines", + } + ), }) .indexes([ { @@ -21,4 +24,4 @@ const OrderShippingMethodTaxLine = model }, ]) -export default OrderShippingMethodTaxLine +export const OrderShippingMethodTaxLine = _OrderShippingMethodTaxLine diff --git a/packages/modules/order/src/models/shipping-method.ts b/packages/modules/order/src/models/shipping-method.ts index c3edd9b9e2ecc..427789a1c24ca 100644 --- a/packages/modules/order/src/models/shipping-method.ts +++ b/packages/modules/order/src/models/shipping-method.ts @@ -1,9 +1,9 @@ import { model } from "@medusajs/framework/utils" -import OrderShipping from "./order-shipping-method" -import OrderShippingMethodAdjustment from "./shipping-method-adjustment" -import OrderShippingMethodTaxLine from "./shipping-method-tax-line" +import { OrderShipping } from "./order-shipping-method" +import { OrderShippingMethodAdjustment } from "./shipping-method-adjustment" +import { OrderShippingMethodTaxLine } from "./shipping-method-tax-line" -const OrderShippingMethod = model +const _OrderShippingMethod = model .define("OrderShippingMethod", { id: model.id({ prefix: "ordsm" }).primaryKey(), name: model.text(), @@ -14,15 +14,24 @@ const OrderShippingMethod = model shipping_option_id: model.text().nullable(), data: model.json().nullable(), metadata: model.json().nullable(), - tax_lines: model.hasMany(() => OrderShippingMethodTaxLine, { - mappedBy: "shipping_method", - }), - adjustments: model.hasMany(() => OrderShippingMethodAdjustment, { - mappedBy: "shipping_method", - }), - shipping_methods: model.hasMany(() => OrderShipping, { - mappedBy: "shipping_method", - }), + tax_lines: model.hasMany<() => typeof OrderShippingMethodTaxLine>( + () => OrderShippingMethodTaxLine, + { + mappedBy: "shipping_method", + } + ), + adjustments: model.hasMany<() => typeof OrderShippingMethodAdjustment>( + () => OrderShippingMethodAdjustment, + { + mappedBy: "shipping_method", + } + ), + shipping_methods: model.hasMany<() => typeof OrderShipping>( + () => OrderShipping, + { + mappedBy: "shipping_method", + } + ), }) .indexes([ { @@ -32,4 +41,4 @@ const OrderShippingMethod = model }, ]) -export default OrderShippingMethod +export const OrderShippingMethod = _OrderShippingMethod diff --git a/packages/modules/order/src/models/transaction.ts b/packages/modules/order/src/models/transaction.ts index 319fea0ae7506..3054a74604d10 100644 --- a/packages/modules/order/src/models/transaction.ts +++ b/packages/modules/order/src/models/transaction.ts @@ -1,22 +1,22 @@ import { model } from "@medusajs/framework/utils" -import OrderClaim from "./claim" -import OrderExchange from "./exchange" -import Order from "./order" -import Return from "./return" +import { OrderClaim } from "./claim" +import { OrderExchange } from "./exchange" +import { Order } from "./order" +import { Return } from "./return" -const OrderTransaction = model +const _OrderTransaction = model .define("OrderTransaction", { id: model.id({ prefix: "ordtrx" }).primaryKey(), - order: model.belongsTo(() => Order, { + order: model.belongsTo<() => typeof Order>(() => Order, { mappedBy: "transactions", }), - return: model.belongsTo(() => Return, { + return: model.belongsTo<() => typeof Return>(() => Return, { mappedBy: "transactions", }), - exchange: model.belongsTo(() => OrderExchange, { + exchange: model.belongsTo<() => typeof OrderExchange>(() => OrderExchange, { mappedBy: "transactions", }), - claim: model.belongsTo(() => OrderClaim, { + claim: model.belongsTo<() => typeof OrderClaim>(() => OrderClaim, { mappedBy: "transactions", }), version: model.number().default(1), @@ -76,4 +76,4 @@ const OrderTransaction = model }, ]) -export default OrderTransaction +export const OrderTransaction = _OrderTransaction From b9a5240f02de9aea62441b0a74e521c2186a239e Mon Sep 17 00:00:00 2001 From: adrien2p Date: Tue, 26 Nov 2024 17:41:38 +0100 Subject: [PATCH 089/175] partially fix types temporarely --- packages/core/utils/src/dml/entity-builder.ts | 1 - .../order/src/models/claim-item-image.ts | 2 +- .../modules/order/src/models/claim-item.ts | 20 ++++++--- packages/modules/order/src/models/claim.ts | 16 ++++--- .../modules/order/src/models/exchange-item.ts | 18 +++++--- packages/modules/order/src/models/exchange.ts | 14 +++--- .../order/src/models/line-item-adjustment.ts | 9 ++-- .../order/src/models/line-item-tax-line.ts | 9 ++-- .../modules/order/src/models/line-item.ts | 26 ++++++----- .../modules/order/src/models/order-change.ts | 10 ++--- .../modules/order/src/models/order-item.ts | 11 +++-- .../order/src/models/order-shipping-method.ts | 21 ++++----- .../modules/order/src/models/order-summary.ts | 2 +- packages/modules/order/src/models/order.ts | 43 ++++++++++++------- .../modules/order/src/models/return-item.ts | 13 +++--- .../modules/order/src/models/return-reason.ts | 29 +++++++------ packages/modules/order/src/models/return.ts | 28 +++++++----- .../src/models/shipping-method-adjustment.ts | 13 +++--- .../src/models/shipping-method-tax-line.ts | 13 +++--- .../order/src/models/shipping-method.ts | 28 ++++++------ .../modules/order/src/models/transaction.ts | 22 ++++++---- .../src/services/order-module-service.ts | 16 +++---- .../order/src/utils/apply-order-changes.ts | 10 +++-- 23 files changed, 222 insertions(+), 152 deletions(-) diff --git a/packages/core/utils/src/dml/entity-builder.ts b/packages/core/utils/src/dml/entity-builder.ts index be2fdc8796497..e890e6f9bc705 100644 --- a/packages/core/utils/src/dml/entity-builder.ts +++ b/packages/core/utils/src/dml/entity-builder.ts @@ -2,7 +2,6 @@ import { DMLSchema, IDmlEntityConfig, RelationshipOptions, - RelationshipType, } from "@medusajs/types" import { DmlEntity } from "./entity" import { diff --git a/packages/modules/order/src/models/claim-item-image.ts b/packages/modules/order/src/models/claim-item-image.ts index 152eca0128491..de35a14743057 100644 --- a/packages/modules/order/src/models/claim-item-image.ts +++ b/packages/modules/order/src/models/claim-item-image.ts @@ -4,7 +4,7 @@ import { OrderClaimItem } from "./claim-item" const _OrderClaimItemImage = model .define("OrderClaimItemImage", { id: model.id({ prefix: "climg" }).primaryKey(), - claim_item: model.belongsTo<() => typeof OrderClaimItem>( + claim_item: model.belongsTo typeof OrderClaimItem> */>( () => OrderClaimItem, { mappedBy: "images", diff --git a/packages/modules/order/src/models/claim-item.ts b/packages/modules/order/src/models/claim-item.ts index 052edb2489852..74f22df9eb438 100644 --- a/packages/modules/order/src/models/claim-item.ts +++ b/packages/modules/order/src/models/claim-item.ts @@ -6,7 +6,7 @@ import { OrderLineItem } from "./line-item" const _OrderClaimItem = model .define("OrderClaimItem", { id: model.id({ prefix: "claitem" }).primaryKey(), - images: model.hasMany<() => typeof OrderClaimItemImage>( + images: model.hasMany typeof OrderClaimItemImage> */>( () => OrderClaimItemImage, { mappedBy: "item", @@ -14,12 +14,18 @@ const _OrderClaimItem = model ), reason: model.enum(ClaimReason).nullable(), quantity: model.bigNumber(), - claim: model.belongsTo<() => typeof OrderClaim>(() => OrderClaim, { - mappedBy: "items", - }), - item: model.belongsTo<() => typeof OrderLineItem>(() => OrderLineItem, { - mappedBy: "claim_items", - }), + claim: model.belongsTo typeof OrderClaim> */>( + () => OrderClaim, + { + mappedBy: "items", + } + ), + item: model.belongsTo typeof OrderLineItem> */>( + () => OrderLineItem, + { + mappedBy: "claim_items", + } + ), is_additional_item: model.boolean().default(false), note: model.text().nullable(), metadata: model.json().nullable(), diff --git a/packages/modules/order/src/models/claim.ts b/packages/modules/order/src/models/claim.ts index 19c8be12810e5..ebb54df4673e8 100644 --- a/packages/modules/order/src/models/claim.ts +++ b/packages/modules/order/src/models/claim.ts @@ -9,11 +9,11 @@ import { OrderTransaction } from "./transaction" const _OrderClaim = model .define("OrderClaim", { id: model.id({ prefix: "claim" }).primaryKey(), - order: model.belongsTo<() => typeof Order>(() => Order, { + order: model.belongsTo typeof Order> */>(() => Order, { mappedBy: "claims", }), return_id: model.text().nullable(), - return: model.hasMany<() => typeof Return>(() => Return, { + return: model.hasMany typeof Return> */>(() => Return, { mappedBy: "claim", }), order_version: model.number(), @@ -21,31 +21,33 @@ const _OrderClaim = model type: model.enum(ClaimType), no_notification: model.boolean().nullable(), refund_amount: model.bigNumber().nullable(), - additional_items: model.hasMany<() => typeof OrderClaimItem>( + additional_items: model.hasMany typeof OrderClaimItem> */>( () => OrderClaimItem, { mappedBy: "claim", } ), - claim_items: model.hasMany<() => typeof OrderClaimItem>( + claim_items: model.hasMany typeof OrderClaimItem> */>( () => OrderClaimItem, { mappedBy: "claim", } ), - shipping_methods: model.hasMany<() => typeof OrderShipping>( + shipping_methods: model.hasMany typeof OrderShipping> */>( () => OrderShipping, { mappedBy: "claim", } ), - transactions: model.hasMany<() => typeof OrderTransaction>( + transactions: model.hasMany typeof OrderTransaction> */>( () => OrderTransaction, { mappedBy: "claim", } ), - changes: model.hasMany<() => typeof OrderChange>(() => OrderChange), + changes: model.hasMany typeof OrderChange> */>( + () => OrderChange + ), created_by: model.text().nullable(), canceled_at: model.dateTime().nullable(), metadata: model.json().nullable(), diff --git a/packages/modules/order/src/models/exchange-item.ts b/packages/modules/order/src/models/exchange-item.ts index 43e238aba78c7..e8849a2f994d7 100644 --- a/packages/modules/order/src/models/exchange-item.ts +++ b/packages/modules/order/src/models/exchange-item.ts @@ -6,12 +6,18 @@ const _OrderExchangeItem = model .define("OrderExchangeItem", { id: model.id({ prefix: "oexcitem" }).primaryKey(), quantity: model.bigNumber(), - exchange: model.belongsTo<() => typeof OrderExchange>(() => OrderExchange, { - mappedBy: "additional_items", - }), - item: model.belongsTo<() => typeof OrderLineItem>(() => OrderLineItem, { - mappedBy: "exchange_items", - }), + exchange: model.belongsTo typeof OrderExchange> */>( + () => OrderExchange, + { + mappedBy: "additional_items", + } + ), + item: model.belongsTo typeof OrderLineItem> */>( + () => OrderLineItem, + { + mappedBy: "exchange_items", + } + ), note: model.text().nullable(), metadata: model.json().nullable(), }) diff --git a/packages/modules/order/src/models/exchange.ts b/packages/modules/order/src/models/exchange.ts index d9e3b48096c9e..9de846e79d1a2 100644 --- a/packages/modules/order/src/models/exchange.ts +++ b/packages/modules/order/src/models/exchange.ts @@ -7,11 +7,11 @@ import { Return } from "./return" const _OrderExchange = model .define("OrderExchange", { id: model.id({ prefix: "oexc" }).primaryKey(), - order: model.belongsTo<() => typeof Order>(() => Order, { + order: model.belongsTo typeof Order> */>(() => Order, { mappedBy: "exchanges", }), return_id: model.text().nullable(), - return: model.hasMany<() => typeof Return>(() => Return, { + return: model.hasMany typeof Return> */>(() => Return, { mappedBy: "exchange", }), order_version: model.number(), @@ -19,25 +19,27 @@ const _OrderExchange = model no_notification: model.boolean().nullable(), difference_due: model.bigNumber().nullable(), allow_backorder: model.boolean().default(false), - additional_items: model.hasMany<() => typeof OrderExchangeItem>( + additional_items: model.hasMany typeof OrderExchangeItem> */>( () => OrderExchangeItem, { mappedBy: "exchange", } ), - shipping_methods: model.hasMany<() => typeof OrderShipping>( + shipping_methods: model.hasMany typeof OrderShipping> */>( () => OrderShipping, { mappedBy: "exchange", } ), - transactions: model.hasMany<() => typeof OrderTransaction>( + transactions: model.hasMany typeof OrderTransaction> */>( () => OrderTransaction, { mappedBy: "exchange", } ), - changes: model.hasMany<() => typeof OrderChange>(() => OrderChange), + changes: model.hasMany typeof OrderChange> */>( + () => OrderChange + ), created_by: model.text().nullable(), metadata: model.json().nullable(), canceled_at: model.dateTime().nullable(), diff --git a/packages/modules/order/src/models/line-item-adjustment.ts b/packages/modules/order/src/models/line-item-adjustment.ts index bcc32a8af4f75..121589aead65a 100644 --- a/packages/modules/order/src/models/line-item-adjustment.ts +++ b/packages/modules/order/src/models/line-item-adjustment.ts @@ -9,9 +9,12 @@ const _OrderLineItemAdjustment = model code: model.text().nullable(), amount: model.bigNumber(), provider_id: model.text().nullable(), - item: model.belongsTo<() => typeof OrderLineItem>(() => OrderLineItem, { - mappedBy: "adjustments", - }), + item: model.belongsTo typeof OrderLineItem> */>( + () => OrderLineItem, + { + mappedBy: "adjustments", + } + ), }) .indexes([ { diff --git a/packages/modules/order/src/models/line-item-tax-line.ts b/packages/modules/order/src/models/line-item-tax-line.ts index f8158723634e2..55ab422980c9a 100644 --- a/packages/modules/order/src/models/line-item-tax-line.ts +++ b/packages/modules/order/src/models/line-item-tax-line.ts @@ -9,9 +9,12 @@ const _OrderLineItemTaxLine = model code: model.text(), rate: model.bigNumber(), provider_id: model.text().nullable(), - item: model.belongsTo<() => typeof OrderLineItem>(() => OrderLineItem, { - mappedBy: "tax_lines", - }), + item: model.belongsTo typeof OrderLineItem> */>( + () => OrderLineItem, + { + mappedBy: "tax_lines", + } + ), }) .indexes([ { diff --git a/packages/modules/order/src/models/line-item.ts b/packages/modules/order/src/models/line-item.ts index 1e7c61524ef9a..170ebb28c4d6d 100644 --- a/packages/modules/order/src/models/line-item.ts +++ b/packages/modules/order/src/models/line-item.ts @@ -32,31 +32,35 @@ const _OrderLineItem = model unit_price: model.bigNumber(), is_custom_price: model.boolean().default(false), metadata: model.json().nullable(), - tax_lines: model.hasMany<() => typeof OrderLineItemTaxLine>( + tax_lines: model.hasMany typeof OrderLineItemTaxLine> */>( () => OrderLineItemTaxLine, { mappedBy: "item", } ), - adjustments: model.hasMany<() => typeof OrderLineItemAdjustment>( - () => OrderLineItemAdjustment, + adjustments: + model.hasMany typeof OrderLineItemAdjustment> */>( + () => OrderLineItemAdjustment, + { + mappedBy: "item", + } + ), + items: model.hasMany typeof OrderItem> */>(() => OrderItem, { + mappedBy: "item", + }), + return_items: model.hasMany typeof ReturnItem> */>( + () => ReturnItem, { mappedBy: "item", } ), - items: model.hasMany<() => typeof OrderItem>(() => OrderItem, { - mappedBy: "item", - }), - return_items: model.hasMany<() => typeof ReturnItem>(() => ReturnItem, { - mappedBy: "item", - }), - claim_items: model.hasMany<() => typeof OrderClaimItem>( + claim_items: model.hasMany typeof OrderClaimItem> */>( () => OrderClaimItem, { mappedBy: "item", } ), - exchange_items: model.hasMany<() => typeof OrderExchangeItem>( + exchange_items: model.hasMany typeof OrderExchangeItem> */>( () => OrderExchangeItem, { mappedBy: "item", diff --git a/packages/modules/order/src/models/order-change.ts b/packages/modules/order/src/models/order-change.ts index 91c050aa2540d..3891ae1eee760 100644 --- a/packages/modules/order/src/models/order-change.ts +++ b/packages/modules/order/src/models/order-change.ts @@ -8,27 +8,27 @@ import { Return } from "./return" const _OrderChange = model .define("OrderChange", { id: model.id({ prefix: "ordch" }).primaryKey(), - order: model.belongsTo<() => typeof Order>(() => Order, { + order: model.belongsTo typeof Order> */>(() => Order, { mappedBy: "changes", }), return: model - .belongsTo<() => typeof Return>(() => Return, { + .belongsTo typeof Return> */>(() => Return, { mappedBy: "changes", }) .nullable(), claim: model - .belongsTo<() => typeof OrderClaim>(() => OrderClaim, { + .belongsTo typeof OrderClaim> */>(() => OrderClaim, { mappedBy: "changes", }) .nullable(), exchange: model - .belongsTo<() => typeof OrderExchange>(() => OrderExchange, { + .belongsTo typeof OrderExchange> */>(() => OrderExchange, { mappedBy: "changes", }) .nullable(), version: model.number(), change_type: model.text().nullable(), - actions: model.hasMany<() => typeof OrderChangeAction>( + actions: model.hasMany typeof OrderChangeAction> */>( () => OrderChangeAction, { mappedBy: "order_change", diff --git a/packages/modules/order/src/models/order-item.ts b/packages/modules/order/src/models/order-item.ts index a2e7a773f73b8..89de36618fe1c 100644 --- a/packages/modules/order/src/models/order-item.ts +++ b/packages/modules/order/src/models/order-item.ts @@ -5,13 +5,16 @@ import { Order } from "./order" const _OrderItem = model .define("OrderItem", { id: model.id({ prefix: "orditem" }).primaryKey(), - order: model.belongsTo<() => typeof Order>(() => Order, { + order: model.belongsTo typeof Order> */>(() => Order, { mappedBy: "items", }), version: model.number(), - item: model.belongsTo<() => typeof OrderLineItem>(() => OrderLineItem, { - mappedBy: "items", - }), + item: model.belongsTo typeof OrderLineItem> */>( + () => OrderLineItem, + { + mappedBy: "items", + } + ), unit_price: model.bigNumber().nullable(), compare_at_unit_price: model.bigNumber().nullable(), quantity: model.bigNumber(), diff --git a/packages/modules/order/src/models/order-shipping-method.ts b/packages/modules/order/src/models/order-shipping-method.ts index a4c3a9e18ec05..e099a1ec5a726 100644 --- a/packages/modules/order/src/models/order-shipping-method.ts +++ b/packages/modules/order/src/models/order-shipping-method.ts @@ -9,30 +9,31 @@ const _OrderShipping = model .define("OrderShipping", { id: model.id({ prefix: "ordspmv" }).primaryKey(), version: model.number(), - order: model.belongsTo<() => typeof Order>(() => Order, { + order: model.belongsTo typeof Order> */>(() => Order, { mappedBy: "shipping_methods", }), return: model - .belongsTo<() => typeof Return>(() => Return, { + .belongsTo typeof Return> */>(() => Return, { mappedBy: "shipping_methods", }) .nullable(), exchange: model - .belongsTo<() => typeof OrderExchange>(() => OrderExchange, { + .belongsTo typeof OrderExchange> */>(() => OrderExchange, { mappedBy: "shipping_methods", }) .nullable(), claim: model - .belongsTo<() => typeof OrderClaim>(() => OrderClaim, { + .belongsTo typeof OrderClaim> */>(() => OrderClaim, { mappedBy: "shipping_methods", }) .nullable(), - shipping_method: model.belongsTo<() => typeof OrderShippingMethod>( - () => OrderShippingMethod, - { - mappedBy: "shipping_methods", - } - ), + shipping_method: + model.belongsTo typeof OrderShippingMethod> */>( + () => OrderShippingMethod, + { + mappedBy: "shipping_methods", + } + ), }) .indexes([ { diff --git a/packages/modules/order/src/models/order-summary.ts b/packages/modules/order/src/models/order-summary.ts index 607d97d8e58c4..cc5649197cae3 100644 --- a/packages/modules/order/src/models/order-summary.ts +++ b/packages/modules/order/src/models/order-summary.ts @@ -6,7 +6,7 @@ const _OrderSummary = model id: model.id({ prefix: "ordsum" }).primaryKey(), version: model.number().default(1), totals: model.json(), - order: model.belongsTo<() => typeof Order>(() => Order, { + order: model.belongsTo typeof Order> */>(() => Order, { mappedBy: "summary", }), }) diff --git a/packages/modules/order/src/models/order.ts b/packages/modules/order/src/models/order.ts index e1695e49bd597..8d0dee6050cfc 100644 --- a/packages/modules/order/src/models/order.ts +++ b/packages/modules/order/src/models/order.ts @@ -21,27 +21,30 @@ const _Order = model is_draft_order: model.boolean().default(false), email: model.text().searchable().nullable(), currency_code: model.text(), - shipping_address: model.belongsTo<() => typeof OrderAddress>( + shipping_address: model.belongsTo typeof OrderAddress> */>( () => OrderAddress ), - billing_address: model.belongsTo<() => typeof OrderAddress>( + billing_address: model.belongsTo typeof OrderAddress> */>( () => OrderAddress ), no_notification: model.boolean().nullable(), metadata: model.json().nullable(), - summary: model.hasMany<() => typeof OrderSummary>(() => OrderSummary, { - mappedBy: "order", - }), - items: model.hasMany<() => typeof OrderItem>(() => OrderItem, { + summary: model.hasMany typeof OrderSummary> */>( + () => OrderSummary, + { + mappedBy: "order", + } + ), + items: model.hasMany typeof OrderItem> */>(() => OrderItem, { mappedBy: "order", }), - shipping_methods: model.hasMany<() => typeof OrderShipping>( + shipping_methods: model.hasMany typeof OrderShipping> */>( () => OrderShipping, { mappedBy: "order", } ), - transactions: model.hasMany<() => typeof OrderTransaction>( + transactions: model.hasMany typeof OrderTransaction> */>( () => OrderTransaction, { mappedBy: "order", @@ -49,16 +52,24 @@ const _Order = model ), canceled_at: model.dateTime().nullable(), - exchanges: model.hasMany<() => typeof OrderExchange>(() => OrderExchange, { - mappedBy: "order", - }), - claims: model.hasMany<() => typeof OrderClaim>(() => OrderClaim, { - mappedBy: "order", - }), - returns: model.hasMany<() => typeof Return>(() => Return, { + exchanges: model.hasMany typeof OrderExchange> */>( + () => OrderExchange, + { + mappedBy: "order", + } + ), + claims: model.hasMany typeof OrderClaim> */>( + () => OrderClaim, + { + mappedBy: "order", + } + ), + returns: model.hasMany typeof Return> */>(() => Return, { mappedBy: "order", }), - changes: model.hasMany<() => typeof OrderChange>(() => OrderChange), + changes: model.hasMany typeof OrderChange> */>( + () => OrderChange + ), }) .indexes([ { diff --git a/packages/modules/order/src/models/return-item.ts b/packages/modules/order/src/models/return-item.ts index d7f0024b4df95..4fcbd182b762f 100644 --- a/packages/modules/order/src/models/return-item.ts +++ b/packages/modules/order/src/models/return-item.ts @@ -7,19 +7,22 @@ const _ReturnItem = model .define("ReturnItem", { id: model.id({ prefix: "retitem" }).primaryKey(), reason: model - .belongsTo<() => typeof ReturnReason>(() => ReturnReason, { + .belongsTo typeof ReturnReason> */>(() => ReturnReason, { mappedBy: "return_items", }) .nullable(), quantity: model.bigNumber(), received_quantity: model.bigNumber().default(0), damaged_quantity: model.bigNumber().default(0), - return: model.belongsTo<() => typeof Return>(() => Return, { + return: model.belongsTo typeof Return> */>(() => Return, { mappedBy: "items", }), - item: model.belongsTo<() => typeof OrderLineItem>(() => OrderLineItem, { - mappedBy: "return_items", - }), + item: model.belongsTo typeof OrderLineItem> */>( + () => OrderLineItem, + { + mappedBy: "return_items", + } + ), note: model.text().nullable(), metadata: model.json().nullable(), }) diff --git a/packages/modules/order/src/models/return-reason.ts b/packages/modules/order/src/models/return-reason.ts index effdbb2b217aa..44595648ae277 100644 --- a/packages/modules/order/src/models/return-reason.ts +++ b/packages/modules/order/src/models/return-reason.ts @@ -8,21 +8,26 @@ const _ReturnReason = model label: model.text().searchable(), description: model.text().nullable(), parent_return_reason_id: model.text().nullable(), - parent_return_reason: model.belongsTo<() => typeof _ReturnReason>( - () => _ReturnReason, + parent_return_reason: + model.belongsTo typeof _ReturnReason> */>( + () => _ReturnReason, + { + mappedBy: "return_reason_children", + } + ), + return_reason_children: + model.hasMany typeof _ReturnReason> */>( + () => _ReturnReason, + { + mappedBy: "parent_return_reason", + } + ), + return_items: model.hasMany typeof ReturnItem> */>( + () => ReturnItem, { - mappedBy: "return_reason_children", + mappedBy: "reason", } ), - return_reason_children: model.hasMany<() => typeof _ReturnReason>( - () => _ReturnReason, - { - mappedBy: "parent_return_reason", - } - ), - return_items: model.hasMany<() => typeof ReturnItem>(() => ReturnItem, { - mappedBy: "reason", - }), metadata: model.json().nullable(), }) .indexes([ diff --git a/packages/modules/order/src/models/return.ts b/packages/modules/order/src/models/return.ts index 5a31a56b894ef..46fa8cc7fe695 100644 --- a/packages/modules/order/src/models/return.ts +++ b/packages/modules/order/src/models/return.ts @@ -8,15 +8,21 @@ import { OrderShipping } from "./order-shipping-method" const _Return = model .define("Return", { id: model.id({ prefix: "return" }).primaryKey(), - order: model.belongsTo<() => typeof Order>(() => Order, { + order: model.belongsTo typeof Order> */>(() => Order, { mappedBy: "returns", }), - exchange: model.belongsTo<() => typeof OrderExchange>(() => OrderExchange, { - mappedBy: "return", - }), - claim: model.belongsTo<() => typeof OrderClaim>(() => OrderClaim, { - mappedBy: "return", - }), + exchange: model.belongsTo typeof OrderExchange> */>( + () => OrderExchange, + { + mappedBy: "return", + } + ), + claim: model.belongsTo typeof OrderClaim> */>( + () => OrderClaim, + { + mappedBy: "return", + } + ), order_version: model.number(), display_id: model.autoincrement(), status: model.enum(ReturnStatus).default(ReturnStatus.OPEN), @@ -26,19 +32,21 @@ const _Return = model items: model.hasMany(() => ReturnItem, { mappedBy: "return", }), - shipping_methods: model.hasMany<() => typeof OrderShipping>( + shipping_methods: model.hasMany typeof OrderShipping> */>( () => OrderShipping, { mappedBy: "return", } ), - transactions: model.hasMany<() => typeof OrderTransaction>( + transactions: model.hasMany typeof OrderTransaction> */>( () => OrderTransaction, { mappedBy: "return", } ), - changes: model.hasMany<() => typeof OrderChange>(() => OrderChange), + changes: model.hasMany typeof OrderChange> */>( + () => OrderChange + ), created_by: model.text().nullable(), metadata: model.json().nullable(), requested_at: model.dateTime().nullable(), diff --git a/packages/modules/order/src/models/shipping-method-adjustment.ts b/packages/modules/order/src/models/shipping-method-adjustment.ts index 01fa946b4430e..fdf4fa944d929 100644 --- a/packages/modules/order/src/models/shipping-method-adjustment.ts +++ b/packages/modules/order/src/models/shipping-method-adjustment.ts @@ -9,12 +9,13 @@ const _OrderShippingMethodAdjustment = model code: model.text().nullable(), amount: model.bigNumber(), provider_id: model.text().nullable(), - shipping_method: model.belongsTo<() => typeof OrderShippingMethod>( - () => OrderShippingMethod, - { - mappedBy: "adjustments", - } - ), + shipping_method: + model.belongsTo typeof OrderShippingMethod> */>( + () => OrderShippingMethod, + { + mappedBy: "adjustments", + } + ), }) .indexes([ { diff --git a/packages/modules/order/src/models/shipping-method-tax-line.ts b/packages/modules/order/src/models/shipping-method-tax-line.ts index e49a9668504ff..bd04dcc67e909 100644 --- a/packages/modules/order/src/models/shipping-method-tax-line.ts +++ b/packages/modules/order/src/models/shipping-method-tax-line.ts @@ -9,12 +9,13 @@ const _OrderShippingMethodTaxLine = model code: model.text(), rate: model.bigNumber(), provider_id: model.text().nullable(), - shipping_method: model.belongsTo<() => typeof OrderShippingMethod>( - () => OrderShippingMethod, - { - mappedBy: "tax_lines", - } - ), + shipping_method: + model.belongsTo typeof OrderShippingMethod> */>( + () => OrderShippingMethod, + { + mappedBy: "tax_lines", + } + ), }) .indexes([ { diff --git a/packages/modules/order/src/models/shipping-method.ts b/packages/modules/order/src/models/shipping-method.ts index 427789a1c24ca..86f1cc9443eff 100644 --- a/packages/modules/order/src/models/shipping-method.ts +++ b/packages/modules/order/src/models/shipping-method.ts @@ -14,19 +14,21 @@ const _OrderShippingMethod = model shipping_option_id: model.text().nullable(), data: model.json().nullable(), metadata: model.json().nullable(), - tax_lines: model.hasMany<() => typeof OrderShippingMethodTaxLine>( - () => OrderShippingMethodTaxLine, - { - mappedBy: "shipping_method", - } - ), - adjustments: model.hasMany<() => typeof OrderShippingMethodAdjustment>( - () => OrderShippingMethodAdjustment, - { - mappedBy: "shipping_method", - } - ), - shipping_methods: model.hasMany<() => typeof OrderShipping>( + tax_lines: + model.hasMany typeof OrderShippingMethodTaxLine> */>( + () => OrderShippingMethodTaxLine, + { + mappedBy: "shipping_method", + } + ), + adjustments: + model.hasMany typeof OrderShippingMethodAdjustment> */>( + () => OrderShippingMethodAdjustment, + { + mappedBy: "shipping_method", + } + ), + shipping_methods: model.hasMany typeof OrderShipping> */>( () => OrderShipping, { mappedBy: "shipping_method", diff --git a/packages/modules/order/src/models/transaction.ts b/packages/modules/order/src/models/transaction.ts index 3054a74604d10..1f526bf8a5006 100644 --- a/packages/modules/order/src/models/transaction.ts +++ b/packages/modules/order/src/models/transaction.ts @@ -7,18 +7,24 @@ import { Return } from "./return" const _OrderTransaction = model .define("OrderTransaction", { id: model.id({ prefix: "ordtrx" }).primaryKey(), - order: model.belongsTo<() => typeof Order>(() => Order, { + order: model.belongsTo typeof Order> */>(() => Order, { mappedBy: "transactions", }), - return: model.belongsTo<() => typeof Return>(() => Return, { - mappedBy: "transactions", - }), - exchange: model.belongsTo<() => typeof OrderExchange>(() => OrderExchange, { - mappedBy: "transactions", - }), - claim: model.belongsTo<() => typeof OrderClaim>(() => OrderClaim, { + return: model.belongsTo typeof Return> */>(() => Return, { mappedBy: "transactions", }), + exchange: model.belongsTo typeof OrderExchange> */>( + () => OrderExchange, + { + mappedBy: "transactions", + } + ), + claim: model.belongsTo typeof OrderClaim> */>( + () => OrderClaim, + { + mappedBy: "transactions", + } + ), version: model.number().default(1), amount: model.bigNumber(), currency_code: model.text(), diff --git a/packages/modules/order/src/services/order-module-service.ts b/packages/modules/order/src/services/order-module-service.ts index 1c16e4bea868a..0a13831153f4a 100644 --- a/packages/modules/order/src/services/order-module-service.ts +++ b/packages/modules/order/src/services/order-module-service.ts @@ -657,7 +657,7 @@ export default class OrderModuleService ) { const lineItemsToCreate: CreateOrderLineItemDTO[] = [] - const createdOrders: (typeof Order)[] = [] + const createdOrders: InferEntityType[] = [] for (const { items, shipping_methods, ...order } of data) { const ord = order as any @@ -1230,10 +1230,10 @@ export default class OrderModuleService version: number }[], @MedusaContext() sharedContext: Context = {} - ): Promise> { + ): Promise[]> { const sm = await this.orderShippingService_.create(data, sharedContext) - return sm.map((s) => s.shipping_method) + return sm.map((s) => s.shipping_method) as any } @InjectManager() @@ -2706,6 +2706,7 @@ export default class OrderModuleService data: OrderTypes.CreateOrderChangeActionDTO[], sharedContext?: Context ): Promise + @InjectTransactionManager() async addOrderAction( data: @@ -2713,8 +2714,7 @@ export default class OrderModuleService | OrderTypes.CreateOrderChangeActionDTO[], @MedusaContext() sharedContext?: Context ): Promise< - | InferEntityType - | InferEntityType[] + OrderTypes.OrderChangeActionDTO | OrderTypes.OrderChangeActionDTO[] > { let dataArr = Array.isArray(data) ? data : [data] @@ -2748,7 +2748,7 @@ export default class OrderModuleService const actions = (await this.orderChangeActionService_.create( dataArr, sharedContext - )) as InferEntityType[] + )) as unknown as OrderTypes.OrderChangeActionDTO[] return Array.isArray(data) ? actions : actions[0] } @@ -2885,10 +2885,10 @@ export default class OrderModuleService } } - const created = await this.orderTransactionService_.create( + const created = (await this.orderTransactionService_.create( data, sharedContext - ) + )) as (InferEntityType & { order_id: string })[] await this.updateOrderPaidRefundableAmount_(created, false, sharedContext) diff --git a/packages/modules/order/src/utils/apply-order-changes.ts b/packages/modules/order/src/utils/apply-order-changes.ts index 0a6e1fe9cfd02..e7798a98b80f1 100644 --- a/packages/modules/order/src/utils/apply-order-changes.ts +++ b/packages/modules/order/src/utils/apply-order-changes.ts @@ -1,4 +1,7 @@ -import { OrderChangeActionDTO } from "@medusajs/framework/types" +import { + InferEntityType, + OrderChangeActionDTO, +} from "@medusajs/framework/types" import { ChangeActionType, MathBN, @@ -22,8 +25,9 @@ export function applyChangesToOrder( addActionReferenceToObject?: boolean } ) { - const itemsToUpsert: (typeof OrderItem)[] = [] - const shippingMethodsToUpsert: (typeof OrderShippingMethod)[] = [] + const itemsToUpsert: InferEntityType[] = [] + const shippingMethodsToUpsert: InferEntityType[] = + [] const summariesToUpsert: any[] = [] const orderToUpdate: any[] = [] From c2c07a33bb410b348350ae9fc904a78d2d5ce8eb Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Tue, 26 Nov 2024 15:17:21 -0300 Subject: [PATCH 090/175] rel --- .../integration-tests/__tests__/index.spec.ts | 28 ++++++++++--------- packages/modules/order/src/models/address.ts | 4 +++ .../modules/order/src/models/claim-item.ts | 4 +-- packages/modules/order/src/models/claim.ts | 5 +++- packages/modules/order/src/models/exchange.ts | 5 +++- .../order/src/models/order-change-action.ts | 8 +++++- .../modules/order/src/models/return-reason.ts | 1 - 7 files changed, 36 insertions(+), 19 deletions(-) diff --git a/packages/modules/order/integration-tests/__tests__/index.spec.ts b/packages/modules/order/integration-tests/__tests__/index.spec.ts index a01bd0992e243..5443aed1a8777 100644 --- a/packages/modules/order/integration-tests/__tests__/index.spec.ts +++ b/packages/modules/order/integration-tests/__tests__/index.spec.ts @@ -12,19 +12,21 @@ moduleIntegrationTestRunner({ service: OrderModuleService, }).linkable - expect(Object.keys(linkable)).toEqual([ - "order", - "orderAddress", - "orderChange", - "orderClaim", - "orderExchange", - "orderItem", - "orderLineItem", - "orderShippingMethod", - "orderTransaction", - "return", - "returnReason", - ]) + expect(Object.keys(linkable)).toEqual( + expect.arrayContaining([ + "order", + "orderAddress", + "orderChange", + "orderClaim", + "orderExchange", + "orderItem", + "orderLineItem", + "orderShippingMethod", + "orderTransaction", + "return", + "returnReason", + ]) + ) Object.keys(linkable).forEach((key) => { delete linkable[key].toJSON diff --git a/packages/modules/order/src/models/address.ts b/packages/modules/order/src/models/address.ts index 368819b1270c8..670f4415b73c7 100644 --- a/packages/modules/order/src/models/address.ts +++ b/packages/modules/order/src/models/address.ts @@ -1,4 +1,5 @@ import { model } from "@medusajs/framework/utils" +import { Order } from "./order" const CustomerIdIndex = "IDX_order_address_customer_id" @@ -17,6 +18,9 @@ const _OrderAddress = model postal_code: model.text().searchable().nullable(), phone: model.text().searchable().nullable(), metadata: model.json().nullable(), + order: model.hasMany typeof Order> */>(() => Order, { + mappedBy: "shipping_address", + }), }) .indexes([ { diff --git a/packages/modules/order/src/models/claim-item.ts b/packages/modules/order/src/models/claim-item.ts index 74f22df9eb438..aa29b8937bb76 100644 --- a/packages/modules/order/src/models/claim-item.ts +++ b/packages/modules/order/src/models/claim-item.ts @@ -9,7 +9,7 @@ const _OrderClaimItem = model images: model.hasMany typeof OrderClaimItemImage> */>( () => OrderClaimItemImage, { - mappedBy: "item", + mappedBy: "claim_item", } ), reason: model.enum(ClaimReason).nullable(), @@ -17,7 +17,7 @@ const _OrderClaimItem = model claim: model.belongsTo typeof OrderClaim> */>( () => OrderClaim, { - mappedBy: "items", + mappedBy: "additional_items", } ), item: model.belongsTo typeof OrderLineItem> */>( diff --git a/packages/modules/order/src/models/claim.ts b/packages/modules/order/src/models/claim.ts index ebb54df4673e8..5dda77b9a306d 100644 --- a/packages/modules/order/src/models/claim.ts +++ b/packages/modules/order/src/models/claim.ts @@ -46,7 +46,10 @@ const _OrderClaim = model } ), changes: model.hasMany typeof OrderChange> */>( - () => OrderChange + () => OrderChange, + { + mappedBy: "claim", + } ), created_by: model.text().nullable(), canceled_at: model.dateTime().nullable(), diff --git a/packages/modules/order/src/models/exchange.ts b/packages/modules/order/src/models/exchange.ts index 9de846e79d1a2..cfc0cd642756d 100644 --- a/packages/modules/order/src/models/exchange.ts +++ b/packages/modules/order/src/models/exchange.ts @@ -38,7 +38,10 @@ const _OrderExchange = model } ), changes: model.hasMany typeof OrderChange> */>( - () => OrderChange + () => OrderChange, + { + mappedBy: "exchange", + } ), created_by: model.text().nullable(), metadata: model.json().nullable(), diff --git a/packages/modules/order/src/models/order-change-action.ts b/packages/modules/order/src/models/order-change-action.ts index 0ae713c78d9bb..361473bb17200 100644 --- a/packages/modules/order/src/models/order-change-action.ts +++ b/packages/modules/order/src/models/order-change-action.ts @@ -1,4 +1,5 @@ import { model } from "@medusajs/framework/utils" +import { OrderChange } from "./order-change" const _OrderChangeAction = model .define("OrderChangeAction", { @@ -9,7 +10,6 @@ const _OrderChangeAction = model claim_id: model.text().nullable(), exchange_id: model.text().nullable(), version: model.number().nullable(), - order_change_id: model.text().nullable(), reference: model.text().nullable(), reference_id: model.text().nullable(), action: model.text(), @@ -17,6 +17,12 @@ const _OrderChangeAction = model amount: model.bigNumber().nullable(), internal_note: model.text().nullable(), applied: model.boolean().default(false), + order_change: model.belongsTo typeof OrderChange> */>( + () => OrderChange, + { + mappedBy: "actions", + } + ), }) .indexes([ { diff --git a/packages/modules/order/src/models/return-reason.ts b/packages/modules/order/src/models/return-reason.ts index 44595648ae277..548fe9f1eea16 100644 --- a/packages/modules/order/src/models/return-reason.ts +++ b/packages/modules/order/src/models/return-reason.ts @@ -7,7 +7,6 @@ const _ReturnReason = model value: model.text().searchable(), label: model.text().searchable(), description: model.text().nullable(), - parent_return_reason_id: model.text().nullable(), parent_return_reason: model.belongsTo typeof _ReturnReason> */>( () => _ReturnReason, From 5fa4e1ddfd655f64b42686b8fb8019f54e8e2a85 Mon Sep 17 00:00:00 2001 From: Harminder Virk Date: Wed, 27 Nov 2024 11:35:21 +0530 Subject: [PATCH 091/175] fix: recursive type issue --- packages/modules/order/src/models/address.ts | 2 +- .../order/src/models/claim-item-image.ts | 2 +- .../modules/order/src/models/claim-item.ts | 32 ++--- packages/modules/order/src/models/claim.ts | 41 +++--- .../modules/order/src/models/exchange-item.ts | 18 +-- packages/modules/order/src/models/exchange.ts | 40 +++--- .../order/src/models/line-item-adjustment.ts | 9 +- .../order/src/models/line-item-tax-line.ts | 9 +- .../modules/order/src/models/line-item.ts | 32 ++--- .../order/src/models/order-change-action.ts | 9 +- .../modules/order/src/models/order-change.ts | 46 +++---- .../modules/order/src/models/order-item.ts | 18 ++- .../order/src/models/order-shipping-method.ts | 25 ++-- .../modules/order/src/models/order-summary.ts | 2 +- packages/modules/order/src/models/order.ts | 123 +++++++++++------- .../modules/order/src/models/return-item.ts | 25 ++-- .../modules/order/src/models/return-reason.ts | 31 ++--- packages/modules/order/src/models/return.ts | 50 ++++--- .../src/models/shipping-method-adjustment.ts | 13 +- .../src/models/shipping-method-tax-line.ts | 13 +- .../order/src/models/shipping-method.ts | 30 ++--- .../modules/order/src/models/transaction.ts | 68 ++++++---- 22 files changed, 319 insertions(+), 319 deletions(-) diff --git a/packages/modules/order/src/models/address.ts b/packages/modules/order/src/models/address.ts index 670f4415b73c7..62a2519ac24e2 100644 --- a/packages/modules/order/src/models/address.ts +++ b/packages/modules/order/src/models/address.ts @@ -18,7 +18,7 @@ const _OrderAddress = model postal_code: model.text().searchable().nullable(), phone: model.text().searchable().nullable(), metadata: model.json().nullable(), - order: model.hasMany typeof Order> */>(() => Order, { + order: model.hasMany<() => typeof Order>(() => Order, { mappedBy: "shipping_address", }), }) diff --git a/packages/modules/order/src/models/claim-item-image.ts b/packages/modules/order/src/models/claim-item-image.ts index de35a14743057..152eca0128491 100644 --- a/packages/modules/order/src/models/claim-item-image.ts +++ b/packages/modules/order/src/models/claim-item-image.ts @@ -4,7 +4,7 @@ import { OrderClaimItem } from "./claim-item" const _OrderClaimItemImage = model .define("OrderClaimItemImage", { id: model.id({ prefix: "climg" }).primaryKey(), - claim_item: model.belongsTo typeof OrderClaimItem> */>( + claim_item: model.belongsTo<() => typeof OrderClaimItem>( () => OrderClaimItem, { mappedBy: "images", diff --git a/packages/modules/order/src/models/claim-item.ts b/packages/modules/order/src/models/claim-item.ts index aa29b8937bb76..a12c355f62262 100644 --- a/packages/modules/order/src/models/claim-item.ts +++ b/packages/modules/order/src/models/claim-item.ts @@ -1,34 +1,28 @@ import { ClaimReason, model } from "@medusajs/framework/utils" import { OrderClaim } from "./claim" -import { OrderClaimItemImage } from "./claim-item-image" import { OrderLineItem } from "./line-item" +import { OrderClaimItemImage } from "./claim-item-image" const _OrderClaimItem = model .define("OrderClaimItem", { id: model.id({ prefix: "claitem" }).primaryKey(), - images: model.hasMany typeof OrderClaimItemImage> */>( - () => OrderClaimItemImage, - { - mappedBy: "claim_item", - } - ), reason: model.enum(ClaimReason).nullable(), quantity: model.bigNumber(), - claim: model.belongsTo typeof OrderClaim> */>( - () => OrderClaim, - { - mappedBy: "additional_items", - } - ), - item: model.belongsTo typeof OrderLineItem> */>( - () => OrderLineItem, - { - mappedBy: "claim_items", - } - ), is_additional_item: model.boolean().default(false), note: model.text().nullable(), metadata: model.json().nullable(), + claim: model.belongsTo<() => typeof OrderClaim>(() => OrderClaim, { + mappedBy: "additional_items", + }), + item: model.belongsTo<() => typeof OrderLineItem>(() => OrderLineItem, { + mappedBy: "claim_items", + }), + images: model.hasMany<() => typeof OrderClaimItemImage>( + () => OrderClaimItemImage, + { + mappedBy: "claim_item", + } + ), }) .indexes([ { diff --git a/packages/modules/order/src/models/claim.ts b/packages/modules/order/src/models/claim.ts index 5dda77b9a306d..63f12c1b28928 100644 --- a/packages/modules/order/src/models/claim.ts +++ b/packages/modules/order/src/models/claim.ts @@ -1,59 +1,56 @@ import { ClaimType, model } from "@medusajs/framework/utils" -import { OrderClaimItem } from "./claim-item" import { Order } from "./order" -import { OrderChange } from "./order-change" -import { OrderShipping } from "./order-shipping-method" import { Return } from "./return" +import { OrderChange } from "./order-change" +import { OrderClaimItem } from "./claim-item" import { OrderTransaction } from "./transaction" +import { OrderShipping } from "./order-shipping-method" const _OrderClaim = model .define("OrderClaim", { id: model.id({ prefix: "claim" }).primaryKey(), - order: model.belongsTo typeof Order> */>(() => Order, { - mappedBy: "claims", - }), return_id: model.text().nullable(), - return: model.hasMany typeof Return> */>(() => Return, { - mappedBy: "claim", - }), order_version: model.number(), display_id: model.autoincrement(), type: model.enum(ClaimType), no_notification: model.boolean().nullable(), refund_amount: model.bigNumber().nullable(), - additional_items: model.hasMany typeof OrderClaimItem> */>( + created_by: model.text().nullable(), + canceled_at: model.dateTime().nullable(), + metadata: model.json().nullable(), + order: model.belongsTo<() => typeof Order>(() => Order, { + mappedBy: "claims", + }), + return: model.hasMany<() => typeof Return>(() => Return, { + mappedBy: "claim", + }), + additional_items: model.hasMany<() => typeof OrderClaimItem>( () => OrderClaimItem, { mappedBy: "claim", } ), - claim_items: model.hasMany typeof OrderClaimItem> */>( + claim_items: model.hasMany<() => typeof OrderClaimItem>( () => OrderClaimItem, { mappedBy: "claim", } ), - shipping_methods: model.hasMany typeof OrderShipping> */>( + shipping_methods: model.hasMany<() => typeof OrderShipping>( () => OrderShipping, { mappedBy: "claim", } ), - transactions: model.hasMany typeof OrderTransaction> */>( + transactions: model.hasMany<() => typeof OrderTransaction>( () => OrderTransaction, { mappedBy: "claim", } ), - changes: model.hasMany typeof OrderChange> */>( - () => OrderChange, - { - mappedBy: "claim", - } - ), - created_by: model.text().nullable(), - canceled_at: model.dateTime().nullable(), - metadata: model.json().nullable(), + changes: model.hasMany<() => typeof OrderChange>(() => OrderChange, { + mappedBy: "claim", + }), }) .indexes([ { diff --git a/packages/modules/order/src/models/exchange-item.ts b/packages/modules/order/src/models/exchange-item.ts index e8849a2f994d7..998aabad7a071 100644 --- a/packages/modules/order/src/models/exchange-item.ts +++ b/packages/modules/order/src/models/exchange-item.ts @@ -6,20 +6,14 @@ const _OrderExchangeItem = model .define("OrderExchangeItem", { id: model.id({ prefix: "oexcitem" }).primaryKey(), quantity: model.bigNumber(), - exchange: model.belongsTo typeof OrderExchange> */>( - () => OrderExchange, - { - mappedBy: "additional_items", - } - ), - item: model.belongsTo typeof OrderLineItem> */>( - () => OrderLineItem, - { - mappedBy: "exchange_items", - } - ), note: model.text().nullable(), metadata: model.json().nullable(), + exchange: model.belongsTo<() => typeof OrderExchange>(() => OrderExchange, { + mappedBy: "additional_items", + }), + item: model.belongsTo<() => typeof OrderLineItem>(() => OrderLineItem, { + mappedBy: "exchange_items", + }), }) .indexes([ { diff --git a/packages/modules/order/src/models/exchange.ts b/packages/modules/order/src/models/exchange.ts index cfc0cd642756d..a31f52f15ff8e 100644 --- a/packages/modules/order/src/models/exchange.ts +++ b/packages/modules/order/src/models/exchange.ts @@ -1,51 +1,51 @@ import { model } from "@medusajs/framework/utils" -import { OrderChange, OrderExchangeItem, OrderTransaction } from "@models" + import { Order } from "./order" -import { OrderShipping } from "./order-shipping-method" import { Return } from "./return" +import { OrderChange } from "./order-change" +import { OrderTransaction } from "./transaction" +import { OrderExchangeItem } from "./exchange-item" +import { OrderShipping } from "./order-shipping-method" const _OrderExchange = model .define("OrderExchange", { id: model.id({ prefix: "oexc" }).primaryKey(), - order: model.belongsTo typeof Order> */>(() => Order, { - mappedBy: "exchanges", - }), return_id: model.text().nullable(), - return: model.hasMany typeof Return> */>(() => Return, { - mappedBy: "exchange", - }), order_version: model.number(), display_id: model.autoincrement(), no_notification: model.boolean().nullable(), difference_due: model.bigNumber().nullable(), allow_backorder: model.boolean().default(false), - additional_items: model.hasMany typeof OrderExchangeItem> */>( + created_by: model.text().nullable(), + metadata: model.json().nullable(), + canceled_at: model.dateTime().nullable(), + order: model.belongsTo<() => typeof Order>(() => Order, { + mappedBy: "exchanges", + }), + return: model.hasMany<() => typeof Return>(() => Return, { + mappedBy: "exchange", + }), + additional_items: model.hasMany<() => typeof OrderExchangeItem>( () => OrderExchangeItem, { mappedBy: "exchange", } ), - shipping_methods: model.hasMany typeof OrderShipping> */>( + shipping_methods: model.hasMany<() => typeof OrderShipping>( () => OrderShipping, { mappedBy: "exchange", } ), - transactions: model.hasMany typeof OrderTransaction> */>( + transactions: model.hasMany<() => typeof OrderTransaction>( () => OrderTransaction, { mappedBy: "exchange", } ), - changes: model.hasMany typeof OrderChange> */>( - () => OrderChange, - { - mappedBy: "exchange", - } - ), - created_by: model.text().nullable(), - metadata: model.json().nullable(), - canceled_at: model.dateTime().nullable(), + changes: model.hasMany<() => typeof OrderChange>(() => OrderChange, { + mappedBy: "exchange", + }), }) .indexes([ { diff --git a/packages/modules/order/src/models/line-item-adjustment.ts b/packages/modules/order/src/models/line-item-adjustment.ts index 121589aead65a..bcc32a8af4f75 100644 --- a/packages/modules/order/src/models/line-item-adjustment.ts +++ b/packages/modules/order/src/models/line-item-adjustment.ts @@ -9,12 +9,9 @@ const _OrderLineItemAdjustment = model code: model.text().nullable(), amount: model.bigNumber(), provider_id: model.text().nullable(), - item: model.belongsTo typeof OrderLineItem> */>( - () => OrderLineItem, - { - mappedBy: "adjustments", - } - ), + item: model.belongsTo<() => typeof OrderLineItem>(() => OrderLineItem, { + mappedBy: "adjustments", + }), }) .indexes([ { diff --git a/packages/modules/order/src/models/line-item-tax-line.ts b/packages/modules/order/src/models/line-item-tax-line.ts index 55ab422980c9a..f8158723634e2 100644 --- a/packages/modules/order/src/models/line-item-tax-line.ts +++ b/packages/modules/order/src/models/line-item-tax-line.ts @@ -9,12 +9,9 @@ const _OrderLineItemTaxLine = model code: model.text(), rate: model.bigNumber(), provider_id: model.text().nullable(), - item: model.belongsTo typeof OrderLineItem> */>( - () => OrderLineItem, - { - mappedBy: "tax_lines", - } - ), + item: model.belongsTo<() => typeof OrderLineItem>(() => OrderLineItem, { + mappedBy: "tax_lines", + }), }) .indexes([ { diff --git a/packages/modules/order/src/models/line-item.ts b/packages/modules/order/src/models/line-item.ts index 170ebb28c4d6d..df03fc07294e3 100644 --- a/packages/modules/order/src/models/line-item.ts +++ b/packages/modules/order/src/models/line-item.ts @@ -1,10 +1,10 @@ import { model } from "@medusajs/framework/utils" +import { OrderItem } from "./order-item" +import { ReturnItem } from "./return-item" import { OrderClaimItem } from "./claim-item" import { OrderExchangeItem } from "./exchange-item" -import { OrderLineItemAdjustment } from "./line-item-adjustment" import { OrderLineItemTaxLine } from "./line-item-tax-line" -import { OrderItem } from "./order-item" -import { ReturnItem } from "./return-item" +import { OrderLineItemAdjustment } from "./line-item-adjustment" const _OrderLineItem = model .define("OrderLineItem", { @@ -32,35 +32,31 @@ const _OrderLineItem = model unit_price: model.bigNumber(), is_custom_price: model.boolean().default(false), metadata: model.json().nullable(), - tax_lines: model.hasMany typeof OrderLineItemTaxLine> */>( + tax_lines: model.hasMany<() => typeof OrderLineItemTaxLine>( () => OrderLineItemTaxLine, { mappedBy: "item", } ), - adjustments: - model.hasMany typeof OrderLineItemAdjustment> */>( - () => OrderLineItemAdjustment, - { - mappedBy: "item", - } - ), - items: model.hasMany typeof OrderItem> */>(() => OrderItem, { - mappedBy: "item", - }), - return_items: model.hasMany typeof ReturnItem> */>( - () => ReturnItem, + adjustments: model.hasMany<() => typeof OrderLineItemAdjustment>( + () => OrderLineItemAdjustment, { mappedBy: "item", } ), - claim_items: model.hasMany typeof OrderClaimItem> */>( + items: model.hasMany<() => typeof OrderItem>(() => OrderItem, { + mappedBy: "item", + }), + return_items: model.hasMany<() => typeof ReturnItem>(() => ReturnItem, { + mappedBy: "item", + }), + claim_items: model.hasMany<() => typeof OrderClaimItem>( () => OrderClaimItem, { mappedBy: "item", } ), - exchange_items: model.hasMany typeof OrderExchangeItem> */>( + exchange_items: model.hasMany<() => typeof OrderExchangeItem>( () => OrderExchangeItem, { mappedBy: "item", diff --git a/packages/modules/order/src/models/order-change-action.ts b/packages/modules/order/src/models/order-change-action.ts index 361473bb17200..b9403a996ab6e 100644 --- a/packages/modules/order/src/models/order-change-action.ts +++ b/packages/modules/order/src/models/order-change-action.ts @@ -17,12 +17,9 @@ const _OrderChangeAction = model amount: model.bigNumber().nullable(), internal_note: model.text().nullable(), applied: model.boolean().default(false), - order_change: model.belongsTo typeof OrderChange> */>( - () => OrderChange, - { - mappedBy: "actions", - } - ), + order_change: model.belongsTo<() => typeof OrderChange>(() => OrderChange, { + mappedBy: "actions", + }), }) .indexes([ { diff --git a/packages/modules/order/src/models/order-change.ts b/packages/modules/order/src/models/order-change.ts index 3891ae1eee760..d34d8401e70a1 100644 --- a/packages/modules/order/src/models/order-change.ts +++ b/packages/modules/order/src/models/order-change.ts @@ -1,53 +1,53 @@ import { model, OrderChangeStatus } from "@medusajs/framework/utils" +import { Order } from "./order" +import { Return } from "./return" import { OrderClaim } from "./claim" import { OrderExchange } from "./exchange" -import { Order } from "./order" import { OrderChangeAction } from "./order-change-action" -import { Return } from "./return" const _OrderChange = model .define("OrderChange", { id: model.id({ prefix: "ordch" }).primaryKey(), - order: model.belongsTo typeof Order> */>(() => Order, { + version: model.number(), + change_type: model.text().nullable(), + description: model.text().nullable(), + status: model.enum(OrderChangeStatus).default(OrderChangeStatus.PENDING), + internal_note: model.text().nullable(), + created_by: model.text(), + requested_by: model.text().nullable(), + requested_at: model.dateTime().nullable(), + confirmed_by: model.text().nullable(), + confirmed_at: model.dateTime().nullable(), + declined_by: model.text().nullable(), + declined_reason: model.text().nullable(), + metadata: model.json().nullable(), + declined_at: model.dateTime().nullable(), + canceled_by: model.text().nullable(), + canceled_at: model.dateTime().nullable(), + order: model.belongsTo<() => typeof Order>(() => Order, { mappedBy: "changes", }), return: model - .belongsTo typeof Return> */>(() => Return, { + .belongsTo<() => typeof Return>(() => Return, { mappedBy: "changes", }) .nullable(), claim: model - .belongsTo typeof OrderClaim> */>(() => OrderClaim, { + .belongsTo<() => typeof OrderClaim>(() => OrderClaim, { mappedBy: "changes", }) .nullable(), exchange: model - .belongsTo typeof OrderExchange> */>(() => OrderExchange, { + .belongsTo<() => typeof OrderExchange>(() => OrderExchange, { mappedBy: "changes", }) .nullable(), - version: model.number(), - change_type: model.text().nullable(), - actions: model.hasMany typeof OrderChangeAction> */>( + actions: model.hasMany<() => typeof OrderChangeAction>( () => OrderChangeAction, { mappedBy: "order_change", } ), - description: model.text().nullable(), - status: model.enum(OrderChangeStatus).default(OrderChangeStatus.PENDING), - internal_note: model.text().nullable(), - created_by: model.text(), - requested_by: model.text().nullable(), - requested_at: model.dateTime().nullable(), - confirmed_by: model.text().nullable(), - confirmed_at: model.dateTime().nullable(), - declined_by: model.text().nullable(), - declined_reason: model.text().nullable(), - metadata: model.json().nullable(), - declined_at: model.dateTime().nullable(), - canceled_by: model.text().nullable(), - canceled_at: model.dateTime().nullable(), }) .indexes([ { diff --git a/packages/modules/order/src/models/order-item.ts b/packages/modules/order/src/models/order-item.ts index 89de36618fe1c..8f2ada3db9d96 100644 --- a/packages/modules/order/src/models/order-item.ts +++ b/packages/modules/order/src/models/order-item.ts @@ -1,20 +1,12 @@ import { model } from "@medusajs/framework/utils" -import { OrderLineItem } from "./line-item" + import { Order } from "./order" +import { OrderLineItem } from "./line-item" const _OrderItem = model .define("OrderItem", { id: model.id({ prefix: "orditem" }).primaryKey(), - order: model.belongsTo typeof Order> */>(() => Order, { - mappedBy: "items", - }), version: model.number(), - item: model.belongsTo typeof OrderLineItem> */>( - () => OrderLineItem, - { - mappedBy: "items", - } - ), unit_price: model.bigNumber().nullable(), compare_at_unit_price: model.bigNumber().nullable(), quantity: model.bigNumber(), @@ -26,6 +18,12 @@ const _OrderItem = model return_dismissed_quantity: model.bigNumber().default(0), written_off_quantity: model.bigNumber().default(0), metadata: model.json().nullable(), + order: model.belongsTo<() => typeof Order>(() => Order, { + mappedBy: "items", + }), + item: model.belongsTo<() => typeof OrderLineItem>(() => OrderLineItem, { + mappedBy: "items", + }), }) .indexes([ { diff --git a/packages/modules/order/src/models/order-shipping-method.ts b/packages/modules/order/src/models/order-shipping-method.ts index e099a1ec5a726..091f4a7f04119 100644 --- a/packages/modules/order/src/models/order-shipping-method.ts +++ b/packages/modules/order/src/models/order-shipping-method.ts @@ -1,39 +1,38 @@ import { model } from "@medusajs/framework/utils" -import { OrderClaim } from "./claim" -import { OrderExchange } from "./exchange" import { Order } from "./order" import { Return } from "./return" +import { OrderClaim } from "./claim" +import { OrderExchange } from "./exchange" import { OrderShippingMethod } from "./shipping-method" const _OrderShipping = model .define("OrderShipping", { id: model.id({ prefix: "ordspmv" }).primaryKey(), version: model.number(), - order: model.belongsTo typeof Order> */>(() => Order, { + order: model.belongsTo<() => typeof Order>(() => Order, { mappedBy: "shipping_methods", }), return: model - .belongsTo typeof Return> */>(() => Return, { + .belongsTo<() => typeof Return>(() => Return, { mappedBy: "shipping_methods", }) .nullable(), exchange: model - .belongsTo typeof OrderExchange> */>(() => OrderExchange, { + .belongsTo<() => typeof OrderExchange>(() => OrderExchange, { mappedBy: "shipping_methods", }) .nullable(), claim: model - .belongsTo typeof OrderClaim> */>(() => OrderClaim, { + .belongsTo<() => typeof OrderClaim>(() => OrderClaim, { mappedBy: "shipping_methods", }) .nullable(), - shipping_method: - model.belongsTo typeof OrderShippingMethod> */>( - () => OrderShippingMethod, - { - mappedBy: "shipping_methods", - } - ), + shipping_method: model.belongsTo<() => typeof OrderShippingMethod>( + () => OrderShippingMethod, + { + mappedBy: "shipping_methods", + } + ), }) .indexes([ { diff --git a/packages/modules/order/src/models/order-summary.ts b/packages/modules/order/src/models/order-summary.ts index cc5649197cae3..607d97d8e58c4 100644 --- a/packages/modules/order/src/models/order-summary.ts +++ b/packages/modules/order/src/models/order-summary.ts @@ -6,7 +6,7 @@ const _OrderSummary = model id: model.id({ prefix: "ordsum" }).primaryKey(), version: model.number().default(1), totals: model.json(), - order: model.belongsTo typeof Order> */>(() => Order, { + order: model.belongsTo<() => typeof Order>(() => Order, { mappedBy: "summary", }), }) diff --git a/packages/modules/order/src/models/order.ts b/packages/modules/order/src/models/order.ts index 8d0dee6050cfc..dc42ac6fc4371 100644 --- a/packages/modules/order/src/models/order.ts +++ b/packages/modules/order/src/models/order.ts @@ -1,13 +1,57 @@ -import { model, OrderStatus } from "@medusajs/framework/utils" -import { OrderAddress } from "./address" +import { + AutoIncrementProperty, + BelongsTo, + BooleanProperty, + DateTimeProperty, + DmlEntity, + DMLSchemaDefaults, + DMLSchemaWithBigNumber, + EnumProperty, + HasMany, + IdProperty, + JSONProperty, + model, + NullableModifier, + NumberProperty, + OrderStatus, + PrimaryKeyModifier, + TextProperty, +} from "@medusajs/framework/utils" +import { Return } from "./return" import { OrderClaim } from "./claim" +import { OrderItem } from "./order-item" +import { OrderAddress } from "./address" import { OrderExchange } from "./exchange" import { OrderChange } from "./order-change" -import { OrderItem } from "./order-item" -import { OrderShipping } from "./order-shipping-method" import { OrderSummary } from "./order-summary" -import { Return } from "./return" import { OrderTransaction } from "./transaction" +import { OrderShipping } from "./order-shipping-method" + +type OrderSchema = { + id: PrimaryKeyModifier + display_id: AutoIncrementProperty + region_id: NullableModifier + customer_id: NullableModifier + version: NumberProperty + sales_channel_id: NullableModifier + status: EnumProperty + is_draft_order: BooleanProperty + email: NullableModifier + currency_code: TextProperty + no_notification: NullableModifier + metadata: NullableModifier, JSONProperty> + canceled_at: NullableModifier + exchanges: HasMany + claims: HasMany + returns: HasMany + changes: HasMany + shipping_address: BelongsTo + billing_address: BelongsTo + summary: HasMany + items: HasMany + shipping_methods: HasMany + transactions: HasMany +} const _Order = model .define("Order", { @@ -21,55 +65,33 @@ const _Order = model is_draft_order: model.boolean().default(false), email: model.text().searchable().nullable(), currency_code: model.text(), - shipping_address: model.belongsTo typeof OrderAddress> */>( - () => OrderAddress - ), - billing_address: model.belongsTo typeof OrderAddress> */>( - () => OrderAddress - ), no_notification: model.boolean().nullable(), metadata: model.json().nullable(), - summary: model.hasMany typeof OrderSummary> */>( - () => OrderSummary, - { - mappedBy: "order", - } - ), - items: model.hasMany typeof OrderItem> */>(() => OrderItem, { + canceled_at: model.dateTime().nullable(), + exchanges: model.hasMany(() => OrderExchange, { mappedBy: "order", }), - shipping_methods: model.hasMany typeof OrderShipping> */>( - () => OrderShipping, - { - mappedBy: "order", - } - ), - transactions: model.hasMany typeof OrderTransaction> */>( - () => OrderTransaction, - { - mappedBy: "order", - } - ), - canceled_at: model.dateTime().nullable(), - - exchanges: model.hasMany typeof OrderExchange> */>( - () => OrderExchange, - { - mappedBy: "order", - } - ), - claims: model.hasMany typeof OrderClaim> */>( - () => OrderClaim, - { - mappedBy: "order", - } - ), - returns: model.hasMany typeof Return> */>(() => Return, { + claims: model.hasMany(() => OrderClaim, { + mappedBy: "order", + }), + returns: model.hasMany(() => Return, { + mappedBy: "order", + }), + changes: model.hasMany(() => OrderChange), + shipping_address: model.belongsTo(() => OrderAddress), + billing_address: model.belongsTo(() => OrderAddress), + summary: model.hasMany(() => OrderSummary, { + mappedBy: "order", + }), + items: model.hasMany(() => OrderItem, { + mappedBy: "order", + }), + shipping_methods: model.hasMany(() => OrderShipping, { + mappedBy: "order", + }), + transactions: model.hasMany(() => OrderTransaction, { mappedBy: "order", }), - changes: model.hasMany typeof OrderChange> */>( - () => OrderChange - ), }) .indexes([ { @@ -128,4 +150,7 @@ const _Order = model }, ]) -export const Order = _Order +export const Order = _Order as DmlEntity< + DMLSchemaWithBigNumber & DMLSchemaDefaults & OrderSchema, + "Order" +> diff --git a/packages/modules/order/src/models/return-item.ts b/packages/modules/order/src/models/return-item.ts index 4fcbd182b762f..85a5d72a2b16c 100644 --- a/packages/modules/order/src/models/return-item.ts +++ b/packages/modules/order/src/models/return-item.ts @@ -1,30 +1,27 @@ import { model } from "@medusajs/framework/utils" -import { OrderLineItem } from "./line-item" import { Return } from "./return" +import { OrderLineItem } from "./line-item" import { ReturnReason } from "./return-reason" const _ReturnItem = model .define("ReturnItem", { id: model.id({ prefix: "retitem" }).primaryKey(), + quantity: model.bigNumber(), + received_quantity: model.bigNumber().default(0), + damaged_quantity: model.bigNumber().default(0), + note: model.text().nullable(), + metadata: model.json().nullable(), reason: model - .belongsTo typeof ReturnReason> */>(() => ReturnReason, { + .belongsTo<() => typeof ReturnReason>(() => ReturnReason, { mappedBy: "return_items", }) .nullable(), - quantity: model.bigNumber(), - received_quantity: model.bigNumber().default(0), - damaged_quantity: model.bigNumber().default(0), - return: model.belongsTo typeof Return> */>(() => Return, { + return: model.belongsTo<() => typeof Return>(() => Return, { mappedBy: "items", }), - item: model.belongsTo typeof OrderLineItem> */>( - () => OrderLineItem, - { - mappedBy: "return_items", - } - ), - note: model.text().nullable(), - metadata: model.json().nullable(), + item: model.belongsTo<() => typeof OrderLineItem>(() => OrderLineItem, { + mappedBy: "return_items", + }), }) .indexes([ { diff --git a/packages/modules/order/src/models/return-reason.ts b/packages/modules/order/src/models/return-reason.ts index 548fe9f1eea16..b37c63645478f 100644 --- a/packages/modules/order/src/models/return-reason.ts +++ b/packages/modules/order/src/models/return-reason.ts @@ -7,27 +7,22 @@ const _ReturnReason = model value: model.text().searchable(), label: model.text().searchable(), description: model.text().nullable(), - parent_return_reason: - model.belongsTo typeof _ReturnReason> */>( - () => _ReturnReason, - { - mappedBy: "return_reason_children", - } - ), - return_reason_children: - model.hasMany typeof _ReturnReason> */>( - () => _ReturnReason, - { - mappedBy: "parent_return_reason", - } - ), - return_items: model.hasMany typeof ReturnItem> */>( - () => ReturnItem, + metadata: model.json().nullable(), + parent_return_reason: model.belongsTo<() => typeof _ReturnReason>( + () => _ReturnReason, { - mappedBy: "reason", + mappedBy: "return_reason_children", } ), - metadata: model.json().nullable(), + return_reason_children: model.hasMany<() => typeof _ReturnReason>( + () => _ReturnReason, + { + mappedBy: "parent_return_reason", + } + ), + return_items: model.hasMany<() => typeof ReturnItem>(() => ReturnItem, { + mappedBy: "reason", + }), }) .indexes([ { diff --git a/packages/modules/order/src/models/return.ts b/packages/modules/order/src/models/return.ts index 46fa8cc7fe695..f83a847137f89 100644 --- a/packages/modules/order/src/models/return.ts +++ b/packages/modules/order/src/models/return.ts @@ -1,57 +1,51 @@ import { model, ReturnStatus } from "@medusajs/framework/utils" -import { OrderChange, OrderTransaction, ReturnItem } from "@models" +import { Order } from "./order" import { OrderClaim } from "./claim" import { OrderExchange } from "./exchange" -import { Order } from "./order" +import { ReturnItem } from "./return-item" +import { OrderChange } from "./order-change" +import { OrderTransaction } from "./transaction" import { OrderShipping } from "./order-shipping-method" const _Return = model .define("Return", { id: model.id({ prefix: "return" }).primaryKey(), - order: model.belongsTo typeof Order> */>(() => Order, { - mappedBy: "returns", - }), - exchange: model.belongsTo typeof OrderExchange> */>( - () => OrderExchange, - { - mappedBy: "return", - } - ), - claim: model.belongsTo typeof OrderClaim> */>( - () => OrderClaim, - { - mappedBy: "return", - } - ), order_version: model.number(), display_id: model.autoincrement(), status: model.enum(ReturnStatus).default(ReturnStatus.OPEN), location_id: model.text().nullable(), no_notification: model.boolean().nullable(), refund_amount: model.bigNumber().nullable(), - items: model.hasMany(() => ReturnItem, { + created_by: model.text().nullable(), + metadata: model.json().nullable(), + requested_at: model.dateTime().nullable(), + received_at: model.dateTime().nullable(), + canceled_at: model.dateTime().nullable(), + order: model.belongsTo<() => typeof Order>(() => Order, { + mappedBy: "returns", + }), + exchange: model.belongsTo<() => typeof OrderExchange>(() => OrderExchange, { + mappedBy: "return", + }), + claim: model.belongsTo<() => typeof OrderClaim>(() => OrderClaim, { + mappedBy: "return", + }), + items: model.hasMany<() => typeof ReturnItem>(() => ReturnItem, { mappedBy: "return", }), - shipping_methods: model.hasMany typeof OrderShipping> */>( + shipping_methods: model.hasMany<() => typeof OrderShipping>( () => OrderShipping, { mappedBy: "return", } ), - transactions: model.hasMany typeof OrderTransaction> */>( + transactions: model.hasMany<() => typeof OrderTransaction>( () => OrderTransaction, { mappedBy: "return", } ), - changes: model.hasMany typeof OrderChange> */>( - () => OrderChange - ), - created_by: model.text().nullable(), - metadata: model.json().nullable(), - requested_at: model.dateTime().nullable(), - received_at: model.dateTime().nullable(), - canceled_at: model.dateTime().nullable(), + changes: model.hasMany<() => typeof OrderChange>(() => OrderChange), }) .indexes([ { diff --git a/packages/modules/order/src/models/shipping-method-adjustment.ts b/packages/modules/order/src/models/shipping-method-adjustment.ts index fdf4fa944d929..01fa946b4430e 100644 --- a/packages/modules/order/src/models/shipping-method-adjustment.ts +++ b/packages/modules/order/src/models/shipping-method-adjustment.ts @@ -9,13 +9,12 @@ const _OrderShippingMethodAdjustment = model code: model.text().nullable(), amount: model.bigNumber(), provider_id: model.text().nullable(), - shipping_method: - model.belongsTo typeof OrderShippingMethod> */>( - () => OrderShippingMethod, - { - mappedBy: "adjustments", - } - ), + shipping_method: model.belongsTo<() => typeof OrderShippingMethod>( + () => OrderShippingMethod, + { + mappedBy: "adjustments", + } + ), }) .indexes([ { diff --git a/packages/modules/order/src/models/shipping-method-tax-line.ts b/packages/modules/order/src/models/shipping-method-tax-line.ts index bd04dcc67e909..e49a9668504ff 100644 --- a/packages/modules/order/src/models/shipping-method-tax-line.ts +++ b/packages/modules/order/src/models/shipping-method-tax-line.ts @@ -9,13 +9,12 @@ const _OrderShippingMethodTaxLine = model code: model.text(), rate: model.bigNumber(), provider_id: model.text().nullable(), - shipping_method: - model.belongsTo typeof OrderShippingMethod> */>( - () => OrderShippingMethod, - { - mappedBy: "tax_lines", - } - ), + shipping_method: model.belongsTo<() => typeof OrderShippingMethod>( + () => OrderShippingMethod, + { + mappedBy: "tax_lines", + } + ), }) .indexes([ { diff --git a/packages/modules/order/src/models/shipping-method.ts b/packages/modules/order/src/models/shipping-method.ts index 86f1cc9443eff..a6679ebcee372 100644 --- a/packages/modules/order/src/models/shipping-method.ts +++ b/packages/modules/order/src/models/shipping-method.ts @@ -1,7 +1,7 @@ import { model } from "@medusajs/framework/utils" import { OrderShipping } from "./order-shipping-method" -import { OrderShippingMethodAdjustment } from "./shipping-method-adjustment" import { OrderShippingMethodTaxLine } from "./shipping-method-tax-line" +import { OrderShippingMethodAdjustment } from "./shipping-method-adjustment" const _OrderShippingMethod = model .define("OrderShippingMethod", { @@ -14,21 +14,19 @@ const _OrderShippingMethod = model shipping_option_id: model.text().nullable(), data: model.json().nullable(), metadata: model.json().nullable(), - tax_lines: - model.hasMany typeof OrderShippingMethodTaxLine> */>( - () => OrderShippingMethodTaxLine, - { - mappedBy: "shipping_method", - } - ), - adjustments: - model.hasMany typeof OrderShippingMethodAdjustment> */>( - () => OrderShippingMethodAdjustment, - { - mappedBy: "shipping_method", - } - ), - shipping_methods: model.hasMany typeof OrderShipping> */>( + tax_lines: model.hasMany<() => typeof OrderShippingMethodTaxLine>( + () => OrderShippingMethodTaxLine, + { + mappedBy: "shipping_method", + } + ), + adjustments: model.hasMany<() => typeof OrderShippingMethodAdjustment>( + () => OrderShippingMethodAdjustment, + { + mappedBy: "shipping_method", + } + ), + shipping_methods: model.hasMany<() => typeof OrderShipping>( () => OrderShipping, { mappedBy: "shipping_method", diff --git a/packages/modules/order/src/models/transaction.ts b/packages/modules/order/src/models/transaction.ts index 1f526bf8a5006..a8df4b9195046 100644 --- a/packages/modules/order/src/models/transaction.ts +++ b/packages/modules/order/src/models/transaction.ts @@ -1,35 +1,54 @@ -import { model } from "@medusajs/framework/utils" -import { OrderClaim } from "./claim" -import { OrderExchange } from "./exchange" +import { + BelongsTo, + BigNumberProperty, + DmlEntity, + DMLSchemaDefaults, + DMLSchemaWithBigNumber, + IdProperty, + model, + NullableModifier, + NumberProperty, + PrimaryKeyModifier, + TextProperty, +} from "@medusajs/framework/utils" import { Order } from "./order" import { Return } from "./return" +import { OrderClaim } from "./claim" +import { OrderExchange } from "./exchange" + +type OrderTransactionSchema = { + id: PrimaryKeyModifier + version: NumberProperty + amount: BigNumberProperty + currency_code: TextProperty + reference: NullableModifier + reference_id: NullableModifier + exchange: BelongsTo + claim: BelongsTo + return: BelongsTo + order: BelongsTo +} const _OrderTransaction = model .define("OrderTransaction", { id: model.id({ prefix: "ordtrx" }).primaryKey(), - order: model.belongsTo typeof Order> */>(() => Order, { - mappedBy: "transactions", - }), - return: model.belongsTo typeof Return> */>(() => Return, { - mappedBy: "transactions", - }), - exchange: model.belongsTo typeof OrderExchange> */>( - () => OrderExchange, - { - mappedBy: "transactions", - } - ), - claim: model.belongsTo typeof OrderClaim> */>( - () => OrderClaim, - { - mappedBy: "transactions", - } - ), version: model.number().default(1), amount: model.bigNumber(), currency_code: model.text(), reference: model.text().nullable(), reference_id: model.text().nullable(), + order: model.belongsTo(() => Order, { + mappedBy: "transactions", + }), + return: model.belongsTo(() => Return, { + mappedBy: "transactions", + }), + exchange: model.belongsTo(() => OrderExchange, { + mappedBy: "transactions", + }), + claim: model.belongsTo(() => OrderClaim, { + mappedBy: "transactions", + }), }) .indexes([ { @@ -82,4 +101,9 @@ const _OrderTransaction = model }, ]) -export const OrderTransaction = _OrderTransaction +export const OrderTransaction = _OrderTransaction as DmlEntity< + DMLSchemaWithBigNumber & + DMLSchemaDefaults & + OrderTransactionSchema, + "OrderTransaction" +> From 1e53148765c6506b0e7d05c1617159510937e02e Mon Sep 17 00:00:00 2001 From: adrien2p Date: Wed, 27 Nov 2024 09:36:55 +0100 Subject: [PATCH 092/175] improve type inference breaks --- packages/core/utils/src/dml/entity-builder.ts | 22 ++---- packages/core/utils/src/dml/entity.ts | 58 +++----------- packages/modules/order/src/models/order.ts | 75 ++++++++----------- .../modules/order/src/models/transaction.ts | 42 ++++------- 4 files changed, 62 insertions(+), 135 deletions(-) diff --git a/packages/core/utils/src/dml/entity-builder.ts b/packages/core/utils/src/dml/entity-builder.ts index e890e6f9bc705..85661b9ebf6f8 100644 --- a/packages/core/utils/src/dml/entity-builder.ts +++ b/packages/core/utils/src/dml/entity-builder.ts @@ -3,15 +3,9 @@ import { IDmlEntityConfig, RelationshipOptions, } from "@medusajs/types" -import { DmlEntity } from "./entity" -import { - createBigNumberProperties, - DMLSchemaWithBigNumber, -} from "./helpers/entity-builder/create-big-number-properties" -import { - createDefaultProperties, - DMLSchemaDefaults, -} from "./helpers/entity-builder/create-default-properties" +import { DmlEntity, DMLEntitySchemaBuilder } from "./entity" +import { createBigNumberProperties } from "./helpers/entity-builder/create-big-number-properties" +import { createDefaultProperties } from "./helpers/entity-builder/create-default-properties" import { ArrayProperty } from "./properties/array" import { AutoIncrementProperty } from "./properties/autoincrement" import { BigNumberProperty } from "./properties/big-number" @@ -121,20 +115,14 @@ export class EntityBuilder { define( nameOrConfig: TConfig, schema: Schema - ): DmlEntity< - DMLSchemaWithBigNumber & DMLSchemaDefaults & Schema, - TConfig - > { + ): DmlEntity, TConfig> { this.#disallowImplicitProperties(schema) return new DmlEntity(nameOrConfig, { ...schema, ...createBigNumberProperties(schema), ...createDefaultProperties(), - } as any) as DmlEntity< - DMLSchemaWithBigNumber & DMLSchemaDefaults & Schema, - TConfig - > + } as any) as DmlEntity, TConfig> } /** diff --git a/packages/core/utils/src/dml/entity.ts b/packages/core/utils/src/dml/entity.ts index fe83f7f016fc6..acb9e449c624e 100644 --- a/packages/core/utils/src/dml/entity.ts +++ b/packages/core/utils/src/dml/entity.ts @@ -6,62 +6,24 @@ import { IDmlEntity, IDmlEntityConfig, InferDmlEntityNameFromConfig, - Prettify, QueryCondition, - RelationshipType, } from "@medusajs/types" import { isObject, isString, toCamelCase } from "../common" import { transformIndexWhere } from "./helpers/entity-builder/build-indexes" -import { - HasMany, - HasOne, - ManyToMany, - RelationNullableModifier, -} from "./relations" import { BelongsTo } from "./relations/belongs-to" - -// TODO: Might need to remove it, it was to run some tests. -// But we are blocked by circular references in the relation resolver -export type CleanupSchemaCiruclarRef< - T, - Exclusion extends string[] = [] -> = Prettify<{ - [K in keyof T]: K extends Exclusion[number] - ? Omit - : T[K] extends RelationNullableModifier - ? R extends () => infer RV - ? RelationNullableModifier< - () => CleanupSchemaCiruclarRef, - RelationshipType< - () => CleanupSchemaCiruclarRef - > - > - : never - : T[K] extends HasOne - ? R extends () => infer RV - ? HasOne<() => CleanupSchemaCiruclarRef> - : never - : T[K] extends BelongsTo - ? R extends () => infer RV - ? BelongsTo< - () => CleanupSchemaCiruclarRef - > - : never - : T[K] extends HasMany - ? R extends () => infer RV - ? HasMany<() => CleanupSchemaCiruclarRef> - : never - : T[K] extends ManyToMany - ? R extends () => infer RV - ? ManyToMany< - () => CleanupSchemaCiruclarRef - > - : never - : T[K] -}> +import { + DMLSchemaDefaults, + DMLSchemaWithBigNumber, +} from "./helpers/entity-builder" const IsDmlEntity = Symbol.for("isDmlEntity") +/** + * Compose the Schema with bigNumbers and the defaults + */ +export type DMLEntitySchemaBuilder = + DMLSchemaWithBigNumber & DMLSchemaDefaults & Schema + function extractNameAndTableName( nameOrConfig: Config ) { diff --git a/packages/modules/order/src/models/order.ts b/packages/modules/order/src/models/order.ts index dc42ac6fc4371..0d11d833d0c52 100644 --- a/packages/modules/order/src/models/order.ts +++ b/packages/modules/order/src/models/order.ts @@ -1,57 +1,44 @@ import { - AutoIncrementProperty, - BelongsTo, - BooleanProperty, - DateTimeProperty, DmlEntity, - DMLSchemaDefaults, - DMLSchemaWithBigNumber, - EnumProperty, - HasMany, - IdProperty, - JSONProperty, + DMLEntitySchemaBuilder, model, - NullableModifier, - NumberProperty, OrderStatus, - PrimaryKeyModifier, - TextProperty, } from "@medusajs/framework/utils" -import { Return } from "./return" -import { OrderClaim } from "./claim" -import { OrderItem } from "./order-item" import { OrderAddress } from "./address" +import { OrderClaim } from "./claim" import { OrderExchange } from "./exchange" import { OrderChange } from "./order-change" +import { OrderItem } from "./order-item" +import { OrderShipping } from "./order-shipping-method" import { OrderSummary } from "./order-summary" +import { Return } from "./return" import { OrderTransaction } from "./transaction" -import { OrderShipping } from "./order-shipping-method" -type OrderSchema = { - id: PrimaryKeyModifier - display_id: AutoIncrementProperty - region_id: NullableModifier - customer_id: NullableModifier - version: NumberProperty - sales_channel_id: NullableModifier - status: EnumProperty - is_draft_order: BooleanProperty - email: NullableModifier - currency_code: TextProperty - no_notification: NullableModifier - metadata: NullableModifier, JSONProperty> - canceled_at: NullableModifier - exchanges: HasMany - claims: HasMany - returns: HasMany - changes: HasMany - shipping_address: BelongsTo - billing_address: BelongsTo - summary: HasMany - items: HasMany - shipping_methods: HasMany - transactions: HasMany -} +//type OrderSchema = { +// id: PrimaryKeyModifier +// display_id: AutoIncrementProperty +// region_id: NullableModifier +// customer_id: NullableModifier +// version: NumberProperty +// sales_channel_id: NullableModifier +// status: EnumProperty +// is_draft_order: BooleanProperty +// email: NullableModifier +// currency_code: TextProperty +// no_notification: NullableModifier +// metadata: NullableModifier, JSONProperty> +// canceled_at: NullableModifier +// exchanges: HasMany +// claims: HasMany +// returns: HasMany +// changes: HasMany +// shipping_address: BelongsTo +// billing_address: BelongsTo +// summary: HasMany +// items: HasMany +// shipping_methods: HasMany +// transactions: HasMany +// } const _Order = model .define("Order", { @@ -151,6 +138,6 @@ const _Order = model ]) export const Order = _Order as DmlEntity< - DMLSchemaWithBigNumber & DMLSchemaDefaults & OrderSchema, + DMLEntitySchemaBuilder<(typeof _Order)["schema"]>, "Order" > diff --git a/packages/modules/order/src/models/transaction.ts b/packages/modules/order/src/models/transaction.ts index a8df4b9195046..ee85ffe0e0a0b 100644 --- a/packages/modules/order/src/models/transaction.ts +++ b/packages/modules/order/src/models/transaction.ts @@ -1,33 +1,25 @@ import { - BelongsTo, - BigNumberProperty, DmlEntity, - DMLSchemaDefaults, - DMLSchemaWithBigNumber, - IdProperty, + DMLEntitySchemaBuilder, model, - NullableModifier, - NumberProperty, - PrimaryKeyModifier, - TextProperty, } from "@medusajs/framework/utils" -import { Order } from "./order" -import { Return } from "./return" import { OrderClaim } from "./claim" import { OrderExchange } from "./exchange" +import { Order } from "./order" +import { Return } from "./return" -type OrderTransactionSchema = { - id: PrimaryKeyModifier - version: NumberProperty - amount: BigNumberProperty - currency_code: TextProperty - reference: NullableModifier - reference_id: NullableModifier - exchange: BelongsTo - claim: BelongsTo - return: BelongsTo - order: BelongsTo -} +// type OrderTransactionSchema = { +// id: PrimaryKeyModifier +// version: NumberProperty +// amount: BigNumberProperty +// currency_code: TextProperty +// reference: NullableModifier +// reference_id: NullableModifier +// exchange: BelongsTo +// claim: BelongsTo +// return: BelongsTo +// order: BelongsTo +// } const _OrderTransaction = model .define("OrderTransaction", { @@ -102,8 +94,6 @@ const _OrderTransaction = model ]) export const OrderTransaction = _OrderTransaction as DmlEntity< - DMLSchemaWithBigNumber & - DMLSchemaDefaults & - OrderTransactionSchema, + DMLEntitySchemaBuilder<(typeof _OrderTransaction)["schema"]>, "OrderTransaction" > From 60d1d24584d74e370e0de787f6d1ca0b3bdde043 Mon Sep 17 00:00:00 2001 From: adrien2p Date: Wed, 27 Nov 2024 09:45:30 +0100 Subject: [PATCH 093/175] improve type inference breaks --- packages/modules/order/src/models/order.ts | 64 +++++++++++-------- .../modules/order/src/models/transaction.ts | 21 ++---- 2 files changed, 42 insertions(+), 43 deletions(-) diff --git a/packages/modules/order/src/models/order.ts b/packages/modules/order/src/models/order.ts index 0d11d833d0c52..9940964291a4f 100644 --- a/packages/modules/order/src/models/order.ts +++ b/packages/modules/order/src/models/order.ts @@ -1,8 +1,20 @@ import { + AutoIncrementProperty, + BelongsTo, + BooleanProperty, + DateTimeProperty, DmlEntity, DMLEntitySchemaBuilder, + EnumProperty, + HasMany, + IdProperty, + JSONProperty, model, + NullableModifier, + NumberProperty, OrderStatus, + PrimaryKeyModifier, + TextProperty, } from "@medusajs/framework/utils" import { OrderAddress } from "./address" import { OrderClaim } from "./claim" @@ -14,31 +26,31 @@ import { OrderSummary } from "./order-summary" import { Return } from "./return" import { OrderTransaction } from "./transaction" -//type OrderSchema = { -// id: PrimaryKeyModifier -// display_id: AutoIncrementProperty -// region_id: NullableModifier -// customer_id: NullableModifier -// version: NumberProperty -// sales_channel_id: NullableModifier -// status: EnumProperty -// is_draft_order: BooleanProperty -// email: NullableModifier -// currency_code: TextProperty -// no_notification: NullableModifier -// metadata: NullableModifier, JSONProperty> -// canceled_at: NullableModifier -// exchanges: HasMany -// claims: HasMany -// returns: HasMany -// changes: HasMany -// shipping_address: BelongsTo -// billing_address: BelongsTo -// summary: HasMany -// items: HasMany -// shipping_methods: HasMany -// transactions: HasMany -// } +type OrderSchema = { + id: PrimaryKeyModifier + display_id: AutoIncrementProperty + region_id: NullableModifier + customer_id: NullableModifier + version: NumberProperty + sales_channel_id: NullableModifier + status: EnumProperty + is_draft_order: BooleanProperty + email: NullableModifier + currency_code: TextProperty + no_notification: NullableModifier + metadata: NullableModifier, JSONProperty> + canceled_at: NullableModifier + exchanges: HasMany + claims: HasMany + returns: HasMany + changes: HasMany + shipping_address: BelongsTo + billing_address: BelongsTo + summary: HasMany + items: HasMany + shipping_methods: HasMany + transactions: HasMany +} const _Order = model .define("Order", { @@ -138,6 +150,6 @@ const _Order = model ]) export const Order = _Order as DmlEntity< - DMLEntitySchemaBuilder<(typeof _Order)["schema"]>, + DMLEntitySchemaBuilder, "Order" > diff --git a/packages/modules/order/src/models/transaction.ts b/packages/modules/order/src/models/transaction.ts index ee85ffe0e0a0b..a61c5c43d723c 100644 --- a/packages/modules/order/src/models/transaction.ts +++ b/packages/modules/order/src/models/transaction.ts @@ -8,19 +8,6 @@ import { OrderExchange } from "./exchange" import { Order } from "./order" import { Return } from "./return" -// type OrderTransactionSchema = { -// id: PrimaryKeyModifier -// version: NumberProperty -// amount: BigNumberProperty -// currency_code: TextProperty -// reference: NullableModifier -// reference_id: NullableModifier -// exchange: BelongsTo -// claim: BelongsTo -// return: BelongsTo -// order: BelongsTo -// } - const _OrderTransaction = model .define("OrderTransaction", { id: model.id({ prefix: "ordtrx" }).primaryKey(), @@ -29,16 +16,16 @@ const _OrderTransaction = model currency_code: model.text(), reference: model.text().nullable(), reference_id: model.text().nullable(), - order: model.belongsTo(() => Order, { + order: model.belongsTo<() => typeof Order>(() => Order, { mappedBy: "transactions", }), - return: model.belongsTo(() => Return, { + return: model.belongsTo<() => typeof Return>(() => Return, { mappedBy: "transactions", }), - exchange: model.belongsTo(() => OrderExchange, { + exchange: model.belongsTo<() => typeof OrderExchange>(() => OrderExchange, { mappedBy: "transactions", }), - claim: model.belongsTo(() => OrderClaim, { + claim: model.belongsTo<() => typeof OrderClaim>(() => OrderClaim, { mappedBy: "transactions", }), }) From 8bb3f1565f51183997ee97d65cd98343af1181a2 Mon Sep 17 00:00:00 2001 From: adrien2p Date: Wed, 27 Nov 2024 11:55:06 +0100 Subject: [PATCH 094/175] update models --- .../__tests__/order-exchange.ts | 2 +- packages/modules/order/src/models/claim-item.ts | 2 +- packages/modules/order/src/models/exchange.ts | 2 +- packages/modules/order/src/models/line-item.ts | 8 ++++---- .../order/src/models/order-change-action.ts | 2 +- .../modules/order/src/models/order-change.ts | 5 ++++- packages/modules/order/src/models/order-item.ts | 14 +++++++------- .../modules/order/src/models/order-summary.ts | 2 +- packages/modules/order/src/models/order.ts | 16 ++++++++-------- packages/modules/order/src/models/return-item.ts | 4 ++-- packages/modules/order/src/models/return.ts | 2 +- .../modules/order/src/models/shipping-method.ts | 4 ++-- packages/modules/order/src/models/transaction.ts | 2 +- .../order/src/services/order-module-service.ts | 2 +- 14 files changed, 35 insertions(+), 32 deletions(-) diff --git a/packages/modules/order/integration-tests/__tests__/order-exchange.ts b/packages/modules/order/integration-tests/__tests__/order-exchange.ts index be846138a5d47..6707173ba5bba 100644 --- a/packages/modules/order/integration-tests/__tests__/order-exchange.ts +++ b/packages/modules/order/integration-tests/__tests__/order-exchange.ts @@ -103,7 +103,7 @@ moduleIntegrationTestRunner({ customer_id: "joe", } as CreateOrderDTO - it("should exchange an item and add two new items to the order", async function () { + it.only("should exchange an item and add two new items to the order", async function () { const createdOrder = await service.createOrders(input) createdOrder.items = createdOrder.items!.sort((a, b) => a.title.localeCompare(b.title) diff --git a/packages/modules/order/src/models/claim-item.ts b/packages/modules/order/src/models/claim-item.ts index a12c355f62262..71200eb9960f4 100644 --- a/packages/modules/order/src/models/claim-item.ts +++ b/packages/modules/order/src/models/claim-item.ts @@ -8,7 +8,7 @@ const _OrderClaimItem = model id: model.id({ prefix: "claitem" }).primaryKey(), reason: model.enum(ClaimReason).nullable(), quantity: model.bigNumber(), - is_additional_item: model.boolean().default(false), + is_additional_item: model.boolean().default(false).nullable(), note: model.text().nullable(), metadata: model.json().nullable(), claim: model.belongsTo<() => typeof OrderClaim>(() => OrderClaim, { diff --git a/packages/modules/order/src/models/exchange.ts b/packages/modules/order/src/models/exchange.ts index a31f52f15ff8e..e7c2ffa7a00b8 100644 --- a/packages/modules/order/src/models/exchange.ts +++ b/packages/modules/order/src/models/exchange.ts @@ -15,7 +15,7 @@ const _OrderExchange = model display_id: model.autoincrement(), no_notification: model.boolean().nullable(), difference_due: model.bigNumber().nullable(), - allow_backorder: model.boolean().default(false), + allow_backorder: model.boolean().default(false).nullable(), created_by: model.text().nullable(), metadata: model.json().nullable(), canceled_at: model.dateTime().nullable(), diff --git a/packages/modules/order/src/models/line-item.ts b/packages/modules/order/src/models/line-item.ts index df03fc07294e3..0373273fdcb46 100644 --- a/packages/modules/order/src/models/line-item.ts +++ b/packages/modules/order/src/models/line-item.ts @@ -25,12 +25,12 @@ const _OrderLineItem = model variant_barcode: model.text().nullable(), variant_title: model.text().nullable(), variant_option_values: model.json().nullable(), - requires_shipping: model.boolean().default(true), - is_discountable: model.boolean().default(true), - is_tax_inclusive: model.boolean().default(false), + requires_shipping: model.boolean().default(true).nullable(), + is_discountable: model.boolean().default(true).nullable(), + is_tax_inclusive: model.boolean().default(false).nullable(), compare_at_unit_price: model.bigNumber().nullable(), unit_price: model.bigNumber(), - is_custom_price: model.boolean().default(false), + is_custom_price: model.boolean().default(false).nullable(), metadata: model.json().nullable(), tax_lines: model.hasMany<() => typeof OrderLineItemTaxLine>( () => OrderLineItemTaxLine, diff --git a/packages/modules/order/src/models/order-change-action.ts b/packages/modules/order/src/models/order-change-action.ts index b9403a996ab6e..3dd8ab0d4c258 100644 --- a/packages/modules/order/src/models/order-change-action.ts +++ b/packages/modules/order/src/models/order-change-action.ts @@ -16,7 +16,7 @@ const _OrderChangeAction = model details: model.json(), amount: model.bigNumber().nullable(), internal_note: model.text().nullable(), - applied: model.boolean().default(false), + applied: model.boolean().default(false).nullable(), order_change: model.belongsTo<() => typeof OrderChange>(() => OrderChange, { mappedBy: "actions", }), diff --git a/packages/modules/order/src/models/order-change.ts b/packages/modules/order/src/models/order-change.ts index d34d8401e70a1..53e24bcee4d22 100644 --- a/packages/modules/order/src/models/order-change.ts +++ b/packages/modules/order/src/models/order-change.ts @@ -11,7 +11,10 @@ const _OrderChange = model version: model.number(), change_type: model.text().nullable(), description: model.text().nullable(), - status: model.enum(OrderChangeStatus).default(OrderChangeStatus.PENDING), + status: model + .enum(OrderChangeStatus) + .default(OrderChangeStatus.PENDING) + .nullable(), internal_note: model.text().nullable(), created_by: model.text(), requested_by: model.text().nullable(), diff --git a/packages/modules/order/src/models/order-item.ts b/packages/modules/order/src/models/order-item.ts index 8f2ada3db9d96..a027f1a225bf0 100644 --- a/packages/modules/order/src/models/order-item.ts +++ b/packages/modules/order/src/models/order-item.ts @@ -10,13 +10,13 @@ const _OrderItem = model unit_price: model.bigNumber().nullable(), compare_at_unit_price: model.bigNumber().nullable(), quantity: model.bigNumber(), - fulfilled_quantity: model.bigNumber().default(0), - delivered_quantity: model.bigNumber().default(0), - shipped_quantity: model.bigNumber().default(0), - return_requested_quantity: model.bigNumber().default(0), - return_received_quantity: model.bigNumber().default(0), - return_dismissed_quantity: model.bigNumber().default(0), - written_off_quantity: model.bigNumber().default(0), + fulfilled_quantity: model.bigNumber().default(0).nullable(), + delivered_quantity: model.bigNumber().default(0).nullable(), + shipped_quantity: model.bigNumber().default(0).nullable(), + return_requested_quantity: model.bigNumber().default(0).nullable(), + return_received_quantity: model.bigNumber().default(0).nullable(), + return_dismissed_quantity: model.bigNumber().default(0).nullable(), + written_off_quantity: model.bigNumber().default(0).nullable(), metadata: model.json().nullable(), order: model.belongsTo<() => typeof Order>(() => Order, { mappedBy: "items", diff --git a/packages/modules/order/src/models/order-summary.ts b/packages/modules/order/src/models/order-summary.ts index 607d97d8e58c4..f035a6d1491c1 100644 --- a/packages/modules/order/src/models/order-summary.ts +++ b/packages/modules/order/src/models/order-summary.ts @@ -4,7 +4,7 @@ import { Order } from "./order" const _OrderSummary = model .define("OrderSummary", { id: model.id({ prefix: "ordsum" }).primaryKey(), - version: model.number().default(1), + version: model.number().default(1).nullable(), totals: model.json(), order: model.belongsTo<() => typeof Order>(() => Order, { mappedBy: "summary", diff --git a/packages/modules/order/src/models/order.ts b/packages/modules/order/src/models/order.ts index 9940964291a4f..02f66c162dab5 100644 --- a/packages/modules/order/src/models/order.ts +++ b/packages/modules/order/src/models/order.ts @@ -28,13 +28,13 @@ import { OrderTransaction } from "./transaction" type OrderSchema = { id: PrimaryKeyModifier - display_id: AutoIncrementProperty + display_id: NullableModifier region_id: NullableModifier customer_id: NullableModifier - version: NumberProperty + version: NullableModifier sales_channel_id: NullableModifier - status: EnumProperty - is_draft_order: BooleanProperty + status: NullableModifier> + is_draft_order: NullableModifier email: NullableModifier currency_code: TextProperty no_notification: NullableModifier @@ -55,13 +55,13 @@ type OrderSchema = { const _Order = model .define("Order", { id: model.id({ prefix: "order" }).primaryKey(), - display_id: model.autoincrement(), + display_id: model.autoincrement().nullable(), region_id: model.text().nullable(), customer_id: model.text().nullable(), - version: model.number().default(1), + version: model.number().default(1).nullable(), sales_channel_id: model.text().nullable(), - status: model.enum(OrderStatus).default(OrderStatus.PENDING), - is_draft_order: model.boolean().default(false), + status: model.enum(OrderStatus).default(OrderStatus.PENDING).nullable(), + is_draft_order: model.boolean().default(false).nullable(), email: model.text().searchable().nullable(), currency_code: model.text(), no_notification: model.boolean().nullable(), diff --git a/packages/modules/order/src/models/return-item.ts b/packages/modules/order/src/models/return-item.ts index 85a5d72a2b16c..cf478e0da9e6c 100644 --- a/packages/modules/order/src/models/return-item.ts +++ b/packages/modules/order/src/models/return-item.ts @@ -7,8 +7,8 @@ const _ReturnItem = model .define("ReturnItem", { id: model.id({ prefix: "retitem" }).primaryKey(), quantity: model.bigNumber(), - received_quantity: model.bigNumber().default(0), - damaged_quantity: model.bigNumber().default(0), + received_quantity: model.bigNumber().default(0).nullable(), + damaged_quantity: model.bigNumber().default(0).nullable(), note: model.text().nullable(), metadata: model.json().nullable(), reason: model diff --git a/packages/modules/order/src/models/return.ts b/packages/modules/order/src/models/return.ts index f83a847137f89..4048aa630b6e8 100644 --- a/packages/modules/order/src/models/return.ts +++ b/packages/modules/order/src/models/return.ts @@ -12,7 +12,7 @@ const _Return = model id: model.id({ prefix: "return" }).primaryKey(), order_version: model.number(), display_id: model.autoincrement(), - status: model.enum(ReturnStatus).default(ReturnStatus.OPEN), + status: model.enum(ReturnStatus).default(ReturnStatus.OPEN).nullable(), location_id: model.text().nullable(), no_notification: model.boolean().nullable(), refund_amount: model.bigNumber().nullable(), diff --git a/packages/modules/order/src/models/shipping-method.ts b/packages/modules/order/src/models/shipping-method.ts index a6679ebcee372..4dd53f2ec6df2 100644 --- a/packages/modules/order/src/models/shipping-method.ts +++ b/packages/modules/order/src/models/shipping-method.ts @@ -9,8 +9,8 @@ const _OrderShippingMethod = model name: model.text(), description: model.json().nullable(), amount: model.bigNumber(), - is_tax_inclusive: model.boolean().default(false), - is_custom_amount: model.boolean().default(false), + is_tax_inclusive: model.boolean().default(false).nullable(), + is_custom_amount: model.boolean().default(false).nullable(), shipping_option_id: model.text().nullable(), data: model.json().nullable(), metadata: model.json().nullable(), diff --git a/packages/modules/order/src/models/transaction.ts b/packages/modules/order/src/models/transaction.ts index a61c5c43d723c..5637253446754 100644 --- a/packages/modules/order/src/models/transaction.ts +++ b/packages/modules/order/src/models/transaction.ts @@ -11,7 +11,7 @@ import { Return } from "./return" const _OrderTransaction = model .define("OrderTransaction", { id: model.id({ prefix: "ordtrx" }).primaryKey(), - version: model.number().default(1), + version: model.number().default(1).nullable(), amount: model.bigNumber(), currency_code: model.text(), reference: model.text().nullable(), diff --git a/packages/modules/order/src/services/order-module-service.ts b/packages/modules/order/src/services/order-module-service.ts index 0a13831153f4a..25008623afe54 100644 --- a/packages/modules/order/src/services/order-module-service.ts +++ b/packages/modules/order/src/services/order-module-service.ts @@ -1969,7 +1969,7 @@ export default class OrderModuleService return { ...dataMap[order.id], - version: order.version + 1, + version: order.version! + 1, } as any }) From 7c0a1d5e0f7ba4588425f45b394a4319c52c27b6 Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Wed, 27 Nov 2024 10:41:33 -0300 Subject: [PATCH 095/175] rm nullable --- packages/modules/order/src/models/claim-item.ts | 4 ++-- packages/modules/order/src/models/exchange.ts | 8 ++++---- packages/modules/order/src/models/line-item.ts | 14 +++++++------- .../order/src/models/order-change-action.ts | 2 +- packages/modules/order/src/models/order-item.ts | 16 ++++++++-------- .../modules/order/src/models/order-summary.ts | 2 +- packages/modules/order/src/models/order.ts | 12 ++++++------ packages/modules/order/src/models/return-item.ts | 6 +++--- packages/modules/order/src/models/return.ts | 8 ++++---- .../modules/order/src/models/shipping-method.ts | 6 +++--- packages/modules/order/src/models/transaction.ts | 2 +- 11 files changed, 40 insertions(+), 40 deletions(-) diff --git a/packages/modules/order/src/models/claim-item.ts b/packages/modules/order/src/models/claim-item.ts index 71200eb9960f4..e5cb6bf656961 100644 --- a/packages/modules/order/src/models/claim-item.ts +++ b/packages/modules/order/src/models/claim-item.ts @@ -1,14 +1,14 @@ import { ClaimReason, model } from "@medusajs/framework/utils" import { OrderClaim } from "./claim" -import { OrderLineItem } from "./line-item" import { OrderClaimItemImage } from "./claim-item-image" +import { OrderLineItem } from "./line-item" const _OrderClaimItem = model .define("OrderClaimItem", { id: model.id({ prefix: "claitem" }).primaryKey(), reason: model.enum(ClaimReason).nullable(), quantity: model.bigNumber(), - is_additional_item: model.boolean().default(false).nullable(), + is_additional_item: model.boolean().default(false), note: model.text().nullable(), metadata: model.json().nullable(), claim: model.belongsTo<() => typeof OrderClaim>(() => OrderClaim, { diff --git a/packages/modules/order/src/models/exchange.ts b/packages/modules/order/src/models/exchange.ts index e7c2ffa7a00b8..859be99620914 100644 --- a/packages/modules/order/src/models/exchange.ts +++ b/packages/modules/order/src/models/exchange.ts @@ -1,11 +1,11 @@ import { model } from "@medusajs/framework/utils" +import { OrderExchangeItem } from "./exchange-item" import { Order } from "./order" -import { Return } from "./return" import { OrderChange } from "./order-change" -import { OrderTransaction } from "./transaction" -import { OrderExchangeItem } from "./exchange-item" import { OrderShipping } from "./order-shipping-method" +import { Return } from "./return" +import { OrderTransaction } from "./transaction" const _OrderExchange = model .define("OrderExchange", { @@ -15,7 +15,7 @@ const _OrderExchange = model display_id: model.autoincrement(), no_notification: model.boolean().nullable(), difference_due: model.bigNumber().nullable(), - allow_backorder: model.boolean().default(false).nullable(), + allow_backorder: model.boolean().default(false), created_by: model.text().nullable(), metadata: model.json().nullable(), canceled_at: model.dateTime().nullable(), diff --git a/packages/modules/order/src/models/line-item.ts b/packages/modules/order/src/models/line-item.ts index 0373273fdcb46..1e7c61524ef9a 100644 --- a/packages/modules/order/src/models/line-item.ts +++ b/packages/modules/order/src/models/line-item.ts @@ -1,10 +1,10 @@ import { model } from "@medusajs/framework/utils" -import { OrderItem } from "./order-item" -import { ReturnItem } from "./return-item" import { OrderClaimItem } from "./claim-item" import { OrderExchangeItem } from "./exchange-item" -import { OrderLineItemTaxLine } from "./line-item-tax-line" import { OrderLineItemAdjustment } from "./line-item-adjustment" +import { OrderLineItemTaxLine } from "./line-item-tax-line" +import { OrderItem } from "./order-item" +import { ReturnItem } from "./return-item" const _OrderLineItem = model .define("OrderLineItem", { @@ -25,12 +25,12 @@ const _OrderLineItem = model variant_barcode: model.text().nullable(), variant_title: model.text().nullable(), variant_option_values: model.json().nullable(), - requires_shipping: model.boolean().default(true).nullable(), - is_discountable: model.boolean().default(true).nullable(), - is_tax_inclusive: model.boolean().default(false).nullable(), + requires_shipping: model.boolean().default(true), + is_discountable: model.boolean().default(true), + is_tax_inclusive: model.boolean().default(false), compare_at_unit_price: model.bigNumber().nullable(), unit_price: model.bigNumber(), - is_custom_price: model.boolean().default(false).nullable(), + is_custom_price: model.boolean().default(false), metadata: model.json().nullable(), tax_lines: model.hasMany<() => typeof OrderLineItemTaxLine>( () => OrderLineItemTaxLine, diff --git a/packages/modules/order/src/models/order-change-action.ts b/packages/modules/order/src/models/order-change-action.ts index 3dd8ab0d4c258..b9403a996ab6e 100644 --- a/packages/modules/order/src/models/order-change-action.ts +++ b/packages/modules/order/src/models/order-change-action.ts @@ -16,7 +16,7 @@ const _OrderChangeAction = model details: model.json(), amount: model.bigNumber().nullable(), internal_note: model.text().nullable(), - applied: model.boolean().default(false).nullable(), + applied: model.boolean().default(false), order_change: model.belongsTo<() => typeof OrderChange>(() => OrderChange, { mappedBy: "actions", }), diff --git a/packages/modules/order/src/models/order-item.ts b/packages/modules/order/src/models/order-item.ts index a027f1a225bf0..4ff9411835666 100644 --- a/packages/modules/order/src/models/order-item.ts +++ b/packages/modules/order/src/models/order-item.ts @@ -1,7 +1,7 @@ import { model } from "@medusajs/framework/utils" -import { Order } from "./order" import { OrderLineItem } from "./line-item" +import { Order } from "./order" const _OrderItem = model .define("OrderItem", { @@ -10,13 +10,13 @@ const _OrderItem = model unit_price: model.bigNumber().nullable(), compare_at_unit_price: model.bigNumber().nullable(), quantity: model.bigNumber(), - fulfilled_quantity: model.bigNumber().default(0).nullable(), - delivered_quantity: model.bigNumber().default(0).nullable(), - shipped_quantity: model.bigNumber().default(0).nullable(), - return_requested_quantity: model.bigNumber().default(0).nullable(), - return_received_quantity: model.bigNumber().default(0).nullable(), - return_dismissed_quantity: model.bigNumber().default(0).nullable(), - written_off_quantity: model.bigNumber().default(0).nullable(), + fulfilled_quantity: model.bigNumber().default(0), + delivered_quantity: model.bigNumber().default(0), + shipped_quantity: model.bigNumber().default(0), + return_requested_quantity: model.bigNumber().default(0), + return_received_quantity: model.bigNumber().default(0), + return_dismissed_quantity: model.bigNumber().default(0), + written_off_quantity: model.bigNumber().default(0), metadata: model.json().nullable(), order: model.belongsTo<() => typeof Order>(() => Order, { mappedBy: "items", diff --git a/packages/modules/order/src/models/order-summary.ts b/packages/modules/order/src/models/order-summary.ts index f035a6d1491c1..607d97d8e58c4 100644 --- a/packages/modules/order/src/models/order-summary.ts +++ b/packages/modules/order/src/models/order-summary.ts @@ -4,7 +4,7 @@ import { Order } from "./order" const _OrderSummary = model .define("OrderSummary", { id: model.id({ prefix: "ordsum" }).primaryKey(), - version: model.number().default(1).nullable(), + version: model.number().default(1), totals: model.json(), order: model.belongsTo<() => typeof Order>(() => Order, { mappedBy: "summary", diff --git a/packages/modules/order/src/models/order.ts b/packages/modules/order/src/models/order.ts index 02f66c162dab5..db5c70b652179 100644 --- a/packages/modules/order/src/models/order.ts +++ b/packages/modules/order/src/models/order.ts @@ -31,10 +31,10 @@ type OrderSchema = { display_id: NullableModifier region_id: NullableModifier customer_id: NullableModifier - version: NullableModifier + version: NumberProperty sales_channel_id: NullableModifier - status: NullableModifier> - is_draft_order: NullableModifier + status: EnumProperty + is_draft_order: BooleanProperty email: NullableModifier currency_code: TextProperty no_notification: NullableModifier @@ -58,10 +58,10 @@ const _Order = model display_id: model.autoincrement().nullable(), region_id: model.text().nullable(), customer_id: model.text().nullable(), - version: model.number().default(1).nullable(), + version: model.number().default(1), sales_channel_id: model.text().nullable(), - status: model.enum(OrderStatus).default(OrderStatus.PENDING).nullable(), - is_draft_order: model.boolean().default(false).nullable(), + status: model.enum(OrderStatus).default(OrderStatus.PENDING), + is_draft_order: model.boolean().default(false), email: model.text().searchable().nullable(), currency_code: model.text(), no_notification: model.boolean().nullable(), diff --git a/packages/modules/order/src/models/return-item.ts b/packages/modules/order/src/models/return-item.ts index cf478e0da9e6c..70c9e6b7b634f 100644 --- a/packages/modules/order/src/models/return-item.ts +++ b/packages/modules/order/src/models/return-item.ts @@ -1,14 +1,14 @@ import { model } from "@medusajs/framework/utils" -import { Return } from "./return" import { OrderLineItem } from "./line-item" +import { Return } from "./return" import { ReturnReason } from "./return-reason" const _ReturnItem = model .define("ReturnItem", { id: model.id({ prefix: "retitem" }).primaryKey(), quantity: model.bigNumber(), - received_quantity: model.bigNumber().default(0).nullable(), - damaged_quantity: model.bigNumber().default(0).nullable(), + received_quantity: model.bigNumber().default(0), + damaged_quantity: model.bigNumber().default(0), note: model.text().nullable(), metadata: model.json().nullable(), reason: model diff --git a/packages/modules/order/src/models/return.ts b/packages/modules/order/src/models/return.ts index 4048aa630b6e8..a2bf5a2400505 100644 --- a/packages/modules/order/src/models/return.ts +++ b/packages/modules/order/src/models/return.ts @@ -1,18 +1,18 @@ import { model, ReturnStatus } from "@medusajs/framework/utils" -import { Order } from "./order" import { OrderClaim } from "./claim" import { OrderExchange } from "./exchange" -import { ReturnItem } from "./return-item" +import { Order } from "./order" import { OrderChange } from "./order-change" -import { OrderTransaction } from "./transaction" import { OrderShipping } from "./order-shipping-method" +import { ReturnItem } from "./return-item" +import { OrderTransaction } from "./transaction" const _Return = model .define("Return", { id: model.id({ prefix: "return" }).primaryKey(), order_version: model.number(), display_id: model.autoincrement(), - status: model.enum(ReturnStatus).default(ReturnStatus.OPEN).nullable(), + status: model.enum(ReturnStatus).default(ReturnStatus.OPEN), location_id: model.text().nullable(), no_notification: model.boolean().nullable(), refund_amount: model.bigNumber().nullable(), diff --git a/packages/modules/order/src/models/shipping-method.ts b/packages/modules/order/src/models/shipping-method.ts index 4dd53f2ec6df2..052f07396472a 100644 --- a/packages/modules/order/src/models/shipping-method.ts +++ b/packages/modules/order/src/models/shipping-method.ts @@ -1,7 +1,7 @@ import { model } from "@medusajs/framework/utils" import { OrderShipping } from "./order-shipping-method" -import { OrderShippingMethodTaxLine } from "./shipping-method-tax-line" import { OrderShippingMethodAdjustment } from "./shipping-method-adjustment" +import { OrderShippingMethodTaxLine } from "./shipping-method-tax-line" const _OrderShippingMethod = model .define("OrderShippingMethod", { @@ -9,8 +9,8 @@ const _OrderShippingMethod = model name: model.text(), description: model.json().nullable(), amount: model.bigNumber(), - is_tax_inclusive: model.boolean().default(false).nullable(), - is_custom_amount: model.boolean().default(false).nullable(), + is_tax_inclusive: model.boolean(), + is_custom_amount: model.boolean(), shipping_option_id: model.text().nullable(), data: model.json().nullable(), metadata: model.json().nullable(), diff --git a/packages/modules/order/src/models/transaction.ts b/packages/modules/order/src/models/transaction.ts index 5637253446754..a61c5c43d723c 100644 --- a/packages/modules/order/src/models/transaction.ts +++ b/packages/modules/order/src/models/transaction.ts @@ -11,7 +11,7 @@ import { Return } from "./return" const _OrderTransaction = model .define("OrderTransaction", { id: model.id({ prefix: "ordtrx" }).primaryKey(), - version: model.number().default(1).nullable(), + version: model.number().default(1), amount: model.bigNumber(), currency_code: model.text(), reference: model.text().nullable(), From 02f4878455c4c27e78fc03bf211dafbd5a079934 Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Wed, 27 Nov 2024 14:18:54 -0300 Subject: [PATCH 096/175] default value --- .../dml/helpers/create-mikro-orm-entity.ts | 26 +- .../helpers/entity-builder/define-property.ts | 19 +- .../src/migrations/Migration20240719123015.ts | 6 +- .../migrations/.snapshot-medusa-order.json | 3703 +++++++++-------- .../src/migrations/Migration20241127171653.ts | 782 ++++ packages/modules/order/src/models/address.ts | 4 +- packages/modules/order/src/models/order.ts | 15 +- 7 files changed, 2764 insertions(+), 1791 deletions(-) create mode 100644 packages/modules/order/src/migrations/Migration20241127171653.ts diff --git a/packages/core/utils/src/dml/helpers/create-mikro-orm-entity.ts b/packages/core/utils/src/dml/helpers/create-mikro-orm-entity.ts index a599da2546ece..da5c7bdcd773d 100644 --- a/packages/core/utils/src/dml/helpers/create-mikro-orm-entity.ts +++ b/packages/core/utils/src/dml/helpers/create-mikro-orm-entity.ts @@ -8,10 +8,11 @@ import type { } from "@medusajs/types" import { Entity, Filter } from "@mikro-orm/core" +import { isDefined } from "../../common" +import { mikroOrmSoftDeletableFilterOptions } from "../../dal" import { DmlEntity } from "../entity" -import { IdProperty } from "../properties/id" import { DuplicateIdPropertyError } from "../errors" -import { mikroOrmSoftDeletableFilterOptions } from "../../dal" +import { IdProperty } from "../properties/id" import { applySearchable } from "./entity-builder/apply-searchable" import { defineProperty } from "./entity-builder/define-property" import { defineRelationship } from "./entity-builder/define-relationship" @@ -45,7 +46,24 @@ function createMikrORMEntity() { * DML entity. */ function createEntity>(entity: T): Infer { - class MikroORMEntity {} + class MikroORMEntity { + static __defaultValues = {} + static setDefaultValue(key: string, value: any) { + this.__defaultValues[key] = value + } + + constructor() { + Object.entries(MikroORMEntity.__defaultValues).forEach( + ([key, value]) => { + if (isDefined(this[key])) { + return + } + + this[key] = value + } + ) + } + } const { schema, cascades, indexes: entityIndexes = [] } = entity.parse() const { modelName, tableName } = parseEntityName(entity) @@ -102,7 +120,7 @@ function createMikrORMEntity() { */ const RegisteredEntity = Entity({ tableName })( Filter(mikroOrmSoftDeletableFilterOptions)(MikroORMEntity) - ) as Infer + ) as unknown as Infer ENTITIES[modelName] = RegisteredEntity return RegisteredEntity diff --git a/packages/core/utils/src/dml/helpers/entity-builder/define-property.ts b/packages/core/utils/src/dml/helpers/entity-builder/define-property.ts index 25bd5e9e68884..4f562ba1cd561 100644 --- a/packages/core/utils/src/dml/helpers/entity-builder/define-property.ts +++ b/packages/core/utils/src/dml/helpers/entity-builder/define-property.ts @@ -119,15 +119,18 @@ export function defineProperty( ) { const field = property.parse(propertyName) /** - * Here we initialize nullable properties with a null value + * Here we initialize all properties with their default values */ - if (field.nullable) { - Object.defineProperty(MikroORMEntity.prototype, field.fieldName, { - value: null, - configurable: true, - enumerable: true, - writable: true, - }) + + if (isDefined(field.defaultValue) || field.nullable) { + ;(MikroORMEntity as any).setDefaultValue( + propertyName, + isDefined(field.defaultValue) + ? field.defaultValue + : field.nullable + ? null + : undefined + ) } if (SPECIAL_PROPERTIES[field.fieldName]) { diff --git a/packages/modules/inventory/src/migrations/Migration20240719123015.ts b/packages/modules/inventory/src/migrations/Migration20240719123015.ts index 01ceffa8753c9..bf66e54607dc5 100644 --- a/packages/modules/inventory/src/migrations/Migration20240719123015.ts +++ b/packages/modules/inventory/src/migrations/Migration20240719123015.ts @@ -43,13 +43,13 @@ export class Migration20240719123015 extends Migration { ALTER TABLE "reservation_item" DROP COLUMN IF EXISTS "raw_quantity"; ALTER TABLE "inventory_level" ALTER COLUMN "stocked_quantity" TYPE integer; - ALTER TABLE "inventory_level" DROP COLUMN IF NOT EXISTS "raw_stocked_quantity"; + ALTER TABLE "inventory_level" DROP COLUMN IF EXISTS "raw_stocked_quantity"; ALTER TABLE "inventory_level" ALTER COLUMN "reserved_quantity" TYPE integer; - ALTER TABLE "inventory_level" DROP COLUMN IF NOT EXISTS "raw_reserved_quantity"; + ALTER TABLE "inventory_level" DROP COLUMN IF EXISTS "raw_reserved_quantity"; ALTER TABLE "inventory_level" ALTER COLUMN "incoming_quantity" TYPE integer; - ALTER TABLE "inventory_level" DROP COLUMN IF NOT EXISTS "raw_incoming_quantity"; + ALTER TABLE "inventory_level" DROP COLUMN IF EXISTS "raw_incoming_quantity"; DROP INDEX IF EXISTS "IDX_inventory_item_sku_unique"; diff --git a/packages/modules/order/src/migrations/.snapshot-medusa-order.json b/packages/modules/order/src/migrations/.snapshot-medusa-order.json index deb6066344986..fd19b1d587297 100644 --- a/packages/modules/order/src/migrations/.snapshot-medusa-order.json +++ b/packages/modules/order/src/migrations/.snapshot-medusa-order.json @@ -144,20 +144,36 @@ "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": "order_address", "schema": "public", "indexes": [ + { + "keyName": "IDX_order_address_deleted_at", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_address_deleted_at\" ON \"order_address\" (deleted_at) WHERE deleted_at IS NULL" + }, { "keyName": "IDX_order_address_customer_id", - "columnNames": [ - "customer_id" - ], + "columnNames": [], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_address_customer_id\" ON \"order_address\" (customer_id)" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_address_customer_id\" ON \"order_address\" (customer_id) WHERE deleted_at IS NULL" }, { "keyName": "order_address_pkey", @@ -185,12 +201,12 @@ }, "display_id": { "name": "display_id", - "type": "serial", - "unsigned": true, - "autoincrement": true, + "type": "bigserial", + "unsigned": false, + "autoincrement": false, "primary": false, - "nullable": false, - "mappedType": "integer" + "nullable": true, + "mappedType": "bigint" }, "region_id": { "name": "region_id", @@ -275,41 +291,51 @@ "nullable": false, "mappedType": "text" }, - "shipping_address_id": { - "name": "shipping_address_id", - "type": "text", + "no_notification": { + "name": "no_notification", + "type": "boolean", "unsigned": false, "autoincrement": false, "primary": false, "nullable": true, - "mappedType": "text" + "mappedType": "boolean" }, - "billing_address_id": { - "name": "billing_address_id", - "type": "text", + "metadata": { + "name": "metadata", + "type": "jsonb", "unsigned": false, "autoincrement": false, "primary": false, "nullable": true, - "mappedType": "text" + "mappedType": "json" }, - "no_notification": { - "name": "no_notification", - "type": "boolean", + "canceled_at": { + "name": "canceled_at", + "type": "timestamptz", "unsigned": false, "autoincrement": false, "primary": false, "nullable": true, - "mappedType": "boolean" + "length": 6, + "mappedType": "datetime" }, - "metadata": { - "name": "metadata", - "type": "jsonb", + "shipping_address_id": { + "name": "shipping_address_id", + "type": "text", "unsigned": false, "autoincrement": false, "primary": false, "nullable": true, - "mappedType": "json" + "mappedType": "text" + }, + "billing_address_id": { + "name": "billing_address_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" }, "created_at": { "name": "created_at", @@ -342,26 +368,38 @@ "nullable": true, "length": 6, "mappedType": "datetime" - }, - "canceled_at": { - "name": "canceled_at", - "type": "timestamptz", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "length": 6, - "mappedType": "datetime" } }, "name": "order", "schema": "public", "indexes": [ + { + "keyName": "IDX_order_shipping_address_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_address_id\" ON \"order\" (shipping_address_id) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_order_billing_address_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_billing_address_id\" ON \"order\" (billing_address_id) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_order_deleted_at", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_deleted_at\" ON \"order\" (deleted_at) WHERE deleted_at IS NULL" + }, { "keyName": "IDX_order_display_id", - "columnNames": [ - "display_id" - ], + "columnNames": [], "composite": false, "primary": false, "unique": false, @@ -369,9 +407,7 @@ }, { "keyName": "IDX_order_region_id", - "columnNames": [ - "region_id" - ], + "columnNames": [], "composite": false, "primary": false, "unique": false, @@ -379,39 +415,31 @@ }, { "keyName": "IDX_order_customer_id", - "columnNames": [ - "customer_id" - ], + "columnNames": [], "composite": false, "primary": false, "unique": false, "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_customer_id\" ON \"order\" (customer_id) WHERE deleted_at IS NOT NULL" }, { - "keyName": "IDX_order_customer_id", - "columnNames": [ - "sales_channel_id" - ], + "keyName": "IDX_order_sales_channel_id", + "columnNames": [], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_customer_id\" ON \"order\" (customer_id) WHERE deleted_at IS NOT NULL" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_sales_channel_id\" ON \"order\" (sales_channel_id) WHERE deleted_at IS NOT NULL" }, { - "keyName": "IDX_order_is_draft_order", - "columnNames": [ - "is_draft_order" - ], + "keyName": "IDX_order_deleted_at", + "columnNames": [], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_is_draft_order\" ON \"order\" (is_draft_order) WHERE deleted_at IS NOT NULL" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_deleted_at\" ON \"order\" (deleted_at) WHERE deleted_at IS NOT NULL" }, { "keyName": "IDX_order_currency_code", - "columnNames": [ - "currency_code" - ], + "columnNames": [], "composite": false, "primary": false, "unique": false, @@ -419,9 +447,7 @@ }, { "keyName": "IDX_order_shipping_address_id", - "columnNames": [ - "shipping_address_id" - ], + "columnNames": [], "composite": false, "primary": false, "unique": false, @@ -429,23 +455,19 @@ }, { "keyName": "IDX_order_billing_address_id", - "columnNames": [ - "billing_address_id" - ], + "columnNames": [], "composite": false, "primary": false, "unique": false, "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_billing_address_id\" ON \"order\" (billing_address_id) WHERE deleted_at IS NOT NULL" }, { - "keyName": "IDX_order_deleted_at", - "columnNames": [ - "deleted_at" - ], + "keyName": "IDX_order_is_draft_order", + "columnNames": [], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_deleted_at\" ON \"order\" (deleted_at) WHERE deleted_at IS NOT NULL" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_is_draft_order\" ON \"order\" (is_draft_order) WHERE deleted_at IS NOT NULL" }, { "keyName": "order_pkey", @@ -498,62 +520,66 @@ "nullable": false, "mappedType": "text" }, - "title": { - "name": "title", + "return_id": { + "name": "return_id", "type": "text", "unsigned": false, "autoincrement": false, "primary": false, - "nullable": false, + "nullable": true, "mappedType": "text" }, - "subtitle": { - "name": "subtitle", - "type": "text", + "order_version": { + "name": "order_version", + "type": "integer", "unsigned": false, "autoincrement": false, "primary": false, - "nullable": true, - "mappedType": "text" + "nullable": false, + "mappedType": "integer" }, - "thumbnail": { - "name": "thumbnail", - "type": "text", + "display_id": { + "name": "display_id", + "type": "bigserial", "unsigned": false, "autoincrement": false, "primary": false, - "nullable": true, - "mappedType": "text" + "nullable": false, + "mappedType": "bigint" }, - "variant_id": { - "name": "variant_id", + "type": { + "name": "type", "type": "text", "unsigned": false, "autoincrement": false, "primary": false, - "nullable": true, - "mappedType": "text" + "nullable": false, + "enumItems": [ + "refund", + "replace" + ], + "mappedType": "enum" }, - "product_id": { - "name": "product_id", - "type": "text", + "no_notification": { + "name": "no_notification", + "type": "boolean", "unsigned": false, "autoincrement": false, "primary": false, "nullable": true, - "mappedType": "text" + "mappedType": "boolean" }, - "product_title": { - "name": "product_title", - "type": "text", + "refund_amount": { + "name": "refund_amount", + "type": "numeric", "unsigned": false, "autoincrement": false, "primary": false, "nullable": true, - "mappedType": "text" + "mappedType": "decimal" }, - "product_description": { - "name": "product_description", + "created_by": { + "name": "created_by", "type": "text", "unsigned": false, "autoincrement": false, @@ -561,116 +587,202 @@ "nullable": true, "mappedType": "text" }, - "product_subtitle": { - "name": "product_subtitle", - "type": "text", + "canceled_at": { + "name": "canceled_at", + "type": "timestamptz", "unsigned": false, "autoincrement": false, "primary": false, "nullable": true, - "mappedType": "text" + "length": 6, + "mappedType": "datetime" }, - "product_type": { - "name": "product_type", - "type": "text", + "metadata": { + "name": "metadata", + "type": "jsonb", "unsigned": false, "autoincrement": false, "primary": false, "nullable": true, - "mappedType": "text" + "mappedType": "json" }, - "product_type_id": { - "name": "product_type_id", + "order_id": { + "name": "order_id", "type": "text", "unsigned": false, "autoincrement": false, "primary": false, - "nullable": true, + "nullable": false, "mappedType": "text" }, - "product_collection": { - "name": "product_collection", - "type": "text", + "raw_refund_amount": { + "name": "raw_refund_amount", + "type": "jsonb", "unsigned": false, "autoincrement": false, "primary": false, "nullable": true, - "mappedType": "text" + "mappedType": "json" }, - "product_handle": { - "name": "product_handle", - "type": "text", + "created_at": { + "name": "created_at", + "type": "timestamptz", "unsigned": false, "autoincrement": false, "primary": false, - "nullable": true, - "mappedType": "text" + "nullable": false, + "length": 6, + "default": "now()", + "mappedType": "datetime" }, - "variant_sku": { - "name": "variant_sku", - "type": "text", + "updated_at": { + "name": "updated_at", + "type": "timestamptz", "unsigned": false, "autoincrement": false, "primary": false, - "nullable": true, - "mappedType": "text" + "nullable": false, + "length": 6, + "default": "now()", + "mappedType": "datetime" }, - "variant_barcode": { - "name": "variant_barcode", - "type": "text", + "deleted_at": { + "name": "deleted_at", + "type": "timestamptz", "unsigned": false, "autoincrement": false, "primary": false, "nullable": true, - "mappedType": "text" - }, - "variant_title": { - "name": "variant_title", + "length": 6, + "mappedType": "datetime" + } + }, + "name": "order_claim", + "schema": "public", + "indexes": [ + { + "keyName": "IDX_order_claim_order_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_claim_order_id\" ON \"order_claim\" (order_id) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_order_claim_deleted_at", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_claim_deleted_at\" ON \"order_claim\" (deleted_at) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_order_claim_display_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_claim_display_id\" ON \"order_claim\" (display_id) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_claim_deleted_at", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_claim_deleted_at\" ON \"order_claim\" (deleted_at) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_claim_order_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_claim_order_id\" ON \"order_claim\" (order_id) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_claim_return_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_claim_return_id\" ON \"order_claim\" (return_id) WHERE return_id IS NOT NULL AND deleted_at IS NOT NULL" + }, + { + "keyName": "order_claim_pkey", + "columnNames": [ + "id" + ], + "composite": false, + "primary": true, + "unique": true + } + ], + "checks": [], + "foreignKeys": { + "order_claim_order_id_foreign": { + "constraintName": "order_claim_order_id_foreign", + "columnNames": [ + "order_id" + ], + "localTableName": "public.order_claim", + "referencedColumnNames": [ + "id" + ], + "referencedTableName": "public.order", + "updateRule": "cascade" + } + } + }, + { + "columns": { + "id": { + "name": "id", "type": "text", "unsigned": false, "autoincrement": false, "primary": false, - "nullable": true, + "nullable": false, "mappedType": "text" }, - "variant_option_values": { - "name": "variant_option_values", - "type": "jsonb", + "return_id": { + "name": "return_id", + "type": "text", "unsigned": false, "autoincrement": false, "primary": false, "nullable": true, - "mappedType": "json" + "mappedType": "text" }, - "requires_shipping": { - "name": "requires_shipping", - "type": "boolean", + "order_version": { + "name": "order_version", + "type": "integer", "unsigned": false, "autoincrement": false, "primary": false, "nullable": false, - "mappedType": "boolean" + "mappedType": "integer" }, - "is_discountable": { - "name": "is_discountable", - "type": "boolean", + "display_id": { + "name": "display_id", + "type": "bigserial", "unsigned": false, "autoincrement": false, "primary": false, "nullable": false, - "mappedType": "boolean" + "mappedType": "bigint" }, - "is_tax_inclusive": { - "name": "is_tax_inclusive", + "no_notification": { + "name": "no_notification", "type": "boolean", "unsigned": false, "autoincrement": false, "primary": false, - "nullable": false, + "nullable": true, "mappedType": "boolean" }, - "compare_at_unit_price": { - "name": "compare_at_unit_price", + "difference_due": { + "name": "difference_due", "type": "numeric", "unsigned": false, "autoincrement": false, @@ -678,45 +790,55 @@ "nullable": true, "mappedType": "decimal" }, - "raw_compare_at_unit_price": { - "name": "raw_compare_at_unit_price", - "type": "jsonb", + "allow_backorder": { + "name": "allow_backorder", + "type": "boolean", "unsigned": false, "autoincrement": false, "primary": false, - "nullable": true, - "mappedType": "json" + "nullable": false, + "default": "false", + "mappedType": "boolean" }, - "unit_price": { - "name": "unit_price", - "type": "numeric", + "created_by": { + "name": "created_by", + "type": "text", "unsigned": false, "autoincrement": false, "primary": false, "nullable": true, - "mappedType": "decimal" + "mappedType": "text" }, - "raw_unit_price": { - "name": "raw_unit_price", + "metadata": { + "name": "metadata", "type": "jsonb", "unsigned": false, "autoincrement": false, "primary": false, - "nullable": false, + "nullable": true, "mappedType": "json" }, - "is_custom_price": { - "name": "is_custom_price", - "type": "boolean", + "canceled_at": { + "name": "canceled_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 6, + "mappedType": "datetime" + }, + "order_id": { + "name": "order_id", + "type": "text", "unsigned": false, "autoincrement": false, "primary": false, "nullable": false, - "default": "false", - "mappedType": "boolean" + "mappedType": "text" }, - "metadata": { - "name": "metadata", + "raw_difference_due": { + "name": "raw_difference_due", "type": "jsonb", "unsigned": false, "autoincrement": false, @@ -757,51 +879,59 @@ "mappedType": "datetime" } }, - "name": "order_line_item", + "name": "order_exchange", "schema": "public", "indexes": [ { - "keyName": "IDX_order_line_item_variant_id", - "columnNames": [ - "variant_id" - ], + "keyName": "IDX_order_exchange_order_id", + "columnNames": [], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_line_item_variant_id\" ON \"order_line_item\" (variant_id) WHERE deleted_at IS NOT NULL" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_exchange_order_id\" ON \"order_exchange\" (order_id) WHERE deleted_at IS NULL" }, { - "keyName": "IDX_order_line_item_product_id", - "columnNames": [ - "product_id" - ], + "keyName": "IDX_order_exchange_deleted_at", + "columnNames": [], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_line_item_product_id\" ON \"order_line_item\" (product_id) WHERE deleted_at IS NOT NULL" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_exchange_deleted_at\" ON \"order_exchange\" (deleted_at) WHERE deleted_at IS NULL" }, { - "keyName": "IDX_line_item_product_type_id", - "columnNames": [ - "product_type_id" - ], + "keyName": "IDX_order_exchange_display_id", + "columnNames": [], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_line_item_product_type_id\" ON \"order_line_item\" (product_type_id) WHERE deleted_at IS NOT NULL AND product_type_id IS NOT NULL" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_exchange_display_id\" ON \"order_exchange\" (display_id) WHERE deleted_at IS NOT NULL" }, { - "keyName": "IDX_order_line_item_deleted_at", - "columnNames": [ - "deleted_at" - ], + "keyName": "IDX_order_exchange_deleted_at", + "columnNames": [], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_line_item_deleted_at\" ON \"order_line_item\" (deleted_at) WHERE deleted_at IS NOT NULL" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_exchange_deleted_at\" ON \"order_exchange\" (deleted_at) WHERE deleted_at IS NOT NULL" }, { - "keyName": "order_line_item_pkey", + "keyName": "IDX_order_exchange_order_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_exchange_order_id\" ON \"order_exchange\" (order_id) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_exchange_return_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_exchange_return_id\" ON \"order_exchange\" (return_id) WHERE return_id IS NOT NULL AND deleted_at IS NOT NULL" + }, + { + "keyName": "order_exchange_pkey", "columnNames": [ "id" ], @@ -811,7 +941,20 @@ } ], "checks": [], - "foreignKeys": {} + "foreignKeys": { + "order_exchange_order_id_foreign": { + "constraintName": "order_exchange_order_id_foreign", + "columnNames": [ + "order_id" + ], + "localTableName": "public.order_exchange", + "referencedColumnNames": [ + "id" + ], + "referencedTableName": "public.order", + "updateRule": "cascade" + } + } }, { "columns": { @@ -824,8 +967,8 @@ "nullable": false, "mappedType": "text" }, - "order_id": { - "name": "order_id", + "title": { + "name": "title", "type": "text", "unsigned": false, "autoincrement": false, @@ -833,170 +976,182 @@ "nullable": false, "mappedType": "text" }, - "version": { - "name": "version", - "type": "integer", + "subtitle": { + "name": "subtitle", + "type": "text", "unsigned": false, "autoincrement": false, "primary": false, - "nullable": false, - "mappedType": "integer" + "nullable": true, + "mappedType": "text" }, - "item_id": { - "name": "item_id", + "thumbnail": { + "name": "thumbnail", "type": "text", "unsigned": false, "autoincrement": false, "primary": false, - "nullable": false, + "nullable": true, "mappedType": "text" }, - "unit_price": { - "name": "unit_price", - "type": "numeric", + "variant_id": { + "name": "variant_id", + "type": "text", "unsigned": false, "autoincrement": false, "primary": false, "nullable": true, - "mappedType": "decimal" + "mappedType": "text" }, - "raw_unit_price": { - "name": "raw_unit_price", - "type": "jsonb", + "product_id": { + "name": "product_id", + "type": "text", "unsigned": false, "autoincrement": false, "primary": false, "nullable": true, - "mappedType": "json" + "mappedType": "text" }, - "compare_at_unit_price": { - "name": "compare_at_unit_price", - "type": "numeric", + "product_title": { + "name": "product_title", + "type": "text", "unsigned": false, "autoincrement": false, "primary": false, "nullable": true, - "mappedType": "decimal" + "mappedType": "text" }, - "raw_compare_at_unit_price": { - "name": "raw_compare_at_unit_price", - "type": "jsonb", + "product_description": { + "name": "product_description", + "type": "text", "unsigned": false, "autoincrement": false, "primary": false, "nullable": true, - "mappedType": "json" + "mappedType": "text" }, - "quantity": { - "name": "quantity", - "type": "numeric", + "product_subtitle": { + "name": "product_subtitle", + "type": "text", "unsigned": false, "autoincrement": false, "primary": false, - "nullable": false, - "mappedType": "decimal" + "nullable": true, + "mappedType": "text" }, - "raw_quantity": { - "name": "raw_quantity", - "type": "jsonb", + "product_type": { + "name": "product_type", + "type": "text", "unsigned": false, "autoincrement": false, "primary": false, - "nullable": false, - "mappedType": "json" + "nullable": true, + "mappedType": "text" }, - "fulfilled_quantity": { - "name": "fulfilled_quantity", - "type": "numeric", + "product_type_id": { + "name": "product_type_id", + "type": "text", "unsigned": false, "autoincrement": false, "primary": false, - "nullable": false, - "mappedType": "decimal" + "nullable": true, + "mappedType": "text" }, - "raw_fulfilled_quantity": { - "name": "raw_fulfilled_quantity", - "type": "jsonb", + "product_collection": { + "name": "product_collection", + "type": "text", "unsigned": false, "autoincrement": false, "primary": false, - "nullable": false, - "mappedType": "json" + "nullable": true, + "mappedType": "text" }, - "delivered_quantity": { - "name": "delivered_quantity", - "type": "numeric", + "product_handle": { + "name": "product_handle", + "type": "text", "unsigned": false, "autoincrement": false, "primary": false, - "nullable": false, - "mappedType": "decimal" + "nullable": true, + "mappedType": "text" }, - "raw_delivered_quantity": { - "name": "raw_delivered_quantity", - "type": "jsonb", + "variant_sku": { + "name": "variant_sku", + "type": "text", "unsigned": false, "autoincrement": false, "primary": false, - "nullable": false, - "mappedType": "json" + "nullable": true, + "mappedType": "text" }, - "shipped_quantity": { - "name": "shipped_quantity", - "type": "numeric", + "variant_barcode": { + "name": "variant_barcode", + "type": "text", "unsigned": false, "autoincrement": false, "primary": false, - "nullable": false, - "mappedType": "decimal" + "nullable": true, + "mappedType": "text" }, - "raw_shipped_quantity": { - "name": "raw_shipped_quantity", + "variant_title": { + "name": "variant_title", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "variant_option_values": { + "name": "variant_option_values", "type": "jsonb", "unsigned": false, "autoincrement": false, "primary": false, - "nullable": false, + "nullable": true, "mappedType": "json" }, - "return_requested_quantity": { - "name": "return_requested_quantity", - "type": "numeric", + "requires_shipping": { + "name": "requires_shipping", + "type": "boolean", "unsigned": false, "autoincrement": false, "primary": false, "nullable": false, - "mappedType": "decimal" + "default": "true", + "mappedType": "boolean" }, - "raw_return_requested_quantity": { - "name": "raw_return_requested_quantity", - "type": "jsonb", + "is_discountable": { + "name": "is_discountable", + "type": "boolean", "unsigned": false, "autoincrement": false, "primary": false, "nullable": false, - "mappedType": "json" + "default": "true", + "mappedType": "boolean" }, - "return_received_quantity": { - "name": "return_received_quantity", - "type": "numeric", + "is_tax_inclusive": { + "name": "is_tax_inclusive", + "type": "boolean", "unsigned": false, "autoincrement": false, "primary": false, "nullable": false, - "mappedType": "decimal" + "default": "false", + "mappedType": "boolean" }, - "raw_return_received_quantity": { - "name": "raw_return_received_quantity", - "type": "jsonb", + "compare_at_unit_price": { + "name": "compare_at_unit_price", + "type": "numeric", "unsigned": false, "autoincrement": false, "primary": false, - "nullable": false, - "mappedType": "json" + "nullable": true, + "mappedType": "decimal" }, - "return_dismissed_quantity": { - "name": "return_dismissed_quantity", + "unit_price": { + "name": "unit_price", "type": "numeric", "unsigned": false, "autoincrement": false, @@ -1004,40 +1159,41 @@ "nullable": false, "mappedType": "decimal" }, - "raw_return_dismissed_quantity": { - "name": "raw_return_dismissed_quantity", - "type": "jsonb", + "is_custom_price": { + "name": "is_custom_price", + "type": "boolean", "unsigned": false, "autoincrement": false, "primary": false, "nullable": false, - "mappedType": "json" + "default": "false", + "mappedType": "boolean" }, - "written_off_quantity": { - "name": "written_off_quantity", - "type": "numeric", + "metadata": { + "name": "metadata", + "type": "jsonb", "unsigned": false, "autoincrement": false, "primary": false, - "nullable": false, - "mappedType": "decimal" + "nullable": true, + "mappedType": "json" }, - "raw_written_off_quantity": { - "name": "raw_written_off_quantity", + "raw_compare_at_unit_price": { + "name": "raw_compare_at_unit_price", "type": "jsonb", "unsigned": false, "autoincrement": false, "primary": false, - "nullable": false, + "nullable": true, "mappedType": "json" }, - "metadata": { - "name": "metadata", + "raw_unit_price": { + "name": "raw_unit_price", "type": "jsonb", "unsigned": false, "autoincrement": false, "primary": false, - "nullable": true, + "nullable": false, "mappedType": "json" }, "created_at": { @@ -1073,51 +1229,51 @@ "mappedType": "datetime" } }, - "name": "order_item", + "name": "order_line_item", "schema": "public", "indexes": [ { - "keyName": "IDX_order_item_order_id", - "columnNames": [ - "order_id" - ], + "keyName": "IDX_order_line_item_deleted_at", + "columnNames": [], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_item_order_id\" ON \"order_item\" (order_id) WHERE deleted_at IS NOT NULL" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_line_item_deleted_at\" ON \"order_line_item\" (deleted_at) WHERE deleted_at IS NULL" }, { - "keyName": "IDX_order_item_version", - "columnNames": [ - "version" - ], + "keyName": "IDX_order_line_item_deleted_at", + "columnNames": [], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_item_version\" ON \"order_item\" (version) WHERE deleted_at IS NOT NULL" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_line_item_deleted_at\" ON \"order_line_item\" (deleted_at) WHERE deleted_at IS NOT NULL" }, { - "keyName": "IDX_order_item_item_id", - "columnNames": [ - "item_id" - ], + "keyName": "IDX_order_line_item_product_id", + "columnNames": [], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_item_item_id\" ON \"order_item\" (item_id) WHERE deleted_at IS NOT NULL" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_line_item_product_id\" ON \"order_line_item\" (product_id) WHERE deleted_at IS NOT NULL" }, { - "keyName": "IDX_order_item_deleted_at", - "columnNames": [ - "deleted_at" - ], + "keyName": "IDX_line_item_product_type_id", + "columnNames": [], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_item_deleted_at\" ON \"order_item\" (deleted_at) WHERE deleted_at IS NOT NULL" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_line_item_product_type_id\" ON \"order_line_item\" (product_type_id) WHERE deleted_at IS NOT NULL AND product_type_id IS NOT NULL" }, { - "keyName": "order_item_pkey", + "keyName": "IDX_order_line_item_variant_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_line_item_variant_id\" ON \"order_line_item\" (variant_id) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "order_line_item_pkey", "columnNames": [ "id" ], @@ -1127,32 +1283,7 @@ } ], "checks": [], - "foreignKeys": { - "order_item_order_id_foreign": { - "constraintName": "order_item_order_id_foreign", - "columnNames": [ - "order_id" - ], - "localTableName": "public.order_item", - "referencedColumnNames": [ - "id" - ], - "referencedTableName": "public.order", - "updateRule": "cascade" - }, - "order_item_item_id_foreign": { - "constraintName": "order_item_item_id_foreign", - "columnNames": [ - "item_id" - ], - "localTableName": "public.order_item", - "referencedColumnNames": [ - "id" - ], - "referencedTableName": "public.order_line_item", - "updateRule": "cascade" - } - } + "foreignKeys": {} }, { "columns": { @@ -1165,35 +1296,35 @@ "nullable": false, "mappedType": "text" }, - "description": { - "name": "description", - "type": "text", + "version": { + "name": "version", + "type": "integer", "unsigned": false, "autoincrement": false, "primary": false, - "nullable": true, - "mappedType": "text" + "nullable": false, + "mappedType": "integer" }, - "promotion_id": { - "name": "promotion_id", - "type": "text", + "unit_price": { + "name": "unit_price", + "type": "numeric", "unsigned": false, "autoincrement": false, "primary": false, "nullable": true, - "mappedType": "text" + "mappedType": "decimal" }, - "code": { - "name": "code", - "type": "text", + "compare_at_unit_price": { + "name": "compare_at_unit_price", + "type": "numeric", "unsigned": false, "autoincrement": false, "primary": false, "nullable": true, - "mappedType": "text" + "mappedType": "decimal" }, - "amount": { - "name": "amount", + "quantity": { + "name": "quantity", "type": "numeric", "unsigned": false, "autoincrement": false, @@ -1201,110 +1332,96 @@ "nullable": false, "mappedType": "decimal" }, - "raw_amount": { - "name": "raw_amount", - "type": "jsonb", + "fulfilled_quantity": { + "name": "fulfilled_quantity", + "type": "numeric", "unsigned": false, "autoincrement": false, "primary": false, "nullable": false, - "mappedType": "json" + "default": "0", + "mappedType": "decimal" }, - "provider_id": { - "name": "provider_id", - "type": "text", + "delivered_quantity": { + "name": "delivered_quantity", + "type": "numeric", "unsigned": false, "autoincrement": false, "primary": false, - "nullable": true, - "mappedType": "text" + "nullable": false, + "default": "0", + "mappedType": "decimal" }, - "created_at": { - "name": "created_at", - "type": "timestamptz", + "shipped_quantity": { + "name": "shipped_quantity", + "type": "numeric", "unsigned": false, "autoincrement": false, "primary": false, "nullable": false, - "length": 6, - "default": "now()", - "mappedType": "datetime" + "default": "0", + "mappedType": "decimal" }, - "updated_at": { - "name": "updated_at", - "type": "timestamptz", + "return_requested_quantity": { + "name": "return_requested_quantity", + "type": "numeric", "unsigned": false, "autoincrement": false, "primary": false, "nullable": false, - "length": 6, - "default": "now()", - "mappedType": "datetime" + "default": "0", + "mappedType": "decimal" }, - "deleted_at": { - "name": "deleted_at", - "type": "timestamptz", + "return_received_quantity": { + "name": "return_received_quantity", + "type": "numeric", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "default": "0", + "mappedType": "decimal" + }, + "return_dismissed_quantity": { + "name": "return_dismissed_quantity", + "type": "numeric", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "default": "0", + "mappedType": "decimal" + }, + "written_off_quantity": { + "name": "written_off_quantity", + "type": "numeric", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "default": "0", + "mappedType": "decimal" + }, + "metadata": { + "name": "metadata", + "type": "jsonb", "unsigned": false, "autoincrement": false, "primary": false, "nullable": true, - "length": 6, - "mappedType": "datetime" + "mappedType": "json" }, - "item_id": { - "name": "item_id", + "order_id": { + "name": "order_id", "type": "text", "unsigned": false, "autoincrement": false, "primary": false, "nullable": false, "mappedType": "text" - } - }, - "name": "order_line_item_adjustment", - "schema": "public", - "indexes": [ - { - "keyName": "IDX_order_line_item_adjustment_item_id", - "columnNames": [ - "item_id" - ], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_line_item_adjustment_item_id\" ON \"order_line_item_adjustment\" (item_id)" }, - { - "keyName": "order_line_item_adjustment_pkey", - "columnNames": [ - "id" - ], - "composite": false, - "primary": true, - "unique": true - } - ], - "checks": [], - "foreignKeys": { - "order_line_item_adjustment_item_id_foreign": { - "constraintName": "order_line_item_adjustment_item_id_foreign", - "columnNames": [ - "item_id" - ], - "localTableName": "public.order_line_item_adjustment", - "referencedColumnNames": [ - "id" - ], - "referencedTableName": "public.order_line_item", - "deleteRule": "cascade", - "updateRule": "cascade" - } - } - }, - { - "columns": { - "id": { - "name": "id", + "item_id": { + "name": "item_id", "type": "text", "unsigned": false, "autoincrement": false, @@ -1312,44 +1429,44 @@ "nullable": false, "mappedType": "text" }, - "description": { - "name": "description", - "type": "text", + "raw_unit_price": { + "name": "raw_unit_price", + "type": "jsonb", "unsigned": false, "autoincrement": false, "primary": false, "nullable": true, - "mappedType": "text" + "mappedType": "json" }, - "tax_rate_id": { - "name": "tax_rate_id", - "type": "text", + "raw_compare_at_unit_price": { + "name": "raw_compare_at_unit_price", + "type": "jsonb", "unsigned": false, "autoincrement": false, "primary": false, "nullable": true, - "mappedType": "text" + "mappedType": "json" }, - "code": { - "name": "code", - "type": "text", + "raw_quantity": { + "name": "raw_quantity", + "type": "jsonb", "unsigned": false, "autoincrement": false, "primary": false, "nullable": false, - "mappedType": "text" + "mappedType": "json" }, - "rate": { - "name": "rate", - "type": "numeric", + "raw_fulfilled_quantity": { + "name": "raw_fulfilled_quantity", + "type": "jsonb", "unsigned": false, "autoincrement": false, "primary": false, "nullable": false, - "mappedType": "decimal" + "mappedType": "json" }, - "raw_rate": { - "name": "raw_rate", + "raw_delivered_quantity": { + "name": "raw_delivered_quantity", "type": "jsonb", "unsigned": false, "autoincrement": false, @@ -1357,14 +1474,50 @@ "nullable": false, "mappedType": "json" }, - "provider_id": { - "name": "provider_id", - "type": "text", + "raw_shipped_quantity": { + "name": "raw_shipped_quantity", + "type": "jsonb", "unsigned": false, "autoincrement": false, "primary": false, - "nullable": true, - "mappedType": "text" + "nullable": false, + "mappedType": "json" + }, + "raw_return_requested_quantity": { + "name": "raw_return_requested_quantity", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "json" + }, + "raw_return_received_quantity": { + "name": "raw_return_received_quantity", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "json" + }, + "raw_return_dismissed_quantity": { + "name": "raw_return_dismissed_quantity", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "json" + }, + "raw_written_off_quantity": { + "name": "raw_written_off_quantity", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "json" }, "created_at": { "name": "created_at", @@ -1397,53 +1550,101 @@ "nullable": true, "length": 6, "mappedType": "datetime" - }, - "item_id": { - "name": "item_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" } }, - "name": "order_line_item_tax_line", + "name": "order_item", "schema": "public", "indexes": [ { - "keyName": "IDX_order_line_item_tax_line_item_id", - "columnNames": [ - "item_id" - ], + "keyName": "IDX_order_item_order_id", + "columnNames": [], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_line_item_tax_line_item_id\" ON \"order_line_item_tax_line\" (item_id)" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_item_order_id\" ON \"order_item\" (order_id) WHERE deleted_at IS NULL" }, { - "keyName": "order_line_item_tax_line_pkey", - "columnNames": [ - "id" - ], + "keyName": "IDX_order_item_item_id", + "columnNames": [], "composite": false, - "primary": true, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_item_item_id\" ON \"order_item\" (item_id) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_order_item_deleted_at", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_item_deleted_at\" ON \"order_item\" (deleted_at) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_order_item_order_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_item_order_id\" ON \"order_item\" (order_id) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_item_version", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_item_version\" ON \"order_item\" (version) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_item_item_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_item_item_id\" ON \"order_item\" (item_id) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_item_deleted_at", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_item_deleted_at\" ON \"order_item\" (deleted_at) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "order_item_pkey", + "columnNames": [ + "id" + ], + "composite": false, + "primary": true, "unique": true } ], "checks": [], "foreignKeys": { - "order_line_item_tax_line_item_id_foreign": { - "constraintName": "order_line_item_tax_line_item_id_foreign", + "order_item_order_id_foreign": { + "constraintName": "order_item_order_id_foreign", + "columnNames": [ + "order_id" + ], + "localTableName": "public.order_item", + "referencedColumnNames": [ + "id" + ], + "referencedTableName": "public.order", + "updateRule": "cascade" + }, + "order_item_item_id_foreign": { + "constraintName": "order_item_item_id_foreign", "columnNames": [ "item_id" ], - "localTableName": "public.order_line_item_tax_line", + "localTableName": "public.order_item", "referencedColumnNames": [ "id" ], "referencedTableName": "public.order_line_item", - "deleteRule": "cascade", "updateRule": "cascade" } } @@ -1459,87 +1660,58 @@ "nullable": false, "mappedType": "text" }, - "name": { - "name": "name", - "type": "text", + "quantity": { + "name": "quantity", + "type": "numeric", "unsigned": false, "autoincrement": false, "primary": false, "nullable": false, - "mappedType": "text" + "mappedType": "decimal" }, - "description": { - "name": "description", - "type": "jsonb", + "note": { + "name": "note", + "type": "text", "unsigned": false, "autoincrement": false, "primary": false, "nullable": true, - "mappedType": "json" - }, - "amount": { - "name": "amount", - "type": "numeric", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "decimal" + "mappedType": "text" }, - "raw_amount": { - "name": "raw_amount", + "metadata": { + "name": "metadata", "type": "jsonb", "unsigned": false, "autoincrement": false, "primary": false, - "nullable": false, + "nullable": true, "mappedType": "json" }, - "is_tax_inclusive": { - "name": "is_tax_inclusive", - "type": "boolean", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "default": "false", - "mappedType": "boolean" - }, - "is_custom_amount": { - "name": "is_custom_amount", - "type": "boolean", + "exchange_id": { + "name": "exchange_id", + "type": "text", "unsigned": false, "autoincrement": false, "primary": false, "nullable": false, - "default": "false", - "mappedType": "boolean" + "mappedType": "text" }, - "shipping_option_id": { - "name": "shipping_option_id", + "item_id": { + "name": "item_id", "type": "text", "unsigned": false, "autoincrement": false, "primary": false, - "nullable": true, + "nullable": false, "mappedType": "text" }, - "data": { - "name": "data", - "type": "jsonb", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "json" - }, - "metadata": { - "name": "metadata", + "raw_quantity": { + "name": "raw_quantity", "type": "jsonb", "unsigned": false, "autoincrement": false, "primary": false, - "nullable": true, + "nullable": false, "mappedType": "json" }, "created_at": { @@ -1575,31 +1747,59 @@ "mappedType": "datetime" } }, - "name": "order_shipping_method", + "name": "order_exchange_item", "schema": "public", "indexes": [ { - "keyName": "IDX_order_shipping_method_shipping_option_id", - "columnNames": [ - "shipping_option_id" - ], + "keyName": "IDX_order_exchange_item_exchange_id", + "columnNames": [], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_method_shipping_option_id\" ON \"order_shipping_method\" (shipping_option_id) WHERE deleted_at IS NOT NULL" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_exchange_item_exchange_id\" ON \"order_exchange_item\" (exchange_id) WHERE deleted_at IS NULL" }, { - "keyName": "IDX_order_shipping_method_deleted_at", - "columnNames": [ - "deleted_at" - ], + "keyName": "IDX_order_exchange_item_item_id", + "columnNames": [], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_method_deleted_at\" ON \"order_shipping_method\" (deleted_at) WHERE deleted_at IS NOT NULL" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_exchange_item_item_id\" ON \"order_exchange_item\" (item_id) WHERE deleted_at IS NULL" }, { - "keyName": "order_shipping_method_pkey", + "keyName": "IDX_order_exchange_item_deleted_at", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_exchange_item_deleted_at\" ON \"order_exchange_item\" (deleted_at) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_order_exchange_item_exchange_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_exchange_item_exchange_id\" ON \"order_exchange_item\" (exchange_id) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_exchange_item_item_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_exchange_item_item_id\" ON \"order_exchange_item\" (item_id) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_exchange_item_deleted_at", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_exchange_item_deleted_at\" ON \"order_exchange_item\" (deleted_at) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "order_exchange_item_pkey", "columnNames": [ "id" ], @@ -1609,7 +1809,32 @@ } ], "checks": [], - "foreignKeys": {} + "foreignKeys": { + "order_exchange_item_exchange_id_foreign": { + "constraintName": "order_exchange_item_exchange_id_foreign", + "columnNames": [ + "exchange_id" + ], + "localTableName": "public.order_exchange_item", + "referencedColumnNames": [ + "id" + ], + "referencedTableName": "public.order_exchange", + "updateRule": "cascade" + }, + "order_exchange_item_item_id_foreign": { + "constraintName": "order_exchange_item_item_id_foreign", + "columnNames": [ + "item_id" + ], + "localTableName": "public.order_exchange_item", + "referencedColumnNames": [ + "id" + ], + "referencedTableName": "public.order_line_item", + "updateRule": "cascade" + } + } }, { "columns": { @@ -1622,35 +1847,23 @@ "nullable": false, "mappedType": "text" }, - "description": { - "name": "description", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "promotion_id": { - "name": "promotion_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "code": { - "name": "code", + "reason": { + "name": "reason", "type": "text", "unsigned": false, "autoincrement": false, "primary": false, "nullable": true, - "mappedType": "text" + "enumItems": [ + "missing_item", + "wrong_item", + "production_failure", + "other" + ], + "mappedType": "enum" }, - "amount": { - "name": "amount", + "quantity": { + "name": "quantity", "type": "numeric", "unsigned": false, "autoincrement": false, @@ -1658,17 +1871,18 @@ "nullable": false, "mappedType": "decimal" }, - "raw_amount": { - "name": "raw_amount", - "type": "jsonb", + "is_additional_item": { + "name": "is_additional_item", + "type": "boolean", "unsigned": false, "autoincrement": false, "primary": false, "nullable": false, - "mappedType": "json" + "default": "false", + "mappedType": "boolean" }, - "provider_id": { - "name": "provider_id", + "note": { + "name": "note", "type": "text", "unsigned": false, "autoincrement": false, @@ -1676,8 +1890,44 @@ "nullable": true, "mappedType": "text" }, - "created_at": { - "name": "created_at", + "metadata": { + "name": "metadata", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "json" + }, + "claim_id": { + "name": "claim_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "item_id": { + "name": "item_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "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", "unsigned": false, "autoincrement": false, @@ -1707,32 +1957,61 @@ "nullable": true, "length": 6, "mappedType": "datetime" - }, - "shipping_method_id": { - "name": "shipping_method_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "text" } }, - "name": "order_shipping_method_adjustment", + "name": "order_claim_item", "schema": "public", "indexes": [ { - "keyName": "IDX_order_shipping_method_adjustment_shipping_method_id", - "columnNames": [ - "shipping_method_id" - ], + "keyName": "IDX_order_claim_item_claim_id", + "columnNames": [], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_method_adjustment_shipping_method_id\" ON \"order_shipping_method_adjustment\" (shipping_method_id)" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_claim_item_claim_id\" ON \"order_claim_item\" (claim_id) WHERE deleted_at IS NULL" }, { - "keyName": "order_shipping_method_adjustment_pkey", + "keyName": "IDX_order_claim_item_item_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_claim_item_item_id\" ON \"order_claim_item\" (item_id) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_order_claim_item_deleted_at", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_claim_item_deleted_at\" ON \"order_claim_item\" (deleted_at) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_order_claim_item_claim_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_claim_item_claim_id\" ON \"order_claim_item\" (claim_id) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_claim_item_item_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_claim_item_item_id\" ON \"order_claim_item\" (item_id) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_claim_item_deleted_at", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_claim_item_deleted_at\" ON \"order_claim_item\" (deleted_at) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "order_claim_item_pkey", "columnNames": [ "id" ], @@ -1743,17 +2022,28 @@ ], "checks": [], "foreignKeys": { - "order_shipping_method_adjustment_shipping_method_id_foreign": { - "constraintName": "order_shipping_method_adjustment_shipping_method_id_foreign", + "order_claim_item_claim_id_foreign": { + "constraintName": "order_claim_item_claim_id_foreign", "columnNames": [ - "shipping_method_id" + "claim_id" ], - "localTableName": "public.order_shipping_method_adjustment", + "localTableName": "public.order_claim_item", "referencedColumnNames": [ "id" ], - "referencedTableName": "public.order_shipping_method", - "deleteRule": "cascade", + "referencedTableName": "public.order_claim", + "updateRule": "cascade" + }, + "order_claim_item_item_id_foreign": { + "constraintName": "order_claim_item_item_id_foreign", + "columnNames": [ + "item_id" + ], + "localTableName": "public.order_claim_item", + "referencedColumnNames": [ + "id" + ], + "referencedTableName": "public.order_line_item", "updateRule": "cascade" } } @@ -1769,26 +2059,17 @@ "nullable": false, "mappedType": "text" }, - "description": { - "name": "description", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "tax_rate_id": { - "name": "tax_rate_id", + "claim_item_id": { + "name": "claim_item_id", "type": "text", "unsigned": false, "autoincrement": false, "primary": false, - "nullable": true, + "nullable": false, "mappedType": "text" }, - "code": { - "name": "code", + "url": { + "name": "url", "type": "text", "unsigned": false, "autoincrement": false, @@ -1796,32 +2077,14 @@ "nullable": false, "mappedType": "text" }, - "rate": { - "name": "rate", - "type": "numeric", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "decimal" - }, - "raw_rate": { - "name": "raw_rate", + "metadata": { + "name": "metadata", "type": "jsonb", "unsigned": false, "autoincrement": false, "primary": false, - "nullable": false, - "mappedType": "json" - }, - "provider_id": { - "name": "provider_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, "nullable": true, - "mappedType": "text" + "mappedType": "json" }, "created_at": { "name": "created_at", @@ -1854,32 +2117,45 @@ "nullable": true, "length": 6, "mappedType": "datetime" - }, - "shipping_method_id": { - "name": "shipping_method_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "text" } }, - "name": "order_shipping_method_tax_line", + "name": "order_claim_item_image", "schema": "public", "indexes": [ { - "keyName": "IDX_order_shipping_method_tax_line_shipping_method_id", - "columnNames": [ - "shipping_method_id" - ], + "keyName": "IDX_order_claim_item_image_claim_item_id", + "columnNames": [], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_method_tax_line_shipping_method_id\" ON \"order_shipping_method_tax_line\" (shipping_method_id)" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_claim_item_image_claim_item_id\" ON \"order_claim_item_image\" (claim_item_id) WHERE deleted_at IS NULL" }, { - "keyName": "order_shipping_method_tax_line_pkey", + "keyName": "IDX_order_claim_item_image_deleted_at", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_claim_item_image_deleted_at\" ON \"order_claim_item_image\" (deleted_at) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_order_claim_item_image_deleted_at", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_claim_item_image_deleted_at\" ON \"order_claim_item_image\" (deleted_at) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_claim_item_image_claim_item_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_claim_item_image_claim_item_id\" ON \"order_claim_item_image\" (claim_item_id) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "order_claim_item_image_pkey", "columnNames": [ "id" ], @@ -1890,17 +2166,16 @@ ], "checks": [], "foreignKeys": { - "order_shipping_method_tax_line_shipping_method_id_foreign": { - "constraintName": "order_shipping_method_tax_line_shipping_method_id_foreign", + "order_claim_item_image_claim_item_id_foreign": { + "constraintName": "order_claim_item_image_claim_item_id_foreign", "columnNames": [ - "shipping_method_id" + "claim_item_id" ], - "localTableName": "public.order_shipping_method_tax_line", + "localTableName": "public.order_claim_item_image", "referencedColumnNames": [ "id" ], - "referencedTableName": "public.order_shipping_method", - "deleteRule": "cascade", + "referencedTableName": "public.order_claim_item", "updateRule": "cascade" } } @@ -1916,52 +2191,87 @@ "nullable": false, "mappedType": "text" }, - "order_id": { - "name": "order_id", + "description": { + "name": "description", "type": "text", "unsigned": false, "autoincrement": false, "primary": false, - "nullable": false, + "nullable": true, "mappedType": "text" }, - "version": { - "name": "version", - "type": "integer", + "promotion_id": { + "name": "promotion_id", + "type": "text", "unsigned": false, "autoincrement": false, "primary": false, - "nullable": false, - "default": "1", - "mappedType": "integer" + "nullable": true, + "mappedType": "text" }, - "totals": { - "name": "totals", - "type": "jsonb", + "code": { + "name": "code", + "type": "text", "unsigned": false, "autoincrement": false, "primary": false, - "nullable": false, - "mappedType": "json" + "nullable": true, + "mappedType": "text" }, - "created_at": { - "name": "created_at", - "type": "timestamptz", + "amount": { + "name": "amount", + "type": "numeric", "unsigned": false, "autoincrement": false, "primary": false, "nullable": false, - "length": 6, - "default": "now()", - "mappedType": "datetime" + "mappedType": "decimal" }, - "updated_at": { - "name": "updated_at", - "type": "timestamptz", + "provider_id": { + "name": "provider_id", + "type": "text", "unsigned": false, "autoincrement": false, "primary": false, - "nullable": false, + "nullable": true, + "mappedType": "text" + }, + "item_id": { + "name": "item_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "raw_amount": { + "name": "raw_amount", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "json" + }, + "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" @@ -1977,29 +2287,35 @@ "mappedType": "datetime" } }, - "name": "order_summary", + "name": "order_line_item_adjustment", "schema": "public", "indexes": [ { - "keyName": "IDX_order_summary_deleted_at", - "columnNames": [ - "deleted_at" - ], + "keyName": "IDX_order_line_item_adjustment_item_id", + "columnNames": [], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_summary_deleted_at\" ON \"order_summary\" (deleted_at) WHERE deleted_at IS NOT NULL" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_line_item_adjustment_item_id\" ON \"order_line_item_adjustment\" (item_id) WHERE deleted_at IS NULL" }, { - "keyName": "IDX_order_summary_order_id_version", + "keyName": "IDX_order_line_item_adjustment_deleted_at", "columnNames": [], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_summary_order_id_version\" ON \"order_summary\" (order_id, version) WHERE deleted_at IS NOT NULL" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_line_item_adjustment_deleted_at\" ON \"order_line_item_adjustment\" (deleted_at) WHERE deleted_at IS NULL" }, { - "keyName": "order_summary_pkey", + "keyName": "ItemIdIndex", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"ItemIdIndex\" ON \"order_line_item_adjustment\" (item_id) WHERE deleted_at IS NULL" + }, + { + "keyName": "order_line_item_adjustment_pkey", "columnNames": [ "id" ], @@ -2010,17 +2326,16 @@ ], "checks": [], "foreignKeys": { - "order_summary_order_id_foreign": { - "constraintName": "order_summary_order_id_foreign", + "order_line_item_adjustment_item_id_foreign": { + "constraintName": "order_line_item_adjustment_item_id_foreign", "columnNames": [ - "order_id" + "item_id" ], - "localTableName": "public.order_summary", + "localTableName": "public.order_line_item_adjustment", "referencedColumnNames": [ "id" ], - "referencedTableName": "public.order", - "deleteRule": "cascade", + "referencedTableName": "public.order_line_item", "updateRule": "cascade" } } @@ -2036,17 +2351,8 @@ "nullable": false, "mappedType": "text" }, - "order_id": { - "name": "order_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "text" - }, - "exchange_id": { - "name": "exchange_id", + "description": { + "name": "description", "type": "text", "unsigned": false, "autoincrement": false, @@ -2054,8 +2360,8 @@ "nullable": true, "mappedType": "text" }, - "claim_id": { - "name": "claim_id", + "tax_rate_id": { + "name": "tax_rate_id", "type": "text", "unsigned": false, "autoincrement": false, @@ -2063,93 +2369,49 @@ "nullable": true, "mappedType": "text" }, - "order_version": { - "name": "order_version", - "type": "integer", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "integer" - }, - "display_id": { - "name": "display_id", - "type": "serial", - "unsigned": true, - "autoincrement": true, - "primary": false, - "nullable": false, - "mappedType": "integer" - }, - "status": { - "name": "status", + "code": { + "name": "code", "type": "text", "unsigned": false, "autoincrement": false, "primary": false, "nullable": false, - "default": "'open'", - "enumItems": [ - "open", - "requested", - "received", - "partially_received", - "canceled" - ], - "mappedType": "enum" - }, - "location_id": { - "name": "location_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, "mappedType": "text" }, - "no_notification": { - "name": "no_notification", - "type": "boolean", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "boolean" - }, - "refund_amount": { - "name": "refund_amount", + "rate": { + "name": "rate", "type": "numeric", "unsigned": false, "autoincrement": false, "primary": false, - "nullable": true, + "nullable": false, "mappedType": "decimal" }, - "raw_refund_amount": { - "name": "raw_refund_amount", - "type": "jsonb", + "provider_id": { + "name": "provider_id", + "type": "text", "unsigned": false, "autoincrement": false, "primary": false, "nullable": true, - "mappedType": "json" + "mappedType": "text" }, - "created_by": { - "name": "created_by", + "item_id": { + "name": "item_id", "type": "text", "unsigned": false, "autoincrement": false, "primary": false, - "nullable": true, + "nullable": false, "mappedType": "text" }, - "metadata": { - "name": "metadata", + "raw_rate": { + "name": "raw_rate", "type": "jsonb", "unsigned": false, "autoincrement": false, "primary": false, - "nullable": true, + "nullable": false, "mappedType": "json" }, "created_at": { @@ -2183,111 +2445,37 @@ "nullable": true, "length": 6, "mappedType": "datetime" - }, - "requested_at": { - "name": "requested_at", - "type": "timestamptz", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "length": 6, - "mappedType": "datetime" - }, - "received_at": { - "name": "received_at", - "type": "timestamptz", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "length": 6, - "mappedType": "datetime" - }, - "canceled_at": { - "name": "canceled_at", - "type": "timestamptz", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "length": 6, - "mappedType": "datetime" } }, - "name": "return", + "name": "order_line_item_tax_line", "schema": "public", "indexes": [ { - "columnNames": [ - "exchange_id" - ], - "composite": false, - "keyName": "return_exchange_id_unique", - "primary": false, - "unique": true - }, - { - "columnNames": [ - "claim_id" - ], - "composite": false, - "keyName": "return_claim_id_unique", - "primary": false, - "unique": true - }, - { - "keyName": "IDX_return_order_id", - "columnNames": [ - "order_id" - ], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_order_id\" ON \"return\" (order_id) WHERE deleted_at IS NOT NULL" - }, - { - "keyName": "IDX_return_exchange_id", - "columnNames": [ - "exchange_id" - ], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_exchange_id\" ON \"return\" (exchange_id) WHERE exchange_id IS NOT NULL AND deleted_at IS NOT NULL" - }, - { - "keyName": "IDX_return_claim_id", - "columnNames": [ - "claim_id" - ], + "keyName": "IDX_order_line_item_tax_line_item_id", + "columnNames": [], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_claim_id\" ON \"return\" (claim_id) WHERE claim_id IS NOT NULL AND deleted_at IS NOT NULL" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_line_item_tax_line_item_id\" ON \"order_line_item_tax_line\" (item_id) WHERE deleted_at IS NULL" }, { - "keyName": "IDX_return_display_id", - "columnNames": [ - "display_id" - ], + "keyName": "IDX_order_line_item_tax_line_deleted_at", + "columnNames": [], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_display_id\" ON \"return\" (display_id) WHERE deleted_at IS NOT NULL" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_line_item_tax_line_deleted_at\" ON \"order_line_item_tax_line\" (deleted_at) WHERE deleted_at IS NULL" }, { - "keyName": "IDX_return_deleted_at", - "columnNames": [ - "deleted_at" - ], + "keyName": "ItemIdIndex", + "columnNames": [], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_deleted_at\" ON \"return\" (deleted_at) WHERE deleted_at IS NOT NULL" + "expression": "CREATE INDEX IF NOT EXISTS \"ItemIdIndex\" ON \"order_line_item_tax_line\" (item_id) WHERE deleted_at IS NULL" }, { - "keyName": "return_pkey", + "keyName": "order_line_item_tax_line_pkey", "columnNames": [ "id" ], @@ -2298,42 +2486,16 @@ ], "checks": [], "foreignKeys": { - "return_order_id_foreign": { - "constraintName": "return_order_id_foreign", - "columnNames": [ - "order_id" - ], - "localTableName": "public.return", - "referencedColumnNames": [ - "id" - ], - "referencedTableName": "public.order", - "updateRule": "cascade" - }, - "return_exchange_id_foreign": { - "constraintName": "return_exchange_id_foreign", - "columnNames": [ - "exchange_id" - ], - "localTableName": "public.return", - "referencedColumnNames": [ - "id" - ], - "referencedTableName": "public.order_exchange", - "deleteRule": "set null", - "updateRule": "cascade" - }, - "return_claim_id_foreign": { - "constraintName": "return_claim_id_foreign", + "order_line_item_tax_line_item_id_foreign": { + "constraintName": "order_line_item_tax_line_item_id_foreign", "columnNames": [ - "claim_id" + "item_id" ], - "localTableName": "public.return", + "localTableName": "public.order_line_item_tax_line", "referencedColumnNames": [ "id" ], - "referencedTableName": "public.order_claim", - "deleteRule": "set null", + "referencedTableName": "public.order_line_item", "updateRule": "cascade" } } @@ -2349,8 +2511,8 @@ "nullable": false, "mappedType": "text" }, - "order_id": { - "name": "order_id", + "name": { + "name": "name", "type": "text", "unsigned": false, "autoincrement": false, @@ -2358,53 +2520,53 @@ "nullable": false, "mappedType": "text" }, - "return_id": { - "name": "return_id", - "type": "text", + "description": { + "name": "description", + "type": "jsonb", "unsigned": false, "autoincrement": false, "primary": false, "nullable": true, - "mappedType": "text" + "mappedType": "json" }, - "order_version": { - "name": "order_version", - "type": "integer", + "amount": { + "name": "amount", + "type": "numeric", "unsigned": false, "autoincrement": false, "primary": false, "nullable": false, - "mappedType": "integer" + "mappedType": "decimal" }, - "display_id": { - "name": "display_id", - "type": "serial", - "unsigned": true, - "autoincrement": true, + "is_tax_inclusive": { + "name": "is_tax_inclusive", + "type": "boolean", + "unsigned": false, + "autoincrement": false, "primary": false, "nullable": false, - "mappedType": "integer" + "mappedType": "boolean" }, - "no_notification": { - "name": "no_notification", + "is_custom_amount": { + "name": "is_custom_amount", "type": "boolean", "unsigned": false, "autoincrement": false, "primary": false, - "nullable": true, + "nullable": false, "mappedType": "boolean" }, - "difference_due": { - "name": "difference_due", - "type": "numeric", + "shipping_option_id": { + "name": "shipping_option_id", + "type": "text", "unsigned": false, "autoincrement": false, "primary": false, "nullable": true, - "mappedType": "decimal" + "mappedType": "text" }, - "raw_difference_due": { - "name": "raw_difference_due", + "data": { + "name": "data", "type": "jsonb", "unsigned": false, "autoincrement": false, @@ -2412,18 +2574,138 @@ "nullable": true, "mappedType": "json" }, - "allow_backorder": { - "name": "allow_backorder", - "type": "boolean", + "metadata": { + "name": "metadata", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "json" + }, + "raw_amount": { + "name": "raw_amount", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "json" + }, + "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": "order_shipping_method", + "schema": "public", + "indexes": [ + { + "keyName": "IDX_order_shipping_method_deleted_at", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_method_deleted_at\" ON \"order_shipping_method\" (deleted_at) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_order_shipping_method_shipping_option_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_method_shipping_option_id\" ON \"order_shipping_method\" (shipping_option_id) WHERE deleted_at IS NULL" + }, + { + "keyName": "order_shipping_method_pkey", + "columnNames": [ + "id" + ], + "composite": false, + "primary": true, + "unique": true + } + ], + "checks": [], + "foreignKeys": {} + }, + { + "columns": { + "id": { + "name": "id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "description": { + "name": "description", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "promotion_id": { + "name": "promotion_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "code": { + "name": "code", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "amount": { + "name": "amount", + "type": "numeric", "unsigned": false, "autoincrement": false, "primary": false, "nullable": false, - "default": "false", - "mappedType": "boolean" + "mappedType": "decimal" }, - "created_by": { - "name": "created_by", + "provider_id": { + "name": "provider_id", "type": "text", "unsigned": false, "autoincrement": false, @@ -2431,13 +2713,22 @@ "nullable": true, "mappedType": "text" }, - "metadata": { - "name": "metadata", + "shipping_method_id": { + "name": "shipping_method_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "raw_amount": { + "name": "raw_amount", "type": "jsonb", "unsigned": false, "autoincrement": false, "primary": false, - "nullable": true, + "nullable": false, "mappedType": "json" }, "created_at": { @@ -2471,72 +2762,29 @@ "nullable": true, "length": 6, "mappedType": "datetime" - }, - "canceled_at": { - "name": "canceled_at", - "type": "timestamptz", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "length": 6, - "mappedType": "datetime" } }, - "name": "order_exchange", + "name": "order_shipping_method_adjustment", "schema": "public", "indexes": [ { - "columnNames": [ - "return_id" - ], - "composite": false, - "keyName": "order_exchange_return_id_unique", - "primary": false, - "unique": true - }, - { - "keyName": "IDX_order_exchange_order_id", - "columnNames": [ - "order_id" - ], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_exchange_order_id\" ON \"order_exchange\" (order_id) WHERE deleted_at IS NOT NULL" - }, - { - "keyName": "IDX_order_exchange_return_id", - "columnNames": [ - "return_id" - ], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_exchange_return_id\" ON \"order_exchange\" (return_id) WHERE return_id IS NOT NULL AND deleted_at IS NOT NULL" - }, - { - "keyName": "IDX_order_exchange_display_id", - "columnNames": [ - "display_id" - ], + "keyName": "IDX_order_shipping_method_adjustment_shipping_method_id", + "columnNames": [], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_exchange_display_id\" ON \"order_exchange\" (display_id) WHERE deleted_at IS NOT NULL" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_method_adjustment_shipping_method_id\" ON \"order_shipping_method_adjustment\" (shipping_method_id) WHERE deleted_at IS NULL" }, { - "keyName": "IDX_order_exchange_deleted_at", - "columnNames": [ - "deleted_at" - ], + "keyName": "IDX_order_shipping_method_adjustment_deleted_at", + "columnNames": [], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_exchange_deleted_at\" ON \"order_exchange\" (deleted_at) WHERE deleted_at IS NOT NULL" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_method_adjustment_deleted_at\" ON \"order_shipping_method_adjustment\" (deleted_at) WHERE deleted_at IS NULL" }, { - "keyName": "order_exchange_pkey", + "keyName": "order_shipping_method_adjustment_pkey", "columnNames": [ "id" ], @@ -2547,29 +2795,16 @@ ], "checks": [], "foreignKeys": { - "order_exchange_order_id_foreign": { - "constraintName": "order_exchange_order_id_foreign", - "columnNames": [ - "order_id" - ], - "localTableName": "public.order_exchange", - "referencedColumnNames": [ - "id" - ], - "referencedTableName": "public.order", - "updateRule": "cascade" - }, - "order_exchange_return_id_foreign": { - "constraintName": "order_exchange_return_id_foreign", + "order_shipping_method_adjustment_shipping_method_id_foreign": { + "constraintName": "order_shipping_method_adjustment_shipping_method_id_foreign", "columnNames": [ - "return_id" + "shipping_method_id" ], - "localTableName": "public.order_exchange", + "localTableName": "public.order_shipping_method_adjustment", "referencedColumnNames": [ "id" ], - "referencedTableName": "public.return", - "deleteRule": "set null", + "referencedTableName": "public.order_shipping_method", "updateRule": "cascade" } } @@ -2585,26 +2820,26 @@ "nullable": false, "mappedType": "text" }, - "quantity": { - "name": "quantity", - "type": "numeric", + "description": { + "name": "description", + "type": "text", "unsigned": false, "autoincrement": false, "primary": false, - "nullable": false, - "mappedType": "decimal" + "nullable": true, + "mappedType": "text" }, - "raw_quantity": { - "name": "raw_quantity", - "type": "jsonb", + "tax_rate_id": { + "name": "tax_rate_id", + "type": "text", "unsigned": false, "autoincrement": false, "primary": false, - "nullable": false, - "mappedType": "json" + "nullable": true, + "mappedType": "text" }, - "exchange_id": { - "name": "exchange_id", + "code": { + "name": "code", "type": "text", "unsigned": false, "autoincrement": false, @@ -2612,17 +2847,17 @@ "nullable": false, "mappedType": "text" }, - "item_id": { - "name": "item_id", - "type": "text", + "rate": { + "name": "rate", + "type": "numeric", "unsigned": false, "autoincrement": false, "primary": false, "nullable": false, - "mappedType": "text" + "mappedType": "decimal" }, - "note": { - "name": "note", + "provider_id": { + "name": "provider_id", "type": "text", "unsigned": false, "autoincrement": false, @@ -2630,13 +2865,22 @@ "nullable": true, "mappedType": "text" }, - "metadata": { - "name": "metadata", + "shipping_method_id": { + "name": "shipping_method_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "raw_rate": { + "name": "raw_rate", "type": "jsonb", "unsigned": false, "autoincrement": false, "primary": false, - "nullable": true, + "nullable": false, "mappedType": "json" }, "created_at": { @@ -2672,41 +2916,27 @@ "mappedType": "datetime" } }, - "name": "order_exchange_item", + "name": "order_shipping_method_tax_line", "schema": "public", "indexes": [ { - "keyName": "IDX_order_exchange_item_exchange_id", - "columnNames": [ - "exchange_id" - ], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_exchange_item_exchange_id\" ON \"order_exchange_item\" (exchange_id) WHERE deleted_at IS NOT NULL" - }, - { - "keyName": "IDX_order_exchange_item_item_id", - "columnNames": [ - "item_id" - ], + "keyName": "IDX_order_shipping_method_tax_line_shipping_method_id", + "columnNames": [], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_exchange_item_item_id\" ON \"order_exchange_item\" (item_id) WHERE deleted_at IS NOT NULL" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_method_tax_line_shipping_method_id\" ON \"order_shipping_method_tax_line\" (shipping_method_id) WHERE deleted_at IS NULL" }, { - "keyName": "IDX_order_claim_item_image_deleted_at", - "columnNames": [ - "deleted_at" - ], + "keyName": "IDX_order_shipping_method_tax_line_deleted_at", + "columnNames": [], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_claim_item_image_deleted_at\" ON \"order_claim_item_image\" (deleted_at) WHERE deleted_at IS NOT NULL" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_method_tax_line_deleted_at\" ON \"order_shipping_method_tax_line\" (deleted_at) WHERE deleted_at IS NULL" }, { - "keyName": "order_exchange_item_pkey", + "keyName": "order_shipping_method_tax_line_pkey", "columnNames": [ "id" ], @@ -2717,29 +2947,16 @@ ], "checks": [], "foreignKeys": { - "order_exchange_item_exchange_id_foreign": { - "constraintName": "order_exchange_item_exchange_id_foreign", - "columnNames": [ - "exchange_id" - ], - "localTableName": "public.order_exchange_item", - "referencedColumnNames": [ - "id" - ], - "referencedTableName": "public.order_exchange", - "deleteRule": "cascade", - "updateRule": "cascade" - }, - "order_exchange_item_item_id_foreign": { - "constraintName": "order_exchange_item_item_id_foreign", + "order_shipping_method_tax_line_shipping_method_id_foreign": { + "constraintName": "order_shipping_method_tax_line_shipping_method_id_foreign", "columnNames": [ - "item_id" + "shipping_method_id" ], - "localTableName": "public.order_exchange_item", + "localTableName": "public.order_shipping_method_tax_line", "referencedColumnNames": [ "id" ], - "referencedTableName": "public.order_line_item", + "referencedTableName": "public.order_shipping_method", "updateRule": "cascade" } } @@ -2755,100 +2972,34 @@ "nullable": false, "mappedType": "text" }, - "order_id": { - "name": "order_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "text" - }, - "return_id": { - "name": "return_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "order_version": { - "name": "order_version", - "type": "integer", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "integer" - }, - "display_id": { - "name": "display_id", - "type": "serial", - "unsigned": true, - "autoincrement": true, - "primary": false, - "nullable": false, - "mappedType": "integer" - }, - "type": { - "name": "type", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "enumItems": [ - "refund", - "replace" - ], - "mappedType": "enum" - }, - "no_notification": { - "name": "no_notification", - "type": "boolean", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "boolean" - }, - "refund_amount": { - "name": "refund_amount", - "type": "numeric", + "version": { + "name": "version", + "type": "integer", "unsigned": false, "autoincrement": false, "primary": false, - "nullable": true, - "mappedType": "decimal" + "nullable": false, + "default": "1", + "mappedType": "integer" }, - "raw_refund_amount": { - "name": "raw_refund_amount", + "totals": { + "name": "totals", "type": "jsonb", "unsigned": false, "autoincrement": false, "primary": false, - "nullable": true, + "nullable": false, "mappedType": "json" }, - "created_by": { - "name": "created_by", + "order_id": { + "name": "order_id", "type": "text", "unsigned": false, "autoincrement": false, "primary": false, - "nullable": true, + "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", @@ -2880,72 +3031,45 @@ "nullable": true, "length": 6, "mappedType": "datetime" - }, - "canceled_at": { - "name": "canceled_at", - "type": "timestamptz", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "length": 6, - "mappedType": "datetime" } }, - "name": "order_claim", + "name": "order_summary", "schema": "public", "indexes": [ { - "columnNames": [ - "return_id" - ], - "composite": false, - "keyName": "order_claim_return_id_unique", - "primary": false, - "unique": true - }, - { - "keyName": "IDX_order_claim_order_id", - "columnNames": [ - "order_id" - ], + "keyName": "IDX_order_summary_order_id", + "columnNames": [], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_claim_order_id\" ON \"order_claim\" (order_id) WHERE deleted_at IS NOT NULL" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_summary_order_id\" ON \"order_summary\" (order_id) WHERE deleted_at IS NULL" }, { - "keyName": "IDX_order_claim_return_id", - "columnNames": [ - "return_id" - ], + "keyName": "IDX_order_summary_deleted_at", + "columnNames": [], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_claim_return_id\" ON \"order_claim\" (return_id) WHERE return_id IS NOT NULL AND deleted_at IS NOT NULL" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_summary_deleted_at\" ON \"order_summary\" (deleted_at) WHERE deleted_at IS NULL" }, { - "keyName": "IDX_order_claim_display_id", - "columnNames": [ - "display_id" - ], + "keyName": "IDX_order_summary_order_id_version", + "columnNames": [], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_claim_display_id\" ON \"order_claim\" (display_id) WHERE deleted_at IS NOT NULL" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_summary_order_id_version\" ON \"order_summary\" (order_id, version) WHERE deleted_at IS NOT NULL" }, { - "keyName": "IDX_order_claim_deleted_at", - "columnNames": [ - "deleted_at" - ], + "keyName": "IDX_order_summary_deleted_at", + "columnNames": [], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_claim_deleted_at\" ON \"order_claim\" (deleted_at) WHERE deleted_at IS NOT NULL" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_summary_deleted_at\" ON \"order_summary\" (deleted_at) WHERE deleted_at IS NOT NULL" }, { - "keyName": "order_claim_pkey", + "keyName": "order_summary_pkey", "columnNames": [ "id" ], @@ -2956,30 +3080,17 @@ ], "checks": [], "foreignKeys": { - "order_claim_order_id_foreign": { - "constraintName": "order_claim_order_id_foreign", + "order_summary_order_id_foreign": { + "constraintName": "order_summary_order_id_foreign", "columnNames": [ "order_id" ], - "localTableName": "public.order_claim", + "localTableName": "public.order_summary", "referencedColumnNames": [ "id" ], "referencedTableName": "public.order", "updateRule": "cascade" - }, - "order_claim_return_id_foreign": { - "constraintName": "order_claim_return_id_foreign", - "columnNames": [ - "return_id" - ], - "localTableName": "public.order_claim", - "referencedColumnNames": [ - "id" - ], - "referencedTableName": "public.return", - "deleteRule": "set null", - "updateRule": "cascade" } } }, @@ -2994,35 +3105,43 @@ "nullable": false, "mappedType": "text" }, - "order_id": { - "name": "order_id", - "type": "text", + "order_version": { + "name": "order_version", + "type": "integer", "unsigned": false, "autoincrement": false, "primary": false, "nullable": false, - "mappedType": "text" + "mappedType": "integer" }, - "return_id": { - "name": "return_id", - "type": "text", + "display_id": { + "name": "display_id", + "type": "bigserial", "unsigned": false, "autoincrement": false, "primary": false, - "nullable": true, - "mappedType": "text" + "nullable": false, + "mappedType": "bigint" }, - "exchange_id": { - "name": "exchange_id", + "status": { + "name": "status", "type": "text", "unsigned": false, "autoincrement": false, "primary": false, - "nullable": true, - "mappedType": "text" + "nullable": false, + "default": "'open'", + "enumItems": [ + "open", + "requested", + "received", + "partially_received", + "canceled" + ], + "mappedType": "enum" }, - "claim_id": { - "name": "claim_id", + "location_id": { + "name": "location_id", "type": "text", "unsigned": false, "autoincrement": false, @@ -3030,36 +3149,74 @@ "nullable": true, "mappedType": "text" }, - "version": { - "name": "version", - "type": "integer", + "no_notification": { + "name": "no_notification", + "type": "boolean", "unsigned": false, "autoincrement": false, "primary": false, - "nullable": false, - "default": "1", - "mappedType": "integer" + "nullable": true, + "mappedType": "boolean" }, - "amount": { - "name": "amount", + "refund_amount": { + "name": "refund_amount", "type": "numeric", "unsigned": false, "autoincrement": false, "primary": false, - "nullable": false, + "nullable": true, "mappedType": "decimal" }, - "raw_amount": { - "name": "raw_amount", + "created_by": { + "name": "created_by", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "metadata": { + "name": "metadata", "type": "jsonb", "unsigned": false, "autoincrement": false, "primary": false, - "nullable": false, + "nullable": true, "mappedType": "json" }, - "currency_code": { - "name": "currency_code", + "requested_at": { + "name": "requested_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 6, + "mappedType": "datetime" + }, + "received_at": { + "name": "received_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 6, + "mappedType": "datetime" + }, + "canceled_at": { + "name": "canceled_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 6, + "mappedType": "datetime" + }, + "order_id": { + "name": "order_id", "type": "text", "unsigned": false, "autoincrement": false, @@ -3067,24 +3224,33 @@ "nullable": false, "mappedType": "text" }, - "reference": { - "name": "reference", + "exchange_id": { + "name": "exchange_id", "type": "text", "unsigned": false, "autoincrement": false, "primary": false, - "nullable": true, + "nullable": false, "mappedType": "text" }, - "reference_id": { - "name": "reference_id", + "claim_id": { + "name": "claim_id", "type": "text", "unsigned": false, "autoincrement": false, "primary": false, - "nullable": true, + "nullable": false, "mappedType": "text" }, + "raw_refund_amount": { + "name": "raw_refund_amount", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "json" + }, "created_at": { "name": "created_at", "type": "timestamptz", @@ -3118,89 +3284,83 @@ "mappedType": "datetime" } }, - "name": "order_transaction", + "name": "return", "schema": "public", "indexes": [ { - "keyName": "IDX_order_transaction_order_id", - "columnNames": [ - "order_id" - ], + "keyName": "IDX_return_order_id", + "columnNames": [], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_transaction_order_id\" ON \"order_transaction\" (order_id) WHERE deleted_at IS NOT NULL" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_order_id\" ON \"return\" (order_id) WHERE deleted_at IS NULL" }, { - "keyName": "IDX_order_transaction_return_id", - "columnNames": [ - "return_id" - ], + "keyName": "IDX_return_exchange_id", + "columnNames": [], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_transaction_return_id\" ON \"order_transaction\" (return_id) WHERE return_id IS NOT NULL AND deleted_at IS NOT NULL" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_exchange_id\" ON \"return\" (exchange_id) WHERE deleted_at IS NULL" }, { - "keyName": "IDX_order_transaction_exchange_id", - "columnNames": [ - "exchange_id" - ], + "keyName": "IDX_return_claim_id", + "columnNames": [], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_transaction_exchange_id\" ON \"order_transaction\" (exchange_id) WHERE exchange_id IS NOT NULL AND deleted_at IS NOT NULL" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_claim_id\" ON \"return\" (claim_id) WHERE deleted_at IS NULL" }, { - "keyName": "IDX_order_transaction_claim_id", - "columnNames": [ - "claim_id" - ], + "keyName": "IDX_return_deleted_at", + "columnNames": [], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_transaction_claim_id\" ON \"order_transaction\" (claim_id) WHERE claim_id IS NOT NULL AND deleted_at IS NOT NULL" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_deleted_at\" ON \"return\" (deleted_at) WHERE deleted_at IS NULL" }, { - "keyName": "IDX_order_transaction_currency_code", - "columnNames": [ - "currency_code" - ], + "keyName": "IDX_return_display_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_display_id\" ON \"return\" (display_id) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_return_deleted_at", + "columnNames": [], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_transaction_currency_code\" ON \"order_transaction\" (currency_code) WHERE deleted_at IS NOT NULL" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_deleted_at\" ON \"return\" (deleted_at) WHERE deleted_at IS NOT NULL" }, { - "keyName": "IDX_order_transaction_reference_id", - "columnNames": [ - "reference_id" - ], + "keyName": "IDX_return_order_id", + "columnNames": [], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_transaction_reference_id\" ON \"order_transaction\" (reference_id) WHERE deleted_at IS NOT NULL" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_order_id\" ON \"return\" (order_id) WHERE deleted_at IS NOT NULL" }, { - "keyName": "IDX_order_transaction_deleted_at", - "columnNames": [ - "deleted_at" - ], + "keyName": "IDX_return_exchange_id", + "columnNames": [], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_transaction_deleted_at\" ON \"order_transaction\" (deleted_at) WHERE deleted_at IS NOT NULL" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_exchange_id\" ON \"return\" (exchange_id) WHERE exchange_id IS NOT NULL AND deleted_at IS NOT NULL" }, { - "keyName": "IDX_order_transaction_order_id_version", + "keyName": "IDX_return_claim_id", "columnNames": [], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_transaction_order_id_version\" ON \"order_transaction\" (order_id, version) WHERE deleted_at IS NOT NULL" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_claim_id\" ON \"return\" (claim_id) WHERE claim_id IS NOT NULL AND deleted_at IS NOT NULL" }, { - "keyName": "order_transaction_pkey", + "keyName": "return_pkey", "columnNames": [ "id" ], @@ -3211,56 +3371,40 @@ ], "checks": [], "foreignKeys": { - "order_transaction_order_id_foreign": { - "constraintName": "order_transaction_order_id_foreign", + "return_order_id_foreign": { + "constraintName": "return_order_id_foreign", "columnNames": [ "order_id" ], - "localTableName": "public.order_transaction", + "localTableName": "public.return", "referencedColumnNames": [ "id" ], "referencedTableName": "public.order", - "deleteRule": "cascade", - "updateRule": "cascade" - }, - "order_transaction_return_id_foreign": { - "constraintName": "order_transaction_return_id_foreign", - "columnNames": [ - "return_id" - ], - "localTableName": "public.order_transaction", - "referencedColumnNames": [ - "id" - ], - "referencedTableName": "public.return", - "deleteRule": "set null", "updateRule": "cascade" }, - "order_transaction_exchange_id_foreign": { - "constraintName": "order_transaction_exchange_id_foreign", + "return_exchange_id_foreign": { + "constraintName": "return_exchange_id_foreign", "columnNames": [ "exchange_id" ], - "localTableName": "public.order_transaction", + "localTableName": "public.return", "referencedColumnNames": [ "id" ], "referencedTableName": "public.order_exchange", - "deleteRule": "set null", "updateRule": "cascade" }, - "order_transaction_claim_id_foreign": { - "constraintName": "order_transaction_claim_id_foreign", + "return_claim_id_foreign": { + "constraintName": "return_claim_id_foreign", "columnNames": [ "claim_id" ], - "localTableName": "public.order_transaction", + "localTableName": "public.return", "referencedColumnNames": [ "id" ], "referencedTableName": "public.order_claim", - "deleteRule": "set null", "updateRule": "cascade" } } @@ -3276,8 +3420,27 @@ "nullable": false, "mappedType": "text" }, - "order_id": { - "name": "order_id", + "version": { + "name": "version", + "type": "integer", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "default": "1", + "mappedType": "integer" + }, + "amount": { + "name": "amount", + "type": "numeric", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "decimal" + }, + "currency_code": { + "name": "currency_code", "type": "text", "unsigned": false, "autoincrement": false, @@ -3285,8 +3448,8 @@ "nullable": false, "mappedType": "text" }, - "return_id": { - "name": "return_id", + "reference": { + "name": "reference", "type": "text", "unsigned": false, "autoincrement": false, @@ -3294,8 +3457,8 @@ "nullable": true, "mappedType": "text" }, - "exchange_id": { - "name": "exchange_id", + "reference_id": { + "name": "reference_id", "type": "text", "unsigned": false, "autoincrement": false, @@ -3303,26 +3466,35 @@ "nullable": true, "mappedType": "text" }, - "claim_id": { - "name": "claim_id", + "order_id": { + "name": "order_id", "type": "text", "unsigned": false, "autoincrement": false, "primary": false, - "nullable": true, + "nullable": false, "mappedType": "text" }, - "version": { - "name": "version", - "type": "integer", + "return_id": { + "name": "return_id", + "type": "text", "unsigned": false, "autoincrement": false, "primary": false, "nullable": false, - "mappedType": "integer" + "mappedType": "text" }, - "shipping_method_id": { - "name": "shipping_method_id", + "exchange_id": { + "name": "exchange_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "claim_id": { + "name": "claim_id", "type": "text", "unsigned": false, "autoincrement": false, @@ -3330,6 +3502,15 @@ "nullable": false, "mappedType": "text" }, + "raw_amount": { + "name": "raw_amount", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "json" + }, "created_at": { "name": "created_at", "type": "timestamptz", @@ -3363,81 +3544,115 @@ "mappedType": "datetime" } }, - "name": "order_shipping", + "name": "order_transaction", "schema": "public", "indexes": [ { - "keyName": "IDX_order_shipping_order_id", - "columnNames": [ - "order_id" - ], + "keyName": "IDX_order_transaction_order_id", + "columnNames": [], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_order_id\" ON \"order_shipping\" (order_id) WHERE deleted_at IS NOT NULL" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_transaction_order_id\" ON \"order_transaction\" (order_id) WHERE deleted_at IS NULL" }, { - "keyName": "IDX_order_shipping_return_id", - "columnNames": [ - "return_id" - ], + "keyName": "IDX_order_transaction_return_id", + "columnNames": [], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_return_id\" ON \"order_shipping\" (return_id) WHERE return_id IS NOT NULL AND deleted_at IS NOT NULL" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_transaction_return_id\" ON \"order_transaction\" (return_id) WHERE deleted_at IS NULL" }, { - "keyName": "IDX_order_shipping_exchange_id", - "columnNames": [ - "exchange_id" - ], + "keyName": "IDX_order_transaction_exchange_id", + "columnNames": [], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_exchange_id\" ON \"order_shipping\" (exchange_id) WHERE exchange_id IS NOT NULL AND deleted_at IS NOT NULL" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_transaction_exchange_id\" ON \"order_transaction\" (exchange_id) WHERE deleted_at IS NULL" }, { - "keyName": "IDX_order_shipping_claim_id", - "columnNames": [ - "claim_id" - ], + "keyName": "IDX_order_transaction_claim_id", + "columnNames": [], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_claim_id\" ON \"order_shipping\" (claim_id) WHERE claim_id IS NOT NULL AND deleted_at IS NOT NULL" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_transaction_claim_id\" ON \"order_transaction\" (claim_id) WHERE deleted_at IS NULL" }, { - "keyName": "IDX_order_shipping_version", - "columnNames": [ - "version" - ], + "keyName": "IDX_order_transaction_deleted_at", + "columnNames": [], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_version\" ON \"order_shipping\" (version) WHERE deleted_at IS NOT NULL" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_transaction_deleted_at\" ON \"order_transaction\" (deleted_at) WHERE deleted_at IS NULL" }, { - "keyName": "IDX_order_shipping_shipping_method_id", - "columnNames": [ - "shipping_method_id" - ], + "keyName": "IDX_order_transaction_reference_id", + "columnNames": [], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_shipping_method_id\" ON \"order_shipping\" (shipping_method_id) WHERE deleted_at IS NOT NULL" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_transaction_reference_id\" ON \"order_transaction\" (reference_id) WHERE deleted_at IS NOT NULL" }, { - "keyName": "IDX_order_shipping_deleted_at", - "columnNames": [ - "deleted_at" - ], + "keyName": "IDX_order_transaction_order_id", + "columnNames": [], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_deleted_at\" ON \"order_shipping\" (deleted_at) WHERE deleted_at IS NOT NULL" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_transaction_order_id\" ON \"order_transaction\" (order_id) WHERE deleted_at IS NOT NULL" }, { - "keyName": "order_shipping_pkey", + "keyName": "IDX_order_transaction_return_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_transaction_return_id\" ON \"order_transaction\" (return_id) WHERE return_id IS NOT NULL AND deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_transaction_exchange_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_transaction_exchange_id\" ON \"order_transaction\" (exchange_id) WHERE exchange_id IS NOT NULL AND deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_transaction_claim_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_transaction_claim_id\" ON \"order_transaction\" (claim_id) WHERE claim_id IS NOT NULL AND deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_transaction_currency_code", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_transaction_currency_code\" ON \"order_transaction\" (currency_code) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_transaction_deleted_at", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_transaction_deleted_at\" ON \"order_transaction\" (deleted_at) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_transaction_order_id_version", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_transaction_order_id_version\" ON \"order_transaction\" (order_id, version) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "order_transaction_pkey", "columnNames": [ "id" ], @@ -3448,67 +3663,52 @@ ], "checks": [], "foreignKeys": { - "order_shipping_order_id_foreign": { - "constraintName": "order_shipping_order_id_foreign", + "order_transaction_order_id_foreign": { + "constraintName": "order_transaction_order_id_foreign", "columnNames": [ "order_id" ], - "localTableName": "public.order_shipping", + "localTableName": "public.order_transaction", "referencedColumnNames": [ "id" ], "referencedTableName": "public.order", "updateRule": "cascade" }, - "order_shipping_return_id_foreign": { - "constraintName": "order_shipping_return_id_foreign", + "order_transaction_return_id_foreign": { + "constraintName": "order_transaction_return_id_foreign", "columnNames": [ "return_id" ], - "localTableName": "public.order_shipping", + "localTableName": "public.order_transaction", "referencedColumnNames": [ "id" ], "referencedTableName": "public.return", - "deleteRule": "set null", "updateRule": "cascade" }, - "order_shipping_exchange_id_foreign": { - "constraintName": "order_shipping_exchange_id_foreign", + "order_transaction_exchange_id_foreign": { + "constraintName": "order_transaction_exchange_id_foreign", "columnNames": [ "exchange_id" ], - "localTableName": "public.order_shipping", - "referencedColumnNames": [ - "id" - ], - "referencedTableName": "public.order_exchange", - "deleteRule": "set null", - "updateRule": "cascade" - }, - "order_shipping_claim_id_foreign": { - "constraintName": "order_shipping_claim_id_foreign", - "columnNames": [ - "claim_id" - ], - "localTableName": "public.order_shipping", + "localTableName": "public.order_transaction", "referencedColumnNames": [ "id" ], - "referencedTableName": "public.order_claim", - "deleteRule": "set null", + "referencedTableName": "public.order_exchange", "updateRule": "cascade" }, - "order_shipping_shipping_method_id_foreign": { - "constraintName": "order_shipping_shipping_method_id_foreign", + "order_transaction_claim_id_foreign": { + "constraintName": "order_transaction_claim_id_foreign", "columnNames": [ - "shipping_method_id" + "claim_id" ], - "localTableName": "public.order_shipping", + "localTableName": "public.order_transaction", "referencedColumnNames": [ "id" ], - "referencedTableName": "public.order_shipping_method", + "referencedTableName": "public.order_claim", "updateRule": "cascade" } } @@ -3524,41 +3724,17 @@ "nullable": false, "mappedType": "text" }, - "reason": { - "name": "reason", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "enumItems": [ - "missing_item", - "wrong_item", - "production_failure", - "other" - ], - "mappedType": "enum" - }, - "quantity": { - "name": "quantity", - "type": "numeric", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "decimal" - }, - "raw_quantity": { - "name": "raw_quantity", - "type": "jsonb", + "version": { + "name": "version", + "type": "integer", "unsigned": false, "autoincrement": false, "primary": false, "nullable": false, - "mappedType": "json" + "mappedType": "integer" }, - "claim_id": { - "name": "claim_id", + "order_id": { + "name": "order_id", "type": "text", "unsigned": false, "autoincrement": false, @@ -3566,27 +3742,26 @@ "nullable": false, "mappedType": "text" }, - "item_id": { - "name": "item_id", + "return_id": { + "name": "return_id", "type": "text", "unsigned": false, "autoincrement": false, "primary": false, - "nullable": false, + "nullable": true, "mappedType": "text" }, - "is_additional_item": { - "name": "is_additional_item", - "type": "boolean", + "exchange_id": { + "name": "exchange_id", + "type": "text", "unsigned": false, "autoincrement": false, "primary": false, - "nullable": false, - "default": "false", - "mappedType": "boolean" + "nullable": true, + "mappedType": "text" }, - "note": { - "name": "note", + "claim_id": { + "name": "claim_id", "type": "text", "unsigned": false, "autoincrement": false, @@ -3594,14 +3769,14 @@ "nullable": true, "mappedType": "text" }, - "metadata": { - "name": "metadata", - "type": "jsonb", + "shipping_method_id": { + "name": "shipping_method_id", + "type": "text", "unsigned": false, "autoincrement": false, "primary": false, - "nullable": true, - "mappedType": "json" + "nullable": false, + "mappedType": "text" }, "created_at": { "name": "created_at", @@ -3636,174 +3811,115 @@ "mappedType": "datetime" } }, - "name": "order_claim_item", + "name": "order_shipping", "schema": "public", "indexes": [ { - "keyName": "IDX_order_claim_item_claim_id", - "columnNames": [ - "claim_id" - ], + "keyName": "IDX_order_shipping_order_id", + "columnNames": [], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_claim_item_claim_id\" ON \"order_claim_item\" (claim_id) WHERE deleted_at IS NOT NULL" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_order_id\" ON \"order_shipping\" (order_id) WHERE deleted_at IS NULL" }, { - "keyName": "IDX_order_claim_item_item_id", - "columnNames": [ - "item_id" - ], + "keyName": "IDX_order_shipping_return_id", + "columnNames": [], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_claim_item_item_id\" ON \"order_claim_item\" (item_id) WHERE deleted_at IS NOT NULL" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_return_id\" ON \"order_shipping\" (return_id) WHERE deleted_at IS NULL" }, { - "keyName": "IDX_order_claim_item_deleted_at", - "columnNames": [ - "deleted_at" - ], + "keyName": "IDX_order_shipping_exchange_id", + "columnNames": [], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_claim_item_deleted_at\" ON \"order_claim_item\" (deleted_at) WHERE deleted_at IS NOT NULL" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_exchange_id\" ON \"order_shipping\" (exchange_id) WHERE deleted_at IS NULL" }, { - "keyName": "order_claim_item_pkey", - "columnNames": [ - "id" - ], + "keyName": "IDX_order_shipping_claim_id", + "columnNames": [], "composite": false, - "primary": true, - "unique": true - } - ], - "checks": [], - "foreignKeys": { - "order_claim_item_claim_id_foreign": { - "constraintName": "order_claim_item_claim_id_foreign", - "columnNames": [ - "claim_id" - ], - "localTableName": "public.order_claim_item", - "referencedColumnNames": [ - "id" - ], - "referencedTableName": "public.order_claim", - "deleteRule": "cascade", - "updateRule": "cascade" + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_claim_id\" ON \"order_shipping\" (claim_id) WHERE deleted_at IS NULL" }, - "order_claim_item_item_id_foreign": { - "constraintName": "order_claim_item_item_id_foreign", - "columnNames": [ - "item_id" - ], - "localTableName": "public.order_claim_item", - "referencedColumnNames": [ - "id" - ], - "referencedTableName": "public.order_line_item", - "updateRule": "cascade" - } - } - }, - { - "columns": { - "id": { - "name": "id", - "type": "text", - "unsigned": false, - "autoincrement": false, + { + "keyName": "IDX_order_shipping_shipping_method_id", + "columnNames": [], + "composite": false, "primary": false, - "nullable": false, - "mappedType": "text" + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_shipping_method_id\" ON \"order_shipping\" (shipping_method_id) WHERE deleted_at IS NULL" }, - "claim_item_id": { - "name": "claim_item_id", - "type": "text", - "unsigned": false, - "autoincrement": false, + { + "keyName": "IDX_order_shipping_deleted_at", + "columnNames": [], + "composite": false, "primary": false, - "nullable": false, - "mappedType": "text" + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_deleted_at\" ON \"order_shipping\" (deleted_at) WHERE deleted_at IS NULL" }, - "url": { - "name": "url", - "type": "text", - "unsigned": false, - "autoincrement": false, + { + "keyName": "IDX_order_shipping_order_id", + "columnNames": [], + "composite": false, "primary": false, - "nullable": false, - "mappedType": "text" + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_order_id\" ON \"order_shipping\" (order_id) WHERE deleted_at IS NOT NULL" }, - "metadata": { - "name": "metadata", - "type": "jsonb", - "unsigned": false, - "autoincrement": false, + { + "keyName": "IDX_order_shipping_return_id", + "columnNames": [], + "composite": false, "primary": false, - "nullable": true, - "mappedType": "json" + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_return_id\" ON \"order_shipping\" (return_id) WHERE return_id IS NOT NULL AND deleted_at IS NOT NULL" }, - "created_at": { - "name": "created_at", - "type": "timestamptz", - "unsigned": false, - "autoincrement": false, + { + "keyName": "IDX_order_shipping_exchange_id", + "columnNames": [], + "composite": false, "primary": false, - "nullable": false, - "length": 6, - "default": "now()", - "mappedType": "datetime" + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_exchange_id\" ON \"order_shipping\" (exchange_id) WHERE exchange_id IS NOT NULL AND deleted_at IS NOT NULL" }, - "updated_at": { - "name": "updated_at", - "type": "timestamptz", - "unsigned": false, - "autoincrement": false, + { + "keyName": "IDX_order_shipping_claim_id", + "columnNames": [], + "composite": false, "primary": false, - "nullable": false, - "length": 6, - "default": "now()", - "mappedType": "datetime" + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_claim_id\" ON \"order_shipping\" (claim_id) WHERE claim_id IS NOT NULL AND deleted_at IS NOT NULL" }, - "deleted_at": { - "name": "deleted_at", - "type": "timestamptz", - "unsigned": false, - "autoincrement": false, + { + "keyName": "IDX_order_shipping_version", + "columnNames": [], + "composite": false, "primary": false, - "nullable": true, - "length": 6, - "mappedType": "datetime" - } - }, - "name": "order_claim_item_image", - "schema": "public", - "indexes": [ + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_version\" ON \"order_shipping\" (version) WHERE deleted_at IS NOT NULL" + }, { - "keyName": "IDX_order_claim_item_image_claim_item_id", - "columnNames": [ - "claim_item_id" - ], + "keyName": "IDX_order_shipping_shipping_method_id", + "columnNames": [], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_claim_item_image_claim_item_id\" ON \"order_claim_item_image\" (claim_item_id) WHERE deleted_at IS NOT NULL" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_shipping_method_id\" ON \"order_shipping\" (shipping_method_id) WHERE deleted_at IS NOT NULL" }, { - "keyName": "IDX_order_claim_item_image_deleted_at", - "columnNames": [ - "deleted_at" - ], + "keyName": "IDX_order_shipping_deleted_at", + "columnNames": [], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_claim_item_image_deleted_at\" ON \"order_claim_item_image\" (deleted_at) WHERE deleted_at IS NOT NULL" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_deleted_at\" ON \"order_shipping\" (deleted_at) WHERE deleted_at IS NOT NULL" }, { - "keyName": "order_claim_item_image_pkey", + "keyName": "order_shipping_pkey", "columnNames": [ "id" ], @@ -3814,16 +3930,67 @@ ], "checks": [], "foreignKeys": { - "order_claim_item_image_claim_item_id_foreign": { - "constraintName": "order_claim_item_image_claim_item_id_foreign", + "order_shipping_order_id_foreign": { + "constraintName": "order_shipping_order_id_foreign", "columnNames": [ - "claim_item_id" + "order_id" ], - "localTableName": "public.order_claim_item_image", + "localTableName": "public.order_shipping", "referencedColumnNames": [ "id" ], - "referencedTableName": "public.order_claim_item", + "referencedTableName": "public.order", + "updateRule": "cascade" + }, + "order_shipping_return_id_foreign": { + "constraintName": "order_shipping_return_id_foreign", + "columnNames": [ + "return_id" + ], + "localTableName": "public.order_shipping", + "referencedColumnNames": [ + "id" + ], + "referencedTableName": "public.return", + "deleteRule": "set null", + "updateRule": "cascade" + }, + "order_shipping_exchange_id_foreign": { + "constraintName": "order_shipping_exchange_id_foreign", + "columnNames": [ + "exchange_id" + ], + "localTableName": "public.order_shipping", + "referencedColumnNames": [ + "id" + ], + "referencedTableName": "public.order_exchange", + "deleteRule": "set null", + "updateRule": "cascade" + }, + "order_shipping_claim_id_foreign": { + "constraintName": "order_shipping_claim_id_foreign", + "columnNames": [ + "claim_id" + ], + "localTableName": "public.order_shipping", + "referencedColumnNames": [ + "id" + ], + "referencedTableName": "public.order_claim", + "deleteRule": "set null", + "updateRule": "cascade" + }, + "order_shipping_shipping_method_id_foreign": { + "constraintName": "order_shipping_shipping_method_id_foreign", + "columnNames": [ + "shipping_method_id" + ], + "localTableName": "public.order_shipping", + "referencedColumnNames": [ + "id" + ], + "referencedTableName": "public.order_shipping_method", "updateRule": "cascade" } } @@ -3839,42 +4006,6 @@ "nullable": false, "mappedType": "text" }, - "order_id": { - "name": "order_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "text" - }, - "return_id": { - "name": "return_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "claim_id": { - "name": "claim_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "exchange_id": { - "name": "exchange_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, "version": { "name": "version", "type": "integer", @@ -3908,7 +4039,7 @@ "unsigned": false, "autoincrement": false, "primary": false, - "nullable": false, + "nullable": true, "default": "'pending'", "enumItems": [ "confirmed", @@ -3934,7 +4065,7 @@ "unsigned": false, "autoincrement": false, "primary": false, - "nullable": true, + "nullable": false, "mappedType": "text" }, "requested_by": { @@ -4031,6 +4162,42 @@ "length": 6, "mappedType": "datetime" }, + "order_id": { + "name": "order_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "return_id": { + "name": "return_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "claim_id": { + "name": "claim_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "exchange_id": { + "name": "exchange_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, "created_at": { "name": "created_at", "type": "timestamptz", @@ -4069,59 +4236,79 @@ "indexes": [ { "keyName": "IDX_order_change_order_id", - "columnNames": [ - "order_id" - ], + "columnNames": [], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_order_id\" ON \"order_change\" (order_id) WHERE deleted_at IS NOT NULL" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_order_id\" ON \"order_change\" (order_id) WHERE deleted_at IS NULL" }, { "keyName": "IDX_order_change_return_id", - "columnNames": [ - "return_id" - ], + "columnNames": [], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_return_id\" ON \"order_change\" (return_id) WHERE return_id IS NOT NULL AND deleted_at IS NOT NULL" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_return_id\" ON \"order_change\" (return_id) WHERE deleted_at IS NULL" }, { "keyName": "IDX_order_change_claim_id", - "columnNames": [ - "claim_id" - ], + "columnNames": [], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_claim_id\" ON \"order_change\" (claim_id) WHERE claim_id IS NOT NULL AND deleted_at IS NOT NULL" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_claim_id\" ON \"order_change\" (claim_id) WHERE deleted_at IS NULL" }, { "keyName": "IDX_order_change_exchange_id", - "columnNames": [ - "exchange_id" - ], + "columnNames": [], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_exchange_id\" ON \"order_change\" (exchange_id) WHERE exchange_id IS NOT NULL AND deleted_at IS NOT NULL" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_exchange_id\" ON \"order_change\" (exchange_id) WHERE deleted_at IS NULL" }, { - "keyName": "IDX_order_change_order_id_version", - "columnNames": [ - "version" - ], + "keyName": "IDX_order_change_deleted_at", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_deleted_at\" ON \"order_change\" (deleted_at) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_order_change_order_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_order_id\" ON \"order_change\" (order_id) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_change_return_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_return_id\" ON \"order_change\" (return_id) WHERE return_id IS NOT NULL AND deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_change_claim_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_claim_id\" ON \"order_change\" (claim_id) WHERE claim_id IS NOT NULL AND deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_change_exchange_id", + "columnNames": [], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_order_id_version\" ON \"order_change\" (order_id, version) WHERE deleted_at IS NOT NULL" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_exchange_id\" ON \"order_change\" (exchange_id) WHERE exchange_id IS NOT NULL AND deleted_at IS NOT NULL" }, { "keyName": "IDX_order_change_status", - "columnNames": [ - "status" - ], + "columnNames": [], "composite": false, "primary": false, "unique": false, @@ -4129,21 +4316,19 @@ }, { "keyName": "IDX_order_change_deleted_at", - "columnNames": [ - "deleted_at" - ], + "columnNames": [], "composite": false, "primary": false, "unique": false, "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_deleted_at\" ON \"order_change\" (deleted_at) WHERE deleted_at IS NOT NULL" }, { - "keyName": "IDX_order_change_order_id_version", + "keyName": "IDX_order_change_version", "columnNames": [], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_order_id_version\" ON \"order_change\" (order_id, version) WHERE deleted_at IS NOT NULL" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_version\" ON \"order_change\" (order_id, version) WHERE deleted_at IS NOT NULL" }, { "keyName": "order_change_pkey", @@ -4167,7 +4352,6 @@ "id" ], "referencedTableName": "public.order", - "deleteRule": "cascade", "updateRule": "cascade" }, "order_change_return_id_foreign": { @@ -4224,12 +4408,12 @@ }, "ordering": { "name": "ordering", - "type": "integer", - "unsigned": true, - "autoincrement": true, + "type": "bigserial", + "unsigned": false, + "autoincrement": false, "primary": false, "nullable": false, - "mappedType": "integer" + "mappedType": "bigint" }, "order_id": { "name": "order_id", @@ -4276,15 +4460,6 @@ "nullable": true, "mappedType": "integer" }, - "order_change_id": { - "name": "order_change_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, "reference": { "name": "reference", "type": "text", @@ -4330,15 +4505,6 @@ "nullable": true, "mappedType": "decimal" }, - "raw_amount": { - "name": "raw_amount", - "type": "jsonb", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "json" - }, "internal_note": { "name": "internal_note", "type": "text", @@ -4358,6 +4524,24 @@ "default": "false", "mappedType": "boolean" }, + "order_change_id": { + "name": "order_change_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "raw_amount": { + "name": "raw_amount", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "json" + }, "created_at": { "name": "created_at", "type": "timestamptz", @@ -4395,20 +4579,32 @@ "schema": "public", "indexes": [ { - "keyName": "IDX_order_change_action_ordering", - "columnNames": [ - "ordering" - ], + "keyName": "IDX_order_change_action_order_change_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_action_order_change_id\" ON \"order_change_action\" (order_change_id) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_order_change_action_deleted_at", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_action_deleted_at\" ON \"order_change_action\" (deleted_at) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_order_change_action_order_change_id", + "columnNames": [], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_action_ordering\" ON \"order_change_action\" (ordering) WHERE deleted_at IS NOT NULL" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_action_order_change_id\" ON \"order_change_action\" (order_change_id) WHERE deleted_at IS NOT NULL" }, { "keyName": "IDX_order_change_action_order_id", - "columnNames": [ - "order_id" - ], + "columnNames": [], "composite": false, "primary": false, "unique": false, @@ -4416,9 +4612,7 @@ }, { "keyName": "IDX_order_change_action_return_id", - "columnNames": [ - "return_id" - ], + "columnNames": [], "composite": false, "primary": false, "unique": false, @@ -4426,9 +4620,7 @@ }, { "keyName": "IDX_order_change_action_claim_id", - "columnNames": [ - "claim_id" - ], + "columnNames": [], "composite": false, "primary": false, "unique": false, @@ -4436,33 +4628,27 @@ }, { "keyName": "IDX_order_change_action_exchange_id", - "columnNames": [ - "exchange_id" - ], + "columnNames": [], "composite": false, "primary": false, "unique": false, "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_action_exchange_id\" ON \"order_change_action\" (exchange_id) WHERE exchange_id IS NOT NULL AND deleted_at IS NOT NULL" }, { - "keyName": "IDX_order_change_action_order_change_id", - "columnNames": [ - "order_change_id" - ], + "keyName": "IDX_order_change_action_deleted_at", + "columnNames": [], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_action_order_change_id\" ON \"order_change_action\" (order_change_id) WHERE deleted_at IS NOT NULL" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_action_deleted_at\" ON \"order_change_action\" (deleted_at) WHERE deleted_at IS NOT NULL" }, { - "keyName": "IDX_order_change_action_deleted_at", - "columnNames": [ - "deleted_at" - ], + "keyName": "IDX_order_change_action_ordering", + "columnNames": [], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_action_deleted_at\" ON \"order_change_action\" (deleted_at) WHERE deleted_at IS NOT NULL" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_action_ordering\" ON \"order_change_action\" (ordering) WHERE deleted_at IS NOT NULL" }, { "keyName": "order_change_action_pkey", @@ -4476,58 +4662,6 @@ ], "checks": [], "foreignKeys": { - "order_change_action_order_id_foreign": { - "constraintName": "order_change_action_order_id_foreign", - "columnNames": [ - "order_id" - ], - "localTableName": "public.order_change_action", - "referencedColumnNames": [ - "id" - ], - "referencedTableName": "public.order", - "deleteRule": "cascade", - "updateRule": "cascade" - }, - "order_change_action_return_id_foreign": { - "constraintName": "order_change_action_return_id_foreign", - "columnNames": [ - "return_id" - ], - "localTableName": "public.order_change_action", - "referencedColumnNames": [ - "id" - ], - "referencedTableName": "public.return", - "deleteRule": "set null", - "updateRule": "cascade" - }, - "order_change_action_claim_id_foreign": { - "constraintName": "order_change_action_claim_id_foreign", - "columnNames": [ - "claim_id" - ], - "localTableName": "public.order_change_action", - "referencedColumnNames": [ - "id" - ], - "referencedTableName": "public.order_claim", - "deleteRule": "set null", - "updateRule": "cascade" - }, - "order_change_action_exchange_id_foreign": { - "constraintName": "order_change_action_exchange_id_foreign", - "columnNames": [ - "exchange_id" - ], - "localTableName": "public.order_change_action", - "referencedColumnNames": [ - "id" - ], - "referencedTableName": "public.order_exchange", - "deleteRule": "set null", - "updateRule": "cascade" - }, "order_change_action_order_change_id_foreign": { "constraintName": "order_change_action_order_change_id_foreign", "columnNames": [ @@ -4538,7 +4672,6 @@ "id" ], "referencedTableName": "public.order_change", - "deleteRule": "cascade", "updateRule": "cascade" } } @@ -4581,15 +4714,6 @@ "nullable": true, "mappedType": "text" }, - "parent_return_reason_id": { - "name": "parent_return_reason_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, "metadata": { "name": "metadata", "type": "jsonb", @@ -4599,6 +4723,15 @@ "nullable": true, "mappedType": "json" }, + "parent_return_reason_id": { + "name": "parent_return_reason_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, "created_at": { "name": "created_at", "type": "timestamptz", @@ -4636,35 +4769,45 @@ "schema": "public", "indexes": [ { - "keyName": "IDX_return_reason_value", - "columnNames": [ - "value" - ], + "keyName": "IDX_return_reason_parent_return_reason_id", + "columnNames": [], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_reason_value\" ON \"return_reason\" (value) WHERE deleted_at IS NOT NULL" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_reason_parent_return_reason_id\" ON \"return_reason\" (parent_return_reason_id) WHERE deleted_at IS NULL" }, { - "keyName": "IDX_return_reason_parent_return_reason_id", - "columnNames": [ - "parent_return_reason_id" - ], + "keyName": "IDX_return_reason_deleted_at", + "columnNames": [], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_reason_parent_return_reason_id\" ON \"return_reason\" (parent_return_reason_id) WHERE deleted_at IS NOT NULL" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_reason_deleted_at\" ON \"return_reason\" (deleted_at) WHERE deleted_at IS NULL" }, { "keyName": "IDX_return_reason_deleted_at", - "columnNames": [ - "deleted_at" - ], + "columnNames": [], "composite": false, "primary": false, "unique": false, "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_reason_deleted_at\" ON \"return_reason\" (deleted_at) WHERE deleted_at IS NOT NULL" }, + { + "keyName": "IDX_return_reason_value", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_reason_value\" ON \"return_reason\" (value) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_return_reason_parent_return_reason_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_reason_parent_return_reason_id\" ON \"return_reason\" (parent_return_reason_id) WHERE deleted_at IS NOT NULL" + }, { "keyName": "return_reason_pkey", "columnNames": [ @@ -4687,7 +4830,6 @@ "id" ], "referencedTableName": "public.return_reason", - "deleteRule": "set null", "updateRule": "cascade" } } @@ -4703,15 +4845,6 @@ "nullable": false, "mappedType": "text" }, - "reason_id": { - "name": "reason_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, "quantity": { "name": "quantity", "type": "numeric", @@ -4721,15 +4854,6 @@ "nullable": false, "mappedType": "decimal" }, - "raw_quantity": { - "name": "raw_quantity", - "type": "jsonb", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "json" - }, "received_quantity": { "name": "received_quantity", "type": "numeric", @@ -4740,15 +4864,6 @@ "default": "0", "mappedType": "decimal" }, - "raw_received_quantity": { - "name": "raw_received_quantity", - "type": "jsonb", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "json" - }, "damaged_quantity": { "name": "damaged_quantity", "type": "numeric", @@ -4759,15 +4874,33 @@ "default": "0", "mappedType": "decimal" }, - "raw_damaged_quantity": { - "name": "raw_damaged_quantity", + "note": { + "name": "note", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "metadata": { + "name": "metadata", "type": "jsonb", "unsigned": false, "autoincrement": false, "primary": false, - "nullable": false, + "nullable": true, "mappedType": "json" }, + "reason_id": { + "name": "reason_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, "return_id": { "name": "return_id", "type": "text", @@ -4786,22 +4919,31 @@ "nullable": false, "mappedType": "text" }, - "note": { - "name": "note", - "type": "text", + "raw_quantity": { + "name": "raw_quantity", + "type": "jsonb", "unsigned": false, "autoincrement": false, "primary": false, - "nullable": true, - "mappedType": "text" + "nullable": false, + "mappedType": "json" }, - "metadata": { - "name": "metadata", + "raw_received_quantity": { + "name": "raw_received_quantity", "type": "jsonb", "unsigned": false, "autoincrement": false, "primary": false, - "nullable": true, + "nullable": false, + "mappedType": "json" + }, + "raw_damaged_quantity": { + "name": "raw_damaged_quantity", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, "mappedType": "json" }, "created_at": { @@ -4842,29 +4984,55 @@ "indexes": [ { "keyName": "IDX_return_item_reason_id", - "columnNames": [ - "reason_id" - ], + "columnNames": [], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_item_reason_id\" ON \"return_item\" (reason_id) WHERE deleted_at IS NOT NULL" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_item_reason_id\" ON \"return_item\" (reason_id) WHERE deleted_at IS NULL" }, { "keyName": "IDX_return_item_return_id", - "columnNames": [ - "return_id" - ], + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_item_return_id\" ON \"return_item\" (return_id) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_return_item_item_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_item_item_id\" ON \"return_item\" (item_id) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_return_item_deleted_at", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_item_deleted_at\" ON \"return_item\" (deleted_at) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_return_item_return_id", + "columnNames": [], "composite": false, "primary": false, "unique": false, "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_item_return_id\" ON \"return_item\" (return_id) WHERE deleted_at IS NOT NULL" }, + { + "keyName": "IDX_return_item_reason_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_item_reason_id\" ON \"return_item\" (reason_id) WHERE deleted_at IS NOT NULL" + }, { "keyName": "IDX_return_item_item_id", - "columnNames": [ - "item_id" - ], + "columnNames": [], "composite": false, "primary": false, "unique": false, @@ -4872,9 +5040,7 @@ }, { "keyName": "IDX_return_item_deleted_at", - "columnNames": [ - "deleted_at" - ], + "columnNames": [], "composite": false, "primary": false, "unique": false, @@ -4915,7 +5081,6 @@ "id" ], "referencedTableName": "public.return", - "deleteRule": "cascade", "updateRule": "cascade" }, "return_item_item_id_foreign": { diff --git a/packages/modules/order/src/migrations/Migration20241127171653.ts b/packages/modules/order/src/migrations/Migration20241127171653.ts new file mode 100644 index 0000000000000..36d1a766dc5b3 --- /dev/null +++ b/packages/modules/order/src/migrations/Migration20241127171653.ts @@ -0,0 +1,782 @@ +import { Migration } from "@mikro-orm/migrations" + +export class Migration20241127171653 extends Migration { + async up(): Promise { + this.addSql( + 'alter table if exists "order_claim" drop constraint if exists "order_claim_return_id_foreign";' + ) + + this.addSql( + 'alter table if exists "order_exchange" drop constraint if exists "order_exchange_return_id_foreign";' + ) + + this.addSql( + 'alter table if exists "order_exchange_item" drop constraint if exists "order_exchange_item_exchange_id_foreign";' + ) + + this.addSql( + 'alter table if exists "order_claim_item" drop constraint if exists "order_claim_item_claim_id_foreign";' + ) + + this.addSql( + 'alter table if exists "order_line_item_adjustment" drop constraint if exists "order_line_item_adjustment_item_id_foreign";' + ) + + this.addSql( + 'alter table if exists "order_line_item_tax_line" drop constraint if exists "order_line_item_tax_line_item_id_foreign";' + ) + + this.addSql( + 'alter table if exists "order_shipping_method_adjustment" drop constraint if exists "order_shipping_method_adjustment_shipping_method_id_foreign";' + ) + + this.addSql( + 'alter table if exists "order_shipping_method_tax_line" drop constraint if exists "order_shipping_method_tax_line_shipping_method_id_foreign";' + ) + + this.addSql( + 'alter table if exists "order_summary" drop constraint if exists "order_summary_order_id_foreign";' + ) + + this.addSql( + 'alter table if exists "return" drop constraint if exists "return_exchange_id_foreign";' + ) + this.addSql( + 'alter table if exists "return" drop constraint if exists "return_claim_id_foreign";' + ) + + this.addSql( + 'alter table if exists "order_transaction" drop constraint if exists "order_transaction_order_id_foreign";' + ) + this.addSql( + 'alter table if exists "order_transaction" drop constraint if exists "order_transaction_return_id_foreign";' + ) + this.addSql( + 'alter table if exists "order_transaction" drop constraint if exists "order_transaction_exchange_id_foreign";' + ) + this.addSql( + 'alter table if exists "order_transaction" drop constraint if exists "order_transaction_claim_id_foreign";' + ) + + this.addSql( + 'alter table if exists "order_change" drop constraint if exists "order_change_status_check";' + ) + + this.addSql( + 'alter table if exists "order_change" drop constraint if exists "order_change_order_id_foreign";' + ) + + this.addSql( + 'alter table if exists "order_change_action" drop constraint if exists "order_change_action_order_id_foreign";' + ) + this.addSql( + 'alter table if exists "order_change_action" drop constraint if exists "order_change_action_return_id_foreign";' + ) + this.addSql( + 'alter table if exists "order_change_action" drop constraint if exists "order_change_action_claim_id_foreign";' + ) + this.addSql( + 'alter table if exists "order_change_action" drop constraint if exists "order_change_action_exchange_id_foreign";' + ) + this.addSql( + 'alter table if exists "order_change_action" drop constraint if exists "order_change_action_order_change_id_foreign";' + ) + + this.addSql( + 'alter table if exists "return_reason" drop constraint if exists "return_reason_parent_return_reason_id_foreign";' + ) + + this.addSql( + 'alter table if exists "return_item" drop constraint if exists "return_item_return_id_foreign";' + ) + + this.addSql( + 'alter table if exists "order_address" add column if not exists "deleted_at" timestamptz null;' + ) + this.addSql( + 'CREATE INDEX IF NOT EXISTS "IDX_order_address_deleted_at" ON "order_address" (deleted_at) WHERE deleted_at IS NULL;' + ) + + this.addSql( + 'alter table if exists "order" alter column "display_id" type bigint using ("display_id"::bigint);' + ) + this.addSql( + 'alter table if exists "order" alter column "display_id" drop not null;' + ) + this.addSql( + 'alter table if exists "order" alter column "display_id" drop default;' + ) + this.addSql( + 'CREATE INDEX IF NOT EXISTS "IDX_order_sales_channel_id" ON "order" (sales_channel_id) WHERE deleted_at IS NOT NULL;' + ) + + this.addSql( + 'alter table if exists "order_claim" alter column "display_id" type bigint using ("display_id"::bigint);' + ) + this.addSql( + 'alter table if exists "order_claim" drop constraint if exists "order_claim_return_id_unique";' + ) + this.addSql( + 'alter table if exists "order_claim" alter column "display_id" drop default;' + ) + + this.addSql( + 'alter table if exists "order_exchange" alter column "display_id" type bigint using ("display_id"::bigint);' + ) + this.addSql( + 'alter table if exists "order_exchange" drop constraint if exists "order_exchange_return_id_unique";' + ) + this.addSql( + 'alter table if exists "order_exchange" alter column "display_id" drop default;' + ) + + this.addSql( + 'alter table if exists "order_line_item" alter column "requires_shipping" type boolean using ("requires_shipping"::boolean);' + ) + this.addSql( + 'alter table if exists "order_line_item" alter column "requires_shipping" set default true;' + ) + this.addSql( + 'alter table if exists "order_line_item" alter column "is_discountable" type boolean using ("is_discountable"::boolean);' + ) + this.addSql( + 'alter table if exists "order_line_item" alter column "is_discountable" set default true;' + ) + this.addSql( + 'alter table if exists "order_line_item" alter column "is_tax_inclusive" type boolean using ("is_tax_inclusive"::boolean);' + ) + this.addSql( + 'alter table if exists "order_line_item" alter column "is_tax_inclusive" set default false;' + ) + this.addSql( + 'alter table if exists "order_line_item" alter column "unit_price" type numeric using ("unit_price"::numeric);' + ) + this.addSql( + 'alter table if exists "order_line_item" alter column "unit_price" set not null;' + ) + + this.addSql( + 'alter table if exists "order_item" alter column "fulfilled_quantity" type numeric using ("fulfilled_quantity"::numeric);' + ) + this.addSql( + 'alter table if exists "order_item" alter column "fulfilled_quantity" set default 0;' + ) + this.addSql( + 'alter table if exists "order_item" alter column "delivered_quantity" type numeric using ("delivered_quantity"::numeric);' + ) + this.addSql( + 'alter table if exists "order_item" alter column "delivered_quantity" set default 0;' + ) + this.addSql( + 'alter table if exists "order_item" alter column "shipped_quantity" type numeric using ("shipped_quantity"::numeric);' + ) + this.addSql( + 'alter table if exists "order_item" alter column "shipped_quantity" set default 0;' + ) + this.addSql( + 'alter table if exists "order_item" alter column "return_requested_quantity" type numeric using ("return_requested_quantity"::numeric);' + ) + this.addSql( + 'alter table if exists "order_item" alter column "return_requested_quantity" set default 0;' + ) + this.addSql( + 'alter table if exists "order_item" alter column "return_received_quantity" type numeric using ("return_received_quantity"::numeric);' + ) + this.addSql( + 'alter table if exists "order_item" alter column "return_received_quantity" set default 0;' + ) + this.addSql( + 'alter table if exists "order_item" alter column "return_dismissed_quantity" type numeric using ("return_dismissed_quantity"::numeric);' + ) + this.addSql( + 'alter table if exists "order_item" alter column "return_dismissed_quantity" set default 0;' + ) + this.addSql( + 'alter table if exists "order_item" alter column "written_off_quantity" type numeric using ("written_off_quantity"::numeric);' + ) + this.addSql( + 'alter table if exists "order_item" alter column "written_off_quantity" set default 0;' + ) + + this.addSql('drop index if exists "IDX_order_claim_item_image_deleted_at";') + this.addSql( + 'alter table if exists "order_exchange_item" add constraint "order_exchange_item_exchange_id_foreign" foreign key ("exchange_id") references "order_exchange" ("id") on update cascade;' + ) + this.addSql( + 'CREATE INDEX IF NOT EXISTS "IDX_order_exchange_item_deleted_at" ON "order_exchange_item" (deleted_at) WHERE deleted_at IS NOT NULL;' + ) + + this.addSql( + 'alter table if exists "order_claim_item" add constraint "order_claim_item_claim_id_foreign" foreign key ("claim_id") references "order_claim" ("id") on update cascade;' + ) + + this.addSql( + 'alter table if exists "order_line_item_adjustment" add constraint "order_line_item_adjustment_item_id_foreign" foreign key ("item_id") references "order_line_item" ("id") on update cascade;' + ) + this.addSql( + 'CREATE INDEX IF NOT EXISTS "IDX_order_line_item_adjustment_deleted_at" ON "order_line_item_adjustment" (deleted_at) WHERE deleted_at IS NULL;' + ) + this.addSql( + 'CREATE INDEX IF NOT EXISTS "ItemIdIndex" ON "order_line_item_adjustment" (item_id) WHERE deleted_at IS NULL;' + ) + + this.addSql( + 'alter table if exists "order_line_item_tax_line" alter column "item_id" type text using ("item_id"::text);' + ) + this.addSql( + 'alter table if exists "order_line_item_tax_line" alter column "item_id" set not null;' + ) + this.addSql( + 'alter table if exists "order_line_item_tax_line" add constraint "order_line_item_tax_line_item_id_foreign" foreign key ("item_id") references "order_line_item" ("id") on update cascade;' + ) + this.addSql( + 'CREATE INDEX IF NOT EXISTS "IDX_order_line_item_tax_line_deleted_at" ON "order_line_item_tax_line" (deleted_at) WHERE deleted_at IS NULL;' + ) + this.addSql( + 'CREATE INDEX IF NOT EXISTS "ItemIdIndex" ON "order_line_item_tax_line" (item_id) WHERE deleted_at IS NULL;' + ) + + this.addSql( + 'alter table if exists "order_shipping_method" alter column "is_tax_inclusive" drop default;' + ) + this.addSql( + 'alter table if exists "order_shipping_method" alter column "is_tax_inclusive" type boolean using ("is_tax_inclusive"::boolean);' + ) + this.addSql( + 'alter table if exists "order_shipping_method" alter column "is_custom_amount" drop default;' + ) + this.addSql( + 'alter table if exists "order_shipping_method" alter column "is_custom_amount" type boolean using ("is_custom_amount"::boolean);' + ) + + this.addSql( + 'alter table if exists "order_shipping_method_adjustment" add constraint "order_shipping_method_adjustment_shipping_method_id_foreign" foreign key ("shipping_method_id") references "order_shipping_method" ("id") on update cascade;' + ) + this.addSql( + 'CREATE INDEX IF NOT EXISTS "IDX_order_shipping_method_adjustment_deleted_at" ON "order_shipping_method_adjustment" (deleted_at) WHERE deleted_at IS NULL;' + ) + + this.addSql( + 'alter table if exists "order_shipping_method_tax_line" add constraint "order_shipping_method_tax_line_shipping_method_id_foreign" foreign key ("shipping_method_id") references "order_shipping_method" ("id") on update cascade;' + ) + this.addSql( + 'CREATE INDEX IF NOT EXISTS "IDX_order_shipping_method_tax_line_deleted_at" ON "order_shipping_method_tax_line" (deleted_at) WHERE deleted_at IS NULL;' + ) + + this.addSql( + 'alter table if exists "order_summary" add constraint "order_summary_order_id_foreign" foreign key ("order_id") references "order" ("id") on update cascade;' + ) + this.addSql( + 'CREATE INDEX IF NOT EXISTS "IDX_order_summary_order_id" ON "order_summary" (order_id) WHERE deleted_at IS NULL;' + ) + + this.addSql( + 'alter table if exists "return" alter column "exchange_id" type text using ("exchange_id"::text);' + ) + this.addSql( + 'alter table if exists "return" alter column "exchange_id" set not null;' + ) + this.addSql( + 'alter table if exists "return" alter column "claim_id" type text using ("claim_id"::text);' + ) + this.addSql( + 'alter table if exists "return" alter column "claim_id" set not null;' + ) + this.addSql( + 'alter table if exists "return" alter column "display_id" type bigint using ("display_id"::bigint);' + ) + this.addSql( + 'alter table if exists "return" drop constraint if exists "return_exchange_id_unique";' + ) + this.addSql( + 'alter table if exists "return" drop constraint if exists "return_claim_id_unique";' + ) + this.addSql( + 'alter table if exists "return" alter column "display_id" drop default;' + ) + this.addSql( + 'alter table if exists "return" add constraint "return_exchange_id_foreign" foreign key ("exchange_id") references "order_exchange" ("id") on update cascade;' + ) + this.addSql( + 'alter table if exists "return" add constraint "return_claim_id_foreign" foreign key ("claim_id") references "order_claim" ("id") on update cascade;' + ) + + this.addSql( + 'alter table if exists "order_transaction" alter column "return_id" type text using ("return_id"::text);' + ) + this.addSql( + 'alter table if exists "order_transaction" alter column "return_id" set not null;' + ) + this.addSql( + 'alter table if exists "order_transaction" alter column "exchange_id" type text using ("exchange_id"::text);' + ) + this.addSql( + 'alter table if exists "order_transaction" alter column "exchange_id" set not null;' + ) + this.addSql( + 'alter table if exists "order_transaction" alter column "claim_id" type text using ("claim_id"::text);' + ) + this.addSql( + 'alter table if exists "order_transaction" alter column "claim_id" set not null;' + ) + this.addSql( + 'alter table if exists "order_transaction" add constraint "order_transaction_order_id_foreign" foreign key ("order_id") references "order" ("id") on update cascade;' + ) + this.addSql( + 'alter table if exists "order_transaction" add constraint "order_transaction_return_id_foreign" foreign key ("return_id") references "return" ("id") on update cascade;' + ) + this.addSql( + 'alter table if exists "order_transaction" add constraint "order_transaction_exchange_id_foreign" foreign key ("exchange_id") references "order_exchange" ("id") on update cascade;' + ) + this.addSql( + 'alter table if exists "order_transaction" add constraint "order_transaction_claim_id_foreign" foreign key ("claim_id") references "order_claim" ("id") on update cascade;' + ) + + this.addSql( + 'alter table if exists "order_change" alter column "status" type text using ("status"::text);' + ) + this.addSql( + "alter table if exists \"order_change\" add constraint \"order_change_status_check\" check (\"status\" in ('confirmed', 'declined', 'requested', 'pending', 'canceled'));" + ) + this.addSql( + 'alter table if exists "order_change" alter column "status" drop not null;' + ) + this.addSql( + 'alter table if exists "order_change" alter column "created_by" type text using ("created_by"::text);' + ) + this.addSql( + 'alter table if exists "order_change" alter column "created_by" set not null;' + ) + this.addSql('drop index if exists "IDX_order_change_order_id_version";') + this.addSql( + 'alter table if exists "order_change" add constraint "order_change_order_id_foreign" foreign key ("order_id") references "order" ("id") on update cascade;' + ) + this.addSql( + 'CREATE INDEX IF NOT EXISTS "IDX_order_change_version" ON "order_change" (order_id, version) WHERE deleted_at IS NOT NULL;' + ) + + this.addSql( + 'alter table if exists "order_change_action" alter column "ordering" type bigint using ("ordering"::bigint);' + ) + this.addSql( + 'alter table if exists "order_change_action" alter column "order_change_id" type text using ("order_change_id"::text);' + ) + this.addSql( + 'alter table if exists "order_change_action" alter column "order_change_id" set not null;' + ) + this.addSql( + 'alter table if exists "order_change_action" alter column "ordering" drop default;' + ) + this.addSql( + 'alter table if exists "order_change_action" add constraint "order_change_action_order_change_id_foreign" foreign key ("order_change_id") references "order_change" ("id") on update cascade;' + ) + + this.addSql( + 'alter table if exists "return_reason" alter column "parent_return_reason_id" type text using ("parent_return_reason_id"::text);' + ) + this.addSql( + 'alter table if exists "return_reason" alter column "parent_return_reason_id" set not null;' + ) + this.addSql( + 'alter table if exists "return_reason" add constraint "return_reason_parent_return_reason_id_foreign" foreign key ("parent_return_reason_id") references "return_reason" ("id") on update cascade;' + ) + + this.addSql( + 'alter table if exists "return_item" add constraint "return_item_return_id_foreign" foreign key ("return_id") references "return" ("id") on update cascade;' + ) + + this.addSql(` + ALTER TABLE "order_address" + ADD COLUMN if NOT exists "deleted_at" timestamptz NULL; + `) + } + + async down(): Promise { + this.addSql( + 'alter table if exists "order_line_item_adjustment" drop constraint if exists "order_line_item_adjustment_item_id_foreign";' + ) + + this.addSql( + 'alter table if exists "order_line_item_tax_line" drop constraint if exists "order_line_item_tax_line_item_id_foreign";' + ) + + this.addSql( + 'alter table if exists "order_shipping_method_adjustment" drop constraint if exists "order_shipping_method_adjustment_shipping_method_id_foreign";' + ) + + this.addSql( + 'alter table if exists "order_shipping_method_tax_line" drop constraint if exists "order_shipping_method_tax_line_shipping_method_id_foreign";' + ) + + this.addSql( + 'alter table if exists "order_summary" drop constraint if exists "order_summary_order_id_foreign";' + ) + + this.addSql( + 'alter table if exists "return" drop constraint if exists "return_exchange_id_foreign";' + ) + this.addSql( + 'alter table if exists "return" drop constraint if exists "return_claim_id_foreign";' + ) + + this.addSql( + 'alter table if exists "order_exchange_item" drop constraint if exists "order_exchange_item_exchange_id_foreign";' + ) + + this.addSql( + 'alter table if exists "order_transaction" drop constraint if exists "order_transaction_order_id_foreign";' + ) + this.addSql( + 'alter table if exists "order_transaction" drop constraint if exists "order_transaction_return_id_foreign";' + ) + this.addSql( + 'alter table if exists "order_transaction" drop constraint if exists "order_transaction_exchange_id_foreign";' + ) + this.addSql( + 'alter table if exists "order_transaction" drop constraint if exists "order_transaction_claim_id_foreign";' + ) + + this.addSql( + 'alter table if exists "order_claim_item" drop constraint if exists "order_claim_item_claim_id_foreign";' + ) + + this.addSql( + 'alter table if exists "order_change" drop constraint if exists "order_change_status_check";' + ) + + this.addSql( + 'alter table if exists "order_change" drop constraint if exists "order_change_order_id_foreign";' + ) + + this.addSql( + 'alter table if exists "order_change_action" drop constraint if exists "order_change_action_order_change_id_foreign";' + ) + + this.addSql( + 'alter table if exists "return_reason" drop constraint if exists "return_reason_parent_return_reason_id_foreign";' + ) + + this.addSql( + 'alter table if exists "return_item" drop constraint if exists "return_item_return_id_foreign";' + ) + + this.addSql('drop index if exists "IDX_order_address_deleted_at";') + this.addSql( + 'alter table if exists "order_address" drop column if exists "deleted_at";' + ) + + this.addSql( + 'alter table if exists "order" alter column "display_id" type int using ("display_id"::int);' + ) + this.addSql( + 'alter table if exists "order" alter column "display_id" set not null;' + ) + this.addSql('drop index if exists "IDX_order_sales_channel_id";') + this.addSql('create sequence if not exists "order_display_id_seq";') + this.addSql( + 'select setval(\'order_display_id_seq\', (select max("display_id") from "order"));' + ) + this.addSql( + 'alter table if exists "order" alter column "display_id" set default nextval(\'order_display_id_seq\');' + ) + + this.addSql( + 'alter table if exists "order_line_item" alter column "is_tax_inclusive" drop default;' + ) + this.addSql( + 'alter table if exists "order_line_item" alter column "is_tax_inclusive" type boolean using ("is_tax_inclusive"::boolean);' + ) + this.addSql( + 'alter table if exists "order_line_item" alter column "unit_price" type numeric using ("unit_price"::numeric);' + ) + this.addSql( + 'alter table if exists "order_line_item" alter column "unit_price" drop not null;' + ) + + this.addSql( + 'alter table if exists "order_item" alter column "fulfilled_quantity" drop default;' + ) + this.addSql( + 'alter table if exists "order_item" alter column "fulfilled_quantity" type numeric using ("fulfilled_quantity"::numeric);' + ) + this.addSql( + 'alter table if exists "order_item" alter column "delivered_quantity" drop default;' + ) + this.addSql( + 'alter table if exists "order_item" alter column "delivered_quantity" type numeric using ("delivered_quantity"::numeric);' + ) + this.addSql( + 'alter table if exists "order_item" alter column "shipped_quantity" drop default;' + ) + this.addSql( + 'alter table if exists "order_item" alter column "shipped_quantity" type numeric using ("shipped_quantity"::numeric);' + ) + this.addSql( + 'alter table if exists "order_item" alter column "return_requested_quantity" drop default;' + ) + this.addSql( + 'alter table if exists "order_item" alter column "return_requested_quantity" type numeric using ("return_requested_quantity"::numeric);' + ) + this.addSql( + 'alter table if exists "order_item" alter column "return_received_quantity" drop default;' + ) + this.addSql( + 'alter table if exists "order_item" alter column "return_received_quantity" type numeric using ("return_received_quantity"::numeric);' + ) + this.addSql( + 'alter table if exists "order_item" alter column "return_dismissed_quantity" drop default;' + ) + this.addSql( + 'alter table if exists "order_item" alter column "return_dismissed_quantity" type numeric using ("return_dismissed_quantity"::numeric);' + ) + this.addSql( + 'alter table if exists "order_item" alter column "written_off_quantity" drop default;' + ) + this.addSql( + 'alter table if exists "order_item" alter column "written_off_quantity" type numeric using ("written_off_quantity"::numeric);' + ) + + this.addSql( + 'drop index if exists "IDX_order_line_item_adjustment_deleted_at";' + ) + this.addSql('drop index if exists "ItemIdIndex";') + this.addSql( + 'alter table if exists "order_line_item_adjustment" add constraint "order_line_item_adjustment_item_id_foreign" foreign key ("item_id") references "order_line_item" ("id") on update cascade on delete cascade;' + ) + + this.addSql( + 'alter table if exists "order_line_item_tax_line" alter column "item_id" type text using ("item_id"::text);' + ) + this.addSql( + 'alter table if exists "order_line_item_tax_line" alter column "item_id" drop not null;' + ) + this.addSql( + 'drop index if exists "IDX_order_line_item_tax_line_deleted_at";' + ) + this.addSql('drop index if exists "ItemIdIndex";') + this.addSql( + 'alter table if exists "order_line_item_tax_line" add constraint "order_line_item_tax_line_item_id_foreign" foreign key ("item_id") references "order_line_item" ("id") on update cascade on delete cascade;' + ) + + this.addSql( + 'alter table if exists "order_shipping_method" alter column "is_tax_inclusive" type boolean using ("is_tax_inclusive"::boolean);' + ) + this.addSql( + 'alter table if exists "order_shipping_method" alter column "is_tax_inclusive" set default false;' + ) + this.addSql( + 'alter table if exists "order_shipping_method" alter column "is_custom_amount" type boolean using ("is_custom_amount"::boolean);' + ) + this.addSql( + 'alter table if exists "order_shipping_method" alter column "is_custom_amount" set default false;' + ) + + this.addSql( + 'drop index if exists "IDX_order_shipping_method_adjustment_deleted_at";' + ) + this.addSql( + 'alter table if exists "order_shipping_method_adjustment" add constraint "order_shipping_method_adjustment_shipping_method_id_foreign" foreign key ("shipping_method_id") references "order_shipping_method" ("id") on update cascade on delete cascade;' + ) + + this.addSql( + 'drop index if exists "IDX_order_shipping_method_tax_line_deleted_at";' + ) + this.addSql( + 'alter table if exists "order_shipping_method_tax_line" add constraint "order_shipping_method_tax_line_shipping_method_id_foreign" foreign key ("shipping_method_id") references "order_shipping_method" ("id") on update cascade on delete cascade;' + ) + + this.addSql('drop index if exists "IDX_order_summary_order_id";') + this.addSql( + 'alter table if exists "order_summary" add constraint "order_summary_order_id_foreign" foreign key ("order_id") references "order" ("id") on update cascade on delete cascade;' + ) + + this.addSql( + 'alter table if exists "return" alter column "display_id" type int using ("display_id"::int);' + ) + this.addSql( + 'alter table if exists "return" alter column "exchange_id" type text using ("exchange_id"::text);' + ) + this.addSql( + 'alter table if exists "return" alter column "exchange_id" drop not null;' + ) + this.addSql( + 'alter table if exists "return" alter column "claim_id" type text using ("claim_id"::text);' + ) + this.addSql( + 'alter table if exists "return" alter column "claim_id" drop not null;' + ) + this.addSql('create sequence if not exists "return_display_id_seq";') + this.addSql( + 'select setval(\'return_display_id_seq\', (select max("display_id") from "return"));' + ) + this.addSql( + 'alter table if exists "return" alter column "display_id" set default nextval(\'return_display_id_seq\');' + ) + this.addSql( + 'alter table if exists "return" add constraint "return_exchange_id_foreign" foreign key ("exchange_id") references "order_exchange" ("id") on update cascade on delete set null;' + ) + this.addSql( + 'alter table if exists "return" add constraint "return_claim_id_foreign" foreign key ("claim_id") references "order_claim" ("id") on update cascade on delete set null;' + ) + this.addSql( + 'alter table if exists "return" add constraint "return_exchange_id_unique" unique ("exchange_id");' + ) + this.addSql( + 'alter table if exists "return" add constraint "return_claim_id_unique" unique ("claim_id");' + ) + + this.addSql( + 'alter table if exists "order_exchange" alter column "display_id" type int using ("display_id"::int);' + ) + this.addSql( + 'create sequence if not exists "order_exchange_display_id_seq";' + ) + this.addSql( + 'select setval(\'order_exchange_display_id_seq\', (select max("display_id") from "order_exchange"));' + ) + this.addSql( + 'alter table if exists "order_exchange" alter column "display_id" set default nextval(\'order_exchange_display_id_seq\');' + ) + this.addSql( + 'alter table if exists "order_exchange" add constraint "order_exchange_return_id_foreign" foreign key ("return_id") references "return" ("id") on update cascade on delete set null;' + ) + this.addSql( + 'alter table if exists "order_exchange" add constraint "order_exchange_return_id_unique" unique ("return_id");' + ) + + this.addSql('drop index if exists "IDX_order_exchange_item_deleted_at";') + this.addSql( + 'alter table if exists "order_exchange_item" add constraint "order_exchange_item_exchange_id_foreign" foreign key ("exchange_id") references "order_exchange" ("id") on update cascade on delete cascade;' + ) + this.addSql( + 'CREATE INDEX IF NOT EXISTS "IDX_order_claim_item_image_deleted_at" ON "order_claim_item_image" (deleted_at) WHERE deleted_at IS NOT NULL;' + ) + + this.addSql( + 'alter table if exists "order_claim" alter column "display_id" type int using ("display_id"::int);' + ) + this.addSql('create sequence if not exists "order_claim_display_id_seq";') + this.addSql( + 'select setval(\'order_claim_display_id_seq\', (select max("display_id") from "order_claim"));' + ) + this.addSql( + 'alter table if exists "order_claim" alter column "display_id" set default nextval(\'order_claim_display_id_seq\');' + ) + this.addSql( + 'alter table if exists "order_claim" add constraint "order_claim_return_id_foreign" foreign key ("return_id") references "return" ("id") on update cascade on delete set null;' + ) + this.addSql( + 'alter table if exists "order_claim" add constraint "order_claim_return_id_unique" unique ("return_id");' + ) + + this.addSql( + 'alter table if exists "order_transaction" alter column "return_id" type text using ("return_id"::text);' + ) + this.addSql( + 'alter table if exists "order_transaction" alter column "return_id" drop not null;' + ) + this.addSql( + 'alter table if exists "order_transaction" alter column "exchange_id" type text using ("exchange_id"::text);' + ) + this.addSql( + 'alter table if exists "order_transaction" alter column "exchange_id" drop not null;' + ) + this.addSql( + 'alter table if exists "order_transaction" alter column "claim_id" type text using ("claim_id"::text);' + ) + this.addSql( + 'alter table if exists "order_transaction" alter column "claim_id" drop not null;' + ) + this.addSql( + 'alter table if exists "order_transaction" add constraint "order_transaction_order_id_foreign" foreign key ("order_id") references "order" ("id") on update cascade on delete cascade;' + ) + this.addSql( + 'alter table if exists "order_transaction" add constraint "order_transaction_return_id_foreign" foreign key ("return_id") references "return" ("id") on update cascade on delete set null;' + ) + this.addSql( + 'alter table if exists "order_transaction" add constraint "order_transaction_exchange_id_foreign" foreign key ("exchange_id") references "order_exchange" ("id") on update cascade on delete set null;' + ) + this.addSql( + 'alter table if exists "order_transaction" add constraint "order_transaction_claim_id_foreign" foreign key ("claim_id") references "order_claim" ("id") on update cascade on delete set null;' + ) + + this.addSql( + 'alter table if exists "order_claim_item" add constraint "order_claim_item_claim_id_foreign" foreign key ("claim_id") references "order_claim" ("id") on update cascade on delete cascade;' + ) + + this.addSql( + 'alter table if exists "order_change" alter column "status" type text using ("status"::text);' + ) + this.addSql( + "alter table if exists \"order_change\" add constraint \"order_change_status_check\" check (\"status\" in ('confirmed', 'declined', 'requested', 'pending', 'canceled'));" + ) + this.addSql( + 'alter table if exists "order_change" alter column "status" set not null;' + ) + this.addSql( + 'alter table if exists "order_change" alter column "created_by" type text using ("created_by"::text);' + ) + this.addSql( + 'alter table if exists "order_change" alter column "created_by" drop not null;' + ) + this.addSql('drop index if exists "IDX_order_change_version";') + this.addSql( + 'alter table if exists "order_change" add constraint "order_change_order_id_foreign" foreign key ("order_id") references "order" ("id") on update cascade on delete cascade;' + ) + this.addSql( + 'CREATE INDEX IF NOT EXISTS "IDX_order_change_order_id_version" ON "order_change" (order_id, version) WHERE deleted_at IS NOT NULL;' + ) + + this.addSql( + 'alter table if exists "order_change_action" alter column "ordering" type integer using ("ordering"::integer);' + ) + this.addSql( + 'alter table if exists "order_change_action" alter column "order_change_id" type text using ("order_change_id"::text);' + ) + this.addSql( + 'alter table if exists "order_change_action" alter column "order_change_id" drop not null;' + ) + this.addSql( + 'create sequence if not exists "order_change_action_ordering_seq";' + ) + this.addSql( + 'select setval(\'order_change_action_ordering_seq\', (select max("ordering") from "order_change_action"));' + ) + this.addSql( + 'alter table if exists "order_change_action" alter column "ordering" set default nextval(\'order_change_action_ordering_seq\');' + ) + this.addSql( + 'alter table if exists "order_change_action" add constraint "order_change_action_order_id_foreign" foreign key ("order_id") references "order" ("id") on update cascade on delete cascade;' + ) + this.addSql( + 'alter table if exists "order_change_action" add constraint "order_change_action_return_id_foreign" foreign key ("return_id") references "return" ("id") on update cascade on delete set null;' + ) + this.addSql( + 'alter table if exists "order_change_action" add constraint "order_change_action_claim_id_foreign" foreign key ("claim_id") references "order_claim" ("id") on update cascade on delete set null;' + ) + this.addSql( + 'alter table if exists "order_change_action" add constraint "order_change_action_exchange_id_foreign" foreign key ("exchange_id") references "order_exchange" ("id") on update cascade on delete set null;' + ) + this.addSql( + 'alter table if exists "order_change_action" add constraint "order_change_action_order_change_id_foreign" foreign key ("order_change_id") references "order_change" ("id") on update cascade on delete cascade;' + ) + + this.addSql( + 'alter table if exists "return_reason" alter column "parent_return_reason_id" type text using ("parent_return_reason_id"::text);' + ) + this.addSql( + 'alter table if exists "return_reason" alter column "parent_return_reason_id" drop not null;' + ) + this.addSql( + 'alter table if exists "return_reason" add constraint "return_reason_parent_return_reason_id_foreign" foreign key ("parent_return_reason_id") references "return_reason" ("id") on update cascade on delete set null;' + ) + + this.addSql( + 'alter table if exists "return_item" add constraint "return_item_return_id_foreign" foreign key ("return_id") references "return" ("id") on update cascade on delete cascade;' + ) + + this.addSql(` + ALTER TABLE "order_address" DROP COLUMN if exists "deleted_at"; + `) + } +} diff --git a/packages/modules/order/src/models/address.ts b/packages/modules/order/src/models/address.ts index 62a2519ac24e2..681326affff30 100644 --- a/packages/modules/order/src/models/address.ts +++ b/packages/modules/order/src/models/address.ts @@ -1,8 +1,6 @@ import { model } from "@medusajs/framework/utils" import { Order } from "./order" -const CustomerIdIndex = "IDX_order_address_customer_id" - const _OrderAddress = model .define("OrderAddress", { id: model.id({ prefix: "ordaddr" }).primaryKey(), @@ -24,7 +22,7 @@ const _OrderAddress = model }) .indexes([ { - name: CustomerIdIndex, + name: "IDX_order_address_customer_id", on: ["customer_id"], unique: false, }, diff --git a/packages/modules/order/src/models/order.ts b/packages/modules/order/src/models/order.ts index db5c70b652179..4979760a39e8e 100644 --- a/packages/modules/order/src/models/order.ts +++ b/packages/modules/order/src/models/order.ts @@ -14,6 +14,7 @@ import { NumberProperty, OrderStatus, PrimaryKeyModifier, + RelationNullableModifier, TextProperty, } from "@medusajs/framework/utils" import { OrderAddress } from "./address" @@ -44,8 +45,14 @@ type OrderSchema = { claims: HasMany returns: HasMany changes: HasMany - shipping_address: BelongsTo - billing_address: BelongsTo + shipping_address: RelationNullableModifier< + typeof OrderAddress, + BelongsTo + > + billing_address: RelationNullableModifier< + typeof OrderAddress, + BelongsTo + > summary: HasMany items: HasMany shipping_methods: HasMany @@ -77,8 +84,8 @@ const _Order = model mappedBy: "order", }), changes: model.hasMany(() => OrderChange), - shipping_address: model.belongsTo(() => OrderAddress), - billing_address: model.belongsTo(() => OrderAddress), + shipping_address: model.belongsTo(() => OrderAddress).nullable(), + billing_address: model.belongsTo(() => OrderAddress).nullable(), summary: model.hasMany(() => OrderSummary, { mappedBy: "order", }), From 903f585a831f6644efdcb8b468b478f20380ca69 Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Wed, 27 Nov 2024 15:56:18 -0300 Subject: [PATCH 097/175] repository --- .../src/migrations/.snapshot-medusa-order.json | 12 ++---------- ...0241127171653.ts => Migration20241127185510.ts} | 14 ++++++-------- .../order/src/models/line-item-adjustment.ts | 2 +- .../modules/order/src/models/line-item-tax-line.ts | 2 +- packages/modules/order/src/repositories/claim.ts | 7 ++++++- .../modules/order/src/repositories/exchange.ts | 7 ++++++- packages/modules/order/src/repositories/order.ts | 7 ++++++- packages/modules/order/src/repositories/return.ts | 7 ++++++- .../order/src/utils/base-repository-find.ts | 10 ++++++---- 9 files changed, 40 insertions(+), 28 deletions(-) rename packages/modules/order/src/migrations/{Migration20241127171653.ts => Migration20241127185510.ts} (98%) diff --git a/packages/modules/order/src/migrations/.snapshot-medusa-order.json b/packages/modules/order/src/migrations/.snapshot-medusa-order.json index fd19b1d587297..8d8549bcd49f2 100644 --- a/packages/modules/order/src/migrations/.snapshot-medusa-order.json +++ b/packages/modules/order/src/migrations/.snapshot-medusa-order.json @@ -2307,12 +2307,12 @@ "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_line_item_adjustment_deleted_at\" ON \"order_line_item_adjustment\" (deleted_at) WHERE deleted_at IS NULL" }, { - "keyName": "ItemIdIndex", + "keyName": "IDX_order_order_line_item_adjustment_item_id", "columnNames": [], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"ItemIdIndex\" ON \"order_line_item_adjustment\" (item_id) WHERE deleted_at IS NULL" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_order_line_item_adjustment_item_id\" ON \"order_line_item_adjustment\" (item_id) WHERE deleted_at IS NULL" }, { "keyName": "order_line_item_adjustment_pkey", @@ -2466,14 +2466,6 @@ "unique": false, "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_line_item_tax_line_deleted_at\" ON \"order_line_item_tax_line\" (deleted_at) WHERE deleted_at IS NULL" }, - { - "keyName": "ItemIdIndex", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"ItemIdIndex\" ON \"order_line_item_tax_line\" (item_id) WHERE deleted_at IS NULL" - }, { "keyName": "order_line_item_tax_line_pkey", "columnNames": [ diff --git a/packages/modules/order/src/migrations/Migration20241127171653.ts b/packages/modules/order/src/migrations/Migration20241127185510.ts similarity index 98% rename from packages/modules/order/src/migrations/Migration20241127171653.ts rename to packages/modules/order/src/migrations/Migration20241127185510.ts index 36d1a766dc5b3..cc6e3485e65e3 100644 --- a/packages/modules/order/src/migrations/Migration20241127171653.ts +++ b/packages/modules/order/src/migrations/Migration20241127185510.ts @@ -1,6 +1,6 @@ import { Migration } from "@mikro-orm/migrations" -export class Migration20241127171653 extends Migration { +export class Migration20241127185510 extends Migration { async up(): Promise { this.addSql( 'alter table if exists "order_claim" drop constraint if exists "order_claim_return_id_foreign";' @@ -217,7 +217,7 @@ export class Migration20241127171653 extends Migration { 'CREATE INDEX IF NOT EXISTS "IDX_order_line_item_adjustment_deleted_at" ON "order_line_item_adjustment" (deleted_at) WHERE deleted_at IS NULL;' ) this.addSql( - 'CREATE INDEX IF NOT EXISTS "ItemIdIndex" ON "order_line_item_adjustment" (item_id) WHERE deleted_at IS NULL;' + 'CREATE INDEX IF NOT EXISTS "IDX_order_order_line_item_adjustment_item_id" ON "order_line_item_adjustment" (item_id) WHERE deleted_at IS NULL;' ) this.addSql( @@ -232,9 +232,6 @@ export class Migration20241127171653 extends Migration { this.addSql( 'CREATE INDEX IF NOT EXISTS "IDX_order_line_item_tax_line_deleted_at" ON "order_line_item_tax_line" (deleted_at) WHERE deleted_at IS NULL;' ) - this.addSql( - 'CREATE INDEX IF NOT EXISTS "ItemIdIndex" ON "order_line_item_tax_line" (item_id) WHERE deleted_at IS NULL;' - ) this.addSql( 'alter table if exists "order_shipping_method" alter column "is_tax_inclusive" drop default;' @@ -539,7 +536,9 @@ export class Migration20241127171653 extends Migration { this.addSql( 'drop index if exists "IDX_order_line_item_adjustment_deleted_at";' ) - this.addSql('drop index if exists "ItemIdIndex";') + this.addSql( + 'drop index if exists "IDX_order_order_line_item_adjustment_item_id";' + ) this.addSql( 'alter table if exists "order_line_item_adjustment" add constraint "order_line_item_adjustment_item_id_foreign" foreign key ("item_id") references "order_line_item" ("id") on update cascade on delete cascade;' ) @@ -553,7 +552,6 @@ export class Migration20241127171653 extends Migration { this.addSql( 'drop index if exists "IDX_order_line_item_tax_line_deleted_at";' ) - this.addSql('drop index if exists "ItemIdIndex";') this.addSql( 'alter table if exists "order_line_item_tax_line" add constraint "order_line_item_tax_line_item_id_foreign" foreign key ("item_id") references "order_line_item" ("id") on update cascade on delete cascade;' ) @@ -776,7 +774,7 @@ export class Migration20241127171653 extends Migration { ) this.addSql(` - ALTER TABLE "order_address" DROP COLUMN if exists "deleted_at"; + ALTER TABLE "order_address" DROP COLUMN if exists "deleted_at" timestamptz NULL; `) } } diff --git a/packages/modules/order/src/models/line-item-adjustment.ts b/packages/modules/order/src/models/line-item-adjustment.ts index bcc32a8af4f75..8808b9c193f22 100644 --- a/packages/modules/order/src/models/line-item-adjustment.ts +++ b/packages/modules/order/src/models/line-item-adjustment.ts @@ -15,7 +15,7 @@ const _OrderLineItemAdjustment = model }) .indexes([ { - name: "ItemIdIndex", + name: "IDX_order_order_line_item_adjustment_item_id", on: ["item_id"], unique: false, }, diff --git a/packages/modules/order/src/models/line-item-tax-line.ts b/packages/modules/order/src/models/line-item-tax-line.ts index f8158723634e2..89436072aa662 100644 --- a/packages/modules/order/src/models/line-item-tax-line.ts +++ b/packages/modules/order/src/models/line-item-tax-line.ts @@ -15,7 +15,7 @@ const _OrderLineItemTaxLine = model }) .indexes([ { - name: "ItemIdIndex", + name: "IDX_order_line_item_tax_line_item_id", on: ["item_id"], unique: false, }, diff --git a/packages/modules/order/src/repositories/claim.ts b/packages/modules/order/src/repositories/claim.ts index 142528f4073b9..51a25fc562b76 100644 --- a/packages/modules/order/src/repositories/claim.ts +++ b/packages/modules/order/src/repositories/claim.ts @@ -4,6 +4,11 @@ import { setFindMethods } from "../utils/base-repository-find" export class OrderClaimRepository extends DALUtils.mikroOrmBaseRepositoryFactory( OrderClaim -) {} +) { + constructor(...args: any[]) { + // @ts-ignore + super(...arguments) + } +} setFindMethods(OrderClaimRepository, OrderClaim) diff --git a/packages/modules/order/src/repositories/exchange.ts b/packages/modules/order/src/repositories/exchange.ts index 915552bdf9488..a99d9a1e1f59b 100644 --- a/packages/modules/order/src/repositories/exchange.ts +++ b/packages/modules/order/src/repositories/exchange.ts @@ -4,6 +4,11 @@ import { setFindMethods } from "../utils/base-repository-find" export class OrderExchangeRepository extends DALUtils.mikroOrmBaseRepositoryFactory( OrderExchange -) {} +) { + constructor(...args: any[]) { + // @ts-ignore + super(...arguments) + } +} setFindMethods(OrderExchangeRepository, OrderExchange) diff --git a/packages/modules/order/src/repositories/order.ts b/packages/modules/order/src/repositories/order.ts index 84fd45ebc7dff..c3b0b42cfdbfe 100644 --- a/packages/modules/order/src/repositories/order.ts +++ b/packages/modules/order/src/repositories/order.ts @@ -4,6 +4,11 @@ import { setFindMethods } from "../utils/base-repository-find" export class OrderRepository extends DALUtils.mikroOrmBaseRepositoryFactory( Order -) {} +) { + constructor(...args: any[]) { + // @ts-ignore + super(...arguments) + } +} setFindMethods(OrderRepository, Order) diff --git a/packages/modules/order/src/repositories/return.ts b/packages/modules/order/src/repositories/return.ts index 00f407a8198f3..2ac15f6fe41b9 100644 --- a/packages/modules/order/src/repositories/return.ts +++ b/packages/modules/order/src/repositories/return.ts @@ -4,6 +4,11 @@ import { setFindMethods } from "../utils/base-repository-find" export class ReturnRepository extends DALUtils.mikroOrmBaseRepositoryFactory( Return -) {} +) { + constructor(...args: any[]) { + // @ts-ignore + super(...arguments) + } +} setFindMethods(ReturnRepository, Return) diff --git a/packages/modules/order/src/utils/base-repository-find.ts b/packages/modules/order/src/utils/base-repository-find.ts index 7055f57659940..ca0100359da04 100644 --- a/packages/modules/order/src/utils/base-repository-find.ts +++ b/packages/modules/order/src/utils/base-repository-find.ts @@ -9,7 +9,8 @@ export function setFindMethods(klass: Constructor, entity: any) { options?: DAL.FindOptions, context?: Context ): Promise { - const manager = this.getActiveManager(context) + // @ts-expect-error + const manager = super.getActiveManager(context) const knex = manager.getKnex() const findOptions_ = { ...options } as any @@ -113,7 +114,7 @@ export function setFindMethods(klass: Constructor, entity: any) { config.where ??= {} config.where.deleted_at ??= null - return await manager.find(entity, config.where, config.options) + return await manager.find(entity.name, config.where, config.options) } klass.prototype.findAndCount = async function findAndCount( @@ -121,7 +122,8 @@ export function setFindMethods(klass: Constructor, entity: any) { findOptions: DAL.FindOptions = { where: {} } as DAL.FindOptions, context: Context = {} ): Promise<[T[], number]> { - const manager = this.getActiveManager(context) + // @ts-expect-error + const manager = super.getActiveManager(context) const knex = manager.getKnex() const findOptions_ = { ...findOptions } as any @@ -198,6 +200,6 @@ export function setFindMethods(klass: Constructor, entity: any) { config.options.orderBy = { id: "ASC" } } - return await manager.findAndCount(entity, config.where, config.options) + return await manager.findAndCount(entity.name, config.where, config.options) } } From b793dc977f8597b4ec0ccad31c7cf65507a31f5d Mon Sep 17 00:00:00 2001 From: adrien2p Date: Thu, 28 Nov 2024 12:44:30 +0100 Subject: [PATCH 098/175] update default value handling --- .../dml/helpers/create-mikro-orm-entity.ts | 20 +--------------- .../helpers/entity-builder/define-property.ts | 24 ++++++++++++------- 2 files changed, 16 insertions(+), 28 deletions(-) diff --git a/packages/core/utils/src/dml/helpers/create-mikro-orm-entity.ts b/packages/core/utils/src/dml/helpers/create-mikro-orm-entity.ts index da5c7bdcd773d..2d45c75873a8a 100644 --- a/packages/core/utils/src/dml/helpers/create-mikro-orm-entity.ts +++ b/packages/core/utils/src/dml/helpers/create-mikro-orm-entity.ts @@ -8,7 +8,6 @@ import type { } from "@medusajs/types" import { Entity, Filter } from "@mikro-orm/core" -import { isDefined } from "../../common" import { mikroOrmSoftDeletableFilterOptions } from "../../dal" import { DmlEntity } from "../entity" import { DuplicateIdPropertyError } from "../errors" @@ -46,24 +45,7 @@ function createMikrORMEntity() { * DML entity. */ function createEntity>(entity: T): Infer { - class MikroORMEntity { - static __defaultValues = {} - static setDefaultValue(key: string, value: any) { - this.__defaultValues[key] = value - } - - constructor() { - Object.entries(MikroORMEntity.__defaultValues).forEach( - ([key, value]) => { - if (isDefined(this[key])) { - return - } - - this[key] = value - } - ) - } - } + class MikroORMEntity {} const { schema, cascades, indexes: entityIndexes = [] } = entity.parse() const { modelName, tableName } = parseEntityName(entity) diff --git a/packages/core/utils/src/dml/helpers/entity-builder/define-property.ts b/packages/core/utils/src/dml/helpers/entity-builder/define-property.ts index 4f562ba1cd561..d63d19cf26cf5 100644 --- a/packages/core/utils/src/dml/helpers/entity-builder/define-property.ts +++ b/packages/core/utils/src/dml/helpers/entity-builder/define-property.ts @@ -119,18 +119,24 @@ export function defineProperty( ) { const field = property.parse(propertyName) /** - * Here we initialize all properties with their default values + * Here we initialize all properties with their default values on before create + * which means when persist is called but not necessarely flush */ if (isDefined(field.defaultValue) || field.nullable) { - ;(MikroORMEntity as any).setDefaultValue( - propertyName, - isDefined(field.defaultValue) - ? field.defaultValue - : field.nullable - ? null - : undefined - ) + const defaultValueSetterHookName = `${field.fieldName}_setDefaultValueOnBeforeCreate` + MikroORMEntity.prototype[defaultValueSetterHookName] = function () { + if (isDefined(field.defaultValue)) { + this[propertyName] = field.defaultValue + return + } + + if (field.nullable) { + this[propertyName] = null + return + } + } + BeforeCreate()(MikroORMEntity.prototype, defaultValueSetterHookName) } if (SPECIAL_PROPERTIES[field.fieldName]) { From 45e4dfc6f476a6bdb776f24352d2579c45999cd1 Mon Sep 17 00:00:00 2001 From: adrien2p Date: Thu, 28 Nov 2024 14:07:25 +0100 Subject: [PATCH 099/175] fix unit tests --- .../src/dml/__tests__/entity-builder.spec.ts | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts b/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts index 7ba29d7fa4e0f..9772492c66b14 100644 --- a/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts +++ b/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts @@ -755,10 +755,10 @@ describe("Entity builder", () => { const userInstance = new User() - expect(userInstance.username).toEqual(null) + expect(userInstance.username).toEqual(undefined) expect(userInstance.spend_limit).toEqual(undefined) - expect(userInstance.raw_spend_limit).toEqual(null) + expect(userInstance.raw_spend_limit).toEqual(undefined) userInstance.username = "john" expect(userInstance.username).toEqual("john") @@ -1121,7 +1121,7 @@ describe("Entity builder", () => { const metaData = MetadataStorage.getMetadataFromDecorator(User) const userInstance = new User() - expect(userInstance.role).toEqual(null) + expect(userInstance.role).toEqual(undefined) userInstance.role = "admin" expect(userInstance.role).toEqual("admin") @@ -1578,7 +1578,10 @@ describe("Entity builder", () => { expect(metaData.path).toEqual("User") expect(metaData.hooks).toEqual({ - beforeCreate: ["generateId"], + beforeCreate: [ + "generateId", + "deleted_at_setDefaultValueOnBeforeCreate", + ], onInit: ["generateId"], }) @@ -1685,7 +1688,10 @@ describe("Entity builder", () => { expect(metaData.path).toEqual("User") expect(metaData.hooks).toEqual({ - beforeCreate: ["generateId"], + beforeCreate: [ + "generateId", + "deleted_at_setDefaultValueOnBeforeCreate", + ], onInit: ["generateId"], }) @@ -1793,7 +1799,10 @@ describe("Entity builder", () => { expect(metaData.path).toEqual("User") expect(metaData.hooks).toEqual({ - beforeCreate: ["generateId"], + beforeCreate: [ + "generateId", + "deleted_at_setDefaultValueOnBeforeCreate", + ], onInit: ["generateId"], }) From 7bdfbb1c41e18c3cb40864cc04e05b87708c11a5 Mon Sep 17 00:00:00 2001 From: adrien2p Date: Thu, 28 Nov 2024 15:00:53 +0100 Subject: [PATCH 100/175] WIP --- .../src/loaders/utils/load-internal.ts | 2 +- .../integration-tests/__tests__/order-claim.ts | 2 +- packages/modules/order/package.json | 2 +- .../order/src/utils/base-repository-find.ts | 15 +++++++-------- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/packages/core/modules-sdk/src/loaders/utils/load-internal.ts b/packages/core/modules-sdk/src/loaders/utils/load-internal.ts index 7782ca6d52b49..0309dfb3de657 100644 --- a/packages/core/modules-sdk/src/loaders/utils/load-internal.ts +++ b/packages/core/modules-sdk/src/loaders/utils/load-internal.ts @@ -559,7 +559,7 @@ export async function loadResources({ normalizedPath = resolve(normalizedPath) try { - const defaultOnFail = () => { + const defaultOnFail = (e) => { return [] } diff --git a/packages/modules/order/integration-tests/__tests__/order-claim.ts b/packages/modules/order/integration-tests/__tests__/order-claim.ts index 9a5badaa58efd..7e21175c0622e 100644 --- a/packages/modules/order/integration-tests/__tests__/order-claim.ts +++ b/packages/modules/order/integration-tests/__tests__/order-claim.ts @@ -103,7 +103,7 @@ moduleIntegrationTestRunner({ customer_id: "joe", } as CreateOrderDTO - it("should claim an item and add two new items to the order", async function () { + it.only("should claim an item and add two new items to the order", async function () { const createdOrder = await service.createOrders(input) createdOrder.items = createdOrder.items!.sort((a, b) => a.title.localeCompare(b.title) diff --git a/packages/modules/order/package.json b/packages/modules/order/package.json index e96f4d39cb3c2..8b985e3181d7e 100644 --- a/packages/modules/order/package.json +++ b/packages/modules/order/package.json @@ -29,7 +29,7 @@ "resolve:aliases": "tsc --showConfig -p tsconfig.json > tsconfig.resolved.json && tsc-alias -p tsconfig.resolved.json && rimraf tsconfig.resolved.json", "build": "rimraf dist && tsc --build && npm run resolve:aliases", "test": "jest --runInBand --bail --forceExit -- src/**/__tests__/**/*.ts", - "test:integration": "jest --forceExit -- integration-tests/**/__tests__/**/*.ts", + "test:integration": "jest --forceExit -- integration-tests/__tests__/order-claim.ts", "migration:initial": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm migration:create --initial", "migration:create": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm migration:create", "migration:up": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm migration:up", diff --git a/packages/modules/order/src/utils/base-repository-find.ts b/packages/modules/order/src/utils/base-repository-find.ts index ca0100359da04..5b8dbada4266b 100644 --- a/packages/modules/order/src/utils/base-repository-find.ts +++ b/packages/modules/order/src/utils/base-repository-find.ts @@ -2,6 +2,7 @@ import { Constructor, Context, DAL } from "@medusajs/framework/types" import { LoadStrategy } from "@mikro-orm/core" import { Order, OrderClaim } from "@models" import { mapRepositoryToOrderModel } from "." +import { toMikroORMEntity } from "@medusajs/framework/utils" export function setFindMethods(klass: Constructor, entity: any) { klass.prototype.find = async function find( @@ -9,8 +10,7 @@ export function setFindMethods(klass: Constructor, entity: any) { options?: DAL.FindOptions, context?: Context ): Promise { - // @ts-expect-error - const manager = super.getActiveManager(context) + const manager = this.getActiveManager(context) const knex = manager.getKnex() const findOptions_ = { ...options } as any @@ -66,7 +66,7 @@ export function setFindMethods(klass: Constructor, entity: any) { if (strategy === LoadStrategy.SELECT_IN) { const sql = manager - .qb(Order, "_sub0") + .qb(toMikroORMEntity(Order), "_sub0") .select("version") .where({ id: knex.raw(`"${orderAlias}"."order_id"`) }) .getKnexQuery() @@ -114,7 +114,7 @@ export function setFindMethods(klass: Constructor, entity: any) { config.where ??= {} config.where.deleted_at ??= null - return await manager.find(entity.name, config.where, config.options) + return await manager.find(this.entity, config.where, config.options) } klass.prototype.findAndCount = async function findAndCount( @@ -122,8 +122,7 @@ export function setFindMethods(klass: Constructor, entity: any) { findOptions: DAL.FindOptions = { where: {} } as DAL.FindOptions, context: Context = {} ): Promise<[T[], number]> { - // @ts-expect-error - const manager = super.getActiveManager(context) + const manager = this.getActiveManager(context) const knex = manager.getKnex() const findOptions_ = { ...findOptions } as any @@ -164,7 +163,7 @@ export function setFindMethods(klass: Constructor, entity: any) { const strategy = config.options.strategy ?? LoadStrategy.JOINED if (strategy === LoadStrategy.SELECT_IN) { const sql = manager - .qb(Order, "_sub0") + .qb(toMikroORMEntity(Order), "_sub0") .select("version") .where({ id: knex.raw(`"${orderAlias}"."order_id"`) }) .getKnexQuery() @@ -200,6 +199,6 @@ export function setFindMethods(klass: Constructor, entity: any) { config.options.orderBy = { id: "ASC" } } - return await manager.findAndCount(entity.name, config.where, config.options) + return await manager.findAndCount(this.entity, config.where, config.options) } } From 15f2dcd99400b8cbb42133429d60b0cc1b675ac5 Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Thu, 28 Nov 2024 11:39:53 -0300 Subject: [PATCH 101/175] toMikroORM --- .../src/migrations/Migration20241127185510.ts | 40 ++----------------- packages/modules/order/src/models/claim.ts | 6 +-- .../modules/order/src/models/order-change.ts | 6 +-- .../order/src/models/shipping-method.ts | 4 +- .../modules/order/src/repositories/claim.ts | 7 +--- .../order/src/repositories/exchange.ts | 7 +--- .../modules/order/src/repositories/order.ts | 7 +--- .../modules/order/src/repositories/return.ts | 7 +--- .../src/services/actions/create-claim.ts | 8 ++-- .../src/services/actions/create-exchange.ts | 6 +-- .../src/services/actions/create-return.ts | 5 ++- .../order/src/utils/base-repository-find.ts | 2 +- .../order/src/utils/transform-order.ts | 4 +- 13 files changed, 29 insertions(+), 80 deletions(-) diff --git a/packages/modules/order/src/migrations/Migration20241127185510.ts b/packages/modules/order/src/migrations/Migration20241127185510.ts index cc6e3485e65e3..ea64a0533c2d4 100644 --- a/packages/modules/order/src/migrations/Migration20241127185510.ts +++ b/packages/modules/order/src/migrations/Migration20241127185510.ts @@ -142,12 +142,7 @@ export class Migration20241127185510 extends Migration { this.addSql( 'alter table if exists "order_line_item" alter column "is_discountable" set default true;' ) - this.addSql( - 'alter table if exists "order_line_item" alter column "is_tax_inclusive" type boolean using ("is_tax_inclusive"::boolean);' - ) - this.addSql( - 'alter table if exists "order_line_item" alter column "is_tax_inclusive" set default false;' - ) + this.addSql( 'alter table if exists "order_line_item" alter column "unit_price" type numeric using ("unit_price"::numeric);' ) @@ -233,19 +228,6 @@ export class Migration20241127185510 extends Migration { 'CREATE INDEX IF NOT EXISTS "IDX_order_line_item_tax_line_deleted_at" ON "order_line_item_tax_line" (deleted_at) WHERE deleted_at IS NULL;' ) - this.addSql( - 'alter table if exists "order_shipping_method" alter column "is_tax_inclusive" drop default;' - ) - this.addSql( - 'alter table if exists "order_shipping_method" alter column "is_tax_inclusive" type boolean using ("is_tax_inclusive"::boolean);' - ) - this.addSql( - 'alter table if exists "order_shipping_method" alter column "is_custom_amount" drop default;' - ) - this.addSql( - 'alter table if exists "order_shipping_method" alter column "is_custom_amount" type boolean using ("is_custom_amount"::boolean);' - ) - this.addSql( 'alter table if exists "order_shipping_method_adjustment" add constraint "order_shipping_method_adjustment_shipping_method_id_foreign" foreign key ("shipping_method_id") references "order_shipping_method" ("id") on update cascade;' ) @@ -338,12 +320,7 @@ export class Migration20241127185510 extends Migration { this.addSql( 'alter table if exists "order_change" alter column "status" drop not null;' ) - this.addSql( - 'alter table if exists "order_change" alter column "created_by" type text using ("created_by"::text);' - ) - this.addSql( - 'alter table if exists "order_change" alter column "created_by" set not null;' - ) + this.addSql('drop index if exists "IDX_order_change_order_id_version";') this.addSql( 'alter table if exists "order_change" add constraint "order_change_order_id_foreign" foreign key ("order_id") references "order" ("id") on update cascade;' @@ -562,12 +539,6 @@ export class Migration20241127185510 extends Migration { this.addSql( 'alter table if exists "order_shipping_method" alter column "is_tax_inclusive" set default false;' ) - this.addSql( - 'alter table if exists "order_shipping_method" alter column "is_custom_amount" type boolean using ("is_custom_amount"::boolean);' - ) - this.addSql( - 'alter table if exists "order_shipping_method" alter column "is_custom_amount" set default false;' - ) this.addSql( 'drop index if exists "IDX_order_shipping_method_adjustment_deleted_at";' @@ -711,12 +682,7 @@ export class Migration20241127185510 extends Migration { this.addSql( 'alter table if exists "order_change" alter column "status" set not null;' ) - this.addSql( - 'alter table if exists "order_change" alter column "created_by" type text using ("created_by"::text);' - ) - this.addSql( - 'alter table if exists "order_change" alter column "created_by" drop not null;' - ) + this.addSql('drop index if exists "IDX_order_change_version";') this.addSql( 'alter table if exists "order_change" add constraint "order_change_order_id_foreign" foreign key ("order_id") references "order" ("id") on update cascade on delete cascade;' diff --git a/packages/modules/order/src/models/claim.ts b/packages/modules/order/src/models/claim.ts index 63f12c1b28928..14643c65c4413 100644 --- a/packages/modules/order/src/models/claim.ts +++ b/packages/modules/order/src/models/claim.ts @@ -1,10 +1,10 @@ import { ClaimType, model } from "@medusajs/framework/utils" +import { OrderClaimItem } from "./claim-item" import { Order } from "./order" -import { Return } from "./return" import { OrderChange } from "./order-change" -import { OrderClaimItem } from "./claim-item" -import { OrderTransaction } from "./transaction" import { OrderShipping } from "./order-shipping-method" +import { Return } from "./return" +import { OrderTransaction } from "./transaction" const _OrderClaim = model .define("OrderClaim", { diff --git a/packages/modules/order/src/models/order-change.ts b/packages/modules/order/src/models/order-change.ts index 53e24bcee4d22..18ce0d2d05fc9 100644 --- a/packages/modules/order/src/models/order-change.ts +++ b/packages/modules/order/src/models/order-change.ts @@ -1,9 +1,9 @@ import { model, OrderChangeStatus } from "@medusajs/framework/utils" -import { Order } from "./order" -import { Return } from "./return" import { OrderClaim } from "./claim" import { OrderExchange } from "./exchange" +import { Order } from "./order" import { OrderChangeAction } from "./order-change-action" +import { Return } from "./return" const _OrderChange = model .define("OrderChange", { @@ -16,7 +16,7 @@ const _OrderChange = model .default(OrderChangeStatus.PENDING) .nullable(), internal_note: model.text().nullable(), - created_by: model.text(), + created_by: model.text().nullable(), requested_by: model.text().nullable(), requested_at: model.dateTime().nullable(), confirmed_by: model.text().nullable(), diff --git a/packages/modules/order/src/models/shipping-method.ts b/packages/modules/order/src/models/shipping-method.ts index 052f07396472a..427789a1c24ca 100644 --- a/packages/modules/order/src/models/shipping-method.ts +++ b/packages/modules/order/src/models/shipping-method.ts @@ -9,8 +9,8 @@ const _OrderShippingMethod = model name: model.text(), description: model.json().nullable(), amount: model.bigNumber(), - is_tax_inclusive: model.boolean(), - is_custom_amount: model.boolean(), + is_tax_inclusive: model.boolean().default(false), + is_custom_amount: model.boolean().default(false), shipping_option_id: model.text().nullable(), data: model.json().nullable(), metadata: model.json().nullable(), diff --git a/packages/modules/order/src/repositories/claim.ts b/packages/modules/order/src/repositories/claim.ts index 51a25fc562b76..142528f4073b9 100644 --- a/packages/modules/order/src/repositories/claim.ts +++ b/packages/modules/order/src/repositories/claim.ts @@ -4,11 +4,6 @@ import { setFindMethods } from "../utils/base-repository-find" export class OrderClaimRepository extends DALUtils.mikroOrmBaseRepositoryFactory( OrderClaim -) { - constructor(...args: any[]) { - // @ts-ignore - super(...arguments) - } -} +) {} setFindMethods(OrderClaimRepository, OrderClaim) diff --git a/packages/modules/order/src/repositories/exchange.ts b/packages/modules/order/src/repositories/exchange.ts index a99d9a1e1f59b..915552bdf9488 100644 --- a/packages/modules/order/src/repositories/exchange.ts +++ b/packages/modules/order/src/repositories/exchange.ts @@ -4,11 +4,6 @@ import { setFindMethods } from "../utils/base-repository-find" export class OrderExchangeRepository extends DALUtils.mikroOrmBaseRepositoryFactory( OrderExchange -) { - constructor(...args: any[]) { - // @ts-ignore - super(...arguments) - } -} +) {} setFindMethods(OrderExchangeRepository, OrderExchange) diff --git a/packages/modules/order/src/repositories/order.ts b/packages/modules/order/src/repositories/order.ts index c3b0b42cfdbfe..84fd45ebc7dff 100644 --- a/packages/modules/order/src/repositories/order.ts +++ b/packages/modules/order/src/repositories/order.ts @@ -4,11 +4,6 @@ import { setFindMethods } from "../utils/base-repository-find" export class OrderRepository extends DALUtils.mikroOrmBaseRepositoryFactory( Order -) { - constructor(...args: any[]) { - // @ts-ignore - super(...arguments) - } -} +) {} setFindMethods(OrderRepository, Order) diff --git a/packages/modules/order/src/repositories/return.ts b/packages/modules/order/src/repositories/return.ts index 2ac15f6fe41b9..00f407a8198f3 100644 --- a/packages/modules/order/src/repositories/return.ts +++ b/packages/modules/order/src/repositories/return.ts @@ -4,11 +4,6 @@ import { setFindMethods } from "../utils/base-repository-find" export class ReturnRepository extends DALUtils.mikroOrmBaseRepositoryFactory( Return -) { - constructor(...args: any[]) { - // @ts-ignore - super(...arguments) - } -} +) {} setFindMethods(ReturnRepository, Return) diff --git a/packages/modules/order/src/services/actions/create-claim.ts b/packages/modules/order/src/services/actions/create-claim.ts index 4f260c8d32691..2fb797103e887 100644 --- a/packages/modules/order/src/services/actions/create-claim.ts +++ b/packages/modules/order/src/services/actions/create-claim.ts @@ -16,7 +16,7 @@ import { import { OrderClaim, OrderClaimItem, Return, ReturnItem } from "@models" function createClaimAndReturnEntities(em, data, order) { - const claimReference = em.create(OrderClaim, { + const claimReference = em.create(toMikroORMEntity(OrderClaim), { order_id: data.order_id, order_version: order.version, type: data.type as ClaimType, @@ -26,7 +26,7 @@ function createClaimAndReturnEntities(em, data, order) { const returnReference = data.type === ClaimType.REPLACE - ? em.create(Return, { + ? em.create(toMikroORMEntity(Return), { order_id: data.order_id, order_version: order.version, status: ReturnStatus.REQUESTED, @@ -52,7 +52,7 @@ function createReturnItem(em, item, claimReference, returnReference, actions) { }, }) - return em.create(ReturnItem, { + return em.create(toMikroORMEntity(ReturnItem), { item_id: item.id, return_id: returnReference.id, quantity: item.quantity, @@ -87,7 +87,7 @@ function createClaimAndReturnItems( : undefined ) - return em.create(OrderClaimItem, { + return em.create(toMikroORMEntity(OrderClaimItem), { item_id: item.id, reason: item.reason, quantity: item.quantity, diff --git a/packages/modules/order/src/services/actions/create-exchange.ts b/packages/modules/order/src/services/actions/create-exchange.ts index 5af2d864d66a6..2db2e52a05084 100644 --- a/packages/modules/order/src/services/actions/create-exchange.ts +++ b/packages/modules/order/src/services/actions/create-exchange.ts @@ -15,7 +15,7 @@ import { import { OrderExchange, OrderExchangeItem, Return, ReturnItem } from "@models" function createExchangeAndReturnEntities(em, data, order) { - const exchangeReference = em.create(OrderExchange, { + const exchangeReference = em.create(toMikroORMEntity(OrderExchange), { order_id: data.order_id, order_version: order.version, no_notification: data.no_notification, @@ -23,7 +23,7 @@ function createExchangeAndReturnEntities(em, data, order) { difference_due: data.difference_due, }) - const returnReference = em.create(Return, { + const returnReference = em.create(toMikroORMEntity(Return), { order_id: data.order_id, order_version: order.version, status: ReturnStatus.REQUESTED, @@ -55,7 +55,7 @@ function createReturnItems( }, }) - return em.create(ReturnItem, { + return em.create(toMikroORMEntity(ReturnItem), { item_id: item.id, return_id: returnReference.id, reason: item.reason, diff --git a/packages/modules/order/src/services/actions/create-return.ts b/packages/modules/order/src/services/actions/create-return.ts index ceedb5776fc8a..400093ceb5166 100644 --- a/packages/modules/order/src/services/actions/create-return.ts +++ b/packages/modules/order/src/services/actions/create-return.ts @@ -11,11 +11,12 @@ import { isDefined, isString, promiseAll, + toMikroORMEntity, } from "@medusajs/framework/utils" import { Return, ReturnItem } from "@models" function createReturnReference(em, data, order) { - return em.create(Return, { + return em.create(toMikroORMEntity(Return), { order_id: data.order_id, order_version: order.version, status: ReturnStatus.REQUESTED, @@ -39,7 +40,7 @@ function createReturnItems(em, data, returnRef, actions) { }, }) - return em.create(ReturnItem, { + return em.create(toMikroORMEntity(ReturnItem), { reason_id: item.reason_id, return_id: returnRef.id, item_id: item.id, diff --git a/packages/modules/order/src/utils/base-repository-find.ts b/packages/modules/order/src/utils/base-repository-find.ts index 5b8dbada4266b..a8cf08881f9a6 100644 --- a/packages/modules/order/src/utils/base-repository-find.ts +++ b/packages/modules/order/src/utils/base-repository-find.ts @@ -1,8 +1,8 @@ import { Constructor, Context, DAL } from "@medusajs/framework/types" +import { toMikroORMEntity } from "@medusajs/framework/utils" import { LoadStrategy } from "@mikro-orm/core" import { Order, OrderClaim } from "@models" import { mapRepositoryToOrderModel } from "." -import { toMikroORMEntity } from "@medusajs/framework/utils" export function setFindMethods(klass: Constructor, entity: any) { klass.prototype.find = async function find( diff --git a/packages/modules/order/src/utils/transform-order.ts b/packages/modules/order/src/utils/transform-order.ts index 2a65c5a764d6a..59dbba90b3744 100644 --- a/packages/modules/order/src/utils/transform-order.ts +++ b/packages/modules/order/src/utils/transform-order.ts @@ -4,6 +4,7 @@ import { deduplicate, isDefined, isObject, + toMikroORMEntity, } from "@medusajs/framework/utils" // Reshape the order object to match the OrderDTO @@ -20,8 +21,9 @@ export function formatOrder( orders.map((order) => { let mainOrder = order + const entity = options?.entity ? toMikroORMEntity(options.entity) : null - const isRelatedEntity = options?.entity?.name !== "Order" + const isRelatedEntity = entity?.name !== "Order" // If the entity is a related entity, the original order is located in the order property if (isRelatedEntity) { From a6e1dbf5dca969552aac540fcb2c47d190600acd Mon Sep 17 00:00:00 2001 From: adrien2p Date: Thu, 28 Nov 2024 18:19:14 +0100 Subject: [PATCH 102/175] fix relations --- .../entity-builder/define-relationship.ts | 11 ++--- packages/modules/order/src/models/address.ts | 4 -- packages/modules/order/src/models/claim.ts | 4 -- packages/modules/order/src/models/exchange.ts | 4 -- .../modules/order/src/models/line-item.ts | 40 +++++++++---------- .../order/src/models/order-change-action.ts | 17 ++++++-- packages/modules/order/src/models/order.ts | 18 --------- .../modules/order/src/models/return-reason.ts | 4 -- packages/modules/order/src/models/return.ts | 2 - .../order/src/models/shipping-method.ts | 7 ---- .../modules/order/src/models/transaction.ts | 24 ++++++----- 11 files changed, 52 insertions(+), 83 deletions(-) diff --git a/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts b/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts index fd86676d7871c..1f67d3ff5e80d 100644 --- a/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts +++ b/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts @@ -208,11 +208,11 @@ export function defineBelongsToRelationship( /** * Ensure the mapped by is defined as relationship on the other side */ - if (!otherSideRelation) { - throw new Error( - `Missing property "${mappedBy}" on "${relatedModelName}" entity. Make sure to define it as a relationship` - ) - } + // if (!otherSideRelation) { + // throw new Error( + // `Missing property "${mappedBy}" on "${relatedModelName}" entity. Make sure to define it as a relationship` + // ) + // } function applyForeignKeyAssignationHooks(foreignKeyName: string) { const hookName = `assignRelationFromForeignKeyValue${foreignKeyName}` @@ -251,6 +251,7 @@ export function defineBelongsToRelationship( * Otherside is a has many. Hence we should defined a ManyToOne */ if ( + !otherSideRelation || HasMany.isHasMany(otherSideRelation) || DmlManyToMany.isManyToMany(otherSideRelation) ) { diff --git a/packages/modules/order/src/models/address.ts b/packages/modules/order/src/models/address.ts index 681326affff30..94b4d7129ef1b 100644 --- a/packages/modules/order/src/models/address.ts +++ b/packages/modules/order/src/models/address.ts @@ -1,5 +1,4 @@ import { model } from "@medusajs/framework/utils" -import { Order } from "./order" const _OrderAddress = model .define("OrderAddress", { @@ -16,9 +15,6 @@ const _OrderAddress = model postal_code: model.text().searchable().nullable(), phone: model.text().searchable().nullable(), metadata: model.json().nullable(), - order: model.hasMany<() => typeof Order>(() => Order, { - mappedBy: "shipping_address", - }), }) .indexes([ { diff --git a/packages/modules/order/src/models/claim.ts b/packages/modules/order/src/models/claim.ts index 14643c65c4413..eebbc44e01a28 100644 --- a/packages/modules/order/src/models/claim.ts +++ b/packages/modules/order/src/models/claim.ts @@ -1,7 +1,6 @@ import { ClaimType, model } from "@medusajs/framework/utils" import { OrderClaimItem } from "./claim-item" import { Order } from "./order" -import { OrderChange } from "./order-change" import { OrderShipping } from "./order-shipping-method" import { Return } from "./return" import { OrderTransaction } from "./transaction" @@ -48,9 +47,6 @@ const _OrderClaim = model mappedBy: "claim", } ), - changes: model.hasMany<() => typeof OrderChange>(() => OrderChange, { - mappedBy: "claim", - }), }) .indexes([ { diff --git a/packages/modules/order/src/models/exchange.ts b/packages/modules/order/src/models/exchange.ts index 859be99620914..38835cdc45d80 100644 --- a/packages/modules/order/src/models/exchange.ts +++ b/packages/modules/order/src/models/exchange.ts @@ -2,7 +2,6 @@ import { model } from "@medusajs/framework/utils" import { OrderExchangeItem } from "./exchange-item" import { Order } from "./order" -import { OrderChange } from "./order-change" import { OrderShipping } from "./order-shipping-method" import { Return } from "./return" import { OrderTransaction } from "./transaction" @@ -43,9 +42,6 @@ const _OrderExchange = model mappedBy: "exchange", } ), - changes: model.hasMany<() => typeof OrderChange>(() => OrderChange, { - mappedBy: "exchange", - }), }) .indexes([ { diff --git a/packages/modules/order/src/models/line-item.ts b/packages/modules/order/src/models/line-item.ts index 1e7c61524ef9a..a146a31356a10 100644 --- a/packages/modules/order/src/models/line-item.ts +++ b/packages/modules/order/src/models/line-item.ts @@ -1,10 +1,6 @@ import { model } from "@medusajs/framework/utils" -import { OrderClaimItem } from "./claim-item" -import { OrderExchangeItem } from "./exchange-item" import { OrderLineItemAdjustment } from "./line-item-adjustment" import { OrderLineItemTaxLine } from "./line-item-tax-line" -import { OrderItem } from "./order-item" -import { ReturnItem } from "./return-item" const _OrderLineItem = model .define("OrderLineItem", { @@ -44,24 +40,24 @@ const _OrderLineItem = model mappedBy: "item", } ), - items: model.hasMany<() => typeof OrderItem>(() => OrderItem, { - mappedBy: "item", - }), - return_items: model.hasMany<() => typeof ReturnItem>(() => ReturnItem, { - mappedBy: "item", - }), - claim_items: model.hasMany<() => typeof OrderClaimItem>( - () => OrderClaimItem, - { - mappedBy: "item", - } - ), - exchange_items: model.hasMany<() => typeof OrderExchangeItem>( - () => OrderExchangeItem, - { - mappedBy: "item", - } - ), + // items: model.hasMany<() => typeof OrderItem>(() => OrderItem, { + // mappedBy: "item", + // }), + // return_items: model.hasMany<() => typeof ReturnItem>(() => ReturnItem, { + // mappedBy: "item", + // }), + // claim_items: model.hasMany<() => typeof OrderClaimItem>( + // () => OrderClaimItem, + // { + // mappedBy: "item", + // } + // ), + // exchange_items: model.hasMany<() => typeof OrderExchangeItem>( + // () => OrderExchangeItem, + // { + // mappedBy: "item", + // } + // ), }) .indexes([ { diff --git a/packages/modules/order/src/models/order-change-action.ts b/packages/modules/order/src/models/order-change-action.ts index b9403a996ab6e..f5b087f944ed6 100644 --- a/packages/modules/order/src/models/order-change-action.ts +++ b/packages/modules/order/src/models/order-change-action.ts @@ -1,14 +1,11 @@ import { model } from "@medusajs/framework/utils" import { OrderChange } from "./order-change" +import { Order, OrderClaim, OrderExchange, Return } from "@models" const _OrderChangeAction = model .define("OrderChangeAction", { id: model.id({ prefix: "ordchact" }).primaryKey(), ordering: model.autoincrement(), - order_id: model.text().nullable(), - return_id: model.text().nullable(), - claim_id: model.text().nullable(), - exchange_id: model.text().nullable(), version: model.number().nullable(), reference: model.text().nullable(), reference_id: model.text().nullable(), @@ -17,6 +14,18 @@ const _OrderChangeAction = model amount: model.bigNumber().nullable(), internal_note: model.text().nullable(), applied: model.boolean().default(false), + order: model.belongsTo<() => typeof OrderChange>(() => Order, { + mappedBy: "actions", + }), + return: model.belongsTo<() => typeof Return>(() => Return, { + mappedBy: "actions", + }), + claim: model.belongsTo<() => typeof OrderClaim>(() => OrderClaim, { + mappedBy: "actions", + }), + exchange: model.belongsTo<() => typeof OrderExchange>(() => OrderExchange, { + mappedBy: "actions", + }), order_change: model.belongsTo<() => typeof OrderChange>(() => OrderChange, { mappedBy: "actions", }), diff --git a/packages/modules/order/src/models/order.ts b/packages/modules/order/src/models/order.ts index 4979760a39e8e..55d6d64770c7e 100644 --- a/packages/modules/order/src/models/order.ts +++ b/packages/modules/order/src/models/order.ts @@ -18,13 +18,9 @@ import { TextProperty, } from "@medusajs/framework/utils" import { OrderAddress } from "./address" -import { OrderClaim } from "./claim" -import { OrderExchange } from "./exchange" -import { OrderChange } from "./order-change" import { OrderItem } from "./order-item" import { OrderShipping } from "./order-shipping-method" import { OrderSummary } from "./order-summary" -import { Return } from "./return" import { OrderTransaction } from "./transaction" type OrderSchema = { @@ -41,10 +37,6 @@ type OrderSchema = { no_notification: NullableModifier metadata: NullableModifier, JSONProperty> canceled_at: NullableModifier - exchanges: HasMany - claims: HasMany - returns: HasMany - changes: HasMany shipping_address: RelationNullableModifier< typeof OrderAddress, BelongsTo @@ -74,16 +66,6 @@ const _Order = model no_notification: model.boolean().nullable(), metadata: model.json().nullable(), canceled_at: model.dateTime().nullable(), - exchanges: model.hasMany(() => OrderExchange, { - mappedBy: "order", - }), - claims: model.hasMany(() => OrderClaim, { - mappedBy: "order", - }), - returns: model.hasMany(() => Return, { - mappedBy: "order", - }), - changes: model.hasMany(() => OrderChange), shipping_address: model.belongsTo(() => OrderAddress).nullable(), billing_address: model.belongsTo(() => OrderAddress).nullable(), summary: model.hasMany(() => OrderSummary, { diff --git a/packages/modules/order/src/models/return-reason.ts b/packages/modules/order/src/models/return-reason.ts index b37c63645478f..f44b333dbc941 100644 --- a/packages/modules/order/src/models/return-reason.ts +++ b/packages/modules/order/src/models/return-reason.ts @@ -1,5 +1,4 @@ import { model } from "@medusajs/framework/utils" -import { ReturnItem } from "./return-item" const _ReturnReason = model .define("ReturnReason", { @@ -20,9 +19,6 @@ const _ReturnReason = model mappedBy: "parent_return_reason", } ), - return_items: model.hasMany<() => typeof ReturnItem>(() => ReturnItem, { - mappedBy: "reason", - }), }) .indexes([ { diff --git a/packages/modules/order/src/models/return.ts b/packages/modules/order/src/models/return.ts index a2bf5a2400505..c7b55af6662e2 100644 --- a/packages/modules/order/src/models/return.ts +++ b/packages/modules/order/src/models/return.ts @@ -2,7 +2,6 @@ import { model, ReturnStatus } from "@medusajs/framework/utils" import { OrderClaim } from "./claim" import { OrderExchange } from "./exchange" import { Order } from "./order" -import { OrderChange } from "./order-change" import { OrderShipping } from "./order-shipping-method" import { ReturnItem } from "./return-item" import { OrderTransaction } from "./transaction" @@ -45,7 +44,6 @@ const _Return = model mappedBy: "return", } ), - changes: model.hasMany<() => typeof OrderChange>(() => OrderChange), }) .indexes([ { diff --git a/packages/modules/order/src/models/shipping-method.ts b/packages/modules/order/src/models/shipping-method.ts index 427789a1c24ca..7828e06028d4c 100644 --- a/packages/modules/order/src/models/shipping-method.ts +++ b/packages/modules/order/src/models/shipping-method.ts @@ -1,5 +1,4 @@ import { model } from "@medusajs/framework/utils" -import { OrderShipping } from "./order-shipping-method" import { OrderShippingMethodAdjustment } from "./shipping-method-adjustment" import { OrderShippingMethodTaxLine } from "./shipping-method-tax-line" @@ -26,12 +25,6 @@ const _OrderShippingMethod = model mappedBy: "shipping_method", } ), - shipping_methods: model.hasMany<() => typeof OrderShipping>( - () => OrderShipping, - { - mappedBy: "shipping_method", - } - ), }) .indexes([ { diff --git a/packages/modules/order/src/models/transaction.ts b/packages/modules/order/src/models/transaction.ts index a61c5c43d723c..bd712353ece16 100644 --- a/packages/modules/order/src/models/transaction.ts +++ b/packages/modules/order/src/models/transaction.ts @@ -19,15 +19,21 @@ const _OrderTransaction = model order: model.belongsTo<() => typeof Order>(() => Order, { mappedBy: "transactions", }), - return: model.belongsTo<() => typeof Return>(() => Return, { - mappedBy: "transactions", - }), - exchange: model.belongsTo<() => typeof OrderExchange>(() => OrderExchange, { - mappedBy: "transactions", - }), - claim: model.belongsTo<() => typeof OrderClaim>(() => OrderClaim, { - mappedBy: "transactions", - }), + return: model + .belongsTo<() => typeof Return>(() => Return, { + mappedBy: "transactions", + }) + .nullable(), + exchange: model + .belongsTo<() => typeof OrderExchange>(() => OrderExchange, { + mappedBy: "transactions", + }) + .nullable(), + claim: model + .belongsTo<() => typeof OrderClaim>(() => OrderClaim, { + mappedBy: "transactions", + }) + .nullable(), }) .indexes([ { From 3be553bc1581f954d6372ff05a109bd216130d3e Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Thu, 28 Nov 2024 16:20:29 -0300 Subject: [PATCH 103/175] cascades --- packages/core/types/src/dml/index.ts | 8 ++- packages/core/utils/src/dml/entity.ts | 20 ++++-- .../dml/helpers/create-mikro-orm-entity.ts | 18 +++-- .../src/migrations/Migration20241127185510.ts | 45 +------------ .../modules/order/src/models/claim-item.ts | 3 + packages/modules/order/src/models/claim.ts | 8 +++ packages/modules/order/src/models/exchange.ts | 3 + .../order/src/models/line-item-adjustment.ts | 29 +++++---- .../order/src/models/line-item-tax-line.ts | 29 +++++---- .../modules/order/src/models/line-item.ts | 21 +----- .../order/src/models/order-change-action.ts | 34 ++++++---- .../modules/order/src/models/order-change.ts | 3 + .../modules/order/src/models/order-item.ts | 49 ++++++++------ .../order/src/models/order-shipping-method.ts | 65 ++++++++++--------- packages/modules/order/src/models/order.ts | 3 + packages/modules/order/src/models/return.ts | 19 ++++-- .../src/models/shipping-method-adjustment.ts | 35 ++++++---- .../src/models/shipping-method-tax-line.ts | 35 ++++++---- .../order/src/models/shipping-method.ts | 3 + 19 files changed, 242 insertions(+), 188 deletions(-) diff --git a/packages/core/types/src/dml/index.ts b/packages/core/types/src/dml/index.ts index d6b1fd4048839..235776965547d 100644 --- a/packages/core/types/src/dml/index.ts +++ b/packages/core/types/src/dml/index.ts @@ -10,7 +10,13 @@ export type DMLSchema = Record< PropertyType | RelationshipType > -export type IDmlEntityConfig = string | { name?: string; tableName: string } +export type IDmlEntityConfig = + | string + | { + name?: string + tableName: string + disableSoftDeleteFilter?: boolean + } export type InferDmlEntityNameFromConfig = TConfig extends string diff --git a/packages/core/utils/src/dml/entity.ts b/packages/core/utils/src/dml/entity.ts index acb9e449c624e..a84000bebf156 100644 --- a/packages/core/utils/src/dml/entity.ts +++ b/packages/core/utils/src/dml/entity.ts @@ -9,12 +9,12 @@ import { QueryCondition, } from "@medusajs/types" import { isObject, isString, toCamelCase } from "../common" -import { transformIndexWhere } from "./helpers/entity-builder/build-indexes" -import { BelongsTo } from "./relations/belongs-to" import { DMLSchemaDefaults, DMLSchemaWithBigNumber, } from "./helpers/entity-builder" +import { transformIndexWhere } from "./helpers/entity-builder/build-indexes" +import { BelongsTo } from "./relations/belongs-to" const IsDmlEntity = Symbol.for("isDmlEntity") @@ -24,15 +24,17 @@ const IsDmlEntity = Symbol.for("isDmlEntity") export type DMLEntitySchemaBuilder = DMLSchemaWithBigNumber & DMLSchemaDefaults & Schema -function extractNameAndTableName( +function extractEntityConfig( nameOrConfig: Config ) { const result = { name: "", tableName: "", + disableSoftDeleteFilter: false, } as { name: InferDmlEntityNameFromConfig tableName: string + disableSoftDeleteFilter: boolean } if (isString(nameOrConfig)) { @@ -56,6 +58,8 @@ function extractNameAndTableName( result.name = toCamelCase(name) as InferDmlEntityNameFromConfig result.tableName = nameOrConfig.tableName + result.disableSoftDeleteFilter = + nameOrConfig.disableSoftDeleteFilter ?? true } return result @@ -76,14 +80,20 @@ export class DmlEntity< schema: Schema readonly #tableName: string + readonly #params: Record + #cascades: EntityCascades = {} #indexes: EntityIndex[] = [] constructor(nameOrConfig: TConfig, schema: Schema) { - const { name, tableName } = extractNameAndTableName(nameOrConfig) + const { name, tableName, disableSoftDeleteFilter } = + extractEntityConfig(nameOrConfig) this.schema = schema this.name = name this.#tableName = tableName + this.#params = { + disableSoftDeleteFilter, + } } /** @@ -106,6 +116,7 @@ export class DmlEntity< schema: DMLSchema cascades: EntityCascades indexes: EntityIndex[] + params: Record } { return { name: this.name, @@ -113,6 +124,7 @@ export class DmlEntity< schema: this.schema, cascades: this.#cascades, indexes: this.#indexes, + params: this.#params, } } diff --git a/packages/core/utils/src/dml/helpers/create-mikro-orm-entity.ts b/packages/core/utils/src/dml/helpers/create-mikro-orm-entity.ts index 2d45c75873a8a..06afbfc17466d 100644 --- a/packages/core/utils/src/dml/helpers/create-mikro-orm-entity.ts +++ b/packages/core/utils/src/dml/helpers/create-mikro-orm-entity.ts @@ -47,8 +47,15 @@ function createMikrORMEntity() { function createEntity>(entity: T): Infer { class MikroORMEntity {} - const { schema, cascades, indexes: entityIndexes = [] } = entity.parse() + const { + schema, + cascades, + indexes: entityIndexes = [], + params, + } = entity.parse() + const { modelName, tableName } = parseEntityName(entity) + if (ENTITIES[modelName]) { return ENTITIES[modelName] as Infer } @@ -100,9 +107,12 @@ function createMikrORMEntity() { /** * Converting class to a MikroORM entity */ - const RegisteredEntity = Entity({ tableName })( - Filter(mikroOrmSoftDeletableFilterOptions)(MikroORMEntity) - ) as unknown as Infer + + const RegisteredEntity = (params.disableSoftDeleteFilter + ? Entity({ tableName })(MikroORMEntity) + : Entity({ tableName })( + Filter(mikroOrmSoftDeletableFilterOptions)(MikroORMEntity) + )) as unknown as Infer ENTITIES[modelName] = RegisteredEntity return RegisteredEntity diff --git a/packages/modules/order/src/migrations/Migration20241127185510.ts b/packages/modules/order/src/migrations/Migration20241127185510.ts index ea64a0533c2d4..a3d922b88b35b 100644 --- a/packages/modules/order/src/migrations/Migration20241127185510.ts +++ b/packages/modules/order/src/migrations/Migration20241127185510.ts @@ -255,12 +255,7 @@ export class Migration20241127185510 extends Migration { this.addSql( 'alter table if exists "return" alter column "exchange_id" set not null;' ) - this.addSql( - 'alter table if exists "return" alter column "claim_id" type text using ("claim_id"::text);' - ) - this.addSql( - 'alter table if exists "return" alter column "claim_id" set not null;' - ) + this.addSql( 'alter table if exists "return" alter column "display_id" type bigint using ("display_id"::bigint);' ) @@ -280,24 +275,10 @@ export class Migration20241127185510 extends Migration { 'alter table if exists "return" add constraint "return_claim_id_foreign" foreign key ("claim_id") references "order_claim" ("id") on update cascade;' ) - this.addSql( - 'alter table if exists "order_transaction" alter column "return_id" type text using ("return_id"::text);' - ) - this.addSql( - 'alter table if exists "order_transaction" alter column "return_id" set not null;' - ) this.addSql( 'alter table if exists "order_transaction" alter column "exchange_id" type text using ("exchange_id"::text);' ) - this.addSql( - 'alter table if exists "order_transaction" alter column "exchange_id" set not null;' - ) - this.addSql( - 'alter table if exists "order_transaction" alter column "claim_id" type text using ("claim_id"::text);' - ) - this.addSql( - 'alter table if exists "order_transaction" alter column "claim_id" set not null;' - ) + this.addSql( 'alter table if exists "order_transaction" add constraint "order_transaction_order_id_foreign" foreign key ("order_id") references "order" ("id") on update cascade;' ) @@ -335,9 +316,7 @@ export class Migration20241127185510 extends Migration { this.addSql( 'alter table if exists "order_change_action" alter column "order_change_id" type text using ("order_change_id"::text);' ) - this.addSql( - 'alter table if exists "order_change_action" alter column "order_change_id" set not null;' - ) + this.addSql( 'alter table if exists "order_change_action" alter column "ordering" drop default;' ) @@ -638,24 +617,6 @@ export class Migration20241127185510 extends Migration { 'alter table if exists "order_claim" add constraint "order_claim_return_id_unique" unique ("return_id");' ) - this.addSql( - 'alter table if exists "order_transaction" alter column "return_id" type text using ("return_id"::text);' - ) - this.addSql( - 'alter table if exists "order_transaction" alter column "return_id" drop not null;' - ) - this.addSql( - 'alter table if exists "order_transaction" alter column "exchange_id" type text using ("exchange_id"::text);' - ) - this.addSql( - 'alter table if exists "order_transaction" alter column "exchange_id" drop not null;' - ) - this.addSql( - 'alter table if exists "order_transaction" alter column "claim_id" type text using ("claim_id"::text);' - ) - this.addSql( - 'alter table if exists "order_transaction" alter column "claim_id" drop not null;' - ) this.addSql( 'alter table if exists "order_transaction" add constraint "order_transaction_order_id_foreign" foreign key ("order_id") references "order" ("id") on update cascade on delete cascade;' ) diff --git a/packages/modules/order/src/models/claim-item.ts b/packages/modules/order/src/models/claim-item.ts index e5cb6bf656961..8539d23567b17 100644 --- a/packages/modules/order/src/models/claim-item.ts +++ b/packages/modules/order/src/models/claim-item.ts @@ -24,6 +24,9 @@ const _OrderClaimItem = model } ), }) + .cascades({ + delete: ["images"], + }) .indexes([ { name: "IDX_order_claim_item_claim_id", diff --git a/packages/modules/order/src/models/claim.ts b/packages/modules/order/src/models/claim.ts index eebbc44e01a28..901a6a3bcf256 100644 --- a/packages/modules/order/src/models/claim.ts +++ b/packages/modules/order/src/models/claim.ts @@ -48,6 +48,14 @@ const _OrderClaim = model } ), }) + .cascades({ + delete: [ + "additional_items", + "claim_items", + "shipping_methods", + "transactions", + ], + }) .indexes([ { name: "IDX_order_claim_display_id", diff --git a/packages/modules/order/src/models/exchange.ts b/packages/modules/order/src/models/exchange.ts index 38835cdc45d80..70d1b82a92146 100644 --- a/packages/modules/order/src/models/exchange.ts +++ b/packages/modules/order/src/models/exchange.ts @@ -43,6 +43,9 @@ const _OrderExchange = model } ), }) + .cascades({ + delete: ["additional_items", "shipping_methods", "transactions"], + }) .indexes([ { name: "IDX_order_exchange_display_id", diff --git a/packages/modules/order/src/models/line-item-adjustment.ts b/packages/modules/order/src/models/line-item-adjustment.ts index 8808b9c193f22..da3872008d982 100644 --- a/packages/modules/order/src/models/line-item-adjustment.ts +++ b/packages/modules/order/src/models/line-item-adjustment.ts @@ -2,17 +2,24 @@ import { model } from "@medusajs/framework/utils" import { OrderLineItem } from "./line-item" const _OrderLineItemAdjustment = model - .define("OrderLineItemAdjustment", { - id: model.id({ prefix: "ordliadj" }).primaryKey(), - description: model.text().nullable(), - promotion_id: model.text().nullable(), - code: model.text().nullable(), - amount: model.bigNumber(), - provider_id: model.text().nullable(), - item: model.belongsTo<() => typeof OrderLineItem>(() => OrderLineItem, { - mappedBy: "adjustments", - }), - }) + .define( + { + name: "OrderLineItemAdjustment", + tableName: "OrderLineItemAdjustment", + disableSoftDeleteFilter: true, + }, + { + id: model.id({ prefix: "ordliadj" }).primaryKey(), + description: model.text().nullable(), + promotion_id: model.text().nullable(), + code: model.text().nullable(), + amount: model.bigNumber(), + provider_id: model.text().nullable(), + item: model.belongsTo<() => typeof OrderLineItem>(() => OrderLineItem, { + mappedBy: "adjustments", + }), + } + ) .indexes([ { name: "IDX_order_order_line_item_adjustment_item_id", diff --git a/packages/modules/order/src/models/line-item-tax-line.ts b/packages/modules/order/src/models/line-item-tax-line.ts index 89436072aa662..ca612a40a1ac1 100644 --- a/packages/modules/order/src/models/line-item-tax-line.ts +++ b/packages/modules/order/src/models/line-item-tax-line.ts @@ -2,17 +2,24 @@ import { model } from "@medusajs/framework/utils" import { OrderLineItem } from "./line-item" const _OrderLineItemTaxLine = model - .define("OrderLineItemTaxLine", { - id: model.id({ prefix: "ordlitxl" }).primaryKey(), - description: model.text().nullable(), - tax_rate_id: model.text().nullable(), - code: model.text(), - rate: model.bigNumber(), - provider_id: model.text().nullable(), - item: model.belongsTo<() => typeof OrderLineItem>(() => OrderLineItem, { - mappedBy: "tax_lines", - }), - }) + .define( + { + name: "OrderLineItemTaxLine", + tableName: "OrderLineItemTaxLine", + disableSoftDeleteFilter: true, + }, + { + id: model.id({ prefix: "ordlitxl" }).primaryKey(), + description: model.text().nullable(), + tax_rate_id: model.text().nullable(), + code: model.text(), + rate: model.bigNumber(), + provider_id: model.text().nullable(), + item: model.belongsTo<() => typeof OrderLineItem>(() => OrderLineItem, { + mappedBy: "tax_lines", + }), + } + ) .indexes([ { name: "IDX_order_line_item_tax_line_item_id", diff --git a/packages/modules/order/src/models/line-item.ts b/packages/modules/order/src/models/line-item.ts index a146a31356a10..fab2d0842ee57 100644 --- a/packages/modules/order/src/models/line-item.ts +++ b/packages/modules/order/src/models/line-item.ts @@ -40,24 +40,9 @@ const _OrderLineItem = model mappedBy: "item", } ), - // items: model.hasMany<() => typeof OrderItem>(() => OrderItem, { - // mappedBy: "item", - // }), - // return_items: model.hasMany<() => typeof ReturnItem>(() => ReturnItem, { - // mappedBy: "item", - // }), - // claim_items: model.hasMany<() => typeof OrderClaimItem>( - // () => OrderClaimItem, - // { - // mappedBy: "item", - // } - // ), - // exchange_items: model.hasMany<() => typeof OrderExchangeItem>( - // () => OrderExchangeItem, - // { - // mappedBy: "item", - // } - // ), + }) + .cascades({ + delete: ["tax_lines", "adjustments"], }) .indexes([ { diff --git a/packages/modules/order/src/models/order-change-action.ts b/packages/modules/order/src/models/order-change-action.ts index f5b087f944ed6..8aabb10f633d5 100644 --- a/packages/modules/order/src/models/order-change-action.ts +++ b/packages/modules/order/src/models/order-change-action.ts @@ -1,6 +1,6 @@ import { model } from "@medusajs/framework/utils" -import { OrderChange } from "./order-change" import { Order, OrderClaim, OrderExchange, Return } from "@models" +import { OrderChange } from "./order-change" const _OrderChangeAction = model .define("OrderChangeAction", { @@ -17,18 +17,26 @@ const _OrderChangeAction = model order: model.belongsTo<() => typeof OrderChange>(() => Order, { mappedBy: "actions", }), - return: model.belongsTo<() => typeof Return>(() => Return, { - mappedBy: "actions", - }), - claim: model.belongsTo<() => typeof OrderClaim>(() => OrderClaim, { - mappedBy: "actions", - }), - exchange: model.belongsTo<() => typeof OrderExchange>(() => OrderExchange, { - mappedBy: "actions", - }), - order_change: model.belongsTo<() => typeof OrderChange>(() => OrderChange, { - mappedBy: "actions", - }), + return: model + .belongsTo<() => typeof Return>(() => Return, { + mappedBy: "actions", + }) + .nullable(), + claim: model + .belongsTo<() => typeof OrderClaim>(() => OrderClaim, { + mappedBy: "actions", + }) + .nullable(), + exchange: model + .belongsTo<() => typeof OrderExchange>(() => OrderExchange, { + mappedBy: "actions", + }) + .nullable(), + order_change: model + .belongsTo<() => typeof OrderChange>(() => OrderChange, { + mappedBy: "actions", + }) + .nullable(), }) .indexes([ { diff --git a/packages/modules/order/src/models/order-change.ts b/packages/modules/order/src/models/order-change.ts index 18ce0d2d05fc9..6d88085b9de9e 100644 --- a/packages/modules/order/src/models/order-change.ts +++ b/packages/modules/order/src/models/order-change.ts @@ -52,6 +52,9 @@ const _OrderChange = model } ), }) + .cascades({ + delete: ["actions"], + }) .indexes([ { name: "IDX_order_change_order_id", diff --git a/packages/modules/order/src/models/order-item.ts b/packages/modules/order/src/models/order-item.ts index 4ff9411835666..d0b3d3ee77896 100644 --- a/packages/modules/order/src/models/order-item.ts +++ b/packages/modules/order/src/models/order-item.ts @@ -4,27 +4,34 @@ import { OrderLineItem } from "./line-item" import { Order } from "./order" const _OrderItem = model - .define("OrderItem", { - id: model.id({ prefix: "orditem" }).primaryKey(), - version: model.number(), - unit_price: model.bigNumber().nullable(), - compare_at_unit_price: model.bigNumber().nullable(), - quantity: model.bigNumber(), - fulfilled_quantity: model.bigNumber().default(0), - delivered_quantity: model.bigNumber().default(0), - shipped_quantity: model.bigNumber().default(0), - return_requested_quantity: model.bigNumber().default(0), - return_received_quantity: model.bigNumber().default(0), - return_dismissed_quantity: model.bigNumber().default(0), - written_off_quantity: model.bigNumber().default(0), - metadata: model.json().nullable(), - order: model.belongsTo<() => typeof Order>(() => Order, { - mappedBy: "items", - }), - item: model.belongsTo<() => typeof OrderLineItem>(() => OrderLineItem, { - mappedBy: "items", - }), - }) + .define( + { + name: "OrderItem", + tableName: "OrderItem", + disableSoftDeleteFilter: true, + }, + { + id: model.id({ prefix: "orditem" }).primaryKey(), + version: model.number(), + unit_price: model.bigNumber().nullable(), + compare_at_unit_price: model.bigNumber().nullable(), + quantity: model.bigNumber(), + fulfilled_quantity: model.bigNumber().default(0), + delivered_quantity: model.bigNumber().default(0), + shipped_quantity: model.bigNumber().default(0), + return_requested_quantity: model.bigNumber().default(0), + return_received_quantity: model.bigNumber().default(0), + return_dismissed_quantity: model.bigNumber().default(0), + written_off_quantity: model.bigNumber().default(0), + metadata: model.json().nullable(), + order: model.belongsTo<() => typeof Order>(() => Order, { + mappedBy: "items", + }), + item: model.belongsTo<() => typeof OrderLineItem>(() => OrderLineItem, { + mappedBy: "items", + }), + } + ) .indexes([ { name: "IDX_order_item_order_id", diff --git a/packages/modules/order/src/models/order-shipping-method.ts b/packages/modules/order/src/models/order-shipping-method.ts index 091f4a7f04119..3dde2b73e4972 100644 --- a/packages/modules/order/src/models/order-shipping-method.ts +++ b/packages/modules/order/src/models/order-shipping-method.ts @@ -1,39 +1,46 @@ import { model } from "@medusajs/framework/utils" -import { Order } from "./order" -import { Return } from "./return" import { OrderClaim } from "./claim" import { OrderExchange } from "./exchange" +import { Order } from "./order" +import { Return } from "./return" import { OrderShippingMethod } from "./shipping-method" const _OrderShipping = model - .define("OrderShipping", { - id: model.id({ prefix: "ordspmv" }).primaryKey(), - version: model.number(), - order: model.belongsTo<() => typeof Order>(() => Order, { - mappedBy: "shipping_methods", - }), - return: model - .belongsTo<() => typeof Return>(() => Return, { - mappedBy: "shipping_methods", - }) - .nullable(), - exchange: model - .belongsTo<() => typeof OrderExchange>(() => OrderExchange, { - mappedBy: "shipping_methods", - }) - .nullable(), - claim: model - .belongsTo<() => typeof OrderClaim>(() => OrderClaim, { - mappedBy: "shipping_methods", - }) - .nullable(), - shipping_method: model.belongsTo<() => typeof OrderShippingMethod>( - () => OrderShippingMethod, - { + .define( + { + name: "OrderShipping", + tableName: "OrderShipping", + disableSoftDeleteFilter: true, + }, + { + id: model.id({ prefix: "ordspmv" }).primaryKey(), + version: model.number(), + order: model.belongsTo<() => typeof Order>(() => Order, { mappedBy: "shipping_methods", - } - ), - }) + }), + return: model + .belongsTo<() => typeof Return>(() => Return, { + mappedBy: "shipping_methods", + }) + .nullable(), + exchange: model + .belongsTo<() => typeof OrderExchange>(() => OrderExchange, { + mappedBy: "shipping_methods", + }) + .nullable(), + claim: model + .belongsTo<() => typeof OrderClaim>(() => OrderClaim, { + mappedBy: "shipping_methods", + }) + .nullable(), + shipping_method: model.belongsTo<() => typeof OrderShippingMethod>( + () => OrderShippingMethod, + { + mappedBy: "shipping_methods", + } + ), + } + ) .indexes([ { name: "IDX_order_shipping_order_id", diff --git a/packages/modules/order/src/models/order.ts b/packages/modules/order/src/models/order.ts index 55d6d64770c7e..5f5b81f6191c6 100644 --- a/packages/modules/order/src/models/order.ts +++ b/packages/modules/order/src/models/order.ts @@ -81,6 +81,9 @@ const _Order = model mappedBy: "order", }), }) + .cascades({ + delete: ["summary", "items", "shipping_methods", "transactions"], + }) .indexes([ { name: "IDX_order_display_id", diff --git a/packages/modules/order/src/models/return.ts b/packages/modules/order/src/models/return.ts index c7b55af6662e2..75f0482f83eaf 100644 --- a/packages/modules/order/src/models/return.ts +++ b/packages/modules/order/src/models/return.ts @@ -23,12 +23,16 @@ const _Return = model order: model.belongsTo<() => typeof Order>(() => Order, { mappedBy: "returns", }), - exchange: model.belongsTo<() => typeof OrderExchange>(() => OrderExchange, { - mappedBy: "return", - }), - claim: model.belongsTo<() => typeof OrderClaim>(() => OrderClaim, { - mappedBy: "return", - }), + exchange: model + .belongsTo<() => typeof OrderExchange>(() => OrderExchange, { + mappedBy: "return", + }) + .nullable(), + claim: model + .belongsTo<() => typeof OrderClaim>(() => OrderClaim, { + mappedBy: "return", + }) + .nullable(), items: model.hasMany<() => typeof ReturnItem>(() => ReturnItem, { mappedBy: "return", }), @@ -45,6 +49,9 @@ const _Return = model } ), }) + .cascades({ + delete: ["items", "shipping_methods", "transactions"], + }) .indexes([ { name: "IDX_return_display_id", diff --git a/packages/modules/order/src/models/shipping-method-adjustment.ts b/packages/modules/order/src/models/shipping-method-adjustment.ts index 01fa946b4430e..1c6efc7a812ad 100644 --- a/packages/modules/order/src/models/shipping-method-adjustment.ts +++ b/packages/modules/order/src/models/shipping-method-adjustment.ts @@ -2,20 +2,27 @@ import { model } from "@medusajs/framework/utils" import { OrderShippingMethod } from "./shipping-method" const _OrderShippingMethodAdjustment = model - .define("OrderShippingMethodAdjustment", { - id: model.id({ prefix: "ordsmadj" }).primaryKey(), - description: model.text().nullable(), - promotion_id: model.text().nullable(), - code: model.text().nullable(), - amount: model.bigNumber(), - provider_id: model.text().nullable(), - shipping_method: model.belongsTo<() => typeof OrderShippingMethod>( - () => OrderShippingMethod, - { - mappedBy: "adjustments", - } - ), - }) + .define( + { + name: "OrderShippingMethodAdjustment", + tableName: "OrderShippingMethodAdjustment", + disableSoftDeleteFilter: true, + }, + { + id: model.id({ prefix: "ordsmadj" }).primaryKey(), + description: model.text().nullable(), + promotion_id: model.text().nullable(), + code: model.text().nullable(), + amount: model.bigNumber(), + provider_id: model.text().nullable(), + shipping_method: model.belongsTo<() => typeof OrderShippingMethod>( + () => OrderShippingMethod, + { + mappedBy: "adjustments", + } + ), + } + ) .indexes([ { name: "IDX_order_shipping_method_adjustment_shipping_method_id", diff --git a/packages/modules/order/src/models/shipping-method-tax-line.ts b/packages/modules/order/src/models/shipping-method-tax-line.ts index e49a9668504ff..8250e8c79e9ae 100644 --- a/packages/modules/order/src/models/shipping-method-tax-line.ts +++ b/packages/modules/order/src/models/shipping-method-tax-line.ts @@ -2,20 +2,27 @@ import { model } from "@medusajs/framework/utils" import { OrderShippingMethod } from "./shipping-method" const _OrderShippingMethodTaxLine = model - .define("OrderShippingMethodTaxLine", { - id: model.id({ prefix: "ordsmtxl" }).primaryKey(), - description: model.text().nullable(), - tax_rate_id: model.text().nullable(), - code: model.text(), - rate: model.bigNumber(), - provider_id: model.text().nullable(), - shipping_method: model.belongsTo<() => typeof OrderShippingMethod>( - () => OrderShippingMethod, - { - mappedBy: "tax_lines", - } - ), - }) + .define( + { + name: "OrderShippingMethodTaxLine", + tableName: "OrderShippingMethodTaxLine", + disableSoftDeleteFilter: true, + }, + { + id: model.id({ prefix: "ordsmtxl" }).primaryKey(), + description: model.text().nullable(), + tax_rate_id: model.text().nullable(), + code: model.text(), + rate: model.bigNumber(), + provider_id: model.text().nullable(), + shipping_method: model.belongsTo<() => typeof OrderShippingMethod>( + () => OrderShippingMethod, + { + mappedBy: "tax_lines", + } + ), + } + ) .indexes([ { name: "IDX_order_shipping_method_tax_line_shipping_method_id", diff --git a/packages/modules/order/src/models/shipping-method.ts b/packages/modules/order/src/models/shipping-method.ts index 7828e06028d4c..aa5db60719fa5 100644 --- a/packages/modules/order/src/models/shipping-method.ts +++ b/packages/modules/order/src/models/shipping-method.ts @@ -26,6 +26,9 @@ const _OrderShippingMethod = model } ), }) + .cascades({ + delete: ["tax_lines", "adjustments"], + }) .indexes([ { name: "IDX_order_shipping_method_shipping_option_id", From 0888a6d79f4eed3d0106ee5c839fa4e0829896f9 Mon Sep 17 00:00:00 2001 From: adrien2p Date: Fri, 29 Nov 2024 10:54:46 +0100 Subject: [PATCH 104/175] fix --- .../utils/src/dml/helpers/entity-builder/define-property.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/core/utils/src/dml/helpers/entity-builder/define-property.ts b/packages/core/utils/src/dml/helpers/entity-builder/define-property.ts index d63d19cf26cf5..ae2f3f4a652db 100644 --- a/packages/core/utils/src/dml/helpers/entity-builder/define-property.ts +++ b/packages/core/utils/src/dml/helpers/entity-builder/define-property.ts @@ -126,12 +126,12 @@ export function defineProperty( if (isDefined(field.defaultValue) || field.nullable) { const defaultValueSetterHookName = `${field.fieldName}_setDefaultValueOnBeforeCreate` MikroORMEntity.prototype[defaultValueSetterHookName] = function () { - if (isDefined(field.defaultValue)) { + if (isDefined(field.defaultValue) && this[propertyName] === undefined) { this[propertyName] = field.defaultValue return } - if (field.nullable) { + if (field.nullable && this[propertyName] === undefined) { this[propertyName] = null return } From 4aee038746f462d6b009089ce3a2a5fa7003faba Mon Sep 17 00:00:00 2001 From: adrien2p Date: Fri, 15 Nov 2024 11:21:53 +0100 Subject: [PATCH 105/175] experimental dml hooks --- packages/core/utils/src/dml/entity.ts | 35 ++++++++++++++++--- .../dml/helpers/create-mikro-orm-entity.ts | 22 ++++++++++-- .../order/src/models/order-change-action.ts | 17 +++++---- 3 files changed, 58 insertions(+), 16 deletions(-) diff --git a/packages/core/utils/src/dml/entity.ts b/packages/core/utils/src/dml/entity.ts index a84000bebf156..ad9020c2e8845 100644 --- a/packages/core/utils/src/dml/entity.ts +++ b/packages/core/utils/src/dml/entity.ts @@ -6,21 +6,25 @@ import { IDmlEntity, IDmlEntityConfig, InferDmlEntityNameFromConfig, + InferSchemaFields, QueryCondition, } from "@medusajs/types" import { isObject, isString, toCamelCase } from "../common" -import { - DMLSchemaDefaults, - DMLSchemaWithBigNumber, -} from "./helpers/entity-builder" import { transformIndexWhere } from "./helpers/entity-builder/build-indexes" +import { DMLSchemaWithBigNumber } from "./helpers/entity-builder/create-big-number-properties" +import { DMLSchemaDefaults } from "./helpers/entity-builder/create-default-properties" import { BelongsTo } from "./relations/belongs-to" const IsDmlEntity = Symbol.for("isDmlEntity") /** - * Compose the Schema with bigNumbers and the defaults + * @experimental + * need to be moved after RFV */ +type Hooks = { + creating?: (entity: InferSchemaFields) => void +} + export type DMLEntitySchemaBuilder = DMLSchemaWithBigNumber & DMLSchemaDefaults & Schema @@ -85,6 +89,13 @@ export class DmlEntity< #cascades: EntityCascades = {} #indexes: EntityIndex[] = [] + /** + * @experimental + * TODO: Write RFC about this, for now it is unstable and mainly + * for test purposes + */ + #hooks: Hooks = {} + constructor(nameOrConfig: TConfig, schema: Schema) { const { name, tableName, disableSoftDeleteFilter } = extractEntityConfig(nameOrConfig) @@ -117,6 +128,7 @@ export class DmlEntity< cascades: EntityCascades indexes: EntityIndex[] params: Record + hooks: Hooks } { return { name: this.name, @@ -125,6 +137,7 @@ export class DmlEntity< cascades: this.#cascades, indexes: this.#indexes, params: this.#params, + hooks: this.#hooks, } } @@ -256,4 +269,16 @@ export class DmlEntity< this.#indexes = indexes as EntityIndex[] return this } + + /** + * @experimental + * TODO: Write RFC about this, for now it is unstable and mainly + * for test purposes + * @param hooks + * @returns + */ + hooks(hooks: Hooks): this { + this.#hooks = hooks + return this + } } diff --git a/packages/core/utils/src/dml/helpers/create-mikro-orm-entity.ts b/packages/core/utils/src/dml/helpers/create-mikro-orm-entity.ts index 06afbfc17466d..c9a26899afdc5 100644 --- a/packages/core/utils/src/dml/helpers/create-mikro-orm-entity.ts +++ b/packages/core/utils/src/dml/helpers/create-mikro-orm-entity.ts @@ -6,8 +6,8 @@ import type { Infer, PropertyType, } from "@medusajs/types" -import { Entity, Filter } from "@mikro-orm/core" - +import { BeforeCreate, Entity, Filter } from "@mikro-orm/core" +import { camelToSnakeCase } from "../../common" import { mikroOrmSoftDeletableFilterOptions } from "../../dal" import { DmlEntity } from "../entity" import { DuplicateIdPropertyError } from "../errors" @@ -52,6 +52,7 @@ function createMikrORMEntity() { cascades, indexes: entityIndexes = [], params, + hooks = {}, } = entity.parse() const { modelName, tableName } = parseEntityName(entity) @@ -104,6 +105,23 @@ function createMikrORMEntity() { applyEntityIndexes(MikroORMEntity, tableName, entityIndexes) + /** + * @experimental + * TODO: Write RFC about this, for now it is unstable and should be moved + * to `applyHooks` + */ + for (const [hookName, hook] of Object.entries(hooks)) { + if (hookName === "creating") { + const hookMethodName = "beforeCreate_" + camelToSnakeCase(modelName) + const hookWrapper = function (this: MikroORMEntity) { + return hook(this as any) + } + + MikroORMEntity.prototype[hookMethodName] = hookWrapper + BeforeCreate()(MikroORMEntity.prototype, hookMethodName) + } + } + /** * Converting class to a MikroORM entity */ diff --git a/packages/modules/order/src/models/order-change-action.ts b/packages/modules/order/src/models/order-change-action.ts index ec5363a7a048e..c859555736f0f 100644 --- a/packages/modules/order/src/models/order-change-action.ts +++ b/packages/modules/order/src/models/order-change-action.ts @@ -42,16 +42,15 @@ const _OrderChangeAction = model }) .nullable(), }) - /* - //@ts-expect-error - .addHook(function (this: any) { - this.order_id ??= this.order_change.order_id - this.return_id ??= this.order_change.return_id - this.claim_id ??= this.order_change.claim_id - this.exchange_id ??= this.order_change.exchange_id - this.version ??= this.order_change.version + .hooks({ + creating: (entity: any) => { + entity.order_id ??= entity.order_change.order_id + entity.return_id ??= entity.order_change.return_id + entity.claim_id ??= entity.order_change.claim_id + entity.exchange_id ??= entity.order_change.exchange_id + entity.version ??= entity.order_change.version + }, }) - */ .indexes([ { name: "IDX_order_change_action_order_change_id", From bf1b50e00ab6a794f7f543a47ba771c3c0482b2e Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Fri, 29 Nov 2024 09:45:34 -0300 Subject: [PATCH 106/175] rm migration --- .../migrations/.snapshot-medusa-order.json | 5093 ----------------- .../src/migrations/Migration20241127185510.ts | 707 --- 2 files changed, 5800 deletions(-) delete mode 100644 packages/modules/order/src/migrations/.snapshot-medusa-order.json delete mode 100644 packages/modules/order/src/migrations/Migration20241127185510.ts diff --git a/packages/modules/order/src/migrations/.snapshot-medusa-order.json b/packages/modules/order/src/migrations/.snapshot-medusa-order.json deleted file mode 100644 index 8d8549bcd49f2..0000000000000 --- a/packages/modules/order/src/migrations/.snapshot-medusa-order.json +++ /dev/null @@ -1,5093 +0,0 @@ -{ - "namespaces": [ - "public" - ], - "name": "public", - "tables": [ - { - "columns": { - "id": { - "name": "id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "text" - }, - "customer_id": { - "name": "customer_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "company": { - "name": "company", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "first_name": { - "name": "first_name", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "last_name": { - "name": "last_name", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "address_1": { - "name": "address_1", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "address_2": { - "name": "address_2", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "city": { - "name": "city", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "country_code": { - "name": "country_code", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "province": { - "name": "province", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "postal_code": { - "name": "postal_code", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "phone": { - "name": "phone", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "metadata": { - "name": "metadata", - "type": "jsonb", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "json" - }, - "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": "order_address", - "schema": "public", - "indexes": [ - { - "keyName": "IDX_order_address_deleted_at", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_address_deleted_at\" ON \"order_address\" (deleted_at) WHERE deleted_at IS NULL" - }, - { - "keyName": "IDX_order_address_customer_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_address_customer_id\" ON \"order_address\" (customer_id) WHERE deleted_at IS NULL" - }, - { - "keyName": "order_address_pkey", - "columnNames": [ - "id" - ], - "composite": false, - "primary": true, - "unique": true - } - ], - "checks": [], - "foreignKeys": {} - }, - { - "columns": { - "id": { - "name": "id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "text" - }, - "display_id": { - "name": "display_id", - "type": "bigserial", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "bigint" - }, - "region_id": { - "name": "region_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "customer_id": { - "name": "customer_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "version": { - "name": "version", - "type": "integer", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "default": "1", - "mappedType": "integer" - }, - "sales_channel_id": { - "name": "sales_channel_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "status": { - "name": "status", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "default": "'pending'", - "enumItems": [ - "pending", - "completed", - "draft", - "archived", - "canceled", - "requires_action" - ], - "mappedType": "enum" - }, - "is_draft_order": { - "name": "is_draft_order", - "type": "boolean", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "default": "false", - "mappedType": "boolean" - }, - "email": { - "name": "email", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "currency_code": { - "name": "currency_code", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "text" - }, - "no_notification": { - "name": "no_notification", - "type": "boolean", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "boolean" - }, - "metadata": { - "name": "metadata", - "type": "jsonb", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "json" - }, - "canceled_at": { - "name": "canceled_at", - "type": "timestamptz", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "length": 6, - "mappedType": "datetime" - }, - "shipping_address_id": { - "name": "shipping_address_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "billing_address_id": { - "name": "billing_address_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "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": "order", - "schema": "public", - "indexes": [ - { - "keyName": "IDX_order_shipping_address_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_address_id\" ON \"order\" (shipping_address_id) WHERE deleted_at IS NULL" - }, - { - "keyName": "IDX_order_billing_address_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_billing_address_id\" ON \"order\" (billing_address_id) WHERE deleted_at IS NULL" - }, - { - "keyName": "IDX_order_deleted_at", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_deleted_at\" ON \"order\" (deleted_at) WHERE deleted_at IS NULL" - }, - { - "keyName": "IDX_order_display_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_display_id\" ON \"order\" (display_id) WHERE deleted_at IS NOT NULL" - }, - { - "keyName": "IDX_order_region_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_region_id\" ON \"order\" (region_id) WHERE deleted_at IS NOT NULL" - }, - { - "keyName": "IDX_order_customer_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_customer_id\" ON \"order\" (customer_id) WHERE deleted_at IS NOT NULL" - }, - { - "keyName": "IDX_order_sales_channel_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_sales_channel_id\" ON \"order\" (sales_channel_id) WHERE deleted_at IS NOT NULL" - }, - { - "keyName": "IDX_order_deleted_at", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_deleted_at\" ON \"order\" (deleted_at) WHERE deleted_at IS NOT NULL" - }, - { - "keyName": "IDX_order_currency_code", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_currency_code\" ON \"order\" (currency_code) WHERE deleted_at IS NOT NULL" - }, - { - "keyName": "IDX_order_shipping_address_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_address_id\" ON \"order\" (shipping_address_id) WHERE deleted_at IS NOT NULL" - }, - { - "keyName": "IDX_order_billing_address_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_billing_address_id\" ON \"order\" (billing_address_id) WHERE deleted_at IS NOT NULL" - }, - { - "keyName": "IDX_order_is_draft_order", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_is_draft_order\" ON \"order\" (is_draft_order) WHERE deleted_at IS NOT NULL" - }, - { - "keyName": "order_pkey", - "columnNames": [ - "id" - ], - "composite": false, - "primary": true, - "unique": true - } - ], - "checks": [], - "foreignKeys": { - "order_shipping_address_id_foreign": { - "constraintName": "order_shipping_address_id_foreign", - "columnNames": [ - "shipping_address_id" - ], - "localTableName": "public.order", - "referencedColumnNames": [ - "id" - ], - "referencedTableName": "public.order_address", - "deleteRule": "set null", - "updateRule": "cascade" - }, - "order_billing_address_id_foreign": { - "constraintName": "order_billing_address_id_foreign", - "columnNames": [ - "billing_address_id" - ], - "localTableName": "public.order", - "referencedColumnNames": [ - "id" - ], - "referencedTableName": "public.order_address", - "deleteRule": "set null", - "updateRule": "cascade" - } - } - }, - { - "columns": { - "id": { - "name": "id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "text" - }, - "return_id": { - "name": "return_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "order_version": { - "name": "order_version", - "type": "integer", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "integer" - }, - "display_id": { - "name": "display_id", - "type": "bigserial", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "bigint" - }, - "type": { - "name": "type", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "enumItems": [ - "refund", - "replace" - ], - "mappedType": "enum" - }, - "no_notification": { - "name": "no_notification", - "type": "boolean", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "boolean" - }, - "refund_amount": { - "name": "refund_amount", - "type": "numeric", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "decimal" - }, - "created_by": { - "name": "created_by", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "canceled_at": { - "name": "canceled_at", - "type": "timestamptz", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "length": 6, - "mappedType": "datetime" - }, - "metadata": { - "name": "metadata", - "type": "jsonb", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "json" - }, - "order_id": { - "name": "order_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "text" - }, - "raw_refund_amount": { - "name": "raw_refund_amount", - "type": "jsonb", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "json" - }, - "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": "order_claim", - "schema": "public", - "indexes": [ - { - "keyName": "IDX_order_claim_order_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_claim_order_id\" ON \"order_claim\" (order_id) WHERE deleted_at IS NULL" - }, - { - "keyName": "IDX_order_claim_deleted_at", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_claim_deleted_at\" ON \"order_claim\" (deleted_at) WHERE deleted_at IS NULL" - }, - { - "keyName": "IDX_order_claim_display_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_claim_display_id\" ON \"order_claim\" (display_id) WHERE deleted_at IS NOT NULL" - }, - { - "keyName": "IDX_order_claim_deleted_at", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_claim_deleted_at\" ON \"order_claim\" (deleted_at) WHERE deleted_at IS NOT NULL" - }, - { - "keyName": "IDX_order_claim_order_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_claim_order_id\" ON \"order_claim\" (order_id) WHERE deleted_at IS NOT NULL" - }, - { - "keyName": "IDX_order_claim_return_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_claim_return_id\" ON \"order_claim\" (return_id) WHERE return_id IS NOT NULL AND deleted_at IS NOT NULL" - }, - { - "keyName": "order_claim_pkey", - "columnNames": [ - "id" - ], - "composite": false, - "primary": true, - "unique": true - } - ], - "checks": [], - "foreignKeys": { - "order_claim_order_id_foreign": { - "constraintName": "order_claim_order_id_foreign", - "columnNames": [ - "order_id" - ], - "localTableName": "public.order_claim", - "referencedColumnNames": [ - "id" - ], - "referencedTableName": "public.order", - "updateRule": "cascade" - } - } - }, - { - "columns": { - "id": { - "name": "id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "text" - }, - "return_id": { - "name": "return_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "order_version": { - "name": "order_version", - "type": "integer", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "integer" - }, - "display_id": { - "name": "display_id", - "type": "bigserial", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "bigint" - }, - "no_notification": { - "name": "no_notification", - "type": "boolean", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "boolean" - }, - "difference_due": { - "name": "difference_due", - "type": "numeric", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "decimal" - }, - "allow_backorder": { - "name": "allow_backorder", - "type": "boolean", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "default": "false", - "mappedType": "boolean" - }, - "created_by": { - "name": "created_by", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "metadata": { - "name": "metadata", - "type": "jsonb", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "json" - }, - "canceled_at": { - "name": "canceled_at", - "type": "timestamptz", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "length": 6, - "mappedType": "datetime" - }, - "order_id": { - "name": "order_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "text" - }, - "raw_difference_due": { - "name": "raw_difference_due", - "type": "jsonb", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "json" - }, - "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": "order_exchange", - "schema": "public", - "indexes": [ - { - "keyName": "IDX_order_exchange_order_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_exchange_order_id\" ON \"order_exchange\" (order_id) WHERE deleted_at IS NULL" - }, - { - "keyName": "IDX_order_exchange_deleted_at", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_exchange_deleted_at\" ON \"order_exchange\" (deleted_at) WHERE deleted_at IS NULL" - }, - { - "keyName": "IDX_order_exchange_display_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_exchange_display_id\" ON \"order_exchange\" (display_id) WHERE deleted_at IS NOT NULL" - }, - { - "keyName": "IDX_order_exchange_deleted_at", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_exchange_deleted_at\" ON \"order_exchange\" (deleted_at) WHERE deleted_at IS NOT NULL" - }, - { - "keyName": "IDX_order_exchange_order_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_exchange_order_id\" ON \"order_exchange\" (order_id) WHERE deleted_at IS NOT NULL" - }, - { - "keyName": "IDX_order_exchange_return_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_exchange_return_id\" ON \"order_exchange\" (return_id) WHERE return_id IS NOT NULL AND deleted_at IS NOT NULL" - }, - { - "keyName": "order_exchange_pkey", - "columnNames": [ - "id" - ], - "composite": false, - "primary": true, - "unique": true - } - ], - "checks": [], - "foreignKeys": { - "order_exchange_order_id_foreign": { - "constraintName": "order_exchange_order_id_foreign", - "columnNames": [ - "order_id" - ], - "localTableName": "public.order_exchange", - "referencedColumnNames": [ - "id" - ], - "referencedTableName": "public.order", - "updateRule": "cascade" - } - } - }, - { - "columns": { - "id": { - "name": "id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "text" - }, - "title": { - "name": "title", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "text" - }, - "subtitle": { - "name": "subtitle", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "thumbnail": { - "name": "thumbnail", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "variant_id": { - "name": "variant_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "product_id": { - "name": "product_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "product_title": { - "name": "product_title", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "product_description": { - "name": "product_description", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "product_subtitle": { - "name": "product_subtitle", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "product_type": { - "name": "product_type", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "product_type_id": { - "name": "product_type_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "product_collection": { - "name": "product_collection", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "product_handle": { - "name": "product_handle", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "variant_sku": { - "name": "variant_sku", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "variant_barcode": { - "name": "variant_barcode", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "variant_title": { - "name": "variant_title", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "variant_option_values": { - "name": "variant_option_values", - "type": "jsonb", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "json" - }, - "requires_shipping": { - "name": "requires_shipping", - "type": "boolean", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "default": "true", - "mappedType": "boolean" - }, - "is_discountable": { - "name": "is_discountable", - "type": "boolean", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "default": "true", - "mappedType": "boolean" - }, - "is_tax_inclusive": { - "name": "is_tax_inclusive", - "type": "boolean", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "default": "false", - "mappedType": "boolean" - }, - "compare_at_unit_price": { - "name": "compare_at_unit_price", - "type": "numeric", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "decimal" - }, - "unit_price": { - "name": "unit_price", - "type": "numeric", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "decimal" - }, - "is_custom_price": { - "name": "is_custom_price", - "type": "boolean", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "default": "false", - "mappedType": "boolean" - }, - "metadata": { - "name": "metadata", - "type": "jsonb", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "json" - }, - "raw_compare_at_unit_price": { - "name": "raw_compare_at_unit_price", - "type": "jsonb", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "json" - }, - "raw_unit_price": { - "name": "raw_unit_price", - "type": "jsonb", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "json" - }, - "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": "order_line_item", - "schema": "public", - "indexes": [ - { - "keyName": "IDX_order_line_item_deleted_at", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_line_item_deleted_at\" ON \"order_line_item\" (deleted_at) WHERE deleted_at IS NULL" - }, - { - "keyName": "IDX_order_line_item_deleted_at", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_line_item_deleted_at\" ON \"order_line_item\" (deleted_at) WHERE deleted_at IS NOT NULL" - }, - { - "keyName": "IDX_order_line_item_product_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_line_item_product_id\" ON \"order_line_item\" (product_id) WHERE deleted_at IS NOT NULL" - }, - { - "keyName": "IDX_line_item_product_type_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_line_item_product_type_id\" ON \"order_line_item\" (product_type_id) WHERE deleted_at IS NOT NULL AND product_type_id IS NOT NULL" - }, - { - "keyName": "IDX_order_line_item_variant_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_line_item_variant_id\" ON \"order_line_item\" (variant_id) WHERE deleted_at IS NOT NULL" - }, - { - "keyName": "order_line_item_pkey", - "columnNames": [ - "id" - ], - "composite": false, - "primary": true, - "unique": true - } - ], - "checks": [], - "foreignKeys": {} - }, - { - "columns": { - "id": { - "name": "id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "text" - }, - "version": { - "name": "version", - "type": "integer", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "integer" - }, - "unit_price": { - "name": "unit_price", - "type": "numeric", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "decimal" - }, - "compare_at_unit_price": { - "name": "compare_at_unit_price", - "type": "numeric", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "decimal" - }, - "quantity": { - "name": "quantity", - "type": "numeric", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "decimal" - }, - "fulfilled_quantity": { - "name": "fulfilled_quantity", - "type": "numeric", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "default": "0", - "mappedType": "decimal" - }, - "delivered_quantity": { - "name": "delivered_quantity", - "type": "numeric", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "default": "0", - "mappedType": "decimal" - }, - "shipped_quantity": { - "name": "shipped_quantity", - "type": "numeric", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "default": "0", - "mappedType": "decimal" - }, - "return_requested_quantity": { - "name": "return_requested_quantity", - "type": "numeric", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "default": "0", - "mappedType": "decimal" - }, - "return_received_quantity": { - "name": "return_received_quantity", - "type": "numeric", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "default": "0", - "mappedType": "decimal" - }, - "return_dismissed_quantity": { - "name": "return_dismissed_quantity", - "type": "numeric", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "default": "0", - "mappedType": "decimal" - }, - "written_off_quantity": { - "name": "written_off_quantity", - "type": "numeric", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "default": "0", - "mappedType": "decimal" - }, - "metadata": { - "name": "metadata", - "type": "jsonb", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "json" - }, - "order_id": { - "name": "order_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "text" - }, - "item_id": { - "name": "item_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "text" - }, - "raw_unit_price": { - "name": "raw_unit_price", - "type": "jsonb", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "json" - }, - "raw_compare_at_unit_price": { - "name": "raw_compare_at_unit_price", - "type": "jsonb", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "json" - }, - "raw_quantity": { - "name": "raw_quantity", - "type": "jsonb", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "json" - }, - "raw_fulfilled_quantity": { - "name": "raw_fulfilled_quantity", - "type": "jsonb", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "json" - }, - "raw_delivered_quantity": { - "name": "raw_delivered_quantity", - "type": "jsonb", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "json" - }, - "raw_shipped_quantity": { - "name": "raw_shipped_quantity", - "type": "jsonb", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "json" - }, - "raw_return_requested_quantity": { - "name": "raw_return_requested_quantity", - "type": "jsonb", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "json" - }, - "raw_return_received_quantity": { - "name": "raw_return_received_quantity", - "type": "jsonb", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "json" - }, - "raw_return_dismissed_quantity": { - "name": "raw_return_dismissed_quantity", - "type": "jsonb", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "json" - }, - "raw_written_off_quantity": { - "name": "raw_written_off_quantity", - "type": "jsonb", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "json" - }, - "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": "order_item", - "schema": "public", - "indexes": [ - { - "keyName": "IDX_order_item_order_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_item_order_id\" ON \"order_item\" (order_id) WHERE deleted_at IS NULL" - }, - { - "keyName": "IDX_order_item_item_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_item_item_id\" ON \"order_item\" (item_id) WHERE deleted_at IS NULL" - }, - { - "keyName": "IDX_order_item_deleted_at", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_item_deleted_at\" ON \"order_item\" (deleted_at) WHERE deleted_at IS NULL" - }, - { - "keyName": "IDX_order_item_order_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_item_order_id\" ON \"order_item\" (order_id) WHERE deleted_at IS NOT NULL" - }, - { - "keyName": "IDX_order_item_version", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_item_version\" ON \"order_item\" (version) WHERE deleted_at IS NOT NULL" - }, - { - "keyName": "IDX_order_item_item_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_item_item_id\" ON \"order_item\" (item_id) WHERE deleted_at IS NOT NULL" - }, - { - "keyName": "IDX_order_item_deleted_at", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_item_deleted_at\" ON \"order_item\" (deleted_at) WHERE deleted_at IS NOT NULL" - }, - { - "keyName": "order_item_pkey", - "columnNames": [ - "id" - ], - "composite": false, - "primary": true, - "unique": true - } - ], - "checks": [], - "foreignKeys": { - "order_item_order_id_foreign": { - "constraintName": "order_item_order_id_foreign", - "columnNames": [ - "order_id" - ], - "localTableName": "public.order_item", - "referencedColumnNames": [ - "id" - ], - "referencedTableName": "public.order", - "updateRule": "cascade" - }, - "order_item_item_id_foreign": { - "constraintName": "order_item_item_id_foreign", - "columnNames": [ - "item_id" - ], - "localTableName": "public.order_item", - "referencedColumnNames": [ - "id" - ], - "referencedTableName": "public.order_line_item", - "updateRule": "cascade" - } - } - }, - { - "columns": { - "id": { - "name": "id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "text" - }, - "quantity": { - "name": "quantity", - "type": "numeric", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "decimal" - }, - "note": { - "name": "note", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "metadata": { - "name": "metadata", - "type": "jsonb", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "json" - }, - "exchange_id": { - "name": "exchange_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "text" - }, - "item_id": { - "name": "item_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "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", - "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": "order_exchange_item", - "schema": "public", - "indexes": [ - { - "keyName": "IDX_order_exchange_item_exchange_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_exchange_item_exchange_id\" ON \"order_exchange_item\" (exchange_id) WHERE deleted_at IS NULL" - }, - { - "keyName": "IDX_order_exchange_item_item_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_exchange_item_item_id\" ON \"order_exchange_item\" (item_id) WHERE deleted_at IS NULL" - }, - { - "keyName": "IDX_order_exchange_item_deleted_at", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_exchange_item_deleted_at\" ON \"order_exchange_item\" (deleted_at) WHERE deleted_at IS NULL" - }, - { - "keyName": "IDX_order_exchange_item_exchange_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_exchange_item_exchange_id\" ON \"order_exchange_item\" (exchange_id) WHERE deleted_at IS NOT NULL" - }, - { - "keyName": "IDX_order_exchange_item_item_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_exchange_item_item_id\" ON \"order_exchange_item\" (item_id) WHERE deleted_at IS NOT NULL" - }, - { - "keyName": "IDX_order_exchange_item_deleted_at", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_exchange_item_deleted_at\" ON \"order_exchange_item\" (deleted_at) WHERE deleted_at IS NOT NULL" - }, - { - "keyName": "order_exchange_item_pkey", - "columnNames": [ - "id" - ], - "composite": false, - "primary": true, - "unique": true - } - ], - "checks": [], - "foreignKeys": { - "order_exchange_item_exchange_id_foreign": { - "constraintName": "order_exchange_item_exchange_id_foreign", - "columnNames": [ - "exchange_id" - ], - "localTableName": "public.order_exchange_item", - "referencedColumnNames": [ - "id" - ], - "referencedTableName": "public.order_exchange", - "updateRule": "cascade" - }, - "order_exchange_item_item_id_foreign": { - "constraintName": "order_exchange_item_item_id_foreign", - "columnNames": [ - "item_id" - ], - "localTableName": "public.order_exchange_item", - "referencedColumnNames": [ - "id" - ], - "referencedTableName": "public.order_line_item", - "updateRule": "cascade" - } - } - }, - { - "columns": { - "id": { - "name": "id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "text" - }, - "reason": { - "name": "reason", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "enumItems": [ - "missing_item", - "wrong_item", - "production_failure", - "other" - ], - "mappedType": "enum" - }, - "quantity": { - "name": "quantity", - "type": "numeric", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "decimal" - }, - "is_additional_item": { - "name": "is_additional_item", - "type": "boolean", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "default": "false", - "mappedType": "boolean" - }, - "note": { - "name": "note", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "metadata": { - "name": "metadata", - "type": "jsonb", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "json" - }, - "claim_id": { - "name": "claim_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "text" - }, - "item_id": { - "name": "item_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "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", - "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": "order_claim_item", - "schema": "public", - "indexes": [ - { - "keyName": "IDX_order_claim_item_claim_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_claim_item_claim_id\" ON \"order_claim_item\" (claim_id) WHERE deleted_at IS NULL" - }, - { - "keyName": "IDX_order_claim_item_item_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_claim_item_item_id\" ON \"order_claim_item\" (item_id) WHERE deleted_at IS NULL" - }, - { - "keyName": "IDX_order_claim_item_deleted_at", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_claim_item_deleted_at\" ON \"order_claim_item\" (deleted_at) WHERE deleted_at IS NULL" - }, - { - "keyName": "IDX_order_claim_item_claim_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_claim_item_claim_id\" ON \"order_claim_item\" (claim_id) WHERE deleted_at IS NOT NULL" - }, - { - "keyName": "IDX_order_claim_item_item_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_claim_item_item_id\" ON \"order_claim_item\" (item_id) WHERE deleted_at IS NOT NULL" - }, - { - "keyName": "IDX_order_claim_item_deleted_at", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_claim_item_deleted_at\" ON \"order_claim_item\" (deleted_at) WHERE deleted_at IS NOT NULL" - }, - { - "keyName": "order_claim_item_pkey", - "columnNames": [ - "id" - ], - "composite": false, - "primary": true, - "unique": true - } - ], - "checks": [], - "foreignKeys": { - "order_claim_item_claim_id_foreign": { - "constraintName": "order_claim_item_claim_id_foreign", - "columnNames": [ - "claim_id" - ], - "localTableName": "public.order_claim_item", - "referencedColumnNames": [ - "id" - ], - "referencedTableName": "public.order_claim", - "updateRule": "cascade" - }, - "order_claim_item_item_id_foreign": { - "constraintName": "order_claim_item_item_id_foreign", - "columnNames": [ - "item_id" - ], - "localTableName": "public.order_claim_item", - "referencedColumnNames": [ - "id" - ], - "referencedTableName": "public.order_line_item", - "updateRule": "cascade" - } - } - }, - { - "columns": { - "id": { - "name": "id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "text" - }, - "claim_item_id": { - "name": "claim_item_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "text" - }, - "url": { - "name": "url", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "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", - "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": "order_claim_item_image", - "schema": "public", - "indexes": [ - { - "keyName": "IDX_order_claim_item_image_claim_item_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_claim_item_image_claim_item_id\" ON \"order_claim_item_image\" (claim_item_id) WHERE deleted_at IS NULL" - }, - { - "keyName": "IDX_order_claim_item_image_deleted_at", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_claim_item_image_deleted_at\" ON \"order_claim_item_image\" (deleted_at) WHERE deleted_at IS NULL" - }, - { - "keyName": "IDX_order_claim_item_image_deleted_at", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_claim_item_image_deleted_at\" ON \"order_claim_item_image\" (deleted_at) WHERE deleted_at IS NOT NULL" - }, - { - "keyName": "IDX_order_claim_item_image_claim_item_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_claim_item_image_claim_item_id\" ON \"order_claim_item_image\" (claim_item_id) WHERE deleted_at IS NOT NULL" - }, - { - "keyName": "order_claim_item_image_pkey", - "columnNames": [ - "id" - ], - "composite": false, - "primary": true, - "unique": true - } - ], - "checks": [], - "foreignKeys": { - "order_claim_item_image_claim_item_id_foreign": { - "constraintName": "order_claim_item_image_claim_item_id_foreign", - "columnNames": [ - "claim_item_id" - ], - "localTableName": "public.order_claim_item_image", - "referencedColumnNames": [ - "id" - ], - "referencedTableName": "public.order_claim_item", - "updateRule": "cascade" - } - } - }, - { - "columns": { - "id": { - "name": "id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "text" - }, - "description": { - "name": "description", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "promotion_id": { - "name": "promotion_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "code": { - "name": "code", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "amount": { - "name": "amount", - "type": "numeric", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "decimal" - }, - "provider_id": { - "name": "provider_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "item_id": { - "name": "item_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "text" - }, - "raw_amount": { - "name": "raw_amount", - "type": "jsonb", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "json" - }, - "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": "order_line_item_adjustment", - "schema": "public", - "indexes": [ - { - "keyName": "IDX_order_line_item_adjustment_item_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_line_item_adjustment_item_id\" ON \"order_line_item_adjustment\" (item_id) WHERE deleted_at IS NULL" - }, - { - "keyName": "IDX_order_line_item_adjustment_deleted_at", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_line_item_adjustment_deleted_at\" ON \"order_line_item_adjustment\" (deleted_at) WHERE deleted_at IS NULL" - }, - { - "keyName": "IDX_order_order_line_item_adjustment_item_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_order_line_item_adjustment_item_id\" ON \"order_line_item_adjustment\" (item_id) WHERE deleted_at IS NULL" - }, - { - "keyName": "order_line_item_adjustment_pkey", - "columnNames": [ - "id" - ], - "composite": false, - "primary": true, - "unique": true - } - ], - "checks": [], - "foreignKeys": { - "order_line_item_adjustment_item_id_foreign": { - "constraintName": "order_line_item_adjustment_item_id_foreign", - "columnNames": [ - "item_id" - ], - "localTableName": "public.order_line_item_adjustment", - "referencedColumnNames": [ - "id" - ], - "referencedTableName": "public.order_line_item", - "updateRule": "cascade" - } - } - }, - { - "columns": { - "id": { - "name": "id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "text" - }, - "description": { - "name": "description", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "tax_rate_id": { - "name": "tax_rate_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "code": { - "name": "code", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "text" - }, - "rate": { - "name": "rate", - "type": "numeric", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "decimal" - }, - "provider_id": { - "name": "provider_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "item_id": { - "name": "item_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "text" - }, - "raw_rate": { - "name": "raw_rate", - "type": "jsonb", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "json" - }, - "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": "order_line_item_tax_line", - "schema": "public", - "indexes": [ - { - "keyName": "IDX_order_line_item_tax_line_item_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_line_item_tax_line_item_id\" ON \"order_line_item_tax_line\" (item_id) WHERE deleted_at IS NULL" - }, - { - "keyName": "IDX_order_line_item_tax_line_deleted_at", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_line_item_tax_line_deleted_at\" ON \"order_line_item_tax_line\" (deleted_at) WHERE deleted_at IS NULL" - }, - { - "keyName": "order_line_item_tax_line_pkey", - "columnNames": [ - "id" - ], - "composite": false, - "primary": true, - "unique": true - } - ], - "checks": [], - "foreignKeys": { - "order_line_item_tax_line_item_id_foreign": { - "constraintName": "order_line_item_tax_line_item_id_foreign", - "columnNames": [ - "item_id" - ], - "localTableName": "public.order_line_item_tax_line", - "referencedColumnNames": [ - "id" - ], - "referencedTableName": "public.order_line_item", - "updateRule": "cascade" - } - } - }, - { - "columns": { - "id": { - "name": "id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "text" - }, - "name": { - "name": "name", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "text" - }, - "description": { - "name": "description", - "type": "jsonb", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "json" - }, - "amount": { - "name": "amount", - "type": "numeric", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "decimal" - }, - "is_tax_inclusive": { - "name": "is_tax_inclusive", - "type": "boolean", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "boolean" - }, - "is_custom_amount": { - "name": "is_custom_amount", - "type": "boolean", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "boolean" - }, - "shipping_option_id": { - "name": "shipping_option_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "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" - }, - "raw_amount": { - "name": "raw_amount", - "type": "jsonb", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "json" - }, - "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": "order_shipping_method", - "schema": "public", - "indexes": [ - { - "keyName": "IDX_order_shipping_method_deleted_at", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_method_deleted_at\" ON \"order_shipping_method\" (deleted_at) WHERE deleted_at IS NULL" - }, - { - "keyName": "IDX_order_shipping_method_shipping_option_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_method_shipping_option_id\" ON \"order_shipping_method\" (shipping_option_id) WHERE deleted_at IS NULL" - }, - { - "keyName": "order_shipping_method_pkey", - "columnNames": [ - "id" - ], - "composite": false, - "primary": true, - "unique": true - } - ], - "checks": [], - "foreignKeys": {} - }, - { - "columns": { - "id": { - "name": "id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "text" - }, - "description": { - "name": "description", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "promotion_id": { - "name": "promotion_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "code": { - "name": "code", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "amount": { - "name": "amount", - "type": "numeric", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "decimal" - }, - "provider_id": { - "name": "provider_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "shipping_method_id": { - "name": "shipping_method_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "text" - }, - "raw_amount": { - "name": "raw_amount", - "type": "jsonb", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "json" - }, - "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": "order_shipping_method_adjustment", - "schema": "public", - "indexes": [ - { - "keyName": "IDX_order_shipping_method_adjustment_shipping_method_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_method_adjustment_shipping_method_id\" ON \"order_shipping_method_adjustment\" (shipping_method_id) WHERE deleted_at IS NULL" - }, - { - "keyName": "IDX_order_shipping_method_adjustment_deleted_at", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_method_adjustment_deleted_at\" ON \"order_shipping_method_adjustment\" (deleted_at) WHERE deleted_at IS NULL" - }, - { - "keyName": "order_shipping_method_adjustment_pkey", - "columnNames": [ - "id" - ], - "composite": false, - "primary": true, - "unique": true - } - ], - "checks": [], - "foreignKeys": { - "order_shipping_method_adjustment_shipping_method_id_foreign": { - "constraintName": "order_shipping_method_adjustment_shipping_method_id_foreign", - "columnNames": [ - "shipping_method_id" - ], - "localTableName": "public.order_shipping_method_adjustment", - "referencedColumnNames": [ - "id" - ], - "referencedTableName": "public.order_shipping_method", - "updateRule": "cascade" - } - } - }, - { - "columns": { - "id": { - "name": "id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "text" - }, - "description": { - "name": "description", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "tax_rate_id": { - "name": "tax_rate_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "code": { - "name": "code", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "text" - }, - "rate": { - "name": "rate", - "type": "numeric", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "decimal" - }, - "provider_id": { - "name": "provider_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "shipping_method_id": { - "name": "shipping_method_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "text" - }, - "raw_rate": { - "name": "raw_rate", - "type": "jsonb", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "json" - }, - "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": "order_shipping_method_tax_line", - "schema": "public", - "indexes": [ - { - "keyName": "IDX_order_shipping_method_tax_line_shipping_method_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_method_tax_line_shipping_method_id\" ON \"order_shipping_method_tax_line\" (shipping_method_id) WHERE deleted_at IS NULL" - }, - { - "keyName": "IDX_order_shipping_method_tax_line_deleted_at", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_method_tax_line_deleted_at\" ON \"order_shipping_method_tax_line\" (deleted_at) WHERE deleted_at IS NULL" - }, - { - "keyName": "order_shipping_method_tax_line_pkey", - "columnNames": [ - "id" - ], - "composite": false, - "primary": true, - "unique": true - } - ], - "checks": [], - "foreignKeys": { - "order_shipping_method_tax_line_shipping_method_id_foreign": { - "constraintName": "order_shipping_method_tax_line_shipping_method_id_foreign", - "columnNames": [ - "shipping_method_id" - ], - "localTableName": "public.order_shipping_method_tax_line", - "referencedColumnNames": [ - "id" - ], - "referencedTableName": "public.order_shipping_method", - "updateRule": "cascade" - } - } - }, - { - "columns": { - "id": { - "name": "id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "text" - }, - "version": { - "name": "version", - "type": "integer", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "default": "1", - "mappedType": "integer" - }, - "totals": { - "name": "totals", - "type": "jsonb", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "json" - }, - "order_id": { - "name": "order_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "text" - }, - "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": "order_summary", - "schema": "public", - "indexes": [ - { - "keyName": "IDX_order_summary_order_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_summary_order_id\" ON \"order_summary\" (order_id) WHERE deleted_at IS NULL" - }, - { - "keyName": "IDX_order_summary_deleted_at", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_summary_deleted_at\" ON \"order_summary\" (deleted_at) WHERE deleted_at IS NULL" - }, - { - "keyName": "IDX_order_summary_order_id_version", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_summary_order_id_version\" ON \"order_summary\" (order_id, version) WHERE deleted_at IS NOT NULL" - }, - { - "keyName": "IDX_order_summary_deleted_at", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_summary_deleted_at\" ON \"order_summary\" (deleted_at) WHERE deleted_at IS NOT NULL" - }, - { - "keyName": "order_summary_pkey", - "columnNames": [ - "id" - ], - "composite": false, - "primary": true, - "unique": true - } - ], - "checks": [], - "foreignKeys": { - "order_summary_order_id_foreign": { - "constraintName": "order_summary_order_id_foreign", - "columnNames": [ - "order_id" - ], - "localTableName": "public.order_summary", - "referencedColumnNames": [ - "id" - ], - "referencedTableName": "public.order", - "updateRule": "cascade" - } - } - }, - { - "columns": { - "id": { - "name": "id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "text" - }, - "order_version": { - "name": "order_version", - "type": "integer", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "integer" - }, - "display_id": { - "name": "display_id", - "type": "bigserial", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "bigint" - }, - "status": { - "name": "status", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "default": "'open'", - "enumItems": [ - "open", - "requested", - "received", - "partially_received", - "canceled" - ], - "mappedType": "enum" - }, - "location_id": { - "name": "location_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "no_notification": { - "name": "no_notification", - "type": "boolean", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "boolean" - }, - "refund_amount": { - "name": "refund_amount", - "type": "numeric", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "decimal" - }, - "created_by": { - "name": "created_by", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "metadata": { - "name": "metadata", - "type": "jsonb", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "json" - }, - "requested_at": { - "name": "requested_at", - "type": "timestamptz", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "length": 6, - "mappedType": "datetime" - }, - "received_at": { - "name": "received_at", - "type": "timestamptz", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "length": 6, - "mappedType": "datetime" - }, - "canceled_at": { - "name": "canceled_at", - "type": "timestamptz", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "length": 6, - "mappedType": "datetime" - }, - "order_id": { - "name": "order_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "text" - }, - "exchange_id": { - "name": "exchange_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "text" - }, - "claim_id": { - "name": "claim_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "text" - }, - "raw_refund_amount": { - "name": "raw_refund_amount", - "type": "jsonb", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "json" - }, - "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": "return", - "schema": "public", - "indexes": [ - { - "keyName": "IDX_return_order_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_order_id\" ON \"return\" (order_id) WHERE deleted_at IS NULL" - }, - { - "keyName": "IDX_return_exchange_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_exchange_id\" ON \"return\" (exchange_id) WHERE deleted_at IS NULL" - }, - { - "keyName": "IDX_return_claim_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_claim_id\" ON \"return\" (claim_id) WHERE deleted_at IS NULL" - }, - { - "keyName": "IDX_return_deleted_at", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_deleted_at\" ON \"return\" (deleted_at) WHERE deleted_at IS NULL" - }, - { - "keyName": "IDX_return_display_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_display_id\" ON \"return\" (display_id) WHERE deleted_at IS NOT NULL" - }, - { - "keyName": "IDX_return_deleted_at", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_deleted_at\" ON \"return\" (deleted_at) WHERE deleted_at IS NOT NULL" - }, - { - "keyName": "IDX_return_order_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_order_id\" ON \"return\" (order_id) WHERE deleted_at IS NOT NULL" - }, - { - "keyName": "IDX_return_exchange_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_exchange_id\" ON \"return\" (exchange_id) WHERE exchange_id IS NOT NULL AND deleted_at IS NOT NULL" - }, - { - "keyName": "IDX_return_claim_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_claim_id\" ON \"return\" (claim_id) WHERE claim_id IS NOT NULL AND deleted_at IS NOT NULL" - }, - { - "keyName": "return_pkey", - "columnNames": [ - "id" - ], - "composite": false, - "primary": true, - "unique": true - } - ], - "checks": [], - "foreignKeys": { - "return_order_id_foreign": { - "constraintName": "return_order_id_foreign", - "columnNames": [ - "order_id" - ], - "localTableName": "public.return", - "referencedColumnNames": [ - "id" - ], - "referencedTableName": "public.order", - "updateRule": "cascade" - }, - "return_exchange_id_foreign": { - "constraintName": "return_exchange_id_foreign", - "columnNames": [ - "exchange_id" - ], - "localTableName": "public.return", - "referencedColumnNames": [ - "id" - ], - "referencedTableName": "public.order_exchange", - "updateRule": "cascade" - }, - "return_claim_id_foreign": { - "constraintName": "return_claim_id_foreign", - "columnNames": [ - "claim_id" - ], - "localTableName": "public.return", - "referencedColumnNames": [ - "id" - ], - "referencedTableName": "public.order_claim", - "updateRule": "cascade" - } - } - }, - { - "columns": { - "id": { - "name": "id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "text" - }, - "version": { - "name": "version", - "type": "integer", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "default": "1", - "mappedType": "integer" - }, - "amount": { - "name": "amount", - "type": "numeric", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "decimal" - }, - "currency_code": { - "name": "currency_code", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "text" - }, - "reference": { - "name": "reference", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "reference_id": { - "name": "reference_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "order_id": { - "name": "order_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "text" - }, - "return_id": { - "name": "return_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "text" - }, - "exchange_id": { - "name": "exchange_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "text" - }, - "claim_id": { - "name": "claim_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "text" - }, - "raw_amount": { - "name": "raw_amount", - "type": "jsonb", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "json" - }, - "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": "order_transaction", - "schema": "public", - "indexes": [ - { - "keyName": "IDX_order_transaction_order_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_transaction_order_id\" ON \"order_transaction\" (order_id) WHERE deleted_at IS NULL" - }, - { - "keyName": "IDX_order_transaction_return_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_transaction_return_id\" ON \"order_transaction\" (return_id) WHERE deleted_at IS NULL" - }, - { - "keyName": "IDX_order_transaction_exchange_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_transaction_exchange_id\" ON \"order_transaction\" (exchange_id) WHERE deleted_at IS NULL" - }, - { - "keyName": "IDX_order_transaction_claim_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_transaction_claim_id\" ON \"order_transaction\" (claim_id) WHERE deleted_at IS NULL" - }, - { - "keyName": "IDX_order_transaction_deleted_at", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_transaction_deleted_at\" ON \"order_transaction\" (deleted_at) WHERE deleted_at IS NULL" - }, - { - "keyName": "IDX_order_transaction_reference_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_transaction_reference_id\" ON \"order_transaction\" (reference_id) WHERE deleted_at IS NOT NULL" - }, - { - "keyName": "IDX_order_transaction_order_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_transaction_order_id\" ON \"order_transaction\" (order_id) WHERE deleted_at IS NOT NULL" - }, - { - "keyName": "IDX_order_transaction_return_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_transaction_return_id\" ON \"order_transaction\" (return_id) WHERE return_id IS NOT NULL AND deleted_at IS NOT NULL" - }, - { - "keyName": "IDX_order_transaction_exchange_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_transaction_exchange_id\" ON \"order_transaction\" (exchange_id) WHERE exchange_id IS NOT NULL AND deleted_at IS NOT NULL" - }, - { - "keyName": "IDX_order_transaction_claim_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_transaction_claim_id\" ON \"order_transaction\" (claim_id) WHERE claim_id IS NOT NULL AND deleted_at IS NOT NULL" - }, - { - "keyName": "IDX_order_transaction_currency_code", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_transaction_currency_code\" ON \"order_transaction\" (currency_code) WHERE deleted_at IS NOT NULL" - }, - { - "keyName": "IDX_order_transaction_deleted_at", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_transaction_deleted_at\" ON \"order_transaction\" (deleted_at) WHERE deleted_at IS NOT NULL" - }, - { - "keyName": "IDX_order_transaction_order_id_version", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_transaction_order_id_version\" ON \"order_transaction\" (order_id, version) WHERE deleted_at IS NOT NULL" - }, - { - "keyName": "order_transaction_pkey", - "columnNames": [ - "id" - ], - "composite": false, - "primary": true, - "unique": true - } - ], - "checks": [], - "foreignKeys": { - "order_transaction_order_id_foreign": { - "constraintName": "order_transaction_order_id_foreign", - "columnNames": [ - "order_id" - ], - "localTableName": "public.order_transaction", - "referencedColumnNames": [ - "id" - ], - "referencedTableName": "public.order", - "updateRule": "cascade" - }, - "order_transaction_return_id_foreign": { - "constraintName": "order_transaction_return_id_foreign", - "columnNames": [ - "return_id" - ], - "localTableName": "public.order_transaction", - "referencedColumnNames": [ - "id" - ], - "referencedTableName": "public.return", - "updateRule": "cascade" - }, - "order_transaction_exchange_id_foreign": { - "constraintName": "order_transaction_exchange_id_foreign", - "columnNames": [ - "exchange_id" - ], - "localTableName": "public.order_transaction", - "referencedColumnNames": [ - "id" - ], - "referencedTableName": "public.order_exchange", - "updateRule": "cascade" - }, - "order_transaction_claim_id_foreign": { - "constraintName": "order_transaction_claim_id_foreign", - "columnNames": [ - "claim_id" - ], - "localTableName": "public.order_transaction", - "referencedColumnNames": [ - "id" - ], - "referencedTableName": "public.order_claim", - "updateRule": "cascade" - } - } - }, - { - "columns": { - "id": { - "name": "id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "text" - }, - "version": { - "name": "version", - "type": "integer", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "integer" - }, - "order_id": { - "name": "order_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "text" - }, - "return_id": { - "name": "return_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "exchange_id": { - "name": "exchange_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "claim_id": { - "name": "claim_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "shipping_method_id": { - "name": "shipping_method_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "text" - }, - "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": "order_shipping", - "schema": "public", - "indexes": [ - { - "keyName": "IDX_order_shipping_order_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_order_id\" ON \"order_shipping\" (order_id) WHERE deleted_at IS NULL" - }, - { - "keyName": "IDX_order_shipping_return_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_return_id\" ON \"order_shipping\" (return_id) WHERE deleted_at IS NULL" - }, - { - "keyName": "IDX_order_shipping_exchange_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_exchange_id\" ON \"order_shipping\" (exchange_id) WHERE deleted_at IS NULL" - }, - { - "keyName": "IDX_order_shipping_claim_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_claim_id\" ON \"order_shipping\" (claim_id) WHERE deleted_at IS NULL" - }, - { - "keyName": "IDX_order_shipping_shipping_method_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_shipping_method_id\" ON \"order_shipping\" (shipping_method_id) WHERE deleted_at IS NULL" - }, - { - "keyName": "IDX_order_shipping_deleted_at", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_deleted_at\" ON \"order_shipping\" (deleted_at) WHERE deleted_at IS NULL" - }, - { - "keyName": "IDX_order_shipping_order_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_order_id\" ON \"order_shipping\" (order_id) WHERE deleted_at IS NOT NULL" - }, - { - "keyName": "IDX_order_shipping_return_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_return_id\" ON \"order_shipping\" (return_id) WHERE return_id IS NOT NULL AND deleted_at IS NOT NULL" - }, - { - "keyName": "IDX_order_shipping_exchange_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_exchange_id\" ON \"order_shipping\" (exchange_id) WHERE exchange_id IS NOT NULL AND deleted_at IS NOT NULL" - }, - { - "keyName": "IDX_order_shipping_claim_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_claim_id\" ON \"order_shipping\" (claim_id) WHERE claim_id IS NOT NULL AND deleted_at IS NOT NULL" - }, - { - "keyName": "IDX_order_shipping_version", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_version\" ON \"order_shipping\" (version) WHERE deleted_at IS NOT NULL" - }, - { - "keyName": "IDX_order_shipping_shipping_method_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_shipping_method_id\" ON \"order_shipping\" (shipping_method_id) WHERE deleted_at IS NOT NULL" - }, - { - "keyName": "IDX_order_shipping_deleted_at", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_deleted_at\" ON \"order_shipping\" (deleted_at) WHERE deleted_at IS NOT NULL" - }, - { - "keyName": "order_shipping_pkey", - "columnNames": [ - "id" - ], - "composite": false, - "primary": true, - "unique": true - } - ], - "checks": [], - "foreignKeys": { - "order_shipping_order_id_foreign": { - "constraintName": "order_shipping_order_id_foreign", - "columnNames": [ - "order_id" - ], - "localTableName": "public.order_shipping", - "referencedColumnNames": [ - "id" - ], - "referencedTableName": "public.order", - "updateRule": "cascade" - }, - "order_shipping_return_id_foreign": { - "constraintName": "order_shipping_return_id_foreign", - "columnNames": [ - "return_id" - ], - "localTableName": "public.order_shipping", - "referencedColumnNames": [ - "id" - ], - "referencedTableName": "public.return", - "deleteRule": "set null", - "updateRule": "cascade" - }, - "order_shipping_exchange_id_foreign": { - "constraintName": "order_shipping_exchange_id_foreign", - "columnNames": [ - "exchange_id" - ], - "localTableName": "public.order_shipping", - "referencedColumnNames": [ - "id" - ], - "referencedTableName": "public.order_exchange", - "deleteRule": "set null", - "updateRule": "cascade" - }, - "order_shipping_claim_id_foreign": { - "constraintName": "order_shipping_claim_id_foreign", - "columnNames": [ - "claim_id" - ], - "localTableName": "public.order_shipping", - "referencedColumnNames": [ - "id" - ], - "referencedTableName": "public.order_claim", - "deleteRule": "set null", - "updateRule": "cascade" - }, - "order_shipping_shipping_method_id_foreign": { - "constraintName": "order_shipping_shipping_method_id_foreign", - "columnNames": [ - "shipping_method_id" - ], - "localTableName": "public.order_shipping", - "referencedColumnNames": [ - "id" - ], - "referencedTableName": "public.order_shipping_method", - "updateRule": "cascade" - } - } - }, - { - "columns": { - "id": { - "name": "id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "text" - }, - "version": { - "name": "version", - "type": "integer", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "integer" - }, - "change_type": { - "name": "change_type", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "description": { - "name": "description", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "status": { - "name": "status", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "default": "'pending'", - "enumItems": [ - "confirmed", - "declined", - "requested", - "pending", - "canceled" - ], - "mappedType": "enum" - }, - "internal_note": { - "name": "internal_note", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "created_by": { - "name": "created_by", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "text" - }, - "requested_by": { - "name": "requested_by", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "requested_at": { - "name": "requested_at", - "type": "timestamptz", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "length": 6, - "mappedType": "datetime" - }, - "confirmed_by": { - "name": "confirmed_by", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "confirmed_at": { - "name": "confirmed_at", - "type": "timestamptz", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "length": 6, - "mappedType": "datetime" - }, - "declined_by": { - "name": "declined_by", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "declined_reason": { - "name": "declined_reason", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "metadata": { - "name": "metadata", - "type": "jsonb", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "json" - }, - "declined_at": { - "name": "declined_at", - "type": "timestamptz", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "length": 6, - "mappedType": "datetime" - }, - "canceled_by": { - "name": "canceled_by", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "canceled_at": { - "name": "canceled_at", - "type": "timestamptz", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "length": 6, - "mappedType": "datetime" - }, - "order_id": { - "name": "order_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "text" - }, - "return_id": { - "name": "return_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "claim_id": { - "name": "claim_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "exchange_id": { - "name": "exchange_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "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": "order_change", - "schema": "public", - "indexes": [ - { - "keyName": "IDX_order_change_order_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_order_id\" ON \"order_change\" (order_id) WHERE deleted_at IS NULL" - }, - { - "keyName": "IDX_order_change_return_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_return_id\" ON \"order_change\" (return_id) WHERE deleted_at IS NULL" - }, - { - "keyName": "IDX_order_change_claim_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_claim_id\" ON \"order_change\" (claim_id) WHERE deleted_at IS NULL" - }, - { - "keyName": "IDX_order_change_exchange_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_exchange_id\" ON \"order_change\" (exchange_id) WHERE deleted_at IS NULL" - }, - { - "keyName": "IDX_order_change_deleted_at", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_deleted_at\" ON \"order_change\" (deleted_at) WHERE deleted_at IS NULL" - }, - { - "keyName": "IDX_order_change_order_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_order_id\" ON \"order_change\" (order_id) WHERE deleted_at IS NOT NULL" - }, - { - "keyName": "IDX_order_change_return_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_return_id\" ON \"order_change\" (return_id) WHERE return_id IS NOT NULL AND deleted_at IS NOT NULL" - }, - { - "keyName": "IDX_order_change_claim_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_claim_id\" ON \"order_change\" (claim_id) WHERE claim_id IS NOT NULL AND deleted_at IS NOT NULL" - }, - { - "keyName": "IDX_order_change_exchange_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_exchange_id\" ON \"order_change\" (exchange_id) WHERE exchange_id IS NOT NULL AND deleted_at IS NOT NULL" - }, - { - "keyName": "IDX_order_change_status", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_status\" ON \"order_change\" (status) WHERE deleted_at IS NOT NULL" - }, - { - "keyName": "IDX_order_change_deleted_at", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_deleted_at\" ON \"order_change\" (deleted_at) WHERE deleted_at IS NOT NULL" - }, - { - "keyName": "IDX_order_change_version", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_version\" ON \"order_change\" (order_id, version) WHERE deleted_at IS NOT NULL" - }, - { - "keyName": "order_change_pkey", - "columnNames": [ - "id" - ], - "composite": false, - "primary": true, - "unique": true - } - ], - "checks": [], - "foreignKeys": { - "order_change_order_id_foreign": { - "constraintName": "order_change_order_id_foreign", - "columnNames": [ - "order_id" - ], - "localTableName": "public.order_change", - "referencedColumnNames": [ - "id" - ], - "referencedTableName": "public.order", - "updateRule": "cascade" - }, - "order_change_return_id_foreign": { - "constraintName": "order_change_return_id_foreign", - "columnNames": [ - "return_id" - ], - "localTableName": "public.order_change", - "referencedColumnNames": [ - "id" - ], - "referencedTableName": "public.return", - "deleteRule": "set null", - "updateRule": "cascade" - }, - "order_change_claim_id_foreign": { - "constraintName": "order_change_claim_id_foreign", - "columnNames": [ - "claim_id" - ], - "localTableName": "public.order_change", - "referencedColumnNames": [ - "id" - ], - "referencedTableName": "public.order_claim", - "deleteRule": "set null", - "updateRule": "cascade" - }, - "order_change_exchange_id_foreign": { - "constraintName": "order_change_exchange_id_foreign", - "columnNames": [ - "exchange_id" - ], - "localTableName": "public.order_change", - "referencedColumnNames": [ - "id" - ], - "referencedTableName": "public.order_exchange", - "deleteRule": "set null", - "updateRule": "cascade" - } - } - }, - { - "columns": { - "id": { - "name": "id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "text" - }, - "ordering": { - "name": "ordering", - "type": "bigserial", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "bigint" - }, - "order_id": { - "name": "order_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "return_id": { - "name": "return_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "claim_id": { - "name": "claim_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "exchange_id": { - "name": "exchange_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "version": { - "name": "version", - "type": "integer", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "integer" - }, - "reference": { - "name": "reference", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "reference_id": { - "name": "reference_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "action": { - "name": "action", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "text" - }, - "details": { - "name": "details", - "type": "jsonb", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "json" - }, - "amount": { - "name": "amount", - "type": "numeric", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "decimal" - }, - "internal_note": { - "name": "internal_note", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "applied": { - "name": "applied", - "type": "boolean", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "default": "false", - "mappedType": "boolean" - }, - "order_change_id": { - "name": "order_change_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "text" - }, - "raw_amount": { - "name": "raw_amount", - "type": "jsonb", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "json" - }, - "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": "order_change_action", - "schema": "public", - "indexes": [ - { - "keyName": "IDX_order_change_action_order_change_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_action_order_change_id\" ON \"order_change_action\" (order_change_id) WHERE deleted_at IS NULL" - }, - { - "keyName": "IDX_order_change_action_deleted_at", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_action_deleted_at\" ON \"order_change_action\" (deleted_at) WHERE deleted_at IS NULL" - }, - { - "keyName": "IDX_order_change_action_order_change_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_action_order_change_id\" ON \"order_change_action\" (order_change_id) WHERE deleted_at IS NOT NULL" - }, - { - "keyName": "IDX_order_change_action_order_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_action_order_id\" ON \"order_change_action\" (order_id) WHERE deleted_at IS NOT NULL" - }, - { - "keyName": "IDX_order_change_action_return_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_action_return_id\" ON \"order_change_action\" (return_id) WHERE return_id IS NOT NULL AND deleted_at IS NOT NULL" - }, - { - "keyName": "IDX_order_change_action_claim_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_action_claim_id\" ON \"order_change_action\" (claim_id) WHERE claim_id IS NOT NULL AND deleted_at IS NOT NULL" - }, - { - "keyName": "IDX_order_change_action_exchange_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_action_exchange_id\" ON \"order_change_action\" (exchange_id) WHERE exchange_id IS NOT NULL AND deleted_at IS NOT NULL" - }, - { - "keyName": "IDX_order_change_action_deleted_at", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_action_deleted_at\" ON \"order_change_action\" (deleted_at) WHERE deleted_at IS NOT NULL" - }, - { - "keyName": "IDX_order_change_action_ordering", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_action_ordering\" ON \"order_change_action\" (ordering) WHERE deleted_at IS NOT NULL" - }, - { - "keyName": "order_change_action_pkey", - "columnNames": [ - "id" - ], - "composite": false, - "primary": true, - "unique": true - } - ], - "checks": [], - "foreignKeys": { - "order_change_action_order_change_id_foreign": { - "constraintName": "order_change_action_order_change_id_foreign", - "columnNames": [ - "order_change_id" - ], - "localTableName": "public.order_change_action", - "referencedColumnNames": [ - "id" - ], - "referencedTableName": "public.order_change", - "updateRule": "cascade" - } - } - }, - { - "columns": { - "id": { - "name": "id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "text" - }, - "value": { - "name": "value", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "text" - }, - "label": { - "name": "label", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "text" - }, - "description": { - "name": "description", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "metadata": { - "name": "metadata", - "type": "jsonb", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "json" - }, - "parent_return_reason_id": { - "name": "parent_return_reason_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "text" - }, - "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": "return_reason", - "schema": "public", - "indexes": [ - { - "keyName": "IDX_return_reason_parent_return_reason_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_reason_parent_return_reason_id\" ON \"return_reason\" (parent_return_reason_id) WHERE deleted_at IS NULL" - }, - { - "keyName": "IDX_return_reason_deleted_at", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_reason_deleted_at\" ON \"return_reason\" (deleted_at) WHERE deleted_at IS NULL" - }, - { - "keyName": "IDX_return_reason_deleted_at", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_reason_deleted_at\" ON \"return_reason\" (deleted_at) WHERE deleted_at IS NOT NULL" - }, - { - "keyName": "IDX_return_reason_value", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_reason_value\" ON \"return_reason\" (value) WHERE deleted_at IS NOT NULL" - }, - { - "keyName": "IDX_return_reason_parent_return_reason_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_reason_parent_return_reason_id\" ON \"return_reason\" (parent_return_reason_id) WHERE deleted_at IS NOT NULL" - }, - { - "keyName": "return_reason_pkey", - "columnNames": [ - "id" - ], - "composite": false, - "primary": true, - "unique": true - } - ], - "checks": [], - "foreignKeys": { - "return_reason_parent_return_reason_id_foreign": { - "constraintName": "return_reason_parent_return_reason_id_foreign", - "columnNames": [ - "parent_return_reason_id" - ], - "localTableName": "public.return_reason", - "referencedColumnNames": [ - "id" - ], - "referencedTableName": "public.return_reason", - "updateRule": "cascade" - } - } - }, - { - "columns": { - "id": { - "name": "id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "text" - }, - "quantity": { - "name": "quantity", - "type": "numeric", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "decimal" - }, - "received_quantity": { - "name": "received_quantity", - "type": "numeric", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "default": "0", - "mappedType": "decimal" - }, - "damaged_quantity": { - "name": "damaged_quantity", - "type": "numeric", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "default": "0", - "mappedType": "decimal" - }, - "note": { - "name": "note", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "metadata": { - "name": "metadata", - "type": "jsonb", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "json" - }, - "reason_id": { - "name": "reason_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, - "return_id": { - "name": "return_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "text" - }, - "item_id": { - "name": "item_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "text" - }, - "raw_quantity": { - "name": "raw_quantity", - "type": "jsonb", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "json" - }, - "raw_received_quantity": { - "name": "raw_received_quantity", - "type": "jsonb", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "json" - }, - "raw_damaged_quantity": { - "name": "raw_damaged_quantity", - "type": "jsonb", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "json" - }, - "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": "return_item", - "schema": "public", - "indexes": [ - { - "keyName": "IDX_return_item_reason_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_item_reason_id\" ON \"return_item\" (reason_id) WHERE deleted_at IS NULL" - }, - { - "keyName": "IDX_return_item_return_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_item_return_id\" ON \"return_item\" (return_id) WHERE deleted_at IS NULL" - }, - { - "keyName": "IDX_return_item_item_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_item_item_id\" ON \"return_item\" (item_id) WHERE deleted_at IS NULL" - }, - { - "keyName": "IDX_return_item_deleted_at", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_item_deleted_at\" ON \"return_item\" (deleted_at) WHERE deleted_at IS NULL" - }, - { - "keyName": "IDX_return_item_return_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_item_return_id\" ON \"return_item\" (return_id) WHERE deleted_at IS NOT NULL" - }, - { - "keyName": "IDX_return_item_reason_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_item_reason_id\" ON \"return_item\" (reason_id) WHERE deleted_at IS NOT NULL" - }, - { - "keyName": "IDX_return_item_item_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_item_item_id\" ON \"return_item\" (item_id) WHERE deleted_at IS NOT NULL" - }, - { - "keyName": "IDX_return_item_deleted_at", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_item_deleted_at\" ON \"return_item\" (deleted_at) WHERE deleted_at IS NOT NULL" - }, - { - "keyName": "return_item_pkey", - "columnNames": [ - "id" - ], - "composite": false, - "primary": true, - "unique": true - } - ], - "checks": [], - "foreignKeys": { - "return_item_reason_id_foreign": { - "constraintName": "return_item_reason_id_foreign", - "columnNames": [ - "reason_id" - ], - "localTableName": "public.return_item", - "referencedColumnNames": [ - "id" - ], - "referencedTableName": "public.return_reason", - "deleteRule": "set null", - "updateRule": "cascade" - }, - "return_item_return_id_foreign": { - "constraintName": "return_item_return_id_foreign", - "columnNames": [ - "return_id" - ], - "localTableName": "public.return_item", - "referencedColumnNames": [ - "id" - ], - "referencedTableName": "public.return", - "updateRule": "cascade" - }, - "return_item_item_id_foreign": { - "constraintName": "return_item_item_id_foreign", - "columnNames": [ - "item_id" - ], - "localTableName": "public.return_item", - "referencedColumnNames": [ - "id" - ], - "referencedTableName": "public.order_line_item", - "updateRule": "cascade" - } - } - } - ] -} diff --git a/packages/modules/order/src/migrations/Migration20241127185510.ts b/packages/modules/order/src/migrations/Migration20241127185510.ts deleted file mode 100644 index a3d922b88b35b..0000000000000 --- a/packages/modules/order/src/migrations/Migration20241127185510.ts +++ /dev/null @@ -1,707 +0,0 @@ -import { Migration } from "@mikro-orm/migrations" - -export class Migration20241127185510 extends Migration { - async up(): Promise { - this.addSql( - 'alter table if exists "order_claim" drop constraint if exists "order_claim_return_id_foreign";' - ) - - this.addSql( - 'alter table if exists "order_exchange" drop constraint if exists "order_exchange_return_id_foreign";' - ) - - this.addSql( - 'alter table if exists "order_exchange_item" drop constraint if exists "order_exchange_item_exchange_id_foreign";' - ) - - this.addSql( - 'alter table if exists "order_claim_item" drop constraint if exists "order_claim_item_claim_id_foreign";' - ) - - this.addSql( - 'alter table if exists "order_line_item_adjustment" drop constraint if exists "order_line_item_adjustment_item_id_foreign";' - ) - - this.addSql( - 'alter table if exists "order_line_item_tax_line" drop constraint if exists "order_line_item_tax_line_item_id_foreign";' - ) - - this.addSql( - 'alter table if exists "order_shipping_method_adjustment" drop constraint if exists "order_shipping_method_adjustment_shipping_method_id_foreign";' - ) - - this.addSql( - 'alter table if exists "order_shipping_method_tax_line" drop constraint if exists "order_shipping_method_tax_line_shipping_method_id_foreign";' - ) - - this.addSql( - 'alter table if exists "order_summary" drop constraint if exists "order_summary_order_id_foreign";' - ) - - this.addSql( - 'alter table if exists "return" drop constraint if exists "return_exchange_id_foreign";' - ) - this.addSql( - 'alter table if exists "return" drop constraint if exists "return_claim_id_foreign";' - ) - - this.addSql( - 'alter table if exists "order_transaction" drop constraint if exists "order_transaction_order_id_foreign";' - ) - this.addSql( - 'alter table if exists "order_transaction" drop constraint if exists "order_transaction_return_id_foreign";' - ) - this.addSql( - 'alter table if exists "order_transaction" drop constraint if exists "order_transaction_exchange_id_foreign";' - ) - this.addSql( - 'alter table if exists "order_transaction" drop constraint if exists "order_transaction_claim_id_foreign";' - ) - - this.addSql( - 'alter table if exists "order_change" drop constraint if exists "order_change_status_check";' - ) - - this.addSql( - 'alter table if exists "order_change" drop constraint if exists "order_change_order_id_foreign";' - ) - - this.addSql( - 'alter table if exists "order_change_action" drop constraint if exists "order_change_action_order_id_foreign";' - ) - this.addSql( - 'alter table if exists "order_change_action" drop constraint if exists "order_change_action_return_id_foreign";' - ) - this.addSql( - 'alter table if exists "order_change_action" drop constraint if exists "order_change_action_claim_id_foreign";' - ) - this.addSql( - 'alter table if exists "order_change_action" drop constraint if exists "order_change_action_exchange_id_foreign";' - ) - this.addSql( - 'alter table if exists "order_change_action" drop constraint if exists "order_change_action_order_change_id_foreign";' - ) - - this.addSql( - 'alter table if exists "return_reason" drop constraint if exists "return_reason_parent_return_reason_id_foreign";' - ) - - this.addSql( - 'alter table if exists "return_item" drop constraint if exists "return_item_return_id_foreign";' - ) - - this.addSql( - 'alter table if exists "order_address" add column if not exists "deleted_at" timestamptz null;' - ) - this.addSql( - 'CREATE INDEX IF NOT EXISTS "IDX_order_address_deleted_at" ON "order_address" (deleted_at) WHERE deleted_at IS NULL;' - ) - - this.addSql( - 'alter table if exists "order" alter column "display_id" type bigint using ("display_id"::bigint);' - ) - this.addSql( - 'alter table if exists "order" alter column "display_id" drop not null;' - ) - this.addSql( - 'alter table if exists "order" alter column "display_id" drop default;' - ) - this.addSql( - 'CREATE INDEX IF NOT EXISTS "IDX_order_sales_channel_id" ON "order" (sales_channel_id) WHERE deleted_at IS NOT NULL;' - ) - - this.addSql( - 'alter table if exists "order_claim" alter column "display_id" type bigint using ("display_id"::bigint);' - ) - this.addSql( - 'alter table if exists "order_claim" drop constraint if exists "order_claim_return_id_unique";' - ) - this.addSql( - 'alter table if exists "order_claim" alter column "display_id" drop default;' - ) - - this.addSql( - 'alter table if exists "order_exchange" alter column "display_id" type bigint using ("display_id"::bigint);' - ) - this.addSql( - 'alter table if exists "order_exchange" drop constraint if exists "order_exchange_return_id_unique";' - ) - this.addSql( - 'alter table if exists "order_exchange" alter column "display_id" drop default;' - ) - - this.addSql( - 'alter table if exists "order_line_item" alter column "requires_shipping" type boolean using ("requires_shipping"::boolean);' - ) - this.addSql( - 'alter table if exists "order_line_item" alter column "requires_shipping" set default true;' - ) - this.addSql( - 'alter table if exists "order_line_item" alter column "is_discountable" type boolean using ("is_discountable"::boolean);' - ) - this.addSql( - 'alter table if exists "order_line_item" alter column "is_discountable" set default true;' - ) - - this.addSql( - 'alter table if exists "order_line_item" alter column "unit_price" type numeric using ("unit_price"::numeric);' - ) - this.addSql( - 'alter table if exists "order_line_item" alter column "unit_price" set not null;' - ) - - this.addSql( - 'alter table if exists "order_item" alter column "fulfilled_quantity" type numeric using ("fulfilled_quantity"::numeric);' - ) - this.addSql( - 'alter table if exists "order_item" alter column "fulfilled_quantity" set default 0;' - ) - this.addSql( - 'alter table if exists "order_item" alter column "delivered_quantity" type numeric using ("delivered_quantity"::numeric);' - ) - this.addSql( - 'alter table if exists "order_item" alter column "delivered_quantity" set default 0;' - ) - this.addSql( - 'alter table if exists "order_item" alter column "shipped_quantity" type numeric using ("shipped_quantity"::numeric);' - ) - this.addSql( - 'alter table if exists "order_item" alter column "shipped_quantity" set default 0;' - ) - this.addSql( - 'alter table if exists "order_item" alter column "return_requested_quantity" type numeric using ("return_requested_quantity"::numeric);' - ) - this.addSql( - 'alter table if exists "order_item" alter column "return_requested_quantity" set default 0;' - ) - this.addSql( - 'alter table if exists "order_item" alter column "return_received_quantity" type numeric using ("return_received_quantity"::numeric);' - ) - this.addSql( - 'alter table if exists "order_item" alter column "return_received_quantity" set default 0;' - ) - this.addSql( - 'alter table if exists "order_item" alter column "return_dismissed_quantity" type numeric using ("return_dismissed_quantity"::numeric);' - ) - this.addSql( - 'alter table if exists "order_item" alter column "return_dismissed_quantity" set default 0;' - ) - this.addSql( - 'alter table if exists "order_item" alter column "written_off_quantity" type numeric using ("written_off_quantity"::numeric);' - ) - this.addSql( - 'alter table if exists "order_item" alter column "written_off_quantity" set default 0;' - ) - - this.addSql('drop index if exists "IDX_order_claim_item_image_deleted_at";') - this.addSql( - 'alter table if exists "order_exchange_item" add constraint "order_exchange_item_exchange_id_foreign" foreign key ("exchange_id") references "order_exchange" ("id") on update cascade;' - ) - this.addSql( - 'CREATE INDEX IF NOT EXISTS "IDX_order_exchange_item_deleted_at" ON "order_exchange_item" (deleted_at) WHERE deleted_at IS NOT NULL;' - ) - - this.addSql( - 'alter table if exists "order_claim_item" add constraint "order_claim_item_claim_id_foreign" foreign key ("claim_id") references "order_claim" ("id") on update cascade;' - ) - - this.addSql( - 'alter table if exists "order_line_item_adjustment" add constraint "order_line_item_adjustment_item_id_foreign" foreign key ("item_id") references "order_line_item" ("id") on update cascade;' - ) - this.addSql( - 'CREATE INDEX IF NOT EXISTS "IDX_order_line_item_adjustment_deleted_at" ON "order_line_item_adjustment" (deleted_at) WHERE deleted_at IS NULL;' - ) - this.addSql( - 'CREATE INDEX IF NOT EXISTS "IDX_order_order_line_item_adjustment_item_id" ON "order_line_item_adjustment" (item_id) WHERE deleted_at IS NULL;' - ) - - this.addSql( - 'alter table if exists "order_line_item_tax_line" alter column "item_id" type text using ("item_id"::text);' - ) - this.addSql( - 'alter table if exists "order_line_item_tax_line" alter column "item_id" set not null;' - ) - this.addSql( - 'alter table if exists "order_line_item_tax_line" add constraint "order_line_item_tax_line_item_id_foreign" foreign key ("item_id") references "order_line_item" ("id") on update cascade;' - ) - this.addSql( - 'CREATE INDEX IF NOT EXISTS "IDX_order_line_item_tax_line_deleted_at" ON "order_line_item_tax_line" (deleted_at) WHERE deleted_at IS NULL;' - ) - - this.addSql( - 'alter table if exists "order_shipping_method_adjustment" add constraint "order_shipping_method_adjustment_shipping_method_id_foreign" foreign key ("shipping_method_id") references "order_shipping_method" ("id") on update cascade;' - ) - this.addSql( - 'CREATE INDEX IF NOT EXISTS "IDX_order_shipping_method_adjustment_deleted_at" ON "order_shipping_method_adjustment" (deleted_at) WHERE deleted_at IS NULL;' - ) - - this.addSql( - 'alter table if exists "order_shipping_method_tax_line" add constraint "order_shipping_method_tax_line_shipping_method_id_foreign" foreign key ("shipping_method_id") references "order_shipping_method" ("id") on update cascade;' - ) - this.addSql( - 'CREATE INDEX IF NOT EXISTS "IDX_order_shipping_method_tax_line_deleted_at" ON "order_shipping_method_tax_line" (deleted_at) WHERE deleted_at IS NULL;' - ) - - this.addSql( - 'alter table if exists "order_summary" add constraint "order_summary_order_id_foreign" foreign key ("order_id") references "order" ("id") on update cascade;' - ) - this.addSql( - 'CREATE INDEX IF NOT EXISTS "IDX_order_summary_order_id" ON "order_summary" (order_id) WHERE deleted_at IS NULL;' - ) - - this.addSql( - 'alter table if exists "return" alter column "exchange_id" type text using ("exchange_id"::text);' - ) - this.addSql( - 'alter table if exists "return" alter column "exchange_id" set not null;' - ) - - this.addSql( - 'alter table if exists "return" alter column "display_id" type bigint using ("display_id"::bigint);' - ) - this.addSql( - 'alter table if exists "return" drop constraint if exists "return_exchange_id_unique";' - ) - this.addSql( - 'alter table if exists "return" drop constraint if exists "return_claim_id_unique";' - ) - this.addSql( - 'alter table if exists "return" alter column "display_id" drop default;' - ) - this.addSql( - 'alter table if exists "return" add constraint "return_exchange_id_foreign" foreign key ("exchange_id") references "order_exchange" ("id") on update cascade;' - ) - this.addSql( - 'alter table if exists "return" add constraint "return_claim_id_foreign" foreign key ("claim_id") references "order_claim" ("id") on update cascade;' - ) - - this.addSql( - 'alter table if exists "order_transaction" alter column "exchange_id" type text using ("exchange_id"::text);' - ) - - this.addSql( - 'alter table if exists "order_transaction" add constraint "order_transaction_order_id_foreign" foreign key ("order_id") references "order" ("id") on update cascade;' - ) - this.addSql( - 'alter table if exists "order_transaction" add constraint "order_transaction_return_id_foreign" foreign key ("return_id") references "return" ("id") on update cascade;' - ) - this.addSql( - 'alter table if exists "order_transaction" add constraint "order_transaction_exchange_id_foreign" foreign key ("exchange_id") references "order_exchange" ("id") on update cascade;' - ) - this.addSql( - 'alter table if exists "order_transaction" add constraint "order_transaction_claim_id_foreign" foreign key ("claim_id") references "order_claim" ("id") on update cascade;' - ) - - this.addSql( - 'alter table if exists "order_change" alter column "status" type text using ("status"::text);' - ) - this.addSql( - "alter table if exists \"order_change\" add constraint \"order_change_status_check\" check (\"status\" in ('confirmed', 'declined', 'requested', 'pending', 'canceled'));" - ) - this.addSql( - 'alter table if exists "order_change" alter column "status" drop not null;' - ) - - this.addSql('drop index if exists "IDX_order_change_order_id_version";') - this.addSql( - 'alter table if exists "order_change" add constraint "order_change_order_id_foreign" foreign key ("order_id") references "order" ("id") on update cascade;' - ) - this.addSql( - 'CREATE INDEX IF NOT EXISTS "IDX_order_change_version" ON "order_change" (order_id, version) WHERE deleted_at IS NOT NULL;' - ) - - this.addSql( - 'alter table if exists "order_change_action" alter column "ordering" type bigint using ("ordering"::bigint);' - ) - this.addSql( - 'alter table if exists "order_change_action" alter column "order_change_id" type text using ("order_change_id"::text);' - ) - - this.addSql( - 'alter table if exists "order_change_action" alter column "ordering" drop default;' - ) - this.addSql( - 'alter table if exists "order_change_action" add constraint "order_change_action_order_change_id_foreign" foreign key ("order_change_id") references "order_change" ("id") on update cascade;' - ) - - this.addSql( - 'alter table if exists "return_reason" alter column "parent_return_reason_id" type text using ("parent_return_reason_id"::text);' - ) - this.addSql( - 'alter table if exists "return_reason" alter column "parent_return_reason_id" set not null;' - ) - this.addSql( - 'alter table if exists "return_reason" add constraint "return_reason_parent_return_reason_id_foreign" foreign key ("parent_return_reason_id") references "return_reason" ("id") on update cascade;' - ) - - this.addSql( - 'alter table if exists "return_item" add constraint "return_item_return_id_foreign" foreign key ("return_id") references "return" ("id") on update cascade;' - ) - - this.addSql(` - ALTER TABLE "order_address" - ADD COLUMN if NOT exists "deleted_at" timestamptz NULL; - `) - } - - async down(): Promise { - this.addSql( - 'alter table if exists "order_line_item_adjustment" drop constraint if exists "order_line_item_adjustment_item_id_foreign";' - ) - - this.addSql( - 'alter table if exists "order_line_item_tax_line" drop constraint if exists "order_line_item_tax_line_item_id_foreign";' - ) - - this.addSql( - 'alter table if exists "order_shipping_method_adjustment" drop constraint if exists "order_shipping_method_adjustment_shipping_method_id_foreign";' - ) - - this.addSql( - 'alter table if exists "order_shipping_method_tax_line" drop constraint if exists "order_shipping_method_tax_line_shipping_method_id_foreign";' - ) - - this.addSql( - 'alter table if exists "order_summary" drop constraint if exists "order_summary_order_id_foreign";' - ) - - this.addSql( - 'alter table if exists "return" drop constraint if exists "return_exchange_id_foreign";' - ) - this.addSql( - 'alter table if exists "return" drop constraint if exists "return_claim_id_foreign";' - ) - - this.addSql( - 'alter table if exists "order_exchange_item" drop constraint if exists "order_exchange_item_exchange_id_foreign";' - ) - - this.addSql( - 'alter table if exists "order_transaction" drop constraint if exists "order_transaction_order_id_foreign";' - ) - this.addSql( - 'alter table if exists "order_transaction" drop constraint if exists "order_transaction_return_id_foreign";' - ) - this.addSql( - 'alter table if exists "order_transaction" drop constraint if exists "order_transaction_exchange_id_foreign";' - ) - this.addSql( - 'alter table if exists "order_transaction" drop constraint if exists "order_transaction_claim_id_foreign";' - ) - - this.addSql( - 'alter table if exists "order_claim_item" drop constraint if exists "order_claim_item_claim_id_foreign";' - ) - - this.addSql( - 'alter table if exists "order_change" drop constraint if exists "order_change_status_check";' - ) - - this.addSql( - 'alter table if exists "order_change" drop constraint if exists "order_change_order_id_foreign";' - ) - - this.addSql( - 'alter table if exists "order_change_action" drop constraint if exists "order_change_action_order_change_id_foreign";' - ) - - this.addSql( - 'alter table if exists "return_reason" drop constraint if exists "return_reason_parent_return_reason_id_foreign";' - ) - - this.addSql( - 'alter table if exists "return_item" drop constraint if exists "return_item_return_id_foreign";' - ) - - this.addSql('drop index if exists "IDX_order_address_deleted_at";') - this.addSql( - 'alter table if exists "order_address" drop column if exists "deleted_at";' - ) - - this.addSql( - 'alter table if exists "order" alter column "display_id" type int using ("display_id"::int);' - ) - this.addSql( - 'alter table if exists "order" alter column "display_id" set not null;' - ) - this.addSql('drop index if exists "IDX_order_sales_channel_id";') - this.addSql('create sequence if not exists "order_display_id_seq";') - this.addSql( - 'select setval(\'order_display_id_seq\', (select max("display_id") from "order"));' - ) - this.addSql( - 'alter table if exists "order" alter column "display_id" set default nextval(\'order_display_id_seq\');' - ) - - this.addSql( - 'alter table if exists "order_line_item" alter column "is_tax_inclusive" drop default;' - ) - this.addSql( - 'alter table if exists "order_line_item" alter column "is_tax_inclusive" type boolean using ("is_tax_inclusive"::boolean);' - ) - this.addSql( - 'alter table if exists "order_line_item" alter column "unit_price" type numeric using ("unit_price"::numeric);' - ) - this.addSql( - 'alter table if exists "order_line_item" alter column "unit_price" drop not null;' - ) - - this.addSql( - 'alter table if exists "order_item" alter column "fulfilled_quantity" drop default;' - ) - this.addSql( - 'alter table if exists "order_item" alter column "fulfilled_quantity" type numeric using ("fulfilled_quantity"::numeric);' - ) - this.addSql( - 'alter table if exists "order_item" alter column "delivered_quantity" drop default;' - ) - this.addSql( - 'alter table if exists "order_item" alter column "delivered_quantity" type numeric using ("delivered_quantity"::numeric);' - ) - this.addSql( - 'alter table if exists "order_item" alter column "shipped_quantity" drop default;' - ) - this.addSql( - 'alter table if exists "order_item" alter column "shipped_quantity" type numeric using ("shipped_quantity"::numeric);' - ) - this.addSql( - 'alter table if exists "order_item" alter column "return_requested_quantity" drop default;' - ) - this.addSql( - 'alter table if exists "order_item" alter column "return_requested_quantity" type numeric using ("return_requested_quantity"::numeric);' - ) - this.addSql( - 'alter table if exists "order_item" alter column "return_received_quantity" drop default;' - ) - this.addSql( - 'alter table if exists "order_item" alter column "return_received_quantity" type numeric using ("return_received_quantity"::numeric);' - ) - this.addSql( - 'alter table if exists "order_item" alter column "return_dismissed_quantity" drop default;' - ) - this.addSql( - 'alter table if exists "order_item" alter column "return_dismissed_quantity" type numeric using ("return_dismissed_quantity"::numeric);' - ) - this.addSql( - 'alter table if exists "order_item" alter column "written_off_quantity" drop default;' - ) - this.addSql( - 'alter table if exists "order_item" alter column "written_off_quantity" type numeric using ("written_off_quantity"::numeric);' - ) - - this.addSql( - 'drop index if exists "IDX_order_line_item_adjustment_deleted_at";' - ) - this.addSql( - 'drop index if exists "IDX_order_order_line_item_adjustment_item_id";' - ) - this.addSql( - 'alter table if exists "order_line_item_adjustment" add constraint "order_line_item_adjustment_item_id_foreign" foreign key ("item_id") references "order_line_item" ("id") on update cascade on delete cascade;' - ) - - this.addSql( - 'alter table if exists "order_line_item_tax_line" alter column "item_id" type text using ("item_id"::text);' - ) - this.addSql( - 'alter table if exists "order_line_item_tax_line" alter column "item_id" drop not null;' - ) - this.addSql( - 'drop index if exists "IDX_order_line_item_tax_line_deleted_at";' - ) - this.addSql( - 'alter table if exists "order_line_item_tax_line" add constraint "order_line_item_tax_line_item_id_foreign" foreign key ("item_id") references "order_line_item" ("id") on update cascade on delete cascade;' - ) - - this.addSql( - 'alter table if exists "order_shipping_method" alter column "is_tax_inclusive" type boolean using ("is_tax_inclusive"::boolean);' - ) - this.addSql( - 'alter table if exists "order_shipping_method" alter column "is_tax_inclusive" set default false;' - ) - - this.addSql( - 'drop index if exists "IDX_order_shipping_method_adjustment_deleted_at";' - ) - this.addSql( - 'alter table if exists "order_shipping_method_adjustment" add constraint "order_shipping_method_adjustment_shipping_method_id_foreign" foreign key ("shipping_method_id") references "order_shipping_method" ("id") on update cascade on delete cascade;' - ) - - this.addSql( - 'drop index if exists "IDX_order_shipping_method_tax_line_deleted_at";' - ) - this.addSql( - 'alter table if exists "order_shipping_method_tax_line" add constraint "order_shipping_method_tax_line_shipping_method_id_foreign" foreign key ("shipping_method_id") references "order_shipping_method" ("id") on update cascade on delete cascade;' - ) - - this.addSql('drop index if exists "IDX_order_summary_order_id";') - this.addSql( - 'alter table if exists "order_summary" add constraint "order_summary_order_id_foreign" foreign key ("order_id") references "order" ("id") on update cascade on delete cascade;' - ) - - this.addSql( - 'alter table if exists "return" alter column "display_id" type int using ("display_id"::int);' - ) - this.addSql( - 'alter table if exists "return" alter column "exchange_id" type text using ("exchange_id"::text);' - ) - this.addSql( - 'alter table if exists "return" alter column "exchange_id" drop not null;' - ) - this.addSql( - 'alter table if exists "return" alter column "claim_id" type text using ("claim_id"::text);' - ) - this.addSql( - 'alter table if exists "return" alter column "claim_id" drop not null;' - ) - this.addSql('create sequence if not exists "return_display_id_seq";') - this.addSql( - 'select setval(\'return_display_id_seq\', (select max("display_id") from "return"));' - ) - this.addSql( - 'alter table if exists "return" alter column "display_id" set default nextval(\'return_display_id_seq\');' - ) - this.addSql( - 'alter table if exists "return" add constraint "return_exchange_id_foreign" foreign key ("exchange_id") references "order_exchange" ("id") on update cascade on delete set null;' - ) - this.addSql( - 'alter table if exists "return" add constraint "return_claim_id_foreign" foreign key ("claim_id") references "order_claim" ("id") on update cascade on delete set null;' - ) - this.addSql( - 'alter table if exists "return" add constraint "return_exchange_id_unique" unique ("exchange_id");' - ) - this.addSql( - 'alter table if exists "return" add constraint "return_claim_id_unique" unique ("claim_id");' - ) - - this.addSql( - 'alter table if exists "order_exchange" alter column "display_id" type int using ("display_id"::int);' - ) - this.addSql( - 'create sequence if not exists "order_exchange_display_id_seq";' - ) - this.addSql( - 'select setval(\'order_exchange_display_id_seq\', (select max("display_id") from "order_exchange"));' - ) - this.addSql( - 'alter table if exists "order_exchange" alter column "display_id" set default nextval(\'order_exchange_display_id_seq\');' - ) - this.addSql( - 'alter table if exists "order_exchange" add constraint "order_exchange_return_id_foreign" foreign key ("return_id") references "return" ("id") on update cascade on delete set null;' - ) - this.addSql( - 'alter table if exists "order_exchange" add constraint "order_exchange_return_id_unique" unique ("return_id");' - ) - - this.addSql('drop index if exists "IDX_order_exchange_item_deleted_at";') - this.addSql( - 'alter table if exists "order_exchange_item" add constraint "order_exchange_item_exchange_id_foreign" foreign key ("exchange_id") references "order_exchange" ("id") on update cascade on delete cascade;' - ) - this.addSql( - 'CREATE INDEX IF NOT EXISTS "IDX_order_claim_item_image_deleted_at" ON "order_claim_item_image" (deleted_at) WHERE deleted_at IS NOT NULL;' - ) - - this.addSql( - 'alter table if exists "order_claim" alter column "display_id" type int using ("display_id"::int);' - ) - this.addSql('create sequence if not exists "order_claim_display_id_seq";') - this.addSql( - 'select setval(\'order_claim_display_id_seq\', (select max("display_id") from "order_claim"));' - ) - this.addSql( - 'alter table if exists "order_claim" alter column "display_id" set default nextval(\'order_claim_display_id_seq\');' - ) - this.addSql( - 'alter table if exists "order_claim" add constraint "order_claim_return_id_foreign" foreign key ("return_id") references "return" ("id") on update cascade on delete set null;' - ) - this.addSql( - 'alter table if exists "order_claim" add constraint "order_claim_return_id_unique" unique ("return_id");' - ) - - this.addSql( - 'alter table if exists "order_transaction" add constraint "order_transaction_order_id_foreign" foreign key ("order_id") references "order" ("id") on update cascade on delete cascade;' - ) - this.addSql( - 'alter table if exists "order_transaction" add constraint "order_transaction_return_id_foreign" foreign key ("return_id") references "return" ("id") on update cascade on delete set null;' - ) - this.addSql( - 'alter table if exists "order_transaction" add constraint "order_transaction_exchange_id_foreign" foreign key ("exchange_id") references "order_exchange" ("id") on update cascade on delete set null;' - ) - this.addSql( - 'alter table if exists "order_transaction" add constraint "order_transaction_claim_id_foreign" foreign key ("claim_id") references "order_claim" ("id") on update cascade on delete set null;' - ) - - this.addSql( - 'alter table if exists "order_claim_item" add constraint "order_claim_item_claim_id_foreign" foreign key ("claim_id") references "order_claim" ("id") on update cascade on delete cascade;' - ) - - this.addSql( - 'alter table if exists "order_change" alter column "status" type text using ("status"::text);' - ) - this.addSql( - "alter table if exists \"order_change\" add constraint \"order_change_status_check\" check (\"status\" in ('confirmed', 'declined', 'requested', 'pending', 'canceled'));" - ) - this.addSql( - 'alter table if exists "order_change" alter column "status" set not null;' - ) - - this.addSql('drop index if exists "IDX_order_change_version";') - this.addSql( - 'alter table if exists "order_change" add constraint "order_change_order_id_foreign" foreign key ("order_id") references "order" ("id") on update cascade on delete cascade;' - ) - this.addSql( - 'CREATE INDEX IF NOT EXISTS "IDX_order_change_order_id_version" ON "order_change" (order_id, version) WHERE deleted_at IS NOT NULL;' - ) - - this.addSql( - 'alter table if exists "order_change_action" alter column "ordering" type integer using ("ordering"::integer);' - ) - this.addSql( - 'alter table if exists "order_change_action" alter column "order_change_id" type text using ("order_change_id"::text);' - ) - this.addSql( - 'alter table if exists "order_change_action" alter column "order_change_id" drop not null;' - ) - this.addSql( - 'create sequence if not exists "order_change_action_ordering_seq";' - ) - this.addSql( - 'select setval(\'order_change_action_ordering_seq\', (select max("ordering") from "order_change_action"));' - ) - this.addSql( - 'alter table if exists "order_change_action" alter column "ordering" set default nextval(\'order_change_action_ordering_seq\');' - ) - this.addSql( - 'alter table if exists "order_change_action" add constraint "order_change_action_order_id_foreign" foreign key ("order_id") references "order" ("id") on update cascade on delete cascade;' - ) - this.addSql( - 'alter table if exists "order_change_action" add constraint "order_change_action_return_id_foreign" foreign key ("return_id") references "return" ("id") on update cascade on delete set null;' - ) - this.addSql( - 'alter table if exists "order_change_action" add constraint "order_change_action_claim_id_foreign" foreign key ("claim_id") references "order_claim" ("id") on update cascade on delete set null;' - ) - this.addSql( - 'alter table if exists "order_change_action" add constraint "order_change_action_exchange_id_foreign" foreign key ("exchange_id") references "order_exchange" ("id") on update cascade on delete set null;' - ) - this.addSql( - 'alter table if exists "order_change_action" add constraint "order_change_action_order_change_id_foreign" foreign key ("order_change_id") references "order_change" ("id") on update cascade on delete cascade;' - ) - - this.addSql( - 'alter table if exists "return_reason" alter column "parent_return_reason_id" type text using ("parent_return_reason_id"::text);' - ) - this.addSql( - 'alter table if exists "return_reason" alter column "parent_return_reason_id" drop not null;' - ) - this.addSql( - 'alter table if exists "return_reason" add constraint "return_reason_parent_return_reason_id_foreign" foreign key ("parent_return_reason_id") references "return_reason" ("id") on update cascade on delete set null;' - ) - - this.addSql( - 'alter table if exists "return_item" add constraint "return_item_return_id_foreign" foreign key ("return_id") references "return" ("id") on update cascade on delete cascade;' - ) - - this.addSql(` - ALTER TABLE "order_address" DROP COLUMN if exists "deleted_at" timestamptz NULL; - `) - } -} From f84dd391334cab10fe9c2eda89c2820f1b5c014d Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Fri, 29 Nov 2024 11:25:01 -0300 Subject: [PATCH 107/175] serial --- packages/core/types/src/dml/index.ts | 2 +- .../__tests__/autoincrement-property.spec.ts | 2 +- .../helpers/entity-builder/define-property.ts | 36 +- .../utils/src/dml/properties/autoincrement.ts | 6 +- .../__tests__/order-claim.ts | 4 +- .../migrations/.snapshot-medusa-order.json | 4985 +++++++++++++++++ .../src/migrations/Migration20241129124827.ts | 18 + .../order/src/models/order-change-action.ts | 2 +- 8 files changed, 5028 insertions(+), 27 deletions(-) create mode 100644 packages/modules/order/src/migrations/.snapshot-medusa-order.json create mode 100644 packages/modules/order/src/migrations/Migration20241129124827.ts diff --git a/packages/core/types/src/dml/index.ts b/packages/core/types/src/dml/index.ts index 235776965547d..430529a1e9bb5 100644 --- a/packages/core/types/src/dml/index.ts +++ b/packages/core/types/src/dml/index.ts @@ -47,7 +47,7 @@ export type KnownDataTypes = | "enum" | "number" | "bigNumber" - | "bigSerial" + | "serial" | "dateTime" | "array" | "json" diff --git a/packages/core/utils/src/dml/__tests__/autoincrement-property.spec.ts b/packages/core/utils/src/dml/__tests__/autoincrement-property.spec.ts index 498d060e8d07a..dd2a1e851bee2 100644 --- a/packages/core/utils/src/dml/__tests__/autoincrement-property.spec.ts +++ b/packages/core/utils/src/dml/__tests__/autoincrement-property.spec.ts @@ -9,7 +9,7 @@ describe("Autoincrement property", () => { expect(property.parse("display_id")).toEqual({ fieldName: "display_id", dataType: { - name: "bigSerial", + name: "serial", options: {}, }, nullable: false, diff --git a/packages/core/utils/src/dml/helpers/entity-builder/define-property.ts b/packages/core/utils/src/dml/helpers/entity-builder/define-property.ts index ceccb495132f8..bf525a37e7154 100644 --- a/packages/core/utils/src/dml/helpers/entity-builder/define-property.ts +++ b/packages/core/utils/src/dml/helpers/entity-builder/define-property.ts @@ -12,6 +12,7 @@ import { PrimaryKey, Property, Utils, + t as mikroOrmType, } from "@mikro-orm/core" import { generateEntityId, isDefined } from "../../../common" import { MikroOrmBigNumberProperty } from "../../../dal" @@ -32,7 +33,7 @@ const COLUMN_TYPES: { dateTime: "timestamptz", number: "integer", bigNumber: "numeric", - bigSerial: "bigserial", + serial: "serial", text: "text", json: "jsonb", array: "array", @@ -52,7 +53,7 @@ const PROPERTY_TYPES: { dateTime: "date", number: "number", bigNumber: "number", - bigSerial: "number", + serial: "number", text: "string", json: "any", array: "string[]", @@ -205,19 +206,16 @@ export function defineProperty( * Defining an id property */ if (field.dataType.name === "id") { - const IdDecorator = PrimaryKeyModifier.isPrimaryKeyModifier(property) - ? PrimaryKey({ - columnType: "text", - type: "string", - nullable: false, - fieldName: field.fieldName, - }) - : Property({ - columnType: "text", - type: "string", - nullable: false, - fieldName: field.fieldName, - }) + const Prop = PrimaryKeyModifier.isPrimaryKeyModifier(property) + ? PrimaryKey + : Property + + const IdDecorator = Prop({ + columnType: "text", + type: "string", + nullable: false, + fieldName: field.fieldName, + }) IdDecorator(MikroORMEntity.prototype, field.fieldName) @@ -263,12 +261,12 @@ export function defineProperty( } /** - * Handling bigSerial property separately to set the column type + * Handling serial property separately to set the column type */ - if (field.dataType.name === "bigSerial") { + if (field.dataType.name === "serial") { Property({ - columnType: "bigserial", - type: "number", + columnType: "serial", + type: mikroOrmType.integer, nullable: field.nullable, fieldName: field.fieldName, })(MikroORMEntity.prototype, field.fieldName) diff --git a/packages/core/utils/src/dml/properties/autoincrement.ts b/packages/core/utils/src/dml/properties/autoincrement.ts index ce25a78c73661..e78279db62026 100644 --- a/packages/core/utils/src/dml/properties/autoincrement.ts +++ b/packages/core/utils/src/dml/properties/autoincrement.ts @@ -2,12 +2,12 @@ import { BaseProperty } from "./base" import { PrimaryKeyModifier } from "./primary-key" /** - * The AutoIncrementProperty is used to define a bigserial + * The AutoIncrementProperty is used to define a serial * property */ export class AutoIncrementProperty extends BaseProperty { protected dataType: { - name: "bigSerial" + name: "serial" options: {} } @@ -34,7 +34,7 @@ export class AutoIncrementProperty extends BaseProperty { super() this.dataType = { - name: "bigSerial", + name: "serial", options: { ...options }, } } diff --git a/packages/modules/order/integration-tests/__tests__/order-claim.ts b/packages/modules/order/integration-tests/__tests__/order-claim.ts index 7e21175c0622e..e3fdc96d07c15 100644 --- a/packages/modules/order/integration-tests/__tests__/order-claim.ts +++ b/packages/modules/order/integration-tests/__tests__/order-claim.ts @@ -103,7 +103,7 @@ moduleIntegrationTestRunner({ customer_id: "joe", } as CreateOrderDTO - it.only("should claim an item and add two new items to the order", async function () { + it("should claim an item and add two new items to the order", async function () { const createdOrder = await service.createOrders(input) createdOrder.items = createdOrder.items!.sort((a, b) => a.title.localeCompare(b.title) @@ -140,9 +140,9 @@ moduleIntegrationTestRunner({ internal_note: "user wants to return all items", shipping_methods: [ { + shipping_option_id: "shipping_dhl_id", name: "Claim method", amount: 35, - provider_id: "dhl", }, ], claim_items: [ diff --git a/packages/modules/order/src/migrations/.snapshot-medusa-order.json b/packages/modules/order/src/migrations/.snapshot-medusa-order.json new file mode 100644 index 0000000000000..25057c8b0a8ec --- /dev/null +++ b/packages/modules/order/src/migrations/.snapshot-medusa-order.json @@ -0,0 +1,4985 @@ +{ + "namespaces": ["public"], + "name": "public", + "tables": [ + { + "columns": { + "id": { + "name": "id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "customer_id": { + "name": "customer_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "company": { + "name": "company", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "first_name": { + "name": "first_name", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "last_name": { + "name": "last_name", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "address_1": { + "name": "address_1", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "address_2": { + "name": "address_2", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "city": { + "name": "city", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "country_code": { + "name": "country_code", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "province": { + "name": "province", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "postal_code": { + "name": "postal_code", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "phone": { + "name": "phone", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "json" + }, + "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": "order_address", + "schema": "public", + "indexes": [ + { + "keyName": "IDX_order_address_deleted_at", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_address_deleted_at\" ON \"order_address\" (deleted_at) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_order_address_customer_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_address_customer_id\" ON \"order_address\" (customer_id) WHERE deleted_at IS NULL" + }, + { + "keyName": "order_address_pkey", + "columnNames": ["id"], + "composite": false, + "primary": true, + "unique": true + } + ], + "checks": [], + "foreignKeys": {} + }, + { + "columns": { + "id": { + "name": "id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "display_id": { + "name": "display_id", + "type": "serial", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "bigint" + }, + "region_id": { + "name": "region_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "customer_id": { + "name": "customer_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "version": { + "name": "version", + "type": "integer", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "default": "1", + "mappedType": "integer" + }, + "sales_channel_id": { + "name": "sales_channel_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "status": { + "name": "status", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "default": "'pending'", + "enumItems": [ + "pending", + "completed", + "draft", + "archived", + "canceled", + "requires_action" + ], + "mappedType": "enum" + }, + "is_draft_order": { + "name": "is_draft_order", + "type": "boolean", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "default": "false", + "mappedType": "boolean" + }, + "email": { + "name": "email", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "currency_code": { + "name": "currency_code", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "no_notification": { + "name": "no_notification", + "type": "boolean", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "boolean" + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "json" + }, + "canceled_at": { + "name": "canceled_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 6, + "mappedType": "datetime" + }, + "shipping_address_id": { + "name": "shipping_address_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "billing_address_id": { + "name": "billing_address_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "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": "order", + "schema": "public", + "indexes": [ + { + "keyName": "IDX_order_shipping_address_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_address_id\" ON \"order\" (shipping_address_id) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_order_billing_address_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_billing_address_id\" ON \"order\" (billing_address_id) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_order_deleted_at", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_deleted_at\" ON \"order\" (deleted_at) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_order_display_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_display_id\" ON \"order\" (display_id) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_region_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_region_id\" ON \"order\" (region_id) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_customer_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_customer_id\" ON \"order\" (customer_id) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_sales_channel_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_sales_channel_id\" ON \"order\" (sales_channel_id) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_deleted_at", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_deleted_at\" ON \"order\" (deleted_at) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_currency_code", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_currency_code\" ON \"order\" (currency_code) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_shipping_address_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_address_id\" ON \"order\" (shipping_address_id) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_billing_address_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_billing_address_id\" ON \"order\" (billing_address_id) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_is_draft_order", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_is_draft_order\" ON \"order\" (is_draft_order) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "order_pkey", + "columnNames": ["id"], + "composite": false, + "primary": true, + "unique": true + } + ], + "checks": [], + "foreignKeys": { + "order_shipping_address_id_foreign": { + "constraintName": "order_shipping_address_id_foreign", + "columnNames": ["shipping_address_id"], + "localTableName": "public.order", + "referencedColumnNames": ["id"], + "referencedTableName": "public.order_address", + "deleteRule": "set null", + "updateRule": "cascade" + }, + "order_billing_address_id_foreign": { + "constraintName": "order_billing_address_id_foreign", + "columnNames": ["billing_address_id"], + "localTableName": "public.order", + "referencedColumnNames": ["id"], + "referencedTableName": "public.order_address", + "deleteRule": "set null", + "updateRule": "cascade" + } + } + }, + { + "columns": { + "id": { + "name": "id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "return_id": { + "name": "return_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "order_version": { + "name": "order_version", + "type": "integer", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "integer" + }, + "display_id": { + "name": "display_id", + "type": "serial", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "bigint" + }, + "type": { + "name": "type", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "enumItems": ["refund", "replace"], + "mappedType": "enum" + }, + "no_notification": { + "name": "no_notification", + "type": "boolean", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "boolean" + }, + "refund_amount": { + "name": "refund_amount", + "type": "numeric", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "decimal" + }, + "created_by": { + "name": "created_by", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "canceled_at": { + "name": "canceled_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 6, + "mappedType": "datetime" + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "json" + }, + "order_id": { + "name": "order_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "raw_refund_amount": { + "name": "raw_refund_amount", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "json" + }, + "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": "order_claim", + "schema": "public", + "indexes": [ + { + "keyName": "IDX_order_claim_order_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_claim_order_id\" ON \"order_claim\" (order_id) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_order_claim_deleted_at", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_claim_deleted_at\" ON \"order_claim\" (deleted_at) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_order_claim_display_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_claim_display_id\" ON \"order_claim\" (display_id) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_claim_deleted_at", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_claim_deleted_at\" ON \"order_claim\" (deleted_at) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_claim_order_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_claim_order_id\" ON \"order_claim\" (order_id) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_claim_return_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_claim_return_id\" ON \"order_claim\" (return_id) WHERE return_id IS NOT NULL AND deleted_at IS NOT NULL" + }, + { + "keyName": "order_claim_pkey", + "columnNames": ["id"], + "composite": false, + "primary": true, + "unique": true + } + ], + "checks": [], + "foreignKeys": { + "order_claim_order_id_foreign": { + "constraintName": "order_claim_order_id_foreign", + "columnNames": ["order_id"], + "localTableName": "public.order_claim", + "referencedColumnNames": ["id"], + "referencedTableName": "public.order", + "updateRule": "cascade" + } + } + }, + { + "columns": { + "id": { + "name": "id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "return_id": { + "name": "return_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "order_version": { + "name": "order_version", + "type": "integer", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "integer" + }, + "display_id": { + "name": "display_id", + "type": "serial", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "bigint" + }, + "no_notification": { + "name": "no_notification", + "type": "boolean", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "boolean" + }, + "difference_due": { + "name": "difference_due", + "type": "numeric", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "decimal" + }, + "allow_backorder": { + "name": "allow_backorder", + "type": "boolean", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "default": "false", + "mappedType": "boolean" + }, + "created_by": { + "name": "created_by", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "json" + }, + "canceled_at": { + "name": "canceled_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 6, + "mappedType": "datetime" + }, + "order_id": { + "name": "order_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "raw_difference_due": { + "name": "raw_difference_due", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "json" + }, + "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": "order_exchange", + "schema": "public", + "indexes": [ + { + "keyName": "IDX_order_exchange_order_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_exchange_order_id\" ON \"order_exchange\" (order_id) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_order_exchange_deleted_at", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_exchange_deleted_at\" ON \"order_exchange\" (deleted_at) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_order_exchange_display_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_exchange_display_id\" ON \"order_exchange\" (display_id) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_exchange_deleted_at", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_exchange_deleted_at\" ON \"order_exchange\" (deleted_at) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_exchange_order_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_exchange_order_id\" ON \"order_exchange\" (order_id) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_exchange_return_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_exchange_return_id\" ON \"order_exchange\" (return_id) WHERE return_id IS NOT NULL AND deleted_at IS NOT NULL" + }, + { + "keyName": "order_exchange_pkey", + "columnNames": ["id"], + "composite": false, + "primary": true, + "unique": true + } + ], + "checks": [], + "foreignKeys": { + "order_exchange_order_id_foreign": { + "constraintName": "order_exchange_order_id_foreign", + "columnNames": ["order_id"], + "localTableName": "public.order_exchange", + "referencedColumnNames": ["id"], + "referencedTableName": "public.order", + "updateRule": "cascade" + } + } + }, + { + "columns": { + "id": { + "name": "id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "title": { + "name": "title", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "subtitle": { + "name": "subtitle", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "thumbnail": { + "name": "thumbnail", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "variant_id": { + "name": "variant_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "product_id": { + "name": "product_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "product_title": { + "name": "product_title", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "product_description": { + "name": "product_description", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "product_subtitle": { + "name": "product_subtitle", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "product_type": { + "name": "product_type", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "product_type_id": { + "name": "product_type_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "product_collection": { + "name": "product_collection", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "product_handle": { + "name": "product_handle", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "variant_sku": { + "name": "variant_sku", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "variant_barcode": { + "name": "variant_barcode", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "variant_title": { + "name": "variant_title", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "variant_option_values": { + "name": "variant_option_values", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "json" + }, + "requires_shipping": { + "name": "requires_shipping", + "type": "boolean", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "default": "true", + "mappedType": "boolean" + }, + "is_discountable": { + "name": "is_discountable", + "type": "boolean", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "default": "true", + "mappedType": "boolean" + }, + "is_tax_inclusive": { + "name": "is_tax_inclusive", + "type": "boolean", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "default": "false", + "mappedType": "boolean" + }, + "compare_at_unit_price": { + "name": "compare_at_unit_price", + "type": "numeric", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "decimal" + }, + "unit_price": { + "name": "unit_price", + "type": "numeric", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "decimal" + }, + "is_custom_price": { + "name": "is_custom_price", + "type": "boolean", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "default": "false", + "mappedType": "boolean" + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "json" + }, + "raw_compare_at_unit_price": { + "name": "raw_compare_at_unit_price", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "json" + }, + "raw_unit_price": { + "name": "raw_unit_price", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "json" + }, + "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": "order_line_item", + "schema": "public", + "indexes": [ + { + "keyName": "IDX_order_line_item_deleted_at", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_line_item_deleted_at\" ON \"order_line_item\" (deleted_at) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_order_line_item_deleted_at", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_line_item_deleted_at\" ON \"order_line_item\" (deleted_at) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_line_item_product_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_line_item_product_id\" ON \"order_line_item\" (product_id) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_line_item_product_type_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_line_item_product_type_id\" ON \"order_line_item\" (product_type_id) WHERE deleted_at IS NOT NULL AND product_type_id IS NOT NULL" + }, + { + "keyName": "IDX_order_line_item_variant_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_line_item_variant_id\" ON \"order_line_item\" (variant_id) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "order_line_item_pkey", + "columnNames": ["id"], + "composite": false, + "primary": true, + "unique": true + } + ], + "checks": [], + "foreignKeys": {} + }, + { + "columns": { + "id": { + "name": "id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "version": { + "name": "version", + "type": "integer", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "default": "1", + "mappedType": "integer" + }, + "unit_price": { + "name": "unit_price", + "type": "numeric", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "decimal" + }, + "compare_at_unit_price": { + "name": "compare_at_unit_price", + "type": "numeric", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "decimal" + }, + "quantity": { + "name": "quantity", + "type": "numeric", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "decimal" + }, + "fulfilled_quantity": { + "name": "fulfilled_quantity", + "type": "numeric", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "default": "0", + "mappedType": "decimal" + }, + "delivered_quantity": { + "name": "delivered_quantity", + "type": "numeric", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "default": "0", + "mappedType": "decimal" + }, + "shipped_quantity": { + "name": "shipped_quantity", + "type": "numeric", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "default": "0", + "mappedType": "decimal" + }, + "return_requested_quantity": { + "name": "return_requested_quantity", + "type": "numeric", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "default": "0", + "mappedType": "decimal" + }, + "return_received_quantity": { + "name": "return_received_quantity", + "type": "numeric", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "default": "0", + "mappedType": "decimal" + }, + "return_dismissed_quantity": { + "name": "return_dismissed_quantity", + "type": "numeric", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "default": "0", + "mappedType": "decimal" + }, + "written_off_quantity": { + "name": "written_off_quantity", + "type": "numeric", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "default": "0", + "mappedType": "decimal" + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "json" + }, + "order_id": { + "name": "order_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "item_id": { + "name": "item_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "raw_unit_price": { + "name": "raw_unit_price", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "json" + }, + "raw_compare_at_unit_price": { + "name": "raw_compare_at_unit_price", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "json" + }, + "raw_quantity": { + "name": "raw_quantity", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "json" + }, + "raw_fulfilled_quantity": { + "name": "raw_fulfilled_quantity", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "json" + }, + "raw_delivered_quantity": { + "name": "raw_delivered_quantity", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "json" + }, + "raw_shipped_quantity": { + "name": "raw_shipped_quantity", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "json" + }, + "raw_return_requested_quantity": { + "name": "raw_return_requested_quantity", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "json" + }, + "raw_return_received_quantity": { + "name": "raw_return_received_quantity", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "json" + }, + "raw_return_dismissed_quantity": { + "name": "raw_return_dismissed_quantity", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "json" + }, + "raw_written_off_quantity": { + "name": "raw_written_off_quantity", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "json" + }, + "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": "order_item", + "schema": "public", + "indexes": [ + { + "keyName": "IDX_order_item_order_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_item_order_id\" ON \"order_item\" (order_id) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_order_item_item_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_item_item_id\" ON \"order_item\" (item_id) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_order_item_deleted_at", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_item_deleted_at\" ON \"order_item\" (deleted_at) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_order_item_order_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_item_order_id\" ON \"order_item\" (order_id) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_item_version", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_item_version\" ON \"order_item\" (version) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_item_item_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_item_item_id\" ON \"order_item\" (item_id) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_item_deleted_at", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_item_deleted_at\" ON \"order_item\" (deleted_at) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "order_item_pkey", + "columnNames": ["id"], + "composite": false, + "primary": true, + "unique": true + } + ], + "checks": [], + "foreignKeys": { + "order_item_order_id_foreign": { + "constraintName": "order_item_order_id_foreign", + "columnNames": ["order_id"], + "localTableName": "public.order_item", + "referencedColumnNames": ["id"], + "referencedTableName": "public.order", + "deleteRule": "cascade", + "updateRule": "cascade" + }, + "order_item_item_id_foreign": { + "constraintName": "order_item_item_id_foreign", + "columnNames": ["item_id"], + "localTableName": "public.order_item", + "referencedColumnNames": ["id"], + "referencedTableName": "public.order_line_item", + "updateRule": "cascade" + } + } + }, + { + "columns": { + "id": { + "name": "id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "quantity": { + "name": "quantity", + "type": "numeric", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "decimal" + }, + "note": { + "name": "note", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "json" + }, + "exchange_id": { + "name": "exchange_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "item_id": { + "name": "item_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "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", + "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": "order_exchange_item", + "schema": "public", + "indexes": [ + { + "keyName": "IDX_order_exchange_item_exchange_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_exchange_item_exchange_id\" ON \"order_exchange_item\" (exchange_id) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_order_exchange_item_item_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_exchange_item_item_id\" ON \"order_exchange_item\" (item_id) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_order_exchange_item_deleted_at", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_exchange_item_deleted_at\" ON \"order_exchange_item\" (deleted_at) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_order_exchange_item_exchange_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_exchange_item_exchange_id\" ON \"order_exchange_item\" (exchange_id) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_exchange_item_item_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_exchange_item_item_id\" ON \"order_exchange_item\" (item_id) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_exchange_item_deleted_at", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_exchange_item_deleted_at\" ON \"order_exchange_item\" (deleted_at) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "order_exchange_item_pkey", + "columnNames": ["id"], + "composite": false, + "primary": true, + "unique": true + } + ], + "checks": [], + "foreignKeys": { + "order_exchange_item_exchange_id_foreign": { + "constraintName": "order_exchange_item_exchange_id_foreign", + "columnNames": ["exchange_id"], + "localTableName": "public.order_exchange_item", + "referencedColumnNames": ["id"], + "referencedTableName": "public.order_exchange", + "deleteRule": "cascade", + "updateRule": "cascade" + }, + "order_exchange_item_item_id_foreign": { + "constraintName": "order_exchange_item_item_id_foreign", + "columnNames": ["item_id"], + "localTableName": "public.order_exchange_item", + "referencedColumnNames": ["id"], + "referencedTableName": "public.order_line_item", + "updateRule": "cascade" + } + } + }, + { + "columns": { + "id": { + "name": "id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "reason": { + "name": "reason", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "enumItems": [ + "missing_item", + "wrong_item", + "production_failure", + "other" + ], + "mappedType": "enum" + }, + "quantity": { + "name": "quantity", + "type": "numeric", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "decimal" + }, + "is_additional_item": { + "name": "is_additional_item", + "type": "boolean", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "default": "false", + "mappedType": "boolean" + }, + "note": { + "name": "note", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "json" + }, + "claim_id": { + "name": "claim_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "item_id": { + "name": "item_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "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", + "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": "order_claim_item", + "schema": "public", + "indexes": [ + { + "keyName": "IDX_order_claim_item_claim_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_claim_item_claim_id\" ON \"order_claim_item\" (claim_id) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_order_claim_item_item_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_claim_item_item_id\" ON \"order_claim_item\" (item_id) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_order_claim_item_deleted_at", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_claim_item_deleted_at\" ON \"order_claim_item\" (deleted_at) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_order_claim_item_claim_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_claim_item_claim_id\" ON \"order_claim_item\" (claim_id) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_claim_item_item_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_claim_item_item_id\" ON \"order_claim_item\" (item_id) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_claim_item_deleted_at", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_claim_item_deleted_at\" ON \"order_claim_item\" (deleted_at) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "order_claim_item_pkey", + "columnNames": ["id"], + "composite": false, + "primary": true, + "unique": true + } + ], + "checks": [], + "foreignKeys": { + "order_claim_item_claim_id_foreign": { + "constraintName": "order_claim_item_claim_id_foreign", + "columnNames": ["claim_id"], + "localTableName": "public.order_claim_item", + "referencedColumnNames": ["id"], + "referencedTableName": "public.order_claim", + "deleteRule": "cascade", + "updateRule": "cascade" + }, + "order_claim_item_item_id_foreign": { + "constraintName": "order_claim_item_item_id_foreign", + "columnNames": ["item_id"], + "localTableName": "public.order_claim_item", + "referencedColumnNames": ["id"], + "referencedTableName": "public.order_line_item", + "updateRule": "cascade" + } + } + }, + { + "columns": { + "id": { + "name": "id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "claim_item_id": { + "name": "claim_item_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "url": { + "name": "url", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "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", + "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": "order_claim_item_image", + "schema": "public", + "indexes": [ + { + "keyName": "IDX_order_claim_item_image_claim_item_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_claim_item_image_claim_item_id\" ON \"order_claim_item_image\" (claim_item_id) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_order_claim_item_image_deleted_at", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_claim_item_image_deleted_at\" ON \"order_claim_item_image\" (deleted_at) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_order_claim_item_image_deleted_at", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_claim_item_image_deleted_at\" ON \"order_claim_item_image\" (deleted_at) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_claim_item_image_claim_item_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_claim_item_image_claim_item_id\" ON \"order_claim_item_image\" (claim_item_id) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "order_claim_item_image_pkey", + "columnNames": ["id"], + "composite": false, + "primary": true, + "unique": true + } + ], + "checks": [], + "foreignKeys": { + "order_claim_item_image_claim_item_id_foreign": { + "constraintName": "order_claim_item_image_claim_item_id_foreign", + "columnNames": ["claim_item_id"], + "localTableName": "public.order_claim_item_image", + "referencedColumnNames": ["id"], + "referencedTableName": "public.order_claim_item", + "deleteRule": "cascade", + "updateRule": "cascade" + } + } + }, + { + "columns": { + "id": { + "name": "id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "description": { + "name": "description", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "promotion_id": { + "name": "promotion_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "code": { + "name": "code", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "amount": { + "name": "amount", + "type": "numeric", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "decimal" + }, + "provider_id": { + "name": "provider_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "item_id": { + "name": "item_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "raw_amount": { + "name": "raw_amount", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "json" + }, + "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": "order_line_item_adjustment", + "schema": "public", + "indexes": [ + { + "keyName": "IDX_order_line_item_adjustment_item_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_line_item_adjustment_item_id\" ON \"order_line_item_adjustment\" (item_id) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_order_line_item_adjustment_deleted_at", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_line_item_adjustment_deleted_at\" ON \"order_line_item_adjustment\" (deleted_at) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_order_order_line_item_adjustment_item_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_order_line_item_adjustment_item_id\" ON \"order_line_item_adjustment\" (item_id) WHERE deleted_at IS NULL" + }, + { + "keyName": "order_line_item_adjustment_pkey", + "columnNames": ["id"], + "composite": false, + "primary": true, + "unique": true + } + ], + "checks": [], + "foreignKeys": { + "order_line_item_adjustment_item_id_foreign": { + "constraintName": "order_line_item_adjustment_item_id_foreign", + "columnNames": ["item_id"], + "localTableName": "public.order_line_item_adjustment", + "referencedColumnNames": ["id"], + "referencedTableName": "public.order_line_item", + "deleteRule": "cascade", + "updateRule": "cascade" + } + } + }, + { + "columns": { + "id": { + "name": "id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "description": { + "name": "description", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "tax_rate_id": { + "name": "tax_rate_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "code": { + "name": "code", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "rate": { + "name": "rate", + "type": "numeric", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "decimal" + }, + "provider_id": { + "name": "provider_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "item_id": { + "name": "item_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "raw_rate": { + "name": "raw_rate", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "json" + }, + "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": "order_line_item_tax_line", + "schema": "public", + "indexes": [ + { + "keyName": "IDX_order_line_item_tax_line_item_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_line_item_tax_line_item_id\" ON \"order_line_item_tax_line\" (item_id) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_order_line_item_tax_line_deleted_at", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_line_item_tax_line_deleted_at\" ON \"order_line_item_tax_line\" (deleted_at) WHERE deleted_at IS NULL" + }, + { + "keyName": "order_line_item_tax_line_pkey", + "columnNames": ["id"], + "composite": false, + "primary": true, + "unique": true + } + ], + "checks": [], + "foreignKeys": { + "order_line_item_tax_line_item_id_foreign": { + "constraintName": "order_line_item_tax_line_item_id_foreign", + "columnNames": ["item_id"], + "localTableName": "public.order_line_item_tax_line", + "referencedColumnNames": ["id"], + "referencedTableName": "public.order_line_item", + "deleteRule": "cascade", + "updateRule": "cascade" + } + } + }, + { + "columns": { + "id": { + "name": "id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "name": { + "name": "name", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "description": { + "name": "description", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "json" + }, + "amount": { + "name": "amount", + "type": "numeric", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "decimal" + }, + "is_tax_inclusive": { + "name": "is_tax_inclusive", + "type": "boolean", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "default": "false", + "mappedType": "boolean" + }, + "is_custom_amount": { + "name": "is_custom_amount", + "type": "boolean", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "default": "false", + "mappedType": "boolean" + }, + "shipping_option_id": { + "name": "shipping_option_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "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" + }, + "raw_amount": { + "name": "raw_amount", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "json" + }, + "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": "order_shipping_method", + "schema": "public", + "indexes": [ + { + "keyName": "IDX_order_shipping_method_deleted_at", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_method_deleted_at\" ON \"order_shipping_method\" (deleted_at) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_order_shipping_method_shipping_option_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_method_shipping_option_id\" ON \"order_shipping_method\" (shipping_option_id) WHERE deleted_at IS NULL" + }, + { + "keyName": "order_shipping_method_pkey", + "columnNames": ["id"], + "composite": false, + "primary": true, + "unique": true + } + ], + "checks": [], + "foreignKeys": {} + }, + { + "columns": { + "id": { + "name": "id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "description": { + "name": "description", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "promotion_id": { + "name": "promotion_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "code": { + "name": "code", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "amount": { + "name": "amount", + "type": "numeric", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "decimal" + }, + "provider_id": { + "name": "provider_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "shipping_method_id": { + "name": "shipping_method_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "raw_amount": { + "name": "raw_amount", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "json" + }, + "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": "order_shipping_method_adjustment", + "schema": "public", + "indexes": [ + { + "keyName": "IDX_order_shipping_method_adjustment_shipping_method_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_method_adjustment_shipping_method_id\" ON \"order_shipping_method_adjustment\" (shipping_method_id) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_order_shipping_method_adjustment_deleted_at", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_method_adjustment_deleted_at\" ON \"order_shipping_method_adjustment\" (deleted_at) WHERE deleted_at IS NULL" + }, + { + "keyName": "order_shipping_method_adjustment_pkey", + "columnNames": ["id"], + "composite": false, + "primary": true, + "unique": true + } + ], + "checks": [], + "foreignKeys": { + "order_shipping_method_adjustment_shipping_method_id_foreign": { + "constraintName": "order_shipping_method_adjustment_shipping_method_id_foreign", + "columnNames": ["shipping_method_id"], + "localTableName": "public.order_shipping_method_adjustment", + "referencedColumnNames": ["id"], + "referencedTableName": "public.order_shipping_method", + "deleteRule": "cascade", + "updateRule": "cascade" + } + } + }, + { + "columns": { + "id": { + "name": "id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "description": { + "name": "description", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "tax_rate_id": { + "name": "tax_rate_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "code": { + "name": "code", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "rate": { + "name": "rate", + "type": "numeric", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "decimal" + }, + "provider_id": { + "name": "provider_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "shipping_method_id": { + "name": "shipping_method_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "raw_rate": { + "name": "raw_rate", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "json" + }, + "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": "order_shipping_method_tax_line", + "schema": "public", + "indexes": [ + { + "keyName": "IDX_order_shipping_method_tax_line_shipping_method_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_method_tax_line_shipping_method_id\" ON \"order_shipping_method_tax_line\" (shipping_method_id) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_order_shipping_method_tax_line_deleted_at", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_method_tax_line_deleted_at\" ON \"order_shipping_method_tax_line\" (deleted_at) WHERE deleted_at IS NULL" + }, + { + "keyName": "order_shipping_method_tax_line_pkey", + "columnNames": ["id"], + "composite": false, + "primary": true, + "unique": true + } + ], + "checks": [], + "foreignKeys": { + "order_shipping_method_tax_line_shipping_method_id_foreign": { + "constraintName": "order_shipping_method_tax_line_shipping_method_id_foreign", + "columnNames": ["shipping_method_id"], + "localTableName": "public.order_shipping_method_tax_line", + "referencedColumnNames": ["id"], + "referencedTableName": "public.order_shipping_method", + "deleteRule": "cascade", + "updateRule": "cascade" + } + } + }, + { + "columns": { + "id": { + "name": "id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "version": { + "name": "version", + "type": "integer", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "default": "1", + "mappedType": "integer" + }, + "totals": { + "name": "totals", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "json" + }, + "order_id": { + "name": "order_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "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": "order_summary", + "schema": "public", + "indexes": [ + { + "keyName": "IDX_order_summary_order_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_summary_order_id\" ON \"order_summary\" (order_id) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_order_summary_deleted_at", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_summary_deleted_at\" ON \"order_summary\" (deleted_at) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_order_summary_order_id_version", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_summary_order_id_version\" ON \"order_summary\" (order_id, version) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_summary_deleted_at", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_summary_deleted_at\" ON \"order_summary\" (deleted_at) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "order_summary_pkey", + "columnNames": ["id"], + "composite": false, + "primary": true, + "unique": true + } + ], + "checks": [], + "foreignKeys": { + "order_summary_order_id_foreign": { + "constraintName": "order_summary_order_id_foreign", + "columnNames": ["order_id"], + "localTableName": "public.order_summary", + "referencedColumnNames": ["id"], + "referencedTableName": "public.order", + "deleteRule": "cascade", + "updateRule": "cascade" + } + } + }, + { + "columns": { + "id": { + "name": "id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "order_version": { + "name": "order_version", + "type": "integer", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "integer" + }, + "display_id": { + "name": "display_id", + "type": "serial", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "bigint" + }, + "status": { + "name": "status", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "default": "'open'", + "enumItems": [ + "open", + "requested", + "received", + "partially_received", + "canceled" + ], + "mappedType": "enum" + }, + "location_id": { + "name": "location_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "no_notification": { + "name": "no_notification", + "type": "boolean", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "boolean" + }, + "refund_amount": { + "name": "refund_amount", + "type": "numeric", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "decimal" + }, + "created_by": { + "name": "created_by", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "json" + }, + "requested_at": { + "name": "requested_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 6, + "mappedType": "datetime" + }, + "received_at": { + "name": "received_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 6, + "mappedType": "datetime" + }, + "canceled_at": { + "name": "canceled_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 6, + "mappedType": "datetime" + }, + "order_id": { + "name": "order_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "exchange_id": { + "name": "exchange_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "claim_id": { + "name": "claim_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "raw_refund_amount": { + "name": "raw_refund_amount", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "json" + }, + "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": "return", + "schema": "public", + "indexes": [ + { + "keyName": "IDX_return_order_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_order_id\" ON \"return\" (order_id) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_return_exchange_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_exchange_id\" ON \"return\" (exchange_id) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_return_claim_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_claim_id\" ON \"return\" (claim_id) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_return_deleted_at", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_deleted_at\" ON \"return\" (deleted_at) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_return_display_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_display_id\" ON \"return\" (display_id) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_return_deleted_at", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_deleted_at\" ON \"return\" (deleted_at) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_return_order_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_order_id\" ON \"return\" (order_id) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_return_exchange_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_exchange_id\" ON \"return\" (exchange_id) WHERE exchange_id IS NOT NULL AND deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_return_claim_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_claim_id\" ON \"return\" (claim_id) WHERE claim_id IS NOT NULL AND deleted_at IS NOT NULL" + }, + { + "keyName": "return_pkey", + "columnNames": ["id"], + "composite": false, + "primary": true, + "unique": true + } + ], + "checks": [], + "foreignKeys": { + "return_order_id_foreign": { + "constraintName": "return_order_id_foreign", + "columnNames": ["order_id"], + "localTableName": "public.return", + "referencedColumnNames": ["id"], + "referencedTableName": "public.order", + "updateRule": "cascade" + }, + "return_exchange_id_foreign": { + "constraintName": "return_exchange_id_foreign", + "columnNames": ["exchange_id"], + "localTableName": "public.return", + "referencedColumnNames": ["id"], + "referencedTableName": "public.order_exchange", + "deleteRule": "set null", + "updateRule": "cascade" + }, + "return_claim_id_foreign": { + "constraintName": "return_claim_id_foreign", + "columnNames": ["claim_id"], + "localTableName": "public.return", + "referencedColumnNames": ["id"], + "referencedTableName": "public.order_claim", + "deleteRule": "set null", + "updateRule": "cascade" + } + } + }, + { + "columns": { + "id": { + "name": "id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "version": { + "name": "version", + "type": "integer", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "default": "1", + "mappedType": "integer" + }, + "amount": { + "name": "amount", + "type": "numeric", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "decimal" + }, + "currency_code": { + "name": "currency_code", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "reference": { + "name": "reference", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "reference_id": { + "name": "reference_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "order_id": { + "name": "order_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "return_id": { + "name": "return_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "exchange_id": { + "name": "exchange_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "claim_id": { + "name": "claim_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "raw_amount": { + "name": "raw_amount", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "json" + }, + "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": "order_transaction", + "schema": "public", + "indexes": [ + { + "keyName": "IDX_order_transaction_order_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_transaction_order_id\" ON \"order_transaction\" (order_id) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_order_transaction_return_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_transaction_return_id\" ON \"order_transaction\" (return_id) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_order_transaction_exchange_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_transaction_exchange_id\" ON \"order_transaction\" (exchange_id) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_order_transaction_claim_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_transaction_claim_id\" ON \"order_transaction\" (claim_id) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_order_transaction_deleted_at", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_transaction_deleted_at\" ON \"order_transaction\" (deleted_at) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_order_transaction_reference_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_transaction_reference_id\" ON \"order_transaction\" (reference_id) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_transaction_order_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_transaction_order_id\" ON \"order_transaction\" (order_id) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_transaction_return_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_transaction_return_id\" ON \"order_transaction\" (return_id) WHERE return_id IS NOT NULL AND deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_transaction_exchange_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_transaction_exchange_id\" ON \"order_transaction\" (exchange_id) WHERE exchange_id IS NOT NULL AND deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_transaction_claim_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_transaction_claim_id\" ON \"order_transaction\" (claim_id) WHERE claim_id IS NOT NULL AND deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_transaction_currency_code", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_transaction_currency_code\" ON \"order_transaction\" (currency_code) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_transaction_deleted_at", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_transaction_deleted_at\" ON \"order_transaction\" (deleted_at) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_transaction_order_id_version", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_transaction_order_id_version\" ON \"order_transaction\" (order_id, version) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "order_transaction_pkey", + "columnNames": ["id"], + "composite": false, + "primary": true, + "unique": true + } + ], + "checks": [], + "foreignKeys": { + "order_transaction_order_id_foreign": { + "constraintName": "order_transaction_order_id_foreign", + "columnNames": ["order_id"], + "localTableName": "public.order_transaction", + "referencedColumnNames": ["id"], + "referencedTableName": "public.order", + "deleteRule": "cascade", + "updateRule": "cascade" + }, + "order_transaction_return_id_foreign": { + "constraintName": "order_transaction_return_id_foreign", + "columnNames": ["return_id"], + "localTableName": "public.order_transaction", + "referencedColumnNames": ["id"], + "referencedTableName": "public.return", + "deleteRule": "cascade", + "updateRule": "cascade" + }, + "order_transaction_exchange_id_foreign": { + "constraintName": "order_transaction_exchange_id_foreign", + "columnNames": ["exchange_id"], + "localTableName": "public.order_transaction", + "referencedColumnNames": ["id"], + "referencedTableName": "public.order_exchange", + "deleteRule": "cascade", + "updateRule": "cascade" + }, + "order_transaction_claim_id_foreign": { + "constraintName": "order_transaction_claim_id_foreign", + "columnNames": ["claim_id"], + "localTableName": "public.order_transaction", + "referencedColumnNames": ["id"], + "referencedTableName": "public.order_claim", + "deleteRule": "cascade", + "updateRule": "cascade" + } + } + }, + { + "columns": { + "id": { + "name": "id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "version": { + "name": "version", + "type": "integer", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "default": "1", + "mappedType": "integer" + }, + "order_id": { + "name": "order_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "return_id": { + "name": "return_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "exchange_id": { + "name": "exchange_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "claim_id": { + "name": "claim_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "shipping_method_id": { + "name": "shipping_method_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "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": "order_shipping", + "schema": "public", + "indexes": [ + { + "keyName": "IDX_order_shipping_order_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_order_id\" ON \"order_shipping\" (order_id) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_order_shipping_return_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_return_id\" ON \"order_shipping\" (return_id) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_order_shipping_exchange_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_exchange_id\" ON \"order_shipping\" (exchange_id) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_order_shipping_claim_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_claim_id\" ON \"order_shipping\" (claim_id) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_order_shipping_shipping_method_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_shipping_method_id\" ON \"order_shipping\" (shipping_method_id) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_order_shipping_deleted_at", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_deleted_at\" ON \"order_shipping\" (deleted_at) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_order_shipping_order_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_order_id\" ON \"order_shipping\" (order_id) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_shipping_return_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_return_id\" ON \"order_shipping\" (return_id) WHERE return_id IS NOT NULL AND deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_shipping_exchange_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_exchange_id\" ON \"order_shipping\" (exchange_id) WHERE exchange_id IS NOT NULL AND deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_shipping_claim_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_claim_id\" ON \"order_shipping\" (claim_id) WHERE claim_id IS NOT NULL AND deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_shipping_version", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_version\" ON \"order_shipping\" (version) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_shipping_shipping_method_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_shipping_method_id\" ON \"order_shipping\" (shipping_method_id) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_shipping_deleted_at", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_deleted_at\" ON \"order_shipping\" (deleted_at) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "order_shipping_pkey", + "columnNames": ["id"], + "composite": false, + "primary": true, + "unique": true + } + ], + "checks": [], + "foreignKeys": { + "order_shipping_order_id_foreign": { + "constraintName": "order_shipping_order_id_foreign", + "columnNames": ["order_id"], + "localTableName": "public.order_shipping", + "referencedColumnNames": ["id"], + "referencedTableName": "public.order", + "deleteRule": "cascade", + "updateRule": "cascade" + }, + "order_shipping_return_id_foreign": { + "constraintName": "order_shipping_return_id_foreign", + "columnNames": ["return_id"], + "localTableName": "public.order_shipping", + "referencedColumnNames": ["id"], + "referencedTableName": "public.return", + "deleteRule": "cascade", + "updateRule": "cascade" + }, + "order_shipping_exchange_id_foreign": { + "constraintName": "order_shipping_exchange_id_foreign", + "columnNames": ["exchange_id"], + "localTableName": "public.order_shipping", + "referencedColumnNames": ["id"], + "referencedTableName": "public.order_exchange", + "deleteRule": "cascade", + "updateRule": "cascade" + }, + "order_shipping_claim_id_foreign": { + "constraintName": "order_shipping_claim_id_foreign", + "columnNames": ["claim_id"], + "localTableName": "public.order_shipping", + "referencedColumnNames": ["id"], + "referencedTableName": "public.order_claim", + "deleteRule": "cascade", + "updateRule": "cascade" + }, + "order_shipping_shipping_method_id_foreign": { + "constraintName": "order_shipping_shipping_method_id_foreign", + "columnNames": ["shipping_method_id"], + "localTableName": "public.order_shipping", + "referencedColumnNames": ["id"], + "referencedTableName": "public.order_shipping_method", + "updateRule": "cascade" + } + } + }, + { + "columns": { + "id": { + "name": "id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "version": { + "name": "version", + "type": "integer", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "integer" + }, + "change_type": { + "name": "change_type", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "description": { + "name": "description", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "status": { + "name": "status", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "default": "'pending'", + "enumItems": [ + "confirmed", + "declined", + "requested", + "pending", + "canceled" + ], + "mappedType": "enum" + }, + "internal_note": { + "name": "internal_note", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "created_by": { + "name": "created_by", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "requested_by": { + "name": "requested_by", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "requested_at": { + "name": "requested_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 6, + "mappedType": "datetime" + }, + "confirmed_by": { + "name": "confirmed_by", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "confirmed_at": { + "name": "confirmed_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 6, + "mappedType": "datetime" + }, + "declined_by": { + "name": "declined_by", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "declined_reason": { + "name": "declined_reason", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "json" + }, + "declined_at": { + "name": "declined_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 6, + "mappedType": "datetime" + }, + "canceled_by": { + "name": "canceled_by", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "canceled_at": { + "name": "canceled_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 6, + "mappedType": "datetime" + }, + "order_id": { + "name": "order_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "return_id": { + "name": "return_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "claim_id": { + "name": "claim_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "exchange_id": { + "name": "exchange_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "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": "order_change", + "schema": "public", + "indexes": [ + { + "keyName": "IDX_order_change_order_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_order_id\" ON \"order_change\" (order_id) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_order_change_return_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_return_id\" ON \"order_change\" (return_id) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_order_change_claim_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_claim_id\" ON \"order_change\" (claim_id) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_order_change_exchange_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_exchange_id\" ON \"order_change\" (exchange_id) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_order_change_deleted_at", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_deleted_at\" ON \"order_change\" (deleted_at) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_order_change_order_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_order_id\" ON \"order_change\" (order_id) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_change_return_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_return_id\" ON \"order_change\" (return_id) WHERE return_id IS NOT NULL AND deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_change_claim_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_claim_id\" ON \"order_change\" (claim_id) WHERE claim_id IS NOT NULL AND deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_change_exchange_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_exchange_id\" ON \"order_change\" (exchange_id) WHERE exchange_id IS NOT NULL AND deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_change_status", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_status\" ON \"order_change\" (status) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_change_deleted_at", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_deleted_at\" ON \"order_change\" (deleted_at) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_change_version", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_version\" ON \"order_change\" (order_id, version) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "order_change_pkey", + "columnNames": ["id"], + "composite": false, + "primary": true, + "unique": true + } + ], + "checks": [], + "foreignKeys": { + "order_change_order_id_foreign": { + "constraintName": "order_change_order_id_foreign", + "columnNames": ["order_id"], + "localTableName": "public.order_change", + "referencedColumnNames": ["id"], + "referencedTableName": "public.order", + "updateRule": "cascade" + }, + "order_change_return_id_foreign": { + "constraintName": "order_change_return_id_foreign", + "columnNames": ["return_id"], + "localTableName": "public.order_change", + "referencedColumnNames": ["id"], + "referencedTableName": "public.return", + "deleteRule": "set null", + "updateRule": "cascade" + }, + "order_change_claim_id_foreign": { + "constraintName": "order_change_claim_id_foreign", + "columnNames": ["claim_id"], + "localTableName": "public.order_change", + "referencedColumnNames": ["id"], + "referencedTableName": "public.order_claim", + "deleteRule": "set null", + "updateRule": "cascade" + }, + "order_change_exchange_id_foreign": { + "constraintName": "order_change_exchange_id_foreign", + "columnNames": ["exchange_id"], + "localTableName": "public.order_change", + "referencedColumnNames": ["id"], + "referencedTableName": "public.order_exchange", + "deleteRule": "set null", + "updateRule": "cascade" + } + } + }, + { + "columns": { + "id": { + "name": "id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "ordering": { + "name": "ordering", + "type": "serial", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "bigint" + }, + "version": { + "name": "version", + "type": "integer", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "integer" + }, + "reference": { + "name": "reference", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "reference_id": { + "name": "reference_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "action": { + "name": "action", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "details": { + "name": "details", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "json" + }, + "amount": { + "name": "amount", + "type": "numeric", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "decimal" + }, + "internal_note": { + "name": "internal_note", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "applied": { + "name": "applied", + "type": "boolean", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "default": "false", + "mappedType": "boolean" + }, + "order_id": { + "name": "order_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "return_id": { + "name": "return_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "claim_id": { + "name": "claim_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "exchange_id": { + "name": "exchange_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "order_change_id": { + "name": "order_change_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "raw_amount": { + "name": "raw_amount", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "json" + }, + "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": "order_change_action", + "schema": "public", + "indexes": [ + { + "keyName": "IDX_order_change_action_order_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_action_order_id\" ON \"order_change_action\" (order_id) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_order_change_action_return_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_action_return_id\" ON \"order_change_action\" (return_id) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_order_change_action_claim_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_action_claim_id\" ON \"order_change_action\" (claim_id) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_order_change_action_exchange_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_action_exchange_id\" ON \"order_change_action\" (exchange_id) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_order_change_action_order_change_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_action_order_change_id\" ON \"order_change_action\" (order_change_id) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_order_change_action_deleted_at", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_action_deleted_at\" ON \"order_change_action\" (deleted_at) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_order_change_action_order_change_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_action_order_change_id\" ON \"order_change_action\" (order_change_id) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_change_action_order_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_action_order_id\" ON \"order_change_action\" (order_id) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_change_action_return_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_action_return_id\" ON \"order_change_action\" (return_id) WHERE return_id IS NOT NULL AND deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_change_action_claim_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_action_claim_id\" ON \"order_change_action\" (claim_id) WHERE claim_id IS NOT NULL AND deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_change_action_exchange_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_action_exchange_id\" ON \"order_change_action\" (exchange_id) WHERE exchange_id IS NOT NULL AND deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_change_action_deleted_at", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_action_deleted_at\" ON \"order_change_action\" (deleted_at) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_change_action_ordering", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_action_ordering\" ON \"order_change_action\" (ordering) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "order_change_action_pkey", + "columnNames": ["id"], + "composite": false, + "primary": true, + "unique": true + } + ], + "checks": [], + "foreignKeys": { + "order_change_action_order_id_foreign": { + "constraintName": "order_change_action_order_id_foreign", + "columnNames": ["order_id"], + "localTableName": "public.order_change_action", + "referencedColumnNames": ["id"], + "referencedTableName": "public.order", + "updateRule": "cascade" + }, + "order_change_action_return_id_foreign": { + "constraintName": "order_change_action_return_id_foreign", + "columnNames": ["return_id"], + "localTableName": "public.order_change_action", + "referencedColumnNames": ["id"], + "referencedTableName": "public.return", + "deleteRule": "set null", + "updateRule": "cascade" + }, + "order_change_action_claim_id_foreign": { + "constraintName": "order_change_action_claim_id_foreign", + "columnNames": ["claim_id"], + "localTableName": "public.order_change_action", + "referencedColumnNames": ["id"], + "referencedTableName": "public.order_claim", + "deleteRule": "set null", + "updateRule": "cascade" + }, + "order_change_action_exchange_id_foreign": { + "constraintName": "order_change_action_exchange_id_foreign", + "columnNames": ["exchange_id"], + "localTableName": "public.order_change_action", + "referencedColumnNames": ["id"], + "referencedTableName": "public.order_exchange", + "deleteRule": "set null", + "updateRule": "cascade" + }, + "order_change_action_order_change_id_foreign": { + "constraintName": "order_change_action_order_change_id_foreign", + "columnNames": ["order_change_id"], + "localTableName": "public.order_change_action", + "referencedColumnNames": ["id"], + "referencedTableName": "public.order_change", + "deleteRule": "cascade", + "updateRule": "cascade" + } + } + }, + { + "columns": { + "id": { + "name": "id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "value": { + "name": "value", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "label": { + "name": "label", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "description": { + "name": "description", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "json" + }, + "parent_return_reason_id": { + "name": "parent_return_reason_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "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": "return_reason", + "schema": "public", + "indexes": [ + { + "keyName": "IDX_return_reason_parent_return_reason_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_reason_parent_return_reason_id\" ON \"return_reason\" (parent_return_reason_id) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_return_reason_deleted_at", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_reason_deleted_at\" ON \"return_reason\" (deleted_at) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_return_reason_deleted_at", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_reason_deleted_at\" ON \"return_reason\" (deleted_at) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_return_reason_value", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_reason_value\" ON \"return_reason\" (value) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_return_reason_parent_return_reason_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_reason_parent_return_reason_id\" ON \"return_reason\" (parent_return_reason_id) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "return_reason_pkey", + "columnNames": ["id"], + "composite": false, + "primary": true, + "unique": true + } + ], + "checks": [], + "foreignKeys": { + "return_reason_parent_return_reason_id_foreign": { + "constraintName": "return_reason_parent_return_reason_id_foreign", + "columnNames": ["parent_return_reason_id"], + "localTableName": "public.return_reason", + "referencedColumnNames": ["id"], + "referencedTableName": "public.return_reason", + "updateRule": "cascade" + } + } + }, + { + "columns": { + "id": { + "name": "id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "quantity": { + "name": "quantity", + "type": "numeric", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "decimal" + }, + "received_quantity": { + "name": "received_quantity", + "type": "numeric", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "default": "0", + "mappedType": "decimal" + }, + "damaged_quantity": { + "name": "damaged_quantity", + "type": "numeric", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "default": "0", + "mappedType": "decimal" + }, + "note": { + "name": "note", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "json" + }, + "reason_id": { + "name": "reason_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "return_id": { + "name": "return_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "item_id": { + "name": "item_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "raw_quantity": { + "name": "raw_quantity", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "json" + }, + "raw_received_quantity": { + "name": "raw_received_quantity", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "json" + }, + "raw_damaged_quantity": { + "name": "raw_damaged_quantity", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "json" + }, + "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": "return_item", + "schema": "public", + "indexes": [ + { + "keyName": "IDX_return_item_reason_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_item_reason_id\" ON \"return_item\" (reason_id) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_return_item_return_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_item_return_id\" ON \"return_item\" (return_id) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_return_item_item_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_item_item_id\" ON \"return_item\" (item_id) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_return_item_deleted_at", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_item_deleted_at\" ON \"return_item\" (deleted_at) WHERE deleted_at IS NULL" + }, + { + "keyName": "IDX_return_item_return_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_item_return_id\" ON \"return_item\" (return_id) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_return_item_reason_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_item_reason_id\" ON \"return_item\" (reason_id) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_return_item_item_id", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_item_item_id\" ON \"return_item\" (item_id) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_return_item_deleted_at", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_return_item_deleted_at\" ON \"return_item\" (deleted_at) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "return_item_pkey", + "columnNames": ["id"], + "composite": false, + "primary": true, + "unique": true + } + ], + "checks": [], + "foreignKeys": { + "return_item_reason_id_foreign": { + "constraintName": "return_item_reason_id_foreign", + "columnNames": ["reason_id"], + "localTableName": "public.return_item", + "referencedColumnNames": ["id"], + "referencedTableName": "public.return_reason", + "deleteRule": "set null", + "updateRule": "cascade" + }, + "return_item_return_id_foreign": { + "constraintName": "return_item_return_id_foreign", + "columnNames": ["return_id"], + "localTableName": "public.return_item", + "referencedColumnNames": ["id"], + "referencedTableName": "public.return", + "deleteRule": "cascade", + "updateRule": "cascade" + }, + "return_item_item_id_foreign": { + "constraintName": "return_item_item_id_foreign", + "columnNames": ["item_id"], + "localTableName": "public.return_item", + "referencedColumnNames": ["id"], + "referencedTableName": "public.order_line_item", + "updateRule": "cascade" + } + } + } + ] +} diff --git a/packages/modules/order/src/migrations/Migration20241129124827.ts b/packages/modules/order/src/migrations/Migration20241129124827.ts new file mode 100644 index 0000000000000..b9fd13eb94275 --- /dev/null +++ b/packages/modules/order/src/migrations/Migration20241129124827.ts @@ -0,0 +1,18 @@ +import { Migration } from "@mikro-orm/migrations" + +export class Migration20241129124827 extends Migration { + async up(): Promise { + this.addSql( + 'alter table if exists "order_address" add column if not exists "deleted_at" timestamptz null;' + ) + this.addSql( + 'CREATE INDEX IF NOT EXISTS "IDX_order_address_deleted_at" ON "order_address" (deleted_at) WHERE deleted_at IS NULL;' + ) + } + + async down(): Promise { + this.addSql(` + ALTER TABLE "order_address" DROP COLUMN if exists "deleted_at"; + `) + } +} diff --git a/packages/modules/order/src/models/order-change-action.ts b/packages/modules/order/src/models/order-change-action.ts index c859555736f0f..ed39d84a4628a 100644 --- a/packages/modules/order/src/models/order-change-action.ts +++ b/packages/modules/order/src/models/order-change-action.ts @@ -9,7 +9,7 @@ import { Return } from "./return" const _OrderChangeAction = model .define("OrderChangeAction", { id: model.id({ prefix: "ordchact" }).primaryKey(), - ordering: model.autoincrement(), + ordering: model.autoincrement().nullable(), version: model.number().nullable(), reference: model.text().nullable(), reference_id: model.text().nullable(), From 05699b3033d9033ff4bfeb0686eb60b4ee18b3ef Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Fri, 29 Nov 2024 11:50:09 -0300 Subject: [PATCH 108/175] nullable autoincrement --- .../dml/helpers/entity-builder/define-property.ts | 2 +- .../modules/order/src/models/order-change-action.ts | 12 ++++++------ packages/modules/order/src/models/order.ts | 9 +++++++-- packages/modules/order/src/models/return-reason.ts | 9 ++++----- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/packages/core/utils/src/dml/helpers/entity-builder/define-property.ts b/packages/core/utils/src/dml/helpers/entity-builder/define-property.ts index bf525a37e7154..4c91d894cdc20 100644 --- a/packages/core/utils/src/dml/helpers/entity-builder/define-property.ts +++ b/packages/core/utils/src/dml/helpers/entity-builder/define-property.ts @@ -267,7 +267,7 @@ export function defineProperty( Property({ columnType: "serial", type: mikroOrmType.integer, - nullable: field.nullable, + nullable: true, fieldName: field.fieldName, })(MikroORMEntity.prototype, field.fieldName) return diff --git a/packages/modules/order/src/models/order-change-action.ts b/packages/modules/order/src/models/order-change-action.ts index ed39d84a4628a..dceb5f42aa4a6 100644 --- a/packages/modules/order/src/models/order-change-action.ts +++ b/packages/modules/order/src/models/order-change-action.ts @@ -9,7 +9,7 @@ import { Return } from "./return" const _OrderChangeAction = model .define("OrderChangeAction", { id: model.id({ prefix: "ordchact" }).primaryKey(), - ordering: model.autoincrement().nullable(), + ordering: model.autoincrement(), version: model.number().nullable(), reference: model.text().nullable(), reference_id: model.text().nullable(), @@ -44,11 +44,11 @@ const _OrderChangeAction = model }) .hooks({ creating: (entity: any) => { - entity.order_id ??= entity.order_change.order_id - entity.return_id ??= entity.order_change.return_id - entity.claim_id ??= entity.order_change.claim_id - entity.exchange_id ??= entity.order_change.exchange_id - entity.version ??= entity.order_change.version + entity.order_id ??= entity.order_change?.order_id ?? null + entity.return_id ??= entity.order_change?.return_id ?? null + entity.claim_id ??= entity.order_change?.claim_id ?? null + entity.exchange_id ??= entity.order_change?.exchange_id ?? null + entity.version ??= entity.order_change?.version ?? null }, }) .indexes([ diff --git a/packages/modules/order/src/models/order.ts b/packages/modules/order/src/models/order.ts index 5f5b81f6191c6..89e7e165400d5 100644 --- a/packages/modules/order/src/models/order.ts +++ b/packages/modules/order/src/models/order.ts @@ -18,6 +18,7 @@ import { TextProperty, } from "@medusajs/framework/utils" import { OrderAddress } from "./address" +import { OrderChange } from "./order-change" import { OrderItem } from "./order-item" import { OrderShipping } from "./order-shipping-method" import { OrderSummary } from "./order-summary" @@ -25,7 +26,7 @@ import { OrderTransaction } from "./transaction" type OrderSchema = { id: PrimaryKeyModifier - display_id: NullableModifier + display_id: AutoIncrementProperty region_id: NullableModifier customer_id: NullableModifier version: NumberProperty @@ -49,12 +50,13 @@ type OrderSchema = { items: HasMany shipping_methods: HasMany transactions: HasMany + changes: HasMany } const _Order = model .define("Order", { id: model.id({ prefix: "order" }).primaryKey(), - display_id: model.autoincrement().nullable(), + display_id: model.autoincrement(), region_id: model.text().nullable(), customer_id: model.text().nullable(), version: model.number().default(1), @@ -80,6 +82,9 @@ const _Order = model transactions: model.hasMany(() => OrderTransaction, { mappedBy: "order", }), + changes: model.hasMany(() => OrderChange, { + mappedBy: "order", + }), }) .cascades({ delete: ["summary", "items", "shipping_methods", "transactions"], diff --git a/packages/modules/order/src/models/return-reason.ts b/packages/modules/order/src/models/return-reason.ts index f44b333dbc941..d774b4b6dc8a8 100644 --- a/packages/modules/order/src/models/return-reason.ts +++ b/packages/modules/order/src/models/return-reason.ts @@ -7,12 +7,11 @@ const _ReturnReason = model label: model.text().searchable(), description: model.text().nullable(), metadata: model.json().nullable(), - parent_return_reason: model.belongsTo<() => typeof _ReturnReason>( - () => _ReturnReason, - { + parent_return_reason: model + .belongsTo<() => typeof _ReturnReason>(() => _ReturnReason, { mappedBy: "return_reason_children", - } - ), + }) + .nullable(), return_reason_children: model.hasMany<() => typeof _ReturnReason>( () => _ReturnReason, { From 2b68956bf2a106d654b166c4bba3172173bb39cd Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Fri, 29 Nov 2024 18:45:32 -0300 Subject: [PATCH 109/175] fix model --- .../__tests__/order-exchange.ts | 2 +- packages/modules/order/src/models/address.ts | 36 ++++---- .../modules/order/src/models/claim-item.ts | 46 +++++----- packages/modules/order/src/models/claim.ts | 12 ++- .../modules/order/src/models/exchange-item.ts | 33 ++++--- packages/modules/order/src/models/exchange.ts | 12 ++- .../order/src/models/line-item-adjustment.ts | 1 - .../order/src/models/line-item-tax-line.ts | 1 - .../order/src/models/order-change-action.ts | 2 +- .../modules/order/src/models/order-item.ts | 1 - .../order/src/models/order-shipping-method.ts | 1 - .../modules/order/src/models/order-summary.ts | 22 +++-- packages/modules/order/src/models/order.ts | 69 +++++++-------- .../modules/order/src/models/return-item.ts | 42 +++++---- packages/modules/order/src/models/return.ts | 4 - .../src/models/shipping-method-adjustment.ts | 1 - .../src/models/shipping-method-tax-line.ts | 1 - .../src/services/actions/create-exchange.ts | 1 - .../order/src/utils/base-repository-find.ts | 86 +++++++++---------- 19 files changed, 194 insertions(+), 179 deletions(-) diff --git a/packages/modules/order/integration-tests/__tests__/order-exchange.ts b/packages/modules/order/integration-tests/__tests__/order-exchange.ts index 6707173ba5bba..be846138a5d47 100644 --- a/packages/modules/order/integration-tests/__tests__/order-exchange.ts +++ b/packages/modules/order/integration-tests/__tests__/order-exchange.ts @@ -103,7 +103,7 @@ moduleIntegrationTestRunner({ customer_id: "joe", } as CreateOrderDTO - it.only("should exchange an item and add two new items to the order", async function () { + it("should exchange an item and add two new items to the order", async function () { const createdOrder = await service.createOrders(input) createdOrder.items = createdOrder.items!.sort((a, b) => a.title.localeCompare(b.title) diff --git a/packages/modules/order/src/models/address.ts b/packages/modules/order/src/models/address.ts index 94b4d7129ef1b..32ec293b70b31 100644 --- a/packages/modules/order/src/models/address.ts +++ b/packages/modules/order/src/models/address.ts @@ -1,21 +1,27 @@ import { model } from "@medusajs/framework/utils" const _OrderAddress = model - .define("OrderAddress", { - id: model.id({ prefix: "ordaddr" }).primaryKey(), - customer_id: model.text().nullable(), - company: model.text().searchable().nullable(), - first_name: model.text().searchable().nullable(), - last_name: model.text().searchable().nullable(), - address_1: model.text().searchable().nullable(), - address_2: model.text().searchable().nullable(), - city: model.text().searchable().nullable(), - country_code: model.text().nullable(), - province: model.text().searchable().nullable(), - postal_code: model.text().searchable().nullable(), - phone: model.text().searchable().nullable(), - metadata: model.json().nullable(), - }) + .define( + { + tableName: "OrderAddress", + disableSoftDeleteFilter: true, + }, + { + id: model.id({ prefix: "ordaddr" }).primaryKey(), + customer_id: model.text().nullable(), + company: model.text().searchable().nullable(), + first_name: model.text().searchable().nullable(), + last_name: model.text().searchable().nullable(), + address_1: model.text().searchable().nullable(), + address_2: model.text().searchable().nullable(), + city: model.text().searchable().nullable(), + country_code: model.text().nullable(), + province: model.text().searchable().nullable(), + postal_code: model.text().searchable().nullable(), + phone: model.text().searchable().nullable(), + metadata: model.json().nullable(), + } + ) .indexes([ { name: "IDX_order_address_customer_id", diff --git a/packages/modules/order/src/models/claim-item.ts b/packages/modules/order/src/models/claim-item.ts index 8539d23567b17..aa0a89dab3e76 100644 --- a/packages/modules/order/src/models/claim-item.ts +++ b/packages/modules/order/src/models/claim-item.ts @@ -4,26 +4,32 @@ import { OrderClaimItemImage } from "./claim-item-image" import { OrderLineItem } from "./line-item" const _OrderClaimItem = model - .define("OrderClaimItem", { - id: model.id({ prefix: "claitem" }).primaryKey(), - reason: model.enum(ClaimReason).nullable(), - quantity: model.bigNumber(), - is_additional_item: model.boolean().default(false), - note: model.text().nullable(), - metadata: model.json().nullable(), - claim: model.belongsTo<() => typeof OrderClaim>(() => OrderClaim, { - mappedBy: "additional_items", - }), - item: model.belongsTo<() => typeof OrderLineItem>(() => OrderLineItem, { - mappedBy: "claim_items", - }), - images: model.hasMany<() => typeof OrderClaimItemImage>( - () => OrderClaimItemImage, - { - mappedBy: "claim_item", - } - ), - }) + .define( + { + tableName: "OrderClaimItem", + disableSoftDeleteFilter: true, + }, + { + id: model.id({ prefix: "claitem" }).primaryKey(), + reason: model.enum(ClaimReason).nullable(), + quantity: model.bigNumber(), + is_additional_item: model.boolean().default(false), + note: model.text().nullable(), + metadata: model.json().nullable(), + claim: model.belongsTo<() => typeof OrderClaim>(() => OrderClaim, { + mappedBy: "additional_items", + }), + item: model.belongsTo<() => typeof OrderLineItem>(() => OrderLineItem, { + mappedBy: "claim_items", + }), + images: model.hasMany<() => typeof OrderClaimItemImage>( + () => OrderClaimItemImage, + { + mappedBy: "claim_item", + } + ), + } + ) .cascades({ delete: ["images"], }) diff --git a/packages/modules/order/src/models/claim.ts b/packages/modules/order/src/models/claim.ts index 62234c84754fd..f0a67b2f41359 100644 --- a/packages/modules/order/src/models/claim.ts +++ b/packages/modules/order/src/models/claim.ts @@ -1,7 +1,6 @@ import { ClaimType, model } from "@medusajs/framework/utils" import { OrderClaimItem } from "./claim-item" import { Order } from "./order" -import { OrderChange } from "./order-change" import { OrderShipping } from "./order-shipping-method" import { Return } from "./return" import { OrderTransaction } from "./transaction" @@ -21,9 +20,11 @@ const _OrderClaim = model order: model.belongsTo<() => typeof Order>(() => Order, { mappedBy: "claims", }), - return: model.hasMany<() => typeof Return>(() => Return, { - mappedBy: "claim", - }), + return: model + .hasOne<() => typeof Return>(() => Return, { + mappedBy: "claim", + }) + .nullable(), additional_items: model.hasMany<() => typeof OrderClaimItem>( () => OrderClaimItem, { @@ -48,9 +49,6 @@ const _OrderClaim = model mappedBy: "claim", } ), - changes: model.hasMany<() => typeof OrderChange>(() => OrderChange, { - mappedBy: "claim", - }), }) .cascades({ delete: [ diff --git a/packages/modules/order/src/models/exchange-item.ts b/packages/modules/order/src/models/exchange-item.ts index 998aabad7a071..d9ccf05bc7fd0 100644 --- a/packages/modules/order/src/models/exchange-item.ts +++ b/packages/modules/order/src/models/exchange-item.ts @@ -3,18 +3,27 @@ import { OrderExchange } from "./exchange" import { OrderLineItem } from "./line-item" const _OrderExchangeItem = model - .define("OrderExchangeItem", { - id: model.id({ prefix: "oexcitem" }).primaryKey(), - quantity: model.bigNumber(), - note: model.text().nullable(), - metadata: model.json().nullable(), - exchange: model.belongsTo<() => typeof OrderExchange>(() => OrderExchange, { - mappedBy: "additional_items", - }), - item: model.belongsTo<() => typeof OrderLineItem>(() => OrderLineItem, { - mappedBy: "exchange_items", - }), - }) + .define( + { + tableName: "OrderExchangeItem", + disableSoftDeleteFilter: true, + }, + { + id: model.id({ prefix: "oexcitem" }).primaryKey(), + quantity: model.bigNumber(), + note: model.text().nullable(), + metadata: model.json().nullable(), + exchange: model.belongsTo<() => typeof OrderExchange>( + () => OrderExchange, + { + mappedBy: "additional_items", + } + ), + item: model.belongsTo<() => typeof OrderLineItem>(() => OrderLineItem, { + mappedBy: "exchange_items", + }), + } + ) .indexes([ { name: "IDX_order_exchange_item_exchange_id", diff --git a/packages/modules/order/src/models/exchange.ts b/packages/modules/order/src/models/exchange.ts index 9ed2688e31630..033654887057c 100644 --- a/packages/modules/order/src/models/exchange.ts +++ b/packages/modules/order/src/models/exchange.ts @@ -2,7 +2,6 @@ import { model } from "@medusajs/framework/utils" import { OrderExchangeItem } from "./exchange-item" import { Order } from "./order" -import { OrderChange } from "./order-change" import { OrderShipping } from "./order-shipping-method" import { Return } from "./return" import { OrderTransaction } from "./transaction" @@ -22,9 +21,11 @@ const _OrderExchange = model order: model.belongsTo<() => typeof Order>(() => Order, { mappedBy: "exchanges", }), - return: model.hasMany<() => typeof Return>(() => Return, { - mappedBy: "exchange", - }), + return: model + .hasOne<() => typeof Return>(() => Return, { + mappedBy: "exchange", + }) + .nullable(), additional_items: model.hasMany<() => typeof OrderExchangeItem>( () => OrderExchangeItem, { @@ -43,9 +44,6 @@ const _OrderExchange = model mappedBy: "exchange", } ), - changes: model.hasMany<() => typeof OrderChange>(() => OrderChange, { - mappedBy: "exchange", - }), }) .cascades({ delete: ["additional_items", "shipping_methods", "transactions"], diff --git a/packages/modules/order/src/models/line-item-adjustment.ts b/packages/modules/order/src/models/line-item-adjustment.ts index da3872008d982..f8f8c7b3e70fa 100644 --- a/packages/modules/order/src/models/line-item-adjustment.ts +++ b/packages/modules/order/src/models/line-item-adjustment.ts @@ -4,7 +4,6 @@ import { OrderLineItem } from "./line-item" const _OrderLineItemAdjustment = model .define( { - name: "OrderLineItemAdjustment", tableName: "OrderLineItemAdjustment", disableSoftDeleteFilter: true, }, diff --git a/packages/modules/order/src/models/line-item-tax-line.ts b/packages/modules/order/src/models/line-item-tax-line.ts index ca612a40a1ac1..0efb7cb76b65c 100644 --- a/packages/modules/order/src/models/line-item-tax-line.ts +++ b/packages/modules/order/src/models/line-item-tax-line.ts @@ -4,7 +4,6 @@ import { OrderLineItem } from "./line-item" const _OrderLineItemTaxLine = model .define( { - name: "OrderLineItemTaxLine", tableName: "OrderLineItemTaxLine", disableSoftDeleteFilter: true, }, diff --git a/packages/modules/order/src/models/order-change-action.ts b/packages/modules/order/src/models/order-change-action.ts index dceb5f42aa4a6..8215b9d23e452 100644 --- a/packages/modules/order/src/models/order-change-action.ts +++ b/packages/modules/order/src/models/order-change-action.ts @@ -14,7 +14,7 @@ const _OrderChangeAction = model reference: model.text().nullable(), reference_id: model.text().nullable(), action: model.text(), - details: model.json(), + details: model.json().default({}), amount: model.bigNumber().nullable(), internal_note: model.text().nullable(), applied: model.boolean().default(false), diff --git a/packages/modules/order/src/models/order-item.ts b/packages/modules/order/src/models/order-item.ts index 419f4da5ebce5..35283a1500c0c 100644 --- a/packages/modules/order/src/models/order-item.ts +++ b/packages/modules/order/src/models/order-item.ts @@ -6,7 +6,6 @@ import { Order } from "./order" const _OrderItem = model .define( { - name: "OrderItem", tableName: "OrderItem", disableSoftDeleteFilter: true, }, diff --git a/packages/modules/order/src/models/order-shipping-method.ts b/packages/modules/order/src/models/order-shipping-method.ts index 696626cf52d3a..3ea7b5d34c238 100644 --- a/packages/modules/order/src/models/order-shipping-method.ts +++ b/packages/modules/order/src/models/order-shipping-method.ts @@ -8,7 +8,6 @@ import { OrderShippingMethod } from "./shipping-method" const _OrderShipping = model .define( { - name: "OrderShipping", tableName: "OrderShipping", disableSoftDeleteFilter: true, }, diff --git a/packages/modules/order/src/models/order-summary.ts b/packages/modules/order/src/models/order-summary.ts index 607d97d8e58c4..89d3e6b6cadae 100644 --- a/packages/modules/order/src/models/order-summary.ts +++ b/packages/modules/order/src/models/order-summary.ts @@ -2,14 +2,20 @@ import { model } from "@medusajs/framework/utils" import { Order } from "./order" const _OrderSummary = model - .define("OrderSummary", { - id: model.id({ prefix: "ordsum" }).primaryKey(), - version: model.number().default(1), - totals: model.json(), - order: model.belongsTo<() => typeof Order>(() => Order, { - mappedBy: "summary", - }), - }) + .define( + { + tableName: "OrderSummary", + disableSoftDeleteFilter: true, + }, + { + id: model.id({ prefix: "ordsum" }).primaryKey(), + version: model.number().default(1), + totals: model.json(), + order: model.belongsTo<() => typeof Order>(() => Order, { + mappedBy: "summary", + }), + } + ) .indexes([ { name: "IDX_order_summary_order_id_version", diff --git a/packages/modules/order/src/models/order.ts b/packages/modules/order/src/models/order.ts index 89e7e165400d5..8c4e1078ae9d7 100644 --- a/packages/modules/order/src/models/order.ts +++ b/packages/modules/order/src/models/order.ts @@ -18,7 +18,6 @@ import { TextProperty, } from "@medusajs/framework/utils" import { OrderAddress } from "./address" -import { OrderChange } from "./order-change" import { OrderItem } from "./order-item" import { OrderShipping } from "./order-shipping-method" import { OrderSummary } from "./order-summary" @@ -50,42 +49,44 @@ type OrderSchema = { items: HasMany shipping_methods: HasMany transactions: HasMany - changes: HasMany } const _Order = model - .define("Order", { - id: model.id({ prefix: "order" }).primaryKey(), - display_id: model.autoincrement(), - region_id: model.text().nullable(), - customer_id: model.text().nullable(), - version: model.number().default(1), - sales_channel_id: model.text().nullable(), - status: model.enum(OrderStatus).default(OrderStatus.PENDING), - is_draft_order: model.boolean().default(false), - email: model.text().searchable().nullable(), - currency_code: model.text(), - no_notification: model.boolean().nullable(), - metadata: model.json().nullable(), - canceled_at: model.dateTime().nullable(), - shipping_address: model.belongsTo(() => OrderAddress).nullable(), - billing_address: model.belongsTo(() => OrderAddress).nullable(), - summary: model.hasMany(() => OrderSummary, { - mappedBy: "order", - }), - items: model.hasMany(() => OrderItem, { - mappedBy: "order", - }), - shipping_methods: model.hasMany(() => OrderShipping, { - mappedBy: "order", - }), - transactions: model.hasMany(() => OrderTransaction, { - mappedBy: "order", - }), - changes: model.hasMany(() => OrderChange, { - mappedBy: "order", - }), - }) + .define( + { + tableName: "Order", + disableSoftDeleteFilter: true, + }, + { + id: model.id({ prefix: "order" }).primaryKey(), + display_id: model.autoincrement(), + region_id: model.text().nullable(), + customer_id: model.text().nullable(), + version: model.number().default(1), + sales_channel_id: model.text().nullable(), + status: model.enum(OrderStatus).default(OrderStatus.PENDING), + is_draft_order: model.boolean().default(false), + email: model.text().searchable().nullable(), + currency_code: model.text(), + no_notification: model.boolean().nullable(), + metadata: model.json().nullable(), + canceled_at: model.dateTime().nullable(), + shipping_address: model.belongsTo(() => OrderAddress).nullable(), + billing_address: model.belongsTo(() => OrderAddress).nullable(), + summary: model.hasMany(() => OrderSummary, { + mappedBy: "order", + }), + items: model.hasMany(() => OrderItem, { + mappedBy: "order", + }), + shipping_methods: model.hasMany(() => OrderShipping, { + mappedBy: "order", + }), + transactions: model.hasMany(() => OrderTransaction, { + mappedBy: "order", + }), + } + ) .cascades({ delete: ["summary", "items", "shipping_methods", "transactions"], }) diff --git a/packages/modules/order/src/models/return-item.ts b/packages/modules/order/src/models/return-item.ts index 70c9e6b7b634f..83bc6529737ca 100644 --- a/packages/modules/order/src/models/return-item.ts +++ b/packages/modules/order/src/models/return-item.ts @@ -4,25 +4,31 @@ import { Return } from "./return" import { ReturnReason } from "./return-reason" const _ReturnItem = model - .define("ReturnItem", { - id: model.id({ prefix: "retitem" }).primaryKey(), - quantity: model.bigNumber(), - received_quantity: model.bigNumber().default(0), - damaged_quantity: model.bigNumber().default(0), - note: model.text().nullable(), - metadata: model.json().nullable(), - reason: model - .belongsTo<() => typeof ReturnReason>(() => ReturnReason, { + .define( + { + tableName: "ReturnItem", + disableSoftDeleteFilter: true, + }, + { + id: model.id({ prefix: "retitem" }).primaryKey(), + quantity: model.bigNumber(), + received_quantity: model.bigNumber().default(0), + damaged_quantity: model.bigNumber().default(0), + note: model.text().nullable(), + metadata: model.json().nullable(), + reason: model + .belongsTo<() => typeof ReturnReason>(() => ReturnReason, { + mappedBy: "return_items", + }) + .nullable(), + return: model.belongsTo<() => typeof Return>(() => Return, { + mappedBy: "items", + }), + item: model.belongsTo<() => typeof OrderLineItem>(() => OrderLineItem, { mappedBy: "return_items", - }) - .nullable(), - return: model.belongsTo<() => typeof Return>(() => Return, { - mappedBy: "items", - }), - item: model.belongsTo<() => typeof OrderLineItem>(() => OrderLineItem, { - mappedBy: "return_items", - }), - }) + }), + } + ) .indexes([ { name: "IDX_return_item_return_id", diff --git a/packages/modules/order/src/models/return.ts b/packages/modules/order/src/models/return.ts index 7f0bd72ed9892..75f0482f83eaf 100644 --- a/packages/modules/order/src/models/return.ts +++ b/packages/modules/order/src/models/return.ts @@ -2,7 +2,6 @@ import { model, ReturnStatus } from "@medusajs/framework/utils" import { OrderClaim } from "./claim" import { OrderExchange } from "./exchange" import { Order } from "./order" -import { OrderChange } from "./order-change" import { OrderShipping } from "./order-shipping-method" import { ReturnItem } from "./return-item" import { OrderTransaction } from "./transaction" @@ -49,9 +48,6 @@ const _Return = model mappedBy: "return", } ), - changes: model.hasMany<() => typeof OrderChange>(() => OrderChange, { - mappedBy: "return", - }), }) .cascades({ delete: ["items", "shipping_methods", "transactions"], diff --git a/packages/modules/order/src/models/shipping-method-adjustment.ts b/packages/modules/order/src/models/shipping-method-adjustment.ts index 1c6efc7a812ad..56946e55f83d3 100644 --- a/packages/modules/order/src/models/shipping-method-adjustment.ts +++ b/packages/modules/order/src/models/shipping-method-adjustment.ts @@ -4,7 +4,6 @@ import { OrderShippingMethod } from "./shipping-method" const _OrderShippingMethodAdjustment = model .define( { - name: "OrderShippingMethodAdjustment", tableName: "OrderShippingMethodAdjustment", disableSoftDeleteFilter: true, }, diff --git a/packages/modules/order/src/models/shipping-method-tax-line.ts b/packages/modules/order/src/models/shipping-method-tax-line.ts index 8250e8c79e9ae..36eb09a5210e6 100644 --- a/packages/modules/order/src/models/shipping-method-tax-line.ts +++ b/packages/modules/order/src/models/shipping-method-tax-line.ts @@ -4,7 +4,6 @@ import { OrderShippingMethod } from "./shipping-method" const _OrderShippingMethodTaxLine = model .define( { - name: "OrderShippingMethodTaxLine", tableName: "OrderShippingMethodTaxLine", disableSoftDeleteFilter: true, }, diff --git a/packages/modules/order/src/services/actions/create-exchange.ts b/packages/modules/order/src/services/actions/create-exchange.ts index 2db2e52a05084..332e3f2ad6973 100644 --- a/packages/modules/order/src/services/actions/create-exchange.ts +++ b/packages/modules/order/src/services/actions/create-exchange.ts @@ -314,6 +314,5 @@ export async function createExchange( this.createOrderExchanges([exchangeReference], sharedContext), this.confirmOrderChange(change[0].id, sharedContext), ]) - return exchangeReference } diff --git a/packages/modules/order/src/utils/base-repository-find.ts b/packages/modules/order/src/utils/base-repository-find.ts index a8cf08881f9a6..2c7f202178443 100644 --- a/packages/modules/order/src/utils/base-repository-find.ts +++ b/packages/modules/order/src/utils/base-repository-find.ts @@ -16,7 +16,6 @@ export function setFindMethods(klass: Constructor, entity: any) { const findOptions_ = { ...options } as any findOptions_.options ??= {} findOptions_.where ??= {} - findOptions_.populate ??= [] if (!("strategy" in findOptions_.options)) { if (findOptions_.options.limit != null || findOptions_.options.offset) { @@ -75,37 +74,10 @@ export function setFindMethods(klass: Constructor, entity: any) { defaultVersion = knex.raw(`(${sql})`) } - const version = config.where.version ?? defaultVersion + const version = config.where?.version ?? defaultVersion delete config.where?.version - config.options.populateWhere ??= {} - const popWhere = config.options.populateWhere - - if (isRelatedEntity) { - popWhere.order ??= {} - - popWhere.shipping_methods ??= {} - popWhere.shipping_methods.deleted_at ??= null - - popWhere.shipping_methods.shipping_method ??= {} - popWhere.shipping_methods.shipping_method.deleted_at ??= null - } - - const orderWhere = isRelatedEntity ? popWhere.order : popWhere - - orderWhere.summary ??= {} - orderWhere.summary.version = version - - orderWhere.items ??= {} - orderWhere.items.version = version - orderWhere.items.deleted_at ??= null - - orderWhere.shipping_methods ??= {} - orderWhere.shipping_methods.version = version - orderWhere.shipping_methods.deleted_at ??= null - - orderWhere.shipping_methods.shipping_method ??= {} - orderWhere.shipping_methods.shipping_method.deleted_at ??= null + configurePopulateWhere(config, isRelatedEntity, version) if (!config.options.orderBy) { config.options.orderBy = { id: "ASC" } @@ -149,7 +121,6 @@ export function setFindMethods(klass: Constructor, entity: any) { } } - // first relation is always order if the entity is not Order const index = config.options.populate.findIndex((p) => p === "order") if (index > -1) { config.options.populate.splice(index, 1) @@ -175,30 +146,55 @@ export function setFindMethods(klass: Constructor, entity: any) { const version = config.where.version ?? defaultVersion delete config.where.version - config.options.populateWhere ??= {} - const popWhere = config.options.populateWhere + configurePopulateWhere(config, isRelatedEntity, version) - if (isRelatedEntity) { - popWhere.order ??= {} + if (!config.options.orderBy) { + config.options.orderBy = { id: "ASC" } + } + + return await manager.findAndCount(this.entity, config.where, config.options) + } +} + +function configurePopulateWhere( + config: any, + isRelatedEntity: boolean, + version: any +) { + const requestedPopulate = config.options?.populate ?? [] + const hasRelation = (relation: string) => + requestedPopulate.some( + (p) => p === relation || p.startsWith(`${relation}.`) + ) + + config.options.populateWhere ??= {} + const popWhere = config.options.populateWhere + + if (isRelatedEntity) { + popWhere.order ??= {} + + if (hasRelation("shipping_methods")) { + popWhere.shipping_methods ??= {} + popWhere.shipping_methods.deleted_at ??= null } + } - const orderWhere = isRelatedEntity ? popWhere.order : popWhere + const orderWhere = isRelatedEntity ? popWhere.order : popWhere + if (hasRelation("summary")) { orderWhere.summary ??= {} orderWhere.summary.version = version + } + if (hasRelation("items")) { orderWhere.items ??= {} orderWhere.items.version = version orderWhere.items.deleted_at ??= null + } - popWhere.shipping_methods ??= {} - popWhere.shipping_methods.version = version - popWhere.shipping_methods.deleted_at ??= null - - if (!config.options.orderBy) { - config.options.orderBy = { id: "ASC" } - } - - return await manager.findAndCount(this.entity, config.where, config.options) + if (hasRelation("shipping_methods")) { + orderWhere.shipping_methods ??= {} + orderWhere.shipping_methods.version = version + orderWhere.shipping_methods.deleted_at ??= null } } From 7b5d65b4e690f9e5e52e96c52f7c1a8412951bb7 Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Mon, 2 Dec 2024 08:47:07 -0300 Subject: [PATCH 110/175] model changes --- packages/modules/order/src/models/claim.ts | 3 +-- packages/modules/order/src/models/exchange.ts | 3 +-- packages/modules/order/src/models/return.ts | 8 ++++++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/modules/order/src/models/claim.ts b/packages/modules/order/src/models/claim.ts index f0a67b2f41359..6ec08536f9019 100644 --- a/packages/modules/order/src/models/claim.ts +++ b/packages/modules/order/src/models/claim.ts @@ -8,7 +8,6 @@ import { OrderTransaction } from "./transaction" const _OrderClaim = model .define("OrderClaim", { id: model.id({ prefix: "claim" }).primaryKey(), - return_id: model.text().nullable(), order_version: model.number(), display_id: model.autoincrement(), type: model.enum(ClaimType), @@ -21,7 +20,7 @@ const _OrderClaim = model mappedBy: "claims", }), return: model - .hasOne<() => typeof Return>(() => Return, { + .belongsTo<() => typeof Return>(() => Return, { mappedBy: "claim", }) .nullable(), diff --git a/packages/modules/order/src/models/exchange.ts b/packages/modules/order/src/models/exchange.ts index 033654887057c..66233ebc383ae 100644 --- a/packages/modules/order/src/models/exchange.ts +++ b/packages/modules/order/src/models/exchange.ts @@ -9,7 +9,6 @@ import { OrderTransaction } from "./transaction" const _OrderExchange = model .define("OrderExchange", { id: model.id({ prefix: "oexc" }).primaryKey(), - return_id: model.text().nullable(), order_version: model.number(), display_id: model.autoincrement(), no_notification: model.boolean().nullable(), @@ -22,7 +21,7 @@ const _OrderExchange = model mappedBy: "exchanges", }), return: model - .hasOne<() => typeof Return>(() => Return, { + .belongsTo<() => typeof Return>(() => Return, { mappedBy: "exchange", }) .nullable(), diff --git a/packages/modules/order/src/models/return.ts b/packages/modules/order/src/models/return.ts index 75f0482f83eaf..a1418cae035e5 100644 --- a/packages/modules/order/src/models/return.ts +++ b/packages/modules/order/src/models/return.ts @@ -9,6 +9,8 @@ import { OrderTransaction } from "./transaction" const _Return = model .define("Return", { id: model.id({ prefix: "return" }).primaryKey(), + exchange_id: model.text().nullable(), + claim_id: model.text().nullable(), order_version: model.number(), display_id: model.autoincrement(), status: model.enum(ReturnStatus).default(ReturnStatus.OPEN), @@ -24,13 +26,15 @@ const _Return = model mappedBy: "returns", }), exchange: model - .belongsTo<() => typeof OrderExchange>(() => OrderExchange, { + .hasOne<() => typeof OrderExchange>(() => OrderExchange, { mappedBy: "return", + fieldName: "exchange_id", }) .nullable(), claim: model - .belongsTo<() => typeof OrderClaim>(() => OrderClaim, { + .hasOne<() => typeof OrderClaim>(() => OrderClaim, { mappedBy: "return", + fieldName: "claim_id", }) .nullable(), items: model.hasMany<() => typeof ReturnItem>(() => ReturnItem, { From 5be3cee96d02f6e246232fa3be4e30819faeb2f6 Mon Sep 17 00:00:00 2001 From: adrien2p Date: Mon, 2 Dec 2024 14:08:59 +0100 Subject: [PATCH 111/175] fix one to one DML --- .../entity-builder/define-relationship.ts | 41 +++++++++++-------- packages/modules/order/package.json | 2 +- .../src/services/actions/receive-return.ts | 2 +- .../src/services/order-module-service.ts | 1 + 4 files changed, 27 insertions(+), 19 deletions(-) diff --git a/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts b/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts index 9d7b6d2ab1b0d..8a2fa682029ad 100644 --- a/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts +++ b/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts @@ -140,14 +140,18 @@ export function defineHasOneRelationship( ) { const shouldRemoveRelated = !!cascades.delete?.includes(relationship.name) - OneToOne({ + const options: Parameters[0] = { entity: relatedModelName, nullable: relationship.nullable, + fieldName: relationship.options.fieldName, mappedBy: relationship.mappedBy || camelToSnakeCase(MikroORMEntity.name), - cascade: shouldRemoveRelated - ? (["persist", "soft-remove"] as any) - : undefined, - })(MikroORMEntity.prototype, relationship.name) + } + + if (shouldRemoveRelated) { + options.cascade = ["persist", "soft-remove"] as any + } + + OneToOne(options)(MikroORMEntity.prototype, relationship.name) } /** @@ -321,14 +325,6 @@ export function defineBelongsToRelationship( if (HasOne.isHasOne(otherSideRelation)) { const foreignKeyName = camelToSnakeCase(`${relationship.name}Id`) - OneToOne({ - entity: relatedModelName, - nullable: relationship.nullable, - mappedBy: mappedBy, - owner: true, - onDelete: shouldCascade ? "cascade" : undefined, - })(MikroORMEntity.prototype, relationship.name) - Object.defineProperty(MikroORMEntity.prototype, foreignKeyName, { value: null, configurable: true, @@ -336,12 +332,23 @@ export function defineBelongsToRelationship( writable: true, }) - Property({ - type: "string", - columnType: "text", + const oneToOneOptions = { + entity: relatedModelName, nullable: relationship.nullable, + inversedBy: mappedBy, + fieldName: foreignKeyName, + owner: true, + onDelete: shouldCascade ? "cascade" : undefined, + mapToPk: true, + } + + OneToOne(oneToOneOptions)(MikroORMEntity.prototype, foreignKeyName) + + OneToOne({ + ...oneToOneOptions, + mapToPk: false, persist: false, - })(MikroORMEntity.prototype, foreignKeyName) + })(MikroORMEntity.prototype, relationship.name) const { tableName } = parseEntityName(entity) applyEntityIndexes(MikroORMEntity, tableName, [ diff --git a/packages/modules/order/package.json b/packages/modules/order/package.json index 8b985e3181d7e..227ac3c8f352c 100644 --- a/packages/modules/order/package.json +++ b/packages/modules/order/package.json @@ -29,7 +29,7 @@ "resolve:aliases": "tsc --showConfig -p tsconfig.json > tsconfig.resolved.json && tsc-alias -p tsconfig.resolved.json && rimraf tsconfig.resolved.json", "build": "rimraf dist && tsc --build && npm run resolve:aliases", "test": "jest --runInBand --bail --forceExit -- src/**/__tests__/**/*.ts", - "test:integration": "jest --forceExit -- integration-tests/__tests__/order-claim.ts", + "test:integration": "jest --forceExit -- integration-tests/__tests__/**/*.ts", "migration:initial": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm migration:create --initial", "migration:create": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm migration:create", "migration:up": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm migration:up", diff --git a/packages/modules/order/src/services/actions/receive-return.ts b/packages/modules/order/src/services/actions/receive-return.ts index 142adde8d0cb1..f5cf8cd6b2a2b 100644 --- a/packages/modules/order/src/services/actions/receive-return.ts +++ b/packages/modules/order/src/services/actions/receive-return.ts @@ -85,7 +85,7 @@ export async function receiveReturn( data.return_id, { select: ["id", "order_id"], - relations: ["items"], + relations: ["items", "items.item"], }, sharedContext ) diff --git a/packages/modules/order/src/services/order-module-service.ts b/packages/modules/order/src/services/order-module-service.ts index e2c49f53385ef..0f0aa7ec3fdc8 100644 --- a/packages/modules/order/src/services/order-module-service.ts +++ b/packages/modules/order/src/services/order-module-service.ts @@ -3243,6 +3243,7 @@ export default class OrderModuleService return await this.retrieveReturn(ret.id, { relations: [ "items", + "items.item", "shipping_methods", "shipping_methods.tax_lines", "shipping_methods.adjustments", From 8e06ebe4139e78283772a958877bae52927b884f Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Mon, 2 Dec 2024 10:46:03 -0300 Subject: [PATCH 112/175] order test --- integration-tests/modules/__tests__/order/order.spec.ts | 2 ++ packages/core/modules-sdk/src/loaders/utils/load-internal.ts | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/integration-tests/modules/__tests__/order/order.spec.ts b/integration-tests/modules/__tests__/order/order.spec.ts index 8e0bc18afc55a..08d574a3de9d2 100644 --- a/integration-tests/modules/__tests__/order/order.spec.ts +++ b/integration-tests/modules/__tests__/order/order.spec.ts @@ -356,6 +356,7 @@ medusaIntegrationTestRunner({ metadata: null, created_at: expect.any(String), updated_at: expect.any(String), + deleted_at: null, }, billing_address: { id: expect.any(String), @@ -373,6 +374,7 @@ medusaIntegrationTestRunner({ metadata: null, created_at: expect.any(String), updated_at: expect.any(String), + deleted_at: null, }, shipping_methods: [ expect.objectContaining({ diff --git a/packages/core/modules-sdk/src/loaders/utils/load-internal.ts b/packages/core/modules-sdk/src/loaders/utils/load-internal.ts index 0309dfb3de657..7782ca6d52b49 100644 --- a/packages/core/modules-sdk/src/loaders/utils/load-internal.ts +++ b/packages/core/modules-sdk/src/loaders/utils/load-internal.ts @@ -559,7 +559,7 @@ export async function loadResources({ normalizedPath = resolve(normalizedPath) try { - const defaultOnFail = (e) => { + const defaultOnFail = () => { return [] } From 236ba43d99c789f796ca4774ed422d017c3eedaa Mon Sep 17 00:00:00 2001 From: adrien2p Date: Tue, 3 Dec 2024 12:50:59 +0100 Subject: [PATCH 113/175] fix addresses --- .../entity-builder/define-relationship.ts | 34 +++++++++++-------- packages/modules/order/src/models/address.ts | 11 ++++++ packages/modules/order/src/models/order.ts | 12 +++++-- 3 files changed, 40 insertions(+), 17 deletions(-) diff --git a/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts b/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts index 8a2fa682029ad..0aff9c6373ce3 100644 --- a/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts +++ b/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts @@ -7,6 +7,7 @@ import { } from "@medusajs/types" import { BeforeCreate, + Cascade, ManyToMany, ManyToOne, OneToMany, @@ -325,6 +326,20 @@ export function defineBelongsToRelationship( if (HasOne.isHasOne(otherSideRelation)) { const foreignKeyName = camelToSnakeCase(`${relationship.name}Id`) + const oneToOneOptions: Parameters[0] = { + entity: relatedModelName, + nullable: relationship.nullable, + mappedBy: mappedBy, + owner: true, + onDelete: shouldCascade ? "cascade" : undefined, + } + + if (shouldCascade) { + oneToOneOptions.cascade = [Cascade.PERSIST, "soft-remove"] as any + } + + OneToOne(oneToOneOptions)(MikroORMEntity.prototype, relationship.name) + Object.defineProperty(MikroORMEntity.prototype, foreignKeyName, { value: null, configurable: true, @@ -332,23 +347,12 @@ export function defineBelongsToRelationship( writable: true, }) - const oneToOneOptions = { - entity: relatedModelName, + Property({ + type: "string", + columnType: "text", nullable: relationship.nullable, - inversedBy: mappedBy, - fieldName: foreignKeyName, - owner: true, - onDelete: shouldCascade ? "cascade" : undefined, - mapToPk: true, - } - - OneToOne(oneToOneOptions)(MikroORMEntity.prototype, foreignKeyName) - - OneToOne({ - ...oneToOneOptions, - mapToPk: false, persist: false, - })(MikroORMEntity.prototype, relationship.name) + })(MikroORMEntity.prototype, foreignKeyName) const { tableName } = parseEntityName(entity) applyEntityIndexes(MikroORMEntity, tableName, [ diff --git a/packages/modules/order/src/models/address.ts b/packages/modules/order/src/models/address.ts index 32ec293b70b31..4bc17d72ed2cf 100644 --- a/packages/modules/order/src/models/address.ts +++ b/packages/modules/order/src/models/address.ts @@ -1,4 +1,5 @@ import { model } from "@medusajs/framework/utils" +import { Order } from "./order" const _OrderAddress = model .define( @@ -19,6 +20,16 @@ const _OrderAddress = model province: model.text().searchable().nullable(), postal_code: model.text().searchable().nullable(), phone: model.text().searchable().nullable(), + shipping_address_order: model + .hasOne(() => Order, { + mappedBy: "shipping_address", + }) + .nullable(), + billing_address_order: model + .hasOne(() => Order, { + mappedBy: "billing_address", + }) + .nullable(), metadata: model.json().nullable(), } ) diff --git a/packages/modules/order/src/models/order.ts b/packages/modules/order/src/models/order.ts index 8c4e1078ae9d7..33f34296a581d 100644 --- a/packages/modules/order/src/models/order.ts +++ b/packages/modules/order/src/models/order.ts @@ -71,8 +71,16 @@ const _Order = model no_notification: model.boolean().nullable(), metadata: model.json().nullable(), canceled_at: model.dateTime().nullable(), - shipping_address: model.belongsTo(() => OrderAddress).nullable(), - billing_address: model.belongsTo(() => OrderAddress).nullable(), + shipping_address: model + .belongsTo(() => OrderAddress, { + mappedBy: "shipping_address_order", + }) + .nullable(), + billing_address: model + .belongsTo(() => OrderAddress, { + mappedBy: "billing_address_order", + }) + .nullable(), summary: model.hasMany(() => OrderSummary, { mappedBy: "order", }), From 0c32e2eabaed09de55c258115b4b2688f0b9b39e Mon Sep 17 00:00:00 2001 From: adrien2p Date: Tue, 3 Dec 2024 12:57:18 +0100 Subject: [PATCH 114/175] fix unit tests --- packages/core/utils/src/dml/__tests__/entity-builder.spec.ts | 4 +++- packages/core/utils/src/dml/entity.ts | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts b/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts index 8f9f5055e844d..2c7bc252d756a 100644 --- a/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts +++ b/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts @@ -2835,6 +2835,7 @@ describe("Entity builder", () => { name: "user", nullable: false, onDelete: "cascade", + cascade: ["persist", "soft-remove"], owner: true, reference: "1:1", }, @@ -4418,7 +4419,8 @@ describe("Entity builder", () => { }) }) - test("throw error when other side relationship is missing", () => { + // We now allow the other side to not exists, maybe remove that test? + test.skip("throw error when other side relationship is missing", () => { const email = model.define("email", { email: model.text(), isVerified: model.boolean(), diff --git a/packages/core/utils/src/dml/entity.ts b/packages/core/utils/src/dml/entity.ts index 1c5ba0a04d8f1..3da8f51a942b1 100644 --- a/packages/core/utils/src/dml/entity.ts +++ b/packages/core/utils/src/dml/entity.ts @@ -68,7 +68,7 @@ function extractEntityConfig( ) as InferDmlEntityNameFromConfig result.tableName = nameOrConfig.tableName result.disableSoftDeleteFilter = - nameOrConfig.disableSoftDeleteFilter ?? true + nameOrConfig.disableSoftDeleteFilter ?? false } return result From 5385fbcd4922524abe3ff968e9ac164b0f3e2f4c Mon Sep 17 00:00:00 2001 From: adrien2p Date: Tue, 3 Dec 2024 13:02:56 +0100 Subject: [PATCH 115/175] Re align dml entity name inference --- packages/core/types/src/dml/index.ts | 16 +++++++++------- packages/modules/order/src/models/order-item.ts | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/packages/core/types/src/dml/index.ts b/packages/core/types/src/dml/index.ts index 98b1645ed8a86..2af4281bce3b2 100644 --- a/packages/core/types/src/dml/index.ts +++ b/packages/core/types/src/dml/index.ts @@ -19,13 +19,15 @@ export type IDmlEntityConfig = } export type InferDmlEntityNameFromConfig = - TConfig extends string - ? CamelCase - : TConfig extends { name: string } - ? CamelCase - : TConfig extends { tableName: string } - ? CamelCase - : never + Capitalize< + TConfig extends string + ? CamelCase + : TConfig extends { name: string } + ? CamelCase + : TConfig extends { tableName: string } + ? CamelCase + : never + > /** * Representation of a DML entity diff --git a/packages/modules/order/src/models/order-item.ts b/packages/modules/order/src/models/order-item.ts index 35283a1500c0c..5417f56cb5aca 100644 --- a/packages/modules/order/src/models/order-item.ts +++ b/packages/modules/order/src/models/order-item.ts @@ -6,7 +6,7 @@ import { Order } from "./order" const _OrderItem = model .define( { - tableName: "OrderItem", + tableName: "order_item", disableSoftDeleteFilter: true, }, { From c45ee3193b3ad7a748de887f68016140161deecd Mon Sep 17 00:00:00 2001 From: adrien2p Date: Tue, 3 Dec 2024 13:05:27 +0100 Subject: [PATCH 116/175] update model table name config --- packages/modules/order/src/models/claim-item.ts | 2 +- packages/modules/order/src/models/exchange-item.ts | 2 +- packages/modules/order/src/models/line-item-adjustment.ts | 2 +- packages/modules/order/src/models/line-item-tax-line.ts | 2 +- packages/modules/order/src/models/order-shipping-method.ts | 2 +- packages/modules/order/src/models/order-summary.ts | 2 +- packages/modules/order/src/models/order.ts | 2 +- packages/modules/order/src/models/return-item.ts | 2 +- packages/modules/order/src/models/shipping-method-adjustment.ts | 2 +- packages/modules/order/src/models/shipping-method-tax-line.ts | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/modules/order/src/models/claim-item.ts b/packages/modules/order/src/models/claim-item.ts index aa0a89dab3e76..a636b2cd0dc93 100644 --- a/packages/modules/order/src/models/claim-item.ts +++ b/packages/modules/order/src/models/claim-item.ts @@ -6,7 +6,7 @@ import { OrderLineItem } from "./line-item" const _OrderClaimItem = model .define( { - tableName: "OrderClaimItem", + tableName: "order_claim_item", disableSoftDeleteFilter: true, }, { diff --git a/packages/modules/order/src/models/exchange-item.ts b/packages/modules/order/src/models/exchange-item.ts index d9ccf05bc7fd0..b286a4fca26c5 100644 --- a/packages/modules/order/src/models/exchange-item.ts +++ b/packages/modules/order/src/models/exchange-item.ts @@ -5,7 +5,7 @@ import { OrderLineItem } from "./line-item" const _OrderExchangeItem = model .define( { - tableName: "OrderExchangeItem", + tableName: "order_exchange_item", disableSoftDeleteFilter: true, }, { diff --git a/packages/modules/order/src/models/line-item-adjustment.ts b/packages/modules/order/src/models/line-item-adjustment.ts index f8f8c7b3e70fa..3e25c07a010e2 100644 --- a/packages/modules/order/src/models/line-item-adjustment.ts +++ b/packages/modules/order/src/models/line-item-adjustment.ts @@ -4,7 +4,7 @@ import { OrderLineItem } from "./line-item" const _OrderLineItemAdjustment = model .define( { - tableName: "OrderLineItemAdjustment", + tableName: "order_line_item_adjustment", disableSoftDeleteFilter: true, }, { diff --git a/packages/modules/order/src/models/line-item-tax-line.ts b/packages/modules/order/src/models/line-item-tax-line.ts index 0efb7cb76b65c..9c6cba59dd437 100644 --- a/packages/modules/order/src/models/line-item-tax-line.ts +++ b/packages/modules/order/src/models/line-item-tax-line.ts @@ -4,7 +4,7 @@ import { OrderLineItem } from "./line-item" const _OrderLineItemTaxLine = model .define( { - tableName: "OrderLineItemTaxLine", + tableName: "order_line_item_tax_line", disableSoftDeleteFilter: true, }, { diff --git a/packages/modules/order/src/models/order-shipping-method.ts b/packages/modules/order/src/models/order-shipping-method.ts index 3ea7b5d34c238..f05d8b754cc61 100644 --- a/packages/modules/order/src/models/order-shipping-method.ts +++ b/packages/modules/order/src/models/order-shipping-method.ts @@ -8,7 +8,7 @@ import { OrderShippingMethod } from "./shipping-method" const _OrderShipping = model .define( { - tableName: "OrderShipping", + tableName: "order_shipping", disableSoftDeleteFilter: true, }, { diff --git a/packages/modules/order/src/models/order-summary.ts b/packages/modules/order/src/models/order-summary.ts index 89d3e6b6cadae..92394920ed466 100644 --- a/packages/modules/order/src/models/order-summary.ts +++ b/packages/modules/order/src/models/order-summary.ts @@ -4,7 +4,7 @@ import { Order } from "./order" const _OrderSummary = model .define( { - tableName: "OrderSummary", + tableName: "order_summary", disableSoftDeleteFilter: true, }, { diff --git a/packages/modules/order/src/models/order.ts b/packages/modules/order/src/models/order.ts index 33f34296a581d..a7f2d91805322 100644 --- a/packages/modules/order/src/models/order.ts +++ b/packages/modules/order/src/models/order.ts @@ -54,7 +54,7 @@ type OrderSchema = { const _Order = model .define( { - tableName: "Order", + tableName: "order", disableSoftDeleteFilter: true, }, { diff --git a/packages/modules/order/src/models/return-item.ts b/packages/modules/order/src/models/return-item.ts index 83bc6529737ca..edf5be8bdeef0 100644 --- a/packages/modules/order/src/models/return-item.ts +++ b/packages/modules/order/src/models/return-item.ts @@ -6,7 +6,7 @@ import { ReturnReason } from "./return-reason" const _ReturnItem = model .define( { - tableName: "ReturnItem", + tableName: "return_item", disableSoftDeleteFilter: true, }, { diff --git a/packages/modules/order/src/models/shipping-method-adjustment.ts b/packages/modules/order/src/models/shipping-method-adjustment.ts index 56946e55f83d3..c6a2dd3e4f0a6 100644 --- a/packages/modules/order/src/models/shipping-method-adjustment.ts +++ b/packages/modules/order/src/models/shipping-method-adjustment.ts @@ -4,7 +4,7 @@ import { OrderShippingMethod } from "./shipping-method" const _OrderShippingMethodAdjustment = model .define( { - tableName: "OrderShippingMethodAdjustment", + tableName: "order_shipping_method_adjustment", disableSoftDeleteFilter: true, }, { diff --git a/packages/modules/order/src/models/shipping-method-tax-line.ts b/packages/modules/order/src/models/shipping-method-tax-line.ts index 36eb09a5210e6..b5e1664f6050a 100644 --- a/packages/modules/order/src/models/shipping-method-tax-line.ts +++ b/packages/modules/order/src/models/shipping-method-tax-line.ts @@ -4,7 +4,7 @@ import { OrderShippingMethod } from "./shipping-method" const _OrderShippingMethodTaxLine = model .define( { - tableName: "OrderShippingMethodTaxLine", + tableName: "order_shipping_method_tax_line", disableSoftDeleteFilter: true, }, { From e5a637db09ba2d8f687fa3e53ee121d2e5afc441 Mon Sep 17 00:00:00 2001 From: adrien2p Date: Tue, 3 Dec 2024 13:06:08 +0100 Subject: [PATCH 117/175] update model table name config --- packages/modules/order/src/models/address.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/modules/order/src/models/address.ts b/packages/modules/order/src/models/address.ts index 4bc17d72ed2cf..8116fb3105598 100644 --- a/packages/modules/order/src/models/address.ts +++ b/packages/modules/order/src/models/address.ts @@ -4,7 +4,7 @@ import { Order } from "./order" const _OrderAddress = model .define( { - tableName: "OrderAddress", + tableName: "order_address", disableSoftDeleteFilter: true, }, { From f4361d9b9fec28c22e7fb5faa91a2be816e0cac4 Mon Sep 17 00:00:00 2001 From: adrien2p Date: Tue, 3 Dec 2024 13:25:51 +0100 Subject: [PATCH 118/175] revert --- packages/core/types/src/dml/index.ts | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/packages/core/types/src/dml/index.ts b/packages/core/types/src/dml/index.ts index 2af4281bce3b2..98b1645ed8a86 100644 --- a/packages/core/types/src/dml/index.ts +++ b/packages/core/types/src/dml/index.ts @@ -19,15 +19,13 @@ export type IDmlEntityConfig = } export type InferDmlEntityNameFromConfig = - Capitalize< - TConfig extends string - ? CamelCase - : TConfig extends { name: string } - ? CamelCase - : TConfig extends { tableName: string } - ? CamelCase - : never - > + TConfig extends string + ? CamelCase + : TConfig extends { name: string } + ? CamelCase + : TConfig extends { tableName: string } + ? CamelCase + : never /** * Representation of a DML entity From f6c6475639c64aa48afd6286a8893d5ebfd4f2b9 Mon Sep 17 00:00:00 2001 From: adrien2p Date: Tue, 3 Dec 2024 15:27:50 +0100 Subject: [PATCH 119/175] update return relation --- packages/modules/order/src/models/return.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/modules/order/src/models/return.ts b/packages/modules/order/src/models/return.ts index a1418cae035e5..66530c583f90a 100644 --- a/packages/modules/order/src/models/return.ts +++ b/packages/modules/order/src/models/return.ts @@ -28,13 +28,11 @@ const _Return = model exchange: model .hasOne<() => typeof OrderExchange>(() => OrderExchange, { mappedBy: "return", - fieldName: "exchange_id", }) .nullable(), claim: model .hasOne<() => typeof OrderClaim>(() => OrderClaim, { mappedBy: "return", - fieldName: "claim_id", }) .nullable(), items: model.hasMany<() => typeof ReturnItem>(() => ReturnItem, { From 2285bb29f01da5c8b39deb62b5aab2a7b1f5b201 Mon Sep 17 00:00:00 2001 From: adrien2p Date: Tue, 3 Dec 2024 17:50:32 +0100 Subject: [PATCH 120/175] WIP --- .../helpers/entity-builder/define-property.ts | 1 + .../entity-builder/define-relationship.ts | 37 ++++++++----------- .../__tests__/order-claim.ts | 4 +- packages/modules/order/package.json | 2 +- .../src/services/order-module-service.ts | 4 +- .../order/src/utils/base-repository-find.ts | 6 ++- 6 files changed, 27 insertions(+), 27 deletions(-) diff --git a/packages/core/utils/src/dml/helpers/entity-builder/define-property.ts b/packages/core/utils/src/dml/helpers/entity-builder/define-property.ts index 4c91d894cdc20..365c88c36c644 100644 --- a/packages/core/utils/src/dml/helpers/entity-builder/define-property.ts +++ b/packages/core/utils/src/dml/helpers/entity-builder/define-property.ts @@ -269,6 +269,7 @@ export function defineProperty( type: mikroOrmType.integer, nullable: true, fieldName: field.fieldName, + serializer: Number, })(MikroORMEntity.prototype, field.fieldName) return } diff --git a/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts b/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts index 0aff9c6373ce3..9050bd8900922 100644 --- a/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts +++ b/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts @@ -7,7 +7,6 @@ import { } from "@medusajs/types" import { BeforeCreate, - Cascade, ManyToMany, ManyToOne, OneToMany, @@ -16,13 +15,13 @@ import { Property, rel, } from "@mikro-orm/core" +import { camelToSnakeCase, pluralize } from "../../../common" import { DmlEntity } from "../../entity" -import { HasOne } from "../../relations/has-one" import { HasMany } from "../../relations/has-many" -import { parseEntityName } from "./parse-entity-name" -import { camelToSnakeCase, pluralize } from "../../../common" -import { applyEntityIndexes } from "../mikro-orm/apply-indexes" +import { HasOne } from "../../relations/has-one" import { ManyToMany as DmlManyToMany } from "../../relations/many-to-many" +import { applyEntityIndexes } from "../mikro-orm/apply-indexes" +import { parseEntityName } from "./parse-entity-name" type Context = { MANY_TO_MANY_TRACKED_RELATIONS: Record @@ -238,7 +237,6 @@ export function defineBelongsToRelationship( relationMeta.class, this[foreignKeyName] ) - this[relationship.name] ??= this[relationship.name]?.id return } @@ -326,20 +324,6 @@ export function defineBelongsToRelationship( if (HasOne.isHasOne(otherSideRelation)) { const foreignKeyName = camelToSnakeCase(`${relationship.name}Id`) - const oneToOneOptions: Parameters[0] = { - entity: relatedModelName, - nullable: relationship.nullable, - mappedBy: mappedBy, - owner: true, - onDelete: shouldCascade ? "cascade" : undefined, - } - - if (shouldCascade) { - oneToOneOptions.cascade = [Cascade.PERSIST, "soft-remove"] as any - } - - OneToOne(oneToOneOptions)(MikroORMEntity.prototype, relationship.name) - Object.defineProperty(MikroORMEntity.prototype, foreignKeyName, { value: null, configurable: true, @@ -348,12 +332,23 @@ export function defineBelongsToRelationship( }) Property({ - type: "string", columnType: "text", + type: "string", nullable: relationship.nullable, persist: false, })(MikroORMEntity.prototype, foreignKeyName) + const oneToOneOptions: Parameters[0] = { + entity: relatedModelName, + nullable: relationship.nullable, + mappedBy: mappedBy, + fieldName: foreignKeyName, + owner: true, + onDelete: shouldCascade ? "cascade" : undefined, + } + + OneToOne(oneToOneOptions)(MikroORMEntity.prototype, relationship.name) + const { tableName } = parseEntityName(entity) applyEntityIndexes(MikroORMEntity, tableName, [ { diff --git a/packages/modules/order/integration-tests/__tests__/order-claim.ts b/packages/modules/order/integration-tests/__tests__/order-claim.ts index e3fdc96d07c15..98be3664d4779 100644 --- a/packages/modules/order/integration-tests/__tests__/order-claim.ts +++ b/packages/modules/order/integration-tests/__tests__/order-claim.ts @@ -2,7 +2,7 @@ import { CreateOrderDTO, IOrderModuleService } from "@medusajs/framework/types" import { ClaimType, Modules } from "@medusajs/framework/utils" import { SuiteOptions, moduleIntegrationTestRunner } from "@medusajs/test-utils" -jest.setTimeout(100000) +jest.setTimeout(1000000) moduleIntegrationTestRunner({ moduleName: Modules.ORDER, @@ -103,7 +103,7 @@ moduleIntegrationTestRunner({ customer_id: "joe", } as CreateOrderDTO - it("should claim an item and add two new items to the order", async function () { + it.only("should claim an item and add two new items to the order", async function () { const createdOrder = await service.createOrders(input) createdOrder.items = createdOrder.items!.sort((a, b) => a.title.localeCompare(b.title) diff --git a/packages/modules/order/package.json b/packages/modules/order/package.json index 227ac3c8f352c..5de2e5c05f5fd 100644 --- a/packages/modules/order/package.json +++ b/packages/modules/order/package.json @@ -29,7 +29,7 @@ "resolve:aliases": "tsc --showConfig -p tsconfig.json > tsconfig.resolved.json && tsc-alias -p tsconfig.resolved.json && rimraf tsconfig.resolved.json", "build": "rimraf dist && tsc --build && npm run resolve:aliases", "test": "jest --runInBand --bail --forceExit -- src/**/__tests__/**/*.ts", - "test:integration": "jest --forceExit -- integration-tests/__tests__/**/*.ts", + "test:integration": "jest --forceExit -- integration-tests/__tests__/**/order-claim.ts", "migration:initial": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm migration:create --initial", "migration:create": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm migration:create", "migration:up": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm migration:up", diff --git a/packages/modules/order/src/services/order-module-service.ts b/packages/modules/order/src/services/order-module-service.ts index 0f0aa7ec3fdc8..2bd6fd89806c2 100644 --- a/packages/modules/order/src/services/order-module-service.ts +++ b/packages/modules/order/src/services/order-module-service.ts @@ -2799,8 +2799,8 @@ export default class OrderModuleService "items.detail", "shipping_methods", ], - } - // sharedContext + }, + sharedContext // TODO: investigate issue while using sharedContext in receive return action ) orders = formatOrder(orders, { diff --git a/packages/modules/order/src/utils/base-repository-find.ts b/packages/modules/order/src/utils/base-repository-find.ts index 2c7f202178443..04985b8e37c01 100644 --- a/packages/modules/order/src/utils/base-repository-find.ts +++ b/packages/modules/order/src/utils/base-repository-find.ts @@ -29,12 +29,16 @@ export function setFindMethods(klass: Constructor, entity: any) { } } + // Object.assign(findOptions_.options, { + // strategy: LoadStrategy.SELECT_IN, + // }) + const isRelatedEntity = entity !== Order const config = mapRepositoryToOrderModel(findOptions_, isRelatedEntity) config.options ??= {} config.options.populate ??= [] - const strategy = config.options.strategy ?? LoadStrategy.JOINED + const strategy = findOptions_.options.strategy ?? LoadStrategy.JOINED let orderAlias = "o0" if (isRelatedEntity) { if (entity === OrderClaim) { From d3e21127e3c40f68c88dc68f906e5c8fc3637dd5 Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Wed, 4 Dec 2024 09:09:58 -0300 Subject: [PATCH 121/175] hasOne --- .../entity-builder/define-relationship.ts | 51 +++++++++++++++---- packages/core/utils/src/dml/relations/base.ts | 4 +- packages/modules/order/src/models/return.ts | 8 ++- .../order/src/utils/base-repository-find.ts | 4 -- 4 files changed, 51 insertions(+), 16 deletions(-) diff --git a/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts b/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts index 9050bd8900922..640d16ddbad56 100644 --- a/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts +++ b/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts @@ -140,18 +140,51 @@ export function defineHasOneRelationship( ) { const shouldRemoveRelated = !!cascades.delete?.includes(relationship.name) - const options: Parameters[0] = { - entity: relatedModelName, - nullable: relationship.nullable, - fieldName: relationship.options.fieldName, - mappedBy: relationship.mappedBy || camelToSnakeCase(MikroORMEntity.name), - } + let mappedBy: string | undefined - if (shouldRemoveRelated) { - options.cascade = ["persist", "soft-remove"] as any + if ("mappedBy" in relationship) { + mappedBy = relationship.mappedBy + } else { + mappedBy = camelToSnakeCase(MikroORMEntity.name) } - OneToOne(options)(MikroORMEntity.prototype, relationship.name) + console.log(relationship.options) + if (relationship.options.foreignKey) { + const foreignKeyName = camelToSnakeCase(`${relationship.name}Id`) + + const props = { + entity: relatedModelName, + nullable: relationship.nullable, + ...(mappedBy ? { mappedBy } : {}), + ...(relationship.options.extra ?? {}), + } as any + + if (shouldRemoveRelated) { + props.cascade = ["persist", "soft-remove"] as any + } + + OneToOne(props)(MikroORMEntity.prototype, relationship.name) + + Property({ + type: "string", + columnType: "text", + nullable: relationship.nullable, + persist: true, + })(MikroORMEntity.prototype, foreignKeyName) + } else { + const props = { + entity: relatedModelName, + nullable: relationship.nullable, + ...(mappedBy ? { mappedBy } : {}), + ...(relationship.options.extra ?? {}), + } as any + + if (shouldRemoveRelated) { + props.cascade = ["persist", "soft-remove"] as any + } + + OneToOne(props)(MikroORMEntity.prototype, relationship.name) + } } /** diff --git a/packages/core/utils/src/dml/relations/base.ts b/packages/core/utils/src/dml/relations/base.ts index bc1c109e0a06a..6b8f31c8231d6 100644 --- a/packages/core/utils/src/dml/relations/base.ts +++ b/packages/core/utils/src/dml/relations/base.ts @@ -79,11 +79,13 @@ export abstract class BaseRelationship implements RelationshipType { return { name: relationshipName, nullable: false, - mappedBy: this.options.mappedBy, options: this.options, searchable: this.#searchable, entity: this.#referencedEntity, type: this.type, + ...("mappedBy" in this.options + ? { mappedBy: this.options.mappedBy } + : {}), } } } diff --git a/packages/modules/order/src/models/return.ts b/packages/modules/order/src/models/return.ts index 66530c583f90a..02913c51093b4 100644 --- a/packages/modules/order/src/models/return.ts +++ b/packages/modules/order/src/models/return.ts @@ -9,8 +9,8 @@ import { OrderTransaction } from "./transaction" const _Return = model .define("Return", { id: model.id({ prefix: "return" }).primaryKey(), - exchange_id: model.text().nullable(), - claim_id: model.text().nullable(), + //exchange_id: model.text().nullable(), + //claim_id: model.text().nullable(), order_version: model.number(), display_id: model.autoincrement(), status: model.enum(ReturnStatus).default(ReturnStatus.OPEN), @@ -28,11 +28,13 @@ const _Return = model exchange: model .hasOne<() => typeof OrderExchange>(() => OrderExchange, { mappedBy: "return", + foreignKey: true, }) .nullable(), claim: model .hasOne<() => typeof OrderClaim>(() => OrderClaim, { mappedBy: "return", + foreignKey: true, }) .nullable(), items: model.hasMany<() => typeof ReturnItem>(() => ReturnItem, { @@ -75,12 +77,14 @@ const _Return = model }, { name: "IDX_return_exchange_id", + // @ts-ignore on: ["exchange_id"], unique: false, where: "exchange_id IS NOT NULL AND deleted_at IS NOT NULL", }, { name: "IDX_return_claim_id", + // @ts-ignore on: ["claim_id"], unique: false, where: "claim_id IS NOT NULL AND deleted_at IS NOT NULL", diff --git a/packages/modules/order/src/utils/base-repository-find.ts b/packages/modules/order/src/utils/base-repository-find.ts index 04985b8e37c01..f3f72fca6ccf1 100644 --- a/packages/modules/order/src/utils/base-repository-find.ts +++ b/packages/modules/order/src/utils/base-repository-find.ts @@ -29,10 +29,6 @@ export function setFindMethods(klass: Constructor, entity: any) { } } - // Object.assign(findOptions_.options, { - // strategy: LoadStrategy.SELECT_IN, - // }) - const isRelatedEntity = entity !== Order const config = mapRepositoryToOrderModel(findOptions_, isRelatedEntity) config.options ??= {} From 96b20ae36945327945b9b1e38a56a115971abbc9 Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Wed, 4 Dec 2024 13:51:10 -0300 Subject: [PATCH 122/175] models --- .../helpers/entity-builder/define-relationship.ts | 6 ++---- packages/modules/order/src/models/order-item.ts | 6 ++++-- .../order/src/models/order-shipping-method.ts | 13 +++++++------ packages/modules/order/src/models/order.ts | 4 ++++ .../order/src/services/order-module-service.ts | 5 +++-- 5 files changed, 20 insertions(+), 14 deletions(-) diff --git a/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts b/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts index 640d16ddbad56..450eb0e2a848e 100644 --- a/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts +++ b/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts @@ -148,13 +148,12 @@ export function defineHasOneRelationship( mappedBy = camelToSnakeCase(MikroORMEntity.name) } - console.log(relationship.options) if (relationship.options.foreignKey) { const foreignKeyName = camelToSnakeCase(`${relationship.name}Id`) const props = { entity: relatedModelName, - nullable: relationship.nullable, + nullable: true, ...(mappedBy ? { mappedBy } : {}), ...(relationship.options.extra ?? {}), } as any @@ -168,13 +167,12 @@ export function defineHasOneRelationship( Property({ type: "string", columnType: "text", - nullable: relationship.nullable, + nullable: !!relationship.nullable, persist: true, })(MikroORMEntity.prototype, foreignKeyName) } else { const props = { entity: relatedModelName, - nullable: relationship.nullable, ...(mappedBy ? { mappedBy } : {}), ...(relationship.options.extra ?? {}), } as any diff --git a/packages/modules/order/src/models/order-item.ts b/packages/modules/order/src/models/order-item.ts index 5417f56cb5aca..a3b4b9b4e0424 100644 --- a/packages/modules/order/src/models/order-item.ts +++ b/packages/modules/order/src/models/order-item.ts @@ -26,8 +26,9 @@ const _OrderItem = model order: model.belongsTo<() => typeof Order>(() => Order, { mappedBy: "items", }), - item: model.belongsTo<() => typeof OrderLineItem>(() => OrderLineItem, { - mappedBy: "items", + item: model.hasOne<() => typeof OrderLineItem>(() => OrderLineItem, { + mappedBy: undefined, + foreignKey: true, }), } ) @@ -46,6 +47,7 @@ const _OrderItem = model }, { name: "IDX_order_item_item_id", + // @ts-expect-error on: ["item_id"], unique: false, where: "deleted_at IS NOT NULL", diff --git a/packages/modules/order/src/models/order-shipping-method.ts b/packages/modules/order/src/models/order-shipping-method.ts index f05d8b754cc61..b818eb8b508a3 100644 --- a/packages/modules/order/src/models/order-shipping-method.ts +++ b/packages/modules/order/src/models/order-shipping-method.ts @@ -32,12 +32,12 @@ const _OrderShipping = model mappedBy: "shipping_methods", }) .nullable(), - shipping_method: model.belongsTo<() => typeof OrderShippingMethod>( - () => OrderShippingMethod, - { - mappedBy: "shipping_methods", - } - ), + shipping_method: model + .hasOne<() => typeof OrderShippingMethod>(() => OrderShippingMethod, { + mappedBy: undefined, + foreignKey: true, + }) + .nullable(), } ) .indexes([ @@ -73,6 +73,7 @@ const _OrderShipping = model }, { name: "IDX_order_shipping_shipping_method_id", + // @ts-ignore on: ["shipping_method_id"], unique: false, where: "deleted_at IS NOT NULL", diff --git a/packages/modules/order/src/models/order.ts b/packages/modules/order/src/models/order.ts index a7f2d91805322..6523b66778d04 100644 --- a/packages/modules/order/src/models/order.ts +++ b/packages/modules/order/src/models/order.ts @@ -21,6 +21,7 @@ import { OrderAddress } from "./address" import { OrderItem } from "./order-item" import { OrderShipping } from "./order-shipping-method" import { OrderSummary } from "./order-summary" +import { Return } from "./return" import { OrderTransaction } from "./transaction" type OrderSchema = { @@ -71,6 +72,9 @@ const _Order = model no_notification: model.boolean().nullable(), metadata: model.json().nullable(), canceled_at: model.dateTime().nullable(), + returns: model.hasMany(() => Return, { + mappedBy: "order", + }), shipping_address: model .belongsTo(() => OrderAddress, { mappedBy: "shipping_address_order", diff --git a/packages/modules/order/src/services/order-module-service.ts b/packages/modules/order/src/services/order-module-service.ts index a0da2647104e3..77c9934065635 100644 --- a/packages/modules/order/src/services/order-module-service.ts +++ b/packages/modules/order/src/services/order-module-service.ts @@ -2047,6 +2047,7 @@ export default class OrderModuleService const actions = item.actions delete item.actions + //@ts-ignore const newItem = itemsToUpsert.find((d) => d.item_id === item.id)! const unitPrice = newItem?.unit_price ?? item.unit_price const compareAtUnitPrice = @@ -2299,9 +2300,9 @@ export default class OrderModuleService applied: true, }, ], - })) as CreateOrderChangeDTO[], + })), sharedContext - )) as OrderTypes.OrderChangeDTO[] + )) as unknown as OrderTypes.OrderChangeDTO[] return Array.isArray(data) ? changes : changes[0] } From e1311f0b2e0427d1a71196d7dc98d95392b290a8 Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Tue, 10 Dec 2024 08:50:04 -0300 Subject: [PATCH 123/175] fix --- packages/core/utils/src/dml/__tests__/entity-builder.spec.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts b/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts index ac47aedca2963..f5d35da0eaef9 100644 --- a/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts +++ b/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts @@ -3614,7 +3614,6 @@ describe("Entity builder", () => { name: "user", nullable: false, onDelete: "cascade", - cascade: ["persist", "soft-remove"], owner: true, reference: "1:1", cascade: ["persist", "soft-remove"], From f0c3f92af4c0cc2c979035c821216f4507c9c94e Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Wed, 11 Dec 2024 08:35:28 -0300 Subject: [PATCH 124/175] model --- .../helpers/entity-builder/define-relationship.ts | 2 +- packages/modules/order/src/models/order-item.ts | 14 +++++++++----- .../order/src/models/order-shipping-method.ts | 3 +++ packages/modules/order/src/models/order.ts | 6 ++++-- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts b/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts index 6a7c7e498eb19..312bb36cd0836 100644 --- a/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts +++ b/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts @@ -152,10 +152,10 @@ export function defineHasOneRelationship( entity: relatedModelName, nullable: relationship.nullable, ...(mappedBy ? { mappedBy } : {}), - onDelete: shouldRemoveRelated ? "cascade" : undefined, } as OneToOneOptions if (shouldRemoveRelated) { + oneToOneOptions.onDelete = shouldRemoveRelated ? "cascade" : undefined oneToOneOptions.cascade = ["persist", "soft-remove"] as any } diff --git a/packages/modules/order/src/models/order-item.ts b/packages/modules/order/src/models/order-item.ts index a3b4b9b4e0424..0a29a6f292c5a 100644 --- a/packages/modules/order/src/models/order-item.ts +++ b/packages/modules/order/src/models/order-item.ts @@ -26,12 +26,17 @@ const _OrderItem = model order: model.belongsTo<() => typeof Order>(() => Order, { mappedBy: "items", }), - item: model.hasOne<() => typeof OrderLineItem>(() => OrderLineItem, { - mappedBy: undefined, - foreignKey: true, - }), + item: model + .hasOne<() => typeof OrderLineItem>(() => OrderLineItem, { + mappedBy: undefined, + foreignKey: true, + }) + .nullable(), } ) + .cascades({ + delete: ["item"], + }) .indexes([ { name: "IDX_order_item_order_id", @@ -47,7 +52,6 @@ const _OrderItem = model }, { name: "IDX_order_item_item_id", - // @ts-expect-error on: ["item_id"], unique: false, where: "deleted_at IS NOT NULL", diff --git a/packages/modules/order/src/models/order-shipping-method.ts b/packages/modules/order/src/models/order-shipping-method.ts index b818eb8b508a3..1ce408f7a9bd1 100644 --- a/packages/modules/order/src/models/order-shipping-method.ts +++ b/packages/modules/order/src/models/order-shipping-method.ts @@ -40,6 +40,9 @@ const _OrderShipping = model .nullable(), } ) + .cascades({ + delete: ["shipping_method"], + }) .indexes([ { name: "IDX_order_shipping_order_id", diff --git a/packages/modules/order/src/models/order.ts b/packages/modules/order/src/models/order.ts index 6523b66778d04..f379b0e07cf5a 100644 --- a/packages/modules/order/src/models/order.ts +++ b/packages/modules/order/src/models/order.ts @@ -40,11 +40,13 @@ type OrderSchema = { canceled_at: NullableModifier shipping_address: RelationNullableModifier< typeof OrderAddress, - BelongsTo + BelongsTo, + boolean > billing_address: RelationNullableModifier< typeof OrderAddress, - BelongsTo + BelongsTo, + boolean > summary: HasMany items: HasMany From a79d1486cfa96ad270cdb1abcf75e18acdb8d76c Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Mon, 16 Dec 2024 14:29:38 -0300 Subject: [PATCH 125/175] initial commit --- integration-tests/package.json | 8 +- packages/cli/medusa-cli/package.json | 16 +- packages/core/core-flows/package.json | 8 +- packages/core/framework/package.json | 18 +- .../core/framework/src/mikro-orm-cli/bin.ts | 8 +- packages/core/modules-sdk/package.json | 16 +- packages/core/orchestration/package.json | 16 +- packages/core/utils/package.json | 16 +- .../src/dal/mikro-orm/__fixtures__/utils.ts | 4 +- .../mikro-orm/__tests__/base-entity.spec.ts | 45 +- .../__tests__/big-number-field.spec.ts | 12 +- .../mikro-orm-free-text-search-filter.spec.ts | 12 +- .../__tests__/mikro-orm-serializer.spec.ts | 26 +- .../__tests__/ts-migration-generator.spec.ts | 2 +- .../src/dal/mikro-orm/big-number-field.ts | 3 +- .../__tests__/mikro-orm-repository.spec.ts | 20 +- .../integration-tests/__tests__/utils.spec.ts | 39 +- .../mikro-orm/mikro-orm-create-connection.ts | 64 +- .../mikro-orm-free-text-search-filter.ts | 4 +- .../src/dal/mikro-orm/mikro-orm-repository.ts | 22 +- .../src/dal/mikro-orm/mikro-orm-serializer.ts | 102 +- .../src/dml/__tests__/entity-builder.spec.ts | 988 +++++++++--------- .../entity-builder/define-relationship.ts | 41 +- .../__tests__/entity.spec.ts | 38 +- .../integration-tests/__tests__/enum.spec.ts | 38 +- .../__tests__/has-one-belongs-to.spec.ts | 38 +- .../__tests__/many-to-many.spec.ts | 38 +- .../__tests__/many-to-one.spec.ts | 45 +- packages/core/utils/src/migrations/index.ts | 18 +- .../mikro-orm-cli-config-builder.spec.ts | 4 +- .../modules-sdk/medusa-internal-service.ts | 2 +- .../mikro-orm-cli-config-builder.ts | 9 +- packages/core/workflows-sdk/package.json | 16 +- packages/medusa-test-utils/package.json | 10 +- packages/medusa-test-utils/src/database.ts | 12 +- packages/medusa/package.json | 8 +- packages/modules/api-key/package.json | 8 +- packages/modules/auth/package.json | 14 +- packages/modules/cart/package.json | 14 +- packages/modules/currency/package.json | 14 +- packages/modules/customer/package.json | 14 +- packages/modules/file/package.json | 8 +- packages/modules/fulfillment/package.json | 14 +- .../src/models/fulfillment-item.ts | 2 +- .../src/models/fulfillment-label.ts | 2 +- .../fulfillment/src/models/fulfillment.ts | 6 +- .../fulfillment/src/models/geo-zone.ts | 2 +- .../fulfillment/src/models/service-zone.ts | 2 +- .../src/models/shipping-option-rule.ts | 2 +- .../src/models/shipping-option-type.ts | 2 +- .../fulfillment/src/models/shipping-option.ts | 6 +- packages/modules/index/package.json | 18 +- packages/modules/inventory/package.json | 14 +- packages/modules/link-modules/package.json | 12 +- packages/modules/locking/package.json | 14 +- packages/modules/notification/package.json | 14 +- packages/modules/order/package.json | 14 +- .../modules/order/src/models/claim-item.ts | 2 +- .../modules/order/src/models/exchange-item.ts | 2 +- .../order/src/models/line-item-adjustment.ts | 2 +- .../order/src/models/order-change-action.ts | 4 +- .../modules/order/src/models/order-change.ts | 2 +- .../modules/order/src/models/order-summary.ts | 2 +- .../modules/order/src/models/return-item.ts | 2 +- .../src/models/shipping-method-adjustment.ts | 2 +- .../src/models/shipping-method-tax-line.ts | 2 +- .../modules/order/src/models/transaction.ts | 2 +- packages/modules/payment/package.json | 14 +- packages/modules/pricing/package.json | 14 +- .../integration-tests/__tests__/product.ts | 20 +- packages/modules/product/package.json | 16 +- .../modules/product/src/models/product.ts | 8 +- .../src/repositories/product-category.ts | 5 +- packages/modules/promotion/package.json | 16 +- .../providers/locking-postgres/package.json | 8 +- packages/modules/region/package.json | 14 +- packages/modules/sales-channel/package.json | 14 +- packages/modules/stock-location/package.json | 14 +- packages/modules/store/package.json | 14 +- packages/modules/tax/package.json | 14 +- packages/modules/user/package.json | 14 +- .../workflow-engine-inmemory/package.json | 14 +- .../workflow-engine-redis/package.json | 14 +- yarn.lock | 799 +++++++------- 84 files changed, 1486 insertions(+), 1510 deletions(-) diff --git a/integration-tests/package.json b/integration-tests/package.json index c64935ddc4199..d991ffa6a2907 100644 --- a/integration-tests/package.json +++ b/integration-tests/package.json @@ -21,10 +21,10 @@ "scrypt-kdf": "^2.0.1", "jsonwebtoken": "^9.0.2", "@medusajs/framework": "^1.0.1", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/knex": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/knex": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "awilix": "^8.0.1", "ioredis": "^5.4.1", "pg": "^8.13.0", diff --git a/packages/cli/medusa-cli/package.json b/packages/cli/medusa-cli/package.json index e0ec585a41756..e455a3733086b 100644 --- a/packages/cli/medusa-cli/package.json +++ b/packages/cli/medusa-cli/package.json @@ -32,10 +32,10 @@ "author": "Sebastian Rindom", "license": "MIT", "devDependencies": { - "@mikro-orm/core": "5.9.7", - "@mikro-orm/knex": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/knex": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "@types/yargs": "^15.0.15", @@ -72,10 +72,10 @@ "yargs": "^15.3.1" }, "peerDependencies": { - "@mikro-orm/core": "5.9.7", - "@mikro-orm/knex": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/knex": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "awilix": "^8.0.1", "pg": "^8.13.0" }, diff --git a/packages/core/core-flows/package.json b/packages/core/core-flows/package.json index 01620d58dd287..0033ef5604381 100644 --- a/packages/core/core-flows/package.json +++ b/packages/core/core-flows/package.json @@ -27,10 +27,10 @@ "license": "MIT", "devDependencies": { "@medusajs/framework": "^2.1.1", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/knex": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/knex": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "awilix": "^8.0.1", diff --git a/packages/core/framework/package.json b/packages/core/framework/package.json index e8d8aa127209c..96a14001a0c47 100644 --- a/packages/core/framework/package.json +++ b/packages/core/framework/package.json @@ -53,10 +53,10 @@ }, "devDependencies": { "@medusajs/cli": "^2.1.1", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/knex": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/knex": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "@types/cors": "^2.8.17", @@ -92,11 +92,11 @@ }, "peerDependencies": { "@medusajs/cli": "^2.0.0", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/knex": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/knex": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "awilix": "^8.0.1", "ioredis": "^5.4.1", "pg": "^8.13.0", diff --git a/packages/core/framework/src/mikro-orm-cli/bin.ts b/packages/core/framework/src/mikro-orm-cli/bin.ts index f131f28d6547c..4ca967e9e4760 100644 --- a/packages/core/framework/src/mikro-orm-cli/bin.ts +++ b/packages/core/framework/src/mikro-orm-cli/bin.ts @@ -11,17 +11,15 @@ * small, we should be okay with managing this wrapper. */ -import { isAbsolute, join } from "path" -import { ConfigurationLoader } from "@mikro-orm/core" import { CLIConfigurator, CLIHelper } from "@mikro-orm/cli" +import { ConfigurationLoader } from "@mikro-orm/core" +import { isAbsolute, join } from "path" /** * Monkey patching the TSNode registration of Mikro ORM to not use * hardcoded module system with TypeScript. */ -ConfigurationLoader.registerTsNode = async function ( - configPath = "tsconfig.json" -) { +ConfigurationLoader.registerTsNode = function (configPath = "tsconfig.json") { const tsConfigPath = isAbsolute(configPath) ? configPath : join(process.cwd(), configPath) diff --git a/packages/core/modules-sdk/package.json b/packages/core/modules-sdk/package.json index 24245c67df01d..93addab472171 100644 --- a/packages/core/modules-sdk/package.json +++ b/packages/core/modules-sdk/package.json @@ -31,10 +31,10 @@ "watch": "tsc --build --watch" }, "devDependencies": { - "@mikro-orm/core": "5.9.7", - "@mikro-orm/knex": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/knex": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "awilix": "^8.0.1", @@ -50,10 +50,10 @@ "@medusajs/utils": "^2.1.1" }, "peerDependencies": { - "@mikro-orm/core": "5.9.7", - "@mikro-orm/knex": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/knex": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "awilix": "^8.0.1", "express": "^4.21.0", "pg": "^8.13.0" diff --git a/packages/core/orchestration/package.json b/packages/core/orchestration/package.json index 0bc8f6bd52b51..448456b1469d6 100644 --- a/packages/core/orchestration/package.json +++ b/packages/core/orchestration/package.json @@ -26,10 +26,10 @@ "author": "Medusa", "license": "MIT", "devDependencies": { - "@mikro-orm/core": "5.9.7", - "@mikro-orm/knex": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/knex": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "awilix": "^8.0.1", @@ -43,10 +43,10 @@ "@medusajs/utils": "^2.1.1" }, "peerDependencies": { - "@mikro-orm/core": "5.9.7", - "@mikro-orm/knex": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/knex": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "awilix": "^8.0.1", "express": "^4.21.0", "pg": "^8.13.0" diff --git a/packages/core/utils/package.json b/packages/core/utils/package.json index afb078667fa2f..8a6c2796ff9ee 100644 --- a/packages/core/utils/package.json +++ b/packages/core/utils/package.json @@ -26,10 +26,10 @@ "author": "Medusa", "license": "MIT", "devDependencies": { - "@mikro-orm/core": "5.9.7", - "@mikro-orm/knex": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/knex": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "@types/express": "^4.17.21", @@ -59,10 +59,10 @@ "ulid": "^2.3.0" }, "peerDependencies": { - "@mikro-orm/core": "5.9.7", - "@mikro-orm/knex": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/knex": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "awilix": "^8.0.1", "express": "^4.21.0", "pg": "^8.13.0" diff --git a/packages/core/utils/src/dal/mikro-orm/__fixtures__/utils.ts b/packages/core/utils/src/dal/mikro-orm/__fixtures__/utils.ts index d3dec6ef446e0..4b8a839484a59 100644 --- a/packages/core/utils/src/dal/mikro-orm/__fixtures__/utils.ts +++ b/packages/core/utils/src/dal/mikro-orm/__fixtures__/utils.ts @@ -63,7 +63,7 @@ class ProductOptionValue { fieldName: "option_id", mapToPk: true, nullable: true, - onDelete: "cascade", + deleteRule: "cascade", }) option_id: string | null @@ -88,7 +88,7 @@ class ProductVariant { @ManyToOne(() => Product, { columnType: "text", nullable: true, - onDelete: "cascade", + deleteRule: "cascade", fieldName: "product_id", mapToPk: true, }) diff --git a/packages/core/utils/src/dal/mikro-orm/__tests__/base-entity.spec.ts b/packages/core/utils/src/dal/mikro-orm/__tests__/base-entity.spec.ts index 09afa1b181ed0..05e1845be0876 100644 --- a/packages/core/utils/src/dal/mikro-orm/__tests__/base-entity.spec.ts +++ b/packages/core/utils/src/dal/mikro-orm/__tests__/base-entity.spec.ts @@ -1,4 +1,5 @@ import { Entity, MikroORM, OnInit, Property } from "@mikro-orm/core" +import { defineConfig } from "@mikro-orm/postgresql" import { BaseEntity } from "../base-entity" describe("BaseEntity", () => { @@ -10,11 +11,12 @@ describe("BaseEntity", () => { } } - const orm = await MikroORM.init({ - entities: [Entity1], - dbName: "test", - type: "postgresql", - }) + const orm = await MikroORM.init( + defineConfig({ + entities: [Entity1], + dbName: "test", + }) + ) const manager = orm.em.fork() const entity1 = manager.create(Entity1, {}) @@ -28,11 +30,12 @@ describe("BaseEntity", () => { @Entity() class Entity1 extends BaseEntity {} - const orm = await MikroORM.init({ - entities: [Entity1], - dbName: "test", - type: "postgresql", - }) + const orm = await MikroORM.init( + defineConfig({ + entities: [Entity1], + dbName: "test", + }) + ) const manager = orm.em.fork() const entity1 = manager.create(Entity1, {}) @@ -52,11 +55,12 @@ describe("BaseEntity", () => { @Entity() class ProductOptionValue extends BaseEntity {} - const orm = await MikroORM.init({ - entities: [ProductModel, ProductCategoryEntity, ProductOptionValue], - dbName: "test", - type: "postgresql", - }) + const orm = await MikroORM.init( + defineConfig({ + entities: [ProductModel, ProductCategoryEntity, ProductOptionValue], + dbName: "test", + }) + ) const manager = orm.em.fork() @@ -105,11 +109,12 @@ describe("BaseEntity", () => { } } - const orm = await MikroORM.init({ - entities: [ProductModel, ProductCategoryEntity, ProductOptionValue], - dbName: "test", - type: "postgresql", - }) + const orm = await MikroORM.init( + defineConfig({ + entities: [ProductModel, ProductCategoryEntity, ProductOptionValue], + dbName: "test", + }) + ) const manager = orm.em.fork() diff --git a/packages/core/utils/src/dal/mikro-orm/__tests__/big-number-field.spec.ts b/packages/core/utils/src/dal/mikro-orm/__tests__/big-number-field.spec.ts index 367ac15dff78a..bb974588bb944 100644 --- a/packages/core/utils/src/dal/mikro-orm/__tests__/big-number-field.spec.ts +++ b/packages/core/utils/src/dal/mikro-orm/__tests__/big-number-field.spec.ts @@ -1,5 +1,6 @@ import { BigNumberRawValue } from "@medusajs/types" import { Entity, MikroORM, PrimaryKey } from "@mikro-orm/core" +import { defineConfig } from "@mikro-orm/postgresql" import { BigNumber } from "../../../totals/big-number" import { MikroOrmBigNumberProperty } from "../big-number-field" @@ -23,11 +24,12 @@ describe("@MikroOrmBigNumberProperty", () => { let orm!: MikroORM beforeEach(async () => { - orm = await MikroORM.init({ - entities: [TestAmount], - dbName: "test", - type: "postgresql", - }) + orm = await MikroORM.init( + defineConfig({ + entities: [TestAmount], + dbName: "test", + }) + ) }) afterEach(async () => { diff --git a/packages/core/utils/src/dal/mikro-orm/__tests__/mikro-orm-free-text-search-filter.spec.ts b/packages/core/utils/src/dal/mikro-orm/__tests__/mikro-orm-free-text-search-filter.spec.ts index d932d5cb7f22c..3760644de89fd 100644 --- a/packages/core/utils/src/dal/mikro-orm/__tests__/mikro-orm-free-text-search-filter.spec.ts +++ b/packages/core/utils/src/dal/mikro-orm/__tests__/mikro-orm-free-text-search-filter.spec.ts @@ -1,4 +1,5 @@ import { MikroORM } from "@mikro-orm/core" +import { defineConfig } from "@mikro-orm/postgresql" import { SearchableEntity1, SearchableEntity2 } from "../__fixtures__/utils" import { mikroOrmFreeTextSearchFilterOptionsFactory } from "../mikro-orm-free-text-search-filter" @@ -6,11 +7,12 @@ describe("mikroOrmFreeTextSearchFilterOptionsFactory", () => { let orm beforeEach(async () => { - orm = await MikroORM.init({ - entities: [SearchableEntity1, SearchableEntity2], - dbName: "test", - type: "postgresql", - }) + orm = await MikroORM.init( + defineConfig({ + entities: [SearchableEntity1, SearchableEntity2], + dbName: "test", + }) + ) }) it("should return a filter function that filters entities based on the free text search value", async () => { diff --git a/packages/core/utils/src/dal/mikro-orm/__tests__/mikro-orm-serializer.spec.ts b/packages/core/utils/src/dal/mikro-orm/__tests__/mikro-orm-serializer.spec.ts index dbeccea8fd449..26039d0c95988 100644 --- a/packages/core/utils/src/dal/mikro-orm/__tests__/mikro-orm-serializer.spec.ts +++ b/packages/core/utils/src/dal/mikro-orm/__tests__/mikro-orm-serializer.spec.ts @@ -1,4 +1,5 @@ import { MikroORM } from "@mikro-orm/core" +import { defineConfig } from "@mikro-orm/postgresql" import { Entity1WithUnDecoratedProp, Entity2WithUnDecoratedProp, @@ -11,18 +12,19 @@ import { mikroOrmSerializer } from "../mikro-orm-serializer" describe("mikroOrmSerializer", () => { beforeEach(async () => { - await MikroORM.init({ - entities: [ - Entity1WithUnDecoratedProp, - Entity2WithUnDecoratedProp, - Product, - ProductOption, - ProductOptionValue, - ProductVariant, - ], - dbName: "test", - type: "postgresql", - }) + await MikroORM.init( + defineConfig({ + entities: [ + Entity1WithUnDecoratedProp, + Entity2WithUnDecoratedProp, + Product, + ProductOption, + ProductOptionValue, + ProductVariant, + ], + dbName: "test", + }) + ) }) it("should serialize an entity", async () => { diff --git a/packages/core/utils/src/dal/mikro-orm/__tests__/ts-migration-generator.spec.ts b/packages/core/utils/src/dal/mikro-orm/__tests__/ts-migration-generator.spec.ts index 71d7b4de21221..1df54e6571889 100644 --- a/packages/core/utils/src/dal/mikro-orm/__tests__/ts-migration-generator.spec.ts +++ b/packages/core/utils/src/dal/mikro-orm/__tests__/ts-migration-generator.spec.ts @@ -4,7 +4,7 @@ function unwrapSql(sql: string) { return sql.match(/this.addSql\('(.*?)'\)/)?.[1] } -describe("CustomTsMigrationGenerator", () => { +describe.skip("CustomTsMigrationGenerator", () => { it('should add "if not exists" to "create table" statements', () => { const sql = "create table my_table (id int)" const result = unwrapSql( diff --git a/packages/core/utils/src/dal/mikro-orm/big-number-field.ts b/packages/core/utils/src/dal/mikro-orm/big-number-field.ts index 9aaa769929473..588f7ceaad9d1 100644 --- a/packages/core/utils/src/dal/mikro-orm/big-number-field.ts +++ b/packages/core/utils/src/dal/mikro-orm/big-number-field.ts @@ -77,9 +77,10 @@ export function MikroOrmBigNumberProperty( }) Property({ - type: "any", + type: "number", columnType: "numeric", trackChanges: false, + runtimeType: "number", ...options, })(target, columnName) } diff --git a/packages/core/utils/src/dal/mikro-orm/integration-tests/__tests__/mikro-orm-repository.spec.ts b/packages/core/utils/src/dal/mikro-orm/integration-tests/__tests__/mikro-orm-repository.spec.ts index 2c5f51541f739..7101872fcd7ca 100644 --- a/packages/core/utils/src/dal/mikro-orm/integration-tests/__tests__/mikro-orm-repository.spec.ts +++ b/packages/core/utils/src/dal/mikro-orm/integration-tests/__tests__/mikro-orm-repository.spec.ts @@ -1,3 +1,4 @@ +import { BigNumberRawValue } from "@medusajs/types" import { BeforeCreate, Collection, @@ -13,11 +14,11 @@ import { Unique, wrap, } from "@mikro-orm/core" -import { mikroOrmBaseRepositoryFactory } from "../../mikro-orm-repository" +import { defineConfig } from "@mikro-orm/postgresql" +import BigNumber from "bignumber.js" import { dropDatabase } from "pg-god" import { MikroOrmBigNumberProperty } from "../../big-number-field" -import BigNumber from "bignumber.js" -import { BigNumberRawValue } from "@medusajs/types" +import { mikroOrmBaseRepositoryFactory } from "../../mikro-orm-repository" import { getDatabaseURL, pgGodCredentials } from "../__fixtures__/database" const dbName = "mikroorm-integration-1" @@ -78,7 +79,7 @@ class Entity2 { nullable: true, mapToPk: true, fieldName: "entity1_id", - onDelete: "set null", + deleteRule: "set null", }) entity1_id: string @@ -143,11 +144,12 @@ describe("mikroOrmRepository", () => { pgGodCredentials ) - orm = await MikroORM.init({ - entities: [Entity1, Entity2], - clientUrl: getDatabaseURL(dbName), - type: "postgresql", - }) + orm = await MikroORM.init( + defineConfig({ + entities: [Entity1, Entity2], + clientUrl: getDatabaseURL(dbName), + }) + ) const generator = orm.getSchemaGenerator() await generator.ensureDatabase() diff --git a/packages/core/utils/src/dal/mikro-orm/integration-tests/__tests__/utils.spec.ts b/packages/core/utils/src/dal/mikro-orm/integration-tests/__tests__/utils.spec.ts index cbef2979e862b..6a492d6304e3e 100644 --- a/packages/core/utils/src/dal/mikro-orm/integration-tests/__tests__/utils.spec.ts +++ b/packages/core/utils/src/dal/mikro-orm/integration-tests/__tests__/utils.spec.ts @@ -1,6 +1,8 @@ -import { mikroOrmUpdateDeletedAtRecursively } from "../../utils" import { MikroORM } from "@mikro-orm/core" -import { SqlEntityManager } from "@mikro-orm/postgresql" +import { defineConfig, SqlEntityManager } from "@mikro-orm/postgresql" +import { dropDatabase } from "pg-god" +import { mikroOrmUpdateDeletedAtRecursively } from "../../utils" +import { getDatabaseURL, pgGodCredentials } from "../__fixtures__/database" import { DeepRecursiveEntity1, DeepRecursiveEntity2, @@ -12,8 +14,6 @@ import { RecursiveEntity1, RecursiveEntity2, } from "../__fixtures__/utils" -import { dropDatabase } from "pg-god" -import { getDatabaseURL, pgGodCredentials } from "../__fixtures__/database" const dbName = "mikroorm-utils-integration-1" @@ -38,21 +38,22 @@ describe("mikroOrmUpdateDeletedAtRecursively", () => { pgGodCredentials ) - orm = await MikroORM.init({ - entities: [ - Entity1, - Entity2, - RecursiveEntity1, - RecursiveEntity2, - DeepRecursiveEntity1, - DeepRecursiveEntity2, - DeepRecursiveEntity3, - DeepRecursiveEntity4, - InternalCircularDependencyEntity1, - ], - clientUrl: getDatabaseURL(dbName), - type: "postgresql", - }) + orm = await MikroORM.init( + defineConfig({ + entities: [ + Entity1, + Entity2, + RecursiveEntity1, + RecursiveEntity2, + DeepRecursiveEntity1, + DeepRecursiveEntity2, + DeepRecursiveEntity3, + DeepRecursiveEntity4, + InternalCircularDependencyEntity1, + ], + clientUrl: getDatabaseURL(dbName), + }) + ) const generator = orm.getSchemaGenerator() await generator.ensureDatabase() diff --git a/packages/core/utils/src/dal/mikro-orm/mikro-orm-create-connection.ts b/packages/core/utils/src/dal/mikro-orm/mikro-orm-create-connection.ts index 6630af8ad437e..aba4d1a84df44 100644 --- a/packages/core/utils/src/dal/mikro-orm/mikro-orm-create-connection.ts +++ b/packages/core/utils/src/dal/mikro-orm/mikro-orm-create-connection.ts @@ -45,34 +45,38 @@ export async function mikroOrmCreateConnection( schema = database.connection.context?.client?.config?.searchPath } - const { MikroORM } = await import("@mikro-orm/postgresql") - return await MikroORM.init({ - discovery: { disableDynamicFileAccess: true, warnWhenNoEntities: false }, - entities, - debug: database.debug ?? process.env.NODE_ENV?.startsWith("dev") ?? false, - baseDir: process.cwd(), - clientUrl, - schema, - driverOptions, - tsNode: process.env.APP_ENV === "development", - type: "postgresql", - filters: database.filters ?? {}, - migrations: { - disableForeignKeys: false, - path: pathToMigrations, - generator: CustomTsMigrationGenerator, - silent: !( - database.debug ?? - process.env.NODE_ENV?.startsWith("dev") ?? - false - ), - }, - schemaGenerator: { - disableForeignKeys: false, - }, - pool: { - min: 2, - ...database.pool, - }, - }) + const { MikroORM, defineConfig } = await import("@mikro-orm/postgresql") + return await MikroORM.init( + defineConfig({ + discovery: { disableDynamicFileAccess: true, warnWhenNoEntities: false }, + entities, + debug: database.debug ?? process.env.NODE_ENV?.startsWith("dev") ?? false, + baseDir: process.cwd(), + clientUrl, + schema, + driverOptions, + tsNode: process.env.APP_ENV === "development", + filters: database.filters ?? {}, + assign: { + convertCustomTypes: true, + }, + migrations: { + disableForeignKeys: false, + path: pathToMigrations, + generator: CustomTsMigrationGenerator, + silent: !( + database.debug ?? + process.env.NODE_ENV?.startsWith("dev") ?? + false + ), + }, + schemaGenerator: { + disableForeignKeys: false, + }, + pool: { + min: 2, + ...database.pool, + }, + }) + ) } diff --git a/packages/core/utils/src/dal/mikro-orm/mikro-orm-free-text-search-filter.ts b/packages/core/utils/src/dal/mikro-orm/mikro-orm-free-text-search-filter.ts index 4b50830b067ad..5679fbb5b9138 100644 --- a/packages/core/utils/src/dal/mikro-orm/mikro-orm-free-text-search-filter.ts +++ b/packages/core/utils/src/dal/mikro-orm/mikro-orm-free-text-search-filter.ts @@ -4,7 +4,7 @@ import type { FindOneOptions, FindOptions, } from "@mikro-orm/core" -import { EntityMetadata, EntitySchema, ReferenceType } from "@mikro-orm/core" +import { EntityMetadata, EntitySchema, ReferenceKind } from "@mikro-orm/core" import { SqlEntityManager } from "@mikro-orm/postgresql" export const FreeTextSearchFilterKey = "freeTextSearch" @@ -52,7 +52,7 @@ function retrieveRelationsConstraints( for (const propertyConfiguration of Object.values(relationProperties)) { if ( !(propertyConfiguration as any).searchable || - propertyConfiguration.reference !== ReferenceType.SCALAR + propertyConfiguration.kind !== ReferenceKind.SCALAR ) { continue } diff --git a/packages/core/utils/src/dal/mikro-orm/mikro-orm-repository.ts b/packages/core/utils/src/dal/mikro-orm/mikro-orm-repository.ts index c4281adfe9822..0115948f16958 100644 --- a/packages/core/utils/src/dal/mikro-orm/mikro-orm-repository.ts +++ b/packages/core/utils/src/dal/mikro-orm/mikro-orm-repository.ts @@ -20,7 +20,7 @@ import { LoadStrategy, FilterQuery as MikroFilterQuery, FindOptions as MikroOptions, - ReferenceType, + ReferenceKind, } from "@mikro-orm/core" import { SqlEntityManager } from "@mikro-orm/postgresql" import { @@ -246,6 +246,7 @@ export class MikroOrmBaseRepository return [entities, softDeletedEntitiesMap] } + /* applyFreeTextSearchFilters( findOptions: DAL.FindOptions, retrieveConstraintsToApply: (q: string) => any[] @@ -263,6 +264,7 @@ export class MikroOrmBaseRepository $and: [findOptions.where, { $or: retrieveConstraintsToApply(q) }], } as unknown as DAL.FindOptions["where"] } + */ } export class MikroOrmBaseTreeRepository< @@ -391,7 +393,7 @@ export function mikroOrmBaseRepositoryFactory( const relation = relations.find((relation) => relation.name === key) const shouldInit = relation && - relation.reference === ReferenceType.MANY_TO_MANY && + relation.kind === ReferenceKind.MANY_TO_MANY && Array.isArray(update[key]) && !update[key].length @@ -578,7 +580,7 @@ export function mikroOrmBaseRepositoryFactory( const existingEntity = existingEntitiesMap.get(key) if (existingEntity) { const updatedType = manager.assign(existingEntity, data_) - updatedEntities.push(updatedType) + updatedEntities.push(updatedType as any) } else { const newEntity = manager.create(this.entity, data_) createdEntities.push(newEntity as InferRepositoryReturnType) @@ -698,8 +700,8 @@ export function mikroOrmBaseRepositoryFactory( // TODO: Handle ONE_TO_ONE // One to one and Many to one are handled outside of the assignment as they need to happen before the main entity is created if ( - relation.reference === ReferenceType.ONE_TO_ONE || - relation.reference === ReferenceType.MANY_TO_ONE + relation.kind === ReferenceKind.ONE_TO_ONE || + relation.kind === ReferenceKind.MANY_TO_ONE ) { return } @@ -765,7 +767,7 @@ export function mikroOrmBaseRepositoryFactory( return this.getEntityWithId(manager, relation.type, normalizedItem) }) - if (relation.reference === ReferenceType.MANY_TO_MANY) { + if (relation.kind === ReferenceKind.MANY_TO_MANY) { const currentPivotColumn = relation.inverseJoinColumns[0] const parentPivotColumn = relation.joinColumns[0] @@ -805,7 +807,7 @@ export function mikroOrmBaseRepositoryFactory( return { entities: normalizedData, performedActions } } - if (relation.reference === ReferenceType.ONE_TO_MANY) { + if (relation.kind === ReferenceKind.ONE_TO_MANY) { const joinColumns = relation.targetMeta?.properties[relation.mappedBy]?.joinColumns @@ -815,7 +817,7 @@ export function mikroOrmBaseRepositoryFactory( joinColumnsConstraints[joinColumn] = data[referencedColumnName] }) - const toDeleteEntities = await manager.find( + const toDeleteEntities = await manager.find( relation.type, { ...joinColumnsConstraints, @@ -869,7 +871,7 @@ export function mikroOrmBaseRepositoryFactory( } // If it is a many-to-one we ensure the ID is set for when we want to set/unset an association - if (relation.reference === ReferenceType.MANY_TO_ONE) { + if (relation.kind === ReferenceKind.MANY_TO_ONE) { if (originalData === null) { entryCopy[relation.joinColumns[0]] = null return null @@ -927,7 +929,7 @@ export function mikroOrmBaseRepositoryFactory( .filter( ([_, propDef]: any) => propDef.persist === false && - propDef.reference === ReferenceType.MANY_TO_ONE + propDef.kind === ReferenceKind.MANY_TO_ONE ) .forEach(([key]) => { delete resp[key] diff --git a/packages/core/utils/src/dal/mikro-orm/mikro-orm-serializer.ts b/packages/core/utils/src/dal/mikro-orm/mikro-orm-serializer.ts index d0a8dce80c302..c8c758a910271 100644 --- a/packages/core/utils/src/dal/mikro-orm/mikro-orm-serializer.ts +++ b/packages/core/utils/src/dal/mikro-orm/mikro-orm-serializer.ts @@ -7,36 +7,45 @@ import { Loaded, Platform, Reference, - ReferenceType, + ReferenceKind, SerializationContext, SerializeOptions, Utils, } from "@mikro-orm/core" +type CustomSerializeOptions = SerializeOptions & { + preventCircularRef?: boolean + populate?: [keyof T][] | boolean +} + function isVisible( meta: EntityMetadata, propName: string, - options: SerializeOptions & { preventCircularRef?: boolean } = {} + options: CustomSerializeOptions = {} ): boolean { if (options.populate === true) { - return options.populate + return true } if ( Array.isArray(options.populate) && - options.populate?.find( - (item) => item === propName || item.startsWith(propName + ".") - ) + options.exclude?.find((item) => item === propName) ) { - return true + return false } - if (options.exclude?.find((item) => item === propName)) { - return false + if ( + Array.isArray(options.populate) && + (options.populate?.find( + (item) => item === propName || item.startsWith(propName + ".") + ) || + options.populate.includes("*")) + ) { + return true } const prop = meta.properties[propName] - const visible = prop && !prop.hidden + const visible = (prop && !prop.hidden) || prop === undefined // allow unknown properties const prefixed = prop && !prop.primary && propName.startsWith("_") // ignore prefixed properties, if it's not a PK return visible && !prefixed @@ -45,13 +54,14 @@ function isVisible( function isPopulated( entity: T, propName: string, - options: SerializeOptions + options: CustomSerializeOptions ): boolean { if ( - typeof options.populate !== "boolean" && - options.populate?.find( + Array.isArray(options.populate) && + (options.populate?.find( (item) => item === propName || item.startsWith(propName + ".") - ) + ) || + options.populate.includes("*")) ) { return true } @@ -78,9 +88,7 @@ function filterEntityPropToSerialize({ }: { propName: string meta: EntityMetadata - options: SerializeOptions & { - preventCircularRef?: boolean - } + options: CustomSerializeOptions parents?: string[] }): boolean { parents ??= [] @@ -92,7 +100,7 @@ function filterEntityPropToSerialize({ prop && options.preventCircularRef && isVisibleRes && - prop.reference !== ReferenceType.SCALAR + prop.kind !== ReferenceKind.SCALAR ) { // mapToPk would represent a foreign key and we want to keep them if (!!prop.mapToPk) { @@ -108,7 +116,7 @@ function filterEntityPropToSerialize({ export class EntitySerializer { static serialize( entity: T, - options: SerializeOptions & { preventCircularRef?: boolean } = {}, + options: CustomSerializeOptions = {}, parents: string[] = [] ): EntityDTO> { const parents_ = Array.from(new Set(parents)) @@ -118,12 +126,11 @@ export class EntitySerializer { let contextCreated = false if (!wrapped.__serializationContext.root) { - const root = new SerializationContext() + const root = new SerializationContext({} as any) // TODO: fix this: v6 Migration SerializationContext.propagate( root, entity, - (meta, prop) => - meta.properties[prop]?.reference !== ReferenceType.SCALAR + (meta, prop) => meta.properties[prop]?.kind !== ReferenceKind.SCALAR ) contextCreated = true } @@ -238,25 +245,25 @@ export class EntitySerializer { private static propertyName( meta: EntityMetadata, - prop: keyof T & string, + prop: string, platform?: Platform ): string { /* istanbul ignore next */ if (meta.properties[prop]?.serializedName) { - return meta.properties[prop].serializedName as keyof T & string + return meta.properties[prop].serializedName as string } if (meta.properties[prop]?.primary && platform) { - return platform.getSerializedPrimaryKeyField(prop) as keyof T & string + return platform.getSerializedPrimaryKeyField(prop) as string } return prop } private static processProperty( - prop: keyof T & string, + prop: string, entity: T, - options: SerializeOptions, + options: CustomSerializeOptions, parents: string[] = [] ): T[keyof T] | undefined { const parents_ = [...parents, entity.constructor.name] @@ -284,12 +291,17 @@ export class EntitySerializer { } if (Utils.isCollection(entity[prop])) { - return this.processCollection(prop, entity, options, parents_) + return this.processCollection( + prop as keyof T & string, + entity, + options, + parents_ + ) } if (Utils.isEntity(entity[prop], true)) { return this.processEntity( - prop, + prop as keyof T & string, entity, wrapped.__platform, options, @@ -298,7 +310,7 @@ export class EntitySerializer { } /* istanbul ignore next */ - if (property?.reference === ReferenceType.EMBEDDED) { + if (property?.reference === ReferenceKind.EMBEDDED) { if (Array.isArray(entity[prop])) { return (entity[prop] as object[]).map((item) => helper(item).toJSON() @@ -322,9 +334,9 @@ export class EntitySerializer { } private static extractChildOptions( - options: SerializeOptions, + options: CustomSerializeOptions, prop: keyof T & string - ): SerializeOptions { + ): CustomSerializeOptions { const extractChildElements = (items: string[]) => { return items .filter((field) => field.startsWith(`${prop}.`)) @@ -333,20 +345,22 @@ export class EntitySerializer { return { ...options, - populate: Array.isArray(options.populate) - ? extractChildElements(options.populate) - : options.populate, - exclude: Array.isArray(options.exclude) - ? extractChildElements(options.exclude) - : options.exclude, - } as SerializeOptions + populate: + Array.isArray(options.populate) && !options.populate.includes("*") + ? extractChildElements(options.populate as unknown as string[]) + : options.populate, + exclude: + Array.isArray(options.exclude) && !options.exclude.includes("*") + ? extractChildElements(options.exclude) + : options.exclude, + } as CustomSerializeOptions } private static processEntity( prop: keyof T & string, entity: T, platform: Platform, - options: SerializeOptions, + options: CustomSerializeOptions, parents: string[] = [] ): T[keyof T] | undefined { const parents_ = [...parents, entity.constructor.name] @@ -373,7 +387,7 @@ export class EntitySerializer { private static processCollection( prop: keyof T & string, entity: T, - options: SerializeOptions, + options: CustomSerializeOptions, parents: string[] = [] ): T[keyof T] | undefined { const parents_ = [...parents, entity.constructor.name] @@ -401,6 +415,7 @@ export const mikroOrmSerializer = ( data: any, options?: Parameters[1] & { preventCircularRef?: boolean + populate?: string[] | boolean } ): Promise => { return new Promise((resolve) => { @@ -422,10 +437,11 @@ export const mikroOrmSerializer = ( let result: any = forSerialization.map((entity) => EntitySerializer.serialize(entity, { forceObject: true, - populate: true, + populate: ["*"], + preventCircularRef: true, ...options, - } as SerializeOptions) + } as CustomSerializeOptions) ) as TOutput[] if (notForSerialization.length) { diff --git a/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts b/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts index 4880b2795457b..0e624b57b7847 100644 --- a/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts +++ b/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts @@ -24,7 +24,7 @@ describe("Entity builder", () => { fieldName: "created_at", nullable: false, onCreate: expect.any(Function), - reference: "scalar", + kind: "scalar", setter: false, type: "date", }, @@ -34,7 +34,7 @@ describe("Entity builder", () => { name: "deleted_at", fieldName: "deleted_at", nullable: true, - reference: "scalar", + kind: "scalar", setter: false, type: "date", }, @@ -47,7 +47,7 @@ describe("Entity builder", () => { nullable: false, onCreate: expect.any(Function), onUpdate: expect.any(Function), - reference: "scalar", + kind: "scalar", setter: false, type: "date", }, @@ -108,7 +108,7 @@ describe("Entity builder", () => { expect(metaData.properties).toEqual({ id: { - reference: "scalar", + kind: "scalar", type: "number", columnType: "integer", name: "id", @@ -118,7 +118,7 @@ describe("Entity builder", () => { setter: false, }, username: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "username", @@ -128,7 +128,7 @@ describe("Entity builder", () => { setter: false, }, email: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "email", @@ -138,7 +138,7 @@ describe("Entity builder", () => { setter: false, }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -155,7 +155,7 @@ describe("Entity builder", () => { name: "spend_limit", fieldName: "spend_limit", nullable: false, - reference: "scalar", + kind: "scalar", setter: true, trackChanges: false, type: "any", @@ -166,7 +166,7 @@ describe("Entity builder", () => { name: "raw_spend_limit", fieldName: "raw_spend_limit", nullable: false, - reference: "scalar", + kind: "scalar", setter: false, type: "any", }, @@ -175,12 +175,12 @@ describe("Entity builder", () => { name: "phones", fieldName: "phones", nullable: false, - reference: "scalar", + kind: "scalar", setter: false, type: ArrayType, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -193,7 +193,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -247,7 +247,7 @@ describe("Entity builder", () => { expect(metaData.properties).toEqual({ id: { - reference: "scalar", + kind: "scalar", type: "number", columnType: "integer", name: "id", @@ -257,7 +257,7 @@ describe("Entity builder", () => { setter: false, }, username: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "username", @@ -267,7 +267,7 @@ describe("Entity builder", () => { setter: false, }, email: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "email", @@ -277,7 +277,7 @@ describe("Entity builder", () => { setter: false, }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -294,7 +294,7 @@ describe("Entity builder", () => { name: "spend_limit", fieldName: "spend_limit", nullable: false, - reference: "scalar", + kind: "scalar", setter: true, trackChanges: false, type: "any", @@ -305,12 +305,12 @@ describe("Entity builder", () => { name: "raw_spend_limit", fieldName: "raw_spend_limit", nullable: false, - reference: "scalar", + kind: "scalar", setter: false, type: "any", }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -323,7 +323,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -377,7 +377,7 @@ describe("Entity builder", () => { expect(metaData.properties).toEqual({ id: { - reference: "scalar", + kind: "scalar", type: "number", columnType: "integer", name: "id", @@ -387,7 +387,7 @@ describe("Entity builder", () => { setter: false, }, username: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "username", @@ -397,7 +397,7 @@ describe("Entity builder", () => { setter: false, }, email: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "email", @@ -407,7 +407,7 @@ describe("Entity builder", () => { setter: false, }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -424,7 +424,7 @@ describe("Entity builder", () => { name: "spend_limit", fieldName: "spend_limit", nullable: false, - reference: "scalar", + kind: "scalar", setter: true, trackChanges: false, type: "any", @@ -435,12 +435,12 @@ describe("Entity builder", () => { name: "raw_spend_limit", fieldName: "raw_spend_limit", nullable: false, - reference: "scalar", + kind: "scalar", setter: false, type: "any", }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -453,7 +453,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -496,7 +496,7 @@ describe("Entity builder", () => { expect(metaData.properties).toEqual({ id: { - reference: "scalar", + kind: "scalar", type: "number", columnType: "integer", name: "id", @@ -506,7 +506,7 @@ describe("Entity builder", () => { setter: false, }, username: { - reference: "scalar", + kind: "scalar", type: "string", default: "foo", columnType: "text", @@ -517,7 +517,7 @@ describe("Entity builder", () => { setter: false, }, email: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "email", @@ -533,7 +533,7 @@ describe("Entity builder", () => { name: "spend_limit", fieldName: "spend_limit", nullable: false, - reference: "scalar", + kind: "scalar", setter: true, trackChanges: false, type: "any", @@ -544,12 +544,12 @@ describe("Entity builder", () => { name: "raw_spend_limit", fieldName: "raw_spend_limit", nullable: false, - reference: "scalar", + kind: "scalar", setter: false, type: "any", }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -561,7 +561,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -574,7 +574,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -637,7 +637,7 @@ describe("Entity builder", () => { expect(metaData.properties).toEqual({ id: { - reference: "scalar", + kind: "scalar", type: "number", columnType: "integer", name: "id", @@ -647,7 +647,7 @@ describe("Entity builder", () => { setter: false, }, username: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "username", @@ -658,7 +658,7 @@ describe("Entity builder", () => { searchable: true, }, email: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "email", @@ -674,7 +674,7 @@ describe("Entity builder", () => { name: "spend_limit", fieldName: "spend_limit", nullable: false, - reference: "scalar", + kind: "scalar", setter: true, trackChanges: false, type: "any", @@ -685,12 +685,12 @@ describe("Entity builder", () => { name: "raw_spend_limit", fieldName: "raw_spend_limit", nullable: false, - reference: "scalar", + kind: "scalar", setter: false, type: "any", }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -702,7 +702,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -715,7 +715,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -781,7 +781,7 @@ describe("Entity builder", () => { expect(metaData.properties).toEqual({ id: { - reference: "scalar", + kind: "scalar", type: "number", columnType: "integer", name: "id", @@ -791,7 +791,7 @@ describe("Entity builder", () => { setter: false, }, username: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "username", @@ -801,7 +801,7 @@ describe("Entity builder", () => { setter: false, }, email: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "email", @@ -816,7 +816,7 @@ describe("Entity builder", () => { name: "raw_spend_limit", fieldName: "raw_spend_limit", nullable: true, - reference: "scalar", + kind: "scalar", setter: false, type: "any", }, @@ -826,13 +826,13 @@ describe("Entity builder", () => { name: "spend_limit", fieldName: "spend_limit", nullable: true, - reference: "scalar", + kind: "scalar", setter: true, trackChanges: false, type: "any", }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -844,7 +844,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -857,7 +857,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -902,7 +902,7 @@ describe("Entity builder", () => { expect(metaData.properties).toEqual({ id: { - reference: "scalar", + kind: "scalar", type: "number", columnType: "integer", name: "id", @@ -912,7 +912,7 @@ describe("Entity builder", () => { setter: false, }, username: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "username", @@ -922,7 +922,7 @@ describe("Entity builder", () => { setter: false, }, email: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "email", @@ -932,7 +932,7 @@ describe("Entity builder", () => { setter: false, }, role: { - reference: "scalar", + kind: "scalar", enum: true, items: expect.any(Function), nullable: false, @@ -941,7 +941,7 @@ describe("Entity builder", () => { type: "string", }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -953,7 +953,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -966,7 +966,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -1019,7 +1019,7 @@ describe("Entity builder", () => { expect(metaData.properties).toEqual({ id: { - reference: "scalar", + kind: "scalar", type: "number", columnType: "integer", name: "id", @@ -1029,7 +1029,7 @@ describe("Entity builder", () => { setter: false, }, username: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "username", @@ -1039,7 +1039,7 @@ describe("Entity builder", () => { setter: false, }, email: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "email", @@ -1049,7 +1049,7 @@ describe("Entity builder", () => { setter: false, }, role: { - reference: "scalar", + kind: "scalar", enum: true, default: "guest", items: expect.any(Function), @@ -1059,7 +1059,7 @@ describe("Entity builder", () => { type: "string", }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -1071,7 +1071,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -1084,7 +1084,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -1140,7 +1140,7 @@ describe("Entity builder", () => { expect(metaData.properties).toEqual({ id: { - reference: "scalar", + kind: "scalar", type: "number", columnType: "integer", name: "id", @@ -1150,7 +1150,7 @@ describe("Entity builder", () => { setter: false, }, username: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "username", @@ -1160,7 +1160,7 @@ describe("Entity builder", () => { setter: false, }, email: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "email", @@ -1170,7 +1170,7 @@ describe("Entity builder", () => { setter: false, }, role: { - reference: "scalar", + kind: "scalar", enum: true, items: expect.any(Function), nullable: true, @@ -1179,7 +1179,7 @@ describe("Entity builder", () => { type: "string", }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -1191,7 +1191,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -1204,7 +1204,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -1281,7 +1281,7 @@ describe("Entity builder", () => { expect(metaData.properties).toEqual({ id: { - reference: "scalar", + kind: "scalar", type: "number", columnType: "integer", name: "id", @@ -1291,7 +1291,7 @@ describe("Entity builder", () => { setter: false, }, username: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "username", @@ -1301,7 +1301,7 @@ describe("Entity builder", () => { setter: false, }, email: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "email", @@ -1311,7 +1311,7 @@ describe("Entity builder", () => { setter: false, }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -1323,7 +1323,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -1336,7 +1336,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -1383,7 +1383,7 @@ describe("Entity builder", () => { expect(metaData.properties).toEqual({ id: { - reference: "scalar", + kind: "scalar", type: "number", columnType: "integer", name: "id", @@ -1393,7 +1393,7 @@ describe("Entity builder", () => { setter: false, }, email: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "email", @@ -1403,7 +1403,7 @@ describe("Entity builder", () => { setter: false, }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -1419,14 +1419,14 @@ describe("Entity builder", () => { name: "phones", fieldName: "phones", nullable: false, - reference: "scalar", + kind: "scalar", default: JSON.stringify({ number: "22222222" }), setter: false, columnType: "jsonb", type: "any", }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -1439,7 +1439,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -1481,7 +1481,7 @@ describe("Entity builder", () => { expect(metaData.properties).toEqual({ id: { - reference: "scalar", + kind: "scalar", type: "number", columnType: "integer", name: "id", @@ -1491,7 +1491,7 @@ describe("Entity builder", () => { setter: false, }, rate: { - reference: "scalar", + kind: "scalar", type: "number", columnType: "real", name: "rate", @@ -1502,7 +1502,7 @@ describe("Entity builder", () => { setter: false, }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -1514,7 +1514,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -1527,7 +1527,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -1576,7 +1576,7 @@ describe("Entity builder", () => { expect(metaData.properties).toEqual({ id: { - reference: "scalar", + kind: "scalar", type: "number", columnType: "integer", name: "id", @@ -1586,7 +1586,7 @@ describe("Entity builder", () => { setter: false, }, username: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "username", @@ -1601,11 +1601,11 @@ describe("Entity builder", () => { mappedBy: "user", name: "emails", orphanRemoval: true, - reference: "1:m", + kind: "1:m", searchable: true, }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -1617,7 +1617,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -1630,7 +1630,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -1684,7 +1684,7 @@ describe("Entity builder", () => { expect(metaData.properties).toEqual({ id: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "id", @@ -1694,7 +1694,7 @@ describe("Entity builder", () => { setter: false, }, username: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "username", @@ -1704,7 +1704,7 @@ describe("Entity builder", () => { setter: false, }, email: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "email", @@ -1714,7 +1714,7 @@ describe("Entity builder", () => { setter: false, }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -1726,7 +1726,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -1739,7 +1739,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -1794,7 +1794,7 @@ describe("Entity builder", () => { expect(metaData.properties).toEqual({ id: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "id", @@ -1803,7 +1803,7 @@ describe("Entity builder", () => { primary: true, }, username: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "username", @@ -1813,7 +1813,7 @@ describe("Entity builder", () => { setter: false, }, email: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "email", @@ -1823,7 +1823,7 @@ describe("Entity builder", () => { setter: false, }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -1835,7 +1835,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -1848,7 +1848,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -1905,7 +1905,7 @@ describe("Entity builder", () => { expect(metaData.properties).toEqual({ id: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "id", @@ -1914,7 +1914,7 @@ describe("Entity builder", () => { primary: true, }, username: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "username", @@ -1924,7 +1924,7 @@ describe("Entity builder", () => { setter: false, }, email: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "email", @@ -1934,7 +1934,7 @@ describe("Entity builder", () => { setter: false, }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -1946,7 +1946,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -1959,7 +1959,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -1992,7 +1992,7 @@ describe("Entity builder", () => { name: "id", fieldName: "id", nullable: false, - reference: "scalar", + kind: "scalar", type: "string", primary: true, }) @@ -2001,7 +2001,7 @@ describe("Entity builder", () => { name: "email", fieldName: "email", nullable: false, - reference: "scalar", + kind: "scalar", type: "string", primary: true, }) @@ -2057,7 +2057,7 @@ describe("Entity builder", () => { expect(metaData.properties).toEqual({ id: { - reference: "scalar", + kind: "scalar", type: "number", columnType: "integer", name: "id", @@ -2067,7 +2067,7 @@ describe("Entity builder", () => { setter: false, }, username: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "username", @@ -2077,7 +2077,7 @@ describe("Entity builder", () => { setter: false, }, email: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "email", @@ -2087,7 +2087,7 @@ describe("Entity builder", () => { setter: false, }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -2099,7 +2099,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -2112,7 +2112,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -2173,7 +2173,7 @@ describe("Entity builder", () => { expect(metaData.properties).toEqual({ id: { - reference: "scalar", + kind: "scalar", type: "number", columnType: "integer", name: "id", @@ -2183,7 +2183,7 @@ describe("Entity builder", () => { setter: false, }, username: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "username", @@ -2193,7 +2193,7 @@ describe("Entity builder", () => { setter: false, }, email: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "email", @@ -2203,7 +2203,7 @@ describe("Entity builder", () => { setter: false, }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -2215,7 +2215,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -2228,7 +2228,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -2288,7 +2288,7 @@ describe("Entity builder", () => { expect(metaData.properties).toEqual({ id: { - reference: "scalar", + kind: "scalar", type: "number", columnType: "integer", name: "id", @@ -2298,7 +2298,7 @@ describe("Entity builder", () => { setter: false, }, username: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "username", @@ -2308,7 +2308,7 @@ describe("Entity builder", () => { setter: false, }, myEmail: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "myEmail", @@ -2318,7 +2318,7 @@ describe("Entity builder", () => { setter: false, }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -2330,7 +2330,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -2343,7 +2343,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -2391,7 +2391,7 @@ describe("Entity builder", () => { expect(metaData.path).toEqual("User") expect(metaData.properties).toEqual({ id: { - reference: "scalar", + kind: "scalar", type: "number", columnType: "integer", name: "id", @@ -2401,7 +2401,7 @@ describe("Entity builder", () => { setter: false, }, username: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "username", @@ -2411,13 +2411,13 @@ describe("Entity builder", () => { setter: false, }, email: { - reference: "1:1", + kind: "1:1", name: "email", entity: "Email", mappedBy: "user", }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -2429,7 +2429,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -2442,7 +2442,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -2484,7 +2484,7 @@ describe("Entity builder", () => { expect(metaData.path).toEqual("User") expect(metaData.properties).toEqual({ id: { - reference: "scalar", + kind: "scalar", type: "number", columnType: "integer", name: "id", @@ -2494,7 +2494,7 @@ describe("Entity builder", () => { setter: false, }, username: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "username", @@ -2504,14 +2504,14 @@ describe("Entity builder", () => { setter: false, }, emails: { - reference: "1:1", + kind: "1:1", name: "emails", entity: "Email", nullable: true, mappedBy: "user", }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -2523,7 +2523,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -2536,7 +2536,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -2572,7 +2572,7 @@ describe("Entity builder", () => { expect(metaData.path).toEqual("User") expect(metaData.properties).toEqual({ id: { - reference: "scalar", + kind: "scalar", type: "number", columnType: "integer", name: "id", @@ -2582,7 +2582,7 @@ describe("Entity builder", () => { setter: false, }, username: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "username", @@ -2592,13 +2592,13 @@ describe("Entity builder", () => { setter: false, }, email: { - reference: "1:1", + kind: "1:1", name: "email", entity: "Email", onDelete: undefined, }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -2610,7 +2610,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -2623,7 +2623,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -2659,7 +2659,7 @@ describe("Entity builder", () => { expect(metaData.path).toEqual("User") expect(metaData.properties).toEqual({ id: { - reference: "scalar", + kind: "scalar", type: "number", columnType: "integer", name: "id", @@ -2669,7 +2669,7 @@ describe("Entity builder", () => { setter: false, }, username: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "username", @@ -2679,13 +2679,13 @@ describe("Entity builder", () => { setter: false, }, email: { - reference: "1:1", + kind: "1:1", name: "email", entity: "Email", mappedBy: "owner", }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -2697,7 +2697,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -2710,7 +2710,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -2750,7 +2750,7 @@ describe("Entity builder", () => { expect(metaData.path).toEqual("User") expect(metaData.properties).toEqual({ id: { - reference: "scalar", + kind: "scalar", type: "number", columnType: "integer", name: "id", @@ -2760,7 +2760,7 @@ describe("Entity builder", () => { setter: false, }, username: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "username", @@ -2770,15 +2770,15 @@ describe("Entity builder", () => { setter: false, }, email: { - reference: "1:1", + kind: "1:1", name: "email", entity: "Email", mappedBy: "user", cascade: ["persist", "soft-remove"], - onDelete: "cascade", + deleteRule: "cascade", }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -2790,7 +2790,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -2803,7 +2803,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -2820,7 +2820,7 @@ describe("Entity builder", () => { expect(emailMetaData.path).toEqual("Email") expect(emailMetaData.properties).toEqual({ email: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "email", @@ -2830,7 +2830,7 @@ describe("Entity builder", () => { setter: false, }, isVerified: { - reference: "scalar", + kind: "scalar", type: "boolean", columnType: "boolean", name: "isVerified", @@ -2840,7 +2840,7 @@ describe("Entity builder", () => { setter: false, }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -2852,7 +2852,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -2865,7 +2865,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -2913,7 +2913,7 @@ describe("Entity builder", () => { expect(metaData.path).toEqual("User") expect(metaData.properties).toEqual({ id: { - reference: "scalar", + kind: "scalar", type: "number", columnType: "integer", name: "id", @@ -2923,7 +2923,7 @@ describe("Entity builder", () => { setter: false, }, username: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "username", @@ -2933,14 +2933,14 @@ describe("Entity builder", () => { setter: false, }, email: { - reference: "1:1", + kind: "1:1", name: "email", entity: "Email", mappedBy: "user", - onDelete: "cascade", + deleteRule: "cascade", }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -2952,7 +2952,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -2965,7 +2965,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -2982,7 +2982,7 @@ describe("Entity builder", () => { expect(emailMetaData.path).toEqual("Email") expect(emailMetaData.properties).toEqual({ email: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "email", @@ -2992,7 +2992,7 @@ describe("Entity builder", () => { setter: false, }, isVerified: { - reference: "scalar", + kind: "scalar", type: "boolean", columnType: "boolean", name: "isVerified", @@ -3007,9 +3007,9 @@ describe("Entity builder", () => { mappedBy: "email", name: "user", nullable: false, - onDelete: "cascade", + deleteRule: "cascade", owner: true, - reference: "1:1", + kind: "1:1", cascade: ["persist", "soft-remove"], }, user_id: { @@ -3018,12 +3018,12 @@ describe("Entity builder", () => { persist: false, name: "user_id", nullable: false, - reference: "scalar", + kind: "scalar", setter: false, type: "string", }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -3035,7 +3035,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -3048,7 +3048,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -3100,7 +3100,7 @@ describe("Entity builder", () => { expect(metaData.path).toEqual("User") expect(metaData.properties).toEqual({ id: { - reference: "scalar", + kind: "scalar", type: "number", columnType: "integer", name: "id", @@ -3110,7 +3110,7 @@ describe("Entity builder", () => { setter: false, }, username: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "username", @@ -3120,14 +3120,14 @@ describe("Entity builder", () => { setter: false, }, email: { - reference: "1:1", + kind: "1:1", name: "email", entity: "Email", }, email_id: { columnType: "text", type: "string", - reference: "scalar", + kind: "scalar", name: "email_id", nullable: false, persist: true, @@ -3135,7 +3135,7 @@ describe("Entity builder", () => { setter: false, }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -3147,7 +3147,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -3160,7 +3160,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -3209,7 +3209,7 @@ describe("Entity builder", () => { expect(metaData.path).toEqual("User") expect(metaData.properties).toEqual({ id: { - reference: "scalar", + kind: "scalar", type: "number", columnType: "integer", name: "id", @@ -3219,7 +3219,7 @@ describe("Entity builder", () => { setter: false, }, username: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "username", @@ -3229,7 +3229,7 @@ describe("Entity builder", () => { setter: false, }, emails: { - reference: "1:1", + kind: "1:1", name: "emails", entity: "Email", nullable: true, @@ -3237,7 +3237,7 @@ describe("Entity builder", () => { emails_id: { columnType: "text", type: "string", - reference: "scalar", + kind: "scalar", name: "emails_id", nullable: true, persist: true, @@ -3245,7 +3245,7 @@ describe("Entity builder", () => { setter: false, }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -3257,7 +3257,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -3270,7 +3270,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -3310,7 +3310,7 @@ describe("Entity builder", () => { expect(metaData.path).toEqual("User") expect(metaData.properties).toEqual({ id: { - reference: "scalar", + kind: "scalar", type: "number", columnType: "integer", name: "id", @@ -3320,7 +3320,7 @@ describe("Entity builder", () => { setter: false, }, username: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "username", @@ -3330,7 +3330,7 @@ describe("Entity builder", () => { setter: false, }, email: { - reference: "1:1", + kind: "1:1", name: "email", entity: "Email", mappedBy: "owner", @@ -3338,7 +3338,7 @@ describe("Entity builder", () => { email_id: { columnType: "text", type: "string", - reference: "scalar", + kind: "scalar", name: "email_id", nullable: false, persist: true, @@ -3346,7 +3346,7 @@ describe("Entity builder", () => { setter: false, }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -3358,7 +3358,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -3371,7 +3371,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -3414,7 +3414,7 @@ describe("Entity builder", () => { expect(metaData.path).toEqual("User") expect(metaData.properties).toEqual({ id: { - reference: "scalar", + kind: "scalar", type: "number", columnType: "integer", name: "id", @@ -3424,7 +3424,7 @@ describe("Entity builder", () => { setter: false, }, username: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "username", @@ -3434,7 +3434,7 @@ describe("Entity builder", () => { setter: false, }, email: { - reference: "1:1", + kind: "1:1", name: "email", entity: "Email", cascade: ["persist", "soft-remove"], @@ -3443,7 +3443,7 @@ describe("Entity builder", () => { email_id: { columnType: "text", type: "string", - reference: "scalar", + kind: "scalar", name: "email_id", nullable: false, persist: true, @@ -3451,7 +3451,7 @@ describe("Entity builder", () => { setter: false, }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -3463,7 +3463,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -3476,7 +3476,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -3493,7 +3493,7 @@ describe("Entity builder", () => { expect(emailMetaData.path).toEqual("Email") expect(emailMetaData.properties).toEqual({ email: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "email", @@ -3503,7 +3503,7 @@ describe("Entity builder", () => { setter: false, }, isVerified: { - reference: "scalar", + kind: "scalar", type: "boolean", columnType: "boolean", name: "isVerified", @@ -3513,7 +3513,7 @@ describe("Entity builder", () => { setter: false, }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -3525,7 +3525,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -3538,7 +3538,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -3589,7 +3589,7 @@ describe("Entity builder", () => { expect(metaData.path).toEqual("User") expect(metaData.properties).toEqual({ id: { - reference: "scalar", + kind: "scalar", type: "number", columnType: "integer", name: "id", @@ -3599,7 +3599,7 @@ describe("Entity builder", () => { setter: false, }, username: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "username", @@ -3609,7 +3609,7 @@ describe("Entity builder", () => { setter: false, }, email: { - reference: "1:1", + kind: "1:1", name: "email", entity: "Email", cascade: ["persist", "soft-remove"], @@ -3618,7 +3618,7 @@ describe("Entity builder", () => { email_id: { columnType: "text", type: "string", - reference: "scalar", + kind: "scalar", name: "email_id", nullable: false, persist: true, @@ -3626,7 +3626,7 @@ describe("Entity builder", () => { setter: false, }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -3638,7 +3638,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -3651,7 +3651,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -3668,7 +3668,7 @@ describe("Entity builder", () => { expect(emailMetaData.path).toEqual("Email") expect(emailMetaData.properties).toEqual({ email: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "email", @@ -3678,7 +3678,7 @@ describe("Entity builder", () => { setter: false, }, isVerified: { - reference: "scalar", + kind: "scalar", type: "boolean", columnType: "boolean", name: "isVerified", @@ -3692,9 +3692,9 @@ describe("Entity builder", () => { mappedBy: "email", name: "user", nullable: false, - onDelete: "cascade", + deleteRule: "cascade", owner: true, - reference: "1:1", + kind: "1:1", cascade: ["persist", "soft-remove"], fieldName: "user_id", }, @@ -3703,13 +3703,13 @@ describe("Entity builder", () => { getter: false, name: "user_id", nullable: false, - reference: "scalar", + kind: "scalar", setter: false, type: "string", persist: false, }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -3721,7 +3721,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -3734,7 +3734,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -3784,7 +3784,7 @@ describe("Entity builder", () => { expect(metaData.properties).toEqual({ email: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "email", @@ -3794,7 +3794,7 @@ describe("Entity builder", () => { setter: false, }, account: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "account", @@ -3809,7 +3809,7 @@ describe("Entity builder", () => { name: "organization", fieldName: "organization", nullable: false, - reference: "scalar", + kind: "scalar", setter: false, type: "string", }, @@ -3819,7 +3819,7 @@ describe("Entity builder", () => { name: "group", nullable: false, persist: false, - reference: "m:1", + kind: "m:1", }, group_id: { columnType: "text", @@ -3829,7 +3829,7 @@ describe("Entity builder", () => { name: "group_id", nullable: false, onDelete: undefined, - reference: "m:1", + kind: "m:1", }, ...defaultColumnMetadata, }) @@ -4067,7 +4067,7 @@ describe("Entity builder", () => { expect(metaData.path).toEqual("User") expect(metaData.properties).toEqual({ id: { - reference: "scalar", + kind: "scalar", type: "number", columnType: "integer", name: "id", @@ -4077,7 +4077,7 @@ describe("Entity builder", () => { setter: false, }, username: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "username", @@ -4087,14 +4087,14 @@ describe("Entity builder", () => { setter: false, }, emails: { - reference: "1:m", + kind: "1:m", name: "emails", entity: "Email", orphanRemoval: true, mappedBy: "user", }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -4106,7 +4106,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -4119,7 +4119,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -4158,7 +4158,7 @@ describe("Entity builder", () => { expect(metaData.path).toEqual("User") expect(metaData.properties).toEqual({ id: { - reference: "scalar", + kind: "scalar", type: "number", columnType: "integer", name: "id", @@ -4168,7 +4168,7 @@ describe("Entity builder", () => { setter: false, }, username: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "username", @@ -4178,14 +4178,14 @@ describe("Entity builder", () => { setter: false, }, emails: { - reference: "1:m", + kind: "1:m", name: "emails", entity: "Email", mappedBy: "the_user", orphanRemoval: true, }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -4197,7 +4197,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -4210,7 +4210,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -4250,7 +4250,7 @@ describe("Entity builder", () => { expect(metaData.path).toEqual("User") expect(metaData.properties).toEqual({ id: { - reference: "scalar", + kind: "scalar", type: "number", columnType: "integer", name: "id", @@ -4260,7 +4260,7 @@ describe("Entity builder", () => { setter: false, }, username: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "username", @@ -4270,7 +4270,7 @@ describe("Entity builder", () => { setter: false, }, emails: { - reference: "1:m", + kind: "1:m", name: "emails", entity: "Email", orphanRemoval: true, @@ -4278,7 +4278,7 @@ describe("Entity builder", () => { cascade: ["persist", "soft-remove"], }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -4290,7 +4290,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -4303,7 +4303,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -4345,7 +4345,7 @@ describe("Entity builder", () => { expect(metaData.path).toEqual("User") expect(metaData.properties).toEqual({ id: { - reference: "scalar", + kind: "scalar", type: "number", columnType: "integer", name: "id", @@ -4355,7 +4355,7 @@ describe("Entity builder", () => { setter: false, }, username: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "username", @@ -4365,7 +4365,7 @@ describe("Entity builder", () => { setter: false, }, emails: { - reference: "1:m", + kind: "1:m", name: "emails", entity: "Email", orphanRemoval: true, @@ -4373,7 +4373,7 @@ describe("Entity builder", () => { cascade: ["persist", "soft-remove"], }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -4385,7 +4385,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -4398,7 +4398,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -4414,7 +4414,7 @@ describe("Entity builder", () => { expect(emailMetaData.path).toEqual("Email") expect(emailMetaData.properties).toEqual({ email: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "email", @@ -4424,7 +4424,7 @@ describe("Entity builder", () => { setter: false, }, isVerified: { - reference: "scalar", + kind: "scalar", type: "boolean", columnType: "boolean", name: "isVerified", @@ -4439,7 +4439,7 @@ describe("Entity builder", () => { name: "user", nullable: false, persist: false, - reference: "m:1", + kind: "m:1", }, user_id: { columnType: "text", @@ -4448,11 +4448,11 @@ describe("Entity builder", () => { fieldName: "user_id", name: "user_id", nullable: false, - onDelete: "cascade", - reference: "m:1", + deleteRule: "cascade", + kind: "m:1", }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -4464,7 +4464,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -4477,7 +4477,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -4549,7 +4549,7 @@ describe("Entity builder", () => { expect(metaData.path).toEqual("User") expect(metaData.properties).toEqual({ id: { - reference: "scalar", + kind: "scalar", type: "number", columnType: "integer", name: "id", @@ -4559,7 +4559,7 @@ describe("Entity builder", () => { setter: false, }, username: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "username", @@ -4569,13 +4569,13 @@ describe("Entity builder", () => { setter: false, }, email: { - reference: "1:1", + kind: "1:1", name: "email", entity: "Email", mappedBy: "user", }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -4587,7 +4587,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -4600,7 +4600,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -4616,7 +4616,7 @@ describe("Entity builder", () => { expect(emailMetaData.path).toEqual("Email") expect(emailMetaData.properties).toEqual({ email: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "email", @@ -4626,7 +4626,7 @@ describe("Entity builder", () => { setter: false, }, isVerified: { - reference: "scalar", + kind: "scalar", type: "boolean", columnType: "boolean", name: "isVerified", @@ -4638,7 +4638,7 @@ describe("Entity builder", () => { user: { name: "user", fieldName: "user_id", - reference: "1:1", + kind: "1:1", entity: "User", nullable: false, mappedBy: "email", @@ -4646,7 +4646,7 @@ describe("Entity builder", () => { owner: true, }, user_id: { - reference: "scalar", + kind: "scalar", persist: false, type: "string", columnType: "text", @@ -4656,7 +4656,7 @@ describe("Entity builder", () => { setter: false, }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -4668,7 +4668,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -4681,7 +4681,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -4746,7 +4746,7 @@ describe("Entity builder", () => { expect(metaData.path).toEqual("User") expect(metaData.properties).toEqual({ id: { - reference: "scalar", + kind: "scalar", type: "number", columnType: "integer", name: "id", @@ -4756,7 +4756,7 @@ describe("Entity builder", () => { setter: false, }, username: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "username", @@ -4766,13 +4766,13 @@ describe("Entity builder", () => { setter: false, }, email: { - reference: "1:1", + kind: "1:1", name: "email", entity: "Email", mappedBy: "user", }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -4784,7 +4784,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -4797,7 +4797,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -4813,7 +4813,7 @@ describe("Entity builder", () => { expect(emailMetaData.path).toEqual("Email") expect(emailMetaData.properties).toEqual({ email: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "email", @@ -4823,7 +4823,7 @@ describe("Entity builder", () => { setter: false, }, isVerified: { - reference: "scalar", + kind: "scalar", type: "boolean", columnType: "boolean", name: "isVerified", @@ -4835,7 +4835,7 @@ describe("Entity builder", () => { user: { name: "user", fieldName: "user_id", - reference: "1:1", + kind: "1:1", entity: "User", nullable: true, onDelete: undefined, @@ -4843,7 +4843,7 @@ describe("Entity builder", () => { owner: true, }, user_id: { - reference: "scalar", + kind: "scalar", persist: false, type: "string", columnType: "text", @@ -4853,7 +4853,7 @@ describe("Entity builder", () => { setter: false, }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -4865,7 +4865,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -4878,7 +4878,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -4937,7 +4937,7 @@ describe("Entity builder", () => { expect(metaData.path).toEqual("User") expect(metaData.properties).toEqual({ id: { - reference: "scalar", + kind: "scalar", type: "number", columnType: "integer", name: "id", @@ -4947,7 +4947,7 @@ describe("Entity builder", () => { setter: false, }, username: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "username", @@ -4957,14 +4957,14 @@ describe("Entity builder", () => { setter: false, }, emails: { - reference: "1:m", + kind: "1:m", name: "emails", entity: "Email", mappedBy: "user", orphanRemoval: true, }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -4976,7 +4976,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -4989,7 +4989,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -5005,7 +5005,7 @@ describe("Entity builder", () => { expect(emailMetaData.path).toEqual("Email") expect(emailMetaData.properties).toEqual({ email: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "email", @@ -5015,7 +5015,7 @@ describe("Entity builder", () => { setter: false, }, isVerified: { - reference: "scalar", + kind: "scalar", type: "boolean", columnType: "boolean", name: "isVerified", @@ -5026,7 +5026,7 @@ describe("Entity builder", () => { }, user: { name: "user", - reference: "m:1", + kind: "m:1", entity: "User", fieldName: "user_id", persist: false, @@ -5034,7 +5034,7 @@ describe("Entity builder", () => { }, user_id: { name: "user_id", - reference: "m:1", + kind: "m:1", entity: "User", columnType: "text", mapToPk: true, @@ -5042,7 +5042,7 @@ describe("Entity builder", () => { nullable: false, }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -5054,7 +5054,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -5067,7 +5067,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -5126,7 +5126,7 @@ describe("Entity builder", () => { expect(metaData.path).toEqual("User") expect(metaData.properties).toEqual({ id: { - reference: "scalar", + kind: "scalar", type: "number", columnType: "integer", name: "id", @@ -5136,7 +5136,7 @@ describe("Entity builder", () => { setter: false, }, username: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "username", @@ -5146,14 +5146,14 @@ describe("Entity builder", () => { setter: false, }, emails: { - reference: "1:m", + kind: "1:m", name: "emails", entity: "Email", mappedBy: "user", orphanRemoval: true, }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -5165,7 +5165,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -5178,7 +5178,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -5194,7 +5194,7 @@ describe("Entity builder", () => { expect(emailMetaData.path).toEqual("Email") expect(emailMetaData.properties).toEqual({ email: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "email", @@ -5204,7 +5204,7 @@ describe("Entity builder", () => { setter: false, }, isVerified: { - reference: "scalar", + kind: "scalar", type: "boolean", columnType: "boolean", name: "isVerified", @@ -5215,7 +5215,7 @@ describe("Entity builder", () => { }, user: { name: "user", - reference: "m:1", + kind: "m:1", fieldName: "user_id", entity: "User", persist: false, @@ -5223,7 +5223,7 @@ describe("Entity builder", () => { }, user_id: { name: "user_id", - reference: "m:1", + kind: "m:1", entity: "User", columnType: "text", mapToPk: true, @@ -5231,7 +5231,7 @@ describe("Entity builder", () => { nullable: true, }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -5243,7 +5243,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -5256,7 +5256,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -5380,7 +5380,7 @@ describe("Entity builder", () => { expect(metaData.tableName).toEqual("platform.user") expect(metaData.properties).toEqual({ id: { - reference: "scalar", + kind: "scalar", type: "number", columnType: "integer", name: "id", @@ -5390,7 +5390,7 @@ describe("Entity builder", () => { setter: false, }, username: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "username", @@ -5400,13 +5400,13 @@ describe("Entity builder", () => { setter: false, }, email: { - reference: "1:1", + kind: "1:1", name: "email", entity: "Email", mappedBy: "user", }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -5418,7 +5418,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -5431,7 +5431,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -5448,7 +5448,7 @@ describe("Entity builder", () => { expect(emailMetaData.tableName).toEqual("platform.email") expect(emailMetaData.properties).toEqual({ email: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "email", @@ -5458,7 +5458,7 @@ describe("Entity builder", () => { setter: false, }, isVerified: { - reference: "scalar", + kind: "scalar", type: "boolean", columnType: "boolean", name: "isVerified", @@ -5470,7 +5470,7 @@ describe("Entity builder", () => { user: { name: "user", fieldName: "user_id", - reference: "1:1", + kind: "1:1", entity: "User", nullable: false, mappedBy: "email", @@ -5478,7 +5478,7 @@ describe("Entity builder", () => { owner: true, }, user_id: { - reference: "scalar", + kind: "scalar", type: "string", persist: false, columnType: "text", @@ -5488,7 +5488,7 @@ describe("Entity builder", () => { setter: false, }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -5500,7 +5500,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -5513,7 +5513,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -5579,7 +5579,7 @@ describe("Entity builder", () => { expect(metaData.tableName).toEqual("public.user") expect(metaData.properties).toEqual({ id: { - reference: "scalar", + kind: "scalar", type: "number", columnType: "integer", name: "id", @@ -5589,7 +5589,7 @@ describe("Entity builder", () => { setter: false, }, username: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "username", @@ -5599,13 +5599,13 @@ describe("Entity builder", () => { setter: false, }, email: { - reference: "1:1", + kind: "1:1", name: "email", entity: "Email", mappedBy: "user", }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -5617,7 +5617,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -5630,7 +5630,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -5647,7 +5647,7 @@ describe("Entity builder", () => { expect(emailMetaData.tableName).toEqual("platform.email") expect(emailMetaData.properties).toEqual({ email: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "email", @@ -5657,7 +5657,7 @@ describe("Entity builder", () => { setter: false, }, isVerified: { - reference: "scalar", + kind: "scalar", type: "boolean", columnType: "boolean", name: "isVerified", @@ -5669,7 +5669,7 @@ describe("Entity builder", () => { user: { name: "user", fieldName: "user_id", - reference: "1:1", + kind: "1:1", entity: "User", nullable: false, mappedBy: "email", @@ -5677,7 +5677,7 @@ describe("Entity builder", () => { owner: true, }, user_id: { - reference: "scalar", + kind: "scalar", persist: false, type: "string", columnType: "text", @@ -5687,7 +5687,7 @@ describe("Entity builder", () => { setter: false, }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -5699,7 +5699,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -5712,7 +5712,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -5755,7 +5755,7 @@ describe("Entity builder", () => { expect(metaData.path).toEqual("User") expect(metaData.properties).toEqual({ id: { - reference: "scalar", + kind: "scalar", type: "number", columnType: "integer", name: "id", @@ -5765,7 +5765,7 @@ describe("Entity builder", () => { setter: false, }, username: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "username", @@ -5777,14 +5777,14 @@ describe("Entity builder", () => { parent: { name: "parent", fieldName: "parent_id", - reference: "m:1", + kind: "m:1", entity: "User", persist: false, nullable: false, }, parent_id: { name: "parent_id", - reference: "m:1", + kind: "m:1", entity: "User", columnType: "text", fieldName: "parent_id", @@ -5798,10 +5798,10 @@ describe("Entity builder", () => { mappedBy: "parent", name: "children", orphanRemoval: true, - reference: "1:m", + kind: "1:m", }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -5813,7 +5813,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -5826,7 +5826,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -5869,7 +5869,7 @@ describe("Entity builder", () => { expect(metaData.path).toEqual("User") expect(metaData.properties).toEqual({ id: { - reference: "scalar", + kind: "scalar", type: "number", columnType: "integer", name: "id", @@ -5879,7 +5879,7 @@ describe("Entity builder", () => { setter: false, }, username: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "username", @@ -5892,7 +5892,7 @@ describe("Entity builder", () => { name: "parent", fieldName: "parent_id", mappedBy: "child", - reference: "1:1", + kind: "1:1", entity: "User", nullable: false, onDelete: undefined, @@ -5902,7 +5902,7 @@ describe("Entity builder", () => { name: "parent_id", type: "string", columnType: "text", - reference: "scalar", + kind: "scalar", persist: false, getter: false, setter: false, @@ -5913,10 +5913,10 @@ describe("Entity builder", () => { entity: "User", mappedBy: "parent", name: "child", - reference: "1:1", + kind: "1:1", }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -5928,7 +5928,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -5941,7 +5941,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -6004,7 +6004,7 @@ describe("Entity builder", () => { expect(metaData.path).toEqual("User") expect(metaData.properties).toEqual({ id: { - reference: "scalar", + kind: "scalar", type: "number", columnType: "integer", name: "id", @@ -6014,7 +6014,7 @@ describe("Entity builder", () => { setter: false, }, username: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "username", @@ -6024,7 +6024,7 @@ describe("Entity builder", () => { setter: false, }, teams: { - reference: "m:n", + kind: "m:n", name: "teams", entity: "Team", owner: false, @@ -6032,7 +6032,7 @@ describe("Entity builder", () => { mappedBy: "users", }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -6044,7 +6044,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -6057,7 +6057,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -6073,7 +6073,7 @@ describe("Entity builder", () => { expect(teamMetaData.path).toEqual("Team") expect(teamMetaData.properties).toEqual({ id: { - reference: "scalar", + kind: "scalar", type: "number", columnType: "integer", name: "id", @@ -6083,7 +6083,7 @@ describe("Entity builder", () => { setter: false, }, name: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "name", @@ -6093,7 +6093,7 @@ describe("Entity builder", () => { setter: false, }, users: { - reference: "m:n", + kind: "m:n", name: "users", inversedBy: "teams", entity: "User", @@ -6101,7 +6101,7 @@ describe("Entity builder", () => { pivotTable: "team_users", }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -6113,7 +6113,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -6126,7 +6126,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -6185,7 +6185,7 @@ describe("Entity builder", () => { expect(metaData.path).toEqual("User") expect(metaData.properties).toEqual({ id: { - reference: "scalar", + kind: "scalar", type: "number", columnType: "integer", name: "id", @@ -6195,7 +6195,7 @@ describe("Entity builder", () => { setter: false, }, username: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "username", @@ -6205,7 +6205,7 @@ describe("Entity builder", () => { setter: false, }, teams: { - reference: "m:n", + kind: "m:n", name: "teams", entity: "Team", owner: false, @@ -6213,7 +6213,7 @@ describe("Entity builder", () => { mappedBy: "users", }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -6225,7 +6225,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -6238,7 +6238,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -6254,7 +6254,7 @@ describe("Entity builder", () => { expect(teamMetaData.path).toEqual("Team") expect(teamMetaData.properties).toEqual({ id: { - reference: "scalar", + kind: "scalar", type: "number", columnType: "integer", name: "id", @@ -6264,7 +6264,7 @@ describe("Entity builder", () => { setter: false, }, name: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "name", @@ -6274,7 +6274,7 @@ describe("Entity builder", () => { setter: false, }, users: { - reference: "m:n", + kind: "m:n", name: "users", entity: "User", owner: true, @@ -6282,7 +6282,7 @@ describe("Entity builder", () => { pivotTable: "team_users", }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -6294,7 +6294,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -6307,7 +6307,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -6360,8 +6360,8 @@ describe("Entity builder", () => { expect(teamUserMetadata.properties).toEqual( expect.objectContaining({ user_id: { - reference: "scalar", - type: "User", + kind: "scalar", + type: "string", columnType: "text", fieldName: "user_id", nullable: false, @@ -6371,15 +6371,16 @@ describe("Entity builder", () => { }, user: { name: "user", - reference: "m:1", + kind: "m:1", entity: "User", + fieldName: "user_id", nullable: false, persist: false, - onDelete: "cascade", + deleteRule: "cascade", }, team_id: { - reference: "scalar", - type: "Team", + kind: "scalar", + type: "string", columnType: "text", fieldName: "team_id", nullable: false, @@ -6389,11 +6390,12 @@ describe("Entity builder", () => { }, team: { name: "team", - reference: "m:1", + kind: "m:1", entity: "Team", + fieldName: "team_id", nullable: false, persist: false, - onDelete: "cascade", + deleteRule: "cascade", }, }) ) @@ -6480,7 +6482,7 @@ describe("Entity builder", () => { expect(metaData.path).toEqual("User") expect(metaData.properties).toEqual({ id: { - reference: "scalar", + kind: "scalar", type: "number", columnType: "integer", name: "id", @@ -6490,7 +6492,7 @@ describe("Entity builder", () => { setter: false, }, username: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "username", @@ -6500,7 +6502,7 @@ describe("Entity builder", () => { setter: false, }, teams: { - reference: "m:n", + kind: "m:n", name: "teams", entity: "Team", owner: false, @@ -6508,7 +6510,7 @@ describe("Entity builder", () => { mappedBy: "users", }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -6520,7 +6522,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -6533,7 +6535,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -6549,7 +6551,7 @@ describe("Entity builder", () => { expect(teamMetaData.path).toEqual("Team") expect(teamMetaData.properties).toEqual({ id: { - reference: "scalar", + kind: "scalar", type: "number", columnType: "integer", name: "id", @@ -6559,7 +6561,7 @@ describe("Entity builder", () => { setter: false, }, name: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "name", @@ -6569,7 +6571,7 @@ describe("Entity builder", () => { setter: false, }, users: { - reference: "m:n", + kind: "m:n", name: "users", entity: "User", owner: true, @@ -6577,7 +6579,7 @@ describe("Entity builder", () => { inversedBy: "teams", }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -6589,7 +6591,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -6602,7 +6604,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -6661,7 +6663,7 @@ describe("Entity builder", () => { expect(metaData.path).toEqual("User") expect(metaData.properties).toEqual({ id: { - reference: "scalar", + kind: "scalar", type: "number", columnType: "integer", name: "id", @@ -6671,7 +6673,7 @@ describe("Entity builder", () => { setter: false, }, username: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "username", @@ -6681,7 +6683,7 @@ describe("Entity builder", () => { setter: false, }, teams: { - reference: "m:n", + kind: "m:n", name: "teams", entity: "Team", owner: false, @@ -6689,7 +6691,7 @@ describe("Entity builder", () => { mappedBy: "users", }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -6701,7 +6703,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -6714,7 +6716,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -6730,7 +6732,7 @@ describe("Entity builder", () => { expect(teamMetaData.path).toEqual("Team") expect(teamMetaData.properties).toEqual({ id: { - reference: "scalar", + kind: "scalar", type: "number", columnType: "integer", name: "id", @@ -6740,7 +6742,7 @@ describe("Entity builder", () => { setter: false, }, name: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "name", @@ -6750,7 +6752,7 @@ describe("Entity builder", () => { setter: false, }, users: { - reference: "m:n", + kind: "m:n", name: "users", entity: "User", owner: true, @@ -6758,7 +6760,7 @@ describe("Entity builder", () => { inversedBy: "teams", }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -6770,7 +6772,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -6783,7 +6785,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -6860,7 +6862,7 @@ describe("Entity builder", () => { expect(metaData.path).toEqual("User") expect(metaData.properties).toEqual({ id: { - reference: "scalar", + kind: "scalar", type: "number", columnType: "integer", name: "id", @@ -6870,7 +6872,7 @@ describe("Entity builder", () => { setter: false, }, username: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "username", @@ -6880,7 +6882,7 @@ describe("Entity builder", () => { setter: false, }, teams: { - reference: "m:n", + kind: "m:n", name: "teams", entity: "Team", owner: false, @@ -6888,7 +6890,7 @@ describe("Entity builder", () => { mappedBy: "users", }, activeTeams: { - reference: "m:n", + kind: "m:n", name: "activeTeams", entity: "Team", owner: false, @@ -6896,7 +6898,7 @@ describe("Entity builder", () => { mappedBy: "activeTeamsUsers", }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -6908,7 +6910,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -6921,7 +6923,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -6937,7 +6939,7 @@ describe("Entity builder", () => { expect(teamMetaData.path).toEqual("Team") expect(teamMetaData.properties).toEqual({ id: { - reference: "scalar", + kind: "scalar", type: "number", columnType: "integer", name: "id", @@ -6947,7 +6949,7 @@ describe("Entity builder", () => { setter: false, }, name: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "name", @@ -6957,7 +6959,7 @@ describe("Entity builder", () => { setter: false, }, users: { - reference: "m:n", + kind: "m:n", name: "users", entity: "User", owner: true, @@ -6965,7 +6967,7 @@ describe("Entity builder", () => { inversedBy: "teams", }, activeTeamsUsers: { - reference: "m:n", + kind: "m:n", name: "activeTeamsUsers", entity: "User", owner: true, @@ -6973,7 +6975,7 @@ describe("Entity builder", () => { inversedBy: "activeTeams", }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -6985,7 +6987,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -6998,7 +7000,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -7060,7 +7062,7 @@ describe("Entity builder", () => { expect(metaData.tableName).toEqual("platform.user") expect(metaData.properties).toEqual({ id: { - reference: "scalar", + kind: "scalar", type: "number", columnType: "integer", name: "id", @@ -7070,7 +7072,7 @@ describe("Entity builder", () => { setter: false, }, username: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "username", @@ -7080,7 +7082,7 @@ describe("Entity builder", () => { setter: false, }, teams: { - reference: "m:n", + kind: "m:n", name: "teams", entity: "Team", owner: false, @@ -7088,7 +7090,7 @@ describe("Entity builder", () => { mappedBy: "users", }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -7100,7 +7102,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -7113,7 +7115,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -7130,7 +7132,7 @@ describe("Entity builder", () => { expect(teamMetaData.tableName).toEqual("platform.team") expect(teamMetaData.properties).toEqual({ id: { - reference: "scalar", + kind: "scalar", type: "number", columnType: "integer", name: "id", @@ -7140,7 +7142,7 @@ describe("Entity builder", () => { setter: false, }, name: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "name", @@ -7150,7 +7152,7 @@ describe("Entity builder", () => { setter: false, }, users: { - reference: "m:n", + kind: "m:n", name: "users", entity: "User", owner: true, @@ -7158,7 +7160,7 @@ describe("Entity builder", () => { pivotTable: "platform.team_users", }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -7170,7 +7172,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -7183,7 +7185,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -7218,7 +7220,7 @@ describe("Entity builder", () => { expect(metaData.path).toEqual("RandomUser") expect(metaData.properties).toEqual({ id: { - reference: "scalar", + kind: "scalar", type: "number", columnType: "integer", name: "id", @@ -7228,7 +7230,7 @@ describe("Entity builder", () => { setter: false, }, username: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "username", @@ -7238,7 +7240,7 @@ describe("Entity builder", () => { setter: false, }, teams: { - reference: "m:n", + kind: "m:n", name: "teams", entity: "TeamSquad", owner: true, @@ -7246,7 +7248,7 @@ describe("Entity builder", () => { inversedBy: "users", }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -7258,7 +7260,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -7271,7 +7273,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -7287,7 +7289,7 @@ describe("Entity builder", () => { expect(teamMetaData.path).toEqual("TeamSquad") expect(teamMetaData.properties).toEqual({ id: { - reference: "scalar", + kind: "scalar", type: "number", columnType: "integer", name: "id", @@ -7297,7 +7299,7 @@ describe("Entity builder", () => { setter: false, }, name: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "name", @@ -7307,7 +7309,7 @@ describe("Entity builder", () => { setter: false, }, users: { - reference: "m:n", + kind: "m:n", name: "users", entity: "RandomUser", owner: false, @@ -7315,7 +7317,7 @@ describe("Entity builder", () => { pivotTable: "random_user_team_squads", }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -7327,7 +7329,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -7340,7 +7342,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -7402,7 +7404,7 @@ describe("Entity builder", () => { expect(metaData.path).toEqual("User") expect(metaData.properties).toEqual({ id: { - reference: "scalar", + kind: "scalar", type: "number", columnType: "integer", name: "id", @@ -7412,7 +7414,7 @@ describe("Entity builder", () => { setter: false, }, username: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "username", @@ -7422,7 +7424,7 @@ describe("Entity builder", () => { setter: false, }, teams: { - reference: "m:n", + kind: "m:n", name: "teams", entity: "Team", owner: true, @@ -7430,7 +7432,7 @@ describe("Entity builder", () => { inversedBy: "users", }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -7442,7 +7444,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -7455,7 +7457,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -7471,7 +7473,7 @@ describe("Entity builder", () => { expect(teamMetaData.path).toEqual("Team") expect(teamMetaData.properties).toEqual({ id: { - reference: "scalar", + kind: "scalar", type: "number", columnType: "integer", name: "id", @@ -7481,7 +7483,7 @@ describe("Entity builder", () => { setter: false, }, name: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "name", @@ -7491,7 +7493,7 @@ describe("Entity builder", () => { setter: false, }, users: { - reference: "m:n", + kind: "m:n", name: "users", owner: false, entity: "User", @@ -7499,7 +7501,7 @@ describe("Entity builder", () => { pivotTable: "users_teams", }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -7511,7 +7513,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -7524,7 +7526,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -7595,7 +7597,7 @@ describe("Entity builder", () => { expect(squadMetaData.properties).toEqual({ id: { - reference: "scalar", + kind: "scalar", columnType: "integer", type: "number", nullable: false, @@ -7606,40 +7608,42 @@ describe("Entity builder", () => { }, user_id: { name: "user_id", - reference: "scalar", + kind: "scalar", columnType: "text", fieldName: "user_id", getter: false, setter: false, nullable: false, - type: "User", + type: "string", }, user: { - reference: "m:1", + kind: "m:1", entity: "User", + fieldName: "user_id", persist: false, nullable: false, name: "user", }, team_id: { name: "team_id", - reference: "scalar", + kind: "scalar", columnType: "text", fieldName: "team_id", nullable: false, getter: false, setter: false, - type: "Team", + type: "string", }, team: { - reference: "m:1", + kind: "m:1", entity: "Team", + fieldName: "team_id", persist: false, nullable: false, name: "team", }, created_at: { - reference: "scalar", + kind: "scalar", columnType: "timestamptz", type: "date", nullable: false, @@ -7651,7 +7655,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", columnType: "timestamptz", type: "date", nullable: false, @@ -7664,7 +7668,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", columnType: "timestamptz", type: "date", nullable: true, @@ -7680,7 +7684,7 @@ describe("Entity builder", () => { expect(teamMetaData.path).toEqual("Team") expect(teamMetaData.properties).toEqual({ id: { - reference: "scalar", + kind: "scalar", type: "number", columnType: "integer", name: "id", @@ -7690,7 +7694,7 @@ describe("Entity builder", () => { setter: false, }, name: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "name", @@ -7700,7 +7704,7 @@ describe("Entity builder", () => { setter: false, }, users: { - reference: "m:n", + kind: "m:n", name: "users", entity: "User", owner: true, @@ -7708,7 +7712,7 @@ describe("Entity builder", () => { pivotEntity: "TeamUsers", }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -7720,7 +7724,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -7733,7 +7737,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", @@ -7749,7 +7753,7 @@ describe("Entity builder", () => { expect(metaData.path).toEqual("User") expect(metaData.properties).toEqual({ id: { - reference: "scalar", + kind: "scalar", type: "number", columnType: "integer", name: "id", @@ -7759,7 +7763,7 @@ describe("Entity builder", () => { setter: false, }, username: { - reference: "scalar", + kind: "scalar", type: "string", columnType: "text", name: "username", @@ -7769,7 +7773,7 @@ describe("Entity builder", () => { setter: false, }, teams: { - reference: "m:n", + kind: "m:n", name: "teams", entity: "Team", owner: false, @@ -7777,7 +7781,7 @@ describe("Entity builder", () => { mappedBy: "users", }, created_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "created_at", @@ -7789,7 +7793,7 @@ describe("Entity builder", () => { setter: false, }, updated_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "updated_at", @@ -7802,7 +7806,7 @@ describe("Entity builder", () => { setter: false, }, deleted_at: { - reference: "scalar", + kind: "scalar", type: "date", columnType: "timestamptz", name: "deleted_at", diff --git a/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts b/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts index 0d506b91f38db..a95350a929676 100644 --- a/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts +++ b/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts @@ -19,13 +19,13 @@ import { } from "@mikro-orm/core" import { camelToSnakeCase, pluralize } from "../../../common" import { DmlEntity } from "../../entity" +import { BelongsTo } from "../../relations" import { HasMany } from "../../relations/has-many" import { HasOne } from "../../relations/has-one" import { HasOneWithForeignKey } from "../../relations/has-one-fk" import { ManyToMany as DmlManyToMany } from "../../relations/many-to-many" import { applyEntityIndexes } from "../mikro-orm/apply-indexes" import { parseEntityName } from "./parse-entity-name" -import { BelongsTo } from "../../relations" type Context = { MANY_TO_MANY_TRACKED_RELATIONS: Record @@ -161,7 +161,7 @@ export function defineHasOneRelationship( entity: relatedModelName, ...(relationship.nullable ? { nullable: relationship.nullable } : {}), ...(mappedBy ? { mappedBy } : {}), - onDelete: shouldRemoveRelated ? "cascade" : undefined, + deleteRule: shouldRemoveRelated ? "cascade" : undefined, } as OneToOneOptions if (shouldRemoveRelated && !isOthersideBelongsTo) { @@ -256,7 +256,7 @@ export function defineBelongsToRelationship( /** * In DML the relationships are cascaded from parent to child. A belongsTo * relationship is always a child, therefore we look at the parent and - * define a onDelete: cascade when we are included in the delete + * define a deleteRule: cascade when we are included in the delete * list of parent cascade. */ const shouldCascade = !!relationCascades.delete?.includes(mappedBy) @@ -343,27 +343,34 @@ export function defineBelongsToRelationship( if (DmlManyToMany.isManyToMany(otherSideRelation)) { Property({ - type: relatedModelName, + type: "string", columnType: "text", fieldName: foreignKeyName, nullable: relationship.nullable, })(MikroORMEntity.prototype, foreignKeyName) - ManyToOne({ + const conf = { entity: relatedModelName, nullable: relationship.nullable, + fieldName: foreignKeyName, persist: false, - onDelete: shouldCascade || detachCascade ? "cascade" : undefined, - })(MikroORMEntity.prototype, relationship.name) + } + if (shouldCascade || detachCascade) { + conf["deleteRule"] = "cascade" + } + ManyToOne(conf)(MikroORMEntity.prototype, relationship.name) } else { - ManyToOne({ + const conf = { entity: relatedModelName, columnType: "text", mapToPk: true, fieldName: foreignKeyName, nullable: relationship.nullable, - onDelete: shouldCascade ? "cascade" : undefined, - })(MikroORMEntity.prototype, foreignKeyName) + } + if (shouldCascade) { + conf["deleteRule"] = "cascade" + } + ManyToOne(conf)(MikroORMEntity.prototype, foreignKeyName) ManyToOne({ entity: relatedModelName, @@ -394,7 +401,6 @@ export function defineBelongsToRelationship( const foreignKeyName = camelToSnakeCase(`${relationship.name}Id`) Object.defineProperty(MikroORMEntity.prototype, foreignKeyName, { - value: null, configurable: true, enumerable: true, writable: true, @@ -413,10 +419,10 @@ export function defineBelongsToRelationship( mappedBy: mappedBy, fieldName: foreignKeyName, owner: true, - onDelete: shouldCascade ? "cascade" : undefined, } if (shouldCascade) { + oneToOneOptions.deleteRule = "cascade" oneToOneOptions.cascade = [Cascade.PERSIST, "soft-remove"] as any } @@ -650,8 +656,15 @@ export function defineManyToManyRelationship( : {}), ...(pivotEntityName ? { pivotEntity: pivotEntityName } : {}), ...({ [mappedByProp]: mappedByPropValue } as any), - [joinColumnProp]: joinColumn ?? joinColumns, - [inverseJoinColumnProp]: inverseJoinColumn ?? inverseJoinColumns, + } as any + + if (joinColumn || joinColumns) { + manytoManyOptions[joinColumnProp] = joinColumn ?? joinColumns + } + + if (inverseJoinColumn || inverseJoinColumns) { + manytoManyOptions[inverseJoinColumnProp] = + inverseJoinColumn ?? inverseJoinColumns } ManyToMany(manytoManyOptions)(MikroORMEntity.prototype, relationship.name) diff --git a/packages/core/utils/src/dml/integration-tests/__tests__/entity.spec.ts b/packages/core/utils/src/dml/integration-tests/__tests__/entity.spec.ts index 6846ceee6fda7..f8d426cd17d77 100644 --- a/packages/core/utils/src/dml/integration-tests/__tests__/entity.spec.ts +++ b/packages/core/utils/src/dml/integration-tests/__tests__/entity.spec.ts @@ -1,15 +1,16 @@ +import { EntityConstructor } from "@medusajs/types" import { MetadataStorage, MikroORM } from "@mikro-orm/core" +import { defineConfig } from "@mikro-orm/postgresql" +import { join } from "path" +import { createDatabase, dropDatabase } from "pg-god" +import { FileSystem } from "../../../common" +import { CustomTsMigrationGenerator, mikroOrmSerializer } from "../../../dal" import { model } from "../../entity-builder" import { mikroORMEntityBuilder, toMikroOrmEntities, } from "../../helpers/create-mikro-orm-entity" -import { createDatabase, dropDatabase } from "pg-god" -import { CustomTsMigrationGenerator, mikroOrmSerializer } from "../../../dal" -import { EntityConstructor } from "@medusajs/types" import { pgGodCredentials } from "../utils" -import { FileSystem } from "../../../common" -import { join } from "path" export const fileSystem = new FileSystem( join(__dirname, "../../integration-tests-migrations-enum") @@ -40,19 +41,20 @@ describe("EntityBuilder", () => { await createDatabase({ databaseName: dbName }, pgGodCredentials) - orm = await MikroORM.init({ - entities: [User], - tsNode: true, - dbName, - password: pgGodCredentials.password, - host: pgGodCredentials.host, - user: pgGodCredentials.user, - type: "postgresql", - migrations: { - generator: CustomTsMigrationGenerator, - path: fileSystem.basePath, - }, - }) + orm = await MikroORM.init( + defineConfig({ + entities: [User], + tsNode: true, + dbName, + password: pgGodCredentials.password, + host: pgGodCredentials.host, + user: pgGodCredentials.user, + migrations: { + generator: CustomTsMigrationGenerator, + path: fileSystem.basePath, + }, + }) + ) const migrator = orm.getMigrator() await migrator.createMigration() diff --git a/packages/core/utils/src/dml/integration-tests/__tests__/enum.spec.ts b/packages/core/utils/src/dml/integration-tests/__tests__/enum.spec.ts index 8cbddb5b33c35..b193959076cfe 100644 --- a/packages/core/utils/src/dml/integration-tests/__tests__/enum.spec.ts +++ b/packages/core/utils/src/dml/integration-tests/__tests__/enum.spec.ts @@ -1,19 +1,20 @@ +import { EntityConstructor } from "@medusajs/types" import { CheckConstraintViolationException, MetadataStorage, MikroORM, } from "@mikro-orm/core" +import { defineConfig } from "@mikro-orm/postgresql" +import { join } from "path" +import { createDatabase, dropDatabase } from "pg-god" +import { FileSystem } from "../../../common" +import { CustomTsMigrationGenerator, mikroOrmSerializer } from "../../../dal" import { model } from "../../entity-builder" import { mikroORMEntityBuilder, toMikroOrmEntities, } from "../../helpers/create-mikro-orm-entity" -import { createDatabase, dropDatabase } from "pg-god" -import { CustomTsMigrationGenerator, mikroOrmSerializer } from "../../../dal" -import { EntityConstructor } from "@medusajs/types" import { pgGodCredentials } from "../utils" -import { FileSystem } from "../../../common" -import { join } from "path" export const fileSystem = new FileSystem( join(__dirname, "../../integration-tests-migrations-enum") @@ -43,19 +44,20 @@ describe("EntityBuilder | enum", () => { await createDatabase({ databaseName: dbName }, pgGodCredentials) - orm = await MikroORM.init({ - entities: [User], - tsNode: true, - dbName, - password: pgGodCredentials.password, - host: pgGodCredentials.host, - user: pgGodCredentials.user, - type: "postgresql", - migrations: { - generator: CustomTsMigrationGenerator, - path: fileSystem.basePath, - }, - }) + orm = await MikroORM.init( + defineConfig({ + entities: [User], + tsNode: true, + dbName, + password: pgGodCredentials.password, + host: pgGodCredentials.host, + user: pgGodCredentials.user, + migrations: { + generator: CustomTsMigrationGenerator, + path: fileSystem.basePath, + }, + }) + ) const migrator = orm.getMigrator() await migrator.createMigration() diff --git a/packages/core/utils/src/dml/integration-tests/__tests__/has-one-belongs-to.spec.ts b/packages/core/utils/src/dml/integration-tests/__tests__/has-one-belongs-to.spec.ts index ba58d8b035d60..7fe0fded46981 100644 --- a/packages/core/utils/src/dml/integration-tests/__tests__/has-one-belongs-to.spec.ts +++ b/packages/core/utils/src/dml/integration-tests/__tests__/has-one-belongs-to.spec.ts @@ -1,15 +1,16 @@ +import { EntityConstructor } from "@medusajs/types" import { MetadataStorage, MikroORM } from "@mikro-orm/core" +import { defineConfig } from "@mikro-orm/postgresql" +import { join } from "path" +import { createDatabase, dropDatabase } from "pg-god" +import { FileSystem } from "../../../common" +import { CustomTsMigrationGenerator, mikroOrmSerializer } from "../../../dal" import { model } from "../../entity-builder" import { mikroORMEntityBuilder, toMikroOrmEntities, } from "../../helpers/create-mikro-orm-entity" -import { createDatabase, dropDatabase } from "pg-god" -import { CustomTsMigrationGenerator, mikroOrmSerializer } from "../../../dal" -import { EntityConstructor } from "@medusajs/types" import { pgGodCredentials } from "../utils" -import { FileSystem } from "../../../common" -import { join } from "path" export const fileSystem = new FileSystem( join(__dirname, "../../integration-tests-migrations-has-one-belongs-to") @@ -45,19 +46,20 @@ describe("hasOne - belongTo", () => { await createDatabase({ databaseName: dbName }, pgGodCredentials) - orm = await MikroORM.init({ - entities: [Team, User], - tsNode: true, - dbName, - password: pgGodCredentials.password, - host: pgGodCredentials.host, - user: pgGodCredentials.user, - type: "postgresql", - migrations: { - generator: CustomTsMigrationGenerator, - path: fileSystem.basePath, - }, - }) + orm = await MikroORM.init( + defineConfig({ + entities: [Team, User], + tsNode: true, + dbName, + password: pgGodCredentials.password, + host: pgGodCredentials.host, + user: pgGodCredentials.user, + migrations: { + generator: CustomTsMigrationGenerator, + path: fileSystem.basePath, + }, + }) + ) const migrator = orm.getMigrator() await migrator.createMigration() diff --git a/packages/core/utils/src/dml/integration-tests/__tests__/many-to-many.spec.ts b/packages/core/utils/src/dml/integration-tests/__tests__/many-to-many.spec.ts index b350e8de51187..d88db258d168f 100644 --- a/packages/core/utils/src/dml/integration-tests/__tests__/many-to-many.spec.ts +++ b/packages/core/utils/src/dml/integration-tests/__tests__/many-to-many.spec.ts @@ -1,15 +1,16 @@ -import { join } from "path" +import { EntityConstructor } from "@medusajs/types" import { MetadataStorage, MikroORM } from "@mikro-orm/core" +import { defineConfig } from "@mikro-orm/postgresql" +import { join } from "path" +import { createDatabase, dropDatabase } from "pg-god" +import { FileSystem } from "../../../common" +import { CustomTsMigrationGenerator, mikroOrmSerializer } from "../../../dal" import { model } from "../../entity-builder" import { mikroORMEntityBuilder, toMikroOrmEntities, } from "../../helpers/create-mikro-orm-entity" -import { createDatabase, dropDatabase } from "pg-god" -import { CustomTsMigrationGenerator, mikroOrmSerializer } from "../../../dal" -import { EntityConstructor } from "@medusajs/types" import { pgGodCredentials } from "../utils" -import { FileSystem } from "../../../common" jest.setTimeout(30000) @@ -62,19 +63,20 @@ describe("manyToMany - manyToMany", () => { await createDatabase({ databaseName: dbName }, pgGodCredentials) - orm = await MikroORM.init({ - entities: [Team, User, Squad], - tsNode: true, - dbName, - password: pgGodCredentials.password, - host: pgGodCredentials.host, - user: pgGodCredentials.user, - type: "postgresql", - migrations: { - generator: CustomTsMigrationGenerator, - path: fileSystem.basePath, - }, - }) + orm = await MikroORM.init( + defineConfig({ + entities: [Team, User, Squad], + tsNode: true, + dbName, + password: pgGodCredentials.password, + host: pgGodCredentials.host, + user: pgGodCredentials.user, + migrations: { + generator: CustomTsMigrationGenerator, + path: fileSystem.basePath, + }, + }) + ) const migrator = orm.getMigrator() await migrator.createMigration() diff --git a/packages/core/utils/src/dml/integration-tests/__tests__/many-to-one.spec.ts b/packages/core/utils/src/dml/integration-tests/__tests__/many-to-one.spec.ts index a44ce4826d71e..3fa4971a47f8e 100644 --- a/packages/core/utils/src/dml/integration-tests/__tests__/many-to-one.spec.ts +++ b/packages/core/utils/src/dml/integration-tests/__tests__/many-to-one.spec.ts @@ -1,21 +1,21 @@ +import { EntityConstructor } from "@medusajs/types" import { MetadataStorage, MikroORM } from "@mikro-orm/core" -import { model } from "../../entity-builder" -import { - mikroORMEntityBuilder, - toMikroOrmEntities, -} from "../../helpers/create-mikro-orm-entity" +import { defineConfig, SqlEntityManager } from "@mikro-orm/postgresql" +import { join } from "path" import { createDatabase, dropDatabase } from "pg-god" +import { FileSystem } from "../../../common" import { CustomTsMigrationGenerator, mikroOrmSerializer, mikroOrmUpdateDeletedAtRecursively, SoftDeletableFilterKey, } from "../../../dal" -import { EntityConstructor } from "@medusajs/types" +import { model } from "../../entity-builder" +import { + mikroORMEntityBuilder, + toMikroOrmEntities, +} from "../../helpers/create-mikro-orm-entity" import { pgGodCredentials } from "../utils" -import { FileSystem } from "../../../common" -import { join } from "path" -import { SqlEntityManager } from "@mikro-orm/postgresql" export const fileSystem = new FileSystem( join(__dirname, "../../integration-tests-migrations-many-to-one") @@ -55,19 +55,20 @@ describe("manyToOne - belongTo", () => { await createDatabase({ databaseName: dbName }, pgGodCredentials) - orm = await MikroORM.init({ - entities: [Team, User], - tsNode: true, - dbName, - password: pgGodCredentials.password, - host: pgGodCredentials.host, - user: pgGodCredentials.user, - type: "postgresql", - migrations: { - generator: CustomTsMigrationGenerator, - path: fileSystem.basePath, - }, - }) + orm = await MikroORM.init( + defineConfig({ + entities: [Team, User], + tsNode: true, + dbName, + password: pgGodCredentials.password, + host: pgGodCredentials.host, + user: pgGodCredentials.user, + migrations: { + generator: CustomTsMigrationGenerator, + path: fileSystem.basePath, + }, + }) + ) const migrator = orm.getMigrator() await migrator.createMigration() diff --git a/packages/core/utils/src/migrations/index.ts b/packages/core/utils/src/migrations/index.ts index b3f09f8268c75..3b3c9564695e5 100644 --- a/packages/core/utils/src/migrations/index.ts +++ b/packages/core/utils/src/migrations/index.ts @@ -4,7 +4,7 @@ import { MigrationResult, UmzugMigration, } from "@mikro-orm/migrations" -import { PostgreSqlDriver } from "@mikro-orm/postgresql" +import { defineConfig, PostgreSqlDriver } from "@mikro-orm/postgresql" import { EventEmitter } from "events" import { access, mkdir, writeFile } from "fs/promises" import { dirname } from "path" @@ -42,13 +42,15 @@ export class Migrations extends EventEmitter { return this.#configOrConnection as MikroORM } - return await MikroORM.init({ - ...this.#configOrConnection, - migrations: { - ...this.#configOrConnection.migrations, - silent: true, - }, - }) + return await MikroORM.init( + defineConfig({ + ...(this.#configOrConnection as any), + migrations: { + ...this.#configOrConnection.migrations, + silent: true, + }, + }) + ) } /** diff --git a/packages/core/utils/src/modules-sdk/__tests__/mikro-orm-cli-config-builder.spec.ts b/packages/core/utils/src/modules-sdk/__tests__/mikro-orm-cli-config-builder.spec.ts index 9d6d90af000d1..2c47ce8d92fed 100644 --- a/packages/core/utils/src/modules-sdk/__tests__/mikro-orm-cli-config-builder.spec.ts +++ b/packages/core/utils/src/modules-sdk/__tests__/mikro-orm-cli-config-builder.spec.ts @@ -19,7 +19,7 @@ describe("defineMikroOrmCliConfig", () => { expect(config).toEqual({ entities: [{}], - type: "postgresql", + driver: expect.any(Function), host: "127.0.0.1", user: "postgres", password: "", @@ -37,7 +37,7 @@ describe("defineMikroOrmCliConfig", () => { expect(config).toEqual({ entities: [{}], - type: "postgresql", + driver: expect.any(Function), dbName: "medusa-my-test", host: "127.0.0.1", user: "postgres", diff --git a/packages/core/utils/src/modules-sdk/medusa-internal-service.ts b/packages/core/utils/src/modules-sdk/medusa-internal-service.ts index 3689869adbe48..afce23f736dd8 100644 --- a/packages/core/utils/src/modules-sdk/medusa-internal-service.ts +++ b/packages/core/utils/src/modules-sdk/medusa-internal-service.ts @@ -2,9 +2,9 @@ import { BaseFilterable, Context, FilterQuery, - FilterQuery as InternalFilterQuery, FindConfig, InferEntityType, + FilterQuery as InternalFilterQuery, ModulesSdkTypes, PerformedActions, UpsertWithReplaceConfig, diff --git a/packages/core/utils/src/modules-sdk/mikro-orm-cli-config-builder.ts b/packages/core/utils/src/modules-sdk/mikro-orm-cli-config-builder.ts index 48bb1c62abb72..0030394a83e88 100644 --- a/packages/core/utils/src/modules-sdk/mikro-orm-cli-config-builder.ts +++ b/packages/core/utils/src/modules-sdk/mikro-orm-cli-config-builder.ts @@ -5,6 +5,7 @@ import type { EntitySchema, MikroORMOptions, } from "@mikro-orm/core" +import { defineConfig } from "@mikro-orm/postgresql" import { kebabCase } from "../common" import { CustomTsMigrationGenerator } from "../dal" import { DmlEntity, toMikroOrmEntities } from "../dml" @@ -21,7 +22,6 @@ type Options = Partial> & { type ReturnedOptions = Partial & { entities: MikroORMOptions["entities"] - type: MikroORMOptions["type"] migrations: MikroORMOptions["migrations"] } @@ -53,17 +53,16 @@ export function defineMikroOrmCliConfig( const normalizedModuleName = kebabCase(moduleName.replace("Service", "")) const databaseName = `medusa-${normalizedModuleName}` - return { - type: "postgresql", + return defineConfig({ dbName: databaseName, host: "127.0.0.1", user: "postgres", password: "", - ...options, + ...(options as any), entities, migrations: { generator: CustomTsMigrationGenerator, ...options.migrations, }, - } + }) as ReturnedOptions } diff --git a/packages/core/workflows-sdk/package.json b/packages/core/workflows-sdk/package.json index c3e0b1bf2e397..55b098372460c 100644 --- a/packages/core/workflows-sdk/package.json +++ b/packages/core/workflows-sdk/package.json @@ -27,10 +27,10 @@ "author": "Medusa", "license": "MIT", "devDependencies": { - "@mikro-orm/core": "5.9.7", - "@mikro-orm/knex": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/knex": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "awilix": "^8.0.1", @@ -47,10 +47,10 @@ "ulid": "^2.3.0" }, "peerDependencies": { - "@mikro-orm/core": "5.9.7", - "@mikro-orm/knex": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/knex": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "awilix": "^8.0.1", "express": "^4.21.0", "pg": "^8.13.0" diff --git a/packages/medusa-test-utils/package.json b/packages/medusa-test-utils/package.json index ffd30b5270c5f..cb30ef5128ff2 100644 --- a/packages/medusa-test-utils/package.json +++ b/packages/medusa-test-utils/package.json @@ -26,10 +26,10 @@ "license": "MIT", "devDependencies": { "@medusajs/framework": "^2.1.1", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/knex": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/knex": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "awilix": "^8.0.1", "jest": "^29.7.0", "pg": "^8.13.0", @@ -47,7 +47,7 @@ "peerDependencies": { "@medusajs/framework": "^2.0.0", "@medusajs/medusa": "^2.0.0", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/postgresql": "6.4.1", "awilix": "^8.0.1" }, "peerDependenciesMeta": { diff --git a/packages/medusa-test-utils/src/database.ts b/packages/medusa-test-utils/src/database.ts index df093c60080d4..2ee7e655609a9 100644 --- a/packages/medusa-test-utils/src/database.ts +++ b/packages/medusa-test-utils/src/database.ts @@ -1,4 +1,9 @@ -import { MikroORM, Options, SqlEntityManager } from "@mikro-orm/postgresql" +import { + defineConfig, + MikroORM, + Options, + SqlEntityManager, +} from "@mikro-orm/postgresql" import { createDatabase, dropDatabase } from "pg-god" const DB_HOST = process.env.DB_HOST ?? "localhost" @@ -35,8 +40,7 @@ export function getMikroOrmConfig({ }): Options { const DB_URL = clientUrl ?? getDatabaseURL() - return { - type: "postgresql", + return defineConfig({ clientUrl: DB_URL, entities: Object.values(mikroOrmEntities), schema: schema ?? process.env.MEDUSA_DB_SCHEMA, @@ -48,7 +52,7 @@ export function getMikroOrmConfig({ pathTs: pathToMigrations, silent: true, }, - } + }) } export interface TestDatabase { diff --git a/packages/medusa/package.json b/packages/medusa/package.json index fcc7bba9f8a1e..eac0c9e939405 100644 --- a/packages/medusa/package.json +++ b/packages/medusa/package.json @@ -126,10 +126,10 @@ }, "peerDependencies": { "@medusajs/framework": "^2.0.0", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/knex": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/knex": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "awilix": "^8.0.1" }, "gitHead": "cd1f5afa5aa8c0b15ea957008ee19f1d695cbd2e" diff --git a/packages/modules/api-key/package.json b/packages/modules/api-key/package.json index 08ba190b75b60..3d53d25b25bc2 100644 --- a/packages/modules/api-key/package.json +++ b/packages/modules/api-key/package.json @@ -38,7 +38,7 @@ "devDependencies": { "@medusajs/framework": "^2.1.1", "@medusajs/test-utils": "^2.1.1", - "@mikro-orm/cli": "5.9.7", + "@mikro-orm/cli": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", @@ -48,9 +48,9 @@ }, "peerDependencies": { "@medusajs/framework": "^2.0.0", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "awilix": "^8.0.1" } } diff --git a/packages/modules/auth/package.json b/packages/modules/auth/package.json index ffb21b3017d9a..864179bef98f3 100644 --- a/packages/modules/auth/package.json +++ b/packages/modules/auth/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.1", "@medusajs/test-utils": "^2.1.1", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", @@ -51,9 +51,9 @@ }, "peerDependencies": { "@medusajs/framework": "^2.0.0", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "awilix": "^8.0.1" } } diff --git a/packages/modules/cart/package.json b/packages/modules/cart/package.json index 4b7f1e5923c50..59bd124d5d691 100644 --- a/packages/modules/cart/package.json +++ b/packages/modules/cart/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.1", "@medusajs/test-utils": "^2.1.1", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", @@ -51,9 +51,9 @@ }, "peerDependencies": { "@medusajs/framework": "^2.0.0", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "awilix": "^8.0.1" } } diff --git a/packages/modules/currency/package.json b/packages/modules/currency/package.json index a4bce78deef5f..b629ec3a256f8 100644 --- a/packages/modules/currency/package.json +++ b/packages/modules/currency/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.1", "@medusajs/test-utils": "^2.1.1", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", @@ -51,9 +51,9 @@ }, "peerDependencies": { "@medusajs/framework": "^2.0.0", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "awilix": "^8.0.1" } } diff --git a/packages/modules/customer/package.json b/packages/modules/customer/package.json index 753e1011d5e98..0f57dd8ceb9fe 100644 --- a/packages/modules/customer/package.json +++ b/packages/modules/customer/package.json @@ -39,10 +39,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.1", "@medusajs/test-utils": "^2.1.1", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", @@ -52,9 +52,9 @@ }, "peerDependencies": { "@medusajs/framework": "^2.0.0", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "awilix": "^8.0.1" } } diff --git a/packages/modules/file/package.json b/packages/modules/file/package.json index 2b1bcb73141c8..ced805fa9482a 100644 --- a/packages/modules/file/package.json +++ b/packages/modules/file/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.1", "@medusajs/test-utils": "^2.1.1", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", diff --git a/packages/modules/fulfillment/package.json b/packages/modules/fulfillment/package.json index a49b314e3153e..7e76ae0fb22e2 100644 --- a/packages/modules/fulfillment/package.json +++ b/packages/modules/fulfillment/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.1", "@medusajs/test-utils": "^2.1.1", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", @@ -51,9 +51,9 @@ }, "peerDependencies": { "@medusajs/framework": "^2.0.0", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "awilix": "^8.0.1" } } diff --git a/packages/modules/fulfillment/src/models/fulfillment-item.ts b/packages/modules/fulfillment/src/models/fulfillment-item.ts index af55445f15076..046b1c9e71e23 100644 --- a/packages/modules/fulfillment/src/models/fulfillment-item.ts +++ b/packages/modules/fulfillment/src/models/fulfillment-item.ts @@ -81,7 +81,7 @@ export default class FulfillmentItem { columnType: "text", mapToPk: true, fieldName: "fulfillment_id", - onDelete: "cascade", + deleteRule: "cascade", }) @FulfillmentIdIndex.MikroORMIndex() fulfillment_id: string diff --git a/packages/modules/fulfillment/src/models/fulfillment-label.ts b/packages/modules/fulfillment/src/models/fulfillment-label.ts index 27b8164d62ea8..96a768f91f867 100644 --- a/packages/modules/fulfillment/src/models/fulfillment-label.ts +++ b/packages/modules/fulfillment/src/models/fulfillment-label.ts @@ -53,7 +53,7 @@ export default class FulfillmentLabel { columnType: "text", mapToPk: true, fieldName: "fulfillment_id", - onDelete: "cascade", + deleteRule: "cascade", }) @FulfillmentIdIndex.MikroORMIndex() fulfillment_id: string diff --git a/packages/modules/fulfillment/src/models/fulfillment.ts b/packages/modules/fulfillment/src/models/fulfillment.ts index dce04f0f34f26..2a244fa1d9fed 100644 --- a/packages/modules/fulfillment/src/models/fulfillment.ts +++ b/packages/modules/fulfillment/src/models/fulfillment.ts @@ -102,7 +102,7 @@ export default class Fulfillment { fieldName: "provider_id", mapToPk: true, nullable: true, - onDelete: "set null", + deleteRule: "set null", }) @FulfillmentProviderIdIndex.MikroORMIndex() provider_id: string @@ -112,7 +112,7 @@ export default class Fulfillment { fieldName: "shipping_option_id", nullable: true, mapToPk: true, - onDelete: "set null", + deleteRule: "set null", }) @FulfillmentShippingOptionIdIndex.MikroORMIndex() shipping_option_id: string | null = null @@ -131,7 +131,7 @@ export default class Fulfillment { owner: true, cascade: [Cascade.PERSIST, "soft-remove"] as any, nullable: true, - onDelete: "cascade", + deleteRule: "cascade", }) delivery_address!: Rel diff --git a/packages/modules/fulfillment/src/models/geo-zone.ts b/packages/modules/fulfillment/src/models/geo-zone.ts index fc7e2f9175488..fffd076695b28 100644 --- a/packages/modules/fulfillment/src/models/geo-zone.ts +++ b/packages/modules/fulfillment/src/models/geo-zone.ts @@ -79,7 +79,7 @@ export default class GeoZone { type: "text", mapToPk: true, fieldName: "service_zone_id", - onDelete: "cascade", + deleteRule: "cascade", }) @ServiceZoneIdIndex.MikroORMIndex() service_zone_id: string diff --git a/packages/modules/fulfillment/src/models/service-zone.ts b/packages/modules/fulfillment/src/models/service-zone.ts index 50b21a9f8711c..a3887c05f8399 100644 --- a/packages/modules/fulfillment/src/models/service-zone.ts +++ b/packages/modules/fulfillment/src/models/service-zone.ts @@ -66,7 +66,7 @@ export default class ServiceZone { type: "text", mapToPk: true, fieldName: "fulfillment_set_id", - onDelete: "cascade", + deleteRule: "cascade", }) @FulfillmentSetIdIndex.MikroORMIndex() fulfillment_set_id: string diff --git a/packages/modules/fulfillment/src/models/shipping-option-rule.ts b/packages/modules/fulfillment/src/models/shipping-option-rule.ts index a237c07b75c76..83bab4f2e81d8 100644 --- a/packages/modules/fulfillment/src/models/shipping-option-rule.ts +++ b/packages/modules/fulfillment/src/models/shipping-option-rule.ts @@ -57,7 +57,7 @@ export default class ShippingOptionRule { type: "text", mapToPk: true, fieldName: "shipping_option_id", - onDelete: "cascade", + deleteRule: "cascade", }) @ShippingOptionIdIndex.MikroORMIndex() shipping_option_id: string diff --git a/packages/modules/fulfillment/src/models/shipping-option-type.ts b/packages/modules/fulfillment/src/models/shipping-option-type.ts index 7425d2bb65ba9..2a8d8001942d7 100644 --- a/packages/modules/fulfillment/src/models/shipping-option-type.ts +++ b/packages/modules/fulfillment/src/models/shipping-option-type.ts @@ -45,7 +45,7 @@ export default class ShippingOptionType { @OneToOne(() => ShippingOption, (so) => so.type, { type: "text", - onDelete: "cascade", + deleteRule: "cascade", }) shipping_option: Rel diff --git a/packages/modules/fulfillment/src/models/shipping-option.ts b/packages/modules/fulfillment/src/models/shipping-option.ts index 5f110b24f127f..41ab6d10100a1 100644 --- a/packages/modules/fulfillment/src/models/shipping-option.ts +++ b/packages/modules/fulfillment/src/models/shipping-option.ts @@ -84,7 +84,7 @@ export default class ShippingOption { type: "text", fieldName: "service_zone_id", mapToPk: true, - onDelete: "cascade", + deleteRule: "cascade", }) @ServiceZoneIdIndex.MikroORMIndex() service_zone_id: string @@ -94,7 +94,7 @@ export default class ShippingOption { fieldName: "shipping_profile_id", mapToPk: true, nullable: true, - onDelete: "set null", + deleteRule: "set null", }) @ShippingProfileIdIndex.MikroORMIndex() shipping_profile_id: string | null @@ -136,7 +136,7 @@ export default class ShippingOption { cascade: [Cascade.PERSIST, "soft-remove"] as any, orphanRemoval: true, fieldName: "shipping_option_type_id", - onDelete: "cascade", + deleteRule: "cascade", }) type: Rel diff --git a/packages/modules/index/package.json b/packages/modules/index/package.json index 7da85e0e44b6f..8af9a19f520db 100644 --- a/packages/modules/index/package.json +++ b/packages/modules/index/package.json @@ -38,11 +38,11 @@ "devDependencies": { "@medusajs/framework": "^2.1.1", "@medusajs/test-utils": "^2.1.1", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/knex": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/knex": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", @@ -52,10 +52,10 @@ }, "peerDependencies": { "@medusajs/framework": "^2.0.0", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/knex": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/knex": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "awilix": "^8.0.1" } } diff --git a/packages/modules/inventory/package.json b/packages/modules/inventory/package.json index ad357cf2a7ad4..f7d9293639e31 100644 --- a/packages/modules/inventory/package.json +++ b/packages/modules/inventory/package.json @@ -25,10 +25,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.1", "@medusajs/test-utils": "^2.1.1", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", @@ -38,9 +38,9 @@ }, "peerDependencies": { "@medusajs/framework": "^2.0.0", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "awilix": "^8.0.1" }, "scripts": { diff --git a/packages/modules/link-modules/package.json b/packages/modules/link-modules/package.json index 99d3c045e10ce..5685b135ac68a 100644 --- a/packages/modules/link-modules/package.json +++ b/packages/modules/link-modules/package.json @@ -35,9 +35,9 @@ "devDependencies": { "@medusajs/framework": "^2.1.1", "@medusajs/test-utils": "^2.1.1", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "cross-env": "^5.2.1", @@ -48,9 +48,9 @@ }, "peerDependencies": { "@medusajs/framework": "^2.0.0", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "awilix": "^8.0.1" } } diff --git a/packages/modules/locking/package.json b/packages/modules/locking/package.json index f3ebd9a43efbf..91ee5f27515fc 100644 --- a/packages/modules/locking/package.json +++ b/packages/modules/locking/package.json @@ -34,10 +34,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.1", "@medusajs/test-utils": "^2.1.1", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", @@ -47,9 +47,9 @@ }, "peerDependencies": { "@medusajs/framework": "^2.0.0", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "awilix": "^8.0.1" } } diff --git a/packages/modules/notification/package.json b/packages/modules/notification/package.json index 543f209673e11..cdbce1a7d6224 100644 --- a/packages/modules/notification/package.json +++ b/packages/modules/notification/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.1", "@medusajs/test-utils": "^2.1.1", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", @@ -51,9 +51,9 @@ }, "peerDependencies": { "@medusajs/framework": "^2.0.0", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "awilix": "^8.0.1" } } diff --git a/packages/modules/order/package.json b/packages/modules/order/package.json index 849e1125cb7dc..df96243de817c 100644 --- a/packages/modules/order/package.json +++ b/packages/modules/order/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.1", "@medusajs/test-utils": "^2.1.1", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", @@ -51,9 +51,9 @@ }, "peerDependencies": { "@medusajs/framework": "^2.0.0", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "awilix": "^8.0.1" } } diff --git a/packages/modules/order/src/models/claim-item.ts b/packages/modules/order/src/models/claim-item.ts index fe90bc20f118e..cfb4155e9353f 100644 --- a/packages/modules/order/src/models/claim-item.ts +++ b/packages/modules/order/src/models/claim-item.ts @@ -69,7 +69,7 @@ export default class OrderClaimItem { columnType: "text", fieldName: "claim_id", mapToPk: true, - onDelete: "cascade", + deleteRule: "cascade", }) @ClaimIdIndex.MikroORMIndex() claim_id: string diff --git a/packages/modules/order/src/models/exchange-item.ts b/packages/modules/order/src/models/exchange-item.ts index 9564d39b8440a..ed4fccd62d909 100644 --- a/packages/modules/order/src/models/exchange-item.ts +++ b/packages/modules/order/src/models/exchange-item.ts @@ -53,7 +53,7 @@ export default class OrderExchangeItem { columnType: "text", fieldName: "exchange_id", mapToPk: true, - onDelete: "cascade", + deleteRule: "cascade", }) @ExchangeIdIndex.MikroORMIndex() exchange_id: string diff --git a/packages/modules/order/src/models/line-item-adjustment.ts b/packages/modules/order/src/models/line-item-adjustment.ts index 3fe70618a574b..25e0c49b1b0eb 100644 --- a/packages/modules/order/src/models/line-item-adjustment.ts +++ b/packages/modules/order/src/models/line-item-adjustment.ts @@ -22,7 +22,7 @@ export default class OrderLineItemAdjustment extends AdjustmentLine { entity: () => OrderLineItem, columnType: "text", fieldName: "item_id", - onDelete: "cascade", + deleteRule: "cascade", mapToPk: true, }) @ItemIdIndex.MikroORMIndex() diff --git a/packages/modules/order/src/models/order-change-action.ts b/packages/modules/order/src/models/order-change-action.ts index 70fb16a5e3125..c18cef2310c4f 100644 --- a/packages/modules/order/src/models/order-change-action.ts +++ b/packages/modules/order/src/models/order-change-action.ts @@ -83,7 +83,7 @@ export default class OrderChangeAction { entity: () => Order, columnType: "text", fieldName: "order_id", - onDelete: "cascade", + deleteRule: "cascade", mapToPk: true, nullable: true, }) @@ -151,7 +151,7 @@ export default class OrderChangeAction { entity: () => OrderChange, columnType: "text", fieldName: "order_change_id", - onDelete: "cascade", + deleteRule: "cascade", mapToPk: true, nullable: true, }) diff --git a/packages/modules/order/src/models/order-change.ts b/packages/modules/order/src/models/order-change.ts index efa172e7a4fef..b169c840b5162 100644 --- a/packages/modules/order/src/models/order-change.ts +++ b/packages/modules/order/src/models/order-change.ts @@ -84,7 +84,7 @@ export default class OrderChange { entity: () => Order, columnType: "text", fieldName: "order_id", - onDelete: "cascade", + deleteRule: "cascade", mapToPk: true, }) @OrderIdIndex.MikroORMIndex() diff --git a/packages/modules/order/src/models/order-summary.ts b/packages/modules/order/src/models/order-summary.ts index dd843b9d7f2bc..64e3acc948215 100644 --- a/packages/modules/order/src/models/order-summary.ts +++ b/packages/modules/order/src/models/order-summary.ts @@ -61,7 +61,7 @@ export default class OrderSummary { columnType: "text", fieldName: "order_id", mapToPk: true, - onDelete: "cascade", + deleteRule: "cascade", }) order_id: string diff --git a/packages/modules/order/src/models/return-item.ts b/packages/modules/order/src/models/return-item.ts index a0e78dd9d6b64..5acf5bf8accb1 100644 --- a/packages/modules/order/src/models/return-item.ts +++ b/packages/modules/order/src/models/return-item.ts @@ -87,7 +87,7 @@ export default class ReturnItem { columnType: "text", fieldName: "return_id", mapToPk: true, - onDelete: "cascade", + deleteRule: "cascade", }) @ReturnIdIndex.MikroORMIndex() return_id: string diff --git a/packages/modules/order/src/models/shipping-method-adjustment.ts b/packages/modules/order/src/models/shipping-method-adjustment.ts index 525869435598e..9a5b45afffe1d 100644 --- a/packages/modules/order/src/models/shipping-method-adjustment.ts +++ b/packages/modules/order/src/models/shipping-method-adjustment.ts @@ -23,7 +23,7 @@ export default class OrderShippingMethodAdjustment extends AdjustmentLine { columnType: "text", fieldName: "shipping_method_id", mapToPk: true, - onDelete: "cascade", + deleteRule: "cascade", }) @ShippingMethodIdIdIndex.MikroORMIndex() shipping_method_id: string diff --git a/packages/modules/order/src/models/shipping-method-tax-line.ts b/packages/modules/order/src/models/shipping-method-tax-line.ts index 1afba00809bdb..bee842a6c7356 100644 --- a/packages/modules/order/src/models/shipping-method-tax-line.ts +++ b/packages/modules/order/src/models/shipping-method-tax-line.ts @@ -23,7 +23,7 @@ export default class OrderShippingMethodTaxLine extends TaxLine { fieldName: "shipping_method_id", columnType: "text", mapToPk: true, - onDelete: "cascade", + deleteRule: "cascade", }) @ShippingMethodIdIdIndex.MikroORMIndex() shipping_method_id: string diff --git a/packages/modules/order/src/models/transaction.ts b/packages/modules/order/src/models/transaction.ts index 42ca89608c469..9182f7b6b30fa 100644 --- a/packages/modules/order/src/models/transaction.ts +++ b/packages/modules/order/src/models/transaction.ts @@ -87,7 +87,7 @@ export default class OrderTransaction { entity: () => Order, columnType: "text", fieldName: "order_id", - onDelete: "cascade", + deleteRule: "cascade", mapToPk: true, }) @OrderIdIndex.MikroORMIndex() diff --git a/packages/modules/payment/package.json b/packages/modules/payment/package.json index c88efe58681a9..f320979b4ff00 100644 --- a/packages/modules/payment/package.json +++ b/packages/modules/payment/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.1", "@medusajs/test-utils": "^2.1.1", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", @@ -51,9 +51,9 @@ }, "peerDependencies": { "@medusajs/framework": "^2.0.0", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "awilix": "^8.0.1" } } diff --git a/packages/modules/pricing/package.json b/packages/modules/pricing/package.json index e5e036288bebc..94b429e61531b 100644 --- a/packages/modules/pricing/package.json +++ b/packages/modules/pricing/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.1", "@medusajs/test-utils": "^2.1.1", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", @@ -51,9 +51,9 @@ }, "peerDependencies": { "@medusajs/framework": "^2.0.0", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "awilix": "^8.0.1" } } diff --git a/packages/modules/product/integration-tests/__tests__/product.ts b/packages/modules/product/integration-tests/__tests__/product.ts index f6116af5e5f48..abb55eec7b000 100644 --- a/packages/modules/product/integration-tests/__tests__/product.ts +++ b/packages/modules/product/integration-tests/__tests__/product.ts @@ -13,10 +13,10 @@ import { ProductDTO, } from "@medusajs/framework/types" import { + kebabCase, Module, Modules, ProductStatus, - kebabCase, toMikroORMEntity, } from "@medusajs/framework/utils" import { moduleIntegrationTestRunner } from "@medusajs/test-utils" @@ -323,7 +323,7 @@ moduleIntegrationTestRunner({ }) describe("list", () => { - it("should list all product that match the free text search", async () => { + it.only("should list all product that match the free text search", async () => { const data = buildProductOnlyData({ title: "test product", }) @@ -577,7 +577,7 @@ moduleIntegrationTestRunner({ }) it("should filter by collection relation and scope fields", async () => { - const products = await service.list( + const products = await moduleService.listProducts( { id: workingProduct.id, collection_id: workingCollection.id, @@ -593,10 +593,8 @@ moduleIntegrationTestRunner({ } ) - const serialized = JSON.parse(JSON.stringify(products)) - - expect(serialized.length).toEqual(1) - expect(serialized).toEqual([ + expect(products.length).toEqual(1) + expect(products).toEqual([ { id: workingProduct.id, title: workingProduct.title, @@ -612,7 +610,7 @@ moduleIntegrationTestRunner({ }) it("should filter by collection when multiple collection ids are passed", async () => { - const products = await service.list( + const products = await moduleService.listProducts( { collection_id: [workingCollection.id, workingCollectionTwo.id], }, @@ -627,10 +625,8 @@ moduleIntegrationTestRunner({ } ) - const serialized = JSON.parse(JSON.stringify(products)) - - expect(serialized.length).toEqual(2) - expect(serialized).toEqual([ + expect(products.length).toEqual(2) + expect(products).toEqual([ { id: workingProduct.id, title: workingProduct.title, diff --git a/packages/modules/product/package.json b/packages/modules/product/package.json index b116ed2e1862a..2d83c87ad78a8 100644 --- a/packages/modules/product/package.json +++ b/packages/modules/product/package.json @@ -29,7 +29,7 @@ "resolve:aliases": "tsc --showConfig -p tsconfig.json > tsconfig.resolved.json && tsc-alias -p tsconfig.resolved.json && rimraf tsconfig.resolved.json", "build": "rimraf dist && tsc --build && npm run resolve:aliases", "test": "jest --runInBand --bail --forceExit -- src/**/__tests__/**/*.ts", - "test:integration": "jest --forceExit -- integration-tests/**/__tests__/**/*.ts", + "test:integration": "jest --forceExit", "migration:initial": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm migration:create --initial", "migration:create": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm migration:create", "migration:up": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm migration:up", @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.1", "@medusajs/test-utils": "^2.1.1", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "faker": "^5.5.3", @@ -52,9 +52,9 @@ }, "peerDependencies": { "@medusajs/framework": "^2.0.0", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "awilix": "^8.0.1" } } diff --git a/packages/modules/product/src/models/product.ts b/packages/modules/product/src/models/product.ts index f56c5d27c6213..3ad4129ed2bc3 100644 --- a/packages/modules/product/src/models/product.ts +++ b/packages/modules/product/src/models/product.ts @@ -1,12 +1,12 @@ import { model, ProductUtils } from "@medusajs/framework/utils" -import ProductTag from "./product-tag" -import ProductType from "./product-type" +import ProductCategory from "./product-category" +import ProductCollection from "./product-collection" import ProductImage from "./product-image" import ProductOption from "./product-option" +import ProductTag from "./product-tag" +import ProductType from "./product-type" import ProductVariant from "./product-variant" -import ProductCategory from "./product-category" -import ProductCollection from "./product-collection" const Product = model .define("Product", { diff --git a/packages/modules/product/src/repositories/product-category.ts b/packages/modules/product/src/repositories/product-category.ts index e6f1429ff7d29..f395d806d0dd5 100644 --- a/packages/modules/product/src/repositories/product-category.ts +++ b/packages/modules/product/src/repositories/product-category.ts @@ -527,7 +527,10 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito const newMpath = `${newBaseMpath}.${category.id}` category.mpath = newMpath for (let child of category.category_children) { - child = manager.getReference(ProductCategory.name, child.id) + child = manager.getReference( + ProductCategory.name, + child.id + ) as any manager.assign( child, categoryDataChildrenMap.get(child.id) ?? {} diff --git a/packages/modules/promotion/package.json b/packages/modules/promotion/package.json index 8ab1e86695848..e4a11ecfce87e 100644 --- a/packages/modules/promotion/package.json +++ b/packages/modules/promotion/package.json @@ -29,7 +29,7 @@ "resolve:aliases": "tsc --showConfig -p tsconfig.json > tsconfig.resolved.json && tsc-alias -p tsconfig.resolved.json && rimraf tsconfig.resolved.json", "build": "rimraf dist && tsc --build && npm run resolve:aliases", "test": "jest --runInBand --passWithNoTests --bail --forceExit -- src", - "test:integration": "jest --forceExit -- integration-tests/**/__tests__/**/*.ts", + "test:integration": "jest --forceExit ", "migration:initial": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm migration:create --initial", "migration:create": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm migration:create", "migration:up": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm migration:up", @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.1", "@medusajs/test-utils": "^2.1.1", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", @@ -51,9 +51,9 @@ }, "peerDependencies": { "@medusajs/framework": "^2.0.0", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "awilix": "^8.0.1" } } diff --git a/packages/modules/providers/locking-postgres/package.json b/packages/modules/providers/locking-postgres/package.json index 538fb3051ad9b..876715706f8fc 100644 --- a/packages/modules/providers/locking-postgres/package.json +++ b/packages/modules/providers/locking-postgres/package.json @@ -21,10 +21,10 @@ "license": "MIT", "devDependencies": { "@medusajs/framework": "^2.1.1", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", diff --git a/packages/modules/region/package.json b/packages/modules/region/package.json index aa78b040f73a3..80cc3cb15ec4e 100644 --- a/packages/modules/region/package.json +++ b/packages/modules/region/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.1", "@medusajs/test-utils": "^2.1.1", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", @@ -51,9 +51,9 @@ }, "peerDependencies": { "@medusajs/framework": "^2.0.0", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "awilix": "^8.0.1" } } diff --git a/packages/modules/sales-channel/package.json b/packages/modules/sales-channel/package.json index 2cdf2b318ff8e..d65d07eeb8f1e 100644 --- a/packages/modules/sales-channel/package.json +++ b/packages/modules/sales-channel/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.1", "@medusajs/test-utils": "^2.1.1", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", @@ -51,9 +51,9 @@ }, "peerDependencies": { "@medusajs/framework": "^2.0.0", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "awilix": "^8.0.1" } } diff --git a/packages/modules/stock-location/package.json b/packages/modules/stock-location/package.json index e890b77915173..b1b48bb83a155 100644 --- a/packages/modules/stock-location/package.json +++ b/packages/modules/stock-location/package.json @@ -25,10 +25,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.1", "@medusajs/test-utils": "^2.1.1", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", @@ -38,9 +38,9 @@ }, "peerDependencies": { "@medusajs/framework": "^2.0.0", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "awilix": "^8.0.1" }, "scripts": { diff --git a/packages/modules/store/package.json b/packages/modules/store/package.json index 56b32ad1d0ebe..99cea784372b5 100644 --- a/packages/modules/store/package.json +++ b/packages/modules/store/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.1", "@medusajs/test-utils": "^2.1.1", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", @@ -51,9 +51,9 @@ }, "peerDependencies": { "@medusajs/framework": "^2.0.0", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "awilix": "^8.0.1" } } diff --git a/packages/modules/tax/package.json b/packages/modules/tax/package.json index 35e11c53c0233..cb6da5ae397ae 100644 --- a/packages/modules/tax/package.json +++ b/packages/modules/tax/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.1", "@medusajs/test-utils": "^2.1.1", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", @@ -51,9 +51,9 @@ }, "peerDependencies": { "@medusajs/framework": "^2.0.0", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "awilix": "^8.0.1" } } diff --git a/packages/modules/user/package.json b/packages/modules/user/package.json index b07574fd4f89f..3b7e6a5ea6320 100644 --- a/packages/modules/user/package.json +++ b/packages/modules/user/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.1", "@medusajs/test-utils": "^2.1.1", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", @@ -54,9 +54,9 @@ }, "peerDependencies": { "@medusajs/framework": "^2.0.0", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "awilix": "^8.0.1" } } diff --git a/packages/modules/workflow-engine-inmemory/package.json b/packages/modules/workflow-engine-inmemory/package.json index f811c51fbbd1a..692a692578140 100644 --- a/packages/modules/workflow-engine-inmemory/package.json +++ b/packages/modules/workflow-engine-inmemory/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.1", "@medusajs/test-utils": "^2.1.1", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", @@ -55,9 +55,9 @@ }, "peerDependencies": { "@medusajs/framework": "^2.0.0", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "awilix": "^8.0.1" } } diff --git a/packages/modules/workflow-engine-redis/package.json b/packages/modules/workflow-engine-redis/package.json index f459c4a42bfbd..80cd0ec1cfd97 100644 --- a/packages/modules/workflow-engine-redis/package.json +++ b/packages/modules/workflow-engine-redis/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.1", "@medusajs/test-utils": "^2.1.1", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", @@ -56,9 +56,9 @@ }, "peerDependencies": { "@medusajs/framework": "^2.0.0", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "awilix": "^8.0.1" } } diff --git a/yarn.lock b/yarn.lock index bdcdbac69daef..9913c1cc00842 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5316,7 +5316,7 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.1 "@medusajs/test-utils": ^2.1.1 - "@mikro-orm/cli": 5.9.7 + "@mikro-orm/cli": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -5325,9 +5325,9 @@ __metadata: typescript: ^5.6.2 peerDependencies: "@medusajs/framework": ^2.0.0 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 awilix: ^8.0.1 languageName: unknown linkType: soft @@ -5387,10 +5387,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.1 "@medusajs/test-utils": ^2.1.1 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -5399,9 +5399,9 @@ __metadata: typescript: ^5.6.2 peerDependencies: "@medusajs/framework": ^2.0.0 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 awilix: ^8.0.1 languageName: unknown linkType: soft @@ -5444,10 +5444,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.1 "@medusajs/test-utils": ^2.1.1 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -5456,9 +5456,9 @@ __metadata: typescript: ^5.6.2 peerDependencies: "@medusajs/framework": ^2.0.0 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 awilix: ^8.0.1 languageName: unknown linkType: soft @@ -5469,10 +5469,10 @@ __metadata: dependencies: "@medusajs/telemetry": ^2.1.1 "@medusajs/utils": 2.1.1 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/knex": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/knex": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 "@types/express": ^4.17.17 @@ -5503,10 +5503,10 @@ __metadata: winston: ^3.8.2 yargs: ^15.3.1 peerDependencies: - "@mikro-orm/core": 5.9.7 - "@mikro-orm/knex": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/knex": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 awilix: ^8.0.1 pg: ^8.13.0 bin: @@ -5519,10 +5519,10 @@ __metadata: resolution: "@medusajs/core-flows@workspace:packages/core/core-flows" dependencies: "@medusajs/framework": ^2.1.1 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/knex": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/knex": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 awilix: ^8.0.1 @@ -5544,10 +5544,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.1 "@medusajs/test-utils": ^2.1.1 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -5556,9 +5556,9 @@ __metadata: typescript: ^5.6.2 peerDependencies: "@medusajs/framework": ^2.0.0 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 awilix: ^8.0.1 languageName: unknown linkType: soft @@ -5569,10 +5569,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.1 "@medusajs/test-utils": ^2.1.1 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -5581,9 +5581,9 @@ __metadata: typescript: ^5.6.2 peerDependencies: "@medusajs/framework": ^2.0.0 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 awilix: ^8.0.1 languageName: unknown linkType: soft @@ -5719,10 +5719,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.1 "@medusajs/test-utils": ^2.1.1 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -5747,10 +5747,10 @@ __metadata: "@medusajs/types": ^2.1.1 "@medusajs/utils": ^2.1.1 "@medusajs/workflows-sdk": ^2.1.1 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/knex": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/knex": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@opentelemetry/api": ^1.9.0 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 @@ -5776,11 +5776,11 @@ __metadata: zod: 3.22.4 peerDependencies: "@medusajs/cli": ^2.0.0 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/knex": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/knex": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 awilix: ^8.0.1 ioredis: ^5.4.1 pg: ^8.13.0 @@ -5818,10 +5818,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.1 "@medusajs/test-utils": ^2.1.1 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -5830,9 +5830,9 @@ __metadata: typescript: ^5.6.2 peerDependencies: "@medusajs/framework": ^2.0.0 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 awilix: ^8.0.1 languageName: unknown linkType: soft @@ -5877,11 +5877,11 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.1 "@medusajs/test-utils": ^2.1.1 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/knex": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/knex": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -5890,10 +5890,10 @@ __metadata: typescript: ^5.6.2 peerDependencies: "@medusajs/framework": ^2.0.0 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/knex": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/knex": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 awilix: ^8.0.1 languageName: unknown linkType: soft @@ -5904,10 +5904,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.1 "@medusajs/test-utils": ^2.1.1 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -5916,9 +5916,9 @@ __metadata: typescript: ^5.6.2 peerDependencies: "@medusajs/framework": ^2.0.0 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 awilix: ^8.0.1 languageName: unknown linkType: soft @@ -5943,9 +5943,9 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.1 "@medusajs/test-utils": ^2.1.1 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 cross-env: ^5.2.1 @@ -5955,9 +5955,9 @@ __metadata: typescript: ^5.6.2 peerDependencies: "@medusajs/framework": ^2.0.0 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 awilix: ^8.0.1 languageName: unknown linkType: soft @@ -5967,10 +5967,10 @@ __metadata: resolution: "@medusajs/locking-postgres@workspace:packages/modules/providers/locking-postgres" dependencies: "@medusajs/framework": ^2.1.1 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -6003,10 +6003,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.1 "@medusajs/test-utils": ^2.1.1 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -6015,9 +6015,9 @@ __metadata: typescript: ^5.6.2 peerDependencies: "@medusajs/framework": ^2.0.0 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 awilix: ^8.0.1 languageName: unknown linkType: soft @@ -6134,10 +6134,10 @@ __metadata: zod: 3.22.4 peerDependencies: "@medusajs/framework": ^2.0.0 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/knex": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/knex": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 awilix: ^8.0.1 languageName: unknown linkType: soft @@ -6149,10 +6149,10 @@ __metadata: "@medusajs/orchestration": ^2.1.1 "@medusajs/types": ^2.1.1 "@medusajs/utils": ^2.1.1 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/knex": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/knex": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 awilix: ^8.0.1 @@ -6162,10 +6162,10 @@ __metadata: rimraf: ^5.0.1 typescript: ^5.6.2 peerDependencies: - "@mikro-orm/core": 5.9.7 - "@mikro-orm/knex": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/knex": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 awilix: ^8.0.1 express: ^4.21.0 pg: ^8.13.0 @@ -6209,10 +6209,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.1 "@medusajs/test-utils": ^2.1.1 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -6221,9 +6221,9 @@ __metadata: typescript: ^5.6.2 peerDependencies: "@medusajs/framework": ^2.0.0 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 awilix: ^8.0.1 languageName: unknown linkType: soft @@ -6243,10 +6243,10 @@ __metadata: dependencies: "@medusajs/types": ^2.1.1 "@medusajs/utils": ^2.1.1 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/knex": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/knex": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 awilix: ^8.0.1 @@ -6255,10 +6255,10 @@ __metadata: rimraf: ^5.0.1 typescript: ^5.6.2 peerDependencies: - "@mikro-orm/core": 5.9.7 - "@mikro-orm/knex": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/knex": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 awilix: ^8.0.1 express: ^4.21.0 pg: ^8.13.0 @@ -6271,10 +6271,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.1 "@medusajs/test-utils": ^2.1.1 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -6283,9 +6283,9 @@ __metadata: typescript: ^5.6.2 peerDependencies: "@medusajs/framework": ^2.0.0 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 awilix: ^8.0.1 languageName: unknown linkType: soft @@ -6313,10 +6313,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.1 "@medusajs/test-utils": ^2.1.1 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -6325,9 +6325,9 @@ __metadata: typescript: ^5.6.2 peerDependencies: "@medusajs/framework": ^2.0.0 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 awilix: ^8.0.1 languageName: unknown linkType: soft @@ -6338,10 +6338,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.1 "@medusajs/test-utils": ^2.1.1 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -6350,9 +6350,9 @@ __metadata: typescript: ^5.6.2 peerDependencies: "@medusajs/framework": ^2.0.0 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 awilix: ^8.0.1 languageName: unknown linkType: soft @@ -6363,10 +6363,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.1 "@medusajs/test-utils": ^2.1.1 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 faker: ^5.5.3 @@ -6376,9 +6376,9 @@ __metadata: typescript: ^5.6.2 peerDependencies: "@medusajs/framework": ^2.0.0 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 awilix: ^8.0.1 languageName: unknown linkType: soft @@ -6389,10 +6389,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.1 "@medusajs/test-utils": ^2.1.1 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -6401,9 +6401,9 @@ __metadata: typescript: ^5.6.2 peerDependencies: "@medusajs/framework": ^2.0.0 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 awilix: ^8.0.1 languageName: unknown linkType: soft @@ -6414,10 +6414,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.1 "@medusajs/test-utils": ^2.1.1 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -6426,9 +6426,9 @@ __metadata: typescript: ^5.6.2 peerDependencies: "@medusajs/framework": ^2.0.0 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 awilix: ^8.0.1 languageName: unknown linkType: soft @@ -6439,10 +6439,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.1 "@medusajs/test-utils": ^2.1.1 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -6451,9 +6451,9 @@ __metadata: typescript: ^5.6.2 peerDependencies: "@medusajs/framework": ^2.0.0 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 awilix: ^8.0.1 languageName: unknown linkType: soft @@ -6464,10 +6464,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.1 "@medusajs/test-utils": ^2.1.1 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -6476,9 +6476,9 @@ __metadata: typescript: ^5.6.2 peerDependencies: "@medusajs/framework": ^2.0.0 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 awilix: ^8.0.1 languageName: unknown linkType: soft @@ -6489,10 +6489,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.1 "@medusajs/test-utils": ^2.1.1 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -6501,9 +6501,9 @@ __metadata: typescript: ^5.6.2 peerDependencies: "@medusajs/framework": ^2.0.0 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 awilix: ^8.0.1 languageName: unknown linkType: soft @@ -6514,10 +6514,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.1 "@medusajs/test-utils": ^2.1.1 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -6526,9 +6526,9 @@ __metadata: typescript: ^5.6.2 peerDependencies: "@medusajs/framework": ^2.0.0 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 awilix: ^8.0.1 languageName: unknown linkType: soft @@ -6560,10 +6560,10 @@ __metadata: resolution: "@medusajs/test-utils@workspace:packages/medusa-test-utils" dependencies: "@medusajs/framework": ^2.1.1 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/knex": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/knex": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@types/express": ^4.17.17 awilix: ^8.0.1 axios: ^0.21.4 @@ -6578,7 +6578,7 @@ __metadata: peerDependencies: "@medusajs/framework": ^2.0.0 "@medusajs/medusa": ^2.0.0 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/postgresql": 6.4.1 awilix: ^8.0.1 peerDependenciesMeta: "@medusajs/medusa": @@ -6728,10 +6728,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.1 "@medusajs/test-utils": ^2.1.1 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -6741,9 +6741,9 @@ __metadata: typescript: ^5.6.2 peerDependencies: "@medusajs/framework": ^2.0.0 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 awilix: ^8.0.1 languageName: unknown linkType: soft @@ -6757,10 +6757,10 @@ __metadata: "@graphql-tools/merge": ^9.0.7 "@graphql-tools/schema": ^10.0.6 "@medusajs/types": ^2.1.1 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/knex": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/knex": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 "@types/express": ^4.17.21 @@ -6782,10 +6782,10 @@ __metadata: typescript: ^5.6.2 ulid: ^2.3.0 peerDependencies: - "@mikro-orm/core": 5.9.7 - "@mikro-orm/knex": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/knex": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 awilix: ^8.0.1 express: ^4.21.0 pg: ^8.13.0 @@ -6798,10 +6798,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.1 "@medusajs/test-utils": ^2.1.1 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 cron-parser: ^4.9.0 @@ -6812,9 +6812,9 @@ __metadata: ulid: ^2.3.0 peerDependencies: "@medusajs/framework": ^2.0.0 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 awilix: ^8.0.1 languageName: unknown linkType: soft @@ -6825,10 +6825,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.1 "@medusajs/test-utils": ^2.1.1 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 bullmq: 5.13.0 @@ -6840,9 +6840,9 @@ __metadata: ulid: ^2.3.0 peerDependencies: "@medusajs/framework": ^2.0.0 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 awilix: ^8.0.1 languageName: unknown linkType: soft @@ -6855,10 +6855,10 @@ __metadata: "@medusajs/orchestration": ^2.1.1 "@medusajs/types": ^2.1.1 "@medusajs/utils": ^2.1.1 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/knex": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/knex": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 awilix: ^8.0.1 @@ -6868,183 +6868,96 @@ __metadata: typescript: ^5.6.2 ulid: ^2.3.0 peerDependencies: - "@mikro-orm/core": 5.9.7 - "@mikro-orm/knex": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/knex": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 awilix: ^8.0.1 express: ^4.21.0 pg: ^8.13.0 languageName: unknown linkType: soft -"@mikro-orm/cli@npm:5.9.7": - version: 5.9.7 - resolution: "@mikro-orm/cli@npm:5.9.7" +"@mikro-orm/cli@npm:6.4.1": + version: 6.4.1 + resolution: "@mikro-orm/cli@npm:6.4.1" dependencies: "@jercle/yargonaut": 1.1.5 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/knex": 5.9.7 - fs-extra: 11.1.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/knex": 6.4.1 + fs-extra: 11.2.0 tsconfig-paths: 4.2.0 yargs: 17.7.2 - peerDependencies: - "@mikro-orm/better-sqlite": ^5.0.0 - "@mikro-orm/entity-generator": ^5.0.0 - "@mikro-orm/mariadb": ^5.0.0 - "@mikro-orm/migrations": ^5.0.0 - "@mikro-orm/migrations-mongodb": ^5.0.0 - "@mikro-orm/mongodb": ^5.0.0 - "@mikro-orm/mysql": ^5.0.0 - "@mikro-orm/postgresql": ^5.0.0 - "@mikro-orm/seeder": ^5.0.0 - "@mikro-orm/sqlite": ^5.0.0 - peerDependenciesMeta: - "@mikro-orm/better-sqlite": - optional: true - "@mikro-orm/entity-generator": - optional: true - "@mikro-orm/mariadb": - optional: true - "@mikro-orm/migrations": - optional: true - "@mikro-orm/migrations-mongodb": - optional: true - "@mikro-orm/mongodb": - optional: true - "@mikro-orm/mysql": - optional: true - "@mikro-orm/postgresql": - optional: true - "@mikro-orm/seeder": - optional: true - "@mikro-orm/sqlite": - optional: true bin: - mikro-orm: cli.js - mikro-orm-esm: esm.js - checksum: 2b0f430485ff4e25a0ee53d776a30832d8b53c83db8f70d2d5305039c042384714e9525169e9bfd897f1c9936242aaf80aaf9e9f917c8894517343cc14f56987 + mikro-orm: ./cli + mikro-orm-esm: ./esm + checksum: 6b92bb031243de3e0d3ec82d596ac740994230b82cc5efc45e1e916325fca15868b6a0b440ceaf8b60097c8929cd1e960b3b986ca1d5f13f97b4de4a794672c0 languageName: node linkType: hard -"@mikro-orm/core@npm:5.9.7": - version: 5.9.7 - resolution: "@mikro-orm/core@npm:5.9.7" +"@mikro-orm/core@npm:6.4.1": + version: 6.4.1 + resolution: "@mikro-orm/core@npm:6.4.1" dependencies: - acorn-loose: 8.3.0 - acorn-walk: 8.2.0 - dotenv: 16.3.1 - fs-extra: 11.1.1 + dataloader: 2.2.3 + dotenv: 16.4.7 + esprima: 4.0.1 + fs-extra: 11.2.0 globby: 11.1.0 - mikro-orm: 5.9.7 - reflect-metadata: 0.1.13 - peerDependencies: - "@mikro-orm/better-sqlite": ^5.0.0 - "@mikro-orm/entity-generator": ^5.0.0 - "@mikro-orm/mariadb": ^5.0.0 - "@mikro-orm/migrations": ^5.0.0 - "@mikro-orm/migrations-mongodb": ^5.0.0 - "@mikro-orm/mongodb": ^5.0.0 - "@mikro-orm/mysql": ^5.0.0 - "@mikro-orm/postgresql": ^5.0.0 - "@mikro-orm/seeder": ^5.0.0 - "@mikro-orm/sqlite": ^5.0.0 - peerDependenciesMeta: - "@mikro-orm/better-sqlite": - optional: true - "@mikro-orm/entity-generator": - optional: true - "@mikro-orm/mariadb": - optional: true - "@mikro-orm/migrations": - optional: true - "@mikro-orm/migrations-mongodb": - optional: true - "@mikro-orm/mongodb": - optional: true - "@mikro-orm/mysql": - optional: true - "@mikro-orm/postgresql": - optional: true - "@mikro-orm/seeder": - optional: true - "@mikro-orm/sqlite": - optional: true - checksum: f58ad6b717571b6c9d4f880a886a34f7de51e7d299c93be5ac9b0733c41fdd22278eae14ca5a1e1e7efb045bc36caa83b639745fc0be7b5a696e49b13bdbbd03 + mikro-orm: 6.4.1 + reflect-metadata: 0.2.2 + checksum: 2ff7c4c84ed10433c13896fd5716b57ffe4d85cb51bc244184ace413daa81ca91e9cf021f6fb2e87f520efe7f59f0d32080a99e703a6bf83af683160b70b2ce1 languageName: node linkType: hard -"@mikro-orm/knex@npm:5.9.7": - version: 5.9.7 - resolution: "@mikro-orm/knex@npm:5.9.7" +"@mikro-orm/knex@npm:6.4.1": + version: 6.4.1 + resolution: "@mikro-orm/knex@npm:6.4.1" dependencies: - fs-extra: 11.1.1 - knex: 2.5.1 + fs-extra: 11.2.0 + knex: 3.1.0 sqlstring: 2.3.3 peerDependencies: - "@mikro-orm/core": ^5.0.0 - "@mikro-orm/entity-generator": ^5.0.0 - "@mikro-orm/migrations": ^5.0.0 + "@mikro-orm/core": ^6.0.0 better-sqlite3: "*" - mssql: "*" - mysql: "*" - mysql2: "*" - pg: "*" - sqlite3: "*" + libsql: "*" + mariadb: "*" peerDependenciesMeta: - "@mikro-orm/entity-generator": - optional: true - "@mikro-orm/migrations": - optional: true better-sqlite3: optional: true - mssql: - optional: true - mysql: - optional: true - mysql2: - optional: true - pg: + libsql: optional: true - sqlite3: + mariadb: optional: true - checksum: 2cce6ef6907d0785e84a9c801980e58ddd3539dbd3dd0b0ced1e3ccddcbc5dfb704816abb97ae7d9c608d6b30d842dd1f59a6ea97ca1d854ebd55df303070500 + checksum: 3692e21978a112b7b8384b5ef1efccb0084f4f89bd0d07c217ea12eb9f79c05623d2d49ca37b3f6800b103b0e0ce700f9ba03d95dfa3db4d92a6bd650b4c3b41 languageName: node linkType: hard -"@mikro-orm/migrations@npm:5.9.7": - version: 5.9.7 - resolution: "@mikro-orm/migrations@npm:5.9.7" +"@mikro-orm/migrations@npm:6.4.1": + version: 6.4.1 + resolution: "@mikro-orm/migrations@npm:6.4.1" dependencies: - "@mikro-orm/knex": 5.9.7 - fs-extra: 11.1.1 - knex: 2.5.1 - umzug: 3.3.1 + "@mikro-orm/knex": 6.4.1 + fs-extra: 11.2.0 + umzug: 3.8.2 peerDependencies: - "@mikro-orm/core": ^5.0.0 - checksum: 3b1c3e449d2aee7ed7f03153e17e2772423115b895836e4ece40c9b318849d8de9cce1ad9fa545a8ef54fa7fe5ab474c3444e2c598ebc9f3e070fe382882862a + "@mikro-orm/core": ^6.0.0 + checksum: 67a8f46e10c34c29df2e548be2840fd63e059e5d9421f9937d536aa68768cbc40b339451a3770a288716650774d22755d763968ccd3aee453516d7e4f08c5218 languageName: node linkType: hard -"@mikro-orm/postgresql@npm:5.9.7": - version: 5.9.7 - resolution: "@mikro-orm/postgresql@npm:5.9.7" +"@mikro-orm/postgresql@npm:6.4.1": + version: 6.4.1 + resolution: "@mikro-orm/postgresql@npm:6.4.1" dependencies: - "@mikro-orm/knex": 5.9.7 - pg: 8.11.3 + "@mikro-orm/knex": 6.4.1 + pg: 8.13.1 + postgres-array: 3.0.2 + postgres-date: 2.1.0 + postgres-interval: 4.0.2 peerDependencies: - "@mikro-orm/core": ^5.0.0 - "@mikro-orm/entity-generator": ^5.0.0 - "@mikro-orm/migrations": ^5.0.0 - "@mikro-orm/seeder": ^5.0.0 - peerDependenciesMeta: - "@mikro-orm/entity-generator": - optional: true - "@mikro-orm/migrations": - optional: true - "@mikro-orm/seeder": - optional: true - checksum: 9380c0a5795fe6c25448a5c302877043a0239d25e087a0dec4ebca63e8f06a6af9435953a55141ac8317cb14e2b141df4c10c4615be1a1deecc5cce7127bf42c + "@mikro-orm/core": ^6.0.0 + checksum: 6d4ede8d20fc3a11e7bd19a966079e849c11bef909f80a343e3c1e1d8a00545ef5c7b853dbbc22d0165ed84269488201a91316667134b29df7cd8d306b924dae languageName: node linkType: hard @@ -14827,22 +14740,6 @@ __metadata: languageName: node linkType: hard -"acorn-loose@npm:8.3.0": - version: 8.3.0 - resolution: "acorn-loose@npm:8.3.0" - dependencies: - acorn: ^8.5.0 - checksum: 970f790a584a2f1703a04711cdc588f424fd7bc2fb37ad8e0b9d6ceaf9c8c6a77f9ce102ce5250259fc96aedbdf346546ed1b496299bc13ed4d1b6fdb2d92f61 - languageName: node - linkType: hard - -"acorn-walk@npm:8.2.0": - version: 8.2.0 - resolution: "acorn-walk@npm:8.2.0" - checksum: dbe92f5b2452c93e960c5594e666dd1fae141b965ff2cb4a1e1d0381e3e4db4274c5ce4ffa3d681a86ca2a8d4e29d5efc0670a08e23fd2800051ea387df56ca2 - languageName: node - linkType: hard - "acorn-walk@npm:^6.0.1": version: 6.2.0 resolution: "acorn-walk@npm:6.2.0" @@ -14882,7 +14779,7 @@ __metadata: languageName: node linkType: hard -"acorn@npm:^8.10.0, acorn@npm:^8.11.3, acorn@npm:^8.4.1, acorn@npm:^8.5.0, acorn@npm:^8.8.2, acorn@npm:^8.9.0": +"acorn@npm:^8.10.0, acorn@npm:^8.11.3, acorn@npm:^8.4.1, acorn@npm:^8.8.2, acorn@npm:^8.9.0": version: 8.11.3 resolution: "acorn@npm:8.11.3" bin: @@ -17936,6 +17833,13 @@ __metadata: languageName: node linkType: hard +"dataloader@npm:2.2.3": + version: 2.2.3 + resolution: "dataloader@npm:2.2.3" + checksum: 9b9a056fbc863ca86da87d59e053e871e263b4966aa4d55e40d61a65e96815fae5530ca220629064ca5f8e3000c0c4ec93292e170c38ff393fb34256b4d7c1aa + languageName: node + linkType: hard + "dataloader@npm:^1.4.0": version: 1.4.0 resolution: "dataloader@npm:1.4.0" @@ -18536,10 +18440,10 @@ __metadata: languageName: node linkType: hard -"dotenv@npm:16.3.1": - version: 16.3.1 - resolution: "dotenv@npm:16.3.1" - checksum: b95ff1bbe624ead85a3cd70dbd827e8e06d5f05f716f2d0cbc476532d54c7c9469c3bc4dd93ea519f6ad711cb522c00ac9a62b6eb340d5affae8008facc3fbd7 +"dotenv@npm:16.4.7": + version: 16.4.7 + resolution: "dotenv@npm:16.4.7" + checksum: be9f597e36a8daf834452daa1f4cc30e5375a5968f98f46d89b16b983c567398a330580c88395069a77473943c06b877d1ca25b4afafcdd6d4adb549e8293462 languageName: node linkType: hard @@ -19834,7 +19738,7 @@ __metadata: languageName: node linkType: hard -"esprima@npm:^4.0.0, esprima@npm:^4.0.1, esprima@npm:~4.0.0": +"esprima@npm:4.0.1, esprima@npm:^4.0.0, esprima@npm:^4.0.1, esprima@npm:~4.0.0": version: 4.0.1 resolution: "esprima@npm:4.0.1" bin: @@ -20286,7 +20190,7 @@ __metadata: languageName: node linkType: hard -"fast-glob@npm:^3.2.12, fast-glob@npm:^3.2.9, fast-glob@npm:^3.3.0": +"fast-glob@npm:^3.2.12, fast-glob@npm:^3.2.9, fast-glob@npm:^3.3.0, fast-glob@npm:^3.3.2": version: 3.3.2 resolution: "fast-glob@npm:3.3.2" dependencies: @@ -20757,6 +20661,17 @@ __metadata: languageName: node linkType: hard +"fs-extra@npm:11.2.0, fs-extra@npm:^11.1.0, fs-extra@npm:^11.2.0": + version: 11.2.0 + resolution: "fs-extra@npm:11.2.0" + dependencies: + graceful-fs: ^4.2.0 + jsonfile: ^6.0.1 + universalify: ^2.0.0 + checksum: d77a9a9efe60532d2e790e938c81a02c1b24904ef7a3efb3990b835514465ba720e99a6ea56fd5e2db53b4695319b644d76d5a0e9988a2beef80aa7b1da63398 + languageName: node + linkType: hard + "fs-extra@npm:8.1.0, fs-extra@npm:^8.1, fs-extra@npm:^8.1.0": version: 8.1.0 resolution: "fs-extra@npm:8.1.0" @@ -20779,17 +20694,6 @@ __metadata: languageName: node linkType: hard -"fs-extra@npm:^11.1.0, fs-extra@npm:^11.2.0": - version: 11.2.0 - resolution: "fs-extra@npm:11.2.0" - dependencies: - graceful-fs: ^4.2.0 - jsonfile: ^6.0.1 - universalify: ^2.0.0 - checksum: d77a9a9efe60532d2e790e938c81a02c1b24904ef7a3efb3990b835514465ba720e99a6ea56fd5e2db53b4695319b644d76d5a0e9988a2beef80aa7b1da63398 - languageName: node - linkType: hard - "fs-extra@npm:^7.0.1, fs-extra@npm:~7.0.1": version: 7.0.1 resolution: "fs-extra@npm:7.0.1" @@ -21114,7 +21018,7 @@ __metadata: languageName: node linkType: hard -"glob@npm:^8.0.3, glob@npm:^8.1.0": +"glob@npm:^8.1.0": version: 8.1.0 resolution: "glob@npm:8.1.0" dependencies: @@ -23825,9 +23729,9 @@ __metadata: languageName: node linkType: hard -"knex@npm:2.5.1": - version: 2.5.1 - resolution: "knex@npm:2.5.1" +"knex@npm:3.1.0": + version: 3.1.0 + resolution: "knex@npm:3.1.0" dependencies: colorette: 2.0.19 commander: ^10.0.0 @@ -23838,7 +23742,7 @@ __metadata: getopts: 2.3.0 interpret: ^2.2.0 lodash: ^4.17.21 - pg-connection-string: 2.6.1 + pg-connection-string: 2.6.2 rechoir: ^0.8.0 resolve-from: ^5.0.0 tarn: ^3.0.2 @@ -23860,7 +23764,7 @@ __metadata: optional: true bin: knex: bin/cli.js - checksum: 33580641feaa93074bdc10e78f06382e5017d46a3cd22821c09057e7da303c35772add39a110fffe685c2f438a78751a0eb6f50aad1c4bdb032e8ec9b7879b69 + checksum: d8a1f99fad143c6057e94759b2ae700ae661a0b0b2385f643011962ef501dcc7b32cfdb5bda66ef81283ca56f13630f47691c579ce66ad0e8128e209533c3785 languageName: node linkType: hard @@ -24906,10 +24810,10 @@ __metadata: languageName: node linkType: hard -"mikro-orm@npm:5.9.7": - version: 5.9.7 - resolution: "mikro-orm@npm:5.9.7" - checksum: 01eb2b71e5f830c064749779d30ed1772e28420cfedeafbbbce8599714eae308af467014001e0404d7ba43de9f1f979a05fd6b267a89c8f7e1e8ec6013fb5120 +"mikro-orm@npm:6.4.1": + version: 6.4.1 + resolution: "mikro-orm@npm:6.4.1" + checksum: 8cd06b83490496abd8686bcc50e88e398ba6e726bc85cdbfd2530072cdf7e24ec6a989df9254f20d1e39ec5571efa312d5e7c2a384a0ce73c25c2c31b0a1aaaf languageName: node linkType: hard @@ -26647,10 +26551,10 @@ __metadata: languageName: node linkType: hard -"pg-connection-string@npm:2.6.1": - version: 2.6.1 - resolution: "pg-connection-string@npm:2.6.1" - checksum: e5a71a2da143b8dc17143a9db7737679b210643771aa678d3bc60c7bc70da11bbb8e2d531be91c8c4eddd6ac6046307811e793f5850b9ba595a11785c948a417 +"pg-connection-string@npm:2.6.2": + version: 2.6.2 + resolution: "pg-connection-string@npm:2.6.2" + checksum: e8fdea74fcc8bdc3d7c5c6eadd9425fdba7e67fb7fe836f9c0cecad94c8984e435256657d1d8ce0483d1fedef667e7a57e32449a63cb805cb0289fc34b62da35 languageName: node linkType: hard @@ -27406,6 +27310,13 @@ __metadata: languageName: node linkType: hard +"postgres-array@npm:3.0.2, postgres-array@npm:~3.0.1": + version: 3.0.2 + resolution: "postgres-array@npm:3.0.2" + checksum: 644aa071f67a66a59f641f8e623887d2b915bc102a32643e2aa8b54c11acd343c5ad97831ea444dd37bd4b921ba35add4aa2cb0c6b76700a8252c2324aeba5b4 + languageName: node + linkType: hard + "postgres-array@npm:~2.0.0": version: 2.0.0 resolution: "postgres-array@npm:2.0.0" @@ -27413,13 +27324,6 @@ __metadata: languageName: node linkType: hard -"postgres-array@npm:~3.0.1": - version: 3.0.2 - resolution: "postgres-array@npm:3.0.2" - checksum: 644aa071f67a66a59f641f8e623887d2b915bc102a32643e2aa8b54c11acd343c5ad97831ea444dd37bd4b921ba35add4aa2cb0c6b76700a8252c2324aeba5b4 - languageName: node - linkType: hard - "postgres-bytea@npm:~1.0.0": version: 1.0.0 resolution: "postgres-bytea@npm:1.0.0" @@ -27436,6 +27340,13 @@ __metadata: languageName: node linkType: hard +"postgres-date@npm:2.1.0, postgres-date@npm:~2.1.0": + version: 2.1.0 + resolution: "postgres-date@npm:2.1.0" + checksum: 00a7472c10788f6b0d08d24108bf1eb80858de1bd6317740198a564918ea4a69b80c98148167b92ae688abd606483020d0de0dd3a36f3ea9a3e26bbeef3464f4 + languageName: node + linkType: hard + "postgres-date@npm:~1.0.4": version: 1.0.7 resolution: "postgres-date@npm:1.0.7" @@ -27443,10 +27354,10 @@ __metadata: languageName: node linkType: hard -"postgres-date@npm:~2.1.0": - version: 2.1.0 - resolution: "postgres-date@npm:2.1.0" - checksum: 00a7472c10788f6b0d08d24108bf1eb80858de1bd6317740198a564918ea4a69b80c98148167b92ae688abd606483020d0de0dd3a36f3ea9a3e26bbeef3464f4 +"postgres-interval@npm:4.0.2": + version: 4.0.2 + resolution: "postgres-interval@npm:4.0.2" + checksum: 46d0766b11ac91ba3e4816c73a04e4e0c13ddf9efb9797982fdc405019a40b85e8b4a36448bd90e1ac1e8f0ca9b2ff22820e65e103368bc6fd9fa6a3b4268fd4 languageName: node linkType: hard @@ -28595,10 +28506,10 @@ __metadata: languageName: node linkType: hard -"reflect-metadata@npm:0.1.13": - version: 0.1.13 - resolution: "reflect-metadata@npm:0.1.13" - checksum: 728bff0b376b05639fd11ed80c648b61f7fe653c5b506d7ca118e58b6752b9b00810fe0c86227ecf02bd88da6251ab3eb19fd403aaf2e9ff5ef36a2fda643026 +"reflect-metadata@npm:0.2.2": + version: 0.2.2 + resolution: "reflect-metadata@npm:0.2.2" + checksum: 1cd93a15ea291e420204955544637c264c216e7aac527470e393d54b4bb075f10a17e60d8168ec96600c7e0b9fcc0cb0bb6e91c3fbf5b0d8c9056f04e6ac1ec2 languageName: node linkType: hard @@ -32076,10 +31987,10 @@ __metadata: languageName: node linkType: hard -"type-fest@npm:^3.0.0": - version: 3.13.1 - resolution: "type-fest@npm:3.13.1" - checksum: 547d22186f73a8c04590b70dcf63baff390078c75ea8acd366bbd510fd0646e348bd1970e47ecf795b7cff0b41d26e9c475c1fedd6ef5c45c82075fbf916b629 +"type-fest@npm:^4.0.0": + version: 4.30.1 + resolution: "type-fest@npm:4.30.1" + checksum: 7ee8084aa764c9703f92e4c3546e0943909a1b508c93a02f1e528b877803b4af2cd68982d1d36578738a14026d5f5a3049d840aa11fca1d690d13a1612222da1 languageName: node linkType: hard @@ -32329,16 +32240,16 @@ __metadata: languageName: node linkType: hard -"umzug@npm:3.3.1": - version: 3.3.1 - resolution: "umzug@npm:3.3.1" +"umzug@npm:3.8.2": + version: 3.8.2 + resolution: "umzug@npm:3.8.2" dependencies: "@rushstack/ts-command-line": ^4.12.2 emittery: ^0.13.0 - glob: ^8.0.3 + fast-glob: ^3.3.2 pony-cause: ^2.1.4 - type-fest: ^3.0.0 - checksum: 52ace90860f9e2adc9f33c786582ca758651f2de8894b5bda7af2353bec8906234dbb456eb37513ec9ceeb45eabfcd286d4abced871cc45c01015a05e4247187 + type-fest: ^4.0.0 + checksum: b5b9659fc3e85f486fa3b701cf0b592117b38974d3c5c039d78fd8dbc60dcbaf04ce6430aa5b79a544a64bd99f230d7c9b3deffa2528fcb00c590cd6909fbc32 languageName: node linkType: hard From 66f48d06aed8d74f1f31384d2d21a27be2a24d82 Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Tue, 17 Dec 2024 08:34:49 -0300 Subject: [PATCH 126/175] cart service --- .../entity-builder/define-relationship.ts | 16 +++++-- .../services/cart-module/index.spec.ts | 2 + .../modules/cart/src/services/cart-module.ts | 48 +++++++++++++++++++ 3 files changed, 61 insertions(+), 5 deletions(-) diff --git a/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts b/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts index a95350a929676..2bea6e4912d42 100644 --- a/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts +++ b/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts @@ -189,14 +189,20 @@ export function defineHasOneWithFKRelationship( mappedBy = relationship.mappedBy } - OneToOne({ + const oneToOneOptions = { entity: relatedModelName, ...(relationship.nullable ? { nullable: relationship.nullable } : {}), ...(mappedBy ? { mappedBy } : {}), - cascade: shouldRemoveRelated - ? (["persist", "soft-remove"] as any) - : undefined, - } as OneToOneOptions)(MikroORMEntity.prototype, relationship.name) + fieldName: foreignKeyName, + orphanRemoval: true, + persist: false, + } as OneToOneOptions + + if (shouldRemoveRelated) { + oneToOneOptions["cascade"] = ["persist", "soft-remove"] as any + } + + OneToOne(oneToOneOptions)(MikroORMEntity.prototype, relationship.name) Property({ type: "string", diff --git a/packages/modules/cart/integration-tests/__tests__/services/cart-module/index.spec.ts b/packages/modules/cart/integration-tests/__tests__/services/cart-module/index.spec.ts index 5d276268af8d6..a0f1011c4dae2 100644 --- a/packages/modules/cart/integration-tests/__tests__/services/cart-module/index.spec.ts +++ b/packages/modules/cart/integration-tests/__tests__/services/cart-module/index.spec.ts @@ -2488,6 +2488,8 @@ moduleIntegrationTestRunner({ const asJson = JSON.parse(JSON.stringify(cart)) expect(asJson).toEqual({ id: createdCart.id, + billing_address: null, + shipping_address: null, items: [ { id: itemOne.id, diff --git a/packages/modules/cart/src/services/cart-module.ts b/packages/modules/cart/src/services/cart-module.ts index 25f155e0e87c7..7b2e0a7c82b18 100644 --- a/packages/modules/cart/src/services/cart-module.ts +++ b/packages/modules/cart/src/services/cart-module.ts @@ -290,6 +290,8 @@ export default class CartModuleService data: CartTypes.CreateCartDTO[], @MedusaContext() sharedContext: Context = {} ) { + await this.createCartAddresses_(data, sharedContext) + const lineItemsToCreate: CreateLineItemDTO[] = [] const createdCarts: InferEntityType[] = [] for (const { items, ...cart } of data) { @@ -316,6 +318,52 @@ export default class CartModuleService return createdCarts } + @InjectTransactionManager() + protected async createCartAddresses_( + input: CartTypes.CreateCartDTO[], + @MedusaContext() sharedContext: Context = {} + ) { + const allAddresses: { + data: CartTypes.CreateAddressDTO + type: "billing" | "shipping" + source: CartTypes.CreateCartDTO + }[] = [] + + input.forEach((inputData) => { + if (inputData.billing_address) { + allAddresses.push({ + data: inputData.billing_address as CartTypes.CreateAddressDTO, + type: "billing", + source: inputData, + }) + } + + if (inputData.shipping_address) { + allAddresses.push({ + data: inputData.shipping_address as CartTypes.CreateAddressDTO, + type: "shipping", + source: inputData, + }) + } + }) + + const createdAddresses = allAddresses.length + ? await this.createAddresses( + allAddresses.map((a) => a.data), + sharedContext + ) + : [] + + createdAddresses.forEach((createdAddress, index) => { + const { type, source } = allAddresses[index] + if (type === "billing") { + source.billing_address_id = createdAddress.id + } else if (type === "shipping") { + source.shipping_address_id = createdAddress.id + } + }) + } + // @ts-expect-error async updateCarts( data: CartTypes.UpdateCartDTO[] From 666f219d845e5b2bf40dc86baab58aff2f7c74ba Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Tue, 17 Dec 2024 11:32:32 -0300 Subject: [PATCH 127/175] order module --- packages/modules/order/src/models/claim.ts | 2 +- packages/modules/order/src/models/exchange.ts | 2 +- packages/modules/order/src/models/order.ts | 2 + .../modules/order/src/models/return-reason.ts | 1 + packages/modules/order/src/models/return.ts | 2 + .../src/services/order-module-service.ts | 54 ++++++++++++++++++- .../order/src/utils/apply-order-changes.ts | 13 +++-- 7 files changed, 68 insertions(+), 8 deletions(-) diff --git a/packages/modules/order/src/models/claim.ts b/packages/modules/order/src/models/claim.ts index 983993098156b..2ae7af5be1e0c 100644 --- a/packages/modules/order/src/models/claim.ts +++ b/packages/modules/order/src/models/claim.ts @@ -82,7 +82,7 @@ export default class OrderClaim { mappedBy: (ret) => ret.claim, fieldName: "return_id", nullable: true, - owner: true, + persist: false, }) return: Rel diff --git a/packages/modules/order/src/models/exchange.ts b/packages/modules/order/src/models/exchange.ts index 34fb61abd6947..315cfb21af7dc 100644 --- a/packages/modules/order/src/models/exchange.ts +++ b/packages/modules/order/src/models/exchange.ts @@ -79,7 +79,7 @@ export default class OrderExchange { mappedBy: (ret) => ret.exchange, fieldName: "return_id", nullable: true, - owner: true, + persist: false, }) return: Rel diff --git a/packages/modules/order/src/models/order.ts b/packages/modules/order/src/models/order.ts index 283e60fcec940..a4037e489e246 100644 --- a/packages/modules/order/src/models/order.ts +++ b/packages/modules/order/src/models/order.ts @@ -149,6 +149,7 @@ export default class Order { fieldName: "shipping_address_id", nullable: true, cascade: [Cascade.PERSIST], + persist: false, }) shipping_address?: Rel | null @@ -161,6 +162,7 @@ export default class Order { fieldName: "billing_address_id", nullable: true, cascade: [Cascade.PERSIST], + persist: false, }) billing_address?: Rel | null diff --git a/packages/modules/order/src/models/return-reason.ts b/packages/modules/order/src/models/return-reason.ts index 9bd52a28a04aa..03374cba4c3bb 100644 --- a/packages/modules/order/src/models/return-reason.ts +++ b/packages/modules/order/src/models/return-reason.ts @@ -68,6 +68,7 @@ export default class ReturnReason { fieldName: "parent_return_reason_id", nullable: true, cascade: [Cascade.PERSIST], + persist: false, }) parent_return_reason?: Rel | null @OneToMany( diff --git a/packages/modules/order/src/models/return.ts b/packages/modules/order/src/models/return.ts index 65bfaf42012a4..e9f741ecca9b3 100644 --- a/packages/modules/order/src/models/return.ts +++ b/packages/modules/order/src/models/return.ts @@ -87,6 +87,7 @@ export default class Return { entity: () => Exchange, fieldName: "exchange_id", nullable: true, + persist: false, }) exchange: Rel @@ -98,6 +99,7 @@ export default class Return { entity: () => Claim, fieldName: "claim_id", nullable: true, + persist: false, }) claim: Rel diff --git a/packages/modules/order/src/services/order-module-service.ts b/packages/modules/order/src/services/order-module-service.ts index 3a15c3cd7fe54..36f7199f1741f 100644 --- a/packages/modules/order/src/services/order-module-service.ts +++ b/packages/modules/order/src/services/order-module-service.ts @@ -636,6 +636,8 @@ export default class OrderModuleService< data: OrderTypes.CreateOrderDTO[], @MedusaContext() sharedContext: Context = {} ) { + await this.createOrderAddresses_(data, sharedContext) + const lineItemsToCreate: CreateOrderLineItemDTO[] = [] const createdOrders: Order[] = [] @@ -689,6 +691,52 @@ export default class OrderModuleService< return createdOrders } + @InjectTransactionManager() + protected async createOrderAddresses_( + input: OrderTypes.CreateOrderDTO[], + @MedusaContext() sharedContext: Context = {} + ) { + const allAddresses: { + data: any + type: "billing" | "shipping" + source: OrderTypes.CreateOrderDTO + }[] = [] + + input.forEach((inputData) => { + if (inputData.billing_address) { + allAddresses.push({ + data: inputData.billing_address, + type: "billing", + source: inputData, + }) + } + + if (inputData.shipping_address) { + allAddresses.push({ + data: inputData.shipping_address, + type: "shipping", + source: inputData, + }) + } + }) + + const createdAddresses = allAddresses.length + ? await this.orderAddressService_.create( + allAddresses.map((a) => a.data), + sharedContext + ) + : [] + + createdAddresses.forEach((createdAddress, index) => { + const { type, source } = allAddresses[index] + if (type === "billing") { + source.billing_address_id = createdAddress.id + } else if (type === "shipping") { + source.shipping_address_id = createdAddress.id + } + }) + } + // @ts-expect-error async updateOrders( data: OrderTypes.UpdateOrderDTO[] @@ -1998,7 +2046,9 @@ export default class OrderModuleService< quantity: item.detail?.quantity ?? item.quantity, unit_price: item.detail?.unit_price || item.unit_price, compare_at_unit_price: - item.detail?.compare_at_unit_price || item.compare_at_unit_price, + item.detail?.compare_at_unit_price || + item.compare_at_unit_price || + null, } } } @@ -2038,7 +2088,7 @@ export default class OrderModuleService< actions, quantity: newItem.quantity, unit_price: unitPrice, - compare_at_unit_price: compareAtUnitPrice, + compare_at_unit_price: compareAtUnitPrice || null, detail: { ...newItem, ...item, diff --git a/packages/modules/order/src/utils/apply-order-changes.ts b/packages/modules/order/src/utils/apply-order-changes.ts index 4d095d84b28d3..124f4f119a35e 100644 --- a/packages/modules/order/src/utils/apply-order-changes.ts +++ b/packages/modules/order/src/utils/apply-order-changes.ts @@ -69,15 +69,13 @@ export function applyChangesToOrder( const orderItem = isExistingItem ? (item.detail as any) : item const itemId = isExistingItem ? orderItem.item_id : item.id - itemsToUpsert.push({ + const itemToUpsert = { id: orderItem.version === version ? orderItem.id : undefined, item_id: itemId, order_id: order.id, version, quantity: orderItem.quantity, unit_price: item.unit_price ?? orderItem.unit_price, - compare_at_unit_price: - item.compare_at_unit_price ?? orderItem.compare_at_unit_price, fulfilled_quantity: orderItem.fulfilled_quantity ?? 0, delivered_quantity: orderItem.delivered_quantity ?? 0, shipped_quantity: orderItem.shipped_quantity ?? 0, @@ -86,7 +84,14 @@ export function applyChangesToOrder( return_dismissed_quantity: orderItem.return_dismissed_quantity ?? 0, written_off_quantity: orderItem.written_off_quantity ?? 0, metadata: orderItem.metadata, - } as OrderItem) + } as OrderItem + + if (item.compare_at_unit_price || orderItem.compare_at_unit_price) { + itemToUpsert.compare_at_unit_price = + item.compare_at_unit_price ?? orderItem.compare_at_unit_price + } + + itemsToUpsert.push(itemToUpsert) } const orderSummary = order.summary as any From 4808b378945e93162755aa8705ad6f5be92adc3f Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Tue, 17 Dec 2024 11:37:30 -0300 Subject: [PATCH 128/175] utils unit test --- .../src/dml/__tests__/entity-builder.spec.ts | 33 +++++++++++++++---- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts b/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts index 0e624b57b7847..764cf6c4b8426 100644 --- a/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts +++ b/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts @@ -158,7 +158,8 @@ describe("Entity builder", () => { kind: "scalar", setter: true, trackChanges: false, - type: "any", + type: "number", + runtimeType: "number", }, raw_spend_limit: { columnType: "jsonb", @@ -297,7 +298,8 @@ describe("Entity builder", () => { kind: "scalar", setter: true, trackChanges: false, - type: "any", + type: "number", + runtimeType: "number", }, raw_spend_limit: { columnType: "jsonb", @@ -427,7 +429,8 @@ describe("Entity builder", () => { kind: "scalar", setter: true, trackChanges: false, - type: "any", + type: "number", + runtimeType: "number", }, raw_spend_limit: { columnType: "jsonb", @@ -536,7 +539,8 @@ describe("Entity builder", () => { kind: "scalar", setter: true, trackChanges: false, - type: "any", + type: "number", + runtimeType: "number", }, raw_spend_limit: { columnType: "jsonb", @@ -677,7 +681,8 @@ describe("Entity builder", () => { kind: "scalar", setter: true, trackChanges: false, - type: "any", + type: "number", + runtimeType: "number", }, raw_spend_limit: { columnType: "jsonb", @@ -829,7 +834,8 @@ describe("Entity builder", () => { kind: "scalar", setter: true, trackChanges: false, - type: "any", + type: "number", + runtimeType: "number", }, created_at: { kind: "scalar", @@ -3123,6 +3129,9 @@ describe("Entity builder", () => { kind: "1:1", name: "email", entity: "Email", + fieldName: "email_id", + orphanRemoval: true, + persist: false, }, email_id: { columnType: "text", @@ -3233,6 +3242,9 @@ describe("Entity builder", () => { name: "emails", entity: "Email", nullable: true, + fieldName: "emails_id", + orphanRemoval: true, + persist: false, }, emails_id: { columnType: "text", @@ -3334,6 +3346,9 @@ describe("Entity builder", () => { name: "email", entity: "Email", mappedBy: "owner", + fieldName: "email_id", + orphanRemoval: true, + persist: false, }, email_id: { columnType: "text", @@ -3439,6 +3454,9 @@ describe("Entity builder", () => { entity: "Email", cascade: ["persist", "soft-remove"], mappedBy: "user", + fieldName: "email_id", + orphanRemoval: true, + persist: false, }, email_id: { columnType: "text", @@ -3614,6 +3632,9 @@ describe("Entity builder", () => { entity: "Email", cascade: ["persist", "soft-remove"], mappedBy: "user", + fieldName: "email_id", + orphanRemoval: true, + persist: false, }, email_id: { columnType: "text", From c4d93dcf30ef372d558b4891e49ed9b672aafeab Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Wed, 18 Dec 2024 06:31:50 -0300 Subject: [PATCH 129/175] index engine --- .../__tests__/index-engine-module.spec.ts | 48 +------------------ .../migrations/.snapshot-medusa-index.json | 12 ++--- .../modules/index/src/models/index-data.ts | 10 ---- .../index/src/models/index-relation.ts | 9 +--- .../index/src/services/postgres-provider.ts | 11 +++-- 5 files changed, 15 insertions(+), 75 deletions(-) diff --git a/packages/modules/index/integration-tests/__tests__/index-engine-module.spec.ts b/packages/modules/index/integration-tests/__tests__/index-engine-module.spec.ts index 8916ba3440b83..69c6396333d72 100644 --- a/packages/modules/index/integration-tests/__tests__/index-engine-module.spec.ts +++ b/packages/modules/index/integration-tests/__tests__/index-engine-module.spec.ts @@ -722,57 +722,11 @@ describe("IndexModuleService", function () { it("should consume all deleted events and delete the index entries", async () => { const indexEntries = await manager.find(toMikroORMEntity(IndexData), {}) const indexRelationEntries = await manager.find( - toMikroORMEntity(IndexRelation), - {}, - { - populate: ["parent", "child"], - } + toMikroORMEntity(IndexRelation) ) expect(indexEntries).toHaveLength(3) expect(indexRelationEntries).toHaveLength(2) - - const linkIndexEntry = indexEntries.find((entry) => { - return ( - entry.name === "LinkProductVariantPriceSet" && entry.id === linkId - ) - })! - - const priceSetIndexEntry = indexEntries.find((entry) => { - return entry.name === "PriceSet" && entry.id === priceSetId - })! - - const priceIndexEntry = indexEntries.find((entry) => { - return entry.name === "Price" && entry.id === priceId - })! - - const linkPriceSetIndexRelationEntry = indexRelationEntries.find( - (entry) => { - return ( - entry.parent_id === linkId && - entry.parent_name === "LinkProductVariantPriceSet" && - entry.child_id === priceSetId && - entry.child_name === "PriceSet" - ) - } - )! - - expect(linkPriceSetIndexRelationEntry.parent).toEqual(linkIndexEntry) - expect(linkPriceSetIndexRelationEntry.child).toEqual(priceSetIndexEntry) - - const priceSetPriceIndexRelationEntry = indexRelationEntries.find( - (entry) => { - return ( - entry.parent_id === priceSetId && - entry.parent_name === "PriceSet" && - entry.child_id === priceId && - entry.child_name === "Price" - ) - } - )! - - expect(priceSetPriceIndexRelationEntry.parent).toEqual(priceSetIndexEntry) - expect(priceSetPriceIndexRelationEntry.child).toEqual(priceIndexEntry) }) }) }) diff --git a/packages/modules/index/src/migrations/.snapshot-medusa-index.json b/packages/modules/index/src/migrations/.snapshot-medusa-index.json index 4f1381987680c..57ef691d6f1cb 100644 --- a/packages/modules/index/src/migrations/.snapshot-medusa-index.json +++ b/packages/modules/index/src/migrations/.snapshot-medusa-index.json @@ -120,11 +120,11 @@ "columns": { "id": { "name": "id", - "type": "number", + "type": "serial", "unsigned": true, "autoincrement": true, "primary": true, - "nullable": false, + "nullable": true, "mappedType": "integer" }, "pivot": { @@ -145,8 +145,8 @@ "nullable": false, "mappedType": "text" }, - "child_name": { - "name": "child_name", + "parent_id": { + "name": "parent_id", "type": "text", "unsigned": false, "autoincrement": false, @@ -154,8 +154,8 @@ "nullable": false, "mappedType": "text" }, - "parent_id": { - "name": "parent_id", + "child_name": { + "name": "child_name", "type": "text", "unsigned": false, "autoincrement": false, diff --git a/packages/modules/index/src/models/index-data.ts b/packages/modules/index/src/models/index-data.ts index b56cb86674fad..0326e34f14cbf 100644 --- a/packages/modules/index/src/models/index-data.ts +++ b/packages/modules/index/src/models/index-data.ts @@ -1,20 +1,10 @@ import { model } from "@medusajs/framework/utils" -import IndexRelation from "./index-relation" const IndexData = model .define("IndexData", { id: model.text().primaryKey(), name: model.text().primaryKey(), data: model.json().default({}), - parents: model.manyToMany(() => IndexData, { - mappedBy: "children", - pivotEntity: () => IndexRelation, - joinColumn: ["child_id", "child_name"], - inverseJoinColumn: ["parent_id", "parent_name"], - }), - children: model.manyToMany(() => IndexData, { - mappedBy: "parents", - }), }) .indexes([ { diff --git a/packages/modules/index/src/models/index-relation.ts b/packages/modules/index/src/models/index-relation.ts index d2ae894ed8557..bf983bcf4160b 100644 --- a/packages/modules/index/src/models/index-relation.ts +++ b/packages/modules/index/src/models/index-relation.ts @@ -1,16 +1,11 @@ import { model } from "@medusajs/framework/utils" -import IndexData from "./index-data" const IndexRelation = model.define("IndexRelation", { id: model.autoincrement().primaryKey(), pivot: model.text(), parent_name: model.text(), + parent_id: model.text().index("IDX_index_relation_parent_id"), child_name: model.text(), - parent: model.belongsTo(() => IndexData, { - mappedBy: "parents", - }), - child: model.belongsTo(() => IndexData, { - mappedBy: "children", - }), + child_id: model.text().index("IDX_index_relation_child_id"), }) export default IndexRelation diff --git a/packages/modules/index/src/services/postgres-provider.ts b/packages/modules/index/src/services/postgres-provider.ts index 4b4e4429686d9..c0dbe177c2d93 100644 --- a/packages/modules/index/src/services/postgres-provider.ts +++ b/packages/modules/index/src/services/postgres-provider.ts @@ -403,7 +403,9 @@ export class PostgresProvider implements IndexTypes.StorageProvider { child_name: entity, pivot: `${parentEntity}-${entity}`, }) - indexRelationRepository.persist(parentIndexRelationEntry) + indexRelationRepository + .getEntityManager() + .persist(parentIndexRelationEntry) } } } @@ -628,10 +630,9 @@ export class PostgresProvider implements IndexTypes.StorageProvider { pivot: `${entity}-${childEntityName}`, }) - indexRelationRepository.persist([ - parentIndexRelationEntry, - childIndexRelationEntry, - ]) + indexRelationRepository + .getEntityManager() + .persist([parentIndexRelationEntry, childIndexRelationEntry]) } } From e934d21d1ab5906c33ce6d6a48ffa59cb2e3f2ad Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Wed, 18 Dec 2024 06:35:24 -0300 Subject: [PATCH 130/175] changeset --- .changeset/fair-ants-heal.md | 41 ++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 .changeset/fair-ants-heal.md diff --git a/.changeset/fair-ants-heal.md b/.changeset/fair-ants-heal.md new file mode 100644 index 0000000000000..2219b8b8f218c --- /dev/null +++ b/.changeset/fair-ants-heal.md @@ -0,0 +1,41 @@ +--- +"@medusajs/locking-postgres": minor +"@medusajs/workflow-engine-inmemory": minor +"@medusajs/workflow-engine-redis": minor +"@medusajs/stock-location": minor +"@medusajs/sales-channel": minor +"@medusajs/link-modules": minor +"@medusajs/notification": minor +"@medusajs/fulfillment": minor +"@medusajs/orchestration": minor +"@medusajs/workflows-sdk": minor +"@medusajs/test-utils": minor +"@medusajs/inventory": minor +"@medusajs/promotion": minor +"@medusajs/modules-sdk": minor +"@medusajs/currency": minor +"@medusajs/customer": minor +"@medusajs/core-flows": minor +"@medusajs/api-key": minor +"@medusajs/locking": minor +"@medusajs/payment": minor +"@medusajs/pricing": minor +"@medusajs/product": minor +"@medusajs/cli": minor +"@medusajs/framework": minor +"@medusajs/region": minor +"integration-tests-http": minor +"@medusajs/index": minor +"@medusajs/order": minor +"@medusajs/store": minor +"@medusajs/auth": minor +"@medusajs/cart": minor +"@medusajs/file": minor +"@medusajs/user": minor +"@medusajs/tax": minor +"@medusajs/types": minor +"@medusajs/utils": minor +"@medusajs/medusa": minor +--- + +chore: upgrade to mikro-orm 6 From 1c55990db3b1ae6cc3efc85ba55cedc1d826ebbd Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Wed, 18 Dec 2024 06:39:09 -0300 Subject: [PATCH 131/175] merge --- packages/core/core-flows/package.json | 8 +- packages/core/framework/package.json | 8 +- packages/medusa-test-utils/package.json | 8 +- packages/modules/api-key/package.json | 2 +- packages/modules/auth/package.json | 8 +- packages/modules/cart/package.json | 8 +- packages/modules/currency/package.json | 8 +- packages/modules/customer/package.json | 8 +- packages/modules/file/package.json | 8 +- packages/modules/fulfillment/package.json | 8 +- packages/modules/index/package.json | 10 +- packages/modules/inventory/package.json | 8 +- packages/modules/link-modules/package.json | 6 +- packages/modules/locking/package.json | 8 +- packages/modules/notification/package.json | 8 +- packages/modules/order/package.json | 8 +- packages/modules/payment/package.json | 8 +- packages/modules/pricing/package.json | 8 +- packages/modules/product/package.json | 8 +- packages/modules/promotion/package.json | 8 +- .../providers/locking-postgres/package.json | 8 +- packages/modules/region/package.json | 8 +- packages/modules/sales-channel/package.json | 8 +- packages/modules/stock-location/package.json | 8 +- packages/modules/store/package.json | 8 +- packages/modules/tax/package.json | 8 +- packages/modules/user/package.json | 8 +- .../workflow-engine-inmemory/package.json | 8 +- .../workflow-engine-redis/package.json | 8 +- yarn.lock | 266 +++++++++--------- 30 files changed, 246 insertions(+), 246 deletions(-) diff --git a/packages/core/core-flows/package.json b/packages/core/core-flows/package.json index 14143414bbd31..a6972ee779706 100644 --- a/packages/core/core-flows/package.json +++ b/packages/core/core-flows/package.json @@ -27,10 +27,10 @@ "license": "MIT", "devDependencies": { "@medusajs/framework": "^2.1.2", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/knex": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/knex": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "awilix": "^8.0.1", diff --git a/packages/core/framework/package.json b/packages/core/framework/package.json index 5ee6906078371..d37448bb6bcc3 100644 --- a/packages/core/framework/package.json +++ b/packages/core/framework/package.json @@ -53,10 +53,10 @@ }, "devDependencies": { "@medusajs/cli": "^2.1.2", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/knex": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/knex": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "@types/cors": "^2.8.17", diff --git a/packages/medusa-test-utils/package.json b/packages/medusa-test-utils/package.json index 5c5d7f1a9e617..c12c597b56864 100644 --- a/packages/medusa-test-utils/package.json +++ b/packages/medusa-test-utils/package.json @@ -26,10 +26,10 @@ "license": "MIT", "devDependencies": { "@medusajs/framework": "^2.1.2", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/knex": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/knex": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "awilix": "^8.0.1", "jest": "^29.7.0", "pg": "^8.13.0", diff --git a/packages/modules/api-key/package.json b/packages/modules/api-key/package.json index 8361a190a86a8..59a1693f960c5 100644 --- a/packages/modules/api-key/package.json +++ b/packages/modules/api-key/package.json @@ -38,7 +38,7 @@ "devDependencies": { "@medusajs/framework": "^2.1.2", "@medusajs/test-utils": "^2.1.2", - "@mikro-orm/cli": "5.9.7", + "@mikro-orm/cli": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", diff --git a/packages/modules/auth/package.json b/packages/modules/auth/package.json index 3b2f5f65b7415..a622d9e3be126 100644 --- a/packages/modules/auth/package.json +++ b/packages/modules/auth/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.2", "@medusajs/test-utils": "^2.1.2", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", diff --git a/packages/modules/cart/package.json b/packages/modules/cart/package.json index 9c41bc1727013..fce22a7022bc4 100644 --- a/packages/modules/cart/package.json +++ b/packages/modules/cart/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.2", "@medusajs/test-utils": "^2.1.2", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", diff --git a/packages/modules/currency/package.json b/packages/modules/currency/package.json index 82e2f4da4526a..6de80b2a9c136 100644 --- a/packages/modules/currency/package.json +++ b/packages/modules/currency/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.2", "@medusajs/test-utils": "^2.1.2", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", diff --git a/packages/modules/customer/package.json b/packages/modules/customer/package.json index f76d19eecce81..c39155011404a 100644 --- a/packages/modules/customer/package.json +++ b/packages/modules/customer/package.json @@ -39,10 +39,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.2", "@medusajs/test-utils": "^2.1.2", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", diff --git a/packages/modules/file/package.json b/packages/modules/file/package.json index 57ca98d7b2093..5be3d3df9c26f 100644 --- a/packages/modules/file/package.json +++ b/packages/modules/file/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.2", "@medusajs/test-utils": "^2.1.2", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", diff --git a/packages/modules/fulfillment/package.json b/packages/modules/fulfillment/package.json index 86e4b7170a777..e5c114e09009e 100644 --- a/packages/modules/fulfillment/package.json +++ b/packages/modules/fulfillment/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.2", "@medusajs/test-utils": "^2.1.2", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", diff --git a/packages/modules/index/package.json b/packages/modules/index/package.json index 89321b29a9fb4..236bfd993ca08 100644 --- a/packages/modules/index/package.json +++ b/packages/modules/index/package.json @@ -38,11 +38,11 @@ "devDependencies": { "@medusajs/framework": "^2.1.2", "@medusajs/test-utils": "^2.1.2", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/knex": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/knex": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", diff --git a/packages/modules/inventory/package.json b/packages/modules/inventory/package.json index 2815d3636802c..67c54fb341fce 100644 --- a/packages/modules/inventory/package.json +++ b/packages/modules/inventory/package.json @@ -25,10 +25,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.2", "@medusajs/test-utils": "^2.1.2", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", diff --git a/packages/modules/link-modules/package.json b/packages/modules/link-modules/package.json index 75ec3062edf6d..fb6fc17c56691 100644 --- a/packages/modules/link-modules/package.json +++ b/packages/modules/link-modules/package.json @@ -35,9 +35,9 @@ "devDependencies": { "@medusajs/framework": "^2.1.2", "@medusajs/test-utils": "^2.1.2", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "cross-env": "^5.2.1", diff --git a/packages/modules/locking/package.json b/packages/modules/locking/package.json index 551eca0c8e9a3..9b5a8da0c46e1 100644 --- a/packages/modules/locking/package.json +++ b/packages/modules/locking/package.json @@ -34,10 +34,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.2", "@medusajs/test-utils": "^2.1.2", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", diff --git a/packages/modules/notification/package.json b/packages/modules/notification/package.json index d323b3a69d88f..969606da533bf 100644 --- a/packages/modules/notification/package.json +++ b/packages/modules/notification/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.2", "@medusajs/test-utils": "^2.1.2", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", diff --git a/packages/modules/order/package.json b/packages/modules/order/package.json index c2bfdab41cb53..363c273447654 100644 --- a/packages/modules/order/package.json +++ b/packages/modules/order/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.2", "@medusajs/test-utils": "^2.1.2", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", diff --git a/packages/modules/payment/package.json b/packages/modules/payment/package.json index 2af38354357ec..c42ea9fe5447f 100644 --- a/packages/modules/payment/package.json +++ b/packages/modules/payment/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.2", "@medusajs/test-utils": "^2.1.2", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", diff --git a/packages/modules/pricing/package.json b/packages/modules/pricing/package.json index cc45950e391c9..a00efcffa198e 100644 --- a/packages/modules/pricing/package.json +++ b/packages/modules/pricing/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.2", "@medusajs/test-utils": "^2.1.2", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", diff --git a/packages/modules/product/package.json b/packages/modules/product/package.json index 1dd964d8f7c72..77a932db5a372 100644 --- a/packages/modules/product/package.json +++ b/packages/modules/product/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.2", "@medusajs/test-utils": "^2.1.2", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "faker": "^5.5.3", diff --git a/packages/modules/promotion/package.json b/packages/modules/promotion/package.json index e1e7c50e4f87f..4814557fe757a 100644 --- a/packages/modules/promotion/package.json +++ b/packages/modules/promotion/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.2", "@medusajs/test-utils": "^2.1.2", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", diff --git a/packages/modules/providers/locking-postgres/package.json b/packages/modules/providers/locking-postgres/package.json index 1d6e6137bb360..2461cc0445f73 100644 --- a/packages/modules/providers/locking-postgres/package.json +++ b/packages/modules/providers/locking-postgres/package.json @@ -21,10 +21,10 @@ "license": "MIT", "devDependencies": { "@medusajs/framework": "^2.1.2", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", diff --git a/packages/modules/region/package.json b/packages/modules/region/package.json index babdeecbb13b6..6711d6423f49d 100644 --- a/packages/modules/region/package.json +++ b/packages/modules/region/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.2", "@medusajs/test-utils": "^2.1.2", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", diff --git a/packages/modules/sales-channel/package.json b/packages/modules/sales-channel/package.json index 483852ee8a731..fc2657bade969 100644 --- a/packages/modules/sales-channel/package.json +++ b/packages/modules/sales-channel/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.2", "@medusajs/test-utils": "^2.1.2", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", diff --git a/packages/modules/stock-location/package.json b/packages/modules/stock-location/package.json index c73f9111bbe9a..7fd6b78ff68f0 100644 --- a/packages/modules/stock-location/package.json +++ b/packages/modules/stock-location/package.json @@ -25,10 +25,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.2", "@medusajs/test-utils": "^2.1.2", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", diff --git a/packages/modules/store/package.json b/packages/modules/store/package.json index 2a1dee71e615e..e3e9a65d7ee3a 100644 --- a/packages/modules/store/package.json +++ b/packages/modules/store/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.2", "@medusajs/test-utils": "^2.1.2", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", diff --git a/packages/modules/tax/package.json b/packages/modules/tax/package.json index faaf7dafbe491..6f798e22fc6f5 100644 --- a/packages/modules/tax/package.json +++ b/packages/modules/tax/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.2", "@medusajs/test-utils": "^2.1.2", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", diff --git a/packages/modules/user/package.json b/packages/modules/user/package.json index fe39e71a65175..b19feceef43b8 100644 --- a/packages/modules/user/package.json +++ b/packages/modules/user/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.2", "@medusajs/test-utils": "^2.1.2", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", diff --git a/packages/modules/workflow-engine-inmemory/package.json b/packages/modules/workflow-engine-inmemory/package.json index 106b25834ffbd..7768be3572f23 100644 --- a/packages/modules/workflow-engine-inmemory/package.json +++ b/packages/modules/workflow-engine-inmemory/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.2", "@medusajs/test-utils": "^2.1.2", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", diff --git a/packages/modules/workflow-engine-redis/package.json b/packages/modules/workflow-engine-redis/package.json index c1de5ec5aa274..01127052a62bf 100644 --- a/packages/modules/workflow-engine-redis/package.json +++ b/packages/modules/workflow-engine-redis/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.2", "@medusajs/test-utils": "^2.1.2", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", diff --git a/yarn.lock b/yarn.lock index b160065f814a5..69b27398245ed 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5316,7 +5316,7 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.2 "@medusajs/test-utils": ^2.1.2 - "@mikro-orm/cli": 5.9.7 + "@mikro-orm/cli": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -5387,10 +5387,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.2 "@medusajs/test-utils": ^2.1.2 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -5444,10 +5444,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.2 "@medusajs/test-utils": ^2.1.2 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -5469,10 +5469,10 @@ __metadata: dependencies: "@medusajs/telemetry": ^2.1.2 "@medusajs/utils": 2.1.2 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/knex": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/knex": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 "@types/express": ^4.17.17 @@ -5519,10 +5519,10 @@ __metadata: resolution: "@medusajs/core-flows@workspace:packages/core/core-flows" dependencies: "@medusajs/framework": ^2.1.2 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/knex": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/knex": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 awilix: ^8.0.1 @@ -5544,10 +5544,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.2 "@medusajs/test-utils": ^2.1.2 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -5569,10 +5569,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.2 "@medusajs/test-utils": ^2.1.2 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -5719,10 +5719,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.2 "@medusajs/test-utils": ^2.1.2 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -5747,10 +5747,10 @@ __metadata: "@medusajs/types": ^2.1.2 "@medusajs/utils": ^2.1.2 "@medusajs/workflows-sdk": ^2.1.2 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/knex": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/knex": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@opentelemetry/api": ^1.9.0 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 @@ -5818,10 +5818,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.2 "@medusajs/test-utils": ^2.1.2 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -5877,11 +5877,11 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.2 "@medusajs/test-utils": ^2.1.2 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/knex": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/knex": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -5904,10 +5904,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.2 "@medusajs/test-utils": ^2.1.2 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -5943,9 +5943,9 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.2 "@medusajs/test-utils": ^2.1.2 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 cross-env: ^5.2.1 @@ -5967,10 +5967,10 @@ __metadata: resolution: "@medusajs/locking-postgres@workspace:packages/modules/providers/locking-postgres" dependencies: "@medusajs/framework": ^2.1.2 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -6003,10 +6003,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.2 "@medusajs/test-utils": ^2.1.2 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -6149,10 +6149,10 @@ __metadata: "@medusajs/orchestration": ^2.1.2 "@medusajs/types": ^2.1.2 "@medusajs/utils": ^2.1.2 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/knex": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/knex": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 awilix: ^8.0.1 @@ -6209,10 +6209,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.2 "@medusajs/test-utils": ^2.1.2 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -6243,10 +6243,10 @@ __metadata: dependencies: "@medusajs/types": ^2.1.2 "@medusajs/utils": ^2.1.2 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/knex": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/knex": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 awilix: ^8.0.1 @@ -6271,10 +6271,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.2 "@medusajs/test-utils": ^2.1.2 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -6313,10 +6313,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.2 "@medusajs/test-utils": ^2.1.2 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -6338,10 +6338,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.2 "@medusajs/test-utils": ^2.1.2 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -6363,10 +6363,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.2 "@medusajs/test-utils": ^2.1.2 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 faker: ^5.5.3 @@ -6389,10 +6389,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.2 "@medusajs/test-utils": ^2.1.2 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -6414,10 +6414,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.2 "@medusajs/test-utils": ^2.1.2 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -6439,10 +6439,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.2 "@medusajs/test-utils": ^2.1.2 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -6464,10 +6464,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.2 "@medusajs/test-utils": ^2.1.2 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -6489,10 +6489,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.2 "@medusajs/test-utils": ^2.1.2 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -6514,10 +6514,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.2 "@medusajs/test-utils": ^2.1.2 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -6560,10 +6560,10 @@ __metadata: resolution: "@medusajs/test-utils@workspace:packages/medusa-test-utils" dependencies: "@medusajs/framework": ^2.1.2 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/knex": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/knex": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@types/express": ^4.17.17 awilix: ^8.0.1 axios: ^0.21.4 @@ -6728,10 +6728,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.2 "@medusajs/test-utils": ^2.1.2 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -6757,10 +6757,10 @@ __metadata: "@graphql-tools/merge": ^9.0.7 "@graphql-tools/schema": ^10.0.6 "@medusajs/types": ^2.1.2 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/knex": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/knex": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 "@types/express": ^4.17.21 @@ -6798,10 +6798,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.2 "@medusajs/test-utils": ^2.1.2 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 cron-parser: ^4.9.0 @@ -6825,10 +6825,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.2 "@medusajs/test-utils": ^2.1.2 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 bullmq: 5.13.0 @@ -6855,10 +6855,10 @@ __metadata: "@medusajs/orchestration": ^2.1.2 "@medusajs/types": ^2.1.2 "@medusajs/utils": ^2.1.2 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/knex": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/knex": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 awilix: ^8.0.1 From d4e2afc10b92d3b54587a835b498a28251684499 Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Wed, 18 Dec 2024 08:13:10 -0300 Subject: [PATCH 132/175] fix hasOne with fk --- .../src/dml/__tests__/entity-builder.spec.ts | 15 ++---- .../entity-builder/define-relationship.ts | 36 ++++++++++++-- .../modules/cart/src/services/cart-module.ts | 48 ------------------- 3 files changed, 36 insertions(+), 63 deletions(-) diff --git a/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts b/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts index 764cf6c4b8426..b85d83d335b3d 100644 --- a/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts +++ b/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts @@ -3131,7 +3131,6 @@ describe("Entity builder", () => { entity: "Email", fieldName: "email_id", orphanRemoval: true, - persist: false, }, email_id: { columnType: "text", @@ -3139,7 +3138,7 @@ describe("Entity builder", () => { kind: "scalar", name: "email_id", nullable: false, - persist: true, + persist: false, getter: false, setter: false, }, @@ -3244,7 +3243,6 @@ describe("Entity builder", () => { nullable: true, fieldName: "emails_id", orphanRemoval: true, - persist: false, }, emails_id: { columnType: "text", @@ -3252,7 +3250,7 @@ describe("Entity builder", () => { kind: "scalar", name: "emails_id", nullable: true, - persist: true, + persist: false, getter: false, setter: false, }, @@ -3348,7 +3346,6 @@ describe("Entity builder", () => { mappedBy: "owner", fieldName: "email_id", orphanRemoval: true, - persist: false, }, email_id: { columnType: "text", @@ -3356,7 +3353,7 @@ describe("Entity builder", () => { kind: "scalar", name: "email_id", nullable: false, - persist: true, + persist: false, getter: false, setter: false, }, @@ -3456,7 +3453,6 @@ describe("Entity builder", () => { mappedBy: "user", fieldName: "email_id", orphanRemoval: true, - persist: false, }, email_id: { columnType: "text", @@ -3464,7 +3460,7 @@ describe("Entity builder", () => { kind: "scalar", name: "email_id", nullable: false, - persist: true, + persist: false, getter: false, setter: false, }, @@ -3634,7 +3630,6 @@ describe("Entity builder", () => { mappedBy: "user", fieldName: "email_id", orphanRemoval: true, - persist: false, }, email_id: { columnType: "text", @@ -3642,7 +3637,7 @@ describe("Entity builder", () => { kind: "scalar", name: "email_id", nullable: false, - persist: true, + persist: false, getter: false, setter: false, }, diff --git a/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts b/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts index 2bea6e4912d42..063a03342de01 100644 --- a/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts +++ b/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts @@ -7,6 +7,7 @@ import { } from "@medusajs/types" import { BeforeCreate, + BeforeUpdate, Cascade, ManyToMany, ManyToOne, @@ -181,7 +182,10 @@ export function defineHasOneWithFKRelationship( { relatedModelName }: { relatedModelName: string }, cascades: EntityCascades ) { - const foreignKeyName = camelToSnakeCase(`${relationship.name}Id`) + const foreignKeyName = + relationship.options.foreignKeyName ?? + camelToSnakeCase(`${relationship.name}Id`) + const shouldRemoveRelated = !!cascades.delete?.includes(relationship.name) let mappedBy: string | undefined = camelToSnakeCase(MikroORMEntity.name) @@ -191,15 +195,14 @@ export function defineHasOneWithFKRelationship( const oneToOneOptions = { entity: relatedModelName, + fieldName: foreignKeyName, ...(relationship.nullable ? { nullable: relationship.nullable } : {}), ...(mappedBy ? { mappedBy } : {}), - fieldName: foreignKeyName, orphanRemoval: true, - persist: false, } as OneToOneOptions if (shouldRemoveRelated) { - oneToOneOptions["cascade"] = ["persist", "soft-remove"] as any + oneToOneOptions.cascade = ["persist", "soft-remove"] as any } OneToOne(oneToOneOptions)(MikroORMEntity.prototype, relationship.name) @@ -208,8 +211,31 @@ export function defineHasOneWithFKRelationship( type: "string", columnType: "text", nullable: relationship.nullable, - persist: true, + persist: false, })(MikroORMEntity.prototype, foreignKeyName) + + const hookName = `assignRelationFromForeignKeyValue${foreignKeyName}` + /** + * Hook to handle foreign key assignation + */ + MikroORMEntity.prototype[hookName] = function () { + const relationMeta = this.__meta.relations.find( + (relation) => relation.name === relationship.name + ).targetMeta + this[relationship.name] ??= rel(relationMeta.class, this[foreignKeyName]) + this[relationship.name] ??= this[relationship.name]?.id + this[foreignKeyName] = this[relationship.name] + ? this[relationship.name]?.id ?? this[relationship.name] + : this[foreignKeyName] + return + } + + /** + * Execute hook via lifecycle decorators + */ + BeforeCreate()(MikroORMEntity.prototype, hookName) + BeforeUpdate()(MikroORMEntity.prototype, hookName) + OnInit()(MikroORMEntity.prototype, hookName) } /** diff --git a/packages/modules/cart/src/services/cart-module.ts b/packages/modules/cart/src/services/cart-module.ts index 7b2e0a7c82b18..25f155e0e87c7 100644 --- a/packages/modules/cart/src/services/cart-module.ts +++ b/packages/modules/cart/src/services/cart-module.ts @@ -290,8 +290,6 @@ export default class CartModuleService data: CartTypes.CreateCartDTO[], @MedusaContext() sharedContext: Context = {} ) { - await this.createCartAddresses_(data, sharedContext) - const lineItemsToCreate: CreateLineItemDTO[] = [] const createdCarts: InferEntityType[] = [] for (const { items, ...cart } of data) { @@ -318,52 +316,6 @@ export default class CartModuleService return createdCarts } - @InjectTransactionManager() - protected async createCartAddresses_( - input: CartTypes.CreateCartDTO[], - @MedusaContext() sharedContext: Context = {} - ) { - const allAddresses: { - data: CartTypes.CreateAddressDTO - type: "billing" | "shipping" - source: CartTypes.CreateCartDTO - }[] = [] - - input.forEach((inputData) => { - if (inputData.billing_address) { - allAddresses.push({ - data: inputData.billing_address as CartTypes.CreateAddressDTO, - type: "billing", - source: inputData, - }) - } - - if (inputData.shipping_address) { - allAddresses.push({ - data: inputData.shipping_address as CartTypes.CreateAddressDTO, - type: "shipping", - source: inputData, - }) - } - }) - - const createdAddresses = allAddresses.length - ? await this.createAddresses( - allAddresses.map((a) => a.data), - sharedContext - ) - : [] - - createdAddresses.forEach((createdAddress, index) => { - const { type, source } = allAddresses[index] - if (type === "billing") { - source.billing_address_id = createdAddress.id - } else if (type === "shipping") { - source.shipping_address_id = createdAddress.id - } - }) - } - // @ts-expect-error async updateCarts( data: CartTypes.UpdateCartDTO[] From 986dd451c9e000917ea724c4acfe397974f968cb Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Wed, 18 Dec 2024 14:37:26 -0300 Subject: [PATCH 133/175] update --- .../entity-builder/define-relationship.ts | 229 +++++++++++------- 1 file changed, 144 insertions(+), 85 deletions(-) diff --git a/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts b/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts index 063a03342de01..30ddd9b79d48c 100644 --- a/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts +++ b/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts @@ -212,30 +212,64 @@ export function defineHasOneWithFKRelationship( columnType: "text", nullable: relationship.nullable, persist: false, + formula(alias) { + return alias + "." + foreignKeyName + }, })(MikroORMEntity.prototype, foreignKeyName) - const hookName = `assignRelationFromForeignKeyValue${foreignKeyName}` - /** - * Hook to handle foreign key assignation - */ - MikroORMEntity.prototype[hookName] = function () { - const relationMeta = this.__meta.relations.find( - (relation) => relation.name === relationship.name - ).targetMeta - this[relationship.name] ??= rel(relationMeta.class, this[foreignKeyName]) - this[relationship.name] ??= this[relationship.name]?.id - this[foreignKeyName] = this[relationship.name] - ? this[relationship.name]?.id ?? this[relationship.name] - : this[foreignKeyName] - return + const hookFactory = function ( + name: string, + type: "init" | "create" | "update", + hookFn: Function + ) { + MikroORMEntity.prototype[name] = function ( + this: typeof MikroORMEntity.prototype + ) { + if (type !== "update") { + // During creation + const relationMeta = this.__meta.relations.find( + (relation) => relation.name === relationship.name + ).targetMeta + this[relationship.name] ??= rel( + relationMeta.class, + this[foreignKeyName] + ) + this[foreignKeyName] ??= this[relationship.name]?.id + + return + } + + if (this[relationship.name]) { + this[foreignKeyName] = this[relationship.name].id + } + + if (this[relationship.name] === null) { + this[foreignKeyName] = null + } + + return + } + hookFn()(MikroORMEntity.prototype, name) } /** - * Execute hook via lifecycle decorators + * Hook to handle foreign key assignation */ - BeforeCreate()(MikroORMEntity.prototype, hookName) - BeforeUpdate()(MikroORMEntity.prototype, hookName) - OnInit()(MikroORMEntity.prototype, hookName) + hookFactory( + `assignRelationFromForeignKeyValue${foreignKeyName}_init`, + "init", + OnInit + ) + hookFactory( + `assignRelationFromForeignKeyValue${foreignKeyName}_create`, + "create", + BeforeCreate + ) + hookFactory( + `assignRelationFromForeignKeyValue${foreignKeyName}_update`, + "update", + BeforeUpdate + ) } /** @@ -293,89 +327,116 @@ export function defineBelongsToRelationship( */ const shouldCascade = !!relationCascades.delete?.includes(mappedBy) - /** - * Ensure the mapped by is defined as relationship on the other side - */ - if (!otherSideRelation) { - throw new Error( - `Missing property "${mappedBy}" on "${relatedModelName}" entity. Make sure to define it as a relationship` - ) - } - function applyForeignKeyAssignationHooks(foreignKeyName: string) { - const hookName = `assignRelationFromForeignKeyValue${foreignKeyName}` - /** - * Hook to handle foreign key assignation - */ - MikroORMEntity.prototype[hookName] = function () { - /** - * In case of has one relation, in order to be able to have both ways - * to associate a relation (through the relation or the foreign key) we need to handle it - * specifically - */ - if ( - HasOne.isHasOne(otherSideRelation) || - HasOneWithForeignKey.isHasOneWithForeignKey(otherSideRelation) + const hookFactory = function ( + name: string, + type: "init" | "create" | "update", + hookFn: Function + ) { + MikroORMEntity.prototype[name] = function ( + this: typeof MikroORMEntity.prototype ) { - const relationMeta = this.__meta.relations.find( - (relation) => relation.name === relationship.name - ).targetMeta - this[relationship.name] ??= rel( - relationMeta.class, - this[foreignKeyName] - ) - this[relationship.name] ??= this[relationship.name]?.id - return - } + /** + * In case of has one relation, in order to be able to have both ways + * to associate a relation (through the relation or the foreign key) we need to handle it + * specifically + */ + if ( + HasOne.isHasOne(otherSideRelation) || + HasOneWithForeignKey.isHasOneWithForeignKey(otherSideRelation) + ) { + if (type !== "update") { + // During creation + const relationMeta = this.__meta.relations.find( + (relation) => relation.name === relationship.name + ).targetMeta + this[relationship.name] ??= rel( + relationMeta.class, + this[foreignKeyName] + ) + this[foreignKeyName] ??= this[relationship.name]?.id + + return + } - /** - * Do not override the existing foreign key value if - * exists - */ - if (this[foreignKeyName] !== undefined) { - return - } + if (this[relationship.name]) { + this[foreignKeyName] = this[relationship.name].id + } - /** - * Set the foreign key when the relationship is initialized - * as null - */ - if (this[relationship.name] === null) { - this[foreignKeyName] = null - return - } + if (this[relationship.name] === null) { + this[foreignKeyName] = null + } - /** - * Set the foreign key when the relationship is initialized - * and as the id - */ - if (this[relationship.name] && "id" in this[relationship.name]) { - this[foreignKeyName] = this[relationship.name].id + return + } + + /** + * Do not override the existing foreign key value if + * exists + */ + if (this[foreignKeyName] !== undefined) { + return + } + + /** + * Set the foreign key when the relationship is initialized + * as null + */ + if (this[relationship.name] === null) { + this[foreignKeyName] = null + return + } + + /** + * Set the foreign key when the relationship is initialized + * and as the id + */ + if (this[relationship.name] && "id" in this[relationship.name]) { + this[foreignKeyName] = this[relationship.name].id + } } + hookFn()(MikroORMEntity.prototype, name) } /** - * Execute hook via lifecycle decorators + * Hook to handle foreign key assignation */ - BeforeCreate()(MikroORMEntity.prototype, hookName) - OnInit()(MikroORMEntity.prototype, hookName) + hookFactory( + `assignRelationFromForeignKeyValue${foreignKeyName}_init`, + "init", + OnInit + ) + hookFactory( + `assignRelationFromForeignKeyValue${foreignKeyName}_create`, + "create", + BeforeCreate + ) + hookFactory( + `assignRelationFromForeignKeyValue${foreignKeyName}_update`, + "update", + BeforeUpdate + ) } /** * Otherside is a has many. Hence we should defined a ManyToOne */ if ( + !otherSideRelation || HasMany.isHasMany(otherSideRelation) || DmlManyToMany.isManyToMany(otherSideRelation) ) { - const foreignKeyName = camelToSnakeCase(`${relationship.name}Id`) + const foreignKeyName = + relationship.options.foreignKeyName ?? + camelToSnakeCase(`${relationship.name}Id`) + const detachCascade = !!relationship.mappedBy && relationCascades.detach?.includes(relationship.mappedBy) if (DmlManyToMany.isManyToMany(otherSideRelation)) { Property({ - type: "string", + type: relatedModelName, columnType: "text", fieldName: foreignKeyName, nullable: relationship.nullable, @@ -384,7 +445,6 @@ export function defineBelongsToRelationship( const conf = { entity: relatedModelName, nullable: relationship.nullable, - fieldName: foreignKeyName, persist: false, } if (shouldCascade || detachCascade) { @@ -430,19 +490,17 @@ export function defineBelongsToRelationship( HasOne.isHasOne(otherSideRelation) || HasOneWithForeignKey.isHasOneWithForeignKey(otherSideRelation) ) { - const foreignKeyName = camelToSnakeCase(`${relationship.name}Id`) - - Object.defineProperty(MikroORMEntity.prototype, foreignKeyName, { - configurable: true, - enumerable: true, - writable: true, - }) - + const foreignKeyName = + relationship.options.foreignKeyName ?? + camelToSnakeCase(`${relationship.name}Id`) Property({ columnType: "text", type: "string", nullable: relationship.nullable, persist: false, + formula(alias) { + return alias + "." + foreignKeyName + }, })(MikroORMEntity.prototype, foreignKeyName) const oneToOneOptions: Parameters[0] = { @@ -451,6 +509,7 @@ export function defineBelongsToRelationship( mappedBy: mappedBy, fieldName: foreignKeyName, owner: true, + orphanRemoval: true, } if (shouldCascade) { From cd75aa035a225add3d2e9b1cdce7a6c232d06178 Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Thu, 19 Dec 2024 14:47:34 -0300 Subject: [PATCH 134/175] free text filter per entity --- .../mikro-orm-free-text-search-filter.ts | 38 +++++++------------ .../src/dal/mikro-orm/mikro-orm-repository.ts | 20 ---------- .../dml/helpers/create-mikro-orm-entity.ts | 16 +++++--- .../loaders/mikro-orm-connection-loader.ts | 15 +------- 4 files changed, 26 insertions(+), 63 deletions(-) diff --git a/packages/core/utils/src/dal/mikro-orm/mikro-orm-free-text-search-filter.ts b/packages/core/utils/src/dal/mikro-orm/mikro-orm-free-text-search-filter.ts index 5679fbb5b9138..baba5b9ca74d4 100644 --- a/packages/core/utils/src/dal/mikro-orm/mikro-orm-free-text-search-filter.ts +++ b/packages/core/utils/src/dal/mikro-orm/mikro-orm-free-text-search-filter.ts @@ -4,23 +4,20 @@ import type { FindOneOptions, FindOptions, } from "@mikro-orm/core" -import { EntityMetadata, EntitySchema, ReferenceKind } from "@mikro-orm/core" +import { EntityMetadata, ReferenceKind } from "@mikro-orm/core" import { SqlEntityManager } from "@mikro-orm/postgresql" -export const FreeTextSearchFilterKey = "freeTextSearch" +export const FreeTextSearchFilterKeyPrefix = "freeTextSearch_" interface FilterArgument { value: string fromEntity: string } -function getEntityProperties(entity: EntityClass | EntitySchema): { +function getEntityProperties(metadata: EntityMetadata): { [key: string]: EntityProperty } { - return ( - (entity as EntityClass)?.prototype.__meta?.properties ?? - (entity as EntitySchema).meta?.properties - ) + return metadata.properties } function retrieveRelationsConstraints( @@ -31,7 +28,7 @@ function retrieveRelationsConstraints( type: string name: string }, - models: (EntityClass | EntitySchema)[], + metadata: EntityMetadata, searchValue: string, visited: Set = new Set(), shouldStop: boolean = false @@ -46,8 +43,7 @@ function retrieveRelationsConstraints( const relationFreeTextSearchWhere: any = [] - const relationClass = models.find((m) => m.name === relation.type)! - const relationProperties = getEntityProperties(relationClass) + const relationProperties = getEntityProperties(metadata) for (const propertyConfiguration of Object.values(relationProperties)) { if ( @@ -69,9 +65,7 @@ function retrieveRelationsConstraints( }) } - const innerRelations: EntityProperty[] = - (relationClass as EntityClass)?.prototype.__meta?.relations ?? - (relationClass as EntitySchema).meta?.relations + const innerRelations: EntityProperty[] = metadata.relations for (const innerRelation of innerRelations) { const branchVisited = new Set(Array.from(visited)) @@ -108,7 +102,7 @@ function retrieveRelationsConstraints( mapToPk: innerRelation.mapToPk, type: innerRelation.type, }, - models, + metadata, searchValue, branchVisited, isSelfCircularDependency @@ -128,10 +122,9 @@ function retrieveRelationsConstraints( return relationFreeTextSearchWhere } -export const mikroOrmFreeTextSearchFilterOptionsFactory = ( - models: (EntityClass | EntitySchema)[] -) => { +export const mikroOrmFreeTextSearchFilterOptionsFactory = (model: string) => { return { + name: FreeTextSearchFilterKeyPrefix + model, cond: ( freeTextSearchArgs: FilterArgument, operation: string, @@ -144,7 +137,7 @@ export const mikroOrmFreeTextSearchFilterOptionsFactory = ( return {} } - const { value, fromEntity } = freeTextSearchArgs + const { value } = freeTextSearchArgs if (options?.visited?.size) { /** @@ -158,17 +151,17 @@ export const mikroOrmFreeTextSearchFilterOptionsFactory = ( } } - const entityMetadata = manager.getDriver().getMetadata().get(fromEntity) + const entityMetadata = manager.getDriver().getMetadata().get(model) const freeTextSearchWhere = retrieveRelationsConstraints( { targetMeta: entityMetadata, mapToPk: false, searchable: true, - type: fromEntity, + type: model, name: entityMetadata.name!, }, - models, + entityMetadata, value ) @@ -180,8 +173,5 @@ export const mikroOrmFreeTextSearchFilterOptionsFactory = ( $or: freeTextSearchWhere, } }, - default: true, - args: false, - entity: models.map((m) => m.name) as string[], } } diff --git a/packages/core/utils/src/dal/mikro-orm/mikro-orm-repository.ts b/packages/core/utils/src/dal/mikro-orm/mikro-orm-repository.ts index 0115948f16958..b335c43f760cc 100644 --- a/packages/core/utils/src/dal/mikro-orm/mikro-orm-repository.ts +++ b/packages/core/utils/src/dal/mikro-orm/mikro-orm-repository.ts @@ -245,26 +245,6 @@ export class MikroOrmBaseRepository return [entities, softDeletedEntitiesMap] } - - /* - applyFreeTextSearchFilters( - findOptions: DAL.FindOptions, - retrieveConstraintsToApply: (q: string) => any[] - ): void { - if (!("q" in findOptions.where) || !findOptions.where.q) { - delete findOptions.where.q - - return - } - - const q = findOptions.where.q as string - delete findOptions.where.q - - findOptions.where = { - $and: [findOptions.where, { $or: retrieveConstraintsToApply(q) }], - } as unknown as DAL.FindOptions["where"] - } - */ } export class MikroOrmBaseTreeRepository< diff --git a/packages/core/utils/src/dml/helpers/create-mikro-orm-entity.ts b/packages/core/utils/src/dml/helpers/create-mikro-orm-entity.ts index 5fca76d11111b..6103974973441 100644 --- a/packages/core/utils/src/dml/helpers/create-mikro-orm-entity.ts +++ b/packages/core/utils/src/dml/helpers/create-mikro-orm-entity.ts @@ -8,15 +8,18 @@ import type { } from "@medusajs/types" import { Entity, Filter } from "@mikro-orm/core" +import { + mikroOrmFreeTextSearchFilterOptionsFactory, + mikroOrmSoftDeletableFilterOptions, +} from "../../dal" import { DmlEntity } from "../entity" -import { IdProperty } from "../properties/id" import { DuplicateIdPropertyError } from "../errors" -import { applyChecks } from "./mikro-orm/apply-checks" -import { mikroOrmSoftDeletableFilterOptions } from "../../dal" -import { defineProperty } from "./entity-builder/define-property" +import { IdProperty } from "../properties/id" import { applySearchable } from "./entity-builder/apply-searchable" -import { parseEntityName } from "./entity-builder/parse-entity-name" +import { defineProperty } from "./entity-builder/define-property" import { defineRelationship } from "./entity-builder/define-relationship" +import { parseEntityName } from "./entity-builder/parse-entity-name" +import { applyChecks } from "./mikro-orm/apply-checks" import { applyEntityIndexes, applyIndexes } from "./mikro-orm/apply-indexes" /** @@ -102,6 +105,9 @@ function createMikrORMEntity() { /** * Converting class to a MikroORM entity */ + Filter(mikroOrmFreeTextSearchFilterOptionsFactory(modelName))( + MikroORMEntity + ) const RegisteredEntity = Entity({ tableName })( Filter(mikroOrmSoftDeletableFilterOptions)(MikroORMEntity) ) as Infer diff --git a/packages/core/utils/src/modules-sdk/loaders/mikro-orm-connection-loader.ts b/packages/core/utils/src/modules-sdk/loaders/mikro-orm-connection-loader.ts index 94a671c71ccf9..2c86a86ae31a5 100644 --- a/packages/core/utils/src/modules-sdk/loaders/mikro-orm-connection-loader.ts +++ b/packages/core/utils/src/modules-sdk/loaders/mikro-orm-connection-loader.ts @@ -2,11 +2,7 @@ import { Logger, MedusaContainer, ModulesSdkTypes } from "@medusajs/types" import { PostgreSqlDriver, SqlEntityManager } from "@mikro-orm/postgresql" import { asValue } from "awilix" import { ContainerRegistrationKeys, MedusaError } from "../../common" -import { - FreeTextSearchFilterKey, - mikroOrmCreateConnection, - mikroOrmFreeTextSearchFilterOptionsFactory, -} from "../../dal" +import { mikroOrmCreateConnection } from "../../dal" import { isSharedConnectionSymbol } from "../create-pg-connection" import { loadDatabaseConfig } from "../load-module-database-config" @@ -39,9 +35,6 @@ export async function mikroOrmConnectionLoader({ logger?: Logger pathToMigrations: string }) { - const freeTextSearchGlobalFilter = - mikroOrmFreeTextSearchFilterOptionsFactory(entities) - let manager = ( options as ModulesSdkTypes.ModuleServiceInitializeCustomDataLayerOptions )?.manager @@ -68,9 +61,6 @@ export async function mikroOrmConnectionLoader({ return await loadShared({ database: { ...dbConfig, - filters: { - [FreeTextSearchFilterKey as string]: freeTextSearchGlobalFilter, - }, }, container, entities, @@ -98,9 +88,6 @@ export async function mikroOrmConnectionLoader({ manager ??= await loadDefault({ database: { ...dbConfig, - filters: { - [FreeTextSearchFilterKey as string]: freeTextSearchGlobalFilter, - }, }, entities, pathToMigrations, From 40f6a2bf94735449e35e433abe71dedadabeeb45 Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Thu, 19 Dec 2024 14:48:24 -0300 Subject: [PATCH 135/175] tests --- .../mikro-orm-free-text-search-filter.spec.ts | 8 +- .../src/dml/__tests__/entity-builder.spec.ts | 88 +++++++++++++++++-- .../modules-sdk/medusa-internal-service.ts | 4 +- .../integration-tests/__tests__/product.ts | 2 +- 4 files changed, 87 insertions(+), 15 deletions(-) diff --git a/packages/core/utils/src/dal/mikro-orm/__tests__/mikro-orm-free-text-search-filter.spec.ts b/packages/core/utils/src/dal/mikro-orm/__tests__/mikro-orm-free-text-search-filter.spec.ts index 3760644de89fd..abde4e9b0cf8e 100644 --- a/packages/core/utils/src/dal/mikro-orm/__tests__/mikro-orm-free-text-search-filter.spec.ts +++ b/packages/core/utils/src/dal/mikro-orm/__tests__/mikro-orm-free-text-search-filter.spec.ts @@ -19,10 +19,8 @@ describe("mikroOrmFreeTextSearchFilterOptionsFactory", () => { const entityManager = orm.em.fork() const freeTextSearchValue = "search" - const models = [SearchableEntity1, SearchableEntity2] - let filterConstraints = mikroOrmFreeTextSearchFilterOptionsFactory( - models + SearchableEntity1.name ).cond( { value: freeTextSearchValue, @@ -53,7 +51,9 @@ describe("mikroOrmFreeTextSearchFilterOptionsFactory", () => { ], }) - filterConstraints = mikroOrmFreeTextSearchFilterOptionsFactory(models).cond( + filterConstraints = mikroOrmFreeTextSearchFilterOptionsFactory( + SearchableEntity2.name + ).cond( { value: freeTextSearchValue, fromEntity: SearchableEntity2.name, diff --git a/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts b/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts index 1dc83e1df1500..cb62ac9e41db6 100644 --- a/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts +++ b/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts @@ -98,6 +98,10 @@ describe("Entity builder", () => { expect(metaData.path).toEqual("User") expect(metaData.filters).toEqual({ + freeTextSearch_User: { + cond: expect.any(Function), + name: "freeTextSearch_User", + }, softDeletable: { name: "softDeletable", cond: expect.any(Function), @@ -238,6 +242,10 @@ describe("Entity builder", () => { expect(metaData.path).toEqual("User") expect(metaData.filters).toEqual({ + freeTextSearch_User: { + cond: expect.any(Function), + name: "freeTextSearch_User", + }, softDeletable: { name: "softDeletable", cond: expect.any(Function), @@ -369,6 +377,10 @@ describe("Entity builder", () => { expect(metaData.path).toEqual("UserRole") expect(metaData.filters).toEqual({ + freeTextSearch_UserRole: { + cond: expect.any(Function), + name: "freeTextSearch_UserRole", + }, softDeletable: { name: "softDeletable", cond: expect.any(Function), @@ -489,6 +501,10 @@ describe("Entity builder", () => { expect(metaData.path).toEqual("User") expect(metaData.filters).toEqual({ + freeTextSearch_User: { + cond: expect.any(Function), + name: "freeTextSearch_User", + }, softDeletable: { name: "softDeletable", cond: expect.any(Function), @@ -631,6 +647,10 @@ describe("Entity builder", () => { expect(metaData.path).toEqual("User") expect(metaData.filters).toEqual({ + freeTextSearch_User: { + cond: expect.any(Function), + name: "freeTextSearch_User", + }, softDeletable: { name: "softDeletable", cond: expect.any(Function), @@ -776,6 +796,10 @@ describe("Entity builder", () => { }) expect(metaData.filters).toEqual({ + freeTextSearch_User: { + cond: expect.any(Function), + name: "freeTextSearch_User", + }, softDeletable: { name: "softDeletable", cond: expect.any(Function), @@ -898,6 +922,10 @@ describe("Entity builder", () => { expect(metaData.path).toEqual("User") expect(metaData.filters).toEqual({ + freeTextSearch_User: { + cond: expect.any(Function), + name: "freeTextSearch_User", + }, softDeletable: { name: "softDeletable", cond: expect.any(Function), @@ -1015,6 +1043,10 @@ describe("Entity builder", () => { expect(metaData.path).toEqual("User") expect(metaData.filters).toEqual({ + freeTextSearch_User: { + cond: expect.any(Function), + name: "freeTextSearch_User", + }, softDeletable: { name: "softDeletable", cond: expect.any(Function), @@ -1136,6 +1168,10 @@ describe("Entity builder", () => { expect(metaData.path).toEqual("User") expect(metaData.filters).toEqual({ + freeTextSearch_User: { + cond: expect.any(Function), + name: "freeTextSearch_User", + }, softDeletable: { name: "softDeletable", cond: expect.any(Function), @@ -1277,6 +1313,10 @@ describe("Entity builder", () => { expect(metaData.tableName).toEqual("public.user") expect(metaData.filters).toEqual({ + freeTextSearch_User: { + cond: expect.any(Function), + name: "freeTextSearch_User", + }, softDeletable: { name: "softDeletable", cond: expect.any(Function), @@ -1379,6 +1419,10 @@ describe("Entity builder", () => { expect(metaData.path).toEqual("User") expect(metaData.filters).toEqual({ + freeTextSearch_User: { + cond: expect.any(Function), + name: "freeTextSearch_User", + }, softDeletable: { name: "softDeletable", cond: expect.any(Function), @@ -1477,6 +1521,10 @@ describe("Entity builder", () => { expect(metaData.path).toEqual("Tax") expect(metaData.filters).toEqual({ + freeTextSearch_Tax: { + cond: expect.any(Function), + name: "freeTextSearch_Tax", + }, softDeletable: { name: "softDeletable", cond: expect.any(Function), @@ -1572,6 +1620,10 @@ describe("Entity builder", () => { expect(metaData.path).toEqual("User") expect(metaData.filters).toEqual({ + freeTextSearch_User: { + cond: expect.any(Function), + name: "freeTextSearch_User", + }, softDeletable: { name: "softDeletable", cond: expect.any(Function), @@ -1680,6 +1732,10 @@ describe("Entity builder", () => { }) expect(metaData.filters).toEqual({ + freeTextSearch_User: { + cond: expect.any(Function), + name: "freeTextSearch_User", + }, softDeletable: { name: "softDeletable", cond: expect.any(Function), @@ -1790,6 +1846,10 @@ describe("Entity builder", () => { }) expect(metaData.filters).toEqual({ + freeTextSearch_User: { + cond: expect.any(Function), + name: "freeTextSearch_User", + }, softDeletable: { name: "softDeletable", cond: expect.any(Function), @@ -1901,6 +1961,10 @@ describe("Entity builder", () => { }) expect(metaData.filters).toEqual({ + freeTextSearch_User: { + cond: expect.any(Function), + name: "freeTextSearch_User", + }, softDeletable: { name: "softDeletable", cond: expect.any(Function), @@ -2053,6 +2117,10 @@ describe("Entity builder", () => { ]) expect(metaData.filters).toEqual({ + freeTextSearch_User: { + cond: expect.any(Function), + name: "freeTextSearch_User", + }, softDeletable: { name: "softDeletable", cond: expect.any(Function), @@ -2169,6 +2237,10 @@ describe("Entity builder", () => { ]) expect(metaData.filters).toEqual({ + freeTextSearch_User: { + cond: expect.any(Function), + name: "freeTextSearch_User", + }, softDeletable: { name: "softDeletable", cond: expect.any(Function), @@ -2284,6 +2356,10 @@ describe("Entity builder", () => { ]) expect(metaData.filters).toEqual({ + freeTextSearch_User: { + cond: expect.any(Function), + name: "freeTextSearch_User", + }, softDeletable: { name: "softDeletable", cond: expect.any(Function), @@ -6367,7 +6443,7 @@ describe("Entity builder", () => { expect.objectContaining({ user_id: { kind: "scalar", - type: "string", + type: "User", columnType: "text", fieldName: "user_id", nullable: false, @@ -6379,14 +6455,13 @@ describe("Entity builder", () => { name: "user", kind: "m:1", entity: "User", - fieldName: "user_id", nullable: false, persist: false, deleteRule: "cascade", }, team_id: { kind: "scalar", - type: "string", + type: "Team", columnType: "text", fieldName: "team_id", nullable: false, @@ -6398,7 +6473,6 @@ describe("Entity builder", () => { name: "team", kind: "m:1", entity: "Team", - fieldName: "team_id", nullable: false, persist: false, deleteRule: "cascade", @@ -7620,12 +7694,11 @@ describe("Entity builder", () => { getter: false, setter: false, nullable: false, - type: "string", + type: "User", }, user: { kind: "m:1", entity: "User", - fieldName: "user_id", persist: false, nullable: false, name: "user", @@ -7638,12 +7711,11 @@ describe("Entity builder", () => { nullable: false, getter: false, setter: false, - type: "string", + type: "Team", }, team: { kind: "m:1", entity: "Team", - fieldName: "team_id", persist: false, nullable: false, name: "team", diff --git a/packages/core/utils/src/modules-sdk/medusa-internal-service.ts b/packages/core/utils/src/modules-sdk/medusa-internal-service.ts index afce23f736dd8..d18fe53d29812 100644 --- a/packages/core/utils/src/modules-sdk/medusa-internal-service.ts +++ b/packages/core/utils/src/modules-sdk/medusa-internal-service.ts @@ -18,7 +18,7 @@ import { lowerCaseFirst, MedusaError, } from "../common" -import { FreeTextSearchFilterKey } from "../dal" +import { FreeTextSearchFilterKeyPrefix } from "../dal" import { DmlEntity, toMikroORMEntity } from "../dml" import { buildQuery } from "./build-query" import { @@ -67,7 +67,7 @@ export function MedusaInternalService< ): void { if (isDefined(filters?.q)) { config.filters ??= {} - config.filters[FreeTextSearchFilterKey] = { + config.filters[FreeTextSearchFilterKeyPrefix + model.name] = { value: filters.q, fromEntity: model.name, } diff --git a/packages/modules/product/integration-tests/__tests__/product.ts b/packages/modules/product/integration-tests/__tests__/product.ts index abb55eec7b000..0a6f1547a34e0 100644 --- a/packages/modules/product/integration-tests/__tests__/product.ts +++ b/packages/modules/product/integration-tests/__tests__/product.ts @@ -323,7 +323,7 @@ moduleIntegrationTestRunner({ }) describe("list", () => { - it.only("should list all product that match the free text search", async () => { + it("should list all product that match the free text search", async () => { const data = buildProductOnlyData({ title: "test product", }) From 63fcdf5f3c75c064bc570cc362782a245a013ac6 Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Thu, 19 Dec 2024 14:57:58 -0300 Subject: [PATCH 136/175] prod category --- packages/modules/product/src/services/product-category.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/modules/product/src/services/product-category.ts b/packages/modules/product/src/services/product-category.ts index b97033b75b83e..df27f4a4bbfbd 100644 --- a/packages/modules/product/src/services/product-category.ts +++ b/packages/modules/product/src/services/product-category.ts @@ -6,7 +6,7 @@ import { ProductTypes, } from "@medusajs/framework/types" import { - FreeTextSearchFilterKey, + FreeTextSearchFilterKeyPrefix, InjectManager, InjectTransactionManager, isDefined, @@ -87,7 +87,7 @@ export default class ProductCategoryService { // Apply free text search filter if (isDefined(filters?.q)) { config.filters ??= {} - config.filters[FreeTextSearchFilterKey] = { + config.filters[FreeTextSearchFilterKeyPrefix + ProductCategory.name] = { value: filters.q, fromEntity: ProductCategory.name, } @@ -121,7 +121,7 @@ export default class ProductCategoryService { // Apply free text search filter if (isDefined(filters?.q)) { config.filters ??= {} - config.filters[FreeTextSearchFilterKey] = { + config.filters[FreeTextSearchFilterKeyPrefix + ProductCategory.name] = { value: filters.q, fromEntity: ProductCategory.name, } From 1a18a43d95241c532351e96142a77030bce82867 Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Thu, 19 Dec 2024 15:36:27 -0300 Subject: [PATCH 137/175] property string many to many --- .../core/utils/src/dml/__tests__/entity-builder.spec.ts | 8 ++++---- .../src/dml/helpers/entity-builder/define-relationship.ts | 2 +- .../__tests__/services/cart-module/index.spec.ts | 2 -- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts b/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts index cb62ac9e41db6..80cfbf6f8aca9 100644 --- a/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts +++ b/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts @@ -6443,7 +6443,7 @@ describe("Entity builder", () => { expect.objectContaining({ user_id: { kind: "scalar", - type: "User", + type: "string", columnType: "text", fieldName: "user_id", nullable: false, @@ -6461,7 +6461,7 @@ describe("Entity builder", () => { }, team_id: { kind: "scalar", - type: "Team", + type: "string", columnType: "text", fieldName: "team_id", nullable: false, @@ -7694,7 +7694,7 @@ describe("Entity builder", () => { getter: false, setter: false, nullable: false, - type: "User", + type: "string", }, user: { kind: "m:1", @@ -7711,7 +7711,7 @@ describe("Entity builder", () => { nullable: false, getter: false, setter: false, - type: "Team", + type: "string", }, team: { kind: "m:1", diff --git a/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts b/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts index c51c3b0c4ebc0..8cf16e0b607ca 100644 --- a/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts +++ b/packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts @@ -435,7 +435,7 @@ export function defineBelongsToRelationship( if (DmlManyToMany.isManyToMany(otherSideRelation)) { Property({ - type: relatedModelName, + type: "string", columnType: "text", fieldName: foreignKeyName, nullable: relationship.nullable, diff --git a/packages/modules/cart/integration-tests/__tests__/services/cart-module/index.spec.ts b/packages/modules/cart/integration-tests/__tests__/services/cart-module/index.spec.ts index b0da88c1d6214..4977a3e0dd396 100644 --- a/packages/modules/cart/integration-tests/__tests__/services/cart-module/index.spec.ts +++ b/packages/modules/cart/integration-tests/__tests__/services/cart-module/index.spec.ts @@ -2488,8 +2488,6 @@ moduleIntegrationTestRunner({ const asJson = JSON.parse(JSON.stringify(cart)) expect(asJson).toEqual({ id: createdCart.id, - billing_address: null, - shipping_address: null, items: [ { id: itemOne.id, From 27111f71c83d62fd98d85553cd27806c61caeb4b Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Thu, 19 Dec 2024 17:47:40 -0300 Subject: [PATCH 138/175] fix big number --- .../src/dal/mikro-orm/big-number-field.ts | 6 ++--- .../src/dml/__tests__/entity-builder.spec.ts | 24 +++++++++---------- .../order/src/utils/apply-order-changes.ts | 7 ++---- 3 files changed, 17 insertions(+), 20 deletions(-) diff --git a/packages/core/utils/src/dal/mikro-orm/big-number-field.ts b/packages/core/utils/src/dal/mikro-orm/big-number-field.ts index 588f7ceaad9d1..3a8c7cb7c9d96 100644 --- a/packages/core/utils/src/dal/mikro-orm/big-number-field.ts +++ b/packages/core/utils/src/dal/mikro-orm/big-number-field.ts @@ -26,7 +26,7 @@ export function MikroOrmBigNumberProperty( set(value: BigNumberInput) { if (options?.nullable && !isPresent(value)) { this.__helper.__data[columnName] = null - this.__helper.__data[rawColumnName] + this.__helper.__data[rawColumnName] = null this[rawColumnName] = null } else { let bigNumber: BigNumber @@ -77,10 +77,10 @@ export function MikroOrmBigNumberProperty( }) Property({ - type: "number", + type: "any", columnType: "numeric", trackChanges: false, - runtimeType: "number", + runtimeType: "any", ...options, })(target, columnName) } diff --git a/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts b/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts index 80cfbf6f8aca9..84faa161c3696 100644 --- a/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts +++ b/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts @@ -162,8 +162,8 @@ describe("Entity builder", () => { kind: "scalar", setter: true, trackChanges: false, - type: "number", - runtimeType: "number", + type: "any", + runtimeType: "any", }, raw_spend_limit: { columnType: "jsonb", @@ -306,8 +306,8 @@ describe("Entity builder", () => { kind: "scalar", setter: true, trackChanges: false, - type: "number", - runtimeType: "number", + type: "any", + runtimeType: "any", }, raw_spend_limit: { columnType: "jsonb", @@ -441,8 +441,8 @@ describe("Entity builder", () => { kind: "scalar", setter: true, trackChanges: false, - type: "number", - runtimeType: "number", + type: "any", + runtimeType: "any", }, raw_spend_limit: { columnType: "jsonb", @@ -555,8 +555,8 @@ describe("Entity builder", () => { kind: "scalar", setter: true, trackChanges: false, - type: "number", - runtimeType: "number", + type: "any", + runtimeType: "any", }, raw_spend_limit: { columnType: "jsonb", @@ -701,8 +701,8 @@ describe("Entity builder", () => { kind: "scalar", setter: true, trackChanges: false, - type: "number", - runtimeType: "number", + type: "any", + runtimeType: "any", }, raw_spend_limit: { columnType: "jsonb", @@ -858,8 +858,8 @@ describe("Entity builder", () => { kind: "scalar", setter: true, trackChanges: false, - type: "number", - runtimeType: "number", + type: "any", + runtimeType: "any", }, created_at: { kind: "scalar", diff --git a/packages/modules/order/src/utils/apply-order-changes.ts b/packages/modules/order/src/utils/apply-order-changes.ts index 124f4f119a35e..5f70edf4a060c 100644 --- a/packages/modules/order/src/utils/apply-order-changes.ts +++ b/packages/modules/order/src/utils/apply-order-changes.ts @@ -76,6 +76,8 @@ export function applyChangesToOrder( version, quantity: orderItem.quantity, unit_price: item.unit_price ?? orderItem.unit_price, + compare_at_unit_price: + item.compare_at_unit_price ?? orderItem.compare_at_unit_price, fulfilled_quantity: orderItem.fulfilled_quantity ?? 0, delivered_quantity: orderItem.delivered_quantity ?? 0, shipped_quantity: orderItem.shipped_quantity ?? 0, @@ -86,11 +88,6 @@ export function applyChangesToOrder( metadata: orderItem.metadata, } as OrderItem - if (item.compare_at_unit_price || orderItem.compare_at_unit_price) { - itemToUpsert.compare_at_unit_price = - item.compare_at_unit_price ?? orderItem.compare_at_unit_price - } - itemsToUpsert.push(itemToUpsert) } From 65be12d9c26071707ec8aea53bdfd4d452fb6d90 Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Fri, 20 Dec 2024 08:34:36 -0300 Subject: [PATCH 139/175] link modules migration set names --- .../__tests__/migrations.spec.ts | 40 +++++++++++++++++-- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/packages/modules/link-modules/integration-tests/__tests__/migrations.spec.ts b/packages/modules/link-modules/integration-tests/__tests__/migrations.spec.ts index 15faf8cc89225..b3d1b1e4f2c76 100644 --- a/packages/modules/link-modules/integration-tests/__tests__/migrations.spec.ts +++ b/packages/modules/link-modules/integration-tests/__tests__/migrations.spec.ts @@ -69,13 +69,43 @@ moduleIntegrationTestRunner({ toModel: "car", }, tableName: "user_user_car_car", - sql: 'create table if not exists "user_user_car_car" ("user_id" varchar(255) not null, "car_id" varchar(255) not null, "id" varchar(255) not null, "created_at" timestamptz(0) not null default CURRENT_TIMESTAMP, "updated_at" timestamptz(0) not null default CURRENT_TIMESTAMP, "deleted_at" timestamptz(0) null, constraint "user_user_car_car_pkey" primary key ("user_id", "car_id"));\ncreate index if not exists "IDX_car_id_-92128f74" on "user_user_car_car" ("car_id");\ncreate index if not exists "IDX_id_-92128f74" on "user_user_car_car" ("id");\ncreate index if not exists "IDX_user_id_-92128f74" on "user_user_car_car" ("user_id");\ncreate index if not exists "IDX_deleted_at_-92128f74" on "user_user_car_car" ("deleted_at");\n\n', + sql: + "set names 'utf8';\n" + + "\n" + + 'create table if not exists "user_user_car_car" ("user_id" varchar(255) not null, "car_id" varchar(255) not null, "id" varchar(255) not null, "created_at" timestamptz not null default CURRENT_TIMESTAMP, "updated_at" timestamptz not null default CURRENT_TIMESTAMP, "deleted_at" timestamptz null, constraint "user_user_car_car_pkey" primary key ("user_id", "car_id"));\n' + + 'create index if not exists "IDX_car_id_-92128f74" on "user_user_car_car" ("car_id");\n' + + 'create index if not exists "IDX_id_-92128f74" on "user_user_car_car" ("id");\n' + + 'create index if not exists "IDX_user_id_-92128f74" on "user_user_car_car" ("user_id");\n' + + 'create index if not exists "IDX_deleted_at_-92128f74" on "user_user_car_car" ("deleted_at");\n' + + "\n", + }) + + expect(actionPlan[1]).toEqual({ + action: "create", + linkDescriptor: { + fromModule: "user", + toModule: + "CustomModuleImplementationContainingAReallyBigNameThatExceedsPosgresLimitToNameATable", + fromModel: "user", + toModel: "very_long_table_name_of_custom_module", + }, + tableName: "user_user_cust_very_long_tabl_name_of_cust_modu1776e67de", + sql: + "set names 'utf8';\n" + + "\n" + + 'create table if not exists "user_user_cust_very_long_tabl_name_of_cust_modu1776e67de" ("user_id" varchar(255) not null, "very_long_table_name_of_custom_module_id" varchar(255) not null, "id" varchar(255) not null, "created_at" timestamptz not null default CURRENT_TIMESTAMP, "updated_at" timestamptz not null default CURRENT_TIMESTAMP, "deleted_at" timestamptz null, constraint "user_user_cust_very_long_tabl_name_of_cust_modu1776e67de_pkey" primary key ("user_id", "very_long_table_name_of_custom_module_id"));\n' + + 'create index if not exists "IDX_very_long_table_name_of_custom_module_id_1776e67de" on "user_user_cust_very_long_tabl_name_of_cust_modu1776e67de" ("very_long_table_name_of_custom_module_id");\n' + + 'create index if not exists "IDX_id_1776e67de" on "user_user_cust_very_long_tabl_name_of_cust_modu1776e67de" ("id");\n' + + 'create index if not exists "IDX_user_id_1776e67de" on "user_user_cust_very_long_tabl_name_of_cust_modu1776e67de" ("user_id");\n' + + 'create index if not exists "IDX_deleted_at_1776e67de" on "user_user_cust_very_long_tabl_name_of_cust_modu1776e67de" ("deleted_at");\n' + + "\n", }) /** * Expect an update plan */ - ;(MedusaModule as any).customLinks_.length = 0 + // @ts-ignore + MedusaModule.customLinks_.length = 0 defineLink(UserModule.linkable.user, CarModule.linkable.car, { database: { @@ -114,7 +144,11 @@ moduleIntegrationTestRunner({ toModel: "car", }, tableName: "user_user_car_car", - sql: 'alter table if exists "user_user_car_car" add column if not exists "data" jsonb not null;\n\n', + sql: + "set names 'utf8';\n" + + "\n" + + 'alter table if exists "user_user_car_car" add column if not exists "data" jsonb not null;\n' + + "\n", }) /** From 1e203d0a5f32254346d0f77f16469404e53c632d Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Fri, 20 Dec 2024 09:02:58 -0300 Subject: [PATCH 140/175] merge --- packages/core/core-flows/package.json | 8 +- packages/core/framework/package.json | 8 +- packages/medusa-test-utils/package.json | 8 +- packages/modules/api-key/package.json | 2 +- packages/modules/auth/package.json | 8 +- packages/modules/cart/package.json | 8 +- packages/modules/currency/package.json | 8 +- packages/modules/customer/package.json | 8 +- packages/modules/file/package.json | 8 +- packages/modules/fulfillment/package.json | 8 +- packages/modules/index/package.json | 10 +- packages/modules/inventory/package.json | 8 +- packages/modules/link-modules/package.json | 6 +- packages/modules/locking/package.json | 8 +- packages/modules/notification/package.json | 8 +- packages/modules/order/package.json | 8 +- packages/modules/payment/package.json | 8 +- packages/modules/pricing/package.json | 8 +- packages/modules/product/package.json | 8 +- packages/modules/promotion/package.json | 8 +- .../providers/locking-postgres/package.json | 8 +- packages/modules/region/package.json | 8 +- packages/modules/sales-channel/package.json | 8 +- packages/modules/stock-location/package.json | 8 +- packages/modules/store/package.json | 8 +- packages/modules/tax/package.json | 8 +- packages/modules/user/package.json | 8 +- .../workflow-engine-inmemory/package.json | 8 +- .../workflow-engine-redis/package.json | 8 +- yarn.lock | 266 +++++++++--------- 30 files changed, 246 insertions(+), 246 deletions(-) diff --git a/packages/core/core-flows/package.json b/packages/core/core-flows/package.json index ac9939a8d1355..98ea983f9c248 100644 --- a/packages/core/core-flows/package.json +++ b/packages/core/core-flows/package.json @@ -27,10 +27,10 @@ "license": "MIT", "devDependencies": { "@medusajs/framework": "^2.1.3", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/knex": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/knex": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "awilix": "^8.0.1", diff --git a/packages/core/framework/package.json b/packages/core/framework/package.json index 980222c59e562..7ac31241f70e4 100644 --- a/packages/core/framework/package.json +++ b/packages/core/framework/package.json @@ -53,10 +53,10 @@ }, "devDependencies": { "@medusajs/cli": "^2.1.3", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/knex": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/knex": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "@types/cors": "^2.8.17", diff --git a/packages/medusa-test-utils/package.json b/packages/medusa-test-utils/package.json index 2727759c871d9..e3a099dcbc5f0 100644 --- a/packages/medusa-test-utils/package.json +++ b/packages/medusa-test-utils/package.json @@ -26,10 +26,10 @@ "license": "MIT", "devDependencies": { "@medusajs/framework": "^2.1.3", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/knex": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/knex": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "awilix": "^8.0.1", "jest": "^29.7.0", "pg": "^8.13.0", diff --git a/packages/modules/api-key/package.json b/packages/modules/api-key/package.json index 7098892e95a87..85807c59dd0b7 100644 --- a/packages/modules/api-key/package.json +++ b/packages/modules/api-key/package.json @@ -38,7 +38,7 @@ "devDependencies": { "@medusajs/framework": "^2.1.3", "@medusajs/test-utils": "^2.1.3", - "@mikro-orm/cli": "5.9.7", + "@mikro-orm/cli": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", diff --git a/packages/modules/auth/package.json b/packages/modules/auth/package.json index 82391150644c2..1400e0f4e636a 100644 --- a/packages/modules/auth/package.json +++ b/packages/modules/auth/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.3", "@medusajs/test-utils": "^2.1.3", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", diff --git a/packages/modules/cart/package.json b/packages/modules/cart/package.json index 417d2262e7f30..913bdcf420da3 100644 --- a/packages/modules/cart/package.json +++ b/packages/modules/cart/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.3", "@medusajs/test-utils": "^2.1.3", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", diff --git a/packages/modules/currency/package.json b/packages/modules/currency/package.json index 956eb04bf764a..0e21d927ac8a3 100644 --- a/packages/modules/currency/package.json +++ b/packages/modules/currency/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.3", "@medusajs/test-utils": "^2.1.3", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", diff --git a/packages/modules/customer/package.json b/packages/modules/customer/package.json index f26f23d6b5def..1a7da16140402 100644 --- a/packages/modules/customer/package.json +++ b/packages/modules/customer/package.json @@ -39,10 +39,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.3", "@medusajs/test-utils": "^2.1.3", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", diff --git a/packages/modules/file/package.json b/packages/modules/file/package.json index eee20a6a7eee4..92b99b7d8d8d4 100644 --- a/packages/modules/file/package.json +++ b/packages/modules/file/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.3", "@medusajs/test-utils": "^2.1.3", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", diff --git a/packages/modules/fulfillment/package.json b/packages/modules/fulfillment/package.json index f9fea12ac98b8..19bed46e6a4e5 100644 --- a/packages/modules/fulfillment/package.json +++ b/packages/modules/fulfillment/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.3", "@medusajs/test-utils": "^2.1.3", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", diff --git a/packages/modules/index/package.json b/packages/modules/index/package.json index c1251133cddad..e20c7b1436e83 100644 --- a/packages/modules/index/package.json +++ b/packages/modules/index/package.json @@ -38,11 +38,11 @@ "devDependencies": { "@medusajs/framework": "^2.1.3", "@medusajs/test-utils": "^2.1.3", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/knex": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/knex": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", diff --git a/packages/modules/inventory/package.json b/packages/modules/inventory/package.json index 626701823ef7c..1dd463b339b95 100644 --- a/packages/modules/inventory/package.json +++ b/packages/modules/inventory/package.json @@ -25,10 +25,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.3", "@medusajs/test-utils": "^2.1.3", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", diff --git a/packages/modules/link-modules/package.json b/packages/modules/link-modules/package.json index de30e34aba6de..a1bcc6f246d09 100644 --- a/packages/modules/link-modules/package.json +++ b/packages/modules/link-modules/package.json @@ -35,9 +35,9 @@ "devDependencies": { "@medusajs/framework": "^2.1.3", "@medusajs/test-utils": "^2.1.3", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "cross-env": "^5.2.1", diff --git a/packages/modules/locking/package.json b/packages/modules/locking/package.json index 26e9d048d4623..45a0001b4a277 100644 --- a/packages/modules/locking/package.json +++ b/packages/modules/locking/package.json @@ -34,10 +34,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.3", "@medusajs/test-utils": "^2.1.3", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", diff --git a/packages/modules/notification/package.json b/packages/modules/notification/package.json index 816511f638c60..a7636c12a0519 100644 --- a/packages/modules/notification/package.json +++ b/packages/modules/notification/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.3", "@medusajs/test-utils": "^2.1.3", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", diff --git a/packages/modules/order/package.json b/packages/modules/order/package.json index f2a40361bcba4..40558a0b9337d 100644 --- a/packages/modules/order/package.json +++ b/packages/modules/order/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.3", "@medusajs/test-utils": "^2.1.3", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", diff --git a/packages/modules/payment/package.json b/packages/modules/payment/package.json index 8b560474fb559..bd39719465320 100644 --- a/packages/modules/payment/package.json +++ b/packages/modules/payment/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.3", "@medusajs/test-utils": "^2.1.3", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", diff --git a/packages/modules/pricing/package.json b/packages/modules/pricing/package.json index 89581ea47b07e..38d0a558c4e3a 100644 --- a/packages/modules/pricing/package.json +++ b/packages/modules/pricing/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.3", "@medusajs/test-utils": "^2.1.3", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", diff --git a/packages/modules/product/package.json b/packages/modules/product/package.json index b16f775540249..41912db464756 100644 --- a/packages/modules/product/package.json +++ b/packages/modules/product/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.3", "@medusajs/test-utils": "^2.1.3", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "faker": "^5.5.3", diff --git a/packages/modules/promotion/package.json b/packages/modules/promotion/package.json index 814e41d51c73f..bb4207e44207b 100644 --- a/packages/modules/promotion/package.json +++ b/packages/modules/promotion/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.3", "@medusajs/test-utils": "^2.1.3", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", diff --git a/packages/modules/providers/locking-postgres/package.json b/packages/modules/providers/locking-postgres/package.json index b3085e3158491..37f6245aecb47 100644 --- a/packages/modules/providers/locking-postgres/package.json +++ b/packages/modules/providers/locking-postgres/package.json @@ -21,10 +21,10 @@ "license": "MIT", "devDependencies": { "@medusajs/framework": "^2.1.3", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", diff --git a/packages/modules/region/package.json b/packages/modules/region/package.json index 97d974519eb64..00e0e6830f46d 100644 --- a/packages/modules/region/package.json +++ b/packages/modules/region/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.3", "@medusajs/test-utils": "^2.1.3", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", diff --git a/packages/modules/sales-channel/package.json b/packages/modules/sales-channel/package.json index 8fb82317968ba..c151d4482128a 100644 --- a/packages/modules/sales-channel/package.json +++ b/packages/modules/sales-channel/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.3", "@medusajs/test-utils": "^2.1.3", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", diff --git a/packages/modules/stock-location/package.json b/packages/modules/stock-location/package.json index e8e574741355e..b886088cf163e 100644 --- a/packages/modules/stock-location/package.json +++ b/packages/modules/stock-location/package.json @@ -25,10 +25,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.3", "@medusajs/test-utils": "^2.1.3", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", diff --git a/packages/modules/store/package.json b/packages/modules/store/package.json index d763e946633fc..fdd4816f495e9 100644 --- a/packages/modules/store/package.json +++ b/packages/modules/store/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.3", "@medusajs/test-utils": "^2.1.3", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", diff --git a/packages/modules/tax/package.json b/packages/modules/tax/package.json index 0f1f85028f0ed..b27a09ff4ce51 100644 --- a/packages/modules/tax/package.json +++ b/packages/modules/tax/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.3", "@medusajs/test-utils": "^2.1.3", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", diff --git a/packages/modules/user/package.json b/packages/modules/user/package.json index 38b7ae6c69f1b..4d988c6b51ee5 100644 --- a/packages/modules/user/package.json +++ b/packages/modules/user/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.3", "@medusajs/test-utils": "^2.1.3", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", diff --git a/packages/modules/workflow-engine-inmemory/package.json b/packages/modules/workflow-engine-inmemory/package.json index 037d1d7577c4c..fa4554cff963c 100644 --- a/packages/modules/workflow-engine-inmemory/package.json +++ b/packages/modules/workflow-engine-inmemory/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.3", "@medusajs/test-utils": "^2.1.3", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", diff --git a/packages/modules/workflow-engine-redis/package.json b/packages/modules/workflow-engine-redis/package.json index dcd92183be7f9..261bcf5c1d93c 100644 --- a/packages/modules/workflow-engine-redis/package.json +++ b/packages/modules/workflow-engine-redis/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.3", "@medusajs/test-utils": "^2.1.3", - "@mikro-orm/cli": "5.9.7", - "@mikro-orm/core": "5.9.7", - "@mikro-orm/migrations": "5.9.7", - "@mikro-orm/postgresql": "5.9.7", + "@mikro-orm/cli": "6.4.1", + "@mikro-orm/core": "6.4.1", + "@mikro-orm/migrations": "6.4.1", + "@mikro-orm/postgresql": "6.4.1", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", diff --git a/yarn.lock b/yarn.lock index a08c0ffbef1cd..6caf76be7b288 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5316,7 +5316,7 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.3 "@medusajs/test-utils": ^2.1.3 - "@mikro-orm/cli": 5.9.7 + "@mikro-orm/cli": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -5387,10 +5387,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.3 "@medusajs/test-utils": ^2.1.3 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -5444,10 +5444,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.3 "@medusajs/test-utils": ^2.1.3 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -5469,10 +5469,10 @@ __metadata: dependencies: "@medusajs/telemetry": ^2.1.3 "@medusajs/utils": 2.1.3 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/knex": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/knex": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 "@types/express": ^4.17.17 @@ -5519,10 +5519,10 @@ __metadata: resolution: "@medusajs/core-flows@workspace:packages/core/core-flows" dependencies: "@medusajs/framework": ^2.1.3 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/knex": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/knex": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 awilix: ^8.0.1 @@ -5544,10 +5544,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.3 "@medusajs/test-utils": ^2.1.3 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -5569,10 +5569,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.3 "@medusajs/test-utils": ^2.1.3 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -5719,10 +5719,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.3 "@medusajs/test-utils": ^2.1.3 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -5747,10 +5747,10 @@ __metadata: "@medusajs/types": ^2.1.3 "@medusajs/utils": ^2.1.3 "@medusajs/workflows-sdk": ^2.1.3 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/knex": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/knex": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@opentelemetry/api": ^1.9.0 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 @@ -5818,10 +5818,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.3 "@medusajs/test-utils": ^2.1.3 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -5877,11 +5877,11 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.3 "@medusajs/test-utils": ^2.1.3 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/knex": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/knex": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -5904,10 +5904,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.3 "@medusajs/test-utils": ^2.1.3 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -5943,9 +5943,9 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.3 "@medusajs/test-utils": ^2.1.3 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 cross-env: ^5.2.1 @@ -5967,10 +5967,10 @@ __metadata: resolution: "@medusajs/locking-postgres@workspace:packages/modules/providers/locking-postgres" dependencies: "@medusajs/framework": ^2.1.3 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -6003,10 +6003,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.3 "@medusajs/test-utils": ^2.1.3 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -6149,10 +6149,10 @@ __metadata: "@medusajs/orchestration": ^2.1.3 "@medusajs/types": ^2.1.3 "@medusajs/utils": ^2.1.3 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/knex": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/knex": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 awilix: ^8.0.1 @@ -6209,10 +6209,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.3 "@medusajs/test-utils": ^2.1.3 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -6243,10 +6243,10 @@ __metadata: dependencies: "@medusajs/types": ^2.1.3 "@medusajs/utils": ^2.1.3 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/knex": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/knex": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 awilix: ^8.0.1 @@ -6271,10 +6271,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.3 "@medusajs/test-utils": ^2.1.3 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -6313,10 +6313,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.3 "@medusajs/test-utils": ^2.1.3 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -6338,10 +6338,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.3 "@medusajs/test-utils": ^2.1.3 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -6363,10 +6363,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.3 "@medusajs/test-utils": ^2.1.3 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 faker: ^5.5.3 @@ -6389,10 +6389,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.3 "@medusajs/test-utils": ^2.1.3 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -6414,10 +6414,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.3 "@medusajs/test-utils": ^2.1.3 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -6439,10 +6439,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.3 "@medusajs/test-utils": ^2.1.3 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -6464,10 +6464,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.3 "@medusajs/test-utils": ^2.1.3 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -6489,10 +6489,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.3 "@medusajs/test-utils": ^2.1.3 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -6514,10 +6514,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.3 "@medusajs/test-utils": ^2.1.3 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -6560,10 +6560,10 @@ __metadata: resolution: "@medusajs/test-utils@workspace:packages/medusa-test-utils" dependencies: "@medusajs/framework": ^2.1.3 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/knex": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/knex": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@types/express": ^4.17.17 awilix: ^8.0.1 axios: ^0.21.4 @@ -6728,10 +6728,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.3 "@medusajs/test-utils": ^2.1.3 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -6757,10 +6757,10 @@ __metadata: "@graphql-tools/merge": ^9.0.7 "@graphql-tools/schema": ^10.0.6 "@medusajs/types": ^2.1.3 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/knex": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/knex": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 "@types/express": ^4.17.21 @@ -6798,10 +6798,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.3 "@medusajs/test-utils": ^2.1.3 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 cron-parser: ^4.9.0 @@ -6825,10 +6825,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.3 "@medusajs/test-utils": ^2.1.3 - "@mikro-orm/cli": 5.9.7 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/cli": 6.4.1 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 bullmq: 5.13.0 @@ -6855,10 +6855,10 @@ __metadata: "@medusajs/orchestration": ^2.1.3 "@medusajs/types": ^2.1.3 "@medusajs/utils": ^2.1.3 - "@mikro-orm/core": 5.9.7 - "@mikro-orm/knex": 5.9.7 - "@mikro-orm/migrations": 5.9.7 - "@mikro-orm/postgresql": 5.9.7 + "@mikro-orm/core": 6.4.1 + "@mikro-orm/knex": 6.4.1 + "@mikro-orm/migrations": 6.4.1 + "@mikro-orm/postgresql": 6.4.1 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 awilix: ^8.0.1 From a623e68dd6d6959735fbef0d9434f5f979c8eba7 Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Fri, 20 Dec 2024 10:23:30 -0300 Subject: [PATCH 141/175] shipping option rules --- integration-tests/http/__tests__/cart/store/cart.spec.ts | 6 +++--- .../__tests__/order/workflows/begin-order-claim.spec.ts | 4 ++-- .../order/workflows/begin-order-exchange.spec.ts | 4 ++-- .../__tests__/order/workflows/begin-order-return.spec.ts | 4 ++-- .../order/workflows/create-complete-return.spec.ts | 4 ++-- .../__tests__/order/workflows/create-shipment.spec.ts | 4 ++-- .../fulfillment-module-service/shipping-option.spec.ts | 8 ++++---- packages/modules/fulfillment/src/utils/utils.ts | 8 ++++---- .../oas-output/schemas/AdminShippingOptionRule.ts | 9 ++++----- 9 files changed, 25 insertions(+), 26 deletions(-) diff --git a/integration-tests/http/__tests__/cart/store/cart.spec.ts b/integration-tests/http/__tests__/cart/store/cart.spec.ts index 8cf153e2fcc6b..f2348a68bdd26 100644 --- a/integration-tests/http/__tests__/cart/store/cart.spec.ts +++ b/integration-tests/http/__tests__/cart/store/cart.spec.ts @@ -386,7 +386,7 @@ medusaIntegrationTestRunner({ rules: [ { attribute: "enabled_in_store", - value: '"true"', + value: "true", operator: "eq", }, { @@ -1708,7 +1708,7 @@ medusaIntegrationTestRunner({ rules: [ { attribute: "enabled_in_store", - value: '"true"', + value: "true", operator: "eq", }, { @@ -2079,7 +2079,7 @@ medusaIntegrationTestRunner({ rules: [ { attribute: "enabled_in_store", - value: '"true"', + value: "true", operator: "eq", }, { diff --git a/integration-tests/modules/__tests__/order/workflows/begin-order-claim.spec.ts b/integration-tests/modules/__tests__/order/workflows/begin-order-claim.spec.ts index c8334e3d90b2a..98e45ab9c561a 100644 --- a/integration-tests/modules/__tests__/order/workflows/begin-order-claim.spec.ts +++ b/integration-tests/modules/__tests__/order/workflows/begin-order-claim.spec.ts @@ -3,6 +3,7 @@ import { createShippingOptionsWorkflow, orderClaimRequestItemReturnWorkflow, } from "@medusajs/core-flows" +import { medusaIntegrationTestRunner } from "@medusajs/test-utils" import { FulfillmentWorkflow, IOrderModuleService, @@ -19,7 +20,6 @@ import { RuleOperator, remoteQueryObjectFromString, } from "@medusajs/utils" -import { medusaIntegrationTestRunner } from "@medusajs/test-utils" jest.setTimeout(500000) @@ -186,7 +186,7 @@ async function prepareDataFixtures({ container }) { { attribute: "is_return", operator: RuleOperator.EQ, - value: '"true"', + value: "true", }, ], } diff --git a/integration-tests/modules/__tests__/order/workflows/begin-order-exchange.spec.ts b/integration-tests/modules/__tests__/order/workflows/begin-order-exchange.spec.ts index aa0caf90b27d0..9ae2091252bfd 100644 --- a/integration-tests/modules/__tests__/order/workflows/begin-order-exchange.spec.ts +++ b/integration-tests/modules/__tests__/order/workflows/begin-order-exchange.spec.ts @@ -4,6 +4,7 @@ import { orderExchangeAddNewItemWorkflow, orderExchangeRequestItemReturnWorkflow, } from "@medusajs/core-flows" +import { medusaIntegrationTestRunner } from "@medusajs/test-utils" import { FulfillmentWorkflow, IRegionModuleService, @@ -21,7 +22,6 @@ import { RuleOperator, remoteQueryObjectFromString, } from "@medusajs/utils" -import { medusaIntegrationTestRunner } from "@medusajs/test-utils" jest.setTimeout(500000) @@ -234,7 +234,7 @@ async function prepareDataFixtures({ container }) { { attribute: "is_return", operator: RuleOperator.EQ, - value: '"true"', + value: "true", }, ], } diff --git a/integration-tests/modules/__tests__/order/workflows/begin-order-return.spec.ts b/integration-tests/modules/__tests__/order/workflows/begin-order-return.spec.ts index 43b5a4727b9a5..9e91d5b3df272 100644 --- a/integration-tests/modules/__tests__/order/workflows/begin-order-return.spec.ts +++ b/integration-tests/modules/__tests__/order/workflows/begin-order-return.spec.ts @@ -2,6 +2,7 @@ import { beginReturnOrderWorkflow, createShippingOptionsWorkflow, } from "@medusajs/core-flows" +import { medusaIntegrationTestRunner } from "@medusajs/test-utils" import { FulfillmentWorkflow, IOrderModuleService, @@ -17,7 +18,6 @@ import { RuleOperator, remoteQueryObjectFromString, } from "@medusajs/utils" -import { medusaIntegrationTestRunner } from "@medusajs/test-utils" jest.setTimeout(500000) @@ -187,7 +187,7 @@ async function prepareDataFixtures({ container }) { { attribute: "is_return", operator: RuleOperator.EQ, - value: '"true"', + value: "true", }, ], } diff --git a/integration-tests/modules/__tests__/order/workflows/create-complete-return.spec.ts b/integration-tests/modules/__tests__/order/workflows/create-complete-return.spec.ts index 6d9a4a9fd1b7d..95da82bff210c 100644 --- a/integration-tests/modules/__tests__/order/workflows/create-complete-return.spec.ts +++ b/integration-tests/modules/__tests__/order/workflows/create-complete-return.spec.ts @@ -3,6 +3,7 @@ import { createShippingOptionsWorkflow, } from "@medusajs/core-flows" import { RemoteLink } from "@medusajs/modules-sdk" +import { medusaIntegrationTestRunner } from "@medusajs/test-utils" import { FulfillmentSetDTO, FulfillmentWorkflow, @@ -21,7 +22,6 @@ import { RuleOperator, remoteQueryObjectFromString, } from "@medusajs/utils" -import { medusaIntegrationTestRunner } from "@medusajs/test-utils" jest.setTimeout(500000) @@ -190,7 +190,7 @@ async function prepareDataFixtures({ container }) { { attribute: "is_return", operator: RuleOperator.EQ, - value: '"true"', + value: "true", }, ], } diff --git a/integration-tests/modules/__tests__/order/workflows/create-shipment.spec.ts b/integration-tests/modules/__tests__/order/workflows/create-shipment.spec.ts index 7ae6fab32f472..7e31f754f1c34 100644 --- a/integration-tests/modules/__tests__/order/workflows/create-shipment.spec.ts +++ b/integration-tests/modules/__tests__/order/workflows/create-shipment.spec.ts @@ -3,6 +3,7 @@ import { createOrderShipmentWorkflow, createShippingOptionsWorkflow, } from "@medusajs/core-flows" +import { medusaIntegrationTestRunner } from "@medusajs/test-utils" import { FulfillmentWorkflow, IOrderModuleService, @@ -20,7 +21,6 @@ import { RuleOperator, remoteQueryObjectFromString, } from "@medusajs/utils" -import { medusaIntegrationTestRunner } from "@medusajs/test-utils" jest.setTimeout(500000) @@ -177,7 +177,7 @@ async function prepareDataFixtures({ container }) { { attribute: "is_return", operator: RuleOperator.EQ, - value: '"true"', + value: "true", }, ], } diff --git a/packages/modules/fulfillment/integration-tests/__tests__/fulfillment-module-service/shipping-option.spec.ts b/packages/modules/fulfillment/integration-tests/__tests__/fulfillment-module-service/shipping-option.spec.ts index c73595bbb9030..441c7e9e2b64a 100644 --- a/packages/modules/fulfillment/integration-tests/__tests__/fulfillment-module-service/shipping-option.spec.ts +++ b/packages/modules/fulfillment/integration-tests/__tests__/fulfillment-module-service/shipping-option.spec.ts @@ -137,7 +137,7 @@ moduleIntegrationTestRunner({ { attribute: "test-attribute", operator: "in", - value: ["test"], + value: ["true"], }, ], }), @@ -161,7 +161,7 @@ moduleIntegrationTestRunner({ { attribute: "test-attribute", operator: "eq", - value: "test", + value: "true", }, { attribute: "test-attribute2.options", @@ -174,7 +174,7 @@ moduleIntegrationTestRunner({ let listedOptions = await service.listShippingOptionsForContext({ context: { - "test-attribute": "test", + "test-attribute": "true", "test-attribute2": { options: "test2", }, @@ -774,7 +774,7 @@ moduleIntegrationTestRunner({ rules: expect.arrayContaining([ expect.objectContaining({ id: existingRule.id, - value: '"false"', + value: "false", }), expect.objectContaining({ id: expect.any(String), diff --git a/packages/modules/fulfillment/src/utils/utils.ts b/packages/modules/fulfillment/src/utils/utils.ts index 7e3fe27fb088c..5017e8359e8f8 100644 --- a/packages/modules/fulfillment/src/utils/utils.ts +++ b/packages/modules/fulfillment/src/utils/utils.ts @@ -146,12 +146,12 @@ export function validateRule(rule: Record): boolean { } export function normalizeRulesValue>(rules: T[]): void { - rules.forEach((rule) => { + rules.forEach((rule: any) => { /** - * If a string is provided, then we don't want jsonb to convert to the primitive value based on the RFC + * If a boolean is provided, then we convert to string */ - if (rule.value === "true" || rule.value === "false") { - rule.value = rule.value === "true" ? '"true"' : '"false"' + if (rule.value === true || rule.value === false) { + rule.value = rule.value === true ? "true" : "false" } return rule diff --git a/www/utils/generated/oas-output/schemas/AdminShippingOptionRule.ts b/www/utils/generated/oas-output/schemas/AdminShippingOptionRule.ts index 54d6836dfc880..6bb7e4982e542 100644 --- a/www/utils/generated/oas-output/schemas/AdminShippingOptionRule.ts +++ b/www/utils/generated/oas-output/schemas/AdminShippingOptionRule.ts @@ -32,14 +32,14 @@ * - type: string * title: value * description: The rule's value. - * example: '"true"' + * example: "true" * - type: array * description: The rule's values. * items: * type: string * title: value * description: A rule's value - * example: '"true"' + * example: "true" * shipping_option_id: * type: string * title: shipping_option_id @@ -59,6 +59,5 @@ * format: date-time * title: deleted_at * description: The date the shipping option rule was deleted. - * -*/ - + * + */ From ca2cacf48c1d7ea5c34e9eadcde3145eefd07c76 Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Fri, 20 Dec 2024 11:12:48 -0300 Subject: [PATCH 142/175] serializer --- .../utils/src/dml/helpers/entity-builder/define-property.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/core/utils/src/dml/helpers/entity-builder/define-property.ts b/packages/core/utils/src/dml/helpers/entity-builder/define-property.ts index 4504a3d0919bc..bcd22909bb1b9 100644 --- a/packages/core/utils/src/dml/helpers/entity-builder/define-property.ts +++ b/packages/core/utils/src/dml/helpers/entity-builder/define-property.ts @@ -278,7 +278,7 @@ export function defineProperty( type: mikroOrmType.integer, nullable: true, fieldName: field.fieldName, - serializer: Number, + serializer: (value) => (value == null ? value : Number(value)), })(MikroORMEntity.prototype, field.fieldName) return } @@ -290,13 +290,14 @@ export function defineProperty( Property({ columnType: "real", type: "number", + runtimeType: "number", nullable: field.nullable, fieldName: field.fieldName, /** * Applying number serializer to convert value back to a * JavaScript number */ - serializer: Number, + serializer: (value) => (value == null ? value : Number(value)), /** * MikroORM does not ignore undefined values for default when generating * the database schema SQL. Conditionally add it here to prevent undefined From 7a784e6b66d21e7e9a020503a9bc5d6a5bb34953 Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Fri, 20 Dec 2024 11:29:39 -0300 Subject: [PATCH 143/175] unit test --- packages/core/utils/src/dml/__tests__/entity-builder.spec.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts b/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts index 84faa161c3696..e58016c26f4f5 100644 --- a/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts +++ b/packages/core/utils/src/dml/__tests__/entity-builder.spec.ts @@ -1547,10 +1547,11 @@ describe("Entity builder", () => { rate: { kind: "scalar", type: "number", + runtimeType: "number", columnType: "real", name: "rate", fieldName: "rate", - serializer: Number, + serializer: expect.any(Function), nullable: false, getter: false, setter: false, From 2f43720e8506849fc814c1cd7ca867c8a95317d7 Mon Sep 17 00:00:00 2001 From: adrien2p Date: Fri, 20 Dec 2024 15:38:53 +0100 Subject: [PATCH 144/175] fix test mikro orm init --- .../core/utils/src/dal/mikro-orm/__tests__/base-entity.spec.ts | 2 ++ .../utils/src/dal/mikro-orm/__tests__/big-number-field.spec.ts | 2 ++ .../__tests__/mikro-orm-free-text-search-filter.spec.ts | 2 ++ .../src/dal/mikro-orm/__tests__/mikro-orm-serializer.spec.ts | 2 ++ .../integration-tests/__tests__/migrations-revert.spec.ts | 2 ++ 5 files changed, 10 insertions(+) diff --git a/packages/core/utils/src/dal/mikro-orm/__tests__/base-entity.spec.ts b/packages/core/utils/src/dal/mikro-orm/__tests__/base-entity.spec.ts index 05e1845be0876..8dbe6412b87fa 100644 --- a/packages/core/utils/src/dal/mikro-orm/__tests__/base-entity.spec.ts +++ b/packages/core/utils/src/dal/mikro-orm/__tests__/base-entity.spec.ts @@ -15,6 +15,8 @@ describe("BaseEntity", () => { defineConfig({ entities: [Entity1], dbName: "test", + user: "postgres", + password: "", }) ) diff --git a/packages/core/utils/src/dal/mikro-orm/__tests__/big-number-field.spec.ts b/packages/core/utils/src/dal/mikro-orm/__tests__/big-number-field.spec.ts index bb974588bb944..934ae1de5dbb5 100644 --- a/packages/core/utils/src/dal/mikro-orm/__tests__/big-number-field.spec.ts +++ b/packages/core/utils/src/dal/mikro-orm/__tests__/big-number-field.spec.ts @@ -28,6 +28,8 @@ describe("@MikroOrmBigNumberProperty", () => { defineConfig({ entities: [TestAmount], dbName: "test", + user: "postgres", + password: "", }) ) }) diff --git a/packages/core/utils/src/dal/mikro-orm/__tests__/mikro-orm-free-text-search-filter.spec.ts b/packages/core/utils/src/dal/mikro-orm/__tests__/mikro-orm-free-text-search-filter.spec.ts index abde4e9b0cf8e..d9e211766e713 100644 --- a/packages/core/utils/src/dal/mikro-orm/__tests__/mikro-orm-free-text-search-filter.spec.ts +++ b/packages/core/utils/src/dal/mikro-orm/__tests__/mikro-orm-free-text-search-filter.spec.ts @@ -10,6 +10,8 @@ describe("mikroOrmFreeTextSearchFilterOptionsFactory", () => { orm = await MikroORM.init( defineConfig({ entities: [SearchableEntity1, SearchableEntity2], + user: "postgres", + password: "", dbName: "test", }) ) diff --git a/packages/core/utils/src/dal/mikro-orm/__tests__/mikro-orm-serializer.spec.ts b/packages/core/utils/src/dal/mikro-orm/__tests__/mikro-orm-serializer.spec.ts index 26039d0c95988..777746b6414df 100644 --- a/packages/core/utils/src/dal/mikro-orm/__tests__/mikro-orm-serializer.spec.ts +++ b/packages/core/utils/src/dal/mikro-orm/__tests__/mikro-orm-serializer.spec.ts @@ -22,6 +22,8 @@ describe("mikroOrmSerializer", () => { ProductOptionValue, ProductVariant, ], + user: "postgres", + password: "", dbName: "test", }) ) diff --git a/packages/core/utils/src/migrations/integration-tests/__tests__/migrations-revert.spec.ts b/packages/core/utils/src/migrations/integration-tests/__tests__/migrations-revert.spec.ts index 1cd6dab42a62e..8d43fe6c02ac0 100644 --- a/packages/core/utils/src/migrations/integration-tests/__tests__/migrations-revert.spec.ts +++ b/packages/core/utils/src/migrations/integration-tests/__tests__/migrations-revert.spec.ts @@ -57,6 +57,8 @@ describe.skip("Revert migrations", () => { const config = defineMikroOrmCliConfig(moduleName, { entities: [User], dbName: dbName, + user: "postgres", + password: "", migrations: { path: fs.basePath, fileName: migrationFileNameGenerator, From eabe606a3da09129c06ca7abde7c48738a82766f Mon Sep 17 00:00:00 2001 From: adrien2p Date: Fri, 20 Dec 2024 15:50:28 +0100 Subject: [PATCH 145/175] fix test mikro orm init --- .../integration-tests/__tests__/migrations-revert.spec.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/core/utils/src/migrations/integration-tests/__tests__/migrations-revert.spec.ts b/packages/core/utils/src/migrations/integration-tests/__tests__/migrations-revert.spec.ts index 8d43fe6c02ac0..1cd6dab42a62e 100644 --- a/packages/core/utils/src/migrations/integration-tests/__tests__/migrations-revert.spec.ts +++ b/packages/core/utils/src/migrations/integration-tests/__tests__/migrations-revert.spec.ts @@ -57,8 +57,6 @@ describe.skip("Revert migrations", () => { const config = defineMikroOrmCliConfig(moduleName, { entities: [User], dbName: dbName, - user: "postgres", - password: "", migrations: { path: fs.basePath, fileName: migrationFileNameGenerator, From 6c6caacf8c3fd80737c267b93c0c340ac4d15f9b Mon Sep 17 00:00:00 2001 From: adrien2p Date: Fri, 20 Dec 2024 16:14:47 +0100 Subject: [PATCH 146/175] Maintain merge object properties --- packages/core/utils/src/dal/mikro-orm/mikro-orm-repository.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/core/utils/src/dal/mikro-orm/mikro-orm-repository.ts b/packages/core/utils/src/dal/mikro-orm/mikro-orm-repository.ts index b335c43f760cc..8506bb42176ba 100644 --- a/packages/core/utils/src/dal/mikro-orm/mikro-orm-repository.ts +++ b/packages/core/utils/src/dal/mikro-orm/mikro-orm-repository.ts @@ -416,7 +416,9 @@ export function mikroOrmBaseRepositoryFactory( await this.initManyToManyToDetachAllItemsIfNeeded(data, context) data.map((_, index) => { - manager.assign(data[index].entity, data[index].update) + manager.assign(data[index].entity, data[index].update, { + mergeObjectProperties: true, + }) manager.persist(data[index].entity) }) From 25681851ec68d6ff19753921fc2b86a9613d4b94 Mon Sep 17 00:00:00 2001 From: adrien2p Date: Fri, 20 Dec 2024 16:22:00 +0100 Subject: [PATCH 147/175] fix test mikro orm init --- .../utils/src/dal/mikro-orm/__tests__/base-entity.spec.ts | 6 ++++++ .../mikro-orm/integration-tests/__fixtures__/database.ts | 2 +- packages/core/utils/src/dml/integration-tests/utils.ts | 2 +- .../integration-tests/__tests__/migrations-revert.spec.ts | 4 ++-- .../integration-tests/__tests__/migrations-run.spec.ts | 4 ++-- packages/medusa-test-utils/src/database.ts | 4 ++-- 6 files changed, 14 insertions(+), 8 deletions(-) diff --git a/packages/core/utils/src/dal/mikro-orm/__tests__/base-entity.spec.ts b/packages/core/utils/src/dal/mikro-orm/__tests__/base-entity.spec.ts index 8dbe6412b87fa..feb803fc7c541 100644 --- a/packages/core/utils/src/dal/mikro-orm/__tests__/base-entity.spec.ts +++ b/packages/core/utils/src/dal/mikro-orm/__tests__/base-entity.spec.ts @@ -36,6 +36,8 @@ describe("BaseEntity", () => { defineConfig({ entities: [Entity1], dbName: "test", + user: "postgres", + password: "", }) ) @@ -61,6 +63,8 @@ describe("BaseEntity", () => { defineConfig({ entities: [ProductModel, ProductCategoryEntity, ProductOptionValue], dbName: "test", + user: "postgres", + password: "", }) ) @@ -115,6 +119,8 @@ describe("BaseEntity", () => { defineConfig({ entities: [ProductModel, ProductCategoryEntity, ProductOptionValue], dbName: "test", + user: "postgres", + password: "", }) ) diff --git a/packages/core/utils/src/dal/mikro-orm/integration-tests/__fixtures__/database.ts b/packages/core/utils/src/dal/mikro-orm/integration-tests/__fixtures__/database.ts index 34b07c08bc7d5..c7b4dace0269c 100644 --- a/packages/core/utils/src/dal/mikro-orm/integration-tests/__fixtures__/database.ts +++ b/packages/core/utils/src/dal/mikro-orm/integration-tests/__fixtures__/database.ts @@ -1,5 +1,5 @@ const DB_HOST = process.env.DB_HOST ?? "localhost" -const DB_USERNAME = process.env.DB_USERNAME ?? "" +const DB_USERNAME = process.env.DB_USERNAME ?? "postgres" const DB_PASSWORD = process.env.DB_PASSWORD export const pgGodCredentials = { diff --git a/packages/core/utils/src/dml/integration-tests/utils.ts b/packages/core/utils/src/dml/integration-tests/utils.ts index 687c8942fd600..865ee07aaf421 100644 --- a/packages/core/utils/src/dml/integration-tests/utils.ts +++ b/packages/core/utils/src/dml/integration-tests/utils.ts @@ -1,5 +1,5 @@ const DB_HOST = process.env.DB_HOST ?? "localhost" -const DB_USERNAME = process.env.DB_USERNAME ?? "" +const DB_USERNAME = process.env.DB_USERNAME ?? "postgres" const DB_PASSWORD = process.env.DB_PASSWORD ?? "" export const pgGodCredentials = { diff --git a/packages/core/utils/src/migrations/integration-tests/__tests__/migrations-revert.spec.ts b/packages/core/utils/src/migrations/integration-tests/__tests__/migrations-revert.spec.ts index 1cd6dab42a62e..9ac812f384977 100644 --- a/packages/core/utils/src/migrations/integration-tests/__tests__/migrations-revert.spec.ts +++ b/packages/core/utils/src/migrations/integration-tests/__tests__/migrations-revert.spec.ts @@ -22,8 +22,8 @@ const migrationFileNameGenerator = (_: string, name?: string) => { } const pgGodCredentials = { - user: DB_USERNAME, - password: DB_PASSWORD, + user: DB_USERNAME ?? "postgres", + password: DB_PASSWORD ?? "", host: DB_HOST, } diff --git a/packages/core/utils/src/migrations/integration-tests/__tests__/migrations-run.spec.ts b/packages/core/utils/src/migrations/integration-tests/__tests__/migrations-run.spec.ts index da1d8bc708fab..1ff76cf74d56c 100644 --- a/packages/core/utils/src/migrations/integration-tests/__tests__/migrations-run.spec.ts +++ b/packages/core/utils/src/migrations/integration-tests/__tests__/migrations-run.spec.ts @@ -23,8 +23,8 @@ const moduleName = "myTestServiceRun" const fs = new FileSystem(join(__dirname, "./migrations-run")) const pgGodCredentials = { - user: DB_USERNAME, - password: DB_PASSWORD, + user: DB_USERNAME ?? "postgres", + password: DB_PASSWORD ?? "", host: DB_HOST, } diff --git a/packages/medusa-test-utils/src/database.ts b/packages/medusa-test-utils/src/database.ts index 2ee7e655609a9..341af26a23a92 100644 --- a/packages/medusa-test-utils/src/database.ts +++ b/packages/medusa-test-utils/src/database.ts @@ -18,8 +18,8 @@ const pgGodCredentials = { export function getDatabaseURL(dbName?: string): string { const DB_HOST = process.env.DB_HOST ?? "localhost" - const DB_USERNAME = process.env.DB_USERNAME ?? "" - const DB_PASSWORD = process.env.DB_PASSWORD + const DB_USERNAME = process.env.DB_USERNAME ?? "postgres" + const DB_PASSWORD = process.env.DB_PASSWORD ?? "" const DB_NAME = dbName ?? process.env.DB_TEMP_NAME return `postgres://${DB_USERNAME}${ From e827a9f511241d2cffb8612a2c2c997092e9fe12 Mon Sep 17 00:00:00 2001 From: adrien2p Date: Fri, 20 Dec 2024 16:43:10 +0100 Subject: [PATCH 148/175] prevent unit test from connecting to db --- .../utils/src/dal/mikro-orm/__tests__/base-entity.spec.ts | 4 ++++ .../src/dal/mikro-orm/__tests__/big-number-field.spec.ts | 1 + .../__tests__/mikro-orm-free-text-search-filter.spec.ts | 1 + .../src/dal/mikro-orm/__tests__/mikro-orm-serializer.spec.ts | 1 + 4 files changed, 7 insertions(+) diff --git a/packages/core/utils/src/dal/mikro-orm/__tests__/base-entity.spec.ts b/packages/core/utils/src/dal/mikro-orm/__tests__/base-entity.spec.ts index feb803fc7c541..5a15dec87e8a2 100644 --- a/packages/core/utils/src/dal/mikro-orm/__tests__/base-entity.spec.ts +++ b/packages/core/utils/src/dal/mikro-orm/__tests__/base-entity.spec.ts @@ -17,6 +17,7 @@ describe("BaseEntity", () => { dbName: "test", user: "postgres", password: "", + connect: false, }) ) @@ -38,6 +39,7 @@ describe("BaseEntity", () => { dbName: "test", user: "postgres", password: "", + connect: false, }) ) @@ -65,6 +67,7 @@ describe("BaseEntity", () => { dbName: "test", user: "postgres", password: "", + connect: false, }) ) @@ -121,6 +124,7 @@ describe("BaseEntity", () => { dbName: "test", user: "postgres", password: "", + connect: false, }) ) diff --git a/packages/core/utils/src/dal/mikro-orm/__tests__/big-number-field.spec.ts b/packages/core/utils/src/dal/mikro-orm/__tests__/big-number-field.spec.ts index 934ae1de5dbb5..13420c3e14534 100644 --- a/packages/core/utils/src/dal/mikro-orm/__tests__/big-number-field.spec.ts +++ b/packages/core/utils/src/dal/mikro-orm/__tests__/big-number-field.spec.ts @@ -30,6 +30,7 @@ describe("@MikroOrmBigNumberProperty", () => { dbName: "test", user: "postgres", password: "", + connect: false, }) ) }) diff --git a/packages/core/utils/src/dal/mikro-orm/__tests__/mikro-orm-free-text-search-filter.spec.ts b/packages/core/utils/src/dal/mikro-orm/__tests__/mikro-orm-free-text-search-filter.spec.ts index d9e211766e713..eb4c4c92f8c0e 100644 --- a/packages/core/utils/src/dal/mikro-orm/__tests__/mikro-orm-free-text-search-filter.spec.ts +++ b/packages/core/utils/src/dal/mikro-orm/__tests__/mikro-orm-free-text-search-filter.spec.ts @@ -13,6 +13,7 @@ describe("mikroOrmFreeTextSearchFilterOptionsFactory", () => { user: "postgres", password: "", dbName: "test", + connect: false, }) ) }) diff --git a/packages/core/utils/src/dal/mikro-orm/__tests__/mikro-orm-serializer.spec.ts b/packages/core/utils/src/dal/mikro-orm/__tests__/mikro-orm-serializer.spec.ts index 777746b6414df..5acd333a04ce4 100644 --- a/packages/core/utils/src/dal/mikro-orm/__tests__/mikro-orm-serializer.spec.ts +++ b/packages/core/utils/src/dal/mikro-orm/__tests__/mikro-orm-serializer.spec.ts @@ -25,6 +25,7 @@ describe("mikroOrmSerializer", () => { user: "postgres", password: "", dbName: "test", + connect: false, }) ) }) From a98476ce969063c067c5952740f73060aa4b280d Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Fri, 20 Dec 2024 12:56:46 -0300 Subject: [PATCH 149/175] wip --- .../admin/customer-group.spec.ts | 1 - packages/core/utils/src/dml/entity.ts | 2 - .../dml/helpers/create-mikro-orm-entity.ts | 20 +-- .../__tests__/migrations-revert.spec.ts | 12 +- packages/modules/order/package.json | 2 +- .../modules/order/src/models/credit-line.ts | 136 ++++-------------- packages/modules/order/src/models/index.ts | 1 + .../order/src/models/order-change-action.ts | 22 +-- .../modules/order/src/models/order-change.ts | 17 ++- packages/modules/order/src/models/order.ts | 32 ++--- .../src/services/order-module-service.ts | 12 ++ 11 files changed, 83 insertions(+), 174 deletions(-) diff --git a/integration-tests/http/__tests__/customer-group/admin/customer-group.spec.ts b/integration-tests/http/__tests__/customer-group/admin/customer-group.spec.ts index 9764af10891b0..0616a9be1196c 100644 --- a/integration-tests/http/__tests__/customer-group/admin/customer-group.spec.ts +++ b/integration-tests/http/__tests__/customer-group/admin/customer-group.spec.ts @@ -69,7 +69,6 @@ medusaIntegrationTestRunner({ await api .post("/admin/customer-groups", payload, adminHeaders) .catch((err) => { - console.log(err) // BREAKING: Duplicate error is now 400 expect(err.response.status).toEqual(400) expect(err.response.data.type).toEqual("invalid_data") diff --git a/packages/core/utils/src/dml/entity.ts b/packages/core/utils/src/dml/entity.ts index 534baf3a6afcc..fe3b62c06695b 100644 --- a/packages/core/utils/src/dml/entity.ts +++ b/packages/core/utils/src/dml/entity.ts @@ -117,7 +117,6 @@ export class DmlEntity< cascades: EntityCascades indexes: EntityIndex[] params: Record - hooks: Hooks checks: CheckConstraint[] } { return { @@ -127,7 +126,6 @@ export class DmlEntity< cascades: this.#cascades, indexes: this.#indexes, params: this.#params, - hooks: this.#hooks, checks: this.#checks, } } diff --git a/packages/core/utils/src/dml/helpers/create-mikro-orm-entity.ts b/packages/core/utils/src/dml/helpers/create-mikro-orm-entity.ts index 068946c010818..d5ed8f85d9c35 100644 --- a/packages/core/utils/src/dml/helpers/create-mikro-orm-entity.ts +++ b/packages/core/utils/src/dml/helpers/create-mikro-orm-entity.ts @@ -55,8 +55,7 @@ function createMikrORMEntity() { schema, cascades, indexes: entityIndexes = [], - params, - hooks = {}, + //params, checks, } = entity.parse() @@ -111,23 +110,6 @@ function createMikrORMEntity() { applyEntityIndexes(MikroORMEntity, tableName, entityIndexes) applyChecks(MikroORMEntity, checks) - /** - * @experimental - * TODO: Write RFC about this, for now it is unstable and should be moved - * to `applyHooks` - */ - for (const [hookName, hook] of Object.entries(hooks)) { - if (hookName === "creating") { - const hookMethodName = "beforeCreate_" + camelToSnakeCase(modelName) - const hookWrapper = function (this: MikroORMEntity) { - return hook(this as any) - } - - MikroORMEntity.prototype[hookMethodName] = hookWrapper - BeforeCreate()(MikroORMEntity.prototype, hookMethodName) - } - } - /** * Converting class to a MikroORM entity */ diff --git a/packages/core/utils/src/migrations/integration-tests/__tests__/migrations-revert.spec.ts b/packages/core/utils/src/migrations/integration-tests/__tests__/migrations-revert.spec.ts index 8d43fe6c02ac0..ccca59e346b60 100644 --- a/packages/core/utils/src/migrations/integration-tests/__tests__/migrations-revert.spec.ts +++ b/packages/core/utils/src/migrations/integration-tests/__tests__/migrations-revert.spec.ts @@ -1,13 +1,13 @@ -import { join } from "path" -import { MikroORM } from "@mikro-orm/postgresql" import { MetadataStorage } from "@mikro-orm/core" -import { createDatabase, dropDatabase } from "pg-god" import { TSMigrationGenerator } from "@mikro-orm/migrations" +import { MikroORM } from "@mikro-orm/postgresql" +import { join } from "path" +import { createDatabase, dropDatabase } from "pg-god" -import { model } from "../../../dml" import { FileSystem } from "../../../common" -import { Migrations, MigrationsEvents } from "../../index" +import { model } from "../../../dml" import { defineMikroOrmCliConfig } from "../../../modules-sdk" +import { Migrations, MigrationsEvents } from "../../index" const DB_HOST = process.env.DB_HOST ?? "localhost" const DB_USERNAME = process.env.DB_USERNAME ?? "" @@ -57,8 +57,6 @@ describe.skip("Revert migrations", () => { const config = defineMikroOrmCliConfig(moduleName, { entities: [User], dbName: dbName, - user: "postgres", - password: "", migrations: { path: fs.basePath, fileName: migrationFileNameGenerator, diff --git a/packages/modules/order/package.json b/packages/modules/order/package.json index b5000c83e47f2..550e26187b643 100644 --- a/packages/modules/order/package.json +++ b/packages/modules/order/package.json @@ -29,7 +29,7 @@ "resolve:aliases": "tsc --showConfig -p tsconfig.json > tsconfig.resolved.json && tsc-alias -p tsconfig.resolved.json && rimraf tsconfig.resolved.json", "build": "rimraf dist && tsc --build && npm run resolve:aliases", "test": "jest --runInBand --bail --forceExit -- src/**/__tests__/**/*.ts", - "test:integration": "jest --forceExit -- integration-tests/__tests__/**/order-claim.ts", + "test:integration": "jest --forceExit", "migration:initial": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm migration:create --initial", "migration:create": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm migration:create", "migration:up": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm migration:up", diff --git a/packages/modules/order/src/models/credit-line.ts b/packages/modules/order/src/models/credit-line.ts index e4e8952d9f35e..0a0c8f02d2b81 100644 --- a/packages/modules/order/src/models/credit-line.ts +++ b/packages/modules/order/src/models/credit-line.ts @@ -1,107 +1,31 @@ -import { BigNumberRawValue, DAL } from "@medusajs/framework/types" -import { - BigNumber, - createPsqlIndexStatementHelper, - generateEntityId, - MikroOrmBigNumberProperty, -} from "@medusajs/framework/utils" -import { - BeforeCreate, - Entity, - ManyToOne, - OnInit, - OptionalProps, - PrimaryKey, - Property, - Rel, -} from "@mikro-orm/core" -import Order from "./order" - -type OptionalLineItemProps = DAL.ModelDateColumns - -const tableName = "order_credit_line" -const OrderIdIndex = createPsqlIndexStatementHelper({ - tableName, - columns: ["order_id"], - where: "deleted_at IS NOT NULL", -}) - -const DeletedAtIndex = createPsqlIndexStatementHelper({ - tableName, - columns: "deleted_at", - where: "deleted_at IS NOT NULL", -}) - -@Entity({ tableName }) -export default class OrderCreditLine { - [OptionalProps]?: OptionalLineItemProps - - @PrimaryKey({ columnType: "text" }) - id: string - - @ManyToOne({ - entity: () => Order, - mapToPk: true, - fieldName: "order_id", - columnType: "text", - }) - @OrderIdIndex.MikroORMIndex() - order_id: string - - @ManyToOne(() => Order, { - persist: false, - }) - order: Rel - - @Property({ - columnType: "text", - nullable: true, - }) - reference: string | null = null - - @Property({ - columnType: "text", - nullable: true, - }) - reference_id: string | null = null - - @MikroOrmBigNumberProperty() - amount: BigNumber | number - - @Property({ columnType: "jsonb" }) - raw_amount: BigNumberRawValue - - @Property({ columnType: "jsonb", nullable: true }) - metadata: Record | null = null - - @Property({ - onCreate: () => new Date(), - columnType: "timestamptz", - defaultRaw: "now()", +import { model } from "@medusajs/framework/utils" +import { Order } from "./order" + +const OrderCreditLine_ = model + .define("OrderCreditLine", { + id: model.id({ prefix: "ordcl" }).primaryKey(), + order: model.belongsTo(() => Order, { + mappedBy: "credit_lines", + }), + reference: model.text().nullable(), + reference_id: model.text().nullable(), + amount: model.bigNumber(), + raw_amount: model.json(), + metadata: model.json().nullable(), }) - 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, "ordcl") - this.order_id ??= this.order?.id - } - - @OnInit() - onInit() { - this.id = generateEntityId(this.id, "ordcl") - this.order_id ??= this.order?.id - } -} + .indexes([ + { + name: "IDX_order_credit_line_order_id", + on: ["order_id"], + unique: false, + where: "deleted_at IS NOT NULL", + }, + { + name: "IDX_order_credit_line_deleted_at", + on: ["deleted_at"], + unique: false, + where: "deleted_at IS NOT NULL", + }, + ]) + +export const OrderCreditLine = OrderCreditLine_ diff --git a/packages/modules/order/src/models/index.ts b/packages/modules/order/src/models/index.ts index d25b6963550e1..630f7afa3a5a1 100644 --- a/packages/modules/order/src/models/index.ts +++ b/packages/modules/order/src/models/index.ts @@ -2,6 +2,7 @@ export { OrderAddress } from "./address" export { OrderClaim } from "./claim" export { OrderClaimItem } from "./claim-item" export { OrderClaimItemImage } from "./claim-item-image" +export { OrderCreditLine } from "./credit-line" export { OrderExchange } from "./exchange" export { OrderExchangeItem } from "./exchange-item" export { OrderLineItem } from "./line-item" diff --git a/packages/modules/order/src/models/order-change-action.ts b/packages/modules/order/src/models/order-change-action.ts index 8215b9d23e452..c9c68a50cfc06 100644 --- a/packages/modules/order/src/models/order-change-action.ts +++ b/packages/modules/order/src/models/order-change-action.ts @@ -18,22 +18,26 @@ const _OrderChangeAction = model amount: model.bigNumber().nullable(), internal_note: model.text().nullable(), applied: model.boolean().default(false), - order: model.belongsTo<() => typeof OrderChange>(() => Order, { - mappedBy: "actions", + order: model.hasOne<() => typeof OrderChange>(() => Order, { + mappedBy: undefined, + foreignKey: true, }), return: model - .belongsTo<() => typeof Return>(() => Return, { - mappedBy: "actions", + .hasOne<() => typeof Return>(() => Return, { + mappedBy: undefined, + foreignKey: true, }) .nullable(), claim: model - .belongsTo<() => typeof OrderClaim>(() => OrderClaim, { - mappedBy: "actions", + .hasOne<() => typeof OrderClaim>(() => OrderClaim, { + mappedBy: undefined, + foreignKey: true, }) .nullable(), exchange: model - .belongsTo<() => typeof OrderExchange>(() => OrderExchange, { - mappedBy: "actions", + .hasOne<() => typeof OrderExchange>(() => OrderExchange, { + mappedBy: undefined, + foreignKey: true, }) .nullable(), order_change: model @@ -42,6 +46,7 @@ const _OrderChangeAction = model }) .nullable(), }) + /* .hooks({ creating: (entity: any) => { entity.order_id ??= entity.order_change?.order_id ?? null @@ -51,6 +56,7 @@ const _OrderChangeAction = model entity.version ??= entity.order_change?.version ?? null }, }) + */ .indexes([ { name: "IDX_order_change_action_order_change_id", diff --git a/packages/modules/order/src/models/order-change.ts b/packages/modules/order/src/models/order-change.ts index 6d88085b9de9e..bbf612a8f57d6 100644 --- a/packages/modules/order/src/models/order-change.ts +++ b/packages/modules/order/src/models/order-change.ts @@ -31,18 +31,21 @@ const _OrderChange = model mappedBy: "changes", }), return: model - .belongsTo<() => typeof Return>(() => Return, { - mappedBy: "changes", + .hasOne<() => typeof Return>(() => Return, { + mappedBy: undefined, + foreignKey: true, }) .nullable(), claim: model - .belongsTo<() => typeof OrderClaim>(() => OrderClaim, { - mappedBy: "changes", + .hasOne<() => typeof OrderClaim>(() => OrderClaim, { + mappedBy: undefined, + foreignKey: true, }) .nullable(), exchange: model - .belongsTo<() => typeof OrderExchange>(() => OrderExchange, { - mappedBy: "changes", + .hasOne<() => typeof OrderExchange>(() => OrderExchange, { + mappedBy: undefined, + foreignKey: true, }) .nullable(), actions: model.hasMany<() => typeof OrderChangeAction>( @@ -53,7 +56,7 @@ const _OrderChange = model ), }) .cascades({ - delete: ["actions"], + // delete: ["actions"], }) .indexes([ { diff --git a/packages/modules/order/src/models/order.ts b/packages/modules/order/src/models/order.ts index f379b0e07cf5a..516d2a4c0fc87 100644 --- a/packages/modules/order/src/models/order.ts +++ b/packages/modules/order/src/models/order.ts @@ -1,29 +1,13 @@ -import { - AutoIncrementProperty, - BelongsTo, - BooleanProperty, - DateTimeProperty, - DmlEntity, - DMLEntitySchemaBuilder, - EnumProperty, - HasMany, - IdProperty, - JSONProperty, - model, - NullableModifier, - NumberProperty, - OrderStatus, - PrimaryKeyModifier, - RelationNullableModifier, - TextProperty, -} from "@medusajs/framework/utils" +import { model, OrderStatus } from "@medusajs/framework/utils" import { OrderAddress } from "./address" +import { OrderCreditLine } from "./credit-line" import { OrderItem } from "./order-item" import { OrderShipping } from "./order-shipping-method" import { OrderSummary } from "./order-summary" import { Return } from "./return" import { OrderTransaction } from "./transaction" +/* type OrderSchema = { id: PrimaryKeyModifier display_id: AutoIncrementProperty @@ -48,11 +32,13 @@ type OrderSchema = { BelongsTo, boolean > + credit_lines: HasMany summary: HasMany items: HasMany shipping_methods: HasMany transactions: HasMany } +*/ const _Order = model .define( @@ -99,6 +85,9 @@ const _Order = model transactions: model.hasMany(() => OrderTransaction, { mappedBy: "order", }), + credit_lines: model.hasMany(() => OrderCreditLine, { + mappedBy: "order", + }), } ) .cascades({ @@ -161,7 +150,4 @@ const _Order = model }, ]) -export const Order = _Order as DmlEntity< - DMLEntitySchemaBuilder, - "Order" -> +export const Order = _Order diff --git a/packages/modules/order/src/services/order-module-service.ts b/packages/modules/order/src/services/order-module-service.ts index ed03df7161e06..f7863e08e6f84 100644 --- a/packages/modules/order/src/services/order-module-service.ts +++ b/packages/modules/order/src/services/order-module-service.ts @@ -38,8 +38,10 @@ import { OrderChangeStatus, OrderStatus, promiseAll, + toMikroORMEntity, transformPropertiesToBigNumber, } from "@medusajs/framework/utils" +import { OnInit } from "@mikro-orm/core" import { Order, OrderAddress, @@ -137,6 +139,16 @@ const generateMethodForModels = { OrderCreditLine, } +const MikroORMEntity = toMikroORMEntity(OrderChangeAction) +MikroORMEntity.prototype["onInit"] = function () { + this.order_id ??= this.order_change?.order_id ?? null + this.return_id ??= this.order_change?.return_id ?? null + this.claim_id ??= this.order_change?.claim_id ?? null + this.exchange_id ??= this.order_change?.exchange_id ?? null + this.version ??= this.order_change?.version ?? null +} +OnInit()(MikroORMEntity.prototype, "onInit") + // TODO: rm template args here, keep it for later to not collide with carlos work at least as little as possible export default class OrderModuleService extends ModulesSdkUtils.MedusaService<{ From a842d147d302634c36c65a7c2025bb61f32d2f21 Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Fri, 20 Dec 2024 13:03:07 -0300 Subject: [PATCH 150/175] fix test --- .../__tests__/services/promotion-module/promotion.spec.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/modules/promotion/integration-tests/__tests__/services/promotion-module/promotion.spec.ts b/packages/modules/promotion/integration-tests/__tests__/services/promotion-module/promotion.spec.ts index 8cc7b9b54da0b..243c68cba7d96 100644 --- a/packages/modules/promotion/integration-tests/__tests__/services/promotion-module/promotion.spec.ts +++ b/packages/modules/promotion/integration-tests/__tests__/services/promotion-module/promotion.spec.ts @@ -6,8 +6,8 @@ import { Modules, PromotionType, } from "@medusajs/framework/utils" -import { PromotionModuleService } from "@services" import { SuiteOptions, moduleIntegrationTestRunner } from "@medusajs/test-utils" +import { PromotionModuleService } from "@services" import { createCampaigns } from "../../../__fixtures__/campaigns" import { createDefaultPromotion, @@ -854,7 +854,6 @@ moduleIntegrationTestRunner({ code: "PROMOTION_1", application_method: { id: expect.any(String), - promotion_id: expect.any(String), type: "fixed", }, }, From 88dcd49afbb0791afb618e24d4db1ed33af844c9 Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Fri, 20 Dec 2024 13:06:05 -0300 Subject: [PATCH 151/175] fix test --- .../workflows/batch-shipping-options-rules.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/integration-tests/modules/__tests__/shipping-options/workflows/batch-shipping-options-rules.ts b/integration-tests/modules/__tests__/shipping-options/workflows/batch-shipping-options-rules.ts index 6ae4109bbfc19..46e3e5c8845d2 100644 --- a/integration-tests/modules/__tests__/shipping-options/workflows/batch-shipping-options-rules.ts +++ b/integration-tests/modules/__tests__/shipping-options/workflows/batch-shipping-options-rules.ts @@ -2,6 +2,7 @@ import { batchShippingOptionRulesWorkflow, createShippingOptionsWorkflow, } from "@medusajs/core-flows" +import { medusaIntegrationTestRunner } from "@medusajs/test-utils" import { BatchWorkflowInput, CreateShippingOptionRuleDTO, @@ -19,7 +20,6 @@ import { RuleOperator, remoteQueryObjectFromString, } from "@medusajs/utils" -import { medusaIntegrationTestRunner } from "@medusajs/test-utils" jest.setTimeout(100000) @@ -249,7 +249,7 @@ medusaIntegrationTestRunner({ expect.objectContaining({ attribute: "new_attribute", operator: "eq", - value: 100, + value: "100", }) ) expect(updatedRule).toEqual( @@ -345,7 +345,7 @@ medusaIntegrationTestRunner({ expect.objectContaining({ attribute: "total", operator: "eq", - value: 100, + value: "100", }), ]) ) From 0548870217041fcf6af94b52f6457da669174ed4 Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Fri, 20 Dec 2024 14:08:02 -0300 Subject: [PATCH 152/175] link test --- integration-tests/modules/__tests__/link-modules/index.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/integration-tests/modules/__tests__/link-modules/index.ts b/integration-tests/modules/__tests__/link-modules/index.ts index cf5e8183c0a3c..dac6f29312dec 100644 --- a/integration-tests/modules/__tests__/link-modules/index.ts +++ b/integration-tests/modules/__tests__/link-modules/index.ts @@ -1,7 +1,7 @@ import { getMigrationPlanner, initialize } from "@medusajs/link-modules" import { MedusaModule } from "@medusajs/modules-sdk" -import { ModuleJoinerConfig } from "@medusajs/types" import { medusaIntegrationTestRunner } from "@medusajs/test-utils" +import { ModuleJoinerConfig } from "@medusajs/types" jest.setTimeout(5000000) @@ -73,7 +73,11 @@ medusaIntegrationTestRunner({ }) as any) const planner = getMigrationPlanner(dbConfig, linkDefinition) - await planner.executePlan(await planner.createPlan()) + let plans = await planner.createPlan() + + // TODO: review update plan of Order module tables + plans = plans.filter((p) => p.action !== "update") + await planner.executePlan(plans) links = await initialize(dbConfig, linkDefinition) }) From a8b6c0766f806112aa4a6004510928d3766e8295 Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Fri, 20 Dec 2024 14:54:53 -0300 Subject: [PATCH 153/175] schema --- .../helpers/entity-builder/define-property.ts | 2 +- packages/modules/order/src/models/address.ts | 11 ----- packages/modules/order/src/models/claim.ts | 5 +- packages/modules/order/src/models/exchange.ts | 5 +- packages/modules/order/src/models/order.ts | 47 +++---------------- packages/modules/order/src/models/return.ts | 8 +--- 6 files changed, 15 insertions(+), 63 deletions(-) diff --git a/packages/core/utils/src/dml/helpers/entity-builder/define-property.ts b/packages/core/utils/src/dml/helpers/entity-builder/define-property.ts index c4461e01b732b..9b704afe61039 100644 --- a/packages/core/utils/src/dml/helpers/entity-builder/define-property.ts +++ b/packages/core/utils/src/dml/helpers/entity-builder/define-property.ts @@ -277,7 +277,7 @@ export function defineProperty( Prop({ columnType: "serial", type: mikroOrmType.integer, - nullable: true, + nullable: field.nullable, fieldName: field.fieldName, serializer: (value) => (value == null ? value : Number(value)), })(MikroORMEntity.prototype, field.fieldName) diff --git a/packages/modules/order/src/models/address.ts b/packages/modules/order/src/models/address.ts index 8116fb3105598..b186380e3e6b1 100644 --- a/packages/modules/order/src/models/address.ts +++ b/packages/modules/order/src/models/address.ts @@ -1,5 +1,4 @@ import { model } from "@medusajs/framework/utils" -import { Order } from "./order" const _OrderAddress = model .define( @@ -20,16 +19,6 @@ const _OrderAddress = model province: model.text().searchable().nullable(), postal_code: model.text().searchable().nullable(), phone: model.text().searchable().nullable(), - shipping_address_order: model - .hasOne(() => Order, { - mappedBy: "shipping_address", - }) - .nullable(), - billing_address_order: model - .hasOne(() => Order, { - mappedBy: "billing_address", - }) - .nullable(), metadata: model.json().nullable(), } ) diff --git a/packages/modules/order/src/models/claim.ts b/packages/modules/order/src/models/claim.ts index 6ec08536f9019..a521c84317ad1 100644 --- a/packages/modules/order/src/models/claim.ts +++ b/packages/modules/order/src/models/claim.ts @@ -20,8 +20,9 @@ const _OrderClaim = model mappedBy: "claims", }), return: model - .belongsTo<() => typeof Return>(() => Return, { - mappedBy: "claim", + .hasOne<() => typeof Return>(() => Return, { + mappedBy: undefined, + foreignKey: true, }) .nullable(), additional_items: model.hasMany<() => typeof OrderClaimItem>( diff --git a/packages/modules/order/src/models/exchange.ts b/packages/modules/order/src/models/exchange.ts index 66233ebc383ae..81548796c0db1 100644 --- a/packages/modules/order/src/models/exchange.ts +++ b/packages/modules/order/src/models/exchange.ts @@ -21,8 +21,9 @@ const _OrderExchange = model mappedBy: "exchanges", }), return: model - .belongsTo<() => typeof Return>(() => Return, { - mappedBy: "exchange", + .hasOne<() => typeof Return>(() => Return, { + mappedBy: undefined, + foreignKey: true, }) .nullable(), additional_items: model.hasMany<() => typeof OrderExchangeItem>( diff --git a/packages/modules/order/src/models/order.ts b/packages/modules/order/src/models/order.ts index 516d2a4c0fc87..98da7665a4e4d 100644 --- a/packages/modules/order/src/models/order.ts +++ b/packages/modules/order/src/models/order.ts @@ -4,42 +4,8 @@ import { OrderCreditLine } from "./credit-line" import { OrderItem } from "./order-item" import { OrderShipping } from "./order-shipping-method" import { OrderSummary } from "./order-summary" -import { Return } from "./return" import { OrderTransaction } from "./transaction" -/* -type OrderSchema = { - id: PrimaryKeyModifier - display_id: AutoIncrementProperty - region_id: NullableModifier - customer_id: NullableModifier - version: NumberProperty - sales_channel_id: NullableModifier - status: EnumProperty - is_draft_order: BooleanProperty - email: NullableModifier - currency_code: TextProperty - no_notification: NullableModifier - metadata: NullableModifier, JSONProperty> - canceled_at: NullableModifier - shipping_address: RelationNullableModifier< - typeof OrderAddress, - BelongsTo, - boolean - > - billing_address: RelationNullableModifier< - typeof OrderAddress, - BelongsTo, - boolean - > - credit_lines: HasMany - summary: HasMany - items: HasMany - shipping_methods: HasMany - transactions: HasMany -} -*/ - const _Order = model .define( { @@ -60,17 +26,16 @@ const _Order = model no_notification: model.boolean().nullable(), metadata: model.json().nullable(), canceled_at: model.dateTime().nullable(), - returns: model.hasMany(() => Return, { - mappedBy: "order", - }), shipping_address: model - .belongsTo(() => OrderAddress, { - mappedBy: "shipping_address_order", + .hasOne(() => OrderAddress, { + mappedBy: undefined, + foreignKey: true, }) .nullable(), billing_address: model - .belongsTo(() => OrderAddress, { - mappedBy: "billing_address_order", + .hasOne(() => OrderAddress, { + mappedBy: undefined, + foreignKey: true, }) .nullable(), summary: model.hasMany(() => OrderSummary, { diff --git a/packages/modules/order/src/models/return.ts b/packages/modules/order/src/models/return.ts index 02913c51093b4..c09acf01de5d3 100644 --- a/packages/modules/order/src/models/return.ts +++ b/packages/modules/order/src/models/return.ts @@ -9,8 +9,6 @@ import { OrderTransaction } from "./transaction" const _Return = model .define("Return", { id: model.id({ prefix: "return" }).primaryKey(), - //exchange_id: model.text().nullable(), - //claim_id: model.text().nullable(), order_version: model.number(), display_id: model.autoincrement(), status: model.enum(ReturnStatus).default(ReturnStatus.OPEN), @@ -27,13 +25,13 @@ const _Return = model }), exchange: model .hasOne<() => typeof OrderExchange>(() => OrderExchange, { - mappedBy: "return", + mappedBy: undefined, foreignKey: true, }) .nullable(), claim: model .hasOne<() => typeof OrderClaim>(() => OrderClaim, { - mappedBy: "return", + mappedBy: undefined, foreignKey: true, }) .nullable(), @@ -77,14 +75,12 @@ const _Return = model }, { name: "IDX_return_exchange_id", - // @ts-ignore on: ["exchange_id"], unique: false, where: "exchange_id IS NOT NULL AND deleted_at IS NOT NULL", }, { name: "IDX_return_claim_id", - // @ts-ignore on: ["claim_id"], unique: false, where: "claim_id IS NOT NULL AND deleted_at IS NOT NULL", From f25cf28b995551e588a99386f418ab29050d816d Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Fri, 20 Dec 2024 15:41:09 -0300 Subject: [PATCH 154/175] models --- .../utils/src/dml/helpers/entity-builder/define-property.ts | 6 +++--- packages/modules/order/src/models/claim.ts | 5 +++-- packages/modules/order/src/models/exchange.ts | 5 +++-- packages/modules/order/src/models/return.ts | 5 +++-- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/packages/core/utils/src/dml/helpers/entity-builder/define-property.ts b/packages/core/utils/src/dml/helpers/entity-builder/define-property.ts index 9b704afe61039..dcd68a656779b 100644 --- a/packages/core/utils/src/dml/helpers/entity-builder/define-property.ts +++ b/packages/core/utils/src/dml/helpers/entity-builder/define-property.ts @@ -12,7 +12,6 @@ import { PrimaryKey, Property, Utils, - t as mikroOrmType, } from "@mikro-orm/core" import { generateEntityId, isDefined } from "../../../common" import { MikroOrmBigNumberProperty } from "../../../dal" @@ -275,8 +274,9 @@ export function defineProperty( : Property Prop({ - columnType: "serial", - type: mikroOrmType.integer, + autoincrement: true, + type: "number", + runtimeType: "number", nullable: field.nullable, fieldName: field.fieldName, serializer: (value) => (value == null ? value : Number(value)), diff --git a/packages/modules/order/src/models/claim.ts b/packages/modules/order/src/models/claim.ts index a521c84317ad1..cfc93f8e09954 100644 --- a/packages/modules/order/src/models/claim.ts +++ b/packages/modules/order/src/models/claim.ts @@ -16,8 +16,9 @@ const _OrderClaim = model created_by: model.text().nullable(), canceled_at: model.dateTime().nullable(), metadata: model.json().nullable(), - order: model.belongsTo<() => typeof Order>(() => Order, { - mappedBy: "claims", + order: model.hasOne<() => typeof Order>(() => Order, { + mappedBy: undefined, + foreignKey: true, }), return: model .hasOne<() => typeof Return>(() => Return, { diff --git a/packages/modules/order/src/models/exchange.ts b/packages/modules/order/src/models/exchange.ts index 81548796c0db1..f8bafe653f7e7 100644 --- a/packages/modules/order/src/models/exchange.ts +++ b/packages/modules/order/src/models/exchange.ts @@ -17,8 +17,9 @@ const _OrderExchange = model created_by: model.text().nullable(), metadata: model.json().nullable(), canceled_at: model.dateTime().nullable(), - order: model.belongsTo<() => typeof Order>(() => Order, { - mappedBy: "exchanges", + order: model.hasOne<() => typeof Order>(() => Order, { + mappedBy: undefined, + foreignKey: true, }), return: model .hasOne<() => typeof Return>(() => Return, { diff --git a/packages/modules/order/src/models/return.ts b/packages/modules/order/src/models/return.ts index c09acf01de5d3..677d03dacd088 100644 --- a/packages/modules/order/src/models/return.ts +++ b/packages/modules/order/src/models/return.ts @@ -20,8 +20,9 @@ const _Return = model requested_at: model.dateTime().nullable(), received_at: model.dateTime().nullable(), canceled_at: model.dateTime().nullable(), - order: model.belongsTo<() => typeof Order>(() => Order, { - mappedBy: "returns", + order: model.hasOne<() => typeof Order>(() => Order, { + mappedBy: undefined, + foreignKey: true, }), exchange: model .hasOne<() => typeof OrderExchange>(() => OrderExchange, { From 261d72396ce2a76b9530adc3835a2bee75d94374 Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Fri, 20 Dec 2024 15:42:32 -0300 Subject: [PATCH 155/175] auto increment --- .../src/dml/helpers/entity-builder/define-property.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/core/utils/src/dml/helpers/entity-builder/define-property.ts b/packages/core/utils/src/dml/helpers/entity-builder/define-property.ts index bcd22909bb1b9..cbe1f83938819 100644 --- a/packages/core/utils/src/dml/helpers/entity-builder/define-property.ts +++ b/packages/core/utils/src/dml/helpers/entity-builder/define-property.ts @@ -12,7 +12,6 @@ import { PrimaryKey, Property, Utils, - t as mikroOrmType, } from "@mikro-orm/core" import { generateEntityId, isDefined } from "../../../common" import { MikroOrmBigNumberProperty } from "../../../dal" @@ -274,9 +273,10 @@ export function defineProperty( : Property Prop({ - columnType: "serial", - type: mikroOrmType.integer, - nullable: true, + autoincrement: true, + type: "number", + runtimeType: "number", + nullable: field.nullable, fieldName: field.fieldName, serializer: (value) => (value == null ? value : Number(value)), })(MikroORMEntity.prototype, field.fieldName) From 2a37ce3276ef75406d52daec8c0a27e469f13641 Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Fri, 20 Dec 2024 16:06:38 -0300 Subject: [PATCH 156/175] hook --- .../modules/order/src/models/order-change.ts | 2 +- .../src/services/order-module-service.ts | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/packages/modules/order/src/models/order-change.ts b/packages/modules/order/src/models/order-change.ts index bbf612a8f57d6..20260b8ec25ab 100644 --- a/packages/modules/order/src/models/order-change.ts +++ b/packages/modules/order/src/models/order-change.ts @@ -56,7 +56,7 @@ const _OrderChange = model ), }) .cascades({ - // delete: ["actions"], + delete: ["actions"], }) .indexes([ { diff --git a/packages/modules/order/src/services/order-module-service.ts b/packages/modules/order/src/services/order-module-service.ts index f7863e08e6f84..c54426d4e1bb9 100644 --- a/packages/modules/order/src/services/order-module-service.ts +++ b/packages/modules/order/src/services/order-module-service.ts @@ -41,7 +41,7 @@ import { toMikroORMEntity, transformPropertiesToBigNumber, } from "@medusajs/framework/utils" -import { OnInit } from "@mikro-orm/core" +import { BeforeCreate, OnInit, rel } from "@mikro-orm/core" import { Order, OrderAddress, @@ -140,14 +140,19 @@ const generateMethodForModels = { } const MikroORMEntity = toMikroORMEntity(OrderChangeAction) -MikroORMEntity.prototype["onInit"] = function () { - this.order_id ??= this.order_change?.order_id ?? null - this.return_id ??= this.order_change?.return_id ?? null - this.claim_id ??= this.order_change?.claim_id ?? null - this.exchange_id ??= this.order_change?.exchange_id ?? null +MikroORMEntity.prototype["onInit_OrderChangeAction"] = function () { + this.order ??= + rel(toMikroORMEntity(Order), this.order_change?.order_id) ?? null + this.return ??= + rel(toMikroORMEntity(Return), this.order_change?.return_id) ?? null + this.claim ??= + rel(toMikroORMEntity(OrderClaim), this.order_change?.claim_id) ?? null + this.exchange ??= + rel(toMikroORMEntity(OrderExchange), this.order_change?.exchange_id) ?? null this.version ??= this.order_change?.version ?? null } -OnInit()(MikroORMEntity.prototype, "onInit") +OnInit()(MikroORMEntity.prototype, "onInit_OrderChangeAction") +BeforeCreate()(MikroORMEntity.prototype, "onInit_OrderChangeAction") // TODO: rm template args here, keep it for later to not collide with carlos work at least as little as possible export default class OrderModuleService From 0ed533a995f3598c3ec8d5be973b9e8929dac994 Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Fri, 20 Dec 2024 20:18:19 -0300 Subject: [PATCH 157/175] model hooks --- .../order/src/models/order-shipping-method.ts | 13 ++-- .../src/services/order-module-service.ts | 66 +++++++++++++++---- 2 files changed, 58 insertions(+), 21 deletions(-) diff --git a/packages/modules/order/src/models/order-shipping-method.ts b/packages/modules/order/src/models/order-shipping-method.ts index 1ce408f7a9bd1..5345a152d4683 100644 --- a/packages/modules/order/src/models/order-shipping-method.ts +++ b/packages/modules/order/src/models/order-shipping-method.ts @@ -32,17 +32,15 @@ const _OrderShipping = model mappedBy: "shipping_methods", }) .nullable(), - shipping_method: model - .hasOne<() => typeof OrderShippingMethod>(() => OrderShippingMethod, { + shipping_method: model.hasOne<() => typeof OrderShippingMethod>( + () => OrderShippingMethod, + { mappedBy: undefined, foreignKey: true, - }) - .nullable(), + } + ), } ) - .cascades({ - delete: ["shipping_method"], - }) .indexes([ { name: "IDX_order_shipping_order_id", @@ -76,7 +74,6 @@ const _OrderShipping = model }, { name: "IDX_order_shipping_shipping_method_id", - // @ts-ignore on: ["shipping_method_id"], unique: false, where: "deleted_at IS NOT NULL", diff --git a/packages/modules/order/src/services/order-module-service.ts b/packages/modules/order/src/services/order-module-service.ts index c54426d4e1bb9..f22c6578286c0 100644 --- a/packages/modules/order/src/services/order-module-service.ts +++ b/packages/modules/order/src/services/order-module-service.ts @@ -139,20 +139,60 @@ const generateMethodForModels = { OrderCreditLine, } -const MikroORMEntity = toMikroORMEntity(OrderChangeAction) -MikroORMEntity.prototype["onInit_OrderChangeAction"] = function () { - this.order ??= - rel(toMikroORMEntity(Order), this.order_change?.order_id) ?? null - this.return ??= - rel(toMikroORMEntity(Return), this.order_change?.return_id) ?? null - this.claim ??= - rel(toMikroORMEntity(OrderClaim), this.order_change?.claim_id) ?? null - this.exchange ??= - rel(toMikroORMEntity(OrderExchange), this.order_change?.exchange_id) ?? null - this.version ??= this.order_change?.version ?? null +{ + const MikroORMEntity = toMikroORMEntity(OrderChangeAction) + MikroORMEntity.prototype["onInit_OrderChangeAction"] = function () { + this.version ??= this.order?.version ?? null + + this.order ??= rel( + toMikroORMEntity(Order), + this.order_change?.order_id ?? null + ) + this.claim ??= rel( + toMikroORMEntity(OrderClaim), + this.order_change?.claim_id ?? null + ) + this.exchange ??= rel( + toMikroORMEntity(OrderExchange), + this.order_change?.exchange_id ?? null + ) + + if (!this.claim_id && !this.exchange_id) { + const ret_id = this.return?.id ?? this.order_change?.return_id ?? null + + this.return = rel(toMikroORMEntity(Return), ret_id) + } + } + OnInit()(MikroORMEntity.prototype, "onInit_OrderChangeAction") + BeforeCreate()(MikroORMEntity.prototype, "onInit_OrderChangeAction") +} +{ + const MikroORMEntity = toMikroORMEntity(OrderShipping) + MikroORMEntity.prototype["onInit_OrderShipping"] = function () { + this.version ??= this.order?.version ?? null + + this.order ??= rel(toMikroORMEntity(Order), this.order?.id ?? null) + this.return ??= rel(toMikroORMEntity(Return), this.return?.id ?? null) + this.claim ??= rel(toMikroORMEntity(OrderClaim), this.claim?.id ?? null) + this.exchange ??= rel( + toMikroORMEntity(OrderExchange), + this.exchange?.id ?? null + ) + } + OnInit()(MikroORMEntity.prototype, "onInit_OrderShipping") + BeforeCreate()(MikroORMEntity.prototype, "onInit_OrderShipping") +} +{ + const MikroORMEntity = toMikroORMEntity(OrderItem) + MikroORMEntity.prototype["onInit_OrderItem"] = function () { + this.version ??= this.order?.version ?? null + + this.order ??= rel(toMikroORMEntity(Order), this.order?.id ?? null) + this.item ??= rel(toMikroORMEntity(OrderLineItem), this.item?.id ?? null) + } + OnInit()(MikroORMEntity.prototype, "onInit_OrderItem") + BeforeCreate()(MikroORMEntity.prototype, "onInit_OrderItem") } -OnInit()(MikroORMEntity.prototype, "onInit_OrderChangeAction") -BeforeCreate()(MikroORMEntity.prototype, "onInit_OrderChangeAction") // TODO: rm template args here, keep it for later to not collide with carlos work at least as little as possible export default class OrderModuleService From 5ae3a0c9523358499b0879a54371a2528683a6e2 Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Sat, 21 Dec 2024 10:02:11 -0300 Subject: [PATCH 158/175] order --- packages/core/types/src/dml/index.ts | 1 - packages/core/utils/src/dml/entity.ts | 14 ++------------ .../integration-tests/__tests__/order-claim.ts | 2 +- .../integration-tests/__tests__/order-return.ts | 2 +- packages/modules/order/src/models/address.ts | 1 - packages/modules/order/src/models/claim-item.ts | 1 - packages/modules/order/src/models/claim.ts | 7 +------ packages/modules/order/src/models/exchange-item.ts | 1 - .../order/src/models/line-item-adjustment.ts | 1 - .../modules/order/src/models/line-item-tax-line.ts | 1 - .../order/src/models/order-change-action.ts | 11 ----------- packages/modules/order/src/models/order-change.ts | 5 +---- packages/modules/order/src/models/order-item.ts | 14 ++++---------- .../order/src/models/order-shipping-method.ts | 1 - packages/modules/order/src/models/order-summary.ts | 1 - packages/modules/order/src/models/order.ts | 1 - packages/modules/order/src/models/return-item.ts | 1 - .../order/src/models/shipping-method-adjustment.ts | 1 - .../order/src/models/shipping-method-tax-line.ts | 1 - .../order/src/services/order-module-service.ts | 8 ++++++-- .../order/src/utils/base-repository-find.ts | 13 ++++++++----- 21 files changed, 24 insertions(+), 64 deletions(-) diff --git a/packages/core/types/src/dml/index.ts b/packages/core/types/src/dml/index.ts index 99d5344493174..3f25730a070ef 100644 --- a/packages/core/types/src/dml/index.ts +++ b/packages/core/types/src/dml/index.ts @@ -15,7 +15,6 @@ export type IDmlEntityConfig = | { name?: string tableName: string - disableSoftDeleteFilter?: boolean } export type InferDmlEntityNameFromConfig = diff --git a/packages/core/utils/src/dml/entity.ts b/packages/core/utils/src/dml/entity.ts index fe3b62c06695b..0db09781da485 100644 --- a/packages/core/utils/src/dml/entity.ts +++ b/packages/core/utils/src/dml/entity.ts @@ -26,11 +26,9 @@ function extractNameAndTableName( const result = { name: "", tableName: "", - disableSoftDeleteFilter: false, } as { name: InferDmlEntityNameFromConfig tableName: string - disableSoftDeleteFilter: boolean } if (isString(nameOrConfig)) { @@ -58,8 +56,6 @@ function extractNameAndTableName( toCamelCase(name) ) as InferDmlEntityNameFromConfig result.tableName = nameOrConfig.tableName - result.disableSoftDeleteFilter = - nameOrConfig.disableSoftDeleteFilter ?? false } return result @@ -81,19 +77,15 @@ export class DmlEntity< readonly #tableName: string #cascades: EntityCascades = {} - #params: Record + #indexes: EntityIndex[] = [] #checks: CheckConstraint[] = [] constructor(nameOrConfig: TConfig, schema: Schema) { - const { name, tableName, disableSoftDeleteFilter } = - extractNameAndTableName(nameOrConfig) + const { name, tableName } = extractNameAndTableName(nameOrConfig) this.schema = schema this.name = name this.#tableName = tableName - this.#params = { - disableSoftDeleteFilter, - } } /** @@ -116,7 +108,6 @@ export class DmlEntity< schema: DMLSchema cascades: EntityCascades indexes: EntityIndex[] - params: Record checks: CheckConstraint[] } { return { @@ -125,7 +116,6 @@ export class DmlEntity< schema: this.schema, cascades: this.#cascades, indexes: this.#indexes, - params: this.#params, checks: this.#checks, } } diff --git a/packages/modules/order/integration-tests/__tests__/order-claim.ts b/packages/modules/order/integration-tests/__tests__/order-claim.ts index 98be3664d4779..a7d1992d1b57a 100644 --- a/packages/modules/order/integration-tests/__tests__/order-claim.ts +++ b/packages/modules/order/integration-tests/__tests__/order-claim.ts @@ -103,7 +103,7 @@ moduleIntegrationTestRunner({ customer_id: "joe", } as CreateOrderDTO - it.only("should claim an item and add two new items to the order", async function () { + it("should claim an item and add two new items to the order", async function () { const createdOrder = await service.createOrders(input) createdOrder.items = createdOrder.items!.sort((a, b) => a.title.localeCompare(b.title) diff --git a/packages/modules/order/integration-tests/__tests__/order-return.ts b/packages/modules/order/integration-tests/__tests__/order-return.ts index 8d8ffbac083b2..d1e7961dae7d9 100644 --- a/packages/modules/order/integration-tests/__tests__/order-return.ts +++ b/packages/modules/order/integration-tests/__tests__/order-return.ts @@ -627,7 +627,7 @@ moduleIntegrationTestRunner({ "items.detail.return_received_quantity", "shipping_methods.id", ], - relations: ["items", "items.detail"], + relations: ["items", "items.detail", "shipping_methods"], }) serializedOrder = JSON.parse(JSON.stringify(getOrder)) diff --git a/packages/modules/order/src/models/address.ts b/packages/modules/order/src/models/address.ts index b186380e3e6b1..69a9571b4090a 100644 --- a/packages/modules/order/src/models/address.ts +++ b/packages/modules/order/src/models/address.ts @@ -4,7 +4,6 @@ const _OrderAddress = model .define( { tableName: "order_address", - disableSoftDeleteFilter: true, }, { id: model.id({ prefix: "ordaddr" }).primaryKey(), diff --git a/packages/modules/order/src/models/claim-item.ts b/packages/modules/order/src/models/claim-item.ts index a636b2cd0dc93..b2ce81348fdbb 100644 --- a/packages/modules/order/src/models/claim-item.ts +++ b/packages/modules/order/src/models/claim-item.ts @@ -7,7 +7,6 @@ const _OrderClaimItem = model .define( { tableName: "order_claim_item", - disableSoftDeleteFilter: true, }, { id: model.id({ prefix: "claitem" }).primaryKey(), diff --git a/packages/modules/order/src/models/claim.ts b/packages/modules/order/src/models/claim.ts index cfc93f8e09954..8d0552ca0806f 100644 --- a/packages/modules/order/src/models/claim.ts +++ b/packages/modules/order/src/models/claim.ts @@ -52,12 +52,7 @@ const _OrderClaim = model ), }) .cascades({ - delete: [ - "additional_items", - "claim_items", - "shipping_methods", - "transactions", - ], + delete: ["additional_items", "claim_items", "transactions"], }) .indexes([ { diff --git a/packages/modules/order/src/models/exchange-item.ts b/packages/modules/order/src/models/exchange-item.ts index b286a4fca26c5..adbc18dd506e9 100644 --- a/packages/modules/order/src/models/exchange-item.ts +++ b/packages/modules/order/src/models/exchange-item.ts @@ -6,7 +6,6 @@ const _OrderExchangeItem = model .define( { tableName: "order_exchange_item", - disableSoftDeleteFilter: true, }, { id: model.id({ prefix: "oexcitem" }).primaryKey(), diff --git a/packages/modules/order/src/models/line-item-adjustment.ts b/packages/modules/order/src/models/line-item-adjustment.ts index 3e25c07a010e2..6b1ecc0cb6171 100644 --- a/packages/modules/order/src/models/line-item-adjustment.ts +++ b/packages/modules/order/src/models/line-item-adjustment.ts @@ -5,7 +5,6 @@ const _OrderLineItemAdjustment = model .define( { tableName: "order_line_item_adjustment", - disableSoftDeleteFilter: true, }, { id: model.id({ prefix: "ordliadj" }).primaryKey(), diff --git a/packages/modules/order/src/models/line-item-tax-line.ts b/packages/modules/order/src/models/line-item-tax-line.ts index 9c6cba59dd437..b8f43729796c8 100644 --- a/packages/modules/order/src/models/line-item-tax-line.ts +++ b/packages/modules/order/src/models/line-item-tax-line.ts @@ -5,7 +5,6 @@ const _OrderLineItemTaxLine = model .define( { tableName: "order_line_item_tax_line", - disableSoftDeleteFilter: true, }, { id: model.id({ prefix: "ordlitxl" }).primaryKey(), diff --git a/packages/modules/order/src/models/order-change-action.ts b/packages/modules/order/src/models/order-change-action.ts index c9c68a50cfc06..34cb83b73a699 100644 --- a/packages/modules/order/src/models/order-change-action.ts +++ b/packages/modules/order/src/models/order-change-action.ts @@ -46,17 +46,6 @@ const _OrderChangeAction = model }) .nullable(), }) - /* - .hooks({ - creating: (entity: any) => { - entity.order_id ??= entity.order_change?.order_id ?? null - entity.return_id ??= entity.order_change?.return_id ?? null - entity.claim_id ??= entity.order_change?.claim_id ?? null - entity.exchange_id ??= entity.order_change?.exchange_id ?? null - entity.version ??= entity.order_change?.version ?? null - }, - }) - */ .indexes([ { name: "IDX_order_change_action_order_change_id", diff --git a/packages/modules/order/src/models/order-change.ts b/packages/modules/order/src/models/order-change.ts index 20260b8ec25ab..910b747714161 100644 --- a/packages/modules/order/src/models/order-change.ts +++ b/packages/modules/order/src/models/order-change.ts @@ -49,10 +49,7 @@ const _OrderChange = model }) .nullable(), actions: model.hasMany<() => typeof OrderChangeAction>( - () => OrderChangeAction, - { - mappedBy: "order_change", - } + () => OrderChangeAction ), }) .cascades({ diff --git a/packages/modules/order/src/models/order-item.ts b/packages/modules/order/src/models/order-item.ts index 0a29a6f292c5a..0e9c604150300 100644 --- a/packages/modules/order/src/models/order-item.ts +++ b/packages/modules/order/src/models/order-item.ts @@ -7,7 +7,6 @@ const _OrderItem = model .define( { tableName: "order_item", - disableSoftDeleteFilter: true, }, { id: model.id({ prefix: "orditem" }).primaryKey(), @@ -26,17 +25,12 @@ const _OrderItem = model order: model.belongsTo<() => typeof Order>(() => Order, { mappedBy: "items", }), - item: model - .hasOne<() => typeof OrderLineItem>(() => OrderLineItem, { - mappedBy: undefined, - foreignKey: true, - }) - .nullable(), + item: model.hasOne<() => typeof OrderLineItem>(() => OrderLineItem, { + mappedBy: undefined, + foreignKey: true, + }), } ) - .cascades({ - delete: ["item"], - }) .indexes([ { name: "IDX_order_item_order_id", diff --git a/packages/modules/order/src/models/order-shipping-method.ts b/packages/modules/order/src/models/order-shipping-method.ts index 5345a152d4683..855001af10a69 100644 --- a/packages/modules/order/src/models/order-shipping-method.ts +++ b/packages/modules/order/src/models/order-shipping-method.ts @@ -9,7 +9,6 @@ const _OrderShipping = model .define( { tableName: "order_shipping", - disableSoftDeleteFilter: true, }, { id: model.id({ prefix: "ordspmv" }).primaryKey(), diff --git a/packages/modules/order/src/models/order-summary.ts b/packages/modules/order/src/models/order-summary.ts index 92394920ed466..d1da43a456db3 100644 --- a/packages/modules/order/src/models/order-summary.ts +++ b/packages/modules/order/src/models/order-summary.ts @@ -5,7 +5,6 @@ const _OrderSummary = model .define( { tableName: "order_summary", - disableSoftDeleteFilter: true, }, { id: model.id({ prefix: "ordsum" }).primaryKey(), diff --git a/packages/modules/order/src/models/order.ts b/packages/modules/order/src/models/order.ts index 98da7665a4e4d..daa0ac84856aa 100644 --- a/packages/modules/order/src/models/order.ts +++ b/packages/modules/order/src/models/order.ts @@ -10,7 +10,6 @@ const _Order = model .define( { tableName: "order", - disableSoftDeleteFilter: true, }, { id: model.id({ prefix: "order" }).primaryKey(), diff --git a/packages/modules/order/src/models/return-item.ts b/packages/modules/order/src/models/return-item.ts index edf5be8bdeef0..ca597903c7a8a 100644 --- a/packages/modules/order/src/models/return-item.ts +++ b/packages/modules/order/src/models/return-item.ts @@ -7,7 +7,6 @@ const _ReturnItem = model .define( { tableName: "return_item", - disableSoftDeleteFilter: true, }, { id: model.id({ prefix: "retitem" }).primaryKey(), diff --git a/packages/modules/order/src/models/shipping-method-adjustment.ts b/packages/modules/order/src/models/shipping-method-adjustment.ts index c6a2dd3e4f0a6..e9d923b1dd923 100644 --- a/packages/modules/order/src/models/shipping-method-adjustment.ts +++ b/packages/modules/order/src/models/shipping-method-adjustment.ts @@ -5,7 +5,6 @@ const _OrderShippingMethodAdjustment = model .define( { tableName: "order_shipping_method_adjustment", - disableSoftDeleteFilter: true, }, { id: model.id({ prefix: "ordsmadj" }).primaryKey(), diff --git a/packages/modules/order/src/models/shipping-method-tax-line.ts b/packages/modules/order/src/models/shipping-method-tax-line.ts index b5e1664f6050a..362300f5114a9 100644 --- a/packages/modules/order/src/models/shipping-method-tax-line.ts +++ b/packages/modules/order/src/models/shipping-method-tax-line.ts @@ -5,7 +5,6 @@ const _OrderShippingMethodTaxLine = model .define( { tableName: "order_shipping_method_tax_line", - disableSoftDeleteFilter: true, }, { id: model.id({ prefix: "ordsmtxl" }).primaryKey(), diff --git a/packages/modules/order/src/services/order-module-service.ts b/packages/modules/order/src/services/order-module-service.ts index f22c6578286c0..4771e1104e74c 100644 --- a/packages/modules/order/src/services/order-module-service.ts +++ b/packages/modules/order/src/services/order-module-service.ts @@ -142,7 +142,7 @@ const generateMethodForModels = { { const MikroORMEntity = toMikroORMEntity(OrderChangeAction) MikroORMEntity.prototype["onInit_OrderChangeAction"] = function () { - this.version ??= this.order?.version ?? null + this.version ??= this.order_change?.version ?? null this.order ??= rel( toMikroORMEntity(Order), @@ -178,6 +178,10 @@ const generateMethodForModels = { toMikroORMEntity(OrderExchange), this.exchange?.id ?? null ) + this.shipping_method ??= rel( + toMikroORMEntity(OrderShippingMethod), + this.shipping_method?.id ?? null + ) } OnInit()(MikroORMEntity.prototype, "onInit_OrderShipping") BeforeCreate()(MikroORMEntity.prototype, "onInit_OrderShipping") @@ -2966,8 +2970,8 @@ export default class OrderModuleService ], }, sharedContext - // TODO: investigate issue while using sharedContext in receive return action ) + orders = formatOrder(orders, { entity: Order, }) as OrderDTO[] diff --git a/packages/modules/order/src/utils/base-repository-find.ts b/packages/modules/order/src/utils/base-repository-find.ts index f3f72fca6ccf1..b9c3d85106478 100644 --- a/packages/modules/order/src/utils/base-repository-find.ts +++ b/packages/modules/order/src/utils/base-repository-find.ts @@ -84,7 +84,6 @@ export function setFindMethods(klass: Constructor, entity: any) { } config.where ??= {} - config.where.deleted_at ??= null return await manager.find(this.entity, config.where, config.options) } @@ -172,10 +171,16 @@ function configurePopulateWhere( if (isRelatedEntity) { popWhere.order ??= {} + popWhere.order.version = version if (hasRelation("shipping_methods")) { popWhere.shipping_methods ??= {} - popWhere.shipping_methods.deleted_at ??= null + popWhere.shipping_methods.version = version + } + + if (hasRelation("shipping_methods")) { + popWhere.shipping_methods ??= {} + popWhere.shipping_methods.version = version } } @@ -186,15 +191,13 @@ function configurePopulateWhere( orderWhere.summary.version = version } - if (hasRelation("items")) { + if (hasRelation("items") || hasRelation("order.items")) { orderWhere.items ??= {} orderWhere.items.version = version - orderWhere.items.deleted_at ??= null } if (hasRelation("shipping_methods")) { orderWhere.shipping_methods ??= {} orderWhere.shipping_methods.version = version - orderWhere.shipping_methods.deleted_at ??= null } } From dc83bdc84ecc74d320b8439faba7dfe019c2ae2c Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Mon, 6 Jan 2025 07:56:09 -0300 Subject: [PATCH 159/175] wip --- .../src/api/admin/claims/[id]/inbound/items/route.ts | 4 ++-- packages/modules/order/src/models/claim.ts | 2 +- packages/modules/order/src/models/exchange.ts | 2 +- packages/modules/order/src/models/return.ts | 10 ++++------ .../modules/order/src/services/actions/create-claim.ts | 2 +- .../order/src/services/actions/create-exchange.ts | 2 +- 6 files changed, 10 insertions(+), 12 deletions(-) diff --git a/packages/medusa/src/api/admin/claims/[id]/inbound/items/route.ts b/packages/medusa/src/api/admin/claims/[id]/inbound/items/route.ts index 6eb8899479c49..699ad421f907e 100644 --- a/packages/medusa/src/api/admin/claims/[id]/inbound/items/route.ts +++ b/packages/medusa/src/api/admin/claims/[id]/inbound/items/route.ts @@ -8,9 +8,9 @@ import { AuthenticatedMedusaRequest, MedusaResponse, } from "@medusajs/framework/http" +import { HttpTypes } from "@medusajs/framework/types" import { defaultAdminDetailsReturnFields } from "../../../../returns/query-config" import { AdminPostReturnsRequestItemsReqSchemaType } from "../../../../returns/validators" -import { HttpTypes } from "@medusajs/framework/types" export const POST = async ( req: AuthenticatedMedusaRequest, @@ -26,7 +26,7 @@ export const POST = async ( variables: { id, }, - fields: ["return_id"], + fields: ["return", "return_id"], }), { throwIfKeyNotFound: true, diff --git a/packages/modules/order/src/models/claim.ts b/packages/modules/order/src/models/claim.ts index 8d0552ca0806f..527314eeb26a4 100644 --- a/packages/modules/order/src/models/claim.ts +++ b/packages/modules/order/src/models/claim.ts @@ -22,7 +22,7 @@ const _OrderClaim = model }), return: model .hasOne<() => typeof Return>(() => Return, { - mappedBy: undefined, + mappedBy: "claim", foreignKey: true, }) .nullable(), diff --git a/packages/modules/order/src/models/exchange.ts b/packages/modules/order/src/models/exchange.ts index f8bafe653f7e7..75db671a0692e 100644 --- a/packages/modules/order/src/models/exchange.ts +++ b/packages/modules/order/src/models/exchange.ts @@ -23,7 +23,7 @@ const _OrderExchange = model }), return: model .hasOne<() => typeof Return>(() => Return, { - mappedBy: undefined, + mappedBy: "exchange", foreignKey: true, }) .nullable(), diff --git a/packages/modules/order/src/models/return.ts b/packages/modules/order/src/models/return.ts index 677d03dacd088..d0d071b8b3ff9 100644 --- a/packages/modules/order/src/models/return.ts +++ b/packages/modules/order/src/models/return.ts @@ -25,15 +25,13 @@ const _Return = model foreignKey: true, }), exchange: model - .hasOne<() => typeof OrderExchange>(() => OrderExchange, { - mappedBy: undefined, - foreignKey: true, + .belongsTo<() => typeof OrderExchange>(() => OrderExchange, { + mappedBy: "return", }) .nullable(), claim: model - .hasOne<() => typeof OrderClaim>(() => OrderClaim, { - mappedBy: undefined, - foreignKey: true, + .belongsTo<() => typeof OrderClaim>(() => OrderClaim, { + mappedBy: "return", }) .nullable(), items: model.hasMany<() => typeof ReturnItem>(() => ReturnItem, { diff --git a/packages/modules/order/src/services/actions/create-claim.ts b/packages/modules/order/src/services/actions/create-claim.ts index 2fb797103e887..ef5272cca36a3 100644 --- a/packages/modules/order/src/services/actions/create-claim.ts +++ b/packages/modules/order/src/services/actions/create-claim.ts @@ -35,7 +35,7 @@ function createClaimAndReturnEntities(em, data, order) { }) : undefined - claimReference.return_id = returnReference?.id + claimReference.return = returnReference return { claimReference, returnReference } } diff --git a/packages/modules/order/src/services/actions/create-exchange.ts b/packages/modules/order/src/services/actions/create-exchange.ts index 332e3f2ad6973..389a52e4a353c 100644 --- a/packages/modules/order/src/services/actions/create-exchange.ts +++ b/packages/modules/order/src/services/actions/create-exchange.ts @@ -31,7 +31,7 @@ function createExchangeAndReturnEntities(em, data, order) { refund_amount: (data.refund_amount as unknown) ?? null, }) - exchangeReference.return_id = returnReference.id + exchangeReference.return = returnReference return { exchangeReference, returnReference } } From 18549f990f192a9213bc6261bff892fb7b04f914 Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Mon, 6 Jan 2025 08:09:19 -0300 Subject: [PATCH 160/175] orm version --- integration-tests/package.json | 8 +- packages/cli/medusa-cli/package.json | 16 +- packages/core/core-flows/package.json | 8 +- packages/core/framework/package.json | 18 +- packages/core/modules-sdk/package.json | 16 +- packages/core/orchestration/package.json | 16 +- packages/core/utils/package.json | 16 +- packages/core/workflows-sdk/package.json | 16 +- packages/medusa-test-utils/package.json | 10 +- packages/medusa/package.json | 8 +- packages/modules/api-key/package.json | 8 +- packages/modules/auth/package.json | 14 +- packages/modules/cart/package.json | 14 +- packages/modules/currency/package.json | 14 +- packages/modules/customer/package.json | 14 +- packages/modules/file/package.json | 8 +- packages/modules/fulfillment/package.json | 14 +- packages/modules/index/package.json | 18 +- packages/modules/inventory/package.json | 14 +- packages/modules/link-modules/package.json | 12 +- packages/modules/locking/package.json | 14 +- packages/modules/notification/package.json | 14 +- packages/modules/order/package.json | 14 +- packages/modules/payment/package.json | 14 +- packages/modules/pricing/package.json | 14 +- packages/modules/product/package.json | 14 +- packages/modules/promotion/package.json | 14 +- .../providers/locking-postgres/package.json | 8 +- packages/modules/region/package.json | 14 +- packages/modules/sales-channel/package.json | 14 +- packages/modules/stock-location/package.json | 14 +- packages/modules/store/package.json | 14 +- packages/modules/tax/package.json | 14 +- packages/modules/user/package.json | 14 +- .../workflow-engine-inmemory/package.json | 14 +- .../workflow-engine-redis/package.json | 14 +- yarn.lock | 530 +++++++++--------- 37 files changed, 505 insertions(+), 505 deletions(-) diff --git a/integration-tests/package.json b/integration-tests/package.json index d991ffa6a2907..bef08aadd7d5d 100644 --- a/integration-tests/package.json +++ b/integration-tests/package.json @@ -21,10 +21,10 @@ "scrypt-kdf": "^2.0.1", "jsonwebtoken": "^9.0.2", "@medusajs/framework": "^1.0.1", - "@mikro-orm/core": "6.4.1", - "@mikro-orm/knex": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/knex": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "awilix": "^8.0.1", "ioredis": "^5.4.1", "pg": "^8.13.0", diff --git a/packages/cli/medusa-cli/package.json b/packages/cli/medusa-cli/package.json index 62626394d5b23..888e5c2701d7c 100644 --- a/packages/cli/medusa-cli/package.json +++ b/packages/cli/medusa-cli/package.json @@ -32,10 +32,10 @@ "author": "Sebastian Rindom", "license": "MIT", "devDependencies": { - "@mikro-orm/core": "6.4.1", - "@mikro-orm/knex": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/knex": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "@types/yargs": "^15.0.15", @@ -72,10 +72,10 @@ "yargs": "^15.3.1" }, "peerDependencies": { - "@mikro-orm/core": "6.4.1", - "@mikro-orm/knex": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/knex": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "awilix": "^8.0.1", "pg": "^8.13.0" }, diff --git a/packages/core/core-flows/package.json b/packages/core/core-flows/package.json index 98ea983f9c248..0f1cac94104fc 100644 --- a/packages/core/core-flows/package.json +++ b/packages/core/core-flows/package.json @@ -27,10 +27,10 @@ "license": "MIT", "devDependencies": { "@medusajs/framework": "^2.1.3", - "@mikro-orm/core": "6.4.1", - "@mikro-orm/knex": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/knex": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "awilix": "^8.0.1", diff --git a/packages/core/framework/package.json b/packages/core/framework/package.json index 7ac31241f70e4..b93d82ffb26e7 100644 --- a/packages/core/framework/package.json +++ b/packages/core/framework/package.json @@ -53,10 +53,10 @@ }, "devDependencies": { "@medusajs/cli": "^2.1.3", - "@mikro-orm/core": "6.4.1", - "@mikro-orm/knex": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/knex": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "@types/cors": "^2.8.17", @@ -92,11 +92,11 @@ }, "peerDependencies": { "@medusajs/cli": "^2.0.0", - "@mikro-orm/cli": "6.4.1", - "@mikro-orm/core": "6.4.1", - "@mikro-orm/knex": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/cli": "6.4.2", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/knex": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "awilix": "^8.0.1", "ioredis": "^5.4.1", "pg": "^8.13.0", diff --git a/packages/core/modules-sdk/package.json b/packages/core/modules-sdk/package.json index 0f2ae627bc35b..3ba6b0f3dbe9d 100644 --- a/packages/core/modules-sdk/package.json +++ b/packages/core/modules-sdk/package.json @@ -31,10 +31,10 @@ "watch": "tsc --build --watch" }, "devDependencies": { - "@mikro-orm/core": "6.4.1", - "@mikro-orm/knex": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/knex": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "awilix": "^8.0.1", @@ -50,10 +50,10 @@ "@medusajs/utils": "^2.1.3" }, "peerDependencies": { - "@mikro-orm/core": "6.4.1", - "@mikro-orm/knex": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/knex": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "awilix": "^8.0.1", "express": "^4.21.0", "pg": "^8.13.0" diff --git a/packages/core/orchestration/package.json b/packages/core/orchestration/package.json index 8a5339aed51a7..4bdad45783c4c 100644 --- a/packages/core/orchestration/package.json +++ b/packages/core/orchestration/package.json @@ -26,10 +26,10 @@ "author": "Medusa", "license": "MIT", "devDependencies": { - "@mikro-orm/core": "6.4.1", - "@mikro-orm/knex": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/knex": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "awilix": "^8.0.1", @@ -43,10 +43,10 @@ "@medusajs/utils": "^2.1.3" }, "peerDependencies": { - "@mikro-orm/core": "6.4.1", - "@mikro-orm/knex": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/knex": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "awilix": "^8.0.1", "express": "^4.21.0", "pg": "^8.13.0" diff --git a/packages/core/utils/package.json b/packages/core/utils/package.json index 9f82e6ba07fb6..de15c392e3c8d 100644 --- a/packages/core/utils/package.json +++ b/packages/core/utils/package.json @@ -26,10 +26,10 @@ "author": "Medusa", "license": "MIT", "devDependencies": { - "@mikro-orm/core": "6.4.1", - "@mikro-orm/knex": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/knex": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "@types/express": "^4.17.21", @@ -59,10 +59,10 @@ "ulid": "^2.3.0" }, "peerDependencies": { - "@mikro-orm/core": "6.4.1", - "@mikro-orm/knex": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/knex": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "awilix": "^8.0.1", "express": "^4.21.0", "pg": "^8.13.0" diff --git a/packages/core/workflows-sdk/package.json b/packages/core/workflows-sdk/package.json index e4e99372cf364..cf9160291cf7b 100644 --- a/packages/core/workflows-sdk/package.json +++ b/packages/core/workflows-sdk/package.json @@ -27,10 +27,10 @@ "author": "Medusa", "license": "MIT", "devDependencies": { - "@mikro-orm/core": "6.4.1", - "@mikro-orm/knex": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/knex": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "awilix": "^8.0.1", @@ -47,10 +47,10 @@ "ulid": "^2.3.0" }, "peerDependencies": { - "@mikro-orm/core": "6.4.1", - "@mikro-orm/knex": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/knex": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "awilix": "^8.0.1", "express": "^4.21.0", "pg": "^8.13.0" diff --git a/packages/medusa-test-utils/package.json b/packages/medusa-test-utils/package.json index e3a099dcbc5f0..41c1c08855e9b 100644 --- a/packages/medusa-test-utils/package.json +++ b/packages/medusa-test-utils/package.json @@ -26,10 +26,10 @@ "license": "MIT", "devDependencies": { "@medusajs/framework": "^2.1.3", - "@mikro-orm/core": "6.4.1", - "@mikro-orm/knex": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/knex": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "awilix": "^8.0.1", "jest": "^29.7.0", "pg": "^8.13.0", @@ -47,7 +47,7 @@ "peerDependencies": { "@medusajs/framework": "^2.0.0", "@medusajs/medusa": "^2.0.0", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/postgresql": "6.4.2", "awilix": "^8.0.1" }, "peerDependenciesMeta": { diff --git a/packages/medusa/package.json b/packages/medusa/package.json index f871c9fad7441..76c3e6b2045b7 100644 --- a/packages/medusa/package.json +++ b/packages/medusa/package.json @@ -126,10 +126,10 @@ }, "peerDependencies": { "@medusajs/framework": "^2.0.0", - "@mikro-orm/core": "6.4.1", - "@mikro-orm/knex": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/knex": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "awilix": "^8.0.1" }, "gitHead": "cd1f5afa5aa8c0b15ea957008ee19f1d695cbd2e" diff --git a/packages/modules/api-key/package.json b/packages/modules/api-key/package.json index 85807c59dd0b7..20af413a28b04 100644 --- a/packages/modules/api-key/package.json +++ b/packages/modules/api-key/package.json @@ -38,7 +38,7 @@ "devDependencies": { "@medusajs/framework": "^2.1.3", "@medusajs/test-utils": "^2.1.3", - "@mikro-orm/cli": "6.4.1", + "@mikro-orm/cli": "6.4.2", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", @@ -48,9 +48,9 @@ }, "peerDependencies": { "@medusajs/framework": "^2.0.0", - "@mikro-orm/core": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "awilix": "^8.0.1" } } diff --git a/packages/modules/auth/package.json b/packages/modules/auth/package.json index 1400e0f4e636a..f4b3dd52eaadd 100644 --- a/packages/modules/auth/package.json +++ b/packages/modules/auth/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.3", "@medusajs/test-utils": "^2.1.3", - "@mikro-orm/cli": "6.4.1", - "@mikro-orm/core": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/cli": "6.4.2", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", @@ -51,9 +51,9 @@ }, "peerDependencies": { "@medusajs/framework": "^2.0.0", - "@mikro-orm/core": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "awilix": "^8.0.1" } } diff --git a/packages/modules/cart/package.json b/packages/modules/cart/package.json index 913bdcf420da3..2945f5f22a579 100644 --- a/packages/modules/cart/package.json +++ b/packages/modules/cart/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.3", "@medusajs/test-utils": "^2.1.3", - "@mikro-orm/cli": "6.4.1", - "@mikro-orm/core": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/cli": "6.4.2", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", @@ -51,9 +51,9 @@ }, "peerDependencies": { "@medusajs/framework": "^2.0.0", - "@mikro-orm/core": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "awilix": "^8.0.1" } } diff --git a/packages/modules/currency/package.json b/packages/modules/currency/package.json index 0e21d927ac8a3..a6a6158c74521 100644 --- a/packages/modules/currency/package.json +++ b/packages/modules/currency/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.3", "@medusajs/test-utils": "^2.1.3", - "@mikro-orm/cli": "6.4.1", - "@mikro-orm/core": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/cli": "6.4.2", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", @@ -51,9 +51,9 @@ }, "peerDependencies": { "@medusajs/framework": "^2.0.0", - "@mikro-orm/core": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "awilix": "^8.0.1" } } diff --git a/packages/modules/customer/package.json b/packages/modules/customer/package.json index 1a7da16140402..e7b2bf340e084 100644 --- a/packages/modules/customer/package.json +++ b/packages/modules/customer/package.json @@ -39,10 +39,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.3", "@medusajs/test-utils": "^2.1.3", - "@mikro-orm/cli": "6.4.1", - "@mikro-orm/core": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/cli": "6.4.2", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", @@ -52,9 +52,9 @@ }, "peerDependencies": { "@medusajs/framework": "^2.0.0", - "@mikro-orm/core": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "awilix": "^8.0.1" } } diff --git a/packages/modules/file/package.json b/packages/modules/file/package.json index 92b99b7d8d8d4..0b70c175be258 100644 --- a/packages/modules/file/package.json +++ b/packages/modules/file/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.3", "@medusajs/test-utils": "^2.1.3", - "@mikro-orm/cli": "6.4.1", - "@mikro-orm/core": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/cli": "6.4.2", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", diff --git a/packages/modules/fulfillment/package.json b/packages/modules/fulfillment/package.json index 19bed46e6a4e5..8ee933bfe26f5 100644 --- a/packages/modules/fulfillment/package.json +++ b/packages/modules/fulfillment/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.3", "@medusajs/test-utils": "^2.1.3", - "@mikro-orm/cli": "6.4.1", - "@mikro-orm/core": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/cli": "6.4.2", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", @@ -51,9 +51,9 @@ }, "peerDependencies": { "@medusajs/framework": "^2.0.0", - "@mikro-orm/core": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "awilix": "^8.0.1" } } diff --git a/packages/modules/index/package.json b/packages/modules/index/package.json index e20c7b1436e83..2e343a709cf00 100644 --- a/packages/modules/index/package.json +++ b/packages/modules/index/package.json @@ -38,11 +38,11 @@ "devDependencies": { "@medusajs/framework": "^2.1.3", "@medusajs/test-utils": "^2.1.3", - "@mikro-orm/cli": "6.4.1", - "@mikro-orm/core": "6.4.1", - "@mikro-orm/knex": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/cli": "6.4.2", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/knex": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", @@ -52,10 +52,10 @@ }, "peerDependencies": { "@medusajs/framework": "^2.0.0", - "@mikro-orm/core": "6.4.1", - "@mikro-orm/knex": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/knex": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "awilix": "^8.0.1" } } diff --git a/packages/modules/inventory/package.json b/packages/modules/inventory/package.json index 1dd463b339b95..d88f9a104487b 100644 --- a/packages/modules/inventory/package.json +++ b/packages/modules/inventory/package.json @@ -25,10 +25,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.3", "@medusajs/test-utils": "^2.1.3", - "@mikro-orm/cli": "6.4.1", - "@mikro-orm/core": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/cli": "6.4.2", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", @@ -38,9 +38,9 @@ }, "peerDependencies": { "@medusajs/framework": "^2.0.0", - "@mikro-orm/core": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "awilix": "^8.0.1" }, "scripts": { diff --git a/packages/modules/link-modules/package.json b/packages/modules/link-modules/package.json index a1bcc6f246d09..f7c58f00c6dc1 100644 --- a/packages/modules/link-modules/package.json +++ b/packages/modules/link-modules/package.json @@ -35,9 +35,9 @@ "devDependencies": { "@medusajs/framework": "^2.1.3", "@medusajs/test-utils": "^2.1.3", - "@mikro-orm/core": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "cross-env": "^5.2.1", @@ -48,9 +48,9 @@ }, "peerDependencies": { "@medusajs/framework": "^2.0.0", - "@mikro-orm/core": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "awilix": "^8.0.1" } } diff --git a/packages/modules/locking/package.json b/packages/modules/locking/package.json index 45a0001b4a277..8effde6de758b 100644 --- a/packages/modules/locking/package.json +++ b/packages/modules/locking/package.json @@ -34,10 +34,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.3", "@medusajs/test-utils": "^2.1.3", - "@mikro-orm/cli": "6.4.1", - "@mikro-orm/core": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/cli": "6.4.2", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", @@ -47,9 +47,9 @@ }, "peerDependencies": { "@medusajs/framework": "^2.0.0", - "@mikro-orm/core": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "awilix": "^8.0.1" } } diff --git a/packages/modules/notification/package.json b/packages/modules/notification/package.json index a7636c12a0519..5f23b74502fa6 100644 --- a/packages/modules/notification/package.json +++ b/packages/modules/notification/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.3", "@medusajs/test-utils": "^2.1.3", - "@mikro-orm/cli": "6.4.1", - "@mikro-orm/core": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/cli": "6.4.2", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", @@ -51,9 +51,9 @@ }, "peerDependencies": { "@medusajs/framework": "^2.0.0", - "@mikro-orm/core": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "awilix": "^8.0.1" } } diff --git a/packages/modules/order/package.json b/packages/modules/order/package.json index 40558a0b9337d..9b26d3456d701 100644 --- a/packages/modules/order/package.json +++ b/packages/modules/order/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.3", "@medusajs/test-utils": "^2.1.3", - "@mikro-orm/cli": "6.4.1", - "@mikro-orm/core": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/cli": "6.4.2", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", @@ -51,9 +51,9 @@ }, "peerDependencies": { "@medusajs/framework": "^2.0.0", - "@mikro-orm/core": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "awilix": "^8.0.1" } } diff --git a/packages/modules/payment/package.json b/packages/modules/payment/package.json index bd39719465320..4da391b8a4ef0 100644 --- a/packages/modules/payment/package.json +++ b/packages/modules/payment/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.3", "@medusajs/test-utils": "^2.1.3", - "@mikro-orm/cli": "6.4.1", - "@mikro-orm/core": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/cli": "6.4.2", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", @@ -51,9 +51,9 @@ }, "peerDependencies": { "@medusajs/framework": "^2.0.0", - "@mikro-orm/core": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "awilix": "^8.0.1" } } diff --git a/packages/modules/pricing/package.json b/packages/modules/pricing/package.json index 38d0a558c4e3a..582cec953800f 100644 --- a/packages/modules/pricing/package.json +++ b/packages/modules/pricing/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.3", "@medusajs/test-utils": "^2.1.3", - "@mikro-orm/cli": "6.4.1", - "@mikro-orm/core": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/cli": "6.4.2", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", @@ -51,9 +51,9 @@ }, "peerDependencies": { "@medusajs/framework": "^2.0.0", - "@mikro-orm/core": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "awilix": "^8.0.1" } } diff --git a/packages/modules/product/package.json b/packages/modules/product/package.json index 41912db464756..d8746af7aef7d 100644 --- a/packages/modules/product/package.json +++ b/packages/modules/product/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.3", "@medusajs/test-utils": "^2.1.3", - "@mikro-orm/cli": "6.4.1", - "@mikro-orm/core": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/cli": "6.4.2", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "faker": "^5.5.3", @@ -52,9 +52,9 @@ }, "peerDependencies": { "@medusajs/framework": "^2.0.0", - "@mikro-orm/core": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "awilix": "^8.0.1" } } diff --git a/packages/modules/promotion/package.json b/packages/modules/promotion/package.json index bb4207e44207b..171ed9887fa56 100644 --- a/packages/modules/promotion/package.json +++ b/packages/modules/promotion/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.3", "@medusajs/test-utils": "^2.1.3", - "@mikro-orm/cli": "6.4.1", - "@mikro-orm/core": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/cli": "6.4.2", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", @@ -51,9 +51,9 @@ }, "peerDependencies": { "@medusajs/framework": "^2.0.0", - "@mikro-orm/core": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "awilix": "^8.0.1" } } diff --git a/packages/modules/providers/locking-postgres/package.json b/packages/modules/providers/locking-postgres/package.json index 37f6245aecb47..e5101ecdca266 100644 --- a/packages/modules/providers/locking-postgres/package.json +++ b/packages/modules/providers/locking-postgres/package.json @@ -21,10 +21,10 @@ "license": "MIT", "devDependencies": { "@medusajs/framework": "^2.1.3", - "@mikro-orm/cli": "6.4.1", - "@mikro-orm/core": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/cli": "6.4.2", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", diff --git a/packages/modules/region/package.json b/packages/modules/region/package.json index 00e0e6830f46d..70450135484d8 100644 --- a/packages/modules/region/package.json +++ b/packages/modules/region/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.3", "@medusajs/test-utils": "^2.1.3", - "@mikro-orm/cli": "6.4.1", - "@mikro-orm/core": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/cli": "6.4.2", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", @@ -51,9 +51,9 @@ }, "peerDependencies": { "@medusajs/framework": "^2.0.0", - "@mikro-orm/core": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "awilix": "^8.0.1" } } diff --git a/packages/modules/sales-channel/package.json b/packages/modules/sales-channel/package.json index c151d4482128a..c0b6bdefb6c38 100644 --- a/packages/modules/sales-channel/package.json +++ b/packages/modules/sales-channel/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.3", "@medusajs/test-utils": "^2.1.3", - "@mikro-orm/cli": "6.4.1", - "@mikro-orm/core": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/cli": "6.4.2", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", @@ -51,9 +51,9 @@ }, "peerDependencies": { "@medusajs/framework": "^2.0.0", - "@mikro-orm/core": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "awilix": "^8.0.1" } } diff --git a/packages/modules/stock-location/package.json b/packages/modules/stock-location/package.json index b886088cf163e..4c7f3ea0bb4da 100644 --- a/packages/modules/stock-location/package.json +++ b/packages/modules/stock-location/package.json @@ -25,10 +25,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.3", "@medusajs/test-utils": "^2.1.3", - "@mikro-orm/cli": "6.4.1", - "@mikro-orm/core": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/cli": "6.4.2", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", @@ -38,9 +38,9 @@ }, "peerDependencies": { "@medusajs/framework": "^2.0.0", - "@mikro-orm/core": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "awilix": "^8.0.1" }, "scripts": { diff --git a/packages/modules/store/package.json b/packages/modules/store/package.json index fdd4816f495e9..8941a39c43059 100644 --- a/packages/modules/store/package.json +++ b/packages/modules/store/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.3", "@medusajs/test-utils": "^2.1.3", - "@mikro-orm/cli": "6.4.1", - "@mikro-orm/core": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/cli": "6.4.2", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", @@ -51,9 +51,9 @@ }, "peerDependencies": { "@medusajs/framework": "^2.0.0", - "@mikro-orm/core": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "awilix": "^8.0.1" } } diff --git a/packages/modules/tax/package.json b/packages/modules/tax/package.json index b27a09ff4ce51..a2299906179a1 100644 --- a/packages/modules/tax/package.json +++ b/packages/modules/tax/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.3", "@medusajs/test-utils": "^2.1.3", - "@mikro-orm/cli": "6.4.1", - "@mikro-orm/core": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/cli": "6.4.2", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", @@ -51,9 +51,9 @@ }, "peerDependencies": { "@medusajs/framework": "^2.0.0", - "@mikro-orm/core": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "awilix": "^8.0.1" } } diff --git a/packages/modules/user/package.json b/packages/modules/user/package.json index 4d988c6b51ee5..a5a1852ea73d5 100644 --- a/packages/modules/user/package.json +++ b/packages/modules/user/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.3", "@medusajs/test-utils": "^2.1.3", - "@mikro-orm/cli": "6.4.1", - "@mikro-orm/core": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/cli": "6.4.2", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", @@ -54,9 +54,9 @@ }, "peerDependencies": { "@medusajs/framework": "^2.0.0", - "@mikro-orm/core": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "awilix": "^8.0.1" } } diff --git a/packages/modules/workflow-engine-inmemory/package.json b/packages/modules/workflow-engine-inmemory/package.json index fa4554cff963c..549ab72b66a4d 100644 --- a/packages/modules/workflow-engine-inmemory/package.json +++ b/packages/modules/workflow-engine-inmemory/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.3", "@medusajs/test-utils": "^2.1.3", - "@mikro-orm/cli": "6.4.1", - "@mikro-orm/core": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/cli": "6.4.2", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", @@ -55,9 +55,9 @@ }, "peerDependencies": { "@medusajs/framework": "^2.0.0", - "@mikro-orm/core": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "awilix": "^8.0.1" } } diff --git a/packages/modules/workflow-engine-redis/package.json b/packages/modules/workflow-engine-redis/package.json index 261bcf5c1d93c..617ddb26c3fd7 100644 --- a/packages/modules/workflow-engine-redis/package.json +++ b/packages/modules/workflow-engine-redis/package.json @@ -38,10 +38,10 @@ "devDependencies": { "@medusajs/framework": "^2.1.3", "@medusajs/test-utils": "^2.1.3", - "@mikro-orm/cli": "6.4.1", - "@mikro-orm/core": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/cli": "6.4.2", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "@swc/core": "^1.7.28", "@swc/jest": "^0.2.36", "jest": "^29.7.0", @@ -56,9 +56,9 @@ }, "peerDependencies": { "@medusajs/framework": "^2.0.0", - "@mikro-orm/core": "6.4.1", - "@mikro-orm/migrations": "6.4.1", - "@mikro-orm/postgresql": "6.4.1", + "@mikro-orm/core": "6.4.2", + "@mikro-orm/migrations": "6.4.2", + "@mikro-orm/postgresql": "6.4.2", "awilix": "^8.0.1" } } diff --git a/yarn.lock b/yarn.lock index aa77289365428..7619a76267181 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5316,7 +5316,7 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.3 "@medusajs/test-utils": ^2.1.3 - "@mikro-orm/cli": 6.4.1 + "@mikro-orm/cli": 6.4.2 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -5325,9 +5325,9 @@ __metadata: typescript: ^5.6.2 peerDependencies: "@medusajs/framework": ^2.0.0 - "@mikro-orm/core": 6.4.1 - "@mikro-orm/migrations": 6.4.1 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/migrations": 6.4.2 + "@mikro-orm/postgresql": 6.4.2 awilix: ^8.0.1 languageName: unknown linkType: soft @@ -5387,10 +5387,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.3 "@medusajs/test-utils": ^2.1.3 - "@mikro-orm/cli": 6.4.1 - "@mikro-orm/core": 6.4.1 - "@mikro-orm/migrations": 6.4.1 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/cli": 6.4.2 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/migrations": 6.4.2 + "@mikro-orm/postgresql": 6.4.2 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -5399,9 +5399,9 @@ __metadata: typescript: ^5.6.2 peerDependencies: "@medusajs/framework": ^2.0.0 - "@mikro-orm/core": 6.4.1 - "@mikro-orm/migrations": 6.4.1 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/migrations": 6.4.2 + "@mikro-orm/postgresql": 6.4.2 awilix: ^8.0.1 languageName: unknown linkType: soft @@ -5444,10 +5444,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.3 "@medusajs/test-utils": ^2.1.3 - "@mikro-orm/cli": 6.4.1 - "@mikro-orm/core": 6.4.1 - "@mikro-orm/migrations": 6.4.1 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/cli": 6.4.2 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/migrations": 6.4.2 + "@mikro-orm/postgresql": 6.4.2 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -5456,9 +5456,9 @@ __metadata: typescript: ^5.6.2 peerDependencies: "@medusajs/framework": ^2.0.0 - "@mikro-orm/core": 6.4.1 - "@mikro-orm/migrations": 6.4.1 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/migrations": 6.4.2 + "@mikro-orm/postgresql": 6.4.2 awilix: ^8.0.1 languageName: unknown linkType: soft @@ -5469,10 +5469,10 @@ __metadata: dependencies: "@medusajs/telemetry": ^2.1.3 "@medusajs/utils": 2.1.3 - "@mikro-orm/core": 6.4.1 - "@mikro-orm/knex": 6.4.1 - "@mikro-orm/migrations": 6.4.1 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/knex": 6.4.2 + "@mikro-orm/migrations": 6.4.2 + "@mikro-orm/postgresql": 6.4.2 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 "@types/express": ^4.17.17 @@ -5503,10 +5503,10 @@ __metadata: winston: ^3.8.2 yargs: ^15.3.1 peerDependencies: - "@mikro-orm/core": 6.4.1 - "@mikro-orm/knex": 6.4.1 - "@mikro-orm/migrations": 6.4.1 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/knex": 6.4.2 + "@mikro-orm/migrations": 6.4.2 + "@mikro-orm/postgresql": 6.4.2 awilix: ^8.0.1 pg: ^8.13.0 bin: @@ -5519,10 +5519,10 @@ __metadata: resolution: "@medusajs/core-flows@workspace:packages/core/core-flows" dependencies: "@medusajs/framework": ^2.1.3 - "@mikro-orm/core": 6.4.1 - "@mikro-orm/knex": 6.4.1 - "@mikro-orm/migrations": 6.4.1 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/knex": 6.4.2 + "@mikro-orm/migrations": 6.4.2 + "@mikro-orm/postgresql": 6.4.2 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 awilix: ^8.0.1 @@ -5544,10 +5544,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.3 "@medusajs/test-utils": ^2.1.3 - "@mikro-orm/cli": 6.4.1 - "@mikro-orm/core": 6.4.1 - "@mikro-orm/migrations": 6.4.1 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/cli": 6.4.2 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/migrations": 6.4.2 + "@mikro-orm/postgresql": 6.4.2 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -5556,9 +5556,9 @@ __metadata: typescript: ^5.6.2 peerDependencies: "@medusajs/framework": ^2.0.0 - "@mikro-orm/core": 6.4.1 - "@mikro-orm/migrations": 6.4.1 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/migrations": 6.4.2 + "@mikro-orm/postgresql": 6.4.2 awilix: ^8.0.1 languageName: unknown linkType: soft @@ -5569,10 +5569,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.3 "@medusajs/test-utils": ^2.1.3 - "@mikro-orm/cli": 6.4.1 - "@mikro-orm/core": 6.4.1 - "@mikro-orm/migrations": 6.4.1 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/cli": 6.4.2 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/migrations": 6.4.2 + "@mikro-orm/postgresql": 6.4.2 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -5581,9 +5581,9 @@ __metadata: typescript: ^5.6.2 peerDependencies: "@medusajs/framework": ^2.0.0 - "@mikro-orm/core": 6.4.1 - "@mikro-orm/migrations": 6.4.1 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/migrations": 6.4.2 + "@mikro-orm/postgresql": 6.4.2 awilix: ^8.0.1 languageName: unknown linkType: soft @@ -5719,10 +5719,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.3 "@medusajs/test-utils": ^2.1.3 - "@mikro-orm/cli": 6.4.1 - "@mikro-orm/core": 6.4.1 - "@mikro-orm/migrations": 6.4.1 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/cli": 6.4.2 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/migrations": 6.4.2 + "@mikro-orm/postgresql": 6.4.2 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -5747,10 +5747,10 @@ __metadata: "@medusajs/types": ^2.1.3 "@medusajs/utils": ^2.1.3 "@medusajs/workflows-sdk": ^2.1.3 - "@mikro-orm/core": 6.4.1 - "@mikro-orm/knex": 6.4.1 - "@mikro-orm/migrations": 6.4.1 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/knex": 6.4.2 + "@mikro-orm/migrations": 6.4.2 + "@mikro-orm/postgresql": 6.4.2 "@opentelemetry/api": ^1.9.0 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 @@ -5776,11 +5776,11 @@ __metadata: zod: 3.22.4 peerDependencies: "@medusajs/cli": ^2.0.0 - "@mikro-orm/cli": 6.4.1 - "@mikro-orm/core": 6.4.1 - "@mikro-orm/knex": 6.4.1 - "@mikro-orm/migrations": 6.4.1 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/cli": 6.4.2 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/knex": 6.4.2 + "@mikro-orm/migrations": 6.4.2 + "@mikro-orm/postgresql": 6.4.2 awilix: ^8.0.1 ioredis: ^5.4.1 pg: ^8.13.0 @@ -5818,10 +5818,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.3 "@medusajs/test-utils": ^2.1.3 - "@mikro-orm/cli": 6.4.1 - "@mikro-orm/core": 6.4.1 - "@mikro-orm/migrations": 6.4.1 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/cli": 6.4.2 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/migrations": 6.4.2 + "@mikro-orm/postgresql": 6.4.2 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -5830,9 +5830,9 @@ __metadata: typescript: ^5.6.2 peerDependencies: "@medusajs/framework": ^2.0.0 - "@mikro-orm/core": 6.4.1 - "@mikro-orm/migrations": 6.4.1 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/migrations": 6.4.2 + "@mikro-orm/postgresql": 6.4.2 awilix: ^8.0.1 languageName: unknown linkType: soft @@ -5877,11 +5877,11 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.3 "@medusajs/test-utils": ^2.1.3 - "@mikro-orm/cli": 6.4.1 - "@mikro-orm/core": 6.4.1 - "@mikro-orm/knex": 6.4.1 - "@mikro-orm/migrations": 6.4.1 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/cli": 6.4.2 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/knex": 6.4.2 + "@mikro-orm/migrations": 6.4.2 + "@mikro-orm/postgresql": 6.4.2 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -5890,10 +5890,10 @@ __metadata: typescript: ^5.6.2 peerDependencies: "@medusajs/framework": ^2.0.0 - "@mikro-orm/core": 6.4.1 - "@mikro-orm/knex": 6.4.1 - "@mikro-orm/migrations": 6.4.1 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/knex": 6.4.2 + "@mikro-orm/migrations": 6.4.2 + "@mikro-orm/postgresql": 6.4.2 awilix: ^8.0.1 languageName: unknown linkType: soft @@ -5904,10 +5904,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.3 "@medusajs/test-utils": ^2.1.3 - "@mikro-orm/cli": 6.4.1 - "@mikro-orm/core": 6.4.1 - "@mikro-orm/migrations": 6.4.1 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/cli": 6.4.2 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/migrations": 6.4.2 + "@mikro-orm/postgresql": 6.4.2 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -5916,9 +5916,9 @@ __metadata: typescript: ^5.6.2 peerDependencies: "@medusajs/framework": ^2.0.0 - "@mikro-orm/core": 6.4.1 - "@mikro-orm/migrations": 6.4.1 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/migrations": 6.4.2 + "@mikro-orm/postgresql": 6.4.2 awilix: ^8.0.1 languageName: unknown linkType: soft @@ -5943,9 +5943,9 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.3 "@medusajs/test-utils": ^2.1.3 - "@mikro-orm/core": 6.4.1 - "@mikro-orm/migrations": 6.4.1 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/migrations": 6.4.2 + "@mikro-orm/postgresql": 6.4.2 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 cross-env: ^5.2.1 @@ -5955,9 +5955,9 @@ __metadata: typescript: ^5.6.2 peerDependencies: "@medusajs/framework": ^2.0.0 - "@mikro-orm/core": 6.4.1 - "@mikro-orm/migrations": 6.4.1 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/migrations": 6.4.2 + "@mikro-orm/postgresql": 6.4.2 awilix: ^8.0.1 languageName: unknown linkType: soft @@ -5967,10 +5967,10 @@ __metadata: resolution: "@medusajs/locking-postgres@workspace:packages/modules/providers/locking-postgres" dependencies: "@medusajs/framework": ^2.1.3 - "@mikro-orm/cli": 6.4.1 - "@mikro-orm/core": 6.4.1 - "@mikro-orm/migrations": 6.4.1 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/cli": 6.4.2 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/migrations": 6.4.2 + "@mikro-orm/postgresql": 6.4.2 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -6003,10 +6003,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.3 "@medusajs/test-utils": ^2.1.3 - "@mikro-orm/cli": 6.4.1 - "@mikro-orm/core": 6.4.1 - "@mikro-orm/migrations": 6.4.1 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/cli": 6.4.2 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/migrations": 6.4.2 + "@mikro-orm/postgresql": 6.4.2 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -6015,9 +6015,9 @@ __metadata: typescript: ^5.6.2 peerDependencies: "@medusajs/framework": ^2.0.0 - "@mikro-orm/core": 6.4.1 - "@mikro-orm/migrations": 6.4.1 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/migrations": 6.4.2 + "@mikro-orm/postgresql": 6.4.2 awilix: ^8.0.1 languageName: unknown linkType: soft @@ -6134,10 +6134,10 @@ __metadata: zod: 3.22.4 peerDependencies: "@medusajs/framework": ^2.0.0 - "@mikro-orm/core": 6.4.1 - "@mikro-orm/knex": 6.4.1 - "@mikro-orm/migrations": 6.4.1 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/knex": 6.4.2 + "@mikro-orm/migrations": 6.4.2 + "@mikro-orm/postgresql": 6.4.2 awilix: ^8.0.1 languageName: unknown linkType: soft @@ -6149,10 +6149,10 @@ __metadata: "@medusajs/orchestration": ^2.1.3 "@medusajs/types": ^2.1.3 "@medusajs/utils": ^2.1.3 - "@mikro-orm/core": 6.4.1 - "@mikro-orm/knex": 6.4.1 - "@mikro-orm/migrations": 6.4.1 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/knex": 6.4.2 + "@mikro-orm/migrations": 6.4.2 + "@mikro-orm/postgresql": 6.4.2 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 awilix: ^8.0.1 @@ -6162,10 +6162,10 @@ __metadata: rimraf: ^5.0.1 typescript: ^5.6.2 peerDependencies: - "@mikro-orm/core": 6.4.1 - "@mikro-orm/knex": 6.4.1 - "@mikro-orm/migrations": 6.4.1 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/knex": 6.4.2 + "@mikro-orm/migrations": 6.4.2 + "@mikro-orm/postgresql": 6.4.2 awilix: ^8.0.1 express: ^4.21.0 pg: ^8.13.0 @@ -6209,10 +6209,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.3 "@medusajs/test-utils": ^2.1.3 - "@mikro-orm/cli": 6.4.1 - "@mikro-orm/core": 6.4.1 - "@mikro-orm/migrations": 6.4.1 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/cli": 6.4.2 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/migrations": 6.4.2 + "@mikro-orm/postgresql": 6.4.2 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -6221,9 +6221,9 @@ __metadata: typescript: ^5.6.2 peerDependencies: "@medusajs/framework": ^2.0.0 - "@mikro-orm/core": 6.4.1 - "@mikro-orm/migrations": 6.4.1 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/migrations": 6.4.2 + "@mikro-orm/postgresql": 6.4.2 awilix: ^8.0.1 languageName: unknown linkType: soft @@ -6243,10 +6243,10 @@ __metadata: dependencies: "@medusajs/types": ^2.1.3 "@medusajs/utils": ^2.1.3 - "@mikro-orm/core": 6.4.1 - "@mikro-orm/knex": 6.4.1 - "@mikro-orm/migrations": 6.4.1 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/knex": 6.4.2 + "@mikro-orm/migrations": 6.4.2 + "@mikro-orm/postgresql": 6.4.2 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 awilix: ^8.0.1 @@ -6255,10 +6255,10 @@ __metadata: rimraf: ^5.0.1 typescript: ^5.6.2 peerDependencies: - "@mikro-orm/core": 6.4.1 - "@mikro-orm/knex": 6.4.1 - "@mikro-orm/migrations": 6.4.1 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/knex": 6.4.2 + "@mikro-orm/migrations": 6.4.2 + "@mikro-orm/postgresql": 6.4.2 awilix: ^8.0.1 express: ^4.21.0 pg: ^8.13.0 @@ -6271,10 +6271,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.3 "@medusajs/test-utils": ^2.1.3 - "@mikro-orm/cli": 6.4.1 - "@mikro-orm/core": 6.4.1 - "@mikro-orm/migrations": 6.4.1 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/cli": 6.4.2 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/migrations": 6.4.2 + "@mikro-orm/postgresql": 6.4.2 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -6283,9 +6283,9 @@ __metadata: typescript: ^5.6.2 peerDependencies: "@medusajs/framework": ^2.0.0 - "@mikro-orm/core": 6.4.1 - "@mikro-orm/migrations": 6.4.1 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/migrations": 6.4.2 + "@mikro-orm/postgresql": 6.4.2 awilix: ^8.0.1 languageName: unknown linkType: soft @@ -6313,10 +6313,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.3 "@medusajs/test-utils": ^2.1.3 - "@mikro-orm/cli": 6.4.1 - "@mikro-orm/core": 6.4.1 - "@mikro-orm/migrations": 6.4.1 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/cli": 6.4.2 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/migrations": 6.4.2 + "@mikro-orm/postgresql": 6.4.2 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -6325,9 +6325,9 @@ __metadata: typescript: ^5.6.2 peerDependencies: "@medusajs/framework": ^2.0.0 - "@mikro-orm/core": 6.4.1 - "@mikro-orm/migrations": 6.4.1 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/migrations": 6.4.2 + "@mikro-orm/postgresql": 6.4.2 awilix: ^8.0.1 languageName: unknown linkType: soft @@ -6338,10 +6338,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.3 "@medusajs/test-utils": ^2.1.3 - "@mikro-orm/cli": 6.4.1 - "@mikro-orm/core": 6.4.1 - "@mikro-orm/migrations": 6.4.1 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/cli": 6.4.2 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/migrations": 6.4.2 + "@mikro-orm/postgresql": 6.4.2 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -6350,9 +6350,9 @@ __metadata: typescript: ^5.6.2 peerDependencies: "@medusajs/framework": ^2.0.0 - "@mikro-orm/core": 6.4.1 - "@mikro-orm/migrations": 6.4.1 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/migrations": 6.4.2 + "@mikro-orm/postgresql": 6.4.2 awilix: ^8.0.1 languageName: unknown linkType: soft @@ -6363,10 +6363,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.3 "@medusajs/test-utils": ^2.1.3 - "@mikro-orm/cli": 6.4.1 - "@mikro-orm/core": 6.4.1 - "@mikro-orm/migrations": 6.4.1 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/cli": 6.4.2 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/migrations": 6.4.2 + "@mikro-orm/postgresql": 6.4.2 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 faker: ^5.5.3 @@ -6376,9 +6376,9 @@ __metadata: typescript: ^5.6.2 peerDependencies: "@medusajs/framework": ^2.0.0 - "@mikro-orm/core": 6.4.1 - "@mikro-orm/migrations": 6.4.1 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/migrations": 6.4.2 + "@mikro-orm/postgresql": 6.4.2 awilix: ^8.0.1 languageName: unknown linkType: soft @@ -6389,10 +6389,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.3 "@medusajs/test-utils": ^2.1.3 - "@mikro-orm/cli": 6.4.1 - "@mikro-orm/core": 6.4.1 - "@mikro-orm/migrations": 6.4.1 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/cli": 6.4.2 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/migrations": 6.4.2 + "@mikro-orm/postgresql": 6.4.2 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -6401,9 +6401,9 @@ __metadata: typescript: ^5.6.2 peerDependencies: "@medusajs/framework": ^2.0.0 - "@mikro-orm/core": 6.4.1 - "@mikro-orm/migrations": 6.4.1 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/migrations": 6.4.2 + "@mikro-orm/postgresql": 6.4.2 awilix: ^8.0.1 languageName: unknown linkType: soft @@ -6414,10 +6414,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.3 "@medusajs/test-utils": ^2.1.3 - "@mikro-orm/cli": 6.4.1 - "@mikro-orm/core": 6.4.1 - "@mikro-orm/migrations": 6.4.1 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/cli": 6.4.2 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/migrations": 6.4.2 + "@mikro-orm/postgresql": 6.4.2 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -6426,9 +6426,9 @@ __metadata: typescript: ^5.6.2 peerDependencies: "@medusajs/framework": ^2.0.0 - "@mikro-orm/core": 6.4.1 - "@mikro-orm/migrations": 6.4.1 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/migrations": 6.4.2 + "@mikro-orm/postgresql": 6.4.2 awilix: ^8.0.1 languageName: unknown linkType: soft @@ -6439,10 +6439,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.3 "@medusajs/test-utils": ^2.1.3 - "@mikro-orm/cli": 6.4.1 - "@mikro-orm/core": 6.4.1 - "@mikro-orm/migrations": 6.4.1 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/cli": 6.4.2 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/migrations": 6.4.2 + "@mikro-orm/postgresql": 6.4.2 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -6451,9 +6451,9 @@ __metadata: typescript: ^5.6.2 peerDependencies: "@medusajs/framework": ^2.0.0 - "@mikro-orm/core": 6.4.1 - "@mikro-orm/migrations": 6.4.1 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/migrations": 6.4.2 + "@mikro-orm/postgresql": 6.4.2 awilix: ^8.0.1 languageName: unknown linkType: soft @@ -6464,10 +6464,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.3 "@medusajs/test-utils": ^2.1.3 - "@mikro-orm/cli": 6.4.1 - "@mikro-orm/core": 6.4.1 - "@mikro-orm/migrations": 6.4.1 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/cli": 6.4.2 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/migrations": 6.4.2 + "@mikro-orm/postgresql": 6.4.2 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -6476,9 +6476,9 @@ __metadata: typescript: ^5.6.2 peerDependencies: "@medusajs/framework": ^2.0.0 - "@mikro-orm/core": 6.4.1 - "@mikro-orm/migrations": 6.4.1 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/migrations": 6.4.2 + "@mikro-orm/postgresql": 6.4.2 awilix: ^8.0.1 languageName: unknown linkType: soft @@ -6489,10 +6489,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.3 "@medusajs/test-utils": ^2.1.3 - "@mikro-orm/cli": 6.4.1 - "@mikro-orm/core": 6.4.1 - "@mikro-orm/migrations": 6.4.1 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/cli": 6.4.2 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/migrations": 6.4.2 + "@mikro-orm/postgresql": 6.4.2 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -6501,9 +6501,9 @@ __metadata: typescript: ^5.6.2 peerDependencies: "@medusajs/framework": ^2.0.0 - "@mikro-orm/core": 6.4.1 - "@mikro-orm/migrations": 6.4.1 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/migrations": 6.4.2 + "@mikro-orm/postgresql": 6.4.2 awilix: ^8.0.1 languageName: unknown linkType: soft @@ -6514,10 +6514,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.3 "@medusajs/test-utils": ^2.1.3 - "@mikro-orm/cli": 6.4.1 - "@mikro-orm/core": 6.4.1 - "@mikro-orm/migrations": 6.4.1 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/cli": 6.4.2 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/migrations": 6.4.2 + "@mikro-orm/postgresql": 6.4.2 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -6526,9 +6526,9 @@ __metadata: typescript: ^5.6.2 peerDependencies: "@medusajs/framework": ^2.0.0 - "@mikro-orm/core": 6.4.1 - "@mikro-orm/migrations": 6.4.1 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/migrations": 6.4.2 + "@mikro-orm/postgresql": 6.4.2 awilix: ^8.0.1 languageName: unknown linkType: soft @@ -6560,10 +6560,10 @@ __metadata: resolution: "@medusajs/test-utils@workspace:packages/medusa-test-utils" dependencies: "@medusajs/framework": ^2.1.3 - "@mikro-orm/core": 6.4.1 - "@mikro-orm/knex": 6.4.1 - "@mikro-orm/migrations": 6.4.1 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/knex": 6.4.2 + "@mikro-orm/migrations": 6.4.2 + "@mikro-orm/postgresql": 6.4.2 "@types/express": ^4.17.17 awilix: ^8.0.1 axios: ^0.21.4 @@ -6578,7 +6578,7 @@ __metadata: peerDependencies: "@medusajs/framework": ^2.0.0 "@medusajs/medusa": ^2.0.0 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/postgresql": 6.4.2 awilix: ^8.0.1 peerDependenciesMeta: "@medusajs/medusa": @@ -6728,10 +6728,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.3 "@medusajs/test-utils": ^2.1.3 - "@mikro-orm/cli": 6.4.1 - "@mikro-orm/core": 6.4.1 - "@mikro-orm/migrations": 6.4.1 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/cli": 6.4.2 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/migrations": 6.4.2 + "@mikro-orm/postgresql": 6.4.2 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 jest: ^29.7.0 @@ -6741,9 +6741,9 @@ __metadata: typescript: ^5.6.2 peerDependencies: "@medusajs/framework": ^2.0.0 - "@mikro-orm/core": 6.4.1 - "@mikro-orm/migrations": 6.4.1 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/migrations": 6.4.2 + "@mikro-orm/postgresql": 6.4.2 awilix: ^8.0.1 languageName: unknown linkType: soft @@ -6757,10 +6757,10 @@ __metadata: "@graphql-tools/merge": ^9.0.7 "@graphql-tools/schema": ^10.0.6 "@medusajs/types": ^2.1.3 - "@mikro-orm/core": 6.4.1 - "@mikro-orm/knex": 6.4.1 - "@mikro-orm/migrations": 6.4.1 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/knex": 6.4.2 + "@mikro-orm/migrations": 6.4.2 + "@mikro-orm/postgresql": 6.4.2 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 "@types/express": ^4.17.21 @@ -6782,10 +6782,10 @@ __metadata: typescript: ^5.6.2 ulid: ^2.3.0 peerDependencies: - "@mikro-orm/core": 6.4.1 - "@mikro-orm/knex": 6.4.1 - "@mikro-orm/migrations": 6.4.1 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/knex": 6.4.2 + "@mikro-orm/migrations": 6.4.2 + "@mikro-orm/postgresql": 6.4.2 awilix: ^8.0.1 express: ^4.21.0 pg: ^8.13.0 @@ -6798,10 +6798,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.3 "@medusajs/test-utils": ^2.1.3 - "@mikro-orm/cli": 6.4.1 - "@mikro-orm/core": 6.4.1 - "@mikro-orm/migrations": 6.4.1 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/cli": 6.4.2 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/migrations": 6.4.2 + "@mikro-orm/postgresql": 6.4.2 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 cron-parser: ^4.9.0 @@ -6812,9 +6812,9 @@ __metadata: ulid: ^2.3.0 peerDependencies: "@medusajs/framework": ^2.0.0 - "@mikro-orm/core": 6.4.1 - "@mikro-orm/migrations": 6.4.1 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/migrations": 6.4.2 + "@mikro-orm/postgresql": 6.4.2 awilix: ^8.0.1 languageName: unknown linkType: soft @@ -6825,10 +6825,10 @@ __metadata: dependencies: "@medusajs/framework": ^2.1.3 "@medusajs/test-utils": ^2.1.3 - "@mikro-orm/cli": 6.4.1 - "@mikro-orm/core": 6.4.1 - "@mikro-orm/migrations": 6.4.1 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/cli": 6.4.2 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/migrations": 6.4.2 + "@mikro-orm/postgresql": 6.4.2 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 bullmq: 5.13.0 @@ -6840,9 +6840,9 @@ __metadata: ulid: ^2.3.0 peerDependencies: "@medusajs/framework": ^2.0.0 - "@mikro-orm/core": 6.4.1 - "@mikro-orm/migrations": 6.4.1 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/migrations": 6.4.2 + "@mikro-orm/postgresql": 6.4.2 awilix: ^8.0.1 languageName: unknown linkType: soft @@ -6855,10 +6855,10 @@ __metadata: "@medusajs/orchestration": ^2.1.3 "@medusajs/types": ^2.1.3 "@medusajs/utils": ^2.1.3 - "@mikro-orm/core": 6.4.1 - "@mikro-orm/knex": 6.4.1 - "@mikro-orm/migrations": 6.4.1 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/knex": 6.4.2 + "@mikro-orm/migrations": 6.4.2 + "@mikro-orm/postgresql": 6.4.2 "@swc/core": ^1.7.28 "@swc/jest": ^0.2.36 awilix: ^8.0.1 @@ -6868,51 +6868,51 @@ __metadata: typescript: ^5.6.2 ulid: ^2.3.0 peerDependencies: - "@mikro-orm/core": 6.4.1 - "@mikro-orm/knex": 6.4.1 - "@mikro-orm/migrations": 6.4.1 - "@mikro-orm/postgresql": 6.4.1 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/knex": 6.4.2 + "@mikro-orm/migrations": 6.4.2 + "@mikro-orm/postgresql": 6.4.2 awilix: ^8.0.1 express: ^4.21.0 pg: ^8.13.0 languageName: unknown linkType: soft -"@mikro-orm/cli@npm:6.4.1": - version: 6.4.1 - resolution: "@mikro-orm/cli@npm:6.4.1" +"@mikro-orm/cli@npm:6.4.2": + version: 6.4.2 + resolution: "@mikro-orm/cli@npm:6.4.2" dependencies: "@jercle/yargonaut": 1.1.5 - "@mikro-orm/core": 6.4.1 - "@mikro-orm/knex": 6.4.1 + "@mikro-orm/core": 6.4.2 + "@mikro-orm/knex": 6.4.2 fs-extra: 11.2.0 tsconfig-paths: 4.2.0 yargs: 17.7.2 bin: mikro-orm: ./cli mikro-orm-esm: ./esm - checksum: 6b92bb031243de3e0d3ec82d596ac740994230b82cc5efc45e1e916325fca15868b6a0b440ceaf8b60097c8929cd1e960b3b986ca1d5f13f97b4de4a794672c0 + checksum: 50f8784c5f66ac42e9e7b56b9041ea38ebec9186702b1fc89c6583686803fddb655061dde762225738ac5d01784aede12b8d34d79ec934be10870d8fd40bbbe8 languageName: node linkType: hard -"@mikro-orm/core@npm:6.4.1": - version: 6.4.1 - resolution: "@mikro-orm/core@npm:6.4.1" +"@mikro-orm/core@npm:6.4.2": + version: 6.4.2 + resolution: "@mikro-orm/core@npm:6.4.2" dependencies: dataloader: 2.2.3 dotenv: 16.4.7 esprima: 4.0.1 fs-extra: 11.2.0 globby: 11.1.0 - mikro-orm: 6.4.1 + mikro-orm: 6.4.2 reflect-metadata: 0.2.2 - checksum: 2ff7c4c84ed10433c13896fd5716b57ffe4d85cb51bc244184ace413daa81ca91e9cf021f6fb2e87f520efe7f59f0d32080a99e703a6bf83af683160b70b2ce1 + checksum: b121626e485f519d947fe50ba204bce3004b940c6473b52e0daefb0cb1da0d70a2c55b194abce597a805fe0fbd47e83e3ecee9e06cd8be728240031ae147e9b5 languageName: node linkType: hard -"@mikro-orm/knex@npm:6.4.1": - version: 6.4.1 - resolution: "@mikro-orm/knex@npm:6.4.1" +"@mikro-orm/knex@npm:6.4.2": + version: 6.4.2 + resolution: "@mikro-orm/knex@npm:6.4.2" dependencies: fs-extra: 11.2.0 knex: 3.1.0 @@ -6929,35 +6929,35 @@ __metadata: optional: true mariadb: optional: true - checksum: 3692e21978a112b7b8384b5ef1efccb0084f4f89bd0d07c217ea12eb9f79c05623d2d49ca37b3f6800b103b0e0ce700f9ba03d95dfa3db4d92a6bd650b4c3b41 + checksum: 76c19d2a0a00eddf81c089c4dad2b976c2003205b8faefc9ccdf005c6d3de7e4e715adf261b0ba591979ffa86ea7a215e380598446a1fc0dc8e79ca6edc725f0 languageName: node linkType: hard -"@mikro-orm/migrations@npm:6.4.1": - version: 6.4.1 - resolution: "@mikro-orm/migrations@npm:6.4.1" +"@mikro-orm/migrations@npm:6.4.2": + version: 6.4.2 + resolution: "@mikro-orm/migrations@npm:6.4.2" dependencies: - "@mikro-orm/knex": 6.4.1 + "@mikro-orm/knex": 6.4.2 fs-extra: 11.2.0 umzug: 3.8.2 peerDependencies: "@mikro-orm/core": ^6.0.0 - checksum: 67a8f46e10c34c29df2e548be2840fd63e059e5d9421f9937d536aa68768cbc40b339451a3770a288716650774d22755d763968ccd3aee453516d7e4f08c5218 + checksum: 28a46ceca4ab5b5292204071babe90523616f766a897779353ded98fced11ee04debe500c8d15a9ce17a7ca94db1afd8d20969866852d4f7b029d82911e55474 languageName: node linkType: hard -"@mikro-orm/postgresql@npm:6.4.1": - version: 6.4.1 - resolution: "@mikro-orm/postgresql@npm:6.4.1" +"@mikro-orm/postgresql@npm:6.4.2": + version: 6.4.2 + resolution: "@mikro-orm/postgresql@npm:6.4.2" dependencies: - "@mikro-orm/knex": 6.4.1 + "@mikro-orm/knex": 6.4.2 pg: 8.13.1 postgres-array: 3.0.2 postgres-date: 2.1.0 postgres-interval: 4.0.2 peerDependencies: "@mikro-orm/core": ^6.0.0 - checksum: 6d4ede8d20fc3a11e7bd19a966079e849c11bef909f80a343e3c1e1d8a00545ef5c7b853dbbc22d0165ed84269488201a91316667134b29df7cd8d306b924dae + checksum: 303a96af794e734b404e21d1085eec04ab7042053e7a95b38b64b911b61dacf25c113d84132f8bafcbca17634b4826ea77d8b6058cea53e169ff391d9c6ff92c languageName: node linkType: hard @@ -24810,10 +24810,10 @@ __metadata: languageName: node linkType: hard -"mikro-orm@npm:6.4.1": - version: 6.4.1 - resolution: "mikro-orm@npm:6.4.1" - checksum: 8cd06b83490496abd8686bcc50e88e398ba6e726bc85cdbfd2530072cdf7e24ec6a989df9254f20d1e39ec5571efa312d5e7c2a384a0ce73c25c2c31b0a1aaaf +"mikro-orm@npm:6.4.2": + version: 6.4.2 + resolution: "mikro-orm@npm:6.4.2" + checksum: fc96b6945b7712648ef1371d6e08acbc6b9cd14092e3835d47ac7c8616e2f5fa11eb2fee764dc6fd26f9a528f7be90b958ee1ba9ea78b92b821ab2aa058a972d languageName: node linkType: hard From f4c5d0c15c195f9173c80f2b002fd95d116abf5d Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Mon, 6 Jan 2025 14:53:07 -0300 Subject: [PATCH 161/175] request return field --- .../order/workflows/claim/cancel-begin-order-claim.ts | 9 ++++++++- .../core-flows/src/order/workflows/claim/cancel-claim.ts | 1 + .../order/workflows/claim/claim-request-item-return.ts | 2 +- .../workflows/exchange/cancel-begin-order-exchange.ts | 9 ++++++++- .../src/order/workflows/exchange/cancel-exchange.ts | 1 + .../workflows/exchange/exchange-request-item-return.ts | 2 +- 6 files changed, 20 insertions(+), 4 deletions(-) diff --git a/packages/core/core-flows/src/order/workflows/claim/cancel-begin-order-claim.ts b/packages/core/core-flows/src/order/workflows/claim/cancel-begin-order-claim.ts index 0f1f106df2087..b4b0224c6d12a 100644 --- a/packages/core/core-flows/src/order/workflows/claim/cancel-begin-order-claim.ts +++ b/packages/core/core-flows/src/order/workflows/claim/cancel-begin-order-claim.ts @@ -57,7 +57,14 @@ export const cancelBeginOrderClaimWorkflow = createWorkflow( function (input: CancelBeginOrderClaimWorkflowInput): WorkflowData { const orderClaim: OrderClaimDTO = useRemoteQueryStep({ entry_point: "order_claim", - fields: ["id", "status", "order_id", "return_id", "canceled_at"], + fields: [ + "id", + "status", + "order_id", + "return", + "return_id", + "canceled_at", + ], variables: { id: input.claim_id }, list: false, throw_if_key_not_found: true, diff --git a/packages/core/core-flows/src/order/workflows/claim/cancel-claim.ts b/packages/core/core-flows/src/order/workflows/claim/cancel-claim.ts index 0a60537f69d0b..4399cb3f58d5c 100644 --- a/packages/core/core-flows/src/order/workflows/claim/cancel-claim.ts +++ b/packages/core/core-flows/src/order/workflows/claim/cancel-claim.ts @@ -70,6 +70,7 @@ export const cancelOrderClaimWorkflow = createWorkflow( fields: [ "id", "order_id", + "return", "return_id", "canceled_at", "fulfillments.canceled_at", diff --git a/packages/core/core-flows/src/order/workflows/claim/claim-request-item-return.ts b/packages/core/core-flows/src/order/workflows/claim/claim-request-item-return.ts index 7a63914a3b6b1..9328f4d0c4d4b 100644 --- a/packages/core/core-flows/src/order/workflows/claim/claim-request-item-return.ts +++ b/packages/core/core-flows/src/order/workflows/claim/claim-request-item-return.ts @@ -64,7 +64,7 @@ export const orderClaimRequestItemReturnWorkflow = createWorkflow( ): WorkflowResponse { const orderClaim = useRemoteQueryStep({ entry_point: "order_claim", - fields: ["id", "order_id", "return_id", "canceled_at"], + fields: ["id", "order_id", "return", "return_id", "canceled_at"], variables: { id: input.claim_id }, list: false, throw_if_key_not_found: true, diff --git a/packages/core/core-flows/src/order/workflows/exchange/cancel-begin-order-exchange.ts b/packages/core/core-flows/src/order/workflows/exchange/cancel-begin-order-exchange.ts index 532ea5e97a796..599b24af18b90 100644 --- a/packages/core/core-flows/src/order/workflows/exchange/cancel-begin-order-exchange.ts +++ b/packages/core/core-flows/src/order/workflows/exchange/cancel-begin-order-exchange.ts @@ -56,7 +56,14 @@ export const cancelBeginOrderExchangeWorkflow = createWorkflow( function (input: CancelBeginOrderExchangeWorkflowInput): WorkflowData { const orderExchange: OrderExchangeDTO = useRemoteQueryStep({ entry_point: "order_exchange", - fields: ["id", "status", "order_id", "return_id", "canceled_at"], + fields: [ + "id", + "status", + "order_id", + "return", + "return_id", + "canceled_at", + ], variables: { id: input.exchange_id }, list: false, throw_if_key_not_found: true, diff --git a/packages/core/core-flows/src/order/workflows/exchange/cancel-exchange.ts b/packages/core/core-flows/src/order/workflows/exchange/cancel-exchange.ts index 0ae849915010a..b95425626e3ff 100644 --- a/packages/core/core-flows/src/order/workflows/exchange/cancel-exchange.ts +++ b/packages/core/core-flows/src/order/workflows/exchange/cancel-exchange.ts @@ -70,6 +70,7 @@ export const cancelOrderExchangeWorkflow = createWorkflow( fields: [ "id", "order_id", + "return", "return_id", "canceled_at", "fulfillments.canceled_at", diff --git a/packages/core/core-flows/src/order/workflows/exchange/exchange-request-item-return.ts b/packages/core/core-flows/src/order/workflows/exchange/exchange-request-item-return.ts index a8a9d83da3f4a..ffbd0d4ec6f28 100644 --- a/packages/core/core-flows/src/order/workflows/exchange/exchange-request-item-return.ts +++ b/packages/core/core-flows/src/order/workflows/exchange/exchange-request-item-return.ts @@ -65,7 +65,7 @@ export const orderExchangeRequestItemReturnWorkflow = createWorkflow( ): WorkflowResponse { const orderExchange = useRemoteQueryStep({ entry_point: "order_exchange", - fields: ["id", "order_id", "return_id", "canceled_at"], + fields: ["id", "order_id", "return", "return_id", "canceled_at"], variables: { id: input.exchange_id }, list: false, throw_if_key_not_found: true, From 5c0d8975cb88213cb31cddf0270c18aec940cf4c Mon Sep 17 00:00:00 2001 From: adrien2p Date: Tue, 7 Jan 2025 13:22:40 +0100 Subject: [PATCH 162/175] fix return configuration on order model --- .../order/workflows/return/items.spec.ts | 4 +- packages/modules/order/src/models/address.ts | 35 +++---- .../modules/order/src/models/claim-item.ts | 45 ++++----- .../modules/order/src/models/exchange-item.ts | 32 +++---- .../order/src/models/line-item-adjustment.ts | 27 +++--- .../order/src/models/line-item-tax-line.ts | 27 +++--- .../modules/order/src/models/order-item.ts | 49 +++++----- .../order/src/models/order-shipping-method.ts | 61 ++++++------ packages/modules/order/src/models/order.ts | 93 +++++++++---------- packages/modules/order/src/models/return.ts | 6 +- .../order/src/utils/base-repository-find.ts | 11 +-- 11 files changed, 175 insertions(+), 215 deletions(-) diff --git a/integration-tests/modules/__tests__/order/workflows/return/items.spec.ts b/integration-tests/modules/__tests__/order/workflows/return/items.spec.ts index fb2ee5a3aa2a8..6bc8c8de0a136 100644 --- a/integration-tests/modules/__tests__/order/workflows/return/items.spec.ts +++ b/integration-tests/modules/__tests__/order/workflows/return/items.spec.ts @@ -145,7 +145,9 @@ medusaIntegrationTestRunner({ throwOnError: false, }) - expect(error.error.message).toEqual(`Order id not found: ${order.id}`) + expect(error.error.message).toEqual( + `Return id not found: ${returnOrder.id}` + ) }) it("should throw an error if order change does not exist", async () => { diff --git a/packages/modules/order/src/models/address.ts b/packages/modules/order/src/models/address.ts index 69a9571b4090a..94b4d7129ef1b 100644 --- a/packages/modules/order/src/models/address.ts +++ b/packages/modules/order/src/models/address.ts @@ -1,26 +1,21 @@ import { model } from "@medusajs/framework/utils" const _OrderAddress = model - .define( - { - tableName: "order_address", - }, - { - id: model.id({ prefix: "ordaddr" }).primaryKey(), - customer_id: model.text().nullable(), - company: model.text().searchable().nullable(), - first_name: model.text().searchable().nullable(), - last_name: model.text().searchable().nullable(), - address_1: model.text().searchable().nullable(), - address_2: model.text().searchable().nullable(), - city: model.text().searchable().nullable(), - country_code: model.text().nullable(), - province: model.text().searchable().nullable(), - postal_code: model.text().searchable().nullable(), - phone: model.text().searchable().nullable(), - metadata: model.json().nullable(), - } - ) + .define("OrderAddress", { + id: model.id({ prefix: "ordaddr" }).primaryKey(), + customer_id: model.text().nullable(), + company: model.text().searchable().nullable(), + first_name: model.text().searchable().nullable(), + last_name: model.text().searchable().nullable(), + address_1: model.text().searchable().nullable(), + address_2: model.text().searchable().nullable(), + city: model.text().searchable().nullable(), + country_code: model.text().nullable(), + province: model.text().searchable().nullable(), + postal_code: model.text().searchable().nullable(), + phone: model.text().searchable().nullable(), + metadata: model.json().nullable(), + }) .indexes([ { name: "IDX_order_address_customer_id", diff --git a/packages/modules/order/src/models/claim-item.ts b/packages/modules/order/src/models/claim-item.ts index b2ce81348fdbb..8539d23567b17 100644 --- a/packages/modules/order/src/models/claim-item.ts +++ b/packages/modules/order/src/models/claim-item.ts @@ -4,31 +4,26 @@ import { OrderClaimItemImage } from "./claim-item-image" import { OrderLineItem } from "./line-item" const _OrderClaimItem = model - .define( - { - tableName: "order_claim_item", - }, - { - id: model.id({ prefix: "claitem" }).primaryKey(), - reason: model.enum(ClaimReason).nullable(), - quantity: model.bigNumber(), - is_additional_item: model.boolean().default(false), - note: model.text().nullable(), - metadata: model.json().nullable(), - claim: model.belongsTo<() => typeof OrderClaim>(() => OrderClaim, { - mappedBy: "additional_items", - }), - item: model.belongsTo<() => typeof OrderLineItem>(() => OrderLineItem, { - mappedBy: "claim_items", - }), - images: model.hasMany<() => typeof OrderClaimItemImage>( - () => OrderClaimItemImage, - { - mappedBy: "claim_item", - } - ), - } - ) + .define("OrderClaimItem", { + id: model.id({ prefix: "claitem" }).primaryKey(), + reason: model.enum(ClaimReason).nullable(), + quantity: model.bigNumber(), + is_additional_item: model.boolean().default(false), + note: model.text().nullable(), + metadata: model.json().nullable(), + claim: model.belongsTo<() => typeof OrderClaim>(() => OrderClaim, { + mappedBy: "additional_items", + }), + item: model.belongsTo<() => typeof OrderLineItem>(() => OrderLineItem, { + mappedBy: "claim_items", + }), + images: model.hasMany<() => typeof OrderClaimItemImage>( + () => OrderClaimItemImage, + { + mappedBy: "claim_item", + } + ), + }) .cascades({ delete: ["images"], }) diff --git a/packages/modules/order/src/models/exchange-item.ts b/packages/modules/order/src/models/exchange-item.ts index adbc18dd506e9..998aabad7a071 100644 --- a/packages/modules/order/src/models/exchange-item.ts +++ b/packages/modules/order/src/models/exchange-item.ts @@ -3,26 +3,18 @@ import { OrderExchange } from "./exchange" import { OrderLineItem } from "./line-item" const _OrderExchangeItem = model - .define( - { - tableName: "order_exchange_item", - }, - { - id: model.id({ prefix: "oexcitem" }).primaryKey(), - quantity: model.bigNumber(), - note: model.text().nullable(), - metadata: model.json().nullable(), - exchange: model.belongsTo<() => typeof OrderExchange>( - () => OrderExchange, - { - mappedBy: "additional_items", - } - ), - item: model.belongsTo<() => typeof OrderLineItem>(() => OrderLineItem, { - mappedBy: "exchange_items", - }), - } - ) + .define("OrderExchangeItem", { + id: model.id({ prefix: "oexcitem" }).primaryKey(), + quantity: model.bigNumber(), + note: model.text().nullable(), + metadata: model.json().nullable(), + exchange: model.belongsTo<() => typeof OrderExchange>(() => OrderExchange, { + mappedBy: "additional_items", + }), + item: model.belongsTo<() => typeof OrderLineItem>(() => OrderLineItem, { + mappedBy: "exchange_items", + }), + }) .indexes([ { name: "IDX_order_exchange_item_exchange_id", diff --git a/packages/modules/order/src/models/line-item-adjustment.ts b/packages/modules/order/src/models/line-item-adjustment.ts index 6b1ecc0cb6171..8808b9c193f22 100644 --- a/packages/modules/order/src/models/line-item-adjustment.ts +++ b/packages/modules/order/src/models/line-item-adjustment.ts @@ -2,22 +2,17 @@ import { model } from "@medusajs/framework/utils" import { OrderLineItem } from "./line-item" const _OrderLineItemAdjustment = model - .define( - { - tableName: "order_line_item_adjustment", - }, - { - id: model.id({ prefix: "ordliadj" }).primaryKey(), - description: model.text().nullable(), - promotion_id: model.text().nullable(), - code: model.text().nullable(), - amount: model.bigNumber(), - provider_id: model.text().nullable(), - item: model.belongsTo<() => typeof OrderLineItem>(() => OrderLineItem, { - mappedBy: "adjustments", - }), - } - ) + .define("OrderLineItemAdjustment", { + id: model.id({ prefix: "ordliadj" }).primaryKey(), + description: model.text().nullable(), + promotion_id: model.text().nullable(), + code: model.text().nullable(), + amount: model.bigNumber(), + provider_id: model.text().nullable(), + item: model.belongsTo<() => typeof OrderLineItem>(() => OrderLineItem, { + mappedBy: "adjustments", + }), + }) .indexes([ { name: "IDX_order_order_line_item_adjustment_item_id", diff --git a/packages/modules/order/src/models/line-item-tax-line.ts b/packages/modules/order/src/models/line-item-tax-line.ts index b8f43729796c8..89436072aa662 100644 --- a/packages/modules/order/src/models/line-item-tax-line.ts +++ b/packages/modules/order/src/models/line-item-tax-line.ts @@ -2,22 +2,17 @@ import { model } from "@medusajs/framework/utils" import { OrderLineItem } from "./line-item" const _OrderLineItemTaxLine = model - .define( - { - tableName: "order_line_item_tax_line", - }, - { - id: model.id({ prefix: "ordlitxl" }).primaryKey(), - description: model.text().nullable(), - tax_rate_id: model.text().nullable(), - code: model.text(), - rate: model.bigNumber(), - provider_id: model.text().nullable(), - item: model.belongsTo<() => typeof OrderLineItem>(() => OrderLineItem, { - mappedBy: "tax_lines", - }), - } - ) + .define("OrderLineItemTaxLine", { + id: model.id({ prefix: "ordlitxl" }).primaryKey(), + description: model.text().nullable(), + tax_rate_id: model.text().nullable(), + code: model.text(), + rate: model.bigNumber(), + provider_id: model.text().nullable(), + item: model.belongsTo<() => typeof OrderLineItem>(() => OrderLineItem, { + mappedBy: "tax_lines", + }), + }) .indexes([ { name: "IDX_order_line_item_tax_line_item_id", diff --git a/packages/modules/order/src/models/order-item.ts b/packages/modules/order/src/models/order-item.ts index 0e9c604150300..07c340c765f64 100644 --- a/packages/modules/order/src/models/order-item.ts +++ b/packages/modules/order/src/models/order-item.ts @@ -4,33 +4,28 @@ import { OrderLineItem } from "./line-item" import { Order } from "./order" const _OrderItem = model - .define( - { - tableName: "order_item", - }, - { - id: model.id({ prefix: "orditem" }).primaryKey(), - version: model.number().default(1), - unit_price: model.bigNumber().nullable(), - compare_at_unit_price: model.bigNumber().nullable(), - quantity: model.bigNumber(), - fulfilled_quantity: model.bigNumber().default(0), - delivered_quantity: model.bigNumber().default(0), - shipped_quantity: model.bigNumber().default(0), - return_requested_quantity: model.bigNumber().default(0), - return_received_quantity: model.bigNumber().default(0), - return_dismissed_quantity: model.bigNumber().default(0), - written_off_quantity: model.bigNumber().default(0), - metadata: model.json().nullable(), - order: model.belongsTo<() => typeof Order>(() => Order, { - mappedBy: "items", - }), - item: model.hasOne<() => typeof OrderLineItem>(() => OrderLineItem, { - mappedBy: undefined, - foreignKey: true, - }), - } - ) + .define("OrderItem", { + id: model.id({ prefix: "orditem" }).primaryKey(), + version: model.number().default(1), + unit_price: model.bigNumber().nullable(), + compare_at_unit_price: model.bigNumber().nullable(), + quantity: model.bigNumber(), + fulfilled_quantity: model.bigNumber().default(0), + delivered_quantity: model.bigNumber().default(0), + shipped_quantity: model.bigNumber().default(0), + return_requested_quantity: model.bigNumber().default(0), + return_received_quantity: model.bigNumber().default(0), + return_dismissed_quantity: model.bigNumber().default(0), + written_off_quantity: model.bigNumber().default(0), + metadata: model.json().nullable(), + order: model.belongsTo<() => typeof Order>(() => Order, { + mappedBy: "items", + }), + item: model.hasOne<() => typeof OrderLineItem>(() => OrderLineItem, { + mappedBy: undefined, + foreignKey: true, + }), + }) .indexes([ { name: "IDX_order_item_order_id", diff --git a/packages/modules/order/src/models/order-shipping-method.ts b/packages/modules/order/src/models/order-shipping-method.ts index 855001af10a69..1889c0dbab209 100644 --- a/packages/modules/order/src/models/order-shipping-method.ts +++ b/packages/modules/order/src/models/order-shipping-method.ts @@ -6,40 +6,35 @@ import { Return } from "./return" import { OrderShippingMethod } from "./shipping-method" const _OrderShipping = model - .define( - { - tableName: "order_shipping", - }, - { - id: model.id({ prefix: "ordspmv" }).primaryKey(), - version: model.number().default(1), - order: model.belongsTo<() => typeof Order>(() => Order, { + .define("OrderShipping", { + id: model.id({ prefix: "ordspmv" }).primaryKey(), + version: model.number().default(1), + order: model.belongsTo<() => typeof Order>(() => Order, { + mappedBy: "shipping_methods", + }), + return: model + .belongsTo<() => typeof Return>(() => Return, { + mappedBy: "shipping_methods", + }) + .nullable(), + exchange: model + .belongsTo<() => typeof OrderExchange>(() => OrderExchange, { + mappedBy: "shipping_methods", + }) + .nullable(), + claim: model + .belongsTo<() => typeof OrderClaim>(() => OrderClaim, { mappedBy: "shipping_methods", - }), - return: model - .belongsTo<() => typeof Return>(() => Return, { - mappedBy: "shipping_methods", - }) - .nullable(), - exchange: model - .belongsTo<() => typeof OrderExchange>(() => OrderExchange, { - mappedBy: "shipping_methods", - }) - .nullable(), - claim: model - .belongsTo<() => typeof OrderClaim>(() => OrderClaim, { - mappedBy: "shipping_methods", - }) - .nullable(), - shipping_method: model.hasOne<() => typeof OrderShippingMethod>( - () => OrderShippingMethod, - { - mappedBy: undefined, - foreignKey: true, - } - ), - } - ) + }) + .nullable(), + shipping_method: model.hasOne<() => typeof OrderShippingMethod>( + () => OrderShippingMethod, + { + mappedBy: undefined, + foreignKey: true, + } + ), + }) .indexes([ { name: "IDX_order_shipping_order_id", diff --git a/packages/modules/order/src/models/order.ts b/packages/modules/order/src/models/order.ts index daa0ac84856aa..584c01762b344 100644 --- a/packages/modules/order/src/models/order.ts +++ b/packages/modules/order/src/models/order.ts @@ -5,55 +5,54 @@ import { OrderItem } from "./order-item" import { OrderShipping } from "./order-shipping-method" import { OrderSummary } from "./order-summary" import { OrderTransaction } from "./transaction" +import { Return } from "@models" const _Order = model - .define( - { - tableName: "order", - }, - { - id: model.id({ prefix: "order" }).primaryKey(), - display_id: model.autoincrement(), - region_id: model.text().nullable(), - customer_id: model.text().nullable(), - version: model.number().default(1), - sales_channel_id: model.text().nullable(), - status: model.enum(OrderStatus).default(OrderStatus.PENDING), - is_draft_order: model.boolean().default(false), - email: model.text().searchable().nullable(), - currency_code: model.text(), - no_notification: model.boolean().nullable(), - metadata: model.json().nullable(), - canceled_at: model.dateTime().nullable(), - shipping_address: model - .hasOne(() => OrderAddress, { - mappedBy: undefined, - foreignKey: true, - }) - .nullable(), - billing_address: model - .hasOne(() => OrderAddress, { - mappedBy: undefined, - foreignKey: true, - }) - .nullable(), - summary: model.hasMany(() => OrderSummary, { - mappedBy: "order", - }), - items: model.hasMany(() => OrderItem, { - mappedBy: "order", - }), - shipping_methods: model.hasMany(() => OrderShipping, { - mappedBy: "order", - }), - transactions: model.hasMany(() => OrderTransaction, { - mappedBy: "order", - }), - credit_lines: model.hasMany(() => OrderCreditLine, { - mappedBy: "order", - }), - } - ) + .define("Order", { + id: model.id({ prefix: "order" }).primaryKey(), + display_id: model.autoincrement(), + region_id: model.text().nullable(), + customer_id: model.text().nullable(), + version: model.number().default(1), + sales_channel_id: model.text().nullable(), + status: model.enum(OrderStatus).default(OrderStatus.PENDING), + is_draft_order: model.boolean().default(false), + email: model.text().searchable().nullable(), + currency_code: model.text(), + no_notification: model.boolean().nullable(), + metadata: model.json().nullable(), + canceled_at: model.dateTime().nullable(), + shipping_address: model + .hasOne(() => OrderAddress, { + mappedBy: undefined, + foreignKey: true, + }) + .nullable(), + billing_address: model + .hasOne(() => OrderAddress, { + mappedBy: undefined, + foreignKey: true, + }) + .nullable(), + summary: model.hasMany(() => OrderSummary, { + mappedBy: "order", + }), + items: model.hasMany(() => OrderItem, { + mappedBy: "order", + }), + shipping_methods: model.hasMany(() => OrderShipping, { + mappedBy: "order", + }), + transactions: model.hasMany(() => OrderTransaction, { + mappedBy: "order", + }), + credit_lines: model.hasMany(() => OrderCreditLine, { + mappedBy: "order", + }), + returns: model.hasMany(() => Return, { + mappedBy: "order", + }), + }) .cascades({ delete: ["summary", "items", "shipping_methods", "transactions"], }) diff --git a/packages/modules/order/src/models/return.ts b/packages/modules/order/src/models/return.ts index d0d071b8b3ff9..4bf931ef5ebe4 100644 --- a/packages/modules/order/src/models/return.ts +++ b/packages/modules/order/src/models/return.ts @@ -20,9 +20,9 @@ const _Return = model requested_at: model.dateTime().nullable(), received_at: model.dateTime().nullable(), canceled_at: model.dateTime().nullable(), - order: model.hasOne<() => typeof Order>(() => Order, { - mappedBy: undefined, - foreignKey: true, + order: model.belongsTo<() => typeof Order>(() => Order, { + mappedBy: "returns", + // foreignKey: true, }), exchange: model .belongsTo<() => typeof OrderExchange>(() => OrderExchange, { diff --git a/packages/modules/order/src/utils/base-repository-find.ts b/packages/modules/order/src/utils/base-repository-find.ts index b9c3d85106478..3d0b65a10108d 100644 --- a/packages/modules/order/src/utils/base-repository-find.ts +++ b/packages/modules/order/src/utils/base-repository-find.ts @@ -29,7 +29,8 @@ export function setFindMethods(klass: Constructor, entity: any) { } } - const isRelatedEntity = entity !== Order + const isRelatedEntity = entity.name !== Order.name + const config = mapRepositoryToOrderModel(findOptions_, isRelatedEntity) config.options ??= {} config.options.populate ??= [] @@ -106,7 +107,8 @@ export function setFindMethods(klass: Constructor, entity: any) { }) } - const isRelatedEntity = entity !== Order + const isRelatedEntity = entity.name !== Order.name + const config = mapRepositoryToOrderModel(findOptions_, isRelatedEntity) let orderAlias = "o0" @@ -177,11 +179,6 @@ function configurePopulateWhere( popWhere.shipping_methods ??= {} popWhere.shipping_methods.version = version } - - if (hasRelation("shipping_methods")) { - popWhere.shipping_methods ??= {} - popWhere.shipping_methods.version = version - } } const orderWhere = isRelatedEntity ? popWhere.order : popWhere From a708664224d898faadb477cdfa19e00ad11895b3 Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Tue, 7 Jan 2025 20:21:31 -0300 Subject: [PATCH 163/175] workflows --- .../src/order/steps/update-order-changes.ts | 2 +- .../order/workflows/claim/begin-order-claim.ts | 2 +- .../claim/claim-request-item-return.ts | 6 +++--- .../workflows/exchange/begin-order-exchange.ts | 2 +- .../exchange/exchange-request-item-return.ts | 6 +++--- .../src/order/workflows/return/begin-return.ts | 2 +- .../[id]/inbound/items/[action_id]/route.ts | 17 ++++++++++------- .../admin/claims/[id]/inbound/items/route.ts | 2 +- .../shipping-method/[action_id]/route.ts | 12 ++++++------ .../[id]/inbound/shipping-method/route.ts | 4 ++-- packages/modules/order/src/models/return.ts | 1 - 11 files changed, 29 insertions(+), 27 deletions(-) diff --git a/packages/core/core-flows/src/order/steps/update-order-changes.ts b/packages/core/core-flows/src/order/steps/update-order-changes.ts index 17c0e3ae122f1..6ca49981bdcf2 100644 --- a/packages/core/core-flows/src/order/steps/update-order-changes.ts +++ b/packages/core/core-flows/src/order/steps/update-order-changes.ts @@ -8,7 +8,7 @@ import { } from "@medusajs/framework/utils" import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk" -export const updateOrderChangesStepId = "update-order-shopping-methods" +export const updateOrderChangesStepId = "update-order-changes" /** * This step updates order change. */ diff --git a/packages/core/core-flows/src/order/workflows/claim/begin-order-claim.ts b/packages/core/core-flows/src/order/workflows/claim/begin-order-claim.ts index ba43b77489438..d90c2c1df9e88 100644 --- a/packages/core/core-flows/src/order/workflows/claim/begin-order-claim.ts +++ b/packages/core/core-flows/src/order/workflows/claim/begin-order-claim.ts @@ -59,7 +59,7 @@ export const beginClaimOrderWorkflow = createWorkflow( return { change_type: "claim" as const, order_id: input.order_id, - claim_id: created[0].id, + claim: created[0].id, created_by: input.created_by, description: input.description, internal_note: input.internal_note, diff --git a/packages/core/core-flows/src/order/workflows/claim/claim-request-item-return.ts b/packages/core/core-flows/src/order/workflows/claim/claim-request-item-return.ts index 9328f4d0c4d4b..8d2468a61a703 100644 --- a/packages/core/core-flows/src/order/workflows/claim/claim-request-item-return.ts +++ b/packages/core/core-flows/src/order/workflows/claim/claim-request-item-return.ts @@ -64,7 +64,7 @@ export const orderClaimRequestItemReturnWorkflow = createWorkflow( ): WorkflowResponse { const orderClaim = useRemoteQueryStep({ entry_point: "order_claim", - fields: ["id", "order_id", "return", "return_id", "canceled_at"], + fields: ["id", "order_id", "return_id", "canceled_at"], variables: { id: input.claim_id }, list: false, throw_if_key_not_found: true, @@ -129,8 +129,8 @@ export const orderClaimRequestItemReturnWorkflow = createWorkflow( updateOrderChangesStep([ { id: orderChange.id, - return_id: createdReturn?.[0]?.id, - }, + return: orderReturn.id, + } as any, ]) }) diff --git a/packages/core/core-flows/src/order/workflows/exchange/begin-order-exchange.ts b/packages/core/core-flows/src/order/workflows/exchange/begin-order-exchange.ts index 9d03ceb3177d4..08c3afdc5ccd8 100644 --- a/packages/core/core-flows/src/order/workflows/exchange/begin-order-exchange.ts +++ b/packages/core/core-flows/src/order/workflows/exchange/begin-order-exchange.ts @@ -58,7 +58,7 @@ export const beginExchangeOrderWorkflow = createWorkflow( return { change_type: "exchange" as const, order_id: input.order_id, - exchange_id: created[0].id, + exchange: created[0].id, created_by: input.created_by, description: input.description, internal_note: input.internal_note, diff --git a/packages/core/core-flows/src/order/workflows/exchange/exchange-request-item-return.ts b/packages/core/core-flows/src/order/workflows/exchange/exchange-request-item-return.ts index ffbd0d4ec6f28..1a830e2532e07 100644 --- a/packages/core/core-flows/src/order/workflows/exchange/exchange-request-item-return.ts +++ b/packages/core/core-flows/src/order/workflows/exchange/exchange-request-item-return.ts @@ -65,7 +65,7 @@ export const orderExchangeRequestItemReturnWorkflow = createWorkflow( ): WorkflowResponse { const orderExchange = useRemoteQueryStep({ entry_point: "order_exchange", - fields: ["id", "order_id", "return", "return_id", "canceled_at"], + fields: ["id", "order_id", "return_id", "canceled_at"], variables: { id: input.exchange_id }, list: false, throw_if_key_not_found: true, @@ -131,8 +131,8 @@ export const orderExchangeRequestItemReturnWorkflow = createWorkflow( updateOrderChangesStep([ { id: orderChange.id, - return_id: createdReturn?.[0]?.id, - }, + return: createdReturn?.[0]?.id, + } as any, ]) }) diff --git a/packages/core/core-flows/src/order/workflows/return/begin-return.ts b/packages/core/core-flows/src/order/workflows/return/begin-return.ts index d31c8e98bfa6c..54ad75ca086ad 100644 --- a/packages/core/core-flows/src/order/workflows/return/begin-return.ts +++ b/packages/core/core-flows/src/order/workflows/return/begin-return.ts @@ -58,7 +58,7 @@ export const beginReturnOrderWorkflow = createWorkflow( return { change_type: "return_request" as const, order_id: input.order_id, - return_id: created[0].id, + return: created[0].id, created_by: input.created_by, description: input.description, internal_note: input.internal_note, diff --git a/packages/medusa/src/api/admin/claims/[id]/inbound/items/[action_id]/route.ts b/packages/medusa/src/api/admin/claims/[id]/inbound/items/[action_id]/route.ts index d5f716b04bbec..b5e07bfd97b4b 100644 --- a/packages/medusa/src/api/admin/claims/[id]/inbound/items/[action_id]/route.ts +++ b/packages/medusa/src/api/admin/claims/[id]/inbound/items/[action_id]/route.ts @@ -2,18 +2,18 @@ import { removeItemReturnActionWorkflow, updateRequestItemReturnWorkflow, } from "@medusajs/core-flows" -import { - ContainerRegistrationKeys, - remoteQueryObjectFromString, -} from "@medusajs/framework/utils" import { AuthenticatedMedusaRequest, MedusaResponse, refetchEntity, } from "@medusajs/framework/http" +import { HttpTypes } from "@medusajs/framework/types" +import { + ContainerRegistrationKeys, + remoteQueryObjectFromString, +} from "@medusajs/framework/utils" import { defaultAdminDetailsReturnFields } from "../../../../../returns/query-config" import { AdminPostReturnsRequestItemsActionReqSchemaType } from "../../../../../returns/validators" -import { HttpTypes } from "@medusajs/framework/types" export const POST = async ( req: AuthenticatedMedusaRequest, @@ -29,7 +29,7 @@ export const POST = async ( variables: { id, }, - fields: ["return_id"], + fields: ["id", "return_id"], }), { throwIfKeyNotFound: true, @@ -67,7 +67,10 @@ export const DELETE = async ( ) => { const { id, action_id } = req.params - const claim = await refetchEntity("order_claim", id, req.scope, ["return_id"]) + const claim = await refetchEntity("order_claim", id, req.scope, [ + "id", + "return_id", + ]) const { result: orderPreview } = await removeItemReturnActionWorkflow( req.scope diff --git a/packages/medusa/src/api/admin/claims/[id]/inbound/items/route.ts b/packages/medusa/src/api/admin/claims/[id]/inbound/items/route.ts index 699ad421f907e..6a2bd13973aae 100644 --- a/packages/medusa/src/api/admin/claims/[id]/inbound/items/route.ts +++ b/packages/medusa/src/api/admin/claims/[id]/inbound/items/route.ts @@ -26,7 +26,7 @@ export const POST = async ( variables: { id, }, - fields: ["return", "return_id"], + fields: ["id", "return_id"], }), { throwIfKeyNotFound: true, diff --git a/packages/medusa/src/api/admin/claims/[id]/inbound/shipping-method/[action_id]/route.ts b/packages/medusa/src/api/admin/claims/[id]/inbound/shipping-method/[action_id]/route.ts index ee2bc56a4cfee..6c9a7a477cf19 100644 --- a/packages/medusa/src/api/admin/claims/[id]/inbound/shipping-method/[action_id]/route.ts +++ b/packages/medusa/src/api/admin/claims/[id]/inbound/shipping-method/[action_id]/route.ts @@ -2,17 +2,17 @@ import { removeClaimShippingMethodWorkflow, updateReturnShippingMethodWorkflow, } from "@medusajs/core-flows" -import { - ContainerRegistrationKeys, - remoteQueryObjectFromString, -} from "@medusajs/framework/utils" import { AuthenticatedMedusaRequest, MedusaResponse, } from "@medusajs/framework/http" +import { HttpTypes } from "@medusajs/framework/types" +import { + ContainerRegistrationKeys, + remoteQueryObjectFromString, +} from "@medusajs/framework/utils" import { defaultAdminDetailsReturnFields } from "../../../../../returns/query-config" import { AdminPostClaimsShippingActionReqSchemaType } from "../../../../validators" -import { HttpTypes } from "@medusajs/framework/types" export const POST = async ( req: AuthenticatedMedusaRequest, @@ -28,7 +28,7 @@ export const POST = async ( variables: { id, }, - fields: ["return_id"], + fields: ["id", "return_id"], }), { throwIfKeyNotFound: true, diff --git a/packages/medusa/src/api/admin/claims/[id]/inbound/shipping-method/route.ts b/packages/medusa/src/api/admin/claims/[id]/inbound/shipping-method/route.ts index 1f1f8344c9684..1ff686a3f80a4 100644 --- a/packages/medusa/src/api/admin/claims/[id]/inbound/shipping-method/route.ts +++ b/packages/medusa/src/api/admin/claims/[id]/inbound/shipping-method/route.ts @@ -8,9 +8,9 @@ import { AuthenticatedMedusaRequest, MedusaResponse, } from "@medusajs/framework/http" +import { HttpTypes } from "@medusajs/framework/types" import { defaultAdminDetailsReturnFields } from "../../../../returns/query-config" import { AdminPostReturnsShippingReqSchemaType } from "../../../../returns/validators" -import { HttpTypes } from "@medusajs/framework/types" export const POST = async ( req: AuthenticatedMedusaRequest, @@ -26,7 +26,7 @@ export const POST = async ( variables: { id, }, - fields: ["return_id"], + fields: ["id", "return_id"], }), { throwIfKeyNotFound: true, diff --git a/packages/modules/order/src/models/return.ts b/packages/modules/order/src/models/return.ts index 4bf931ef5ebe4..75f0482f83eaf 100644 --- a/packages/modules/order/src/models/return.ts +++ b/packages/modules/order/src/models/return.ts @@ -22,7 +22,6 @@ const _Return = model canceled_at: model.dateTime().nullable(), order: model.belongsTo<() => typeof Order>(() => Order, { mappedBy: "returns", - // foreignKey: true, }), exchange: model .belongsTo<() => typeof OrderExchange>(() => OrderExchange, { From 5dd6b5343845735b532bac26c1ff28683cceaa8c Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Wed, 8 Jan 2025 14:41:33 -0300 Subject: [PATCH 164/175] core flows --- .../__tests__/exchanges/exchanges.spec.ts | 4 +- .../order/steps/claim/update-order-claims.ts | 4 +- .../steps/exchange/update-order-exchanges.ts | 4 +- .../core/core-flows/src/order/steps/index.ts | 5 +- .../src/order/steps/update-order-exchanges.ts | 57 ------------------- .../workflows/claim/begin-order-claim.ts | 2 +- .../claim/claim-request-item-return.ts | 25 ++++---- .../workflows/claim/confirm-claim-request.ts | 2 + .../exchange/begin-order-exchange.ts | 2 +- .../exchange/exchange-request-item-return.ts | 12 +--- .../order/workflows/return/begin-return.ts | 2 +- .../return/remove-item-return-action.ts | 12 +++- packages/core/types/src/order/common.ts | 15 +++++ packages/core/types/src/order/mutations.ts | 4 +- .../src/dal/mikro-orm/big-number-field.ts | 22 ++++--- .../admin/claims/[id]/inbound/items/route.ts | 3 +- .../[id]/inbound/shipping-method/route.ts | 3 +- .../[id]/inbound/items/[action_id]/route.ts | 12 ++-- .../exchanges/[id]/inbound/items/route.ts | 7 ++- .../shipping-method/[action_id]/route.ts | 14 ++--- .../[id]/inbound/shipping-method/route.ts | 7 ++- packages/modules/order/src/models/claim.ts | 2 +- packages/modules/order/src/models/exchange.ts | 5 +- .../modules/order/src/models/line-item.ts | 2 +- .../order/src/models/order-change-action.ts | 30 ++-------- .../modules/order/src/models/order-change.ts | 24 +------- packages/modules/order/src/models/return.ts | 10 ++-- .../src/services/actions/create-claim.ts | 4 +- .../src/services/order-module-service.ts | 23 ++------ .../order/src/utils/base-repository-find.ts | 53 ++++++++++++----- 30 files changed, 156 insertions(+), 215 deletions(-) delete mode 100644 packages/core/core-flows/src/order/steps/update-order-exchanges.ts diff --git a/integration-tests/http/__tests__/exchanges/exchanges.spec.ts b/integration-tests/http/__tests__/exchanges/exchanges.spec.ts index 0dd8cd4b07183..50ab7f65d9892 100644 --- a/integration-tests/http/__tests__/exchanges/exchanges.spec.ts +++ b/integration-tests/http/__tests__/exchanges/exchanges.spec.ts @@ -1,16 +1,16 @@ +import { medusaIntegrationTestRunner } from "@medusajs/test-utils" import { ContainerRegistrationKeys, Modules, RuleOperator, } from "@medusajs/utils" -import { medusaIntegrationTestRunner } from "@medusajs/test-utils" import { adminHeaders, createAdminUser, } from "../../../helpers/create-admin-user" import { setupTaxStructure } from "../../../modules/__tests__/fixtures/tax" -jest.setTimeout(30000) +jest.setTimeout(300000) medusaIntegrationTestRunner({ testSuite: ({ dbConnection, getContainer, api }) => { diff --git a/packages/core/core-flows/src/order/steps/claim/update-order-claims.ts b/packages/core/core-flows/src/order/steps/claim/update-order-claims.ts index 7ff933d2687b5..7775c8e1e3dcc 100644 --- a/packages/core/core-flows/src/order/steps/claim/update-order-claims.ts +++ b/packages/core/core-flows/src/order/steps/claim/update-order-claims.ts @@ -20,10 +20,10 @@ export const updateOrderClaimsStep = createStep( const { selects, relations } = getSelectsAndRelationsFromObjectArray(data, { objectFields: ["metadata"], }) - const dataBeforeUpdate = await service.listOrderClaims( + const dataBeforeUpdate = (await service.listOrderClaims( { id: data.map((d) => d.id) }, { relations, select: selects } - ) + )) as UpdateOrderClaimDTO[] const updated = await service.updateOrderClaims( data.map((dt) => { diff --git a/packages/core/core-flows/src/order/steps/exchange/update-order-exchanges.ts b/packages/core/core-flows/src/order/steps/exchange/update-order-exchanges.ts index 8d48d6f7dc0ad..27cea3d0787de 100644 --- a/packages/core/core-flows/src/order/steps/exchange/update-order-exchanges.ts +++ b/packages/core/core-flows/src/order/steps/exchange/update-order-exchanges.ts @@ -20,10 +20,10 @@ export const updateOrderExchangesStep = createStep( const { selects, relations } = getSelectsAndRelationsFromObjectArray(data, { objectFields: ["metadata"], }) - const dataBeforeUpdate = await service.listOrderExchanges( + const dataBeforeUpdate = (await service.listOrderExchanges( { id: data.map((d) => d.id) }, { relations, select: selects } - ) + )) as UpdateOrderExchangeDTO[] const updated = await service.updateOrderExchanges( data.map((dt) => { diff --git a/packages/core/core-flows/src/order/steps/index.ts b/packages/core/core-flows/src/order/steps/index.ts index f7b049b02bae4..bb5a1206be3cd 100644 --- a/packages/core/core-flows/src/order/steps/index.ts +++ b/packages/core/core-flows/src/order/steps/index.ts @@ -22,6 +22,7 @@ export * from "./exchange/create-exchange-items-from-actions" export * from "./exchange/delete-exchanges" export * from "./preview-order-change" export * from "./register-fulfillment" +export * from "./register-order-changes" export * from "./register-shipment" export * from "./return/cancel-return" export * from "./return/create-complete-return" @@ -32,7 +33,5 @@ export * from "./return/update-returns" export * from "./set-tax-lines-for-items" export * from "./update-order-change-actions" export * from "./update-order-changes" -export * from "./update-order-exchanges" -export * from "./update-shipping-methods" export * from "./update-orders" -export * from "./register-order-changes" +export * from "./update-shipping-methods" diff --git a/packages/core/core-flows/src/order/steps/update-order-exchanges.ts b/packages/core/core-flows/src/order/steps/update-order-exchanges.ts deleted file mode 100644 index 9887c327d327d..0000000000000 --- a/packages/core/core-flows/src/order/steps/update-order-exchanges.ts +++ /dev/null @@ -1,57 +0,0 @@ -import { - IOrderModuleService, - UpdateOrderExchangeDTO, -} from "@medusajs/framework/types" -import { - Modules, - getSelectsAndRelationsFromObjectArray, -} from "@medusajs/framework/utils" -import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk" - -export const updateOrderExchangesStepId = "update-order-exchange" -/** - * This step update order changes. - */ -export const updateOrderExchangesStep = createStep( - updateOrderExchangesStepId, - async (data: UpdateOrderExchangeDTO[], { container }) => { - const service = container.resolve(Modules.ORDER) - - const { selects, relations } = getSelectsAndRelationsFromObjectArray(data, { - objectFields: ["metadata"], - }) - const dataBeforeUpdate = await service.listOrderExchanges( - { id: data.map((d) => d.id) }, - { relations, select: selects } - ) - - const updated = await service.updateOrderExchanges( - data.map((dt) => { - const { id, ...rest } = dt - return { - selector: { id }, - data: rest, - } - }) - ) - - return new StepResponse(updated, dataBeforeUpdate) - }, - async (dataBeforeUpdate, { container }) => { - if (!dataBeforeUpdate?.length) { - return - } - - const service = container.resolve(Modules.ORDER) - - await service.updateOrderExchanges( - dataBeforeUpdate.map((dt) => { - const { id, ...rest } = dt - return { - selector: { id }, - data: rest, - } - }) - ) - } -) diff --git a/packages/core/core-flows/src/order/workflows/claim/begin-order-claim.ts b/packages/core/core-flows/src/order/workflows/claim/begin-order-claim.ts index d90c2c1df9e88..ba43b77489438 100644 --- a/packages/core/core-flows/src/order/workflows/claim/begin-order-claim.ts +++ b/packages/core/core-flows/src/order/workflows/claim/begin-order-claim.ts @@ -59,7 +59,7 @@ export const beginClaimOrderWorkflow = createWorkflow( return { change_type: "claim" as const, order_id: input.order_id, - claim: created[0].id, + claim_id: created[0].id, created_by: input.created_by, description: input.description, internal_note: input.internal_note, diff --git a/packages/core/core-flows/src/order/workflows/claim/claim-request-item-return.ts b/packages/core/core-flows/src/order/workflows/claim/claim-request-item-return.ts index 8d2468a61a703..de775630744bb 100644 --- a/packages/core/core-flows/src/order/workflows/claim/claim-request-item-return.ts +++ b/packages/core/core-flows/src/order/workflows/claim/claim-request-item-return.ts @@ -94,8 +94,8 @@ export const orderClaimRequestItemReturnWorkflow = createWorkflow( }) const orderReturn: ReturnDTO = transform( - { createdReturn, existingOrderReturn }, - ({ createdReturn, existingOrderReturn }) => { + { createdReturn, existingOrderReturn, orderClaim }, + ({ createdReturn, existingOrderReturn, orderClaim }) => { return existingOrderReturn ?? (createdReturn?.[0] as ReturnDTO) } ) @@ -123,14 +123,17 @@ export const orderClaimRequestItemReturnWorkflow = createWorkflow( name: "order-change-query", }) - when({ createdReturn }, ({ createdReturn }) => { - return !!createdReturn?.length - }).then(() => { + when( + { createdReturn, orderClaim, orderChange }, + ({ createdReturn, orderClaim, orderChange }) => { + return !!createdReturn?.length + } + ).then(() => { updateOrderChangesStep([ { id: orderChange.id, - return: orderReturn.id, - } as any, + return_id: createdReturn?.[0]?.id, + }, ]) }) @@ -145,16 +148,10 @@ export const orderClaimRequestItemReturnWorkflow = createWorkflow( when({ orderClaim }, ({ orderClaim }) => { return !orderClaim.return_id }).then(() => { - const createdReturnId = transform( - { createdReturn }, - ({ createdReturn }) => { - return createdReturn?.[0]!.id - } - ) updateOrderClaimsStep([ { id: orderClaim.id, - return_id: createdReturnId, + return: createdReturn?.[0]!.id, }, ]) }) diff --git a/packages/core/core-flows/src/order/workflows/claim/confirm-claim-request.ts b/packages/core/core-flows/src/order/workflows/claim/confirm-claim-request.ts index 6f8a2999780e6..34307c62429af 100644 --- a/packages/core/core-flows/src/order/workflows/claim/confirm-claim-request.ts +++ b/packages/core/core-flows/src/order/workflows/claim/confirm-claim-request.ts @@ -264,6 +264,8 @@ export const confirmClaimRequestWorkflow = createWorkflow( fields: [ "id", "status", + "claim_id", + "return_id", "actions.id", "actions.claim_id", "actions.return_id", diff --git a/packages/core/core-flows/src/order/workflows/exchange/begin-order-exchange.ts b/packages/core/core-flows/src/order/workflows/exchange/begin-order-exchange.ts index 08c3afdc5ccd8..9d03ceb3177d4 100644 --- a/packages/core/core-flows/src/order/workflows/exchange/begin-order-exchange.ts +++ b/packages/core/core-flows/src/order/workflows/exchange/begin-order-exchange.ts @@ -58,7 +58,7 @@ export const beginExchangeOrderWorkflow = createWorkflow( return { change_type: "exchange" as const, order_id: input.order_id, - exchange: created[0].id, + exchange_id: created[0].id, created_by: input.created_by, description: input.description, internal_note: input.internal_note, diff --git a/packages/core/core-flows/src/order/workflows/exchange/exchange-request-item-return.ts b/packages/core/core-flows/src/order/workflows/exchange/exchange-request-item-return.ts index 1a830e2532e07..e2c34add0e4a4 100644 --- a/packages/core/core-flows/src/order/workflows/exchange/exchange-request-item-return.ts +++ b/packages/core/core-flows/src/order/workflows/exchange/exchange-request-item-return.ts @@ -131,8 +131,8 @@ export const orderExchangeRequestItemReturnWorkflow = createWorkflow( updateOrderChangesStep([ { id: orderChange.id, - return: createdReturn?.[0]?.id, - } as any, + return_id: createdReturn?.[0]?.id, + }, ]) }) @@ -147,16 +147,10 @@ export const orderExchangeRequestItemReturnWorkflow = createWorkflow( when({ orderExchange }, ({ orderExchange }) => { return !orderExchange.return_id }).then(() => { - const createdReturnId = transform( - { createdReturn }, - ({ createdReturn }) => { - return createdReturn?.[0]!.id - } - ) updateOrderExchangesStep([ { id: orderExchange.id, - return_id: createdReturnId, + return: createdReturn?.[0]!.id, }, ]) }) diff --git a/packages/core/core-flows/src/order/workflows/return/begin-return.ts b/packages/core/core-flows/src/order/workflows/return/begin-return.ts index 54ad75ca086ad..d31c8e98bfa6c 100644 --- a/packages/core/core-flows/src/order/workflows/return/begin-return.ts +++ b/packages/core/core-flows/src/order/workflows/return/begin-return.ts @@ -58,7 +58,7 @@ export const beginReturnOrderWorkflow = createWorkflow( return { change_type: "return_request" as const, order_id: input.order_id, - return: created[0].id, + return_id: created[0].id, created_by: input.created_by, description: input.description, internal_note: input.internal_note, diff --git a/packages/core/core-flows/src/order/workflows/return/remove-item-return-action.ts b/packages/core/core-flows/src/order/workflows/return/remove-item-return-action.ts index 0ffb7bff3400a..4569b59113aa8 100644 --- a/packages/core/core-flows/src/order/workflows/return/remove-item-return-action.ts +++ b/packages/core/core-flows/src/order/workflows/return/remove-item-return-action.ts @@ -122,7 +122,17 @@ export const removeItemReturnActionWorkflow = createWorkflow( const updatedOrderChange: OrderChangeDTO = useRemoteQueryStep({ entry_point: "order_change", - fields: ["actions.action", "actions.return_id", "actions.id"], + fields: [ + "actions.id", + "actions.action", + "actions.order_id", + "actions.return_id", + "actions.claim_id", + "actions.exchange_id", + "actions.reference", + "actions.reference_id", + "actions.order_change_id", + ], variables: { filters: { order_id: orderReturn.order_id, diff --git a/packages/core/types/src/order/common.ts b/packages/core/types/src/order/common.ts index 4d0403b751a9d..d0801d54b3477 100644 --- a/packages/core/types/src/order/common.ts +++ b/packages/core/types/src/order/common.ts @@ -2715,6 +2715,21 @@ export interface FilterableOrderChangeProps */ order_id?: string | string[] | OperatorMap + /** + * Filter the changes by their associated return's ID. + */ + return_id?: string | string[] | OperatorMap + + /** + * Filter the changes by their associated claim's ID. + */ + claim_id?: string | string[] | OperatorMap + + /** + * Filter the changes by their associated exchange's ID. + */ + exchange_id?: string | string[] | OperatorMap + /** * Filter the order changes by their status. */ diff --git a/packages/core/types/src/order/mutations.ts b/packages/core/types/src/order/mutations.ts index f8c6b6bd2ab90..7aed69f09b436 100644 --- a/packages/core/types/src/order/mutations.ts +++ b/packages/core/types/src/order/mutations.ts @@ -1737,7 +1737,7 @@ export interface UpdateOrderClaimDTO { * The associated return's ID, if the * claim's {@link type} is `replace`. */ - return_id?: string + return?: string /** * The type of the claim. @@ -1777,7 +1777,7 @@ export interface UpdateOrderExchangeDTO { /** * The associated return's ID. */ - return_id?: string + return?: string /** * Whether backorders are allowed on the exchange's items. diff --git a/packages/core/utils/src/dal/mikro-orm/big-number-field.ts b/packages/core/utils/src/dal/mikro-orm/big-number-field.ts index 3a8c7cb7c9d96..e3012fbcdec77 100644 --- a/packages/core/utils/src/dal/mikro-orm/big-number-field.ts +++ b/packages/core/utils/src/dal/mikro-orm/big-number-field.ts @@ -31,15 +31,19 @@ export function MikroOrmBigNumberProperty( } else { let bigNumber: BigNumber - if (value instanceof BigNumber) { - bigNumber = value - } else if (this[rawColumnName]) { - const precision = this[rawColumnName].precision - bigNumber = new BigNumber(value, { - precision, - }) - } else { - bigNumber = new BigNumber(value) + try { + if (value instanceof BigNumber) { + bigNumber = value + } else if (this[rawColumnName]) { + const precision = this[rawColumnName].precision + bigNumber = new BigNumber(value, { + precision, + }) + } else { + bigNumber = new BigNumber(value) + } + } catch (e) { + throw new Error(`Cannot set value ${value} for ${columnName}.`) } const raw = bigNumber.raw! diff --git a/packages/medusa/src/api/admin/claims/[id]/inbound/items/route.ts b/packages/medusa/src/api/admin/claims/[id]/inbound/items/route.ts index 6a2bd13973aae..eeb30607ae188 100644 --- a/packages/medusa/src/api/admin/claims/[id]/inbound/items/route.ts +++ b/packages/medusa/src/api/admin/claims/[id]/inbound/items/route.ts @@ -41,10 +41,11 @@ export const POST = async ( }, }) + const returnId = result.order_change.return_id const queryObject = remoteQueryObjectFromString({ entryPoint: "return", variables: { - id: claim.return_id, + id: returnId, }, fields: defaultAdminDetailsReturnFields, }) diff --git a/packages/medusa/src/api/admin/claims/[id]/inbound/shipping-method/route.ts b/packages/medusa/src/api/admin/claims/[id]/inbound/shipping-method/route.ts index 1ff686a3f80a4..21bda50691803 100644 --- a/packages/medusa/src/api/admin/claims/[id]/inbound/shipping-method/route.ts +++ b/packages/medusa/src/api/admin/claims/[id]/inbound/shipping-method/route.ts @@ -41,10 +41,11 @@ export const POST = async ( }, }) + const returnId = result.order_change.return_id const queryObject = remoteQueryObjectFromString({ entryPoint: "return", variables: { - id: claim.return_id, + id: returnId, }, fields: defaultAdminDetailsReturnFields, }) diff --git a/packages/medusa/src/api/admin/exchanges/[id]/inbound/items/[action_id]/route.ts b/packages/medusa/src/api/admin/exchanges/[id]/inbound/items/[action_id]/route.ts index 9e43aeeaaca6f..b0d7405a32da3 100644 --- a/packages/medusa/src/api/admin/exchanges/[id]/inbound/items/[action_id]/route.ts +++ b/packages/medusa/src/api/admin/exchanges/[id]/inbound/items/[action_id]/route.ts @@ -2,16 +2,16 @@ import { removeItemReturnActionWorkflow, updateRequestItemReturnWorkflow, } from "@medusajs/core-flows" -import { HttpTypes } from "@medusajs/framework/types" -import { - ContainerRegistrationKeys, - remoteQueryObjectFromString, -} from "@medusajs/framework/utils" import { AuthenticatedMedusaRequest, MedusaResponse, refetchEntity, } from "@medusajs/framework/http" +import { HttpTypes } from "@medusajs/framework/types" +import { + ContainerRegistrationKeys, + remoteQueryObjectFromString, +} from "@medusajs/framework/utils" import { defaultAdminDetailsReturnFields } from "../../../../../returns/query-config" import { AdminPostExchangesRequestItemsReturnActionReqSchemaType } from "../../../../validators" @@ -29,7 +29,7 @@ export const POST = async ( variables: { id, }, - fields: ["return_id"], + fields: ["id", "return_id"], }), { throwIfKeyNotFound: true, diff --git a/packages/medusa/src/api/admin/exchanges/[id]/inbound/items/route.ts b/packages/medusa/src/api/admin/exchanges/[id]/inbound/items/route.ts index d3cc37326bc86..75183a213372d 100644 --- a/packages/medusa/src/api/admin/exchanges/[id]/inbound/items/route.ts +++ b/packages/medusa/src/api/admin/exchanges/[id]/inbound/items/route.ts @@ -8,9 +8,9 @@ import { AuthenticatedMedusaRequest, MedusaResponse, } from "@medusajs/framework/http" +import { HttpTypes } from "@medusajs/framework/types" import { defaultAdminDetailsReturnFields } from "../../../../returns/query-config" import { AdminPostExchangesReturnRequestItemsReqSchemaType } from "../../../validators" -import { HttpTypes } from "@medusajs/framework/types" export const POST = async ( req: AuthenticatedMedusaRequest, @@ -26,7 +26,7 @@ export const POST = async ( variables: { id, }, - fields: ["return_id"], + fields: ["id", "return_id"], }), { throwIfKeyNotFound: true, @@ -43,10 +43,11 @@ export const POST = async ( }, }) + const returnId = result.order_change.return_id const queryObject = remoteQueryObjectFromString({ entryPoint: "return", variables: { - id: exchange.return_id, + id: returnId, }, fields: defaultAdminDetailsReturnFields, }) diff --git a/packages/medusa/src/api/admin/exchanges/[id]/inbound/shipping-method/[action_id]/route.ts b/packages/medusa/src/api/admin/exchanges/[id]/inbound/shipping-method/[action_id]/route.ts index dd80ae96d8fe0..ba8141928c592 100644 --- a/packages/medusa/src/api/admin/exchanges/[id]/inbound/shipping-method/[action_id]/route.ts +++ b/packages/medusa/src/api/admin/exchanges/[id]/inbound/shipping-method/[action_id]/route.ts @@ -2,17 +2,17 @@ import { removeReturnShippingMethodWorkflow, updateReturnShippingMethodWorkflow, } from "@medusajs/core-flows" -import { - ContainerRegistrationKeys, - remoteQueryObjectFromString, -} from "@medusajs/framework/utils" import { AuthenticatedMedusaRequest, MedusaResponse, } from "@medusajs/framework/http" +import { AdminOrderPreview, HttpTypes } from "@medusajs/framework/types" +import { + ContainerRegistrationKeys, + remoteQueryObjectFromString, +} from "@medusajs/framework/utils" import { defaultAdminDetailsReturnFields } from "../../../../../returns/query-config" import { AdminPostExchangesShippingActionReqSchemaType } from "../../../../validators" -import { AdminOrderPreview, HttpTypes } from "@medusajs/framework/types" export const POST = async ( req: AuthenticatedMedusaRequest, @@ -28,7 +28,7 @@ export const POST = async ( variables: { id, }, - fields: ["return_id"], + fields: ["id", "return_id"], }), { throwIfKeyNotFound: true, @@ -76,7 +76,7 @@ export const DELETE = async ( variables: { id, }, - fields: ["return_id"], + fields: ["id", "return_id"], }), { throwIfKeyNotFound: true, diff --git a/packages/medusa/src/api/admin/exchanges/[id]/inbound/shipping-method/route.ts b/packages/medusa/src/api/admin/exchanges/[id]/inbound/shipping-method/route.ts index 77ed17423b69c..9b23b23506fc9 100644 --- a/packages/medusa/src/api/admin/exchanges/[id]/inbound/shipping-method/route.ts +++ b/packages/medusa/src/api/admin/exchanges/[id]/inbound/shipping-method/route.ts @@ -8,9 +8,9 @@ import { AuthenticatedMedusaRequest, MedusaResponse, } from "@medusajs/framework/http" +import { HttpTypes } from "@medusajs/framework/types" import { defaultAdminDetailsReturnFields } from "../../../../returns/query-config" import { AdminPostReturnsShippingReqSchemaType } from "../../../../returns/validators" -import { HttpTypes } from "@medusajs/framework/types" export const POST = async ( req: AuthenticatedMedusaRequest, @@ -26,7 +26,7 @@ export const POST = async ( variables: { id, }, - fields: ["return_id"], + fields: ["id", "return_id"], }), { throwIfKeyNotFound: true, @@ -41,10 +41,11 @@ export const POST = async ( }, }) + const returnId = result.order_change.return_id const queryObject = remoteQueryObjectFromString({ entryPoint: "return", variables: { - id: exchange.return_id, + id: returnId, }, fields: defaultAdminDetailsReturnFields, }) diff --git a/packages/modules/order/src/models/claim.ts b/packages/modules/order/src/models/claim.ts index 527314eeb26a4..8d0552ca0806f 100644 --- a/packages/modules/order/src/models/claim.ts +++ b/packages/modules/order/src/models/claim.ts @@ -22,7 +22,7 @@ const _OrderClaim = model }), return: model .hasOne<() => typeof Return>(() => Return, { - mappedBy: "claim", + mappedBy: undefined, foreignKey: true, }) .nullable(), diff --git a/packages/modules/order/src/models/exchange.ts b/packages/modules/order/src/models/exchange.ts index 75db671a0692e..deadbd439baea 100644 --- a/packages/modules/order/src/models/exchange.ts +++ b/packages/modules/order/src/models/exchange.ts @@ -1,5 +1,4 @@ import { model } from "@medusajs/framework/utils" - import { OrderExchangeItem } from "./exchange-item" import { Order } from "./order" import { OrderShipping } from "./order-shipping-method" @@ -23,7 +22,7 @@ const _OrderExchange = model }), return: model .hasOne<() => typeof Return>(() => Return, { - mappedBy: "exchange", + mappedBy: undefined, foreignKey: true, }) .nullable(), @@ -47,7 +46,7 @@ const _OrderExchange = model ), }) .cascades({ - delete: ["additional_items", "shipping_methods", "transactions"], + delete: ["additional_items", "transactions"], }) .indexes([ { diff --git a/packages/modules/order/src/models/line-item.ts b/packages/modules/order/src/models/line-item.ts index fab2d0842ee57..b1ac33bd25bf6 100644 --- a/packages/modules/order/src/models/line-item.ts +++ b/packages/modules/order/src/models/line-item.ts @@ -25,7 +25,7 @@ const _OrderLineItem = model is_discountable: model.boolean().default(true), is_tax_inclusive: model.boolean().default(false), compare_at_unit_price: model.bigNumber().nullable(), - unit_price: model.bigNumber(), + unit_price: model.bigNumber().nullable(), is_custom_price: model.boolean().default(false), metadata: model.json().nullable(), tax_lines: model.hasMany<() => typeof OrderLineItemTaxLine>( diff --git a/packages/modules/order/src/models/order-change-action.ts b/packages/modules/order/src/models/order-change-action.ts index 34cb83b73a699..95ad863441b55 100644 --- a/packages/modules/order/src/models/order-change-action.ts +++ b/packages/modules/order/src/models/order-change-action.ts @@ -1,14 +1,14 @@ import { model } from "@medusajs/framework/utils" -import { OrderClaim } from "./claim" -import { OrderExchange } from "./exchange" -import { Order } from "./order" import { OrderChange } from "./order-change" -import { Return } from "./return" const _OrderChangeAction = model .define("OrderChangeAction", { id: model.id({ prefix: "ordchact" }).primaryKey(), + order_id: model.text(), + return_id: model.text().nullable(), + claim_id: model.text().nullable(), + exchange_id: model.text().nullable(), ordering: model.autoincrement(), version: model.number().nullable(), reference: model.text().nullable(), @@ -18,28 +18,6 @@ const _OrderChangeAction = model amount: model.bigNumber().nullable(), internal_note: model.text().nullable(), applied: model.boolean().default(false), - order: model.hasOne<() => typeof OrderChange>(() => Order, { - mappedBy: undefined, - foreignKey: true, - }), - return: model - .hasOne<() => typeof Return>(() => Return, { - mappedBy: undefined, - foreignKey: true, - }) - .nullable(), - claim: model - .hasOne<() => typeof OrderClaim>(() => OrderClaim, { - mappedBy: undefined, - foreignKey: true, - }) - .nullable(), - exchange: model - .hasOne<() => typeof OrderExchange>(() => OrderExchange, { - mappedBy: undefined, - foreignKey: true, - }) - .nullable(), order_change: model .belongsTo<() => typeof OrderChange>(() => OrderChange, { mappedBy: "actions", diff --git a/packages/modules/order/src/models/order-change.ts b/packages/modules/order/src/models/order-change.ts index 910b747714161..f6d7683fe44ff 100644 --- a/packages/modules/order/src/models/order-change.ts +++ b/packages/modules/order/src/models/order-change.ts @@ -1,13 +1,13 @@ import { model, OrderChangeStatus } from "@medusajs/framework/utils" -import { OrderClaim } from "./claim" -import { OrderExchange } from "./exchange" import { Order } from "./order" import { OrderChangeAction } from "./order-change-action" -import { Return } from "./return" const _OrderChange = model .define("OrderChange", { id: model.id({ prefix: "ordch" }).primaryKey(), + return_id: model.text().nullable(), + claim_id: model.text().nullable(), + exchange_id: model.text().nullable(), version: model.number(), change_type: model.text().nullable(), description: model.text().nullable(), @@ -30,24 +30,6 @@ const _OrderChange = model order: model.belongsTo<() => typeof Order>(() => Order, { mappedBy: "changes", }), - return: model - .hasOne<() => typeof Return>(() => Return, { - mappedBy: undefined, - foreignKey: true, - }) - .nullable(), - claim: model - .hasOne<() => typeof OrderClaim>(() => OrderClaim, { - mappedBy: undefined, - foreignKey: true, - }) - .nullable(), - exchange: model - .hasOne<() => typeof OrderExchange>(() => OrderExchange, { - mappedBy: undefined, - foreignKey: true, - }) - .nullable(), actions: model.hasMany<() => typeof OrderChangeAction>( () => OrderChangeAction ), diff --git a/packages/modules/order/src/models/return.ts b/packages/modules/order/src/models/return.ts index 75f0482f83eaf..c09acf01de5d3 100644 --- a/packages/modules/order/src/models/return.ts +++ b/packages/modules/order/src/models/return.ts @@ -24,13 +24,15 @@ const _Return = model mappedBy: "returns", }), exchange: model - .belongsTo<() => typeof OrderExchange>(() => OrderExchange, { - mappedBy: "return", + .hasOne<() => typeof OrderExchange>(() => OrderExchange, { + mappedBy: undefined, + foreignKey: true, }) .nullable(), claim: model - .belongsTo<() => typeof OrderClaim>(() => OrderClaim, { - mappedBy: "return", + .hasOne<() => typeof OrderClaim>(() => OrderClaim, { + mappedBy: undefined, + foreignKey: true, }) .nullable(), items: model.hasMany<() => typeof ReturnItem>(() => ReturnItem, { diff --git a/packages/modules/order/src/services/actions/create-claim.ts b/packages/modules/order/src/services/actions/create-claim.ts index ef5272cca36a3..25a00e90e4e5c 100644 --- a/packages/modules/order/src/services/actions/create-claim.ts +++ b/packages/modules/order/src/services/actions/create-claim.ts @@ -30,12 +30,12 @@ function createClaimAndReturnEntities(em, data, order) { order_id: data.order_id, order_version: order.version, status: ReturnStatus.REQUESTED, - claim_id: claimReference.id, + claim: claimReference.id, refund_amount: (data.refund_amount as unknown) ?? null, }) : undefined - claimReference.return = returnReference + claimReference.return = returnReference?.id return { claimReference, returnReference } } diff --git a/packages/modules/order/src/services/order-module-service.ts b/packages/modules/order/src/services/order-module-service.ts index 4771e1104e74c..aa6cf1cdc13ec 100644 --- a/packages/modules/order/src/services/order-module-service.ts +++ b/packages/modules/order/src/services/order-module-service.ts @@ -144,23 +144,12 @@ const generateMethodForModels = { MikroORMEntity.prototype["onInit_OrderChangeAction"] = function () { this.version ??= this.order_change?.version ?? null - this.order ??= rel( - toMikroORMEntity(Order), - this.order_change?.order_id ?? null - ) - this.claim ??= rel( - toMikroORMEntity(OrderClaim), - this.order_change?.claim_id ?? null - ) - this.exchange ??= rel( - toMikroORMEntity(OrderExchange), - this.order_change?.exchange_id ?? null - ) + this.order_id ??= this.order_change?.order_id ?? null + this.claim_id ??= this.order_change?.claim_id ?? null + this.exchange_id ??= this.order_change?.exchange_id ?? null if (!this.claim_id && !this.exchange_id) { - const ret_id = this.return?.id ?? this.order_change?.return_id ?? null - - this.return = rel(toMikroORMEntity(Return), ret_id) + this.return_id = this.return?.id ?? this.order_change?.return_id ?? null } } OnInit()(MikroORMEntity.prototype, "onInit_OrderChangeAction") @@ -3522,7 +3511,7 @@ export default class OrderModuleService ): Promise { const ret = await this.createExchange_(data, sharedContext) - const claim = await this.retrieveOrderExchange( + const exchange = await this.retrieveOrderExchange( ret.id, { relations: [ @@ -3540,7 +3529,7 @@ export default class OrderModuleService ) return await this.baseRepository_.serialize( - claim, + exchange, { populate: true, } diff --git a/packages/modules/order/src/utils/base-repository-find.ts b/packages/modules/order/src/utils/base-repository-find.ts index 3d0b65a10108d..057ad7e2a247a 100644 --- a/packages/modules/order/src/utils/base-repository-find.ts +++ b/packages/modules/order/src/utils/base-repository-find.ts @@ -134,20 +134,19 @@ export function setFindMethods(klass: Constructor, entity: any) { let defaultVersion = knex.raw(`"${orderAlias}"."version"`) const strategy = config.options.strategy ?? LoadStrategy.JOINED if (strategy === LoadStrategy.SELECT_IN) { - const sql = manager - .qb(toMikroORMEntity(Order), "_sub0") - .select("version") - .where({ id: knex.raw(`"${orderAlias}"."order_id"`) }) - .getKnexQuery() - .toString() - - defaultVersion = knex.raw(`(${sql})`) + defaultVersion = getVersionSubQuery(manager, orderAlias) } const version = config.where.version ?? defaultVersion delete config.where.version - configurePopulateWhere(config, isRelatedEntity, version) + configurePopulateWhere( + config, + isRelatedEntity, + version, + strategy === LoadStrategy.SELECT_IN, + manager + ) if (!config.options.orderBy) { config.options.orderBy = { id: "ASC" } @@ -157,10 +156,24 @@ export function setFindMethods(klass: Constructor, entity: any) { } } +function getVersionSubQuery(manager, alias, field = "order_id") { + const knex = manager.getKnex() + const sql = manager + .qb(toMikroORMEntity(Order), "_sub0") + .select("version") + .where({ id: knex.raw(`"${alias}"."${field}"`) }) + .getKnexQuery() + .toString() + + return knex.raw(`(${sql})`) +} + function configurePopulateWhere( config: any, isRelatedEntity: boolean, - version: any + version: any, + isSelectIn = false, + manager? ) { const requestedPopulate = config.options?.populate ?? [] const hasRelation = (relation: string) => @@ -173,11 +186,15 @@ function configurePopulateWhere( if (isRelatedEntity) { popWhere.order ??= {} - popWhere.order.version = version + popWhere.order.version = isSelectIn + ? getVersionSubQuery(manager, "o0", "id") + : version if (hasRelation("shipping_methods")) { popWhere.shipping_methods ??= {} - popWhere.shipping_methods.version = version + popWhere.shipping_methods.version = isSelectIn + ? getVersionSubQuery(manager, "s0") + : version } } @@ -185,16 +202,22 @@ function configurePopulateWhere( if (hasRelation("summary")) { orderWhere.summary ??= {} - orderWhere.summary.version = version + orderWhere.summary.version = isSelectIn + ? getVersionSubQuery(manager, "s0") + : version } if (hasRelation("items") || hasRelation("order.items")) { orderWhere.items ??= {} - orderWhere.items.version = version + orderWhere.items.version = isSelectIn + ? getVersionSubQuery(manager, "i0") + : version } if (hasRelation("shipping_methods")) { orderWhere.shipping_methods ??= {} - orderWhere.shipping_methods.version = version + orderWhere.shipping_methods.version = isSelectIn + ? getVersionSubQuery(manager, "s0") + : version } } From c73ebbfb9a87f51960c8ac93fb369e53d61c0dfb Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Wed, 8 Jan 2025 15:06:39 -0300 Subject: [PATCH 165/175] unit test --- .../src/dal/mikro-orm/__tests__/big-number-field.spec.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/core/utils/src/dal/mikro-orm/__tests__/big-number-field.spec.ts b/packages/core/utils/src/dal/mikro-orm/__tests__/big-number-field.spec.ts index 13420c3e14534..a2e49231e2e4a 100644 --- a/packages/core/utils/src/dal/mikro-orm/__tests__/big-number-field.spec.ts +++ b/packages/core/utils/src/dal/mikro-orm/__tests__/big-number-field.spec.ts @@ -56,9 +56,7 @@ describe("@MikroOrmBigNumberProperty", () => { try { ;(testAmount as any).amount = null } catch (e) { - expect(e.message).toEqual( - "Invalid BigNumber value: null. Should be one of: string, number, BigNumber (bignumber.js), BigNumberRawValue" - ) + expect(e.message).toEqual("Cannot set value null for amount.") } testAmount.nullable_amount = null From 824dfdba5d717fc21bc4d52b6237165cdc8f780e Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Wed, 8 Jan 2025 21:20:05 -0300 Subject: [PATCH 166/175] test --- .../order/workflows/create-fulfillment.spec.ts | 3 +-- .../order/workflows/cancel-order-fulfillment.ts | 14 ++++++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/integration-tests/modules/__tests__/order/workflows/create-fulfillment.spec.ts b/integration-tests/modules/__tests__/order/workflows/create-fulfillment.spec.ts index 0a94876ccfe13..795aff216f92e 100644 --- a/integration-tests/modules/__tests__/order/workflows/create-fulfillment.spec.ts +++ b/integration-tests/modules/__tests__/order/workflows/create-fulfillment.spec.ts @@ -3,6 +3,7 @@ import { createOrderFulfillmentWorkflow, createShippingOptionsWorkflow, } from "@medusajs/core-flows" +import { medusaIntegrationTestRunner } from "@medusajs/test-utils" import { FulfillmentWorkflow, IOrderModuleService, @@ -20,7 +21,6 @@ import { Modules, remoteQueryObjectFromString, } from "@medusajs/utils" -import { medusaIntegrationTestRunner } from "@medusajs/test-utils" jest.setTimeout(500000) @@ -433,7 +433,6 @@ medusaIntegrationTestRunner({ await cancelOrderFulfillmentWorkflow(container).run({ input: cancelFulfillmentData, }) - const remoteQueryObjectFulfill = remoteQueryObjectFromString({ entryPoint: "order", variables: { diff --git a/packages/core/core-flows/src/order/workflows/cancel-order-fulfillment.ts b/packages/core/core-flows/src/order/workflows/cancel-order-fulfillment.ts index 30905c1f586c1..17022dd3ae563 100644 --- a/packages/core/core-flows/src/order/workflows/cancel-order-fulfillment.ts +++ b/packages/core/core-flows/src/order/workflows/cancel-order-fulfillment.ts @@ -101,13 +101,15 @@ function prepareInventoryUpdate({ }[] = [] for (const item of fulfillment.items) { // if this is `null` this means that item is from variant that has `manage_inventory` false - if (item.inventory_item_id) { - inventoryAdjustment.push({ - inventory_item_id: item.inventory_item_id as string, - location_id: fulfillment.location_id, - adjustment: item.quantity, - }) + if (!item.inventory_item_id) { + continue } + + inventoryAdjustment.push({ + inventory_item_id: item.inventory_item_id as string, + location_id: fulfillment.location_id, + adjustment: item.quantity, + }) } return { From 815383db8c9662cd848920b39b2e60701f4b249c Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Thu, 9 Jan 2025 07:07:37 -0300 Subject: [PATCH 167/175] base repo --- .../order/src/utils/base-repository-find.ts | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/packages/modules/order/src/utils/base-repository-find.ts b/packages/modules/order/src/utils/base-repository-find.ts index 057ad7e2a247a..7a93ca236b7d4 100644 --- a/packages/modules/order/src/utils/base-repository-find.ts +++ b/packages/modules/order/src/utils/base-repository-find.ts @@ -184,6 +184,10 @@ function configurePopulateWhere( config.options.populateWhere ??= {} const popWhere = config.options.populateWhere + if (isSelectIn) { + version = getVersionSubQuery(manager, "o0") + } + if (isRelatedEntity) { popWhere.order ??= {} popWhere.order.version = isSelectIn @@ -202,22 +206,16 @@ function configurePopulateWhere( if (hasRelation("summary")) { orderWhere.summary ??= {} - orderWhere.summary.version = isSelectIn - ? getVersionSubQuery(manager, "s0") - : version + orderWhere.summary.version = version } if (hasRelation("items") || hasRelation("order.items")) { orderWhere.items ??= {} - orderWhere.items.version = isSelectIn - ? getVersionSubQuery(manager, "i0") - : version + orderWhere.items.version = version } if (hasRelation("shipping_methods")) { orderWhere.shipping_methods ??= {} - orderWhere.shipping_methods.version = isSelectIn - ? getVersionSubQuery(manager, "s0") - : version + orderWhere.shipping_methods.version = version } } From 656d831639fff42ff6a9e49f4d26702cebc1c480 Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Thu, 9 Jan 2025 07:25:36 -0300 Subject: [PATCH 168/175] test --- integration-tests/modules/__tests__/order/draft-order.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/integration-tests/modules/__tests__/order/draft-order.spec.ts b/integration-tests/modules/__tests__/order/draft-order.spec.ts index e11bf06c43ed3..78d35f1985757 100644 --- a/integration-tests/modules/__tests__/order/draft-order.spec.ts +++ b/integration-tests/modules/__tests__/order/draft-order.spec.ts @@ -236,7 +236,7 @@ medusaIntegrationTestRunner({ summary: expect.objectContaining({ // TODO: add summary fields }), - items: [ + items: expect.arrayContaining([ expect.objectContaining({ title: "Test variant", subtitle: "Test product", @@ -335,7 +335,7 @@ medusaIntegrationTestRunner({ value: "1", }), }), - ], + ]), shipping_address: expect.objectContaining({ last_name: "Test", address_1: "Test", From fa366733dd6515a8dccf1b92aefdf1c940b13a45 Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Thu, 9 Jan 2025 08:04:27 -0300 Subject: [PATCH 169/175] base repo --- .../order/src/utils/base-repository-find.ts | 43 +++++++++++++------ 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/packages/modules/order/src/utils/base-repository-find.ts b/packages/modules/order/src/utils/base-repository-find.ts index 7a93ca236b7d4..ec514ae78e249 100644 --- a/packages/modules/order/src/utils/base-repository-find.ts +++ b/packages/modules/order/src/utils/base-repository-find.ts @@ -184,38 +184,57 @@ function configurePopulateWhere( config.options.populateWhere ??= {} const popWhere = config.options.populateWhere - if (isSelectIn) { - version = getVersionSubQuery(manager, "o0") - } - + // isSelectIn && isRelatedEntity - Order is always the FROM clause (field o0.id) if (isRelatedEntity) { popWhere.order ??= {} - popWhere.order.version = isSelectIn + + const popWhereOrder = popWhere.order + + popWhereOrder.version = isSelectIn ? getVersionSubQuery(manager, "o0", "id") : version + // related entity shipping method if (hasRelation("shipping_methods")) { popWhere.shipping_methods ??= {} popWhere.shipping_methods.version = isSelectIn ? getVersionSubQuery(manager, "s0") : version } + + if (hasRelation("items") || hasRelation("order.items")) { + popWhereOrder.items ??= {} + popWhereOrder.items.version = isSelectIn + ? getVersionSubQuery(manager, "o0", "id") + : version + } + + if (hasRelation("shipping_methods")) { + popWhereOrder.shipping_methods ??= {} + popWhereOrder.shipping_methods.version = isSelectIn + ? getVersionSubQuery(manager, "o0", "id") + : version + } + + return } - const orderWhere = isRelatedEntity ? popWhere.order : popWhere + if (isSelectIn) { + version = getVersionSubQuery(manager, "o0") + } if (hasRelation("summary")) { - orderWhere.summary ??= {} - orderWhere.summary.version = version + popWhere.summary ??= {} + popWhere.summary.version = version } if (hasRelation("items") || hasRelation("order.items")) { - orderWhere.items ??= {} - orderWhere.items.version = version + popWhere.items ??= {} + popWhere.items.version = version } if (hasRelation("shipping_methods")) { - orderWhere.shipping_methods ??= {} - orderWhere.shipping_methods.version = version + popWhere.shipping_methods ??= {} + popWhere.shipping_methods.version = version } } From 96b48928783ec6d8cd3c033f5766bc4e6f193eda Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Thu, 9 Jan 2025 08:50:14 -0300 Subject: [PATCH 170/175] test fix --- .../http/__tests__/order/admin/rma-flows.spec.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/integration-tests/http/__tests__/order/admin/rma-flows.spec.ts b/integration-tests/http/__tests__/order/admin/rma-flows.spec.ts index c3b42a3d8a6fe..58354afa7beba 100644 --- a/integration-tests/http/__tests__/order/admin/rma-flows.spec.ts +++ b/integration-tests/http/__tests__/order/admin/rma-flows.spec.ts @@ -1,5 +1,5 @@ -import { ClaimType, Modules, RuleOperator } from "@medusajs/utils" import { medusaIntegrationTestRunner } from "@medusajs/test-utils" +import { ClaimType, Modules, RuleOperator } from "@medusajs/utils" import { adminHeaders, createAdminUser, @@ -7,7 +7,7 @@ import { import { setupTaxStructure } from "../../../../modules/__tests__/fixtures" import { createOrderSeeder } from "../../fixtures/order" -jest.setTimeout(30000) +jest.setTimeout(300000) medusaIntegrationTestRunner({ testSuite: ({ dbConnection, getContainer, api }) => { @@ -268,6 +268,7 @@ medusaIntegrationTestRunner({ { items: [ { + title: "new ITEM", variant_id: order.items[0].variant_id, quantity: 1, }, @@ -480,6 +481,7 @@ medusaIntegrationTestRunner({ { items: [ { + title: "Test item 2", variant_id: order.items[0].variant_id, quantity: 1, }, @@ -551,7 +553,7 @@ medusaIntegrationTestRunner({ }) ) - inboundItem = orderResult.items[0] + inboundItem = orderResult.items[1] await api.post( `/admin/claims/${claimWithInboundAndOutbound.id}/inbound/items`, From feeed0167a48e209ebf1605985b6dea71d9dba53 Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Thu, 9 Jan 2025 09:08:48 -0300 Subject: [PATCH 171/175] inventory move --- .../core-flows/src/order/workflows/cancel-order-fulfillment.ts | 2 +- .../order/workflows/return/confirm-receive-return-request.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/core/core-flows/src/order/workflows/cancel-order-fulfillment.ts b/packages/core/core-flows/src/order/workflows/cancel-order-fulfillment.ts index 17022dd3ae563..06db99a5903f6 100644 --- a/packages/core/core-flows/src/order/workflows/cancel-order-fulfillment.ts +++ b/packages/core/core-flows/src/order/workflows/cancel-order-fulfillment.ts @@ -166,9 +166,9 @@ export const cancelOrderFulfillmentWorkflow = createWorkflow( } }) + adjustInventoryLevelsStep(inventoryAdjustment) parallelize( cancelOrderFulfillmentStep(cancelOrderFulfillmentData), - adjustInventoryLevelsStep(inventoryAdjustment), emitEventStep({ eventName: OrderWorkflowEvents.FULFILLMENT_CANCELED, data: eventData, diff --git a/packages/core/core-flows/src/order/workflows/return/confirm-receive-return-request.ts b/packages/core/core-flows/src/order/workflows/return/confirm-receive-return-request.ts index 64a1c94bcc66e..e7372ef985acc 100644 --- a/packages/core/core-flows/src/order/workflows/return/confirm-receive-return-request.ts +++ b/packages/core/core-flows/src/order/workflows/return/confirm-receive-return-request.ts @@ -292,6 +292,7 @@ export const confirmReturnReceiveWorkflow = createWorkflow( confirmReceiveReturnValidationStep({ order, orderReturn, orderChange }) + adjustInventoryLevelsStep(inventoryAdjustment) parallelize( updateReturnsStep([updateReturn]), updateReturnItemsStep(updateReturnItem), @@ -300,7 +301,6 @@ export const confirmReturnReceiveWorkflow = createWorkflow( orderId: order.id, confirmed_by: input.confirmed_by, }), - adjustInventoryLevelsStep(inventoryAdjustment), emitEventStep({ eventName: OrderWorkflowEvents.RETURN_RECEIVED, data: { From 1bd1a64d729ab45b179e46a64b1d0411c868dc26 Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Thu, 9 Jan 2025 10:33:49 -0300 Subject: [PATCH 172/175] locking inventory --- .../workflows/create-fulfillment.spec.ts | 16 +++--- .../steps/adjust-inventory-levels.ts | 54 +++++++++++-------- .../workflows/cancel-order-fulfillment.ts | 2 +- .../return/confirm-receive-return-request.ts | 2 +- 4 files changed, 43 insertions(+), 31 deletions(-) diff --git a/integration-tests/modules/__tests__/order/workflows/create-fulfillment.spec.ts b/integration-tests/modules/__tests__/order/workflows/create-fulfillment.spec.ts index 795aff216f92e..d770eb3c4a4a5 100644 --- a/integration-tests/modules/__tests__/order/workflows/create-fulfillment.spec.ts +++ b/integration-tests/modules/__tests__/order/workflows/create-fulfillment.spec.ts @@ -305,12 +305,15 @@ async function createOrderFixture({ container, product, location }) { const inventoryModule = container.resolve(Modules.INVENTORY) + const itemWithInventory = order.items!.find( + (o) => o.variant_sku === variantSkuWithInventory + )! const reservation = await inventoryModule.createReservationItems([ { - line_item_id: order.items![0].id, + line_item_id: itemWithInventory.id, inventory_item_id: inventoryItem.id, location_id: location.id, - quantity: order.items![0].quantity, + quantity: itemWithInventory.quantity, }, ]) @@ -433,13 +436,13 @@ medusaIntegrationTestRunner({ await cancelOrderFulfillmentWorkflow(container).run({ input: cancelFulfillmentData, }) + const remoteQueryObjectFulfill = remoteQueryObjectFromString({ entryPoint: "order", variables: { id: order.id, }, fields: [ - "*", "items.*", "shipping_methods.*", "total", @@ -457,14 +460,15 @@ medusaIntegrationTestRunner({ )! expect(orderFulfillAfterCancelled.fulfillments).toHaveLength(1) - expect(orderFulfillItemWithInventory.detail.fulfilled_quantity).toEqual( - 0 - ) + expect( + orderFulfillItemWithInventory.detail.fulfilled_quantity.valueOf() + ).toEqual(0) const stockAvailabilityAfterCancelled = await inventoryModule.retrieveStockedQuantity(inventoryItem.id, [ location.id, ]) + expect(stockAvailabilityAfterCancelled.valueOf()).toEqual(2) }) diff --git a/packages/core/core-flows/src/inventory/steps/adjust-inventory-levels.ts b/packages/core/core-flows/src/inventory/steps/adjust-inventory-levels.ts index ce96f67525443..2aa2b4755dcbc 100644 --- a/packages/core/core-flows/src/inventory/steps/adjust-inventory-levels.ts +++ b/packages/core/core-flows/src/inventory/steps/adjust-inventory-levels.ts @@ -1,4 +1,4 @@ -import { IInventoryService, InventoryTypes } from "@medusajs/framework/types" +import { InventoryTypes } from "@medusajs/framework/types" import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk" import { MathBN, Modules } from "@medusajs/framework/utils" @@ -13,20 +13,22 @@ export const adjustInventoryLevelsStep = createStep( input: InventoryTypes.BulkAdjustInventoryLevelInput[], { container } ) => { - const inventoryService: IInventoryService = container.resolve( - Modules.INVENTORY - ) + const inventoryService = container.resolve(Modules.INVENTORY) + const locking = container.resolve(Modules.LOCKING) + const inventoryItemIds = input.map((item) => item.inventory_item_id) const adjustedLevels: InventoryTypes.InventoryLevelDTO[] = - await inventoryService.adjustInventory( - input.map((item) => { - return { - inventoryItemId: item.inventory_item_id, - locationId: item.location_id, - adjustment: item.adjustment, - } - }) - ) + await locking.execute(inventoryItemIds, async () => { + return await inventoryService.adjustInventory( + input.map((item) => { + return { + inventoryItemId: item.inventory_item_id, + locationId: item.location_id, + adjustment: item.adjustment, + } + }) + ) + }) return new StepResponse( adjustedLevels, @@ -39,11 +41,15 @@ export const adjustInventoryLevelsStep = createStep( ) }, async (adjustedLevels, { container }) => { - if (!adjustedLevels) { + if (!adjustedLevels?.length) { return } const inventoryService = container.resolve(Modules.INVENTORY) + const locking = container.resolve(Modules.LOCKING) + const inventoryItemIds = adjustedLevels.map( + (item) => item.inventory_item_id + ) /** * @todo @@ -51,14 +57,16 @@ export const adjustInventoryLevelsStep = createStep( * "inventoryItemId" and "locationId" as snake case, whereas * the expected object needed these properties as camelCase */ - await inventoryService.adjustInventory( - adjustedLevels.map((level) => { - return { - inventoryItemId: level.inventory_item_id, - locationId: level.location_id, - adjustment: level.adjustment, - } - }) - ) + await locking.execute(inventoryItemIds, async () => { + await inventoryService.adjustInventory( + adjustedLevels.map((level) => { + return { + inventoryItemId: level.inventory_item_id, + locationId: level.location_id, + adjustment: level.adjustment, + } + }) + ) + }) } ) diff --git a/packages/core/core-flows/src/order/workflows/cancel-order-fulfillment.ts b/packages/core/core-flows/src/order/workflows/cancel-order-fulfillment.ts index 06db99a5903f6..17022dd3ae563 100644 --- a/packages/core/core-flows/src/order/workflows/cancel-order-fulfillment.ts +++ b/packages/core/core-flows/src/order/workflows/cancel-order-fulfillment.ts @@ -166,9 +166,9 @@ export const cancelOrderFulfillmentWorkflow = createWorkflow( } }) - adjustInventoryLevelsStep(inventoryAdjustment) parallelize( cancelOrderFulfillmentStep(cancelOrderFulfillmentData), + adjustInventoryLevelsStep(inventoryAdjustment), emitEventStep({ eventName: OrderWorkflowEvents.FULFILLMENT_CANCELED, data: eventData, diff --git a/packages/core/core-flows/src/order/workflows/return/confirm-receive-return-request.ts b/packages/core/core-flows/src/order/workflows/return/confirm-receive-return-request.ts index e7372ef985acc..64a1c94bcc66e 100644 --- a/packages/core/core-flows/src/order/workflows/return/confirm-receive-return-request.ts +++ b/packages/core/core-flows/src/order/workflows/return/confirm-receive-return-request.ts @@ -292,7 +292,6 @@ export const confirmReturnReceiveWorkflow = createWorkflow( confirmReceiveReturnValidationStep({ order, orderReturn, orderChange }) - adjustInventoryLevelsStep(inventoryAdjustment) parallelize( updateReturnsStep([updateReturn]), updateReturnItemsStep(updateReturnItem), @@ -301,6 +300,7 @@ export const confirmReturnReceiveWorkflow = createWorkflow( orderId: order.id, confirmed_by: input.confirmed_by, }), + adjustInventoryLevelsStep(inventoryAdjustment), emitEventStep({ eventName: OrderWorkflowEvents.RETURN_RECEIVED, data: { From c9bebecc438f82340ff70174d50e0cfea9202c73 Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Thu, 9 Jan 2025 13:01:07 -0300 Subject: [PATCH 173/175] test --- .../http/__tests__/reservations/admin/reservations.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/integration-tests/http/__tests__/reservations/admin/reservations.spec.ts b/integration-tests/http/__tests__/reservations/admin/reservations.spec.ts index 4fa3429b7df7a..3c15449a2def4 100644 --- a/integration-tests/http/__tests__/reservations/admin/reservations.spec.ts +++ b/integration-tests/http/__tests__/reservations/admin/reservations.spec.ts @@ -329,7 +329,7 @@ medusaIntegrationTestRunner({ ) }) - it("lists reservation items with free text search on SKU on inventory item", async () => { + it.skip("lists reservation items with free text search on SKU on inventory item", async () => { const reservationsRes = await api .get(`/admin/reservations?q=second`, adminHeaders) .catch(console.warn) @@ -371,7 +371,7 @@ medusaIntegrationTestRunner({ ]) }) - it("lists reservation items with free text search on descroption", async () => { + it.skip("lists reservation items with free text search on descroption", async () => { const reservationsRes = await api .get(`/admin/reservations?q=test`, adminHeaders) .catch(console.warn) From 5ecdcc6d293a6807133fa5ba82db3c8f4f4ef971 Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Fri, 10 Jan 2025 06:31:28 -0300 Subject: [PATCH 174/175] free text fix --- .../http/__tests__/reservations/admin/reservations.spec.ts | 4 ++-- .../src/dal/mikro-orm/mikro-orm-free-text-search-filter.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/integration-tests/http/__tests__/reservations/admin/reservations.spec.ts b/integration-tests/http/__tests__/reservations/admin/reservations.spec.ts index 3c15449a2def4..4fa3429b7df7a 100644 --- a/integration-tests/http/__tests__/reservations/admin/reservations.spec.ts +++ b/integration-tests/http/__tests__/reservations/admin/reservations.spec.ts @@ -329,7 +329,7 @@ medusaIntegrationTestRunner({ ) }) - it.skip("lists reservation items with free text search on SKU on inventory item", async () => { + it("lists reservation items with free text search on SKU on inventory item", async () => { const reservationsRes = await api .get(`/admin/reservations?q=second`, adminHeaders) .catch(console.warn) @@ -371,7 +371,7 @@ medusaIntegrationTestRunner({ ]) }) - it.skip("lists reservation items with free text search on descroption", async () => { + it("lists reservation items with free text search on descroption", async () => { const reservationsRes = await api .get(`/admin/reservations?q=test`, adminHeaders) .catch(console.warn) diff --git a/packages/core/utils/src/dal/mikro-orm/mikro-orm-free-text-search-filter.ts b/packages/core/utils/src/dal/mikro-orm/mikro-orm-free-text-search-filter.ts index baba5b9ca74d4..1b515069ca1f3 100644 --- a/packages/core/utils/src/dal/mikro-orm/mikro-orm-free-text-search-filter.ts +++ b/packages/core/utils/src/dal/mikro-orm/mikro-orm-free-text-search-filter.ts @@ -102,7 +102,7 @@ function retrieveRelationsConstraints( mapToPk: innerRelation.mapToPk, type: innerRelation.type, }, - metadata, + innerRelation.targetMeta!, searchValue, branchVisited, isSelfCircularDependency From a20977b7b02338a52a604077b46a5f7c0ebeb47d Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Fri, 10 Jan 2025 07:31:46 -0300 Subject: [PATCH 175/175] rm timeout mock --- .../integration-tests/__tests__/index.spec.ts | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/packages/modules/workflow-engine-inmemory/integration-tests/__tests__/index.spec.ts b/packages/modules/workflow-engine-inmemory/integration-tests/__tests__/index.spec.ts index 765d64facacbe..e2fa4d527a92d 100644 --- a/packages/modules/workflow-engine-inmemory/integration-tests/__tests__/index.spec.ts +++ b/packages/modules/workflow-engine-inmemory/integration-tests/__tests__/index.spec.ts @@ -12,9 +12,9 @@ import { Modules, TransactionHandlerType, } from "@medusajs/framework/utils" +import { moduleIntegrationTestRunner } from "@medusajs/test-utils" import { WorkflowsModuleService } from "@services" import { asFunction } from "awilix" -import { moduleIntegrationTestRunner } from "@medusajs/test-utils" import { setTimeout as setTimeoutPromise } from "timers/promises" import "../__fixtures__" import { @@ -332,15 +332,11 @@ moduleIntegrationTestRunner({ describe("Scheduled workflows", () => { beforeEach(() => { - jest.clearAllMocks() - }) - - beforeAll(() => { jest.useFakeTimers() - jest.spyOn(global, "setTimeout") + jest.clearAllMocks() }) - afterAll(() => { + afterEach(() => { jest.useRealTimers() }) @@ -348,11 +344,9 @@ moduleIntegrationTestRunner({ const spy = createScheduled("standard") await jest.runOnlyPendingTimersAsync() - expect(setTimeout).toHaveBeenCalledTimes(2) expect(spy).toHaveBeenCalledTimes(1) await jest.runOnlyPendingTimersAsync() - expect(setTimeout).toHaveBeenCalledTimes(3) expect(spy).toHaveBeenCalledTimes(2) })