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:
Stevche Radevski
2024-02-20 12:46:42 +01:00
committed by GitHub
parent c319edb8e0
commit cfefd59249
10 changed files with 436 additions and 132 deletions
@@ -1,6 +1,12 @@
import { OperatorMap } from "@medusajs/types"
import { Type } from "class-transformer"
import { IsOptional, IsString, ValidateNested } from "class-validator"
import {
IsArray,
IsObject,
IsOptional,
IsString,
ValidateNested,
} from "class-validator"
import { FindParams, extendedFindParamsMixin } from "../../../types/common"
import { OperatorMapValidator } from "../../../types/validators/operator-map"
@@ -76,6 +82,14 @@ export class AdminPostRegionsReq {
@IsString()
currency_code: string
@IsArray()
@IsOptional()
countries?: string[]
@IsObject()
@IsOptional()
metadata?: Record<string, unknown>
}
export class AdminPostRegionsRegionReq {
@@ -86,4 +100,12 @@ export class AdminPostRegionsRegionReq {
@IsString()
@IsOptional()
currency_code?: string
@IsArray()
@IsOptional()
countries?: string[]
@IsObject()
@IsOptional()
metadata?: Record<string, unknown>
}