From 3c548be88224d00c81aa21f85d8e432c3f43d04b Mon Sep 17 00:00:00 2001 From: GTFalcao Date: Thu, 31 Oct 2024 16:07:12 -0300 Subject: [PATCH] Removing CSM props and adding "additional options" --- .../create-or-update-company.mjs | 26 +++++-------------- components/gainsight_nxt/common/utils.mjs | 22 ++++++++++++++++ 2 files changed, 29 insertions(+), 19 deletions(-) create mode 100644 components/gainsight_nxt/common/utils.mjs diff --git a/components/gainsight_nxt/actions/create-or-update-company/create-or-update-company.mjs b/components/gainsight_nxt/actions/create-or-update-company/create-or-update-company.mjs index 5cad58c2f169f..9e0f536672c31 100644 --- a/components/gainsight_nxt/actions/create-or-update-company/create-or-update-company.mjs +++ b/components/gainsight_nxt/actions/create-or-update-company/create-or-update-company.mjs @@ -1,3 +1,4 @@ +import { parseObjectEntries } from "../../common/utils.mjs"; import app from "../../gainsight_nxt.app.mjs"; export default { @@ -74,22 +75,11 @@ export default { "Churn", ], }, - csmFirstName: { - type: "string", - label: "CSM First Name", - description: "The first name of the POC of the company.", - optional: true, - }, - csmLastName: { - type: "string", - label: "CSM Last Name", - description: "The last name of the POC of the company.", - optional: true, - }, - parentCompanyName: { - type: "string", - label: "Parent Company Name", - description: "The name of the parent company.", + additionalOptions: { + type: "object", + label: "Additional Options", + description: + "Additional parameters to send in the request. [See the documentation](https://support.gainsight.com/gainsight_nxt/API_and_Developer_Docs/Company_and_Relationship_API/Company_API_Documentation#Parameters) for available parameters. Values will be parsed as JSON where applicable.", optional: true, }, }, @@ -106,9 +96,7 @@ export default { RenewalDate: this.renewalDate, Stage: this.stage, Status: this.status, - CSMFirstName: this.csmFirstName, - CSMLastName: this.csmLastName, - ParentCompanyName: this.parentCompanyName, + ...(this.additionalOptions && parseObjectEntries(this.additionalOptions)), }, ], }; diff --git a/components/gainsight_nxt/common/utils.mjs b/components/gainsight_nxt/common/utils.mjs new file mode 100644 index 0000000000000..9c3cdbf569744 --- /dev/null +++ b/components/gainsight_nxt/common/utils.mjs @@ -0,0 +1,22 @@ +function optionalParseAsJSON(value) { + try { + return JSON.parse(value); + } catch (e) { + return value; + } +} + +export function parseObjectEntries(value) { + const obj = typeof value === "string" + ? JSON.parse(value) + : value; + return Object.fromEntries( + Object.entries(obj).map(([ + key, + value, + ]) => [ + key, + optionalParseAsJSON(value), + ]), + ); +}