-
Notifications
You must be signed in to change notification settings - Fork 0
69 - Able to update an entity with wrong fields from another entity #166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
joneubank
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just check if we use the correct error type, the name of the one used seems confusing. Otherwise these changes look correct.
| } | ||
|
|
||
| submissionSchemaErrors.updates[entityName].push( | ||
| createUnrecognizedFieldBatchError({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the correct error name? The field systemId is recognized, but the value is not found for this entity. This is an invalid value, not unrecognized field.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated code to return a INVALID_BY_RESTRICTION reason and an error object because Lectern does not provide a reason for 'INVALID_VALUE'.
Example:
{
"fieldName": "systemId",
"fieldValue": "ABC12456465",
"reason": "INVALID_BY_RESTRICTION",
"index": 0,
"errors": [
{
"message": "Value does not match any existing record.",
"restriction": {
"rule": true,
"type": "required"
}
}
],
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated code to return a UNRECOGNIZED_VALUE error.
Example:
{
"index": 0,
"reason": "UNRECOGNIZED_VALUE",
"fieldName": "systemId",
"fieldValue": "NOOOO"
}| .references(() => dictionaries.id) | ||
| .notNull(), | ||
| errors: jsonb('errors').$type<Record<string, Record<string, DictionaryValidationRecordErrorDetails[]>>>(), | ||
| errors: jsonb('errors').$type<SubmissionErrors>(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a type used for Lyric submissions, it combines Lectern dictionary errors and additional validation errors
| const unrecodgnizedValueError: SubmissionRecordErrorDetails = { | ||
| fieldName: 'systemId', | ||
| fieldValue: submissionEditData.systemId, | ||
| index, | ||
| reason: 'UNRECOGNIZED_VALUE', | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return a UNRECOGNIZED_VALUE submission error when the systemId doesn't match any record.
| if (foundSubmittedData.entityName !== schemaName) { | ||
| logger.error( | ||
| LOG_MODULE, | ||
| `Entity name mismatch for system ID '${systemId}': expected '${schemaName}', found '${foundSubmittedData.entityName}'`, | ||
| ); | ||
| results.push({ | ||
| systemId: systemId, | ||
| old: {}, | ||
| new: {}, | ||
| }); | ||
| return; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
validation added to ensure the systemId belongs to the specified entityName.
| if (!submissionSchemaErrors[actionType]) { | ||
| submissionSchemaErrors[actionType] = {}; | ||
| } | ||
| if (dictionaryValidationError.reason !== 'INVALID_RECORDS') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this function was refactored only, not related to any issue
| export type UnrecognizedValueReason = { | ||
| reason: 'UNRECOGNIZED_VALUE'; | ||
| }; | ||
|
|
||
| export type RecordErrorInvalidValue = FieldDetails & UnrecognizedValueReason; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Description
This PR fixes and issue where creating a submission to edit data by systemId on the wrong entity does not return any error.
Code changes:
INVALIDwhensystemIddoes not exists in the right entity.{}(means no data were found):Example:
Example:
{ "errors": { "updates": { "diagnosis": [ { "index": 0, "reason": "UNRECOGNIZED_VALUE", "fieldName": "systemId", "fieldValue": "1065Y2R2GWUHKD1U47E3V" }, { "index": 1, "reason": "UNRECOGNIZED_VALUE", "fieldName": "systemId", "fieldValue": "DOESNOTEXIST" } ] } } }Issue related: