(jsonData: any)
| 358 | } |
| 359 | |
| 360 | export function validateUiPatchTask(jsonData: any): [string, number[]] { |
| 361 | ensureJsonBodyIsDict(jsonData); |
| 362 | |
| 363 | let action = jsonData.action; |
| 364 | const taskIds = jsonData.task_ids; |
| 365 | |
| 366 | if (isNullish(action)) { |
| 367 | throw new JsonHTTPResponseWithMessage("'action' must be provided"); |
| 368 | } |
| 369 | |
| 370 | if (typeof action !== 'string') { |
| 371 | throw new JsonHTTPResponseWithMessage("'action' must be a string"); |
| 372 | } |
| 373 | action = action.toLowerCase(); |
| 374 | if (!['abort', 'delete', 'retry'].includes(action)) { |
| 375 | throw new JsonHTTPResponseWithMessage('\'action\' must be either "abort", "delete", or "retry"'); |
| 376 | } |
| 377 | |
| 378 | if (isNullish(taskIds)) { |
| 379 | throw new JsonHTTPResponseWithMessage("'task_ids' must be provided. Task IDs are unique identifiers for scraping tasks."); |
| 380 | } |
| 381 | |
| 382 | if (!isListOfValidIds(taskIds)) { |
| 383 | const taskIdsStr = isObject(taskIds) || Array.isArray(taskIds) ? JSON.stringify(taskIds) : taskIds; |
| 384 | throw new JsonHTTPResponseWithMessage(`'task_ids' with value '${taskIdsStr}' must be a list of integers representing scraping tasks.`); |
| 385 | } |
| 386 | |
| 387 | return [action, taskIds]; |
| 388 | } |
| 389 | |
| 390 | // ───────────────────────────────────────────────────────── |
| 391 | // K8s Validation Functions |
no test coverage detected