Correct API error on unknown field edit
This commit is contained in:
parent
8c8a6a8094
commit
522eff2031
@ -12,6 +12,10 @@ addFormats(ajv);
|
|||||||
|
|
||||||
const compiledSchemas = _.mapValues(fieldSchemaConfig, (val) => ajv.compile(val));
|
const compiledSchemas = _.mapValues(fieldSchemaConfig, (val) => ajv.compile(val));
|
||||||
|
|
||||||
|
function isDefined(key: string) {
|
||||||
|
return allAttributesConfig[key] !== undefined;
|
||||||
|
}
|
||||||
|
|
||||||
function canEdit(key: string, allowDerived: boolean = false) {
|
function canEdit(key: string, allowDerived: boolean = false) {
|
||||||
const config = allAttributesConfig[key];
|
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) {
|
export function validateFieldChange(field: string, value: any, isExternal: boolean = true) {
|
||||||
|
if(!isDefined(field)) {
|
||||||
|
throw new InvalidFieldError('Field does not exist', field);
|
||||||
|
}
|
||||||
|
|
||||||
const allowDerived = !isExternal;
|
const allowDerived = !isExternal;
|
||||||
if(!canEdit(field, allowDerived)) {
|
if(!canEdit(field, allowDerived)) {
|
||||||
throw new InvalidFieldError('Field is not editable', field);
|
throw new InvalidFieldError('Field is not editable', field);
|
||||||
|
Loading…
Reference in New Issue
Block a user