(jsonData: any, allowedViews: string[])
| 200 | } |
| 201 | |
| 202 | export function validateView(jsonData: any, allowedViews: string[]): string | undefined { |
| 203 | let view = jsonData.view; |
| 204 | |
| 205 | if (isNotNullish(view)) { |
| 206 | if (!isStringOfMinLength(view)) { |
| 207 | throw new JsonHTTPResponseWithMessage('View must be a string with at least one character'); |
| 208 | } |
| 209 | |
| 210 | view = view.toLowerCase(); |
| 211 | if (!allowedViews.includes(view)) { |
| 212 | throw new JsonHTTPResponseWithMessage(`Invalid view. Must be one of: ${allowedViews.join(', ')}.`); |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | return view; |
| 217 | } |
| 218 | |
| 219 | export function validateSort(jsonData: any, allowedSorts: string[], defaultSort: string): string | null { |
| 220 | let sort = jsonData.sort ?? defaultSort; |
no test coverage detected