From 08952e59cf0c94e8c4eaae26586779f4d63f9d5b Mon Sep 17 00:00:00 2001 From: Dusan Radovanovic Date: Tue, 9 Aug 2022 00:01:09 -0700 Subject: [PATCH 1/3] feat(Flows): Support for flow relationships --- src/endpoints/flows.js | 34 ++++++++++++++++++++++++++++++++++ src/types/flow.d.ts | 6 ++++++ 2 files changed, 40 insertions(+) diff --git a/src/endpoints/flows.js b/src/endpoints/flows.js index 6834df7e8..d511926cc 100644 --- a/src/endpoints/flows.js +++ b/src/endpoints/flows.js @@ -121,6 +121,40 @@ class FlowsEndpoint extends CRUDExtend { token ) } + + CreateFlowRelationship(srcType, srcId, targetType, resources) { + const srcEndpoint = getEndpoint(srcType); + const body = buildRelationshipData(targetType, resources) + const parsedType = formatUrlResource(targetType) + + return this.request.send( + `${srcEndpoint}/${srcId}/relationships/${parsedType}`, + 'POST', + body + ) + } + + DeleteFlowRelationships(srcType, srcId, targetType) { + const srcEndpoint = getEndpoint(srcType); + const parsedType = formatUrlResource(targetType) + + return this.request.send( + `${srcEndpoint}/${srcId}/relationships/${parsedType}`, + 'DELETE' + ) + } + + UpdateRelationships(srcType, srcId, targetType, resources = null) { + const srcEndpoint = getEndpoint(srcType); + const body = buildRelationshipData(targetType, resources) + const parsedType = formatUrlResource(targetType) + + return this.request.send( + `${srcEndpoint}/${srcId}/relationships/${parsedType}`, + 'PUT', + body + ) + } } export default FlowsEndpoint diff --git a/src/types/flow.d.ts b/src/types/flow.d.ts index 20bc4d863..3103ccf65 100644 --- a/src/types/flow.d.ts +++ b/src/types/flow.d.ts @@ -98,4 +98,10 @@ export interface FlowEndpoint { Attributes(token?: string): Promise GetFlowTypeAttributes(flowType: string, token?: string): Promise + + CreateFlowRelationship(srcType: string, srcId: string, targetType: string, resources?: string | any[]): Promise + + DeleteFlowRelationships(srcType: string, srcId: string, targetType: string): Promise + + UpdateRelationships(srcType: string, srcId: string, targetType: string, resources?: string | any[]): Promise } From 0dc82690584f2600b87498a1932b882db1155203 Mon Sep 17 00:00:00 2001 From: Dusan Radovanovic Date: Tue, 9 Aug 2022 23:45:39 -0700 Subject: [PATCH 2/3] Updated CreateFlowRelationship API --- src/endpoints/flows.js | 55 +++++++++++++++++++++--------------------- src/types/flow.d.ts | 6 ++--- 2 files changed, 30 insertions(+), 31 deletions(-) diff --git a/src/endpoints/flows.js b/src/endpoints/flows.js index d511926cc..2b6310e6f 100644 --- a/src/endpoints/flows.js +++ b/src/endpoints/flows.js @@ -122,39 +122,38 @@ class FlowsEndpoint extends CRUDExtend { ) } - CreateFlowRelationship(srcType, srcId, targetType, resources) { - const srcEndpoint = getEndpoint(srcType); - const body = buildRelationshipData(targetType, resources) - const parsedType = formatUrlResource(targetType) - + CreateFlowRelationship(flowSlug, fieldSlug, srcId, targetType, targetId) { return this.request.send( - `${srcEndpoint}/${srcId}/relationships/${parsedType}`, + `v2/flows/${flowSlug}/entries/${srcId}/relationships/${fieldSlug}`, 'POST', - body - ) - } - - DeleteFlowRelationships(srcType, srcId, targetType) { - const srcEndpoint = getEndpoint(srcType); - const parsedType = formatUrlResource(targetType) - - return this.request.send( - `${srcEndpoint}/${srcId}/relationships/${parsedType}`, - 'DELETE' + { + type: targetType, + id: targetId, + }, ) } - UpdateRelationships(srcType, srcId, targetType, resources = null) { - const srcEndpoint = getEndpoint(srcType); - const body = buildRelationshipData(targetType, resources) - const parsedType = formatUrlResource(targetType) - - return this.request.send( - `${srcEndpoint}/${srcId}/relationships/${parsedType}`, - 'PUT', - body - ) - } + // DeleteFlowRelationships(srcType, srcId, targetType) { + // const srcEndpoint = getEndpoint(srcType); + // const parsedType = formatUrlResource(targetType) + + // return this.request.send( + // `${srcEndpoint}/${srcId}/relationships/${parsedType}`, + // 'DELETE' + // ) + // } + + // UpdateRelationships(srcType, srcId, targetType, resources = null) { + // const srcEndpoint = getEndpoint(srcType); + // const body = buildRelationshipData(targetType, resources) + // const parsedType = formatUrlResource(targetType) + + // return this.request.send( + // `${srcEndpoint}/${srcId}/relationships/${parsedType}`, + // 'PUT', + // body + // ) + // } } export default FlowsEndpoint diff --git a/src/types/flow.d.ts b/src/types/flow.d.ts index 3103ccf65..9aad5c257 100644 --- a/src/types/flow.d.ts +++ b/src/types/flow.d.ts @@ -99,9 +99,9 @@ export interface FlowEndpoint { GetFlowTypeAttributes(flowType: string, token?: string): Promise - CreateFlowRelationship(srcType: string, srcId: string, targetType: string, resources?: string | any[]): Promise + CreateFlowRelationship(flowSlug: string, fieldSlug: string, srcId: string, targetType: string, targetId: string): Promise - DeleteFlowRelationships(srcType: string, srcId: string, targetType: string): Promise + // DeleteFlowRelationships(srcType: string, srcId: string, targetType: string): Promise - UpdateRelationships(srcType: string, srcId: string, targetType: string, resources?: string | any[]): Promise + // UpdateRelationships(srcType: string, srcId: string, targetType: string, resources?: string | any[]): Promise } From 210891cb98b6341b3da9b3684d345e8e1465a753 Mon Sep 17 00:00:00 2001 From: Dusan Radovanovic Date: Wed, 10 Aug 2022 16:05:49 -0700 Subject: [PATCH 3/3] New APIs --- src/endpoints/flows.js | 48 +++++++++++++++++++----------------------- src/types/flow.d.ts | 7 +++--- 2 files changed, 26 insertions(+), 29 deletions(-) diff --git a/src/endpoints/flows.js b/src/endpoints/flows.js index 2b6310e6f..78eb402e3 100644 --- a/src/endpoints/flows.js +++ b/src/endpoints/flows.js @@ -122,38 +122,34 @@ class FlowsEndpoint extends CRUDExtend { ) } - CreateFlowRelationship(flowSlug, fieldSlug, srcId, targetType, targetId) { + CreateFlowRelationship(endpoint, srcId, flowSlug, targetType, targetId) { return this.request.send( - `v2/flows/${flowSlug}/entries/${srcId}/relationships/${fieldSlug}`, + `${endpoint}/${srcId}/relationships/${flowSlug}`, 'POST', { - type: targetType, - id: targetId, - }, + type: targetType, + id: targetId + } + ) + } + + DeleteFlowRelationship(endpoint, srcId, flowSlug) { + return this.request.send( + `${endpoint}/${srcId}/relationships/${flowSlug}`, + 'DELETE' ) } - // DeleteFlowRelationships(srcType, srcId, targetType) { - // const srcEndpoint = getEndpoint(srcType); - // const parsedType = formatUrlResource(targetType) - - // return this.request.send( - // `${srcEndpoint}/${srcId}/relationships/${parsedType}`, - // 'DELETE' - // ) - // } - - // UpdateRelationships(srcType, srcId, targetType, resources = null) { - // const srcEndpoint = getEndpoint(srcType); - // const body = buildRelationshipData(targetType, resources) - // const parsedType = formatUrlResource(targetType) - - // return this.request.send( - // `${srcEndpoint}/${srcId}/relationships/${parsedType}`, - // 'PUT', - // body - // ) - // } + UpdateFlowRelationship(endpoint, srcId, flowSlug, targetType, targetId) { + return this.request.send( + `${endpoint}/${srcId}/relationships/${flowSlug}`, + 'PUT', + { + type: targetType, + id: targetId + } + ) + } } export default FlowsEndpoint diff --git a/src/types/flow.d.ts b/src/types/flow.d.ts index 9aad5c257..f80f4168f 100644 --- a/src/types/flow.d.ts +++ b/src/types/flow.d.ts @@ -99,9 +99,10 @@ export interface FlowEndpoint { GetFlowTypeAttributes(flowType: string, token?: string): Promise - CreateFlowRelationship(flowSlug: string, fieldSlug: string, srcId: string, targetType: string, targetId: string): Promise - // DeleteFlowRelationships(srcType: string, srcId: string, targetType: string): Promise + CreateFlowRelationship(endpoint: string, srcId: string, flowSlug: string, targetType: string, targetId: string) - // UpdateRelationships(srcType: string, srcId: string, targetType: string, resources?: string | any[]): Promise + DeleteFlowRelationship(endpoint: string, srcId: string, flowSlug: string) + + UpdateFlowRelationship(endpoint: string, srcId: string, flowSlug: string, targetType: string, targetId: string) }