Skip to content

Commit

Permalink
api: Query isHealthy field as a string to handle JSOnull (#2143)
Browse files Browse the repository at this point in the history
* api: Query isHealthy field as a string to handle JSOnull

* api: Add check on boolean fields filter value
  • Loading branch information
victorges authored Apr 23, 2024
1 parent 47dbc3c commit 1539353
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
7 changes: 7 additions & 0 deletions packages/api/src/controllers/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,13 @@ function parseFiltersRaw(fieldsMap: FieldsMap, val: string): SQLStatement[] {
q.push(sql``.append(fv).append(sql` = ${filter.value}`));
} else if (fv.val) {
if (fv.type === "boolean") {
if (typeof filter.value !== "boolean") {
throw new Error(
`expected boolean value for field "${
filter.id
}", got: ${JSON.stringify(filter.value)}`
);
}
q.push(
sql``.append(
`coalesce((${fv.val})::boolean, FALSE) IS ${
Expand Down
3 changes: 2 additions & 1 deletion packages/api/src/controllers/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,8 @@ const fieldsMap: FieldsMap = {
val: `stream.data->'transcodedSegmentsDuration'`,
type: "real",
},
isHealthy: { val: `stream.data->'isHealthy'`, type: "boolean" },
// isHealthy field is sometimes JSON-`null` so we query it as a string (->>)
isHealthy: { val: `stream.data->>'isHealthy'`, type: "boolean" },
};

app.get("/", authorizer({}), async (req, res) => {
Expand Down

0 comments on commit 1539353

Please sign in to comment.