chore(): Remove default limit from the build query (#9257)
* chore(): Remove default limit from the build query * rm take: null * fix tests * fix tests * fix db usage * fix typo * rm unsused template arg * fixes * fixes * fixes * fixes * fixes * fixes * fixes
This commit is contained in:
1 parent
9e711720dd
commit
90d530565b
41 files changed
+540
-215
No files matched your search
@@ -42,7 +42,7 @@ export const getPromotionCodesToApply = createStep(
|
|||||||
(
|
(
|
||||||
await promotionService.listPromotions(
|
await promotionService.listPromotions(
|
||||||
{ code: adjustmentCodes },
|
{ code: adjustmentCodes },
|
||||||
{ select: ["code"], take: null }
|
{ select: ["code"] }
|
||||||
)
|
)
|
||||||
).map((p) => p.code!)
|
).map((p) => p.code!)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ async function getCurrentShippingOptionPriceSetsLinks(
|
|||||||
service: LINKS.ShippingOptionPriceSet,
|
service: LINKS.ShippingOptionPriceSet,
|
||||||
variables: {
|
variables: {
|
||||||
filters: { shipping_option_id: shippingOptionIds },
|
filters: { shipping_option_id: shippingOptionIds },
|
||||||
take: null,
|
|
||||||
},
|
},
|
||||||
fields: ["shipping_option_id", "price_set_id"],
|
fields: ["shipping_option_id", "price_set_id"],
|
||||||
} as any)) as {
|
} as any)) as {
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ async function getCurrentShippingOptionPrices(
|
|||||||
service: LINKS.ShippingOptionPriceSet,
|
service: LINKS.ShippingOptionPriceSet,
|
||||||
variables: {
|
variables: {
|
||||||
filters: { shipping_option_id: shippingOptionIds },
|
filters: { shipping_option_id: shippingOptionIds },
|
||||||
take: null,
|
|
||||||
},
|
},
|
||||||
fields: ["shipping_option_id", "price_set_id", "price_set.prices.*"],
|
fields: ["shipping_option_id", "price_set_id", "price_set.prices.*"],
|
||||||
} as any)) as {
|
} as any)) as {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import {
|
|||||||
MedusaError,
|
MedusaError,
|
||||||
Modules,
|
Modules,
|
||||||
} from "@medusajs/utils"
|
} from "@medusajs/utils"
|
||||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
import { createStep, StepResponse } from "@medusajs/workflows-sdk"
|
||||||
|
|
||||||
export type FulfillmentProviderValidationWorkflowInput = {
|
export type FulfillmentProviderValidationWorkflowInput = {
|
||||||
id?: string
|
id?: string
|
||||||
@@ -36,7 +36,6 @@ export const validateFulfillmentProvidersStep = createStep(
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
select: ["id", "service_zone_id", "provider_id"],
|
select: ["id", "service_zone_id", "provider_id"],
|
||||||
take: null,
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ export const getExistingPriceListsPriceIdsStep = createStep(
|
|||||||
const existingPrices = priceListIds.length
|
const existingPrices = priceListIds.length
|
||||||
? await pricingModule.listPrices(
|
? await pricingModule.listPrices(
|
||||||
{ price_list_id: priceListIds },
|
{ price_list_id: priceListIds },
|
||||||
{ relations: ["price_list"], take: null }
|
{ relations: ["price_list"] }
|
||||||
)
|
)
|
||||||
: []
|
: []
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ export const validateVariantPriceLinksStep = createStep(
|
|||||||
const links = await remoteQuery({
|
const links = await remoteQuery({
|
||||||
entryPoint: "product_variant_price_set",
|
entryPoint: "product_variant_price_set",
|
||||||
fields: ["variant_id", "price_set_id"],
|
fields: ["variant_id", "price_set_id"],
|
||||||
variables: { variant_id: variantIds, take: null },
|
variables: { variant_id: variantIds },
|
||||||
})
|
})
|
||||||
const variantPriceSetMap: Record<string, string> = {}
|
const variantPriceSetMap: Record<string, string> = {}
|
||||||
|
|
||||||
|
|||||||
@@ -16,8 +16,7 @@ export const updatePricePreferencesAsArrayStep = createStep(
|
|||||||
const service = container.resolve<IPricingModuleService>(Modules.PRICING)
|
const service = container.resolve<IPricingModuleService>(Modules.PRICING)
|
||||||
|
|
||||||
const prevData = await service.listPricePreferences({
|
const prevData = await service.listPricePreferences({
|
||||||
$or: input.map(
|
$or: input.map((entry) => {
|
||||||
(entry) => {
|
|
||||||
if (!entry.attribute || !entry.value) {
|
if (!entry.attribute || !entry.value) {
|
||||||
throw new MedusaError(
|
throw new MedusaError(
|
||||||
MedusaError.Types.INVALID_DATA,
|
MedusaError.Types.INVALID_DATA,
|
||||||
@@ -26,9 +25,7 @@ export const updatePricePreferencesAsArrayStep = createStep(
|
|||||||
}
|
}
|
||||||
|
|
||||||
return { attribute: entry.attribute, value: entry.value }
|
return { attribute: entry.attribute, value: entry.value }
|
||||||
},
|
}, {}),
|
||||||
{ take: null }
|
|
||||||
),
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const toUpsert = input.map((entry) => {
|
const toUpsert = input.map((entry) => {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { IProductModuleService, LinkWorkflowInput } from "@medusajs/types"
|
import { IProductModuleService, LinkWorkflowInput } from "@medusajs/types"
|
||||||
import { Modules } from "@medusajs/utils"
|
import { Modules } from "@medusajs/utils"
|
||||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
import { createStep, StepResponse } from "@medusajs/workflows-sdk"
|
||||||
|
|
||||||
export const batchLinkProductsToCollectionStepId =
|
export const batchLinkProductsToCollectionStepId =
|
||||||
"batch-link-products-to-collection"
|
"batch-link-products-to-collection"
|
||||||
@@ -17,7 +17,6 @@ export const batchLinkProductsToCollectionStep = createStep(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const dbCollection = await service.retrieveProductCollection(data.id, {
|
const dbCollection = await service.retrieveProductCollection(data.id, {
|
||||||
take: null,
|
|
||||||
select: ["id", "products.id"],
|
select: ["id", "products.id"],
|
||||||
relations: ["products"],
|
relations: ["products"],
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { IProductModuleService, ProductCategoryWorkflow } from "@medusajs/types"
|
import { IProductModuleService, ProductCategoryWorkflow } from "@medusajs/types"
|
||||||
import { Modules } from "@medusajs/utils"
|
import { Modules } from "@medusajs/utils"
|
||||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
import { createStep, StepResponse } from "@medusajs/workflows-sdk"
|
||||||
|
|
||||||
export const batchLinkProductsToCategoryStepId =
|
export const batchLinkProductsToCategoryStepId =
|
||||||
"batch-link-products-to-category"
|
"batch-link-products-to-category"
|
||||||
@@ -23,7 +23,6 @@ export const batchLinkProductsToCategoryStep = createStep(
|
|||||||
const dbProducts = await service.listProducts(
|
const dbProducts = await service.listProducts(
|
||||||
{ id: [...(data.add ?? []), ...(data.remove ?? [])] },
|
{ id: [...(data.add ?? []), ...(data.remove ?? [])] },
|
||||||
{
|
{
|
||||||
take: null,
|
|
||||||
select: ["id", "categories"],
|
select: ["id", "categories"],
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -63,7 +62,6 @@ export const batchLinkProductsToCategoryStep = createStep(
|
|||||||
const dbProducts = await service.listProducts(
|
const dbProducts = await service.listProducts(
|
||||||
{ id: prevData.productIds },
|
{ id: prevData.productIds },
|
||||||
{
|
{
|
||||||
take: null,
|
|
||||||
select: ["id", "categories"],
|
select: ["id", "categories"],
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ export const generateProductCsvStep = createStep(
|
|||||||
|
|
||||||
const regions = await regionService.listRegions(
|
const regions = await regionService.listRegions(
|
||||||
{},
|
{},
|
||||||
{ select: ["id", "name", "currency_code"], take: null }
|
{ select: ["id", "name", "currency_code"] }
|
||||||
)
|
)
|
||||||
|
|
||||||
const normalizedData = normalizeForExport(products, { regions })
|
const normalizedData = normalizeForExport(products, { regions })
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ export const getProductsStep = createStep(
|
|||||||
|
|
||||||
const products = await service.listProducts(
|
const products = await service.listProducts(
|
||||||
{ id: data.ids },
|
{ id: data.ids },
|
||||||
{ relations: ["variants"], take: null }
|
{ relations: ["variants"] }
|
||||||
)
|
)
|
||||||
return new StepResponse(products, products)
|
return new StepResponse(products, products)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ export const groupProductsForBatchStep = createStep(
|
|||||||
// We use the ID to do product updates
|
// We use the ID to do product updates
|
||||||
id: data.map((product) => product.id).filter(Boolean) as string[],
|
id: data.map((product) => product.id).filter(Boolean) as string[],
|
||||||
},
|
},
|
||||||
{ take: null, select: ["handle"] }
|
{ select: ["handle"] }
|
||||||
)
|
)
|
||||||
const existingProductsSet = new Set(existingProducts.map((p) => p.id))
|
const existingProductsSet = new Set(existingProducts.map((p) => p.id))
|
||||||
|
|
||||||
|
|||||||
@@ -30,9 +30,9 @@ export const parseProductCsvStep = createStep(
|
|||||||
|
|
||||||
const [productTypes, productCollections, salesChannels] = await Promise.all(
|
const [productTypes, productCollections, salesChannels] = await Promise.all(
|
||||||
[
|
[
|
||||||
productService.listProductTypes({}, { take: null }),
|
productService.listProductTypes({}, {}),
|
||||||
productService.listProductCollections({}, { take: null }),
|
productService.listProductCollections({}, {}),
|
||||||
salesChannelService.listSalesChannels({}, { take: null }),
|
salesChannelService.listSalesChannels({}, {}),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -55,12 +55,9 @@ export const parseProductCsvStep = createStep(
|
|||||||
const [allRegions, allTags] = await Promise.all([
|
const [allRegions, allTags] = await Promise.all([
|
||||||
regionService.listRegions(
|
regionService.listRegions(
|
||||||
{},
|
{},
|
||||||
{ select: ["id", "name", "currency_code"], take: null }
|
{ select: ["id", "name", "currency_code"] }
|
||||||
),
|
|
||||||
productService.listProductTags(
|
|
||||||
{},
|
|
||||||
{ select: ["id", "value"], take: null }
|
|
||||||
),
|
),
|
||||||
|
productService.listProductTags({}, { select: ["id", "value"] }),
|
||||||
])
|
])
|
||||||
|
|
||||||
const normalizedData = normalizeForImport(v1Normalized, {
|
const normalizedData = normalizeForImport(v1Normalized, {
|
||||||
|
|||||||
@@ -66,7 +66,6 @@ async function getCurrentRegionPaymentProvidersLinks(
|
|||||||
service: LINKS.RegionPaymentProvider,
|
service: LINKS.RegionPaymentProvider,
|
||||||
variables: {
|
variables: {
|
||||||
filters: { region_id: regionIds },
|
filters: { region_id: regionIds },
|
||||||
take: null,
|
|
||||||
},
|
},
|
||||||
fields: ["region_id", "payment_provider_id"],
|
fields: ["region_id", "payment_provider_id"],
|
||||||
} as any)) as {
|
} as any)) as {
|
||||||
|
|||||||
@@ -1,4 +1,15 @@
|
|||||||
import { MikroORM, Options, SqlEntityManager } from "@mikro-orm/postgresql"
|
import { MikroORM, Options, SqlEntityManager } from "@mikro-orm/postgresql"
|
||||||
|
import { createDatabase, dropDatabase } from "pg-god"
|
||||||
|
|
||||||
|
const DB_HOST = process.env.DB_HOST ?? "localhost"
|
||||||
|
const DB_USERNAME = process.env.DB_USERNAME ?? ""
|
||||||
|
const DB_PASSWORD = process.env.DB_PASSWORD ?? ""
|
||||||
|
|
||||||
|
const pgGodCredentials = {
|
||||||
|
user: DB_USERNAME,
|
||||||
|
password: DB_PASSWORD,
|
||||||
|
host: DB_HOST,
|
||||||
|
}
|
||||||
|
|
||||||
export function getDatabaseURL(dbName?: string): string {
|
export function getDatabaseURL(dbName?: string): string {
|
||||||
const DB_HOST = process.env.DB_HOST ?? "localhost"
|
const DB_HOST = process.env.DB_HOST ?? "localhost"
|
||||||
@@ -158,3 +169,46 @@ export function getMikroOrmWrapper({
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const dbTestUtilFactory = (): any => ({
|
||||||
|
pgConnection_: null,
|
||||||
|
|
||||||
|
create: async function (dbName: string) {
|
||||||
|
await createDatabase(
|
||||||
|
{ databaseName: dbName, errorIfExist: false },
|
||||||
|
pgGodCredentials
|
||||||
|
)
|
||||||
|
},
|
||||||
|
|
||||||
|
teardown: async function ({ schema }: { schema?: string } = {}) {
|
||||||
|
if (!this.pgConnection_) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const runRawQuery = this.pgConnection_.raw.bind(this.pgConnection_)
|
||||||
|
|
||||||
|
schema ??= "public"
|
||||||
|
|
||||||
|
await runRawQuery(`SET session_replication_role = 'replica';`)
|
||||||
|
const { rows: tableNames } = await runRawQuery(`SELECT table_name
|
||||||
|
FROM information_schema.tables
|
||||||
|
WHERE table_schema = '${schema}';`)
|
||||||
|
|
||||||
|
for (const { table_name } of tableNames) {
|
||||||
|
await runRawQuery(`DELETE
|
||||||
|
FROM ${schema}."${table_name}";`)
|
||||||
|
}
|
||||||
|
|
||||||
|
await runRawQuery(`SET session_replication_role = 'origin';`)
|
||||||
|
},
|
||||||
|
|
||||||
|
shutdown: async function (dbName: string) {
|
||||||
|
await this.pgConnection_?.context?.destroy()
|
||||||
|
await this.pgConnection_?.destroy()
|
||||||
|
|
||||||
|
return await dropDatabase(
|
||||||
|
{ databaseName: dbName, errorIfNonExist: false },
|
||||||
|
pgGodCredentials
|
||||||
|
)
|
||||||
|
},
|
||||||
|
})
|
||||||
@@ -4,5 +4,6 @@ export { default as IdMap } from "./id-map"
|
|||||||
export * from "./init-modules"
|
export * from "./init-modules"
|
||||||
export * as JestUtils from "./jest"
|
export * as JestUtils from "./jest"
|
||||||
export * from "./medusa-test-runner"
|
export * from "./medusa-test-runner"
|
||||||
|
export * from "./medusa-test-runner-utils/"
|
||||||
export { default as MockEventBusService } from "./mock-event-bus-service"
|
export { default as MockEventBusService } from "./mock-event-bus-service"
|
||||||
export * from "./module-test-runner"
|
export * from "./module-test-runner"
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
export * from "./bootstrap-app"
|
||||||
|
export * from "./clear-instances"
|
||||||
|
export * from "./config"
|
||||||
|
export * from "./use-db"
|
||||||
|
export * from "./utils"
|
||||||
@@ -5,8 +5,7 @@ import {
|
|||||||
createMedusaContainer,
|
createMedusaContainer,
|
||||||
} from "@medusajs/utils"
|
} from "@medusajs/utils"
|
||||||
import { asValue } from "awilix"
|
import { asValue } from "awilix"
|
||||||
import { createDatabase, dropDatabase } from "pg-god"
|
import { dbTestUtilFactory, getDatabaseURL } from "./database"
|
||||||
import { getDatabaseURL } from "./database"
|
|
||||||
import { startApp } from "./medusa-test-runner-utils/bootstrap-app"
|
import { startApp } from "./medusa-test-runner-utils/bootstrap-app"
|
||||||
import { clearInstances } from "./medusa-test-runner-utils/clear-instances"
|
import { clearInstances } from "./medusa-test-runner-utils/clear-instances"
|
||||||
import { configLoaderOverride } from "./medusa-test-runner-utils/config"
|
import { configLoaderOverride } from "./medusa-test-runner-utils/config"
|
||||||
@@ -17,60 +16,7 @@ import {
|
|||||||
} from "./medusa-test-runner-utils/use-db"
|
} from "./medusa-test-runner-utils/use-db"
|
||||||
import { applyEnvVarsToProcess } from "./medusa-test-runner-utils/utils"
|
import { applyEnvVarsToProcess } from "./medusa-test-runner-utils/utils"
|
||||||
|
|
||||||
const DB_HOST = process.env.DB_HOST
|
export interface MedusaSuiteOptions {
|
||||||
const DB_USERNAME = process.env.DB_USERNAME ?? ""
|
|
||||||
const DB_PASSWORD = process.env.DB_PASSWORD ?? ""
|
|
||||||
|
|
||||||
const pgGodCredentials = {
|
|
||||||
user: DB_USERNAME,
|
|
||||||
password: DB_PASSWORD,
|
|
||||||
host: DB_HOST,
|
|
||||||
}
|
|
||||||
|
|
||||||
export const dbTestUtilFactory = (): any => ({
|
|
||||||
pgConnection_: null,
|
|
||||||
|
|
||||||
create: async function (dbName: string) {
|
|
||||||
await createDatabase(
|
|
||||||
{ databaseName: dbName, errorIfExist: false },
|
|
||||||
pgGodCredentials
|
|
||||||
)
|
|
||||||
},
|
|
||||||
|
|
||||||
teardown: async function ({ schema }: { schema?: string } = {}) {
|
|
||||||
if (!this.pgConnection_) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const runRawQuery = this.pgConnection_.raw.bind(this.pgConnection_)
|
|
||||||
|
|
||||||
schema ??= "public"
|
|
||||||
|
|
||||||
await runRawQuery(`SET session_replication_role = 'replica';`)
|
|
||||||
const { rows: tableNames } = await runRawQuery(`SELECT table_name
|
|
||||||
FROM information_schema.tables
|
|
||||||
WHERE table_schema = '${schema}';`)
|
|
||||||
|
|
||||||
for (const { table_name } of tableNames) {
|
|
||||||
await runRawQuery(`DELETE
|
|
||||||
FROM ${schema}."${table_name}";`)
|
|
||||||
}
|
|
||||||
|
|
||||||
await runRawQuery(`SET session_replication_role = 'origin';`)
|
|
||||||
},
|
|
||||||
|
|
||||||
shutdown: async function (dbName: string) {
|
|
||||||
await this.pgConnection_?.context?.destroy()
|
|
||||||
await this.pgConnection_?.destroy()
|
|
||||||
|
|
||||||
return await dropDatabase(
|
|
||||||
{ databaseName: dbName, errorIfNonExist: false },
|
|
||||||
pgGodCredentials
|
|
||||||
)
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
export interface MedusaSuiteOptions<TService = unknown> {
|
|
||||||
dbConnection: any // knex instance
|
dbConnection: any // knex instance
|
||||||
getContainer: () => MedusaContainer
|
getContainer: () => MedusaContainer
|
||||||
api: any
|
api: any
|
||||||
@@ -106,7 +52,7 @@ export function medusaIntegrationTestRunner({
|
|||||||
schema?: string
|
schema?: string
|
||||||
debug?: boolean
|
debug?: boolean
|
||||||
inApp?: boolean
|
inApp?: boolean
|
||||||
testSuite: <TService = unknown>(options: MedusaSuiteOptions<TService>) => void
|
testSuite: (options: MedusaSuiteOptions) => void
|
||||||
}) {
|
}) {
|
||||||
const tempName = parseInt(process.env.JEST_WORKER_ID || "1")
|
const tempName = parseInt(process.env.JEST_WORKER_ID || "1")
|
||||||
moduleName = moduleName ?? Math.random().toString(36).substring(7)
|
moduleName = moduleName ?? Math.random().toString(36).substring(7)
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ class RecursiveEntity1 {
|
|||||||
@PrimaryKey()
|
@PrimaryKey()
|
||||||
id: string
|
id: string
|
||||||
|
|
||||||
@Property()
|
@Property({ nullable: true })
|
||||||
deleted_at: Date | null
|
deleted_at: Date | null
|
||||||
|
|
||||||
@OneToMany(() => RecursiveEntity2, (entity2) => entity2.entity1, {
|
@OneToMany(() => RecursiveEntity2, (entity2) => entity2.entity1, {
|
||||||
@@ -44,7 +44,7 @@ class RecursiveEntity2 {
|
|||||||
@PrimaryKey()
|
@PrimaryKey()
|
||||||
id: string
|
id: string
|
||||||
|
|
||||||
@Property()
|
@Property({ nullable: true })
|
||||||
deleted_at: Date | null
|
deleted_at: Date | null
|
||||||
|
|
||||||
@ManyToOne(() => RecursiveEntity1, {
|
@ManyToOne(() => RecursiveEntity1, {
|
||||||
@@ -64,7 +64,7 @@ class Entity1 {
|
|||||||
@PrimaryKey()
|
@PrimaryKey()
|
||||||
id: string
|
id: string
|
||||||
|
|
||||||
@Property()
|
@Property({ nullable: true })
|
||||||
deleted_at: Date | null
|
deleted_at: Date | null
|
||||||
|
|
||||||
@OneToMany(() => Entity2, (entity2) => entity2.entity1, {
|
@OneToMany(() => Entity2, (entity2) => entity2.entity1, {
|
||||||
@@ -89,7 +89,7 @@ class Entity2 {
|
|||||||
@PrimaryKey()
|
@PrimaryKey()
|
||||||
id: string
|
id: string
|
||||||
|
|
||||||
@Property()
|
@Property({ nullable: true })
|
||||||
deleted_at: Date | null
|
deleted_at: Date | null
|
||||||
|
|
||||||
@ManyToOne(() => Entity1, { mapToPk: true })
|
@ManyToOne(() => Entity1, { mapToPk: true })
|
||||||
@@ -111,7 +111,7 @@ class DeepRecursiveEntity1 {
|
|||||||
@PrimaryKey()
|
@PrimaryKey()
|
||||||
id: string
|
id: string
|
||||||
|
|
||||||
@Property()
|
@Property({ nullable: true })
|
||||||
deleted_at: Date | null
|
deleted_at: Date | null
|
||||||
|
|
||||||
@OneToMany(() => DeepRecursiveEntity2, (entity2) => entity2.entity1, {
|
@OneToMany(() => DeepRecursiveEntity2, (entity2) => entity2.entity1, {
|
||||||
@@ -136,7 +136,7 @@ class DeepRecursiveEntity2 {
|
|||||||
@PrimaryKey()
|
@PrimaryKey()
|
||||||
id: string
|
id: string
|
||||||
|
|
||||||
@Property()
|
@Property({ nullable: true })
|
||||||
deleted_at: Date | null
|
deleted_at: Date | null
|
||||||
|
|
||||||
@ManyToOne(() => DeepRecursiveEntity1)
|
@ManyToOne(() => DeepRecursiveEntity1)
|
||||||
@@ -163,7 +163,7 @@ class DeepRecursiveEntity3 {
|
|||||||
@PrimaryKey()
|
@PrimaryKey()
|
||||||
id: string
|
id: string
|
||||||
|
|
||||||
@Property()
|
@Property({ nullable: true })
|
||||||
deleted_at: Date | null
|
deleted_at: Date | null
|
||||||
|
|
||||||
@ManyToOne(() => DeepRecursiveEntity1, {
|
@ManyToOne(() => DeepRecursiveEntity1, {
|
||||||
@@ -187,7 +187,7 @@ class DeepRecursiveEntity4 {
|
|||||||
@PrimaryKey()
|
@PrimaryKey()
|
||||||
id: string
|
id: string
|
||||||
|
|
||||||
@Property()
|
@Property({ nullable: true })
|
||||||
deleted_at: Date | null
|
deleted_at: Date | null
|
||||||
|
|
||||||
@ManyToOne(() => DeepRecursiveEntity1)
|
@ManyToOne(() => DeepRecursiveEntity1)
|
||||||
@@ -214,7 +214,7 @@ class InternalCircularDependencyEntity1 {
|
|||||||
@PrimaryKey()
|
@PrimaryKey()
|
||||||
id: string
|
id: string
|
||||||
|
|
||||||
@Property()
|
@Property({ nullable: true })
|
||||||
deleted_at: Date | null
|
deleted_at: Date | null
|
||||||
|
|
||||||
@OneToMany(
|
@OneToMany(
|
||||||
@@ -226,7 +226,7 @@ class InternalCircularDependencyEntity1 {
|
|||||||
)
|
)
|
||||||
children = new Collection<InternalCircularDependencyEntity1>(this)
|
children = new Collection<InternalCircularDependencyEntity1>(this)
|
||||||
|
|
||||||
@ManyToOne(() => InternalCircularDependencyEntity1)
|
@ManyToOne(() => InternalCircularDependencyEntity1, { nullable: true })
|
||||||
parent: Rel<InternalCircularDependencyEntity1>
|
parent: Rel<InternalCircularDependencyEntity1>
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -244,7 +244,7 @@ class Entity1WithUnDecoratedProp {
|
|||||||
@PrimaryKey()
|
@PrimaryKey()
|
||||||
id: string
|
id: string
|
||||||
|
|
||||||
@Property()
|
@Property({ nullable: true })
|
||||||
deleted_at: Date | null
|
deleted_at: Date | null
|
||||||
|
|
||||||
@OneToMany(() => Entity2WithUnDecoratedProp, (entity2) => entity2.entity1, {
|
@OneToMany(() => Entity2WithUnDecoratedProp, (entity2) => entity2.entity1, {
|
||||||
@@ -271,7 +271,7 @@ class Entity2WithUnDecoratedProp {
|
|||||||
@PrimaryKey()
|
@PrimaryKey()
|
||||||
id: string
|
id: string
|
||||||
|
|
||||||
@Property()
|
@Property({ nullable: true })
|
||||||
deleted_at: Date | null
|
deleted_at: Date | null
|
||||||
|
|
||||||
@ManyToOne(() => Entity1WithUnDecoratedProp, { mapToPk: true })
|
@ManyToOne(() => Entity1WithUnDecoratedProp, { mapToPk: true })
|
||||||
@@ -293,7 +293,7 @@ class SearchableEntity1 {
|
|||||||
@PrimaryKey()
|
@PrimaryKey()
|
||||||
id: string
|
id: string
|
||||||
|
|
||||||
@Property()
|
@Property({ nullable: true })
|
||||||
deleted_at: Date | null
|
deleted_at: Date | null
|
||||||
|
|
||||||
@Searchable()
|
@Searchable()
|
||||||
@@ -321,7 +321,7 @@ class SearchableEntity2 {
|
|||||||
@PrimaryKey()
|
@PrimaryKey()
|
||||||
id: string
|
id: string
|
||||||
|
|
||||||
@Property()
|
@Property({ nullable: true })
|
||||||
deleted_at: Date | null
|
deleted_at: Date | null
|
||||||
|
|
||||||
@Searchable()
|
@Searchable()
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
const DB_HOST = process.env.DB_HOST ?? "localhost"
|
||||||
|
const DB_USERNAME = process.env.DB_USERNAME ?? ""
|
||||||
|
const DB_PASSWORD = process.env.DB_PASSWORD
|
||||||
|
|
||||||
|
export const pgGodCredentials = {
|
||||||
|
user: DB_USERNAME,
|
||||||
|
password: DB_PASSWORD,
|
||||||
|
host: DB_HOST,
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getDatabaseURL(dbName): string {
|
||||||
|
return `postgres://${DB_USERNAME}${
|
||||||
|
DB_PASSWORD ? `:${DB_PASSWORD}` : ""
|
||||||
|
}@${DB_HOST}/${dbName}`
|
||||||
|
}
|
||||||
@@ -0,0 +1,352 @@
|
|||||||
|
import {
|
||||||
|
Collection,
|
||||||
|
Entity,
|
||||||
|
ManyToOne,
|
||||||
|
OneToMany,
|
||||||
|
PrimaryKey,
|
||||||
|
Property,
|
||||||
|
Rel,
|
||||||
|
} from "@mikro-orm/core"
|
||||||
|
import { Searchable } from "../../decorators/searchable"
|
||||||
|
|
||||||
|
// Circular dependency one level
|
||||||
|
@Entity()
|
||||||
|
class RecursiveEntity1 {
|
||||||
|
constructor(props: { id: string; deleted_at: Date | null }) {
|
||||||
|
this.id = props.id
|
||||||
|
this.deleted_at = props.deleted_at
|
||||||
|
}
|
||||||
|
|
||||||
|
@PrimaryKey()
|
||||||
|
id: string
|
||||||
|
|
||||||
|
@Property({ nullable: true })
|
||||||
|
deleted_at: Date | null
|
||||||
|
|
||||||
|
@OneToMany(() => RecursiveEntity2, (entity2) => entity2.entity1, {
|
||||||
|
cascade: ["soft-remove"] as any,
|
||||||
|
})
|
||||||
|
entity2 = new Collection<RecursiveEntity2>(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Entity()
|
||||||
|
class RecursiveEntity2 {
|
||||||
|
constructor(props: {
|
||||||
|
id: string
|
||||||
|
deleted_at: Date | null
|
||||||
|
entity1: RecursiveEntity1
|
||||||
|
}) {
|
||||||
|
this.id = props.id
|
||||||
|
this.deleted_at = props.deleted_at
|
||||||
|
this.entity1 = props.entity1
|
||||||
|
}
|
||||||
|
|
||||||
|
@PrimaryKey()
|
||||||
|
id: string
|
||||||
|
|
||||||
|
@Property({ nullable: true })
|
||||||
|
deleted_at: Date | null
|
||||||
|
|
||||||
|
@ManyToOne(() => RecursiveEntity1, {
|
||||||
|
cascade: ["soft-remove"] as any,
|
||||||
|
})
|
||||||
|
entity1: Rel<RecursiveEntity1>
|
||||||
|
}
|
||||||
|
|
||||||
|
// No circular dependency
|
||||||
|
@Entity()
|
||||||
|
class Entity1 {
|
||||||
|
constructor(props: { id: string; deleted_at: Date | null }) {
|
||||||
|
this.id = props.id
|
||||||
|
this.deleted_at = props.deleted_at
|
||||||
|
}
|
||||||
|
|
||||||
|
@PrimaryKey()
|
||||||
|
id: string
|
||||||
|
|
||||||
|
@Property({ nullable: true })
|
||||||
|
deleted_at: Date | null
|
||||||
|
|
||||||
|
@OneToMany(() => Entity2, (entity2) => entity2.entity1, {
|
||||||
|
cascade: ["soft-remove"] as any,
|
||||||
|
})
|
||||||
|
entity2 = new Collection<Entity2>(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Entity()
|
||||||
|
class Entity2 {
|
||||||
|
constructor(props: {
|
||||||
|
id: string
|
||||||
|
deleted_at: Date | null
|
||||||
|
entity1: Rel<Entity1>
|
||||||
|
}) {
|
||||||
|
this.id = props.id
|
||||||
|
this.deleted_at = props.deleted_at
|
||||||
|
this.entity1 = props.entity1
|
||||||
|
this.entity1_id = props.entity1.id
|
||||||
|
}
|
||||||
|
|
||||||
|
@PrimaryKey()
|
||||||
|
id: string
|
||||||
|
|
||||||
|
@Property({ nullable: true })
|
||||||
|
deleted_at: Date | null
|
||||||
|
|
||||||
|
@ManyToOne(() => Entity1, { mapToPk: true })
|
||||||
|
entity1_id: string
|
||||||
|
|
||||||
|
@ManyToOne(() => Entity1, { persist: false })
|
||||||
|
entity1: Entity1
|
||||||
|
}
|
||||||
|
|
||||||
|
// Circular dependency deep level
|
||||||
|
|
||||||
|
@Entity()
|
||||||
|
class DeepRecursiveEntity1 {
|
||||||
|
constructor(props: { id: string; deleted_at: Date | null }) {
|
||||||
|
this.id = props.id
|
||||||
|
this.deleted_at = props.deleted_at
|
||||||
|
}
|
||||||
|
|
||||||
|
@PrimaryKey()
|
||||||
|
id: string
|
||||||
|
|
||||||
|
@Property({ nullable: true })
|
||||||
|
deleted_at: Date | null
|
||||||
|
|
||||||
|
@OneToMany(() => DeepRecursiveEntity2, (entity2) => entity2.entity1, {
|
||||||
|
cascade: ["soft-remove"] as any,
|
||||||
|
})
|
||||||
|
entity2 = new Collection<DeepRecursiveEntity2>(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Entity()
|
||||||
|
class DeepRecursiveEntity2 {
|
||||||
|
constructor(props: {
|
||||||
|
id: string
|
||||||
|
deleted_at: Date | null
|
||||||
|
entity1: Rel<DeepRecursiveEntity1>
|
||||||
|
entity3: Rel<DeepRecursiveEntity3>
|
||||||
|
}) {
|
||||||
|
this.id = props.id
|
||||||
|
this.deleted_at = props.deleted_at
|
||||||
|
this.entity3 = props.entity3
|
||||||
|
}
|
||||||
|
|
||||||
|
@PrimaryKey()
|
||||||
|
id: string
|
||||||
|
|
||||||
|
@Property({ nullable: true })
|
||||||
|
deleted_at: Date | null
|
||||||
|
|
||||||
|
@ManyToOne(() => DeepRecursiveEntity1)
|
||||||
|
entity1: DeepRecursiveEntity1
|
||||||
|
|
||||||
|
@ManyToOne(() => DeepRecursiveEntity3, {
|
||||||
|
cascade: ["soft-remove"] as any,
|
||||||
|
})
|
||||||
|
entity3: Rel<DeepRecursiveEntity3>
|
||||||
|
}
|
||||||
|
|
||||||
|
@Entity()
|
||||||
|
class DeepRecursiveEntity3 {
|
||||||
|
constructor(props: {
|
||||||
|
id: string
|
||||||
|
deleted_at: Date | null
|
||||||
|
entity1: Rel<DeepRecursiveEntity1>
|
||||||
|
}) {
|
||||||
|
this.id = props.id
|
||||||
|
this.deleted_at = props.deleted_at
|
||||||
|
this.entity1 = props.entity1
|
||||||
|
}
|
||||||
|
|
||||||
|
@PrimaryKey()
|
||||||
|
id: string
|
||||||
|
|
||||||
|
@Property({ nullable: true })
|
||||||
|
deleted_at: Date | null
|
||||||
|
|
||||||
|
@ManyToOne(() => DeepRecursiveEntity1, {
|
||||||
|
cascade: ["soft-remove"] as any,
|
||||||
|
})
|
||||||
|
entity1: Rel<DeepRecursiveEntity1>
|
||||||
|
}
|
||||||
|
|
||||||
|
@Entity()
|
||||||
|
class DeepRecursiveEntity4 {
|
||||||
|
constructor(props: {
|
||||||
|
id: string
|
||||||
|
deleted_at: Date | null
|
||||||
|
entity1: Rel<DeepRecursiveEntity1>
|
||||||
|
}) {
|
||||||
|
this.id = props.id
|
||||||
|
this.deleted_at = props.deleted_at
|
||||||
|
this.entity1 = props.entity1
|
||||||
|
}
|
||||||
|
|
||||||
|
@PrimaryKey()
|
||||||
|
id: string
|
||||||
|
|
||||||
|
@Property({ nullable: true })
|
||||||
|
deleted_at: Date | null
|
||||||
|
|
||||||
|
@ManyToOne(() => DeepRecursiveEntity1)
|
||||||
|
entity1: Rel<DeepRecursiveEntity1>
|
||||||
|
}
|
||||||
|
|
||||||
|
// Internal circular dependency
|
||||||
|
|
||||||
|
@Entity()
|
||||||
|
class InternalCircularDependencyEntity1 {
|
||||||
|
constructor(props: {
|
||||||
|
id: string
|
||||||
|
deleted_at: Date | null
|
||||||
|
parent?: InternalCircularDependencyEntity1
|
||||||
|
}) {
|
||||||
|
this.id = props.id
|
||||||
|
this.deleted_at = props.deleted_at
|
||||||
|
|
||||||
|
if (props.parent) {
|
||||||
|
this.parent = props.parent
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@PrimaryKey()
|
||||||
|
id: string
|
||||||
|
|
||||||
|
@Property({ nullable: true })
|
||||||
|
deleted_at: Date | null
|
||||||
|
|
||||||
|
@OneToMany(
|
||||||
|
() => InternalCircularDependencyEntity1,
|
||||||
|
(entity) => entity.parent,
|
||||||
|
{
|
||||||
|
cascade: ["soft-remove"] as any,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
children = new Collection<InternalCircularDependencyEntity1>(this)
|
||||||
|
|
||||||
|
@ManyToOne(() => InternalCircularDependencyEntity1, { nullable: true })
|
||||||
|
parent: Rel<InternalCircularDependencyEntity1>
|
||||||
|
}
|
||||||
|
|
||||||
|
// With un decorated prop
|
||||||
|
|
||||||
|
@Entity()
|
||||||
|
class Entity1WithUnDecoratedProp {
|
||||||
|
constructor(props: { id: string; deleted_at: Date | null }) {
|
||||||
|
this.id = props.id
|
||||||
|
this.deleted_at = props.deleted_at
|
||||||
|
}
|
||||||
|
|
||||||
|
unknownProp: string
|
||||||
|
|
||||||
|
@PrimaryKey()
|
||||||
|
id: string
|
||||||
|
|
||||||
|
@Property({ nullable: true })
|
||||||
|
deleted_at: Date | null
|
||||||
|
|
||||||
|
@OneToMany(() => Entity2WithUnDecoratedProp, (entity2) => entity2.entity1, {
|
||||||
|
cascade: ["soft-remove"] as any,
|
||||||
|
})
|
||||||
|
entity2 = new Collection<Entity2WithUnDecoratedProp>(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Entity()
|
||||||
|
class Entity2WithUnDecoratedProp {
|
||||||
|
constructor(props: {
|
||||||
|
id: string
|
||||||
|
deleted_at: Date | null
|
||||||
|
entity1: Rel<Entity1WithUnDecoratedProp>
|
||||||
|
}) {
|
||||||
|
this.id = props.id
|
||||||
|
this.deleted_at = props.deleted_at
|
||||||
|
this.entity1 = props.entity1
|
||||||
|
this.entity1_id = props.entity1.id
|
||||||
|
}
|
||||||
|
|
||||||
|
unknownProp: string
|
||||||
|
|
||||||
|
@PrimaryKey()
|
||||||
|
id: string
|
||||||
|
|
||||||
|
@Property({ nullable: true })
|
||||||
|
deleted_at: Date | null
|
||||||
|
|
||||||
|
@ManyToOne(() => Entity1WithUnDecoratedProp, { mapToPk: true })
|
||||||
|
entity1_id: string
|
||||||
|
|
||||||
|
@ManyToOne(() => Entity1WithUnDecoratedProp, { persist: false })
|
||||||
|
entity1: Rel<Entity1WithUnDecoratedProp>
|
||||||
|
}
|
||||||
|
|
||||||
|
// Searchable fields
|
||||||
|
|
||||||
|
@Entity()
|
||||||
|
class SearchableEntity1 {
|
||||||
|
constructor(props: { id: string; deleted_at: Date | null }) {
|
||||||
|
this.id = props.id
|
||||||
|
this.deleted_at = props.deleted_at
|
||||||
|
}
|
||||||
|
|
||||||
|
@PrimaryKey()
|
||||||
|
id: string
|
||||||
|
|
||||||
|
@Property({ nullable: true })
|
||||||
|
deleted_at: Date | null
|
||||||
|
|
||||||
|
@Searchable()
|
||||||
|
@Property()
|
||||||
|
searchableField: string
|
||||||
|
|
||||||
|
@Searchable()
|
||||||
|
@OneToMany(() => SearchableEntity2, (entity2) => entity2.entity1)
|
||||||
|
entity2 = new Collection<SearchableEntity2>(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Entity()
|
||||||
|
class SearchableEntity2 {
|
||||||
|
constructor(props: {
|
||||||
|
id: string
|
||||||
|
deleted_at: Date | null
|
||||||
|
entity1: SearchableEntity1
|
||||||
|
}) {
|
||||||
|
this.id = props.id
|
||||||
|
this.deleted_at = props.deleted_at
|
||||||
|
this.entity1 = props.entity1
|
||||||
|
this.entity1_id = props.entity1.id
|
||||||
|
}
|
||||||
|
|
||||||
|
@PrimaryKey()
|
||||||
|
id: string
|
||||||
|
|
||||||
|
@Property({ nullable: true })
|
||||||
|
deleted_at: Date | null
|
||||||
|
|
||||||
|
@Searchable()
|
||||||
|
@Property()
|
||||||
|
searchableField: string
|
||||||
|
|
||||||
|
@ManyToOne(() => SearchableEntity1, { mapToPk: true })
|
||||||
|
entity1_id: string
|
||||||
|
|
||||||
|
@ManyToOne(() => SearchableEntity1, { persist: false })
|
||||||
|
entity1: Rel<SearchableEntity1>
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
DeepRecursiveEntity1,
|
||||||
|
DeepRecursiveEntity2,
|
||||||
|
DeepRecursiveEntity3,
|
||||||
|
DeepRecursiveEntity4,
|
||||||
|
Entity1,
|
||||||
|
Entity1WithUnDecoratedProp,
|
||||||
|
Entity2,
|
||||||
|
Entity2WithUnDecoratedProp,
|
||||||
|
InternalCircularDependencyEntity1,
|
||||||
|
RecursiveEntity1,
|
||||||
|
RecursiveEntity2,
|
||||||
|
SearchableEntity1,
|
||||||
|
SearchableEntity2,
|
||||||
|
}
|
||||||
+4
-18
@@ -18,23 +18,9 @@ import { dropDatabase } from "pg-god"
|
|||||||
import { MikroOrmBigNumberProperty } from "../../big-number-field"
|
import { MikroOrmBigNumberProperty } from "../../big-number-field"
|
||||||
import BigNumber from "bignumber.js"
|
import BigNumber from "bignumber.js"
|
||||||
import { BigNumberRawValue } from "@medusajs/types"
|
import { BigNumberRawValue } from "@medusajs/types"
|
||||||
|
import { getDatabaseURL, pgGodCredentials } from "../__fixtures__/database"
|
||||||
|
|
||||||
const DB_HOST = process.env.DB_HOST ?? "localhost"
|
const dbName = "mikroorm-integration-1"
|
||||||
const DB_USERNAME = process.env.DB_USERNAME ?? ""
|
|
||||||
const DB_PASSWORD = process.env.DB_PASSWORD
|
|
||||||
const DB_NAME = "mikroorm-integration-1"
|
|
||||||
|
|
||||||
const pgGodCredentials = {
|
|
||||||
user: DB_USERNAME,
|
|
||||||
password: DB_PASSWORD,
|
|
||||||
host: DB_HOST,
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getDatabaseURL(): string {
|
|
||||||
return `postgres://${DB_USERNAME}${
|
|
||||||
DB_PASSWORD ? `:${DB_PASSWORD}` : ""
|
|
||||||
}@${DB_HOST}/${DB_NAME}`
|
|
||||||
}
|
|
||||||
|
|
||||||
jest.setTimeout(300000)
|
jest.setTimeout(300000)
|
||||||
@Entity()
|
@Entity()
|
||||||
@@ -153,13 +139,13 @@ describe("mikroOrmRepository", () => {
|
|||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await dropDatabase(
|
await dropDatabase(
|
||||||
{ databaseName: DB_NAME, errorIfNonExist: false },
|
{ databaseName: dbName, errorIfNonExist: false },
|
||||||
pgGodCredentials
|
pgGodCredentials
|
||||||
)
|
)
|
||||||
|
|
||||||
orm = await MikroORM.init({
|
orm = await MikroORM.init({
|
||||||
entities: [Entity1, Entity2],
|
entities: [Entity1, Entity2],
|
||||||
clientUrl: getDatabaseURL(),
|
clientUrl: getDatabaseURL(dbName),
|
||||||
type: "postgresql",
|
type: "postgresql",
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
+27
-7
@@ -1,4 +1,4 @@
|
|||||||
import { mikroOrmUpdateDeletedAtRecursively } from "../utils"
|
import { mikroOrmUpdateDeletedAtRecursively } from "../../utils"
|
||||||
import { MikroORM } from "@mikro-orm/core"
|
import { MikroORM } from "@mikro-orm/core"
|
||||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||||
import {
|
import {
|
||||||
@@ -12,6 +12,10 @@ import {
|
|||||||
RecursiveEntity1,
|
RecursiveEntity1,
|
||||||
RecursiveEntity2,
|
RecursiveEntity2,
|
||||||
} from "../__fixtures__/utils"
|
} from "../__fixtures__/utils"
|
||||||
|
import { dropDatabase } from "pg-god"
|
||||||
|
import { getDatabaseURL, pgGodCredentials } from "../__fixtures__/database"
|
||||||
|
|
||||||
|
const dbName = "mikroorm-utils-integration-1"
|
||||||
|
|
||||||
jest.mock("@mikro-orm/core", () => ({
|
jest.mock("@mikro-orm/core", () => ({
|
||||||
...jest.requireActual("@mikro-orm/core"),
|
...jest.requireActual("@mikro-orm/core"),
|
||||||
@@ -29,6 +33,11 @@ describe("mikroOrmUpdateDeletedAtRecursively", () => {
|
|||||||
let orm!: MikroORM
|
let orm!: MikroORM
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
|
await dropDatabase(
|
||||||
|
{ databaseName: dbName, errorIfNonExist: false },
|
||||||
|
pgGodCredentials
|
||||||
|
)
|
||||||
|
|
||||||
orm = await MikroORM.init({
|
orm = await MikroORM.init({
|
||||||
entities: [
|
entities: [
|
||||||
Entity1,
|
Entity1,
|
||||||
@@ -41,13 +50,19 @@ describe("mikroOrmUpdateDeletedAtRecursively", () => {
|
|||||||
DeepRecursiveEntity4,
|
DeepRecursiveEntity4,
|
||||||
InternalCircularDependencyEntity1,
|
InternalCircularDependencyEntity1,
|
||||||
],
|
],
|
||||||
dbName: "test",
|
clientUrl: getDatabaseURL(dbName),
|
||||||
type: "postgresql",
|
type: "postgresql",
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const generator = orm.getSchemaGenerator()
|
||||||
|
await generator.ensureDatabase()
|
||||||
|
await generator.createSchema()
|
||||||
})
|
})
|
||||||
|
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
await orm.close()
|
const generator = orm.getSchemaGenerator()
|
||||||
|
await generator.dropSchema()
|
||||||
|
await orm.close(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should successfully mark the entities deleted_at recursively", async () => {
|
it("should successfully mark the entities deleted_at recursively", async () => {
|
||||||
@@ -59,12 +74,14 @@ describe("mikroOrmUpdateDeletedAtRecursively", () => {
|
|||||||
entity1: entity1,
|
entity1: entity1,
|
||||||
})
|
})
|
||||||
entity1.entity2.add(entity2)
|
entity1.entity2.add(entity2)
|
||||||
|
manager.persist(entity1)
|
||||||
|
manager.persist(entity2)
|
||||||
|
|
||||||
const deletedAt = new Date()
|
const deletedAt = new Date()
|
||||||
await mikroOrmUpdateDeletedAtRecursively(manager, [entity1], deletedAt)
|
await mikroOrmUpdateDeletedAtRecursively(manager, [entity1], deletedAt)
|
||||||
|
|
||||||
expect(entity1.deleted_at).toEqual(deletedAt)
|
expect(!!entity1.deleted_at).toEqual(true)
|
||||||
expect(entity2.deleted_at).toEqual(deletedAt)
|
expect(!!entity2.deleted_at).toEqual(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should successfully mark the entities deleted_at recursively with internal parent/child relation", async () => {
|
it("should successfully mark the entities deleted_at recursively with internal parent/child relation", async () => {
|
||||||
@@ -80,11 +97,14 @@ describe("mikroOrmUpdateDeletedAtRecursively", () => {
|
|||||||
parent: entity1,
|
parent: entity1,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
manager.persist(entity1)
|
||||||
|
manager.persist(childEntity1)
|
||||||
|
|
||||||
const deletedAt = new Date()
|
const deletedAt = new Date()
|
||||||
await mikroOrmUpdateDeletedAtRecursively(manager, [entity1], deletedAt)
|
await mikroOrmUpdateDeletedAtRecursively(manager, [entity1], deletedAt)
|
||||||
|
|
||||||
expect(entity1.deleted_at).toEqual(deletedAt)
|
expect(!!entity1.deleted_at).toEqual(true)
|
||||||
expect(childEntity1.deleted_at).toEqual(deletedAt)
|
expect(!!childEntity1.deleted_at).toEqual(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should throw an error when a circular dependency is detected", async () => {
|
it("should throw an error when a circular dependency is detected", async () => {
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { EntityMetadata, FindOptions, wrap } from "@mikro-orm/core"
|
import { Collection, EntityMetadata, FindOptions, wrap } from "@mikro-orm/core"
|
||||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||||
import { buildQuery } from "../../modules-sdk/build-query"
|
import { buildQuery } from "../../modules-sdk/build-query"
|
||||||
|
|
||||||
@@ -92,28 +92,29 @@ async function performCascadingSoftDeletion<T>(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!entityRelation) {
|
|
||||||
// Fixes the case of many to many through pivot table
|
|
||||||
entityRelation = await retrieveEntity()
|
entityRelation = await retrieveEntity()
|
||||||
|
entityRelation = entityRelation[relation.name]
|
||||||
if (!entityRelation) {
|
if (!entityRelation) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
const isCollection = "toArray" in entityRelation
|
const isCollection = "toArray" in entityRelation
|
||||||
let relationEntities: any[] = []
|
let relationEntities: any[] = []
|
||||||
|
|
||||||
if (isCollection) {
|
if (isCollection) {
|
||||||
if (!entityRelation.isInitialized()) {
|
if (!(entityRelation as Collection<any, any>).isInitialized()) {
|
||||||
entityRelation = await retrieveEntity()
|
entityRelation = await retrieveEntity()
|
||||||
entityRelation = entityRelation[relation.name]
|
entityRelation = entityRelation[relation.name]
|
||||||
}
|
}
|
||||||
relationEntities = entityRelation.getItems()
|
relationEntities = entityRelation.getItems()
|
||||||
} else {
|
} else {
|
||||||
const wrappedEntity = wrap(entityRelation)
|
const wrappedEntity = wrap(entityRelation)
|
||||||
const initializedEntityRelation = wrappedEntity.isInitialized()
|
|
||||||
? entityRelation
|
let initializedEntityRelation = entityRelation
|
||||||
: await wrap(entityRelation).init()
|
if (!wrappedEntity.isInitialized()) {
|
||||||
|
initializedEntityRelation = await wrap(entityRelation).init()
|
||||||
|
}
|
||||||
|
|
||||||
relationEntities = [initializedEntityRelation]
|
relationEntities = [initializedEntityRelation]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { DAL, FindConfig } from "@medusajs/types"
|
import { DAL, FindConfig } from "@medusajs/types"
|
||||||
import { deduplicate, isDefined, isObject } from "../common"
|
import { deduplicate, isObject } from "../common"
|
||||||
|
|
||||||
import { SoftDeletableFilterKey } from "../dal/mikro-orm/mikro-orm-soft-deletable-filter"
|
import { SoftDeletableFilterKey } from "../dal/mikro-orm/mikro-orm-soft-deletable-filter"
|
||||||
|
|
||||||
@@ -18,33 +18,13 @@ export function buildQuery<T = any, TDto = any>(
|
|||||||
const filterFlags: FilterFlags = {}
|
const filterFlags: FilterFlags = {}
|
||||||
buildWhere(filters, where, filterFlags)
|
buildWhere(filters, where, filterFlags)
|
||||||
|
|
||||||
const primaryKeyFieldArray = isDefined(config.primaryKeyFields)
|
|
||||||
? !Array.isArray(config.primaryKeyFields)
|
|
||||||
? [config.primaryKeyFields]
|
|
||||||
: config.primaryKeyFields
|
|
||||||
: ["id"]
|
|
||||||
|
|
||||||
const whereHasPrimaryKeyFields = primaryKeyFieldArray.some(
|
|
||||||
(pkField) => !!where[pkField]
|
|
||||||
)
|
|
||||||
|
|
||||||
const defaultLimit = whereHasPrimaryKeyFields ? undefined : 15
|
|
||||||
|
|
||||||
delete config.primaryKeyFields
|
delete config.primaryKeyFields
|
||||||
|
|
||||||
const findOptions: DAL.OptionsQuery<T, any> = {
|
const findOptions: DAL.OptionsQuery<T, any> = {
|
||||||
populate: deduplicate(config.relations ?? []),
|
populate: deduplicate(config.relations ?? []),
|
||||||
fields: config.select as string[],
|
fields: config.select as string[],
|
||||||
limit:
|
limit: (Number.isSafeInteger(config.take) && config.take) || undefined,
|
||||||
(Number.isSafeInteger(config.take) && config.take! >= 0) ||
|
offset: (Number.isSafeInteger(config.skip) && config.skip) || undefined,
|
||||||
null === config.take
|
|
||||||
? config.take ?? undefined
|
|
||||||
: defaultLimit,
|
|
||||||
offset:
|
|
||||||
(Number.isSafeInteger(config.skip) && config.skip! >= 0) ||
|
|
||||||
null === config.skip
|
|
||||||
? config.skip ?? undefined
|
|
||||||
: 0,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.order) {
|
if (config.order) {
|
||||||
|
|||||||
@@ -272,9 +272,7 @@ export function MedusaInternalService<
|
|||||||
if (input_.selector) {
|
if (input_.selector) {
|
||||||
const entitiesToUpdate = await this.list(
|
const entitiesToUpdate = await this.list(
|
||||||
input_.selector,
|
input_.selector,
|
||||||
{
|
{},
|
||||||
take: null,
|
|
||||||
},
|
|
||||||
sharedContext
|
sharedContext
|
||||||
)
|
)
|
||||||
// Create a pair of entity and data to update
|
// Create a pair of entity and data to update
|
||||||
@@ -303,7 +301,7 @@ export function MedusaInternalService<
|
|||||||
if (keySelectorForDataOnly.$or.length) {
|
if (keySelectorForDataOnly.$or.length) {
|
||||||
const entitiesToUpdate = await this.list(
|
const entitiesToUpdate = await this.list(
|
||||||
keySelectorForDataOnly,
|
keySelectorForDataOnly,
|
||||||
{ take: null },
|
{},
|
||||||
sharedContext
|
sharedContext
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ export class ApiKeyModuleService
|
|||||||
{ revoked_at: { $gt: new Date() } },
|
{ revoked_at: { $gt: new Date() } },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{ take: null, select: ["id"] },
|
{ select: ["id"] },
|
||||||
sharedContext
|
sharedContext
|
||||||
)
|
)
|
||||||
).map((apiKey) => apiKey.id)
|
).map((apiKey) => apiKey.id)
|
||||||
@@ -445,7 +445,7 @@ export class ApiKeyModuleService
|
|||||||
{ revoked_at: { $gt: new Date() } },
|
{ revoked_at: { $gt: new Date() } },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{ take: null },
|
{},
|
||||||
sharedContext
|
sharedContext
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -500,7 +500,7 @@ export class ApiKeyModuleService
|
|||||||
{ revoked_at: { $gt: new Date() } },
|
{ revoked_at: { $gt: new Date() } },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{ take: null },
|
{},
|
||||||
sharedContext
|
sharedContext
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
+5
-8
@@ -35,10 +35,7 @@ moduleIntegrationTestRunner<ICurrencyModuleService>({
|
|||||||
|
|
||||||
describe("list", () => {
|
describe("list", () => {
|
||||||
it("list currencies", async () => {
|
it("list currencies", async () => {
|
||||||
const currenciesResult = await service.listCurrencies(
|
const currenciesResult = await service.listCurrencies({}, {})
|
||||||
{},
|
|
||||||
{ take: null }
|
|
||||||
)
|
|
||||||
expect(currenciesResult).toEqual(
|
expect(currenciesResult).toEqual(
|
||||||
expect.arrayContaining([
|
expect.arrayContaining([
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
@@ -58,7 +55,7 @@ moduleIntegrationTestRunner<ICurrencyModuleService>({
|
|||||||
it("list currencies by code", async () => {
|
it("list currencies by code", async () => {
|
||||||
const currenciesResult = await service.listCurrencies(
|
const currenciesResult = await service.listCurrencies(
|
||||||
{ code: ["usd"] },
|
{ code: ["usd"] },
|
||||||
{ take: null }
|
{}
|
||||||
)
|
)
|
||||||
|
|
||||||
expect(currenciesResult).toEqual([
|
expect(currenciesResult).toEqual([
|
||||||
@@ -72,7 +69,7 @@ moduleIntegrationTestRunner<ICurrencyModuleService>({
|
|||||||
it("list currencies by code regardless of case-sensitivity", async () => {
|
it("list currencies by code regardless of case-sensitivity", async () => {
|
||||||
const currenciesResult = await service.listCurrencies(
|
const currenciesResult = await service.listCurrencies(
|
||||||
{ code: ["Usd"] },
|
{ code: ["Usd"] },
|
||||||
{ take: null }
|
{}
|
||||||
)
|
)
|
||||||
|
|
||||||
expect(currenciesResult).toEqual([
|
expect(currenciesResult).toEqual([
|
||||||
@@ -87,7 +84,7 @@ moduleIntegrationTestRunner<ICurrencyModuleService>({
|
|||||||
describe("listAndCountCurrenciesCurrencies", () => {
|
describe("listAndCountCurrenciesCurrencies", () => {
|
||||||
it("should return currencies and count", async () => {
|
it("should return currencies and count", async () => {
|
||||||
const [currenciesResult, count] =
|
const [currenciesResult, count] =
|
||||||
await service.listAndCountCurrencies({}, { take: null })
|
await service.listAndCountCurrencies({}, {})
|
||||||
|
|
||||||
expect(count).toEqual(120)
|
expect(count).toEqual(120)
|
||||||
expect(currenciesResult).toEqual(
|
expect(currenciesResult).toEqual(
|
||||||
@@ -110,7 +107,7 @@ moduleIntegrationTestRunner<ICurrencyModuleService>({
|
|||||||
{
|
{
|
||||||
code: ["usd"],
|
code: ["usd"],
|
||||||
},
|
},
|
||||||
{ take: null }
|
{}
|
||||||
)
|
)
|
||||||
|
|
||||||
expect(count).toEqual(1)
|
expect(count).toEqual(1)
|
||||||
|
|||||||
+4
-3
@@ -3,14 +3,16 @@ import { FulfillmentSetDTO, IFulfillmentModuleService } from "@medusajs/types"
|
|||||||
import { Module, Modules } from "@medusajs/utils"
|
import { Module, Modules } from "@medusajs/utils"
|
||||||
import { FulfillmentModuleService, FulfillmentProviderService } from "@services"
|
import { FulfillmentModuleService, FulfillmentProviderService } from "@services"
|
||||||
import {
|
import {
|
||||||
SuiteOptions,
|
|
||||||
initModules,
|
initModules,
|
||||||
moduleIntegrationTestRunner,
|
moduleIntegrationTestRunner,
|
||||||
|
SuiteOptions,
|
||||||
} from "medusa-test-utils"
|
} from "medusa-test-utils"
|
||||||
import { resolve } from "path"
|
import { resolve } from "path"
|
||||||
import { createFullDataStructure } from "../../__fixtures__"
|
import { createFullDataStructure } from "../../__fixtures__"
|
||||||
import { FulfillmentProviderServiceFixtures } from "../../__fixtures__/providers"
|
import { FulfillmentProviderServiceFixtures } from "../../__fixtures__/providers"
|
||||||
|
|
||||||
|
jest.setTimeout(60000)
|
||||||
|
|
||||||
let moduleOptions = {
|
let moduleOptions = {
|
||||||
providers: [
|
providers: [
|
||||||
{
|
{
|
||||||
@@ -34,7 +36,6 @@ async function list(
|
|||||||
const finalConfig = {
|
const finalConfig = {
|
||||||
relations: [
|
relations: [
|
||||||
"service_zones.geo_zones",
|
"service_zones.geo_zones",
|
||||||
"service_zones.shipping_options.shipping_profile",
|
|
||||||
"service_zones.shipping_options.provider",
|
"service_zones.shipping_options.provider",
|
||||||
"service_zones.shipping_options.type",
|
"service_zones.shipping_options.type",
|
||||||
"service_zones.shipping_options.rules",
|
"service_zones.shipping_options.rules",
|
||||||
@@ -382,7 +383,7 @@ moduleIntegrationTestRunner({
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
await service.restoreFulfillmentSets([fulfillmentSets[0].id])
|
await service.restoreFulfillmentSets([fulfillmentSets[0].id])
|
||||||
const restoredFulfillmentSets = await list(service)
|
const restoredFulfillmentSets = await list(service, {})
|
||||||
expectSoftDeleted(restoredFulfillmentSets)
|
expectSoftDeleted(restoredFulfillmentSets)
|
||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -14,8 +14,7 @@ import {
|
|||||||
import { EntityManager } from "@mikro-orm/postgresql"
|
import { EntityManager } from "@mikro-orm/postgresql"
|
||||||
import { IndexData, IndexRelation } from "@models"
|
import { IndexData, IndexRelation } from "@models"
|
||||||
import { asValue } from "awilix"
|
import { asValue } from "awilix"
|
||||||
import { dbTestUtilFactory } from "medusa-test-utils"
|
import { TestDatabaseUtils, initDb } from "medusa-test-utils"
|
||||||
import { initDb } from "medusa-test-utils/dist/medusa-test-runner-utils/use-db"
|
|
||||||
import * as path from "path"
|
import * as path from "path"
|
||||||
import { EventBusServiceMock } from "../__fixtures__"
|
import { EventBusServiceMock } from "../__fixtures__"
|
||||||
import { dbName } from "../__fixtures__/medusa-config"
|
import { dbName } from "../__fixtures__/medusa-config"
|
||||||
@@ -25,7 +24,7 @@ const queryMock = {
|
|||||||
graph: jest.fn(),
|
graph: jest.fn(),
|
||||||
}
|
}
|
||||||
|
|
||||||
const dbUtils = dbTestUtilFactory()
|
const dbUtils = TestDatabaseUtils.dbTestUtilFactory()
|
||||||
|
|
||||||
jest.setTimeout(300000)
|
jest.setTimeout(300000)
|
||||||
|
|
||||||
|
|||||||
@@ -14,8 +14,7 @@ import {
|
|||||||
import { EntityManager } from "@mikro-orm/postgresql"
|
import { EntityManager } from "@mikro-orm/postgresql"
|
||||||
import { IndexData, IndexRelation } from "@models"
|
import { IndexData, IndexRelation } from "@models"
|
||||||
import { asValue } from "awilix"
|
import { asValue } from "awilix"
|
||||||
import { dbTestUtilFactory } from "medusa-test-utils"
|
import { TestDatabaseUtils, initDb } from "medusa-test-utils"
|
||||||
import { initDb } from "medusa-test-utils/dist/medusa-test-runner-utils/use-db"
|
|
||||||
import path from "path"
|
import path from "path"
|
||||||
import { EventBusServiceMock } from "../__fixtures__"
|
import { EventBusServiceMock } from "../__fixtures__"
|
||||||
import { dbName } from "../__fixtures__/medusa-config"
|
import { dbName } from "../__fixtures__/medusa-config"
|
||||||
@@ -25,7 +24,7 @@ const queryMock = jest.fn().mockReturnValue({
|
|||||||
graph: jest.fn(),
|
graph: jest.fn(),
|
||||||
})
|
})
|
||||||
|
|
||||||
const dbUtils = dbTestUtilFactory()
|
const dbUtils = TestDatabaseUtils.dbTestUtilFactory()
|
||||||
|
|
||||||
jest.setTimeout(300000)
|
jest.setTimeout(300000)
|
||||||
|
|
||||||
|
|||||||
@@ -1045,7 +1045,7 @@ export default class InventoryModuleService
|
|||||||
): Promise<InventoryTypes.InventoryLevelDTO> {
|
): Promise<InventoryTypes.InventoryLevelDTO> {
|
||||||
const [inventoryLevel] = await this.listInventoryLevels(
|
const [inventoryLevel] = await this.listInventoryLevels(
|
||||||
{ inventory_item_id: inventoryItemId, location_id: locationId },
|
{ inventory_item_id: inventoryItemId, location_id: locationId },
|
||||||
{ take: null },
|
{},
|
||||||
context
|
context
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ export default class NotificationModuleService
|
|||||||
{
|
{
|
||||||
idempotency_key: idempotencyKeys,
|
idempotency_key: idempotencyKeys,
|
||||||
},
|
},
|
||||||
{ take: null },
|
{},
|
||||||
context
|
context
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -384,7 +384,6 @@ moduleIntegrationTestRunner<IOrderModuleService>({
|
|||||||
{
|
{
|
||||||
select: ["id"],
|
select: ["id"],
|
||||||
relations: ["items"],
|
relations: ["items"],
|
||||||
take: null,
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
expect(orders.length).toEqual(1)
|
expect(orders.length).toEqual(1)
|
||||||
@@ -398,7 +397,6 @@ moduleIntegrationTestRunner<IOrderModuleService>({
|
|||||||
{
|
{
|
||||||
select: ["items.quantity"],
|
select: ["items.quantity"],
|
||||||
relations: ["items"],
|
relations: ["items"],
|
||||||
take: null,
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
expect(orders2.length).toEqual(0)
|
expect(orders2.length).toEqual(0)
|
||||||
@@ -414,7 +412,6 @@ moduleIntegrationTestRunner<IOrderModuleService>({
|
|||||||
{
|
{
|
||||||
select: ["id"],
|
select: ["id"],
|
||||||
relations: ["items.detail"],
|
relations: ["items.detail"],
|
||||||
take: null,
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
expect(orders3.length).toEqual(1)
|
expect(orders3.length).toEqual(1)
|
||||||
@@ -430,7 +427,6 @@ moduleIntegrationTestRunner<IOrderModuleService>({
|
|||||||
{
|
{
|
||||||
select: ["id"],
|
select: ["id"],
|
||||||
relations: ["items.detail"],
|
relations: ["items.detail"],
|
||||||
take: null,
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
expect(orders4.length).toEqual(0)
|
expect(orders4.length).toEqual(0)
|
||||||
|
|||||||
@@ -2678,7 +2678,6 @@ export default class OrderModuleService<
|
|||||||
: transactionData.order_id,
|
: transactionData.order_id,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
take: null,
|
|
||||||
select: ["id", "version"],
|
select: ["id", "version"],
|
||||||
},
|
},
|
||||||
sharedContext
|
sharedContext
|
||||||
@@ -2726,7 +2725,6 @@ export default class OrderModuleService<
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
select: ["order_id", "version", "amount"],
|
select: ["order_id", "version", "amount"],
|
||||||
take: null,
|
|
||||||
},
|
},
|
||||||
sharedContext
|
sharedContext
|
||||||
)
|
)
|
||||||
@@ -2752,7 +2750,6 @@ export default class OrderModuleService<
|
|||||||
id: transactionIds,
|
id: transactionIds,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
take: null,
|
|
||||||
select: ["order_id", "amount"],
|
select: ["order_id", "amount"],
|
||||||
},
|
},
|
||||||
sharedContext
|
sharedContext
|
||||||
@@ -2787,7 +2784,6 @@ export default class OrderModuleService<
|
|||||||
{
|
{
|
||||||
select: ["order_id", "amount"],
|
select: ["order_id", "amount"],
|
||||||
withDeleted: true,
|
withDeleted: true,
|
||||||
take: null,
|
|
||||||
},
|
},
|
||||||
sharedContext
|
sharedContext
|
||||||
)
|
)
|
||||||
@@ -2820,7 +2816,7 @@ export default class OrderModuleService<
|
|||||||
{
|
{
|
||||||
order_id: transactionData.map((trx) => trx.order_id),
|
order_id: transactionData.map((trx) => trx.order_id),
|
||||||
},
|
},
|
||||||
{ take: null },
|
{},
|
||||||
sharedContext
|
sharedContext
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ const registerProvidersInDb = async ({
|
|||||||
|
|
||||||
const existingProviders = await paymentProviderService.list(
|
const existingProviders = await paymentProviderService.list(
|
||||||
{ id: providersToLoad },
|
{ id: providersToLoad },
|
||||||
{ take: null }
|
{}
|
||||||
)
|
)
|
||||||
|
|
||||||
const upsertData: CreatePaymentProviderDTO[] = []
|
const upsertData: CreatePaymentProviderDTO[] = []
|
||||||
|
|||||||
@@ -292,7 +292,7 @@ export default class PricingModuleService
|
|||||||
// We use the price rules to get the right preferences for the price
|
// We use the price rules to get the right preferences for the price
|
||||||
const priceRulesForPrices = await this.priceRuleService_.list(
|
const priceRulesForPrices = await this.priceRuleService_.list(
|
||||||
{ price_id: priceIds },
|
{ price_id: priceIds },
|
||||||
{ take: null }
|
{}
|
||||||
)
|
)
|
||||||
|
|
||||||
const priceRulesPriceMap = groupBy(priceRulesForPrices, "price_id")
|
const priceRulesPriceMap = groupBy(priceRulesForPrices, "price_id")
|
||||||
@@ -947,7 +947,7 @@ export default class PricingModuleService
|
|||||||
) {
|
) {
|
||||||
const priceSets = await this.listPriceSets(
|
const priceSets = await this.listPriceSets(
|
||||||
{ id: input.map((d) => d.priceSetId) },
|
{ id: input.map((d) => d.priceSetId) },
|
||||||
{ take: null, relations: ["prices", "prices.price_rules"] },
|
{ relations: ["prices", "prices.price_rules"] },
|
||||||
sharedContext
|
sharedContext
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -1201,7 +1201,7 @@ export default class PricingModuleService
|
|||||||
): Promise<Price[]> {
|
): Promise<Price[]> {
|
||||||
const priceLists = await this.listPriceLists(
|
const priceLists = await this.listPriceLists(
|
||||||
{ id: data.map((p) => p.price_list_id) },
|
{ id: data.map((p) => p.price_list_id) },
|
||||||
{ take: null, relations: ["prices", "prices.price_rules"] },
|
{ relations: ["prices", "prices.price_rules"] },
|
||||||
sharedContext
|
sharedContext
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -1257,7 +1257,7 @@ export default class PricingModuleService
|
|||||||
): Promise<Price[]> {
|
): Promise<Price[]> {
|
||||||
const priceLists = await this.listPriceLists(
|
const priceLists = await this.listPriceLists(
|
||||||
{ id: data.map((p) => p.price_list_id) },
|
{ id: data.map((p) => p.price_list_id) },
|
||||||
{ take: null, relations: ["prices", "prices.price_rules"] },
|
{ relations: ["prices", "prices.price_rules"] },
|
||||||
sharedContext
|
sharedContext
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -204,7 +204,6 @@ export default class ProductModuleService
|
|||||||
product_id: [...new Set<string>(data.map((v) => v.product_id!))],
|
product_id: [...new Set<string>(data.map((v) => v.product_id!))],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
take: null,
|
|
||||||
relations: ["values"],
|
relations: ["values"],
|
||||||
},
|
},
|
||||||
sharedContext
|
sharedContext
|
||||||
@@ -326,7 +325,7 @@ export default class ProductModuleService
|
|||||||
const variantIdsToUpdate = data.map(({ id }) => id)
|
const variantIdsToUpdate = data.map(({ id }) => id)
|
||||||
const variants = await this.productVariantService_.list(
|
const variants = await this.productVariantService_.list(
|
||||||
{ id: variantIdsToUpdate },
|
{ id: variantIdsToUpdate },
|
||||||
{ take: null },
|
{},
|
||||||
sharedContext
|
sharedContext
|
||||||
)
|
)
|
||||||
if (variants.length !== data.length) {
|
if (variants.length !== data.length) {
|
||||||
@@ -354,7 +353,7 @@ export default class ProductModuleService
|
|||||||
new Set(variantsWithProductId.map((v) => v.product_id!))
|
new Set(variantsWithProductId.map((v) => v.product_id!))
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
{ take: null, relations: ["values"] },
|
{ relations: ["values"] },
|
||||||
sharedContext
|
sharedContext
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -791,7 +790,7 @@ export default class ProductModuleService
|
|||||||
|
|
||||||
const dbOptions = await this.productOptionService_.list(
|
const dbOptions = await this.productOptionService_.list(
|
||||||
{ id: data.map(({ id }) => id) },
|
{ id: data.map(({ id }) => id) },
|
||||||
{ take: null, relations: ["values"] },
|
{ relations: ["values"] },
|
||||||
sharedContext
|
sharedContext
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -1553,7 +1552,7 @@ export default class ProductModuleService
|
|||||||
if (product.variants?.length) {
|
if (product.variants?.length) {
|
||||||
allOptions = await this.productOptionService_.list(
|
allOptions = await this.productOptionService_.list(
|
||||||
{ product_id: upsertedProduct.id },
|
{ product_id: upsertedProduct.id },
|
||||||
{ take: null, relations: ["values"] },
|
{ relations: ["values"] },
|
||||||
sharedContext
|
sharedContext
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -1641,7 +1640,7 @@ export default class ProductModuleService
|
|||||||
if (productData.options?.length) {
|
if (productData.options?.length) {
|
||||||
const dbOptions = await this.productOptionService_.list(
|
const dbOptions = await this.productOptionService_.list(
|
||||||
{ product_id: productData.id },
|
{ product_id: productData.id },
|
||||||
{ take: null, relations: ["values"] },
|
{ relations: ["values"] },
|
||||||
sharedContext
|
sharedContext
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -138,7 +138,6 @@ export default class PromotionModuleService
|
|||||||
{ code: promotionCodes },
|
{ code: promotionCodes },
|
||||||
{
|
{
|
||||||
relations: ["campaign", "campaign.budget"],
|
relations: ["campaign", "campaign.budget"],
|
||||||
take: null,
|
|
||||||
},
|
},
|
||||||
sharedContext
|
sharedContext
|
||||||
)
|
)
|
||||||
@@ -245,7 +244,6 @@ export default class PromotionModuleService
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
relations: ["campaign", "campaign.budget"],
|
relations: ["campaign", "campaign.budget"],
|
||||||
take: null,
|
|
||||||
},
|
},
|
||||||
sharedContext
|
sharedContext
|
||||||
)
|
)
|
||||||
@@ -352,7 +350,7 @@ export default class PromotionModuleService
|
|||||||
? []
|
? []
|
||||||
: await this.listPromotions(
|
: await this.listPromotions(
|
||||||
{ is_automatic: true },
|
{ is_automatic: true },
|
||||||
{ select: ["code"], take: null },
|
{ select: ["code"] },
|
||||||
sharedContext
|
sharedContext
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -410,7 +408,6 @@ export default class PromotionModuleService
|
|||||||
"campaign",
|
"campaign",
|
||||||
"campaign.budget",
|
"campaign.budget",
|
||||||
],
|
],
|
||||||
take: null,
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -564,7 +561,6 @@ export default class PromotionModuleService
|
|||||||
"campaign",
|
"campaign",
|
||||||
"campaign.budget",
|
"campaign.budget",
|
||||||
],
|
],
|
||||||
take: null,
|
|
||||||
},
|
},
|
||||||
sharedContext
|
sharedContext
|
||||||
)
|
)
|
||||||
@@ -830,7 +826,6 @@ export default class PromotionModuleService
|
|||||||
"campaign",
|
"campaign",
|
||||||
"campaign.budget",
|
"campaign.budget",
|
||||||
],
|
],
|
||||||
take: null,
|
|
||||||
},
|
},
|
||||||
sharedContext
|
sharedContext
|
||||||
)
|
)
|
||||||
@@ -1275,7 +1270,6 @@ export default class PromotionModuleService
|
|||||||
{ id: createdCampaigns.map((p) => p!.id) },
|
{ id: createdCampaigns.map((p) => p!.id) },
|
||||||
{
|
{
|
||||||
relations: ["budget", "promotions"],
|
relations: ["budget", "promotions"],
|
||||||
take: null,
|
|
||||||
},
|
},
|
||||||
sharedContext
|
sharedContext
|
||||||
)
|
)
|
||||||
@@ -1385,7 +1379,6 @@ export default class PromotionModuleService
|
|||||||
{ id: updatedCampaigns.map((p) => p!.id) },
|
{ id: updatedCampaigns.map((p) => p!.id) },
|
||||||
{
|
{
|
||||||
relations: ["budget", "promotions"],
|
relations: ["budget", "promotions"],
|
||||||
take: null,
|
|
||||||
},
|
},
|
||||||
sharedContext
|
sharedContext
|
||||||
)
|
)
|
||||||
@@ -1405,7 +1398,7 @@ export default class PromotionModuleService
|
|||||||
|
|
||||||
const existingCampaigns = await this.listCampaigns(
|
const existingCampaigns = await this.listCampaigns(
|
||||||
{ id: campaignIds },
|
{ id: campaignIds },
|
||||||
{ relations: ["budget"], take: null },
|
{ relations: ["budget"] },
|
||||||
sharedContext
|
sharedContext
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -1489,7 +1482,7 @@ export default class PromotionModuleService
|
|||||||
const campaign = await this.campaignService_.retrieve(id, {}, sharedContext)
|
const campaign = await this.campaignService_.retrieve(id, {}, sharedContext)
|
||||||
const promotionsToAdd = await this.promotionService_.list(
|
const promotionsToAdd = await this.promotionService_.list(
|
||||||
{ id: promotionIds, campaign_id: null },
|
{ id: promotionIds, campaign_id: null },
|
||||||
{ take: null, relations: ["application_method"] },
|
{ relations: ["application_method"] },
|
||||||
sharedContext
|
sharedContext
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -1552,7 +1545,7 @@ export default class PromotionModuleService
|
|||||||
await this.campaignService_.retrieve(id, {}, sharedContext)
|
await this.campaignService_.retrieve(id, {}, sharedContext)
|
||||||
const promotionsToRemove = await this.promotionService_.list(
|
const promotionsToRemove = await this.promotionService_.list(
|
||||||
{ id: promotionIds },
|
{ id: promotionIds },
|
||||||
{ take: null },
|
{},
|
||||||
sharedContext
|
sharedContext
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ moduleIntegrationTestRunner<IRegionModuleService>({
|
|||||||
})
|
})
|
||||||
|
|
||||||
it("should create countries on application start", async () => {
|
it("should create countries on application start", async () => {
|
||||||
const countries = await service.listCountries({}, { take: null })
|
const countries = await service.listCountries({}, {})
|
||||||
expect(countries.length).toEqual(250)
|
expect(countries.length).toEqual(250)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -323,7 +323,7 @@ export default class RegionModuleService
|
|||||||
|
|
||||||
const countriesInDb = await this.countryService_.list(
|
const countriesInDb = await this.countryService_.list(
|
||||||
{ iso_2: uniqueCountries },
|
{ iso_2: uniqueCountries },
|
||||||
{ select: ["iso_2", "region_id"], take: null },
|
{ select: ["iso_2", "region_id"] },
|
||||||
sharedContext
|
sharedContext
|
||||||
)
|
)
|
||||||
const countryCodesInDb = countriesInDb.map((c) => c.iso_2.toLowerCase())
|
const countryCodesInDb = countriesInDb.map((c) => c.iso_2.toLowerCase())
|
||||||
|
|||||||
Reference in new issue
Block a user