diff --git a/api/src/controllers/movies.ts b/api/src/controllers/movies.ts index a73e1c3c..aa046935 100644 --- a/api/src/controllers/movies.ts +++ b/api/src/controllers/movies.ts @@ -136,7 +136,7 @@ export const movies = new Elysia({ prefix: "/movies", tags: ["movies"] }) ...KError, description: comment` The Accept-Language header can't be satisfied (all languages listed are - unavailable). Try with another languages or add * to the list of languages + unavailable.) Try with another languages or add * to the list of languages to fallback to any language. `, examples: [ @@ -158,6 +158,7 @@ export const movies = new Elysia({ prefix: "/movies", tags: ["movies"] }) }) => { const langs = processLanguages(languages); const [transQ, transCol] = getTranslationQuery(langs); + // TODO: move this to typebox transform const order = sort.map((x) => { const desc = x[0] === "-"; const key = (desc ? x.substring(1) : x) as RemovePrefix; @@ -203,7 +204,11 @@ export const movies = new Elysia({ prefix: "/movies", tags: ["movies"] }) "-nextRefresh", ]), // TODO: support explode: true (allow sort=slug,-createdAt). needs a pr to elysia - { explode: false, default: ["slug"] }, + { + explode: false, + default: ["slug"], + description: "How to sort the query", + }, ), filter: t.Optional(Filter({ def: movieFilters })), limit: t.Integer({ diff --git a/api/src/models/utils/filters/index.ts b/api/src/models/utils/filters/index.ts index 0255f7da..22f19bce 100644 --- a/api/src/models/utils/filters/index.ts +++ b/api/src/models/utils/filters/index.ts @@ -24,9 +24,9 @@ export const Filter = ({ t.String({ description: comment` ${description} - This is based on [odata's filter specification](https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part1-protocol.html#sec_SystemQueryOptionfilter). - Filters available: ${Object.keys(def).join(", ")} + This is based on [odata's filter specification](https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part1-protocol.html#sec_SystemQueryOptionfilter). + Filters available: ${Object.keys(def).join(", ")}. `, example: "(rating gt 75 and genres has action) or status eq planned", }), diff --git a/api/src/utils.ts b/api/src/utils.ts index 78f8181f..e24a0ad6 100644 --- a/api/src/utils.ts +++ b/api/src/utils.ts @@ -2,7 +2,10 @@ export const comment = (str: TemplateStringsArray, ...values: any[]) => str .reduce((acc, str, i) => `${acc}${values[i - 1]}${str}`) - .replace(/(^[^\S\n]+|\s+$|^\s+)/gm, ""); + .replace(/(^\s)|(\s+$)/g, "") // first & last whitespaces + .replace(/^[ \t]+/gm, "") // leading spaces + .replace(/([^\n])\n([^\n])/g, "$1 $2") // two lines to space separated line + .replace(/\n{2}/g, "\n"); // keep newline if there's an empty line export type RemovePrefix< T extends string, diff --git a/api/tests/movies/get-movies.test.ts b/api/tests/movies/get-movies.test.ts index 53a38f95..689a34c9 100644 --- a/api/tests/movies/get-movies.test.ts +++ b/api/tests/movies/get-movies.test.ts @@ -130,7 +130,7 @@ describe("Get all movies", () => { expect(body).toMatchObject({ status: 422, message: - "Invalid property: slug.\nExpected one of genres, rating, status, runtime, airDate, originalLanguage.", + "Invalid property: slug. Expected one of genres, rating, status, runtime, airDate, originalLanguage.", details: { in: "slug eq bubble", },