Skip to content

Commit

Permalink
Removing CSM props and adding "additional options"
Browse files Browse the repository at this point in the history
  • Loading branch information
GTFalcao committed Oct 31, 2024
1 parent c5a99d4 commit 3c548be
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { parseObjectEntries } from "../../common/utils.mjs";
import app from "../../gainsight_nxt.app.mjs";

export default {
Expand Down Expand Up @@ -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,
},
},
Expand All @@ -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)),
},
],
};
Expand Down
22 changes: 22 additions & 0 deletions components/gainsight_nxt/common/utils.mjs
Original file line number Diff line number Diff line change
@@ -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),
]),
);
}

0 comments on commit 3c548be

Please sign in to comment.