From 601ec145dd16ab31b32f59c2700944d43b138335 Mon Sep 17 00:00:00 2001 From: Thomas Lathuiliere <40292402+balzdur@users.noreply.github.com> Date: Tue, 9 Apr 2024 15:19:09 +0200 Subject: [PATCH] feat(marble-api): handle breaking changes in marble-api (#422) --- .../src/repositories/CaseRepository.ts | 5 +- .../src/repositories/DecisionRepository.ts | 13 +- packages/marble-api/scripts/openapi.yaml | 120 ++++++++++-------- .../marble-api/src/generated/marble-api.ts | 54 ++++---- 4 files changed, 108 insertions(+), 84 deletions(-) diff --git a/packages/app-builder/src/repositories/CaseRepository.ts b/packages/app-builder/src/repositories/CaseRepository.ts index 3fb6a7e35..746c0a96b 100644 --- a/packages/app-builder/src/repositories/CaseRepository.ts +++ b/packages/app-builder/src/repositories/CaseRepository.ts @@ -44,7 +44,7 @@ export interface CaseRepository { export function getCaseRepository() { return (marbleApiClient: MarbleApi): CaseRepository => ({ - listCases: async ({ dateRange, ...rest }: CaseFilters) => { + listCases: async ({ dateRange, inboxIds, statuses }: CaseFilters) => { let startDate, endDate: string | undefined; if (dateRange?.type === 'static') { startDate = dateRange?.startDate; @@ -57,9 +57,10 @@ export function getCaseRepository() { } const { items, ...pagination } = await marbleApiClient.listCases({ - ...rest, startDate, endDate, + inboxId: inboxIds, + status: statuses, }); return { diff --git a/packages/app-builder/src/repositories/DecisionRepository.ts b/packages/app-builder/src/repositories/DecisionRepository.ts index 1bee81a39..f31338081 100644 --- a/packages/app-builder/src/repositories/DecisionRepository.ts +++ b/packages/app-builder/src/repositories/DecisionRepository.ts @@ -43,7 +43,13 @@ export interface DecisionRepository { export function getDecisionRepository() { return (marbleApiClient: MarbleApi): DecisionRepository => ({ - listDecisions: async ({ dateRange, ...rest }) => { + listDecisions: async ({ + dateRange, + outcome, + triggerObject, + scenarioId, + hasCase, + }) => { let startDate, endDate: string | undefined; if (dateRange?.type === 'static') { startDate = dateRange?.startDate; @@ -56,7 +62,10 @@ export function getDecisionRepository() { } const { items, ...pagination } = await marbleApiClient.listDecisions({ - ...rest, + outcome, + triggerObject, + scenarioId, + hasCase, startDate, endDate, }); diff --git a/packages/marble-api/scripts/openapi.yaml b/packages/marble-api/scripts/openapi.yaml index a5f20ec53..44a232936 100644 --- a/packages/marble-api/scripts/openapi.yaml +++ b/packages/marble-api/scripts/openapi.yaml @@ -107,7 +107,7 @@ paths: type: array items: $ref: '#/components/schemas/Outcome' - - name: scenarioId[] + - name: scenario_id[] description: scenario IDs used to filter the list in: query required: false @@ -116,7 +116,7 @@ paths: items: type: string format: uuid - - name: triggerObject[] + - name: trigger_object[] description: trigger objects used to filter the list in: query required: false @@ -124,32 +124,36 @@ paths: type: array items: type: string - - name: startDate - description: start date used to filter the list + - name: has_case + description: Filter decisions that have a case associated with them or not (true or false, default returns all) in: query required: false schema: - type: string - format: date-time - - name: endDate - description: end date used to filter the list + type: boolean + - name: scheduled_execution_id[] + description: scheduled execution IDs used to filter the list in: query required: false schema: - type: string - format: date-time - - name: has_case - description: 'Optional filter: the decision is attached to a case' + type: array + items: + type: string + format: uuid + - $ref: '#/components/parameters/start_date' + - $ref: '#/components/parameters/end_date' + - name: sorting + description: the field used to sort the items in: query required: false schema: - type: boolean - - $ref: '#/components/parameters/offsetId' + type: string + enum: + - created_at + - $ref: '#/components/parameters/offset_id' - $ref: '#/components/parameters/previous' - $ref: '#/components/parameters/next' - $ref: '#/components/parameters/limit' - $ref: '#/components/parameters/order' - - $ref: '#/components/parameters/sorting' responses: '200': description: List of corresponding decisions @@ -204,7 +208,7 @@ paths: security: - bearerAuth: [] parameters: - - name: statuses[] + - name: status[] description: case statuses used to filter the list in: query required: false @@ -212,7 +216,7 @@ paths: type: array items: $ref: '#/components/schemas/CaseStatus' - - name: inbox_ids[] + - name: inbox_id[] description: inbox IDs used to filter the list in: query required: false @@ -221,26 +225,21 @@ paths: items: type: string format: uuid - - name: startDate - description: start date used to filter the list - in: query - required: false - schema: - type: string - format: date-time - - name: endDate - description: end date used to filter the list + - $ref: '#/components/parameters/start_date' + - $ref: '#/components/parameters/end_date' + - name: sorting + description: the field used to sort the items in: query required: false schema: type: string - format: date-time - - $ref: '#/components/parameters/offsetId' + enum: + - created_at + - $ref: '#/components/parameters/offset_id' - $ref: '#/components/parameters/previous' - $ref: '#/components/parameters/next' - $ref: '#/components/parameters/limit' - $ref: '#/components/parameters/order' - - $ref: '#/components/parameters/sorting' responses: '200': description: List of corresponding cases @@ -2836,9 +2835,25 @@ paths: $ref: '#/components/responses/403' components: parameters: - offsetId: + start_date: in: query - name: offsetId + name: start_date + description: start date used to filter the list + required: false + schema: + type: string + format: date-time + end_date: + in: query + name: end_date + description: end date used to filter the list + required: false + schema: + type: string + format: date-time + offset_id: + in: query + name: offset_id description: the item from which to paginate required: false schema: @@ -2877,15 +2892,6 @@ components: enum: - ASC - DESC - sorting: - in: query - name: sorting - description: the field used to sort the items - required: false - schema: - type: string - enum: - - created_at schemas: OrganizationDto: type: object @@ -3686,39 +3692,43 @@ components: ScheduledExecution: type: object required: - - id - - scenario_iteration_id - - status - - started_at - finished_at + - id + - manual - number_of_created_decisions - scenario_id + - scenario_iteration_id - scenario_name - scenario_trigger_object_type + - started_at + - status properties: - id: - type: string - format: uuid - scenario_iteration_id: - type: string - format: uuid - status: - type: string - started_at: - type: string finished_at: - type: string format: date-time nullable: true + type: string + id: + format: uuid + type: string + manual: + description: Whether the execution was manual or not + type: boolean number_of_created_decisions: type: number scenario_id: + format: uuid type: string + scenario_iteration_id: format: uuid + type: string scenario_name: type: string scenario_trigger_object_type: type: string + started_at: + type: string + status: + type: string CreateDecisionBody: type: object required: diff --git a/packages/marble-api/src/generated/marble-api.ts b/packages/marble-api/src/generated/marble-api.ts index b4159112b..f9b46535f 100644 --- a/packages/marble-api/src/generated/marble-api.ts +++ b/packages/marble-api/src/generated/marble-api.ts @@ -227,15 +227,17 @@ export type Tag = { cases_count?: number; }; export type ScheduledExecution = { - id: string; - scenario_iteration_id: string; - status: string; - started_at: string; finished_at: string | null; + id: string; + /** Whether the execution was manual or not */ + manual: boolean; number_of_created_decisions: number; scenario_id: string; + scenario_iteration_id: string; scenario_name: string; scenario_trigger_object_type: string; + started_at: string; + status: string; }; export type UploadLog = { started_at: string; @@ -582,19 +584,20 @@ export function getCredentials(opts?: Oazapfts.RequestOpts) { /** * List decisions */ -export function listDecisions({ outcome, scenarioId, triggerObject, startDate, endDate, hasCase, offsetId, previous, next, limit, order, sorting }: { +export function listDecisions({ outcome, scenarioId, triggerObject, hasCase, scheduledExecutionId, startDate, endDate, sorting, offsetId, previous, next, limit, order }: { outcome?: Outcome[]; scenarioId?: string[]; triggerObject?: string[]; + hasCase?: boolean; + scheduledExecutionId?: string[]; startDate?: string; endDate?: string; - hasCase?: boolean; + sorting?: "created_at"; offsetId?: string; previous?: boolean; next?: boolean; limit?: number; order?: "ASC" | "DESC"; - sorting?: "created_at"; } = {}, opts?: Oazapfts.RequestOpts) { return oazapfts.ok(oazapfts.fetchJson<{ status: 200; @@ -609,17 +612,18 @@ export function listDecisions({ outcome, scenarioId, triggerObject, startDate, e data: string; }>(`/decisions${QS.query(QS.explode({ "outcome[]": outcome, - "scenarioId[]": scenarioId, - "triggerObject[]": triggerObject, - startDate, - endDate, + "scenario_id[]": scenarioId, + "trigger_object[]": triggerObject, has_case: hasCase, - offsetId, + "scheduled_execution_id[]": scheduledExecutionId, + start_date: startDate, + end_date: endDate, + sorting, + offset_id: offsetId, previous, next, limit, - order, - sorting + order }))}`, { ...opts })); @@ -646,17 +650,17 @@ export function createDecision(createDecisionBody: CreateDecisionBody, opts?: Oa /** * List cases */ -export function listCases({ statuses, inboxIds, startDate, endDate, offsetId, previous, next, limit, order, sorting }: { - statuses?: CaseStatus[]; - inboxIds?: string[]; +export function listCases({ status, inboxId, startDate, endDate, sorting, offsetId, previous, next, limit, order }: { + status?: CaseStatus[]; + inboxId?: string[]; startDate?: string; endDate?: string; + sorting?: "created_at"; offsetId?: string; previous?: boolean; next?: boolean; limit?: number; order?: "ASC" | "DESC"; - sorting?: "created_at"; } = {}, opts?: Oazapfts.RequestOpts) { return oazapfts.ok(oazapfts.fetchJson<{ status: 200; @@ -670,16 +674,16 @@ export function listCases({ statuses, inboxIds, startDate, endDate, offsetId, pr status: 403; data: string; }>(`/cases${QS.query(QS.explode({ - "statuses[]": statuses, - "inbox_ids[]": inboxIds, - startDate, - endDate, - offsetId, + "status[]": status, + "inbox_id[]": inboxId, + start_date: startDate, + end_date: endDate, + sorting, + offset_id: offsetId, previous, next, limit, - order, - sorting + order }))}`, { ...opts }));