From 522eff20314ad55d29c1e9d1376f7a88b4ff2cd4 Mon Sep 17 00:00:00 2001 From: Maciej Ziarkowski Date: Fri, 24 Sep 2021 20:32:05 +0300 Subject: [PATCH] Correct API error on unknown field edit --- app/src/api/services/domainLogic/validateUpdate.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/src/api/services/domainLogic/validateUpdate.ts b/app/src/api/services/domainLogic/validateUpdate.ts index 1ea25cf5..b9e35d3a 100644 --- a/app/src/api/services/domainLogic/validateUpdate.ts +++ b/app/src/api/services/domainLogic/validateUpdate.ts @@ -12,6 +12,10 @@ addFormats(ajv); const compiledSchemas = _.mapValues(fieldSchemaConfig, (val) => ajv.compile(val)); +function isDefined(key: string) { + return allAttributesConfig[key] !== undefined; +} + function canEdit(key: string, allowDerived: boolean = false) { const config = allAttributesConfig[key]; @@ -19,6 +23,10 @@ function canEdit(key: string, allowDerived: boolean = false) { } export function validateFieldChange(field: string, value: any, isExternal: boolean = true) { + if(!isDefined(field)) { + throw new InvalidFieldError('Field does not exist', field); + } + const allowDerived = !isExternal; if(!canEdit(field, allowDerived)) { throw new InvalidFieldError('Field is not editable', field);