Skip to content

Add Validation Endpoint with Configurable Category, Entity, and Field Validation#124

Merged
leoraba merged 9 commits into
mainfrom
feature/external-validation
Jul 8, 2025
Merged

Add Validation Endpoint with Configurable Category, Entity, and Field Validation#124
leoraba merged 9 commits into
mainfrom
feature/external-validation

Conversation

@Azher2Ali
Copy link
Copy Markdown
Contributor

@Azher2Ali Azher2Ali commented Dec 12, 2024

Description

This feature introduces a configurable endpoint to validate the existence of a record with a specified value. It supports checks within a specific category, organization, and entity to ensure data integrity by preventing duplicates and confirming the presence of required records.

Key Features:

Validation Endpoint:
Path: /validator/category/{categoryId}/entity/{entityName}/exists?organization={organization}&value{value}

Method: GET
Behavior:

If the record exists in the submitted_data table, returns 200 OK with body:

{
  "message": "Record found"
}

If the record does not exist, returns 404 Not found with an error response:

{
   "error": "Not found",
   "message": "The specified value was not found"
}

Configuration Requirements:

  • Added configuration properties in AppConfig to define the valid combinations of category, entity, and field.
  • Requests to the endpoint validate that category, entity, exist in the configuration. If not, returns a 400 Bad request with error response:
{
   "error": "Bad Request",
   "message": "Validation is not enabled for categoryId '${categoryId}' and entityName '${entityName}'"
}

Implemented Changes:

  • Added router ValidatorRouter for routing the new endpoint.
  • Created a ValidatorController to handle the new endpoint.
  • Developed a ValidationService to check records in the submitted_data table.
  • Defined data models for ValidationRequest and ValidationResponse.

Configuration Validation Behavior

  • Ensures the categoryId, entityName, and fieldName combinations are present in the configuration.
  • Returns 400 Not Found if validation fails.
  • This feature is crucial for applications needing configurable record validation, offering flexibility while ensuring strict data integrity standards.

Related issues:

Comment thread packages/data-provider/src/core/provider.ts Outdated
Comment thread apps/server/src/server.ts Outdated
Comment thread packages/data-provider/src/utils/schemas.ts Outdated
Comment thread packages/data-provider/src/services/validationService.ts Outdated
Copy link
Copy Markdown
Contributor

@leoraba leoraba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some comments but more importantly about the configuration part. Also more details on issue #110

Copy link
Copy Markdown
Contributor

@joneubank joneubank left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks generally good to me now that all required files are here. I'll leave it to @leoraba to give final approval on this.

@leoraba leoraba self-assigned this May 15, 2025
@leoraba leoraba requested a review from joneubank May 15, 2025 13:39
@leoraba leoraba marked this pull request as ready for review May 15, 2025 13:39
@leoraba leoraba requested a review from justincorrigible July 3, 2025 13:40
Copy link
Copy Markdown
Contributor

@joneubank joneubank left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, accomplishes our initial design goal. I think we need to update this design slightly for how we configure the end point, but that will require an additional task. This is good to be merged.

Comment thread README.md
| `LOG_LEVEL` | Log Level | 'info' |
| `PLURALIZE_SCHEMAS_ENABLED` | This feature automatically convert schema names to their plural forms when handling compound documents. Pluralization assumes the words are in English | true |
| `PORT` | Server Port | 3030 |
| `VALIDATOR_CONFIG` | Defines a configurable endpoint for validating the existence of a record with a specific value. The configuration is provided as an array of objects, where each object must include 'categoryId', 'entityName', and 'fieldName'. These entries determine which entity-field combinations are enabled for validation. (Example: `[{"categoryId": "1", "entityName": "sample", "fieldName": "sample_id" }]`) | |
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good system and does what we agreed to do, but we'll need to revisit this approach... since the categories are added as data, the validation endpoints also need to be configurable as data. This solution requires a system admin to update the config and restart the service after the category is added so that this can communicate with song.

After merging this work, let's make an additional ticket to move this info to the DB and add an endpoint to configure this per category.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

created ticket #150 to detail the work refactoring this configuration.

Comment on lines +32 to +42
const filterSqon = convertSqonToQuery(
parseSQON({
op: 'in',
content: { fieldName: field, value: [value] },
}),
);

