fix(region): Soft deleting region unsets region on countries (#7786)
**What** Unset `region_id` on countries when soft deleting the associated region. Otherwise, countries cannot be added to new or other regions Alternatively, we hard delete the region, which will trigger the DB level cascade In both cases, we cannot easily restore the region countries.
This commit is contained in:
@@ -9,6 +9,7 @@ import {
|
||||
ModulesSdkTypes,
|
||||
RegionCountryDTO,
|
||||
RegionDTO,
|
||||
SoftDeleteReturn,
|
||||
UpdateRegionDTO,
|
||||
UpsertRegionDTO,
|
||||
} from "@medusajs/types"
|
||||
@@ -129,6 +130,26 @@ export default class RegionModuleService
|
||||
return result
|
||||
}
|
||||
|
||||
@InjectManager("baseRepository_")
|
||||
// @ts-ignore
|
||||
async softDeleteRegions(
|
||||
ids: string | object | string[] | object[],
|
||||
config?: SoftDeleteReturn<string>,
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<Record<string, string[]> | void> {
|
||||
const result = await super.softDeleteRegions(ids, config, sharedContext)
|
||||
// Note: You cannot revert the state of a region by simply restoring it. The association with countries is lost.
|
||||
await super.updateCountries(
|
||||
{
|
||||
selector: { region_id: ids },
|
||||
data: { region_id: null },
|
||||
},
|
||||
sharedContext
|
||||
)
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
async upsertRegions(
|
||||
data: UpsertRegionDTO[],
|
||||
sharedContext?: Context
|
||||
|
||||
Reference in New Issue
Block a user