Skip to content

Commit

Permalink
feat(marble-api): handle breaking changes in marble-api (#422)
Browse files Browse the repository at this point in the history
  • Loading branch information
balzdur authored Apr 9, 2024
1 parent 1da5924 commit 601ec14
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 84 deletions.
5 changes: 3 additions & 2 deletions packages/app-builder/src/repositories/CaseRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -57,9 +57,10 @@ export function getCaseRepository() {
}

const { items, ...pagination } = await marbleApiClient.listCases({
...rest,
startDate,
endDate,
inboxId: inboxIds,
status: statuses,
});

return {
Expand Down
13 changes: 11 additions & 2 deletions packages/app-builder/src/repositories/DecisionRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -56,7 +62,10 @@ export function getDecisionRepository() {
}

const { items, ...pagination } = await marbleApiClient.listDecisions({
...rest,
outcome,
triggerObject,
scenarioId,
hasCase,
startDate,
endDate,
});
Expand Down
120 changes: 65 additions & 55 deletions packages/marble-api/scripts/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -116,40 +116,44 @@ paths:
items:
type: string
format: uuid
- name: triggerObject[]
- name: trigger_object[]
description: trigger objects used to filter the list
in: query
required: false
schema:
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
Expand Down Expand Up @@ -204,15 +208,15 @@ paths:
security:
- bearerAuth: []
parameters:
- name: statuses[]
- name: status[]
description: case statuses used to filter the list
in: query
required: false
schema:
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
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
54 changes: 29 additions & 25 deletions packages/marble-api/src/generated/marble-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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
}));
Expand All @@ -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;
Expand All @@ -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
}));
Expand Down

0 comments on commit 601ec14

Please sign in to comment.