num-codex / codex-feasibility-gui

Apache License 2.0
0 stars 2 forks source link

Ensure only valid StructuredQueries are send to ui backend #34

Closed juliangruendner closed 3 years ago

juliangruendner commented 3 years ago

The ApiTranslator.js needs to be adapted, so that the query which is translated from the ui query to the StructuredQuery accepted by the ui backend adheres to the json schema definition of the StructuredQuery here:

https://github.com/num-codex/codex-structured-query/blob/main/structured-query/json-schema/2021_01_29_StructuredQuerySchema(Draft).json

The ApiTranslator.js was for example still sending an empty "exclusionCriteria" Array, when no exclusionCriteria were chosen in the ui, which is not allowed according to the specification of the StructuredQuery schema.

Task:

  1. Ensure that exlusion crtieria are only set in the result query object in the "translateToV1" function if they are non empty. -- one simple way is to check for the length of the exclusion criteria and set them to undefined:
    if (exclusionCriteria.length > 0){
      result.exclusionCriteria = this.translateCritGroupV1(exclusionCriteria)
    } else {
      result.exclusionCriteria = undefined
    }
  2. Double check if there are any other fields that need to be unset on query conversion