Merge pull request 'fix(wine): fixed region validation' (#39) from wine-characteristics into staging
Reviewed-on: #39
This commit is contained in:
commit
3816e32289
@ -183,7 +183,9 @@ export const wineValidation = (data: unknown): Joi.ValidationResult =>
|
||||
): Joi.ErrorReport =>
|
||||
helper.message({
|
||||
custom: Joi.expression(
|
||||
`"region" contains an invalid value. Valid values for ${map.join(' -> ')} are [${options.join(', ')}]`
|
||||
options.length
|
||||
? `"region" contains an invalid value. Valid values for "${map.join(' -> ')}" are [${options.map((option) => `"${option}"`).join(', ')}]`
|
||||
: `"region" contains an invalid value. "${map.join(' -> ')}" does not have nested options`
|
||||
)
|
||||
})
|
||||
|
||||
@ -243,26 +245,24 @@ export const wineValidation = (data: unknown): Joi.ValidationResult =>
|
||||
/**
|
||||
* Village
|
||||
*/
|
||||
// list of supported villages
|
||||
const villages: string[] = Array.isArray(
|
||||
(
|
||||
(regionMap as WineRegion)[providedRegion] as {
|
||||
[key: string]: string | { [key: string]: string[] }
|
||||
}
|
||||
)[providedSubRegionName]
|
||||
)
|
||||
? ((
|
||||
(regionMap as WineRegion)[providedRegion] as {
|
||||
[key: string]: string | { [key: string]: string[] }
|
||||
}
|
||||
)[providedSubRegionName] as unknown as string[])
|
||||
: Object.keys(
|
||||
(
|
||||
(regionMap as WineRegion)[providedRegion] as {
|
||||
[key: string]: string | { [key: string]: string[] }
|
||||
}
|
||||
)[providedSubRegionName]
|
||||
const villageMap = (
|
||||
(regionMap as WineRegion)[providedRegion] as {
|
||||
[key: string]: string | { [key: string]: string[] }
|
||||
}
|
||||
)[providedSubRegionName]
|
||||
|
||||
if (villageMap === undefined) {
|
||||
return helper.message({
|
||||
custom: Joi.expression(
|
||||
`"region" contains an invalid value. "${[country, providedRegion, providedSubRegionName].join(' -> ')}" does not have villages"`
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
// list of supported villages
|
||||
const villages: string[] = Array.isArray(villageMap)
|
||||
? (villageMap as unknown as string[])
|
||||
: Object.keys(villageMap)
|
||||
|
||||
const providedVillage: string | { [key: string]: string } = (
|
||||
value[providedRegion] as {
|
||||
@ -318,6 +318,14 @@ export const wineValidation = (data: unknown): Joi.ValidationResult =>
|
||||
}
|
||||
)[providedSubRegionName][providedVillageName]
|
||||
|
||||
if (!vineyards) {
|
||||
return helper.message({
|
||||
custom: Joi.expression(
|
||||
`"region" contains an invalid value. "${[country, providedRegion, providedSubRegionName, providedVillageName].join(' -> ')}" does not have vineyards"`
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
const providedVineyard: string = (
|
||||
value[providedRegion] as {
|
||||
[key: string]: {
|
||||
|
Loading…
x
Reference in New Issue
Block a user