const totalRecords = await getTotalRecordsByCategoryIdAndOrganization(categoryId, organization, {
sql: filterSqon,
entityNames: [entityName],
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works fine, but is some very awkward syntax to work with as a developer... does the SQON builder client not work for this?

Something like:

const filterSqon = SQONBuilder.in(field, value);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could also be separated in 2 parts for better understanding:

const sqonFilter = SQONBuilder.default.in(field, value);
const sqlFilter = convertSqonToQuery(sqonFilter);

I've changed the code to address this.

Comment on lines +11 to +19
export const findValidatorEntry = ({
validatorConfig,
categoryId,
entityName,
}: {
validatorConfig: ValidatorConfig;
categoryId: string;
entityName: string;
}) => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, functions signatures should declare their return types. Its good practice to be explicit about what you intend to return. In this case, its helpful to see that this could return undefined for the case where no match is found.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added return type ValidatorEntry | undefined as suggested.

@leoraba leoraba merged commit 9fb8244 into main Jul 8, 2025
2 checks passed
@leoraba leoraba deleted the feature/external-validation branch July 8, 2025 20:36
@leoraba leoraba mentioned this pull request Jul 9, 2025
leoraba added a commit that referenced this pull request Jul 9, 2025
* feat: export migration scripts (#113)

* export migration scripts

* export DbConfig from data-model

Export models

* export dist path (#116)

* Feat #120 - Get previous submissions paginated (#121)

* get submission by id

* retrieve submissions by category

* get submission by organization

* relocate submission unit tests

* Add customizable callback for post-commit (#126)

* on finish commit callback

* check record data changes

* fix bytes parsing number (#128)

* Submit data using JSON format (#133)

* remove file reading

* Update types.ts

* fix typescript error & remove deprecated endpoint

* Fix issue comparing Submitted Data property names (#136)

* remove invalid keys

* refactoring update entity data function

* split submitted data unit test file

* logging improvement

* Fix Delete submitted data issue (#137)

* return when record has no data dependencies

* filter unique records to delete

* eslint rule to enforce curly braces

* make curly linting a suggestion warning

---------

Co-authored-by: Anders Richardsson <2107110+justincorrigible@users.noreply.github.com>

* New Feature - Authentication Middleware Injection (#123)

* retrieve username from userSession

* rename config file

* rename auth middleware

* remove unused code

* custom auth handler

* auth middleware

* fix readme typos

* auth custom handle error codes

* auth write privilege

* log module

* update auth handler readme

* auth configuration

* update auth README

* updated docker compose file

* Update packages/data-provider/src/utils/authUtils.ts

Co-authored-by: Anders Richardsson <2107110+justincorrigible@users.noreply.github.com>

---------

Co-authored-by: Anders Richardsson <2107110+justincorrigible@users.noreply.github.com>

* Lyric Dev Documentation (#106)

* initializing branch for documentation site

* templated overview page

* minor fix

* minor update

* minor change

* template update

* minor + test

* updated readme

* testing branch commit issue in build

* updating contributing & code of conduct

* minor update

* updated overview page

* links

* updated image

* Updated inline with PR feedback

* minor update

* netlify link

* updated cross referenced urls to docs.overture.bio

* removed code of conduct (.github covers this) removed repository structure in readme (it is in the overview)

* updated submission system diagram

* Update README.md

---------

Co-authored-by: Leonardo Rivera <leorivera_88@hotmail.com>

* Request user authentication (#141)

* auth required on modification endpoints

* get submissions by user name

* lowercase username variable

* update auth custom handler readme

* configure protected methods

* bypass auth function

* Upgrade Lectern Client to 2.0.0-beta.4 (#144)

* fix(auth): update customAuthHandler to accpet async functions

* #26: Fix Submit new data - Data loss on Submission with multiple files (#148)

* fix submit data

* small refactor code

* Add Validation Endpoint with Configurable Category, Entity, and Field Validation (#124)

* Add Validation Endpoint with Configurable Category, Entity, and Field Validation

* validator query endpoint

* external validation config

* update documentation

* validator exists endpoint

* refactor code for readability

---------

Co-authored-by: Leonardo Rivera <leorivera_88@hotmail.com>

* 0.10.0

---------

Co-authored-by: Anders Richardsson <2107110+justincorrigible@users.noreply.github.com>
Co-authored-by: Mitchell Shiell <59712867+MitchellShiell@users.noreply.github.com>
Co-authored-by: Jon Eubank <joneubank@gmail.com>
Co-authored-by: James Lopez <jamestlopez.code@gmail.com>
Co-authored-by: Azher2Ali <121898125+Azher2Ali@users.noreply.github.com>
leoraba added a commit that referenced this pull request Jul 11, 2025
* feat: export migration scripts (#113)

* export migration scripts

* export DbConfig from data-model

Export models

* export dist path (#116)

* Feat #120 - Get previous submissions paginated (#121)

* get submission by id

* retrieve submissions by category

* get submission by organization

* relocate submission unit tests

* Add customizable callback for post-commit (#126)

* on finish commit callback

* check record data changes

* fix bytes parsing number (#128)

* Submit data using JSON format (#133)

* remove file reading

* Update types.ts

* fix typescript error & remove deprecated endpoint

* Fix issue comparing Submitted Data property names (#136)

* remove invalid keys

* refactoring update entity data function

* split submitted data unit test file

* logging improvement

* Fix Delete submitted data issue (#137)

* return when record has no data dependencies

* filter unique records to delete

* eslint rule to enforce curly braces

* make curly linting a suggestion warning

---------

Co-authored-by: Anders Richardsson <2107110+justincorrigible@users.noreply.github.com>

* New Feature - Authentication Middleware Injection (#123)

* retrieve username from userSession

* rename config file

* rename auth middleware

* remove unused code

* custom auth handler

* auth middleware

* fix readme typos

* auth custom handle error codes

* auth write privilege

* log module

* update auth handler readme

* auth configuration

* update auth README

* updated docker compose file

* Update packages/data-provider/src/utils/authUtils.ts

Co-authored-by: Anders Richardsson <2107110+justincorrigible@users.noreply.github.com>

---------

Co-authored-by: Anders Richardsson <2107110+justincorrigible@users.noreply.github.com>

* Lyric Dev Documentation (#106)

* initializing branch for documentation site

* templated overview page

* minor fix

* minor update

* minor change

* template update

* minor + test

* updated readme

* testing branch commit issue in build

* updating contributing & code of conduct

* minor update

* updated overview page

* links

* updated image

* Updated inline with PR feedback

* minor update

* netlify link

* updated cross referenced urls to docs.overture.bio

* removed code of conduct (.github covers this) removed repository structure in readme (it is in the overview)

* updated submission system diagram

* Update README.md

---------

Co-authored-by: Leonardo Rivera <leorivera_88@hotmail.com>

* Request user authentication (#141)

* auth required on modification endpoints

* get submissions by user name

* lowercase username variable

* update auth custom handler readme

* configure protected methods

* bypass auth function

* Upgrade Lectern Client to 2.0.0-beta.4 (#144)

* feat(provider): add data file template download route by data category

* Updating the lectern dependency and fixing imports

* Changes related to the feedback

* Refactoring the request validation

* Refactoring the data-model and code cleanup

* fix: Resolving Build failures

* Refactor: Minor code fixes and adding routes to files

* Refactor: Simplify type annotation

* fix(auth): update customAuthHandler to accpet async functions

* #26: Fix Submit new data - Data loss on Submission with multiple files (#148)

* fix submit data

* small refactor code

* Add Validation Endpoint with Configurable Category, Entity, and Field Validation (#124)

* Add Validation Endpoint with Configurable Category, Entity, and Field Validation

* validator query endpoint

* external validation config

* update documentation

* validator exists endpoint

* refactor code for readability

---------

Co-authored-by: Leonardo Rivera <leorivera_88@hotmail.com>

* refactor(dictionary): simplify routes and params to use categoryId

* Resolving built issues in schemas.ts

* refactor: move categoryId to path param and clean up controller imports and request parsing

* 0.11.0

---------

Co-authored-by: Anders Richardsson <2107110+justincorrigible@users.noreply.github.com>
Co-authored-by: Mitchell Shiell <59712867+MitchellShiell@users.noreply.github.com>
Co-authored-by: Jon Eubank <joneubank@gmail.com>
Co-authored-by: Azher2Ali <121898125+Azher2Ali@users.noreply.github.com>
Co-authored-by: James Lopez <jamestlopez.code@gmail.com>
leoraba added a commit that referenced this pull request Sep 16, 2025
* feat: export migration scripts (#113)

* export migration scripts

* export DbConfig from data-model

Export models

* export dist path (#116)

* Feat #120 - Get previous submissions paginated (#121)

* get submission by id

* retrieve submissions by category

* get submission by organization

* relocate submission unit tests

* Add customizable callback for post-commit (#126)

* on finish commit callback

* check record data changes

* fix bytes parsing number (#128)

* Submit data using JSON format (#133)

* remove file reading

* Update types.ts

* fix typescript error & remove deprecated endpoint

* Fix issue comparing Submitted Data property names (#136)

* remove invalid keys

* refactoring update entity data function

* split submitted data unit test file

* logging improvement

* Fix Delete submitted data issue (#137)

* return when record has no data dependencies

* filter unique records to delete

* eslint rule to enforce curly braces

* make curly linting a suggestion warning

---------

Co-authored-by: Anders Richardsson <2107110+justincorrigible@users.noreply.github.com>

* New Feature - Authentication Middleware Injection (#123)

* retrieve username from userSession

* rename config file

* rename auth middleware

* remove unused code

* custom auth handler

* auth middleware

* fix readme typos

* auth custom handle error codes

* auth write privilege

* log module

* update auth handler readme

* auth configuration

* update auth README

* updated docker compose file

* Update packages/data-provider/src/utils/authUtils.ts

Co-authored-by: Anders Richardsson <2107110+justincorrigible@users.noreply.github.com>

---------

Co-authored-by: Anders Richardsson <2107110+justincorrigible@users.noreply.github.com>

* Lyric Dev Documentation (#106)

* initializing branch for documentation site

* templated overview page

* minor fix

* minor update

* minor change

* template update

* minor + test

* updated readme

* testing branch commit issue in build

* updating contributing & code of conduct

* minor update

* updated overview page

* links

* updated image

* Updated inline with PR feedback

* minor update

* netlify link

* updated cross referenced urls to docs.overture.bio

* removed code of conduct (.github covers this) removed repository structure in readme (it is in the overview)

* updated submission system diagram

* Update README.md

---------

Co-authored-by: Leonardo Rivera <leorivera_88@hotmail.com>

* Request user authentication (#141)

* auth required on modification endpoints

* get submissions by user name

* lowercase username variable

* update auth custom handler readme

* configure protected methods

* bypass auth function

* Upgrade Lectern Client to 2.0.0-beta.4 (#144)

* feat(provider): add data file template download route by data category

* Updating the lectern dependency and fixing imports

* Changes related to the feedback

* Refactoring the request validation

* Refactoring the data-model and code cleanup

* fix: Resolving Build failures

* Refactor: Minor code fixes and adding routes to files

* Refactor: Simplify type annotation

* fix(auth): update customAuthHandler to accpet async functions

* #26: Fix Submit new data - Data loss on Submission with multiple files (#148)

* fix submit data

* small refactor code

* Add Validation Endpoint with Configurable Category, Entity, and Field Validation (#124)

* Add Validation Endpoint with Configurable Category, Entity, and Field Validation

* validator query endpoint

* external validation config

* update documentation

* validator exists endpoint

* refactor code for readability

---------

Co-authored-by: Leonardo Rivera <leorivera_88@hotmail.com>

* refactor(dictionary): simplify routes and params to use categoryId

* Resolving built issues in schemas.ts

* refactor: move categoryId to path param and clean up controller imports and request parsing

* fix(docker): resolve docker issues not connecting auth

* feat(data): add stream endpoint

* feat(view): add view to stream endpoint

* feat(transformer): add transformer config

* fix(stream): cleanup stream logic and use totalRecords

* fix(stream): fix variable increment logic

* feat(swagger): add swagger for stream

* fix(stream): resolve issues with content-type

* fix(readme): add transformer documentation

* refactor(stream): remove transformer function

* feat(helper): create isDataRecordValue helper function

* fix(util): incorrect return boolean

* chore(import): remove unused import

* chore(logger): update logger message

* feat(entityNames): add entity names filter option and comments

* feat(swagger): add entityName param

* fix(stream): bail if no data is returned

* Update Dockerfile

* 0.12.0

---------

Co-authored-by: Anders Richardsson <2107110+justincorrigible@users.noreply.github.com>
Co-authored-by: Mitchell Shiell <59712867+MitchellShiell@users.noreply.github.com>
Co-authored-by: Jon Eubank <joneubank@gmail.com>
Co-authored-by: Azher2Ali <121898125+Azher2Ali@users.noreply.github.com>
Co-authored-by: James Lopez <jamestlopez.code@gmail.com>
leoraba added a commit that referenced this pull request Sep 25, 2025
* feat: export migration scripts (#113)

* export migration scripts

* export DbConfig from data-model

Export models

* export dist path (#116)

* Feat #120 - Get previous submissions paginated (#121)

* get submission by id

* retrieve submissions by category

* get submission by organization

* relocate submission unit tests

* Add customizable callback for post-commit (#126)

* on finish commit callback

* check record data changes

* fix bytes parsing number (#128)

* Submit data using JSON format (#133)

* remove file reading

* Update types.ts

* fix typescript error & remove deprecated endpoint

* Fix issue comparing Submitted Data property names (#136)

* remove invalid keys

* refactoring update entity data function

* split submitted data unit test file

* logging improvement

* Fix Delete submitted data issue (#137)

* return when record has no data dependencies

* filter unique records to delete

* eslint rule to enforce curly braces

* make curly linting a suggestion warning

---------

Co-authored-by: Anders Richardsson <2107110+justincorrigible@users.noreply.github.com>

* New Feature - Authentication Middleware Injection (#123)

* retrieve username from userSession

* rename config file

* rename auth middleware

* remove unused code

* custom auth handler

* auth middleware

* fix readme typos

* auth custom handle error codes

* auth write privilege

* log module

* update auth handler readme

* auth configuration

* update auth README

* updated docker compose file

* Update packages/data-provider/src/utils/authUtils.ts

Co-authored-by: Anders Richardsson <2107110+justincorrigible@users.noreply.github.com>

---------

Co-authored-by: Anders Richardsson <2107110+justincorrigible@users.noreply.github.com>

* Lyric Dev Documentation (#106)

* initializing branch for documentation site

* templated overview page

* minor fix

* minor update

* minor change

* template update

* minor + test

* updated readme

* testing branch commit issue in build

* updating contributing & code of conduct

* minor update

* updated overview page

* links

* updated image

* Updated inline with PR feedback

* minor update

* netlify link

* updated cross referenced urls to docs.overture.bio

* removed code of conduct (.github covers this) removed repository structure in readme (it is in the overview)

* updated submission system diagram

* Update README.md

---------

Co-authored-by: Leonardo Rivera <leorivera_88@hotmail.com>

* Request user authentication (#141)

* auth required on modification endpoints

* get submissions by user name

* lowercase username variable

* update auth custom handler readme

* configure protected methods

* bypass auth function

* Upgrade Lectern Client to 2.0.0-beta.4 (#144)

* feat(provider): add data file template download route by data category

* Updating the lectern dependency and fixing imports

* Changes related to the feedback

* Refactoring the request validation

* Refactoring the data-model and code cleanup

* fix: Resolving Build failures

* Refactor: Minor code fixes and adding routes to files

* Refactor: Simplify type annotation

* fix(auth): update customAuthHandler to accpet async functions

* #26: Fix Submit new data - Data loss on Submission with multiple files (#148)

* fix submit data

* small refactor code

* Add Validation Endpoint with Configurable Category, Entity, and Field Validation (#124)

* Add Validation Endpoint with Configurable Category, Entity, and Field Validation

* validator query endpoint

* external validation config

* update documentation

* validator exists endpoint

* refactor code for readability

---------

Co-authored-by: Leonardo Rivera <leorivera_88@hotmail.com>

* refactor(dictionary): simplify routes and params to use categoryId

* Resolving built issues in schemas.ts

* refactor: move categoryId to path param and clean up controller imports and request parsing

* fix(docker): resolve docker issues not connecting auth

* feat(data): add stream endpoint

* feat(view): add view to stream endpoint

* feat(transformer): add transformer config

* fix(stream): cleanup stream logic and use totalRecords

* fix(stream): fix variable increment logic

* feat(swagger): add swagger for stream

* fix(stream): resolve issues with content-type

* fix(readme): add transformer documentation

* refactor(stream): remove transformer function

* feat(helper): create isDataRecordValue helper function

* fix(util): incorrect return boolean

* chore(import): remove unused import

* chore(logger): update logger message

* feat(entityNames): add entity names filter option and comments

* feat(swagger): add entityName param

* fix(stream): bail if no data is returned

* Update Dockerfile

* #79: Enable auth to read data (#157)

* enable auth to read data

* read access validation

* filter repository by organization

* custom request user session

* code refactoring

* 0.13.0

* version 0.13.0

---------

Co-authored-by: Anders Richardsson <2107110+justincorrigible@users.noreply.github.com>
Co-authored-by: Mitchell Shiell <59712867+MitchellShiell@users.noreply.github.com>
Co-authored-by: Jon Eubank <joneubank@gmail.com>
Co-authored-by: Azher2Ali <121898125+Azher2Ali@users.noreply.github.com>
Co-authored-by: James Lopez <jamestlopez.code@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants