fix: Remove undefined from events in update (#10170)
This commit is contained in:
@@ -20,8 +20,10 @@ import {
|
||||
upperCaseFirst,
|
||||
} from "../common"
|
||||
import { DmlEntity } from "../dml"
|
||||
import { CommonEvents } from "../event-bus"
|
||||
import { EmitEvents, InjectManager, MedusaContext } from "./decorators"
|
||||
import { Modules } from "./definition"
|
||||
import { moduleEventBuilderFactory } from "./event-builder-factory"
|
||||
import { buildModelsNameToLinkableKeysMap } from "./joiner-config-builder"
|
||||
import {
|
||||
BaseMethods,
|
||||
@@ -31,8 +33,6 @@ import {
|
||||
ModelEntries,
|
||||
ModelsConfigTemplate,
|
||||
} from "./types/medusa-service"
|
||||
import { CommonEvents } from "../event-bus"
|
||||
import { moduleEventBuilderFactory } from "./event-builder-factory"
|
||||
|
||||
const readMethods = ["retrieve", "list", "listAndCount"] as BaseMethods[]
|
||||
const writeMethods = [
|
||||
@@ -215,7 +215,11 @@ export function MedusaService<
|
||||
const serviceData = Array.isArray(data) ? data : [data]
|
||||
const service = this.__container__[serviceRegistrationName]
|
||||
const models = await service.update(serviceData, sharedContext)
|
||||
const response = Array.isArray(data) ? models : models[0]
|
||||
const response = models.length
|
||||
? Array.isArray(data)
|
||||
? models
|
||||
: models[0]
|
||||
: []
|
||||
|
||||
klassPrototype.aggregatedEvents.bind(this)({
|
||||
action: CommonEvents.UPDATED,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { IRegionModuleService } from "@medusajs/framework/types"
|
||||
import { Module, Modules } from "@medusajs/framework/utils"
|
||||
import { RegionModuleService } from "@services"
|
||||
import { moduleIntegrationTestRunner } from "@medusajs/test-utils"
|
||||
import { RegionModuleService } from "@services"
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
@@ -403,6 +403,32 @@ moduleIntegrationTestRunner<IRegionModuleService>({
|
||||
expect(resp.countries).toHaveLength(2)
|
||||
})
|
||||
|
||||
it("should delete a region without countries", async () => {
|
||||
const createdRegion = await service.createRegions({
|
||||
name: "North America",
|
||||
currency_code: "USD",
|
||||
countries: [],
|
||||
})
|
||||
|
||||
await service.softDeleteRegions([createdRegion.id])
|
||||
|
||||
const [deletedRegion] = await service.listRegions(
|
||||
{ id: createdRegion.id },
|
||||
{ withDeleted: true }
|
||||
)
|
||||
|
||||
expect(deletedRegion).toEqual({
|
||||
id: createdRegion.id,
|
||||
name: createdRegion.name,
|
||||
currency_code: createdRegion.currency_code,
|
||||
metadata: null,
|
||||
automatic_taxes: createdRegion.automatic_taxes,
|
||||
created_at: expect.any(Date),
|
||||
updated_at: expect.any(Date),
|
||||
deleted_at: expect.any(Date),
|
||||
})
|
||||
})
|
||||
|
||||
it("should unset the region ID on the country when soft deleting a region", async () => {
|
||||
const createdRegion = await service.createRegions({
|
||||
name: "North America",
|
||||
|
||||
Reference in New Issue
Block a user