feat(regions): Add support for updating countries in a region (#6432)
**What** Add missing support for updating countries on the POST /admin/regions/:id route. Furthermore, the PR refactors how the normalization and validation was handled in both create and update scenarios. Finally, the PR adds a unique index on the country entity, which ensures at the DB level that we cannot have a duplicate country in the DB for a single region.
This commit is contained in:
@@ -1,15 +1,30 @@
|
||||
import {
|
||||
BeforeCreate,
|
||||
Entity,
|
||||
Unique,
|
||||
ManyToOne,
|
||||
OnInit,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
Index,
|
||||
} from "@mikro-orm/core"
|
||||
|
||||
import { generateEntityId } from "@medusajs/utils"
|
||||
import {
|
||||
createPsqlIndexStatementHelper,
|
||||
generateEntityId,
|
||||
} from "@medusajs/utils"
|
||||
import Region from "./region"
|
||||
|
||||
// We don't need a partial index on deleted_at here since we don't support soft deletes on countries
|
||||
const regionIdIsoIndexName = "IDX_region_country_region_id_iso_2_unique"
|
||||
const RegionIdIsoIndexStatement = createPsqlIndexStatementHelper({
|
||||
name: regionIdIsoIndexName,
|
||||
tableName: "region_country",
|
||||
columns: ["region_id", "iso_2"],
|
||||
unique: true,
|
||||
})
|
||||
|
||||
RegionIdIsoIndexStatement.MikroORMIndex()
|
||||
@Entity({ tableName: "region_country" })
|
||||
export default class Country {
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
@@ -35,7 +50,6 @@ export default class Country {
|
||||
|
||||
@ManyToOne({
|
||||
entity: () => Region,
|
||||
index: "IDX_country_region_id",
|
||||
nullable: true,
|
||||
})
|
||||
region?: Region | null
|
||||
|
||||
Reference in New Issue
Block a user