Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 102 additions & 0 deletions components/riskadvisor/actions/create-client/create-client.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import riskadvisor from "../../riskadvisor.app.mjs";

export default {
key: "riskadvisor-create-client",
name: "Create Client",
description: "Create a new client in RiskAdvisor. [See the documentation](https://api.riskadvisor.insure/clients#create-a-client)",
version: "0.0.1",
type: "action",
props: {
riskadvisor,
firstName: {
propDefinition: [
riskadvisor,
"firstName",
],
},
lastName: {
propDefinition: [
riskadvisor,
"lastName",
],
},
phoneNumber: {
propDefinition: [
riskadvisor,
"phoneNumber",
],
},
email: {
propDefinition: [
riskadvisor,
"email",
],
},
middleName: {
propDefinition: [
riskadvisor,
"middleName",
],
},
suffix: {
propDefinition: [
riskadvisor,
"suffix",
],
},
dateOfBirth: {
propDefinition: [
riskadvisor,
"dateOfBirth",
],
},
contactPreference: {
propDefinition: [
riskadvisor,
"contactPreference",
],
},
gender: {
propDefinition: [
riskadvisor,
"gender",
],
},
education: {
propDefinition: [
riskadvisor,
"education",
],
},
occupation: {
propDefinition: [
riskadvisor,
"occupation",
],
},
},
async run({ $ }) {
const response = await this.riskadvisor.createClient({
data: {
first_name: this.firstName,
last_name: this.lastName,
phone_number: this.phoneNumber,
email: this.email,
middle_name: this.middleName,
suffix: this.suffix,
date_of_birth: this.dateOfBirth,
contact_preference: this.contactPreference,
gender: this.gender,
education: this.education,
occupation: this.occupation,
},
$,
});

if (response?.id) {
$.export("$summary", `Successfully created client with ID ${response.id}.`);
}

return response;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import riskadvisor from "../../riskadvisor.app.mjs";
import constants from "../../common/constants.mjs";

export default {
key: "riskadvisor-create-risk-profile",
name: "Create Risk Profile",
description: "Creates a risk profile in RiskAdvisor. [See the documentation](https://api.riskadvisor.insure/risk-profiles#create-a-risk-profile)",
version: "0.0.1",
type: "action",
props: {
riskadvisor,
insuranceType: {
type: "string",
label: "Insurance Type",
description: "The type of insurance",
options: constants.INSURANCE_TYPES,
},
clientId: {
propDefinition: [
riskadvisor,
"clientId",
],
description: "Unique identifier for the client in the risk profile.",
},
coClientId: {
propDefinition: [
riskadvisor,
"clientId",
],
label: "Co-Client",
description: "Unique identifier for the other client in the risk profile.",
optional: true,
},
},
async run({ $ }) {
const response = await this.riskadvisor.createRiskProfile({
data: {
insurance_type: this.insuranceType,
client_id: this.clientId,
co_client_id: this.coClientId,
},
$,
});

if (response?.id) {
$.export("$summary", `Successfully created risk profile with ID ${response.id}.`);
}

return response;
},
};
131 changes: 131 additions & 0 deletions components/riskadvisor/actions/update-client/update-client.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import riskadvisor from "../../riskadvisor.app.mjs";
import lodash from "lodash";

export default {
key: "riskadvisor-update-client",
name: "Update Client",
description: "Updates an existing in RiskAdvisor. [See the documentation](https://api.riskadvisor.insure/clients#update-a-client)",
version: "0.0.1",
type: "action",
props: {
riskadvisor,
clientId: {
propDefinition: [
riskadvisor,
"clientId",
],
},
firstName: {
propDefinition: [
riskadvisor,
"firstName",
],
optional: true,
},
lastName: {
propDefinition: [
riskadvisor,
"lastName",
],
optional: true,
},
phoneNumber: {
propDefinition: [
riskadvisor,
"phoneNumber",
],
optional: true,
},
email: {
propDefinition: [
riskadvisor,
"email",
],
optional: true,
},
middleName: {
propDefinition: [
riskadvisor,
"middleName",
],
},
suffix: {
propDefinition: [
riskadvisor,
"suffix",
],
},
dateOfBirth: {
propDefinition: [
riskadvisor,
"dateOfBirth",
],
},
contactPreference: {
propDefinition: [
riskadvisor,
"contactPreference",
],
},
gender: {
propDefinition: [
riskadvisor,
"gender",
],
},
education: {
propDefinition: [
riskadvisor,
"education",
],
},
occupation: {
propDefinition: [
riskadvisor,
"occupation",
],
},
},
methods: {
// getClient endpoint "/api/clients/:id" not yet implemented in the RiskAdvisor API
// todo: update to use getClient endpoint when implemented
async getClient(clientId) {
const clients = this.riskadvisor.paginate({
resourceFn: this.riskadvisor.listClients,
});

for await (const client of clients) {
if (client.id === clientId) {
return client;
}
}
},
},
async run({ $ }) {
const client = await this.getClient(this.clientId);

const response = await this.riskadvisor.updateClient({
clientId: this.clientId,
data: lodash.pickBy({
first_name: this.firstName || client.first_name,
last_name: this.lastName || client.last_name,
phone_number: this.phoneNumber || client.phone_number,
email: this.email || client.email,
middle_name: this.middleName,
suffix: this.suffix,
date_of_birth: this.dateOfBirth,
contact_preference: this.contactPreference,
gender: this.gender,
education: this.education,
occupation: this.occupation,
}),
$,
});

if (response?.id) {
$.export("$summary", `Successfully updated client with ID ${response.id}.`);
}

return response;
},
};
13 changes: 13 additions & 0 deletions components/riskadvisor/common/constants.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const DEFAULT_LIMIT = 25;

const INSURANCE_TYPES = [
"home",
"auto",
"umbrella",
"home_auto",
];

export default {
DEFAULT_LIMIT,
INSURANCE_TYPES,
};
8 changes: 6 additions & 2 deletions components/riskadvisor/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/riskadvisor",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream RiskAdvisor Components",
"main": "riskadvisor.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,9 @@
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^1.5.1",
"lodash": "^4.17.21"
}
}
}
Loading