chore(): Improve internal repository delete algo (#11601)
* chore(): Improve internal repository delete algo * chore(): Improve internal repository delete algo * chore(): Improve internal repository delete algo * update tests * Create purple-donkeys-learn.md * update tests
This commit is contained in:
@@ -547,7 +547,7 @@ export default class InventoryModuleService
|
||||
return
|
||||
}
|
||||
|
||||
return await this.inventoryLevelService_.delete(inventoryLevel.id, context)
|
||||
await this.inventoryLevelService_.delete(inventoryLevel.id, context)
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
|
||||
@@ -17,7 +17,7 @@ export function getLinkRepository(model: EntitySchema) {
|
||||
this.joinerConfig_ = joinerConfig
|
||||
}
|
||||
|
||||
async delete(data: any, context: Context = {}): Promise<void> {
|
||||
async delete(data: any, context: Context = {}): Promise<string[]> {
|
||||
const filter = {}
|
||||
for (const key in data) {
|
||||
filter[key] = {
|
||||
@@ -25,8 +25,7 @@ export function getLinkRepository(model: EntitySchema) {
|
||||
}
|
||||
}
|
||||
|
||||
const manager = this.getActiveManager<SqlEntityManager>(context)
|
||||
await manager.nativeDelete(model, data, {})
|
||||
return await super.delete(filter, context)
|
||||
}
|
||||
|
||||
async create(data: object[], context: Context = {}): Promise<object[]> {
|
||||
|
||||
+10
-5
@@ -1312,12 +1312,15 @@ moduleIntegrationTestRunner<IProductModuleService>({
|
||||
relations: ["images"],
|
||||
})
|
||||
|
||||
const retrievedProductAgain = await service.retrieveProduct(product.id, {
|
||||
relations: ["images"],
|
||||
})
|
||||
const retrievedProductAgain = await service.retrieveProduct(
|
||||
product.id,
|
||||
{
|
||||
relations: ["images"],
|
||||
}
|
||||
)
|
||||
|
||||
expect(retrievedProduct.images).toEqual(retrievedProductAgain.images)
|
||||
|
||||
|
||||
expect(retrievedProduct.images).toEqual(
|
||||
Array.from({ length: 1000 }, (_, i) =>
|
||||
expect.objectContaining({
|
||||
@@ -1332,7 +1335,9 @@ moduleIntegrationTestRunner<IProductModuleService>({
|
||||
// Explicitly verify sequential order
|
||||
retrievedProduct.images.forEach((img, idx) => {
|
||||
if (idx > 0) {
|
||||
expect(img.rank).toBeGreaterThan(retrievedProduct.images[idx - 1].rank)
|
||||
expect(img.rank).toBeGreaterThan(
|
||||
retrievedProduct.images[idx - 1].rank
|
||||
)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
@@ -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",
|
||||
"test:integration": "jest --forceExit -- integration-tests/__tests__/**/*.ts",
|
||||
"migration:initial": " MIKRO_ORM_CLI_CONFIG=./mikro-orm.config.dev.ts medusa-mikro-orm migration:create --initial",
|
||||
"migration:create": " MIKRO_ORM_CLI_CONFIG=./mikro-orm.config.dev.ts medusa-mikro-orm migration:create",
|
||||
"migration:up": " MIKRO_ORM_CLI_CONFIG=./mikro-orm.config.dev.ts medusa-mikro-orm migration:up",
|
||||
|
||||
@@ -272,10 +272,11 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito
|
||||
return [this.sortCategoriesByRank(categoriesTree), count]
|
||||
}
|
||||
|
||||
async delete(ids: string[], context: Context = {}): Promise<void> {
|
||||
async delete(ids: string[], context: Context = {}): Promise<string[]> {
|
||||
const manager = super.getActiveManager<SqlEntityManager>(context)
|
||||
await this.baseDelete(ids, context)
|
||||
await manager.nativeDelete(ProductCategory.name, { id: ids }, {})
|
||||
return ids
|
||||
}
|
||||
|
||||
async softDelete(
|
||||
|
||||
@@ -163,8 +163,8 @@ export default class ProductCategoryService {
|
||||
async delete(
|
||||
ids: string[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<void> {
|
||||
await this.productCategoryRepository_.delete(ids, sharedContext)
|
||||
): Promise<string[]> {
|
||||
return await this.productCategoryRepository_.delete(ids, sharedContext)
|
||||
}
|
||||
|
||||
@InjectTransactionManager("productCategoryRepository_")
|
||||
|
||||
Reference in New Issue
Block a user