|
1 | 1 | import bloomerang from "../../bloomerang.app.mjs";
|
2 |
| -import { axios } from "@pipedream/platform"; |
| 2 | +import { |
| 3 | + COMMUNICATION_CHANNEL_OPTIONS, |
| 4 | + CONSTITUENT_GENDER_OPTIONS, |
| 5 | + CONSTITUENT_PREFIX_OPTIONS, |
| 6 | + CONSTITUENT_STATUS_OPTIONS, |
| 7 | + CONSTITUENT_SUFFIX_OPTIONS, |
| 8 | + CONSTITUENT_TYPE_OPTIONS, |
| 9 | +} from "../../common/constants.mjs"; |
3 | 10 |
|
4 | 11 | export default {
|
5 | 12 | key: "bloomerang-create-constituent",
|
6 | 13 | name: "Create Constituent",
|
7 |
| - description: "Creates a new constituent in Bloomerang. [See the documentation](https://bloomerang.co/product/integrations-data-management/api/rest-api/)", |
8 |
| - version: "0.0.{{ts}}", |
| 14 | + description: "Creates a new constituent in Bloomerang. [See the documentation](https://bloomerang.co/product/integrations-data-management/api/rest-api/#/Constituents/post_constituent)", |
| 15 | + version: "0.0.1", |
9 | 16 | type: "action",
|
10 | 17 | props: {
|
11 | 18 | bloomerang,
|
12 |
| - constituentType: { |
13 |
| - propDefinition: [ |
14 |
| - bloomerang, |
15 |
| - "constituentType", |
16 |
| - ], |
| 19 | + type: { |
| 20 | + type: "string", |
| 21 | + label: "Constituent Type", |
| 22 | + description: "Filter constituents by type", |
| 23 | + options: CONSTITUENT_TYPE_OPTIONS, |
| 24 | + reloadProps: true, |
| 25 | + }, |
| 26 | + status: { |
| 27 | + type: "string", |
| 28 | + label: "Status", |
| 29 | + description: "The status of the constituent", |
| 30 | + options: CONSTITUENT_STATUS_OPTIONS, |
| 31 | + optional: true, |
| 32 | + }, |
| 33 | + fullName: { |
| 34 | + type: "string", |
| 35 | + label: "Organization Name", |
| 36 | + description: "The organization's name of the constituent", |
| 37 | + hidden: true, |
17 | 38 | },
|
18 |
| - name: { |
| 39 | + firstName: { |
19 | 40 | type: "string",
|
20 |
| - label: "Name", |
21 |
| - description: "The name of the constituent", |
| 41 | + label: "First Name", |
| 42 | + description: "The first name of the constituent", |
| 43 | + hidden: true, |
22 | 44 | },
|
23 |
| - contactDetails: { |
| 45 | + lastName: { |
24 | 46 | type: "string",
|
25 |
| - label: "Contact Details", |
26 |
| - description: "Contact details of the constituent in JSON format", |
| 47 | + label: "Last Name", |
| 48 | + description: "The last name of the constituent", |
| 49 | + hidden: true, |
27 | 50 | },
|
28 |
| - address: { |
| 51 | + middleName: { |
29 | 52 | type: "string",
|
30 |
| - label: "Address", |
31 |
| - description: "Address of the constituent", |
| 53 | + label: "Middle Name", |
| 54 | + description: "The middle name of the constituent", |
32 | 55 | optional: true,
|
33 | 56 | },
|
34 |
| - tags: { |
35 |
| - type: "string[]", |
36 |
| - label: "Tags", |
37 |
| - description: "Tags for the constituent", |
| 57 | + prefix: { |
| 58 | + type: "string", |
| 59 | + label: "Title", |
| 60 | + description: "The prefix of the constituent", |
| 61 | + options: CONSTITUENT_PREFIX_OPTIONS, |
38 | 62 | optional: true,
|
39 | 63 | },
|
40 |
| - customFields: { |
41 |
| - type: "string[]", |
42 |
| - label: "Custom Fields", |
43 |
| - description: "Custom fields for the constituent in JSON format", |
| 64 | + suffix: { |
| 65 | + type: "string", |
| 66 | + label: "Suffix", |
| 67 | + description: "The suffix of the constituent", |
| 68 | + options: CONSTITUENT_SUFFIX_OPTIONS, |
| 69 | + optional: true, |
| 70 | + }, |
| 71 | + jobTitle: { |
| 72 | + type: "string", |
| 73 | + label: "Job Title", |
| 74 | + description: "The job title of the constituent", |
| 75 | + optional: true, |
| 76 | + }, |
| 77 | + gender: { |
| 78 | + type: "string", |
| 79 | + label: "Gender", |
| 80 | + description: "The gender of the constituent", |
| 81 | + options: CONSTITUENT_GENDER_OPTIONS, |
| 82 | + optional: true, |
| 83 | + }, |
| 84 | + birthdate: { |
| 85 | + type: "string", |
| 86 | + label: "Birthdate", |
| 87 | + description: "The birth date of the constituent", |
| 88 | + optional: true, |
| 89 | + }, |
| 90 | + employer: { |
| 91 | + type: "string", |
| 92 | + label: "Employer", |
| 93 | + description: "The employer of the constituent", |
| 94 | + optional: true, |
| 95 | + }, |
| 96 | + website: { |
| 97 | + type: "string", |
| 98 | + label: "Website", |
| 99 | + description: "An website of the constituent", |
| 100 | + optional: true, |
| 101 | + }, |
| 102 | + facebookId: { |
| 103 | + type: "string", |
| 104 | + label: "Facebook", |
| 105 | + description: "The constituent's facebook page", |
| 106 | + optional: true, |
| 107 | + }, |
| 108 | + twitterId: { |
| 109 | + type: "string", |
| 110 | + label: "Twitter ID", |
| 111 | + description: "The constituent's twitter ID", |
| 112 | + optional: true, |
| 113 | + }, |
| 114 | + linkedInId: { |
| 115 | + type: "string", |
| 116 | + label: "LinkedIn", |
| 117 | + description: "The constituent's linkedIn page", |
| 118 | + optional: true, |
| 119 | + }, |
| 120 | + preferredCommunicationChannel: { |
| 121 | + type: "string", |
| 122 | + label: "Preferred Communication Channel", |
| 123 | + description: "The preferred comunication channel of the constituent", |
| 124 | + options: COMMUNICATION_CHANNEL_OPTIONS, |
44 | 125 | optional: true,
|
45 | 126 | },
|
46 | 127 | },
|
| 128 | + async additionalProps(props) { |
| 129 | + const isIndividual = this.type === "Individual"; |
| 130 | + props.firstName.hidden = !isIndividual; |
| 131 | + props.lastName.hidden = !isIndividual; |
| 132 | + props.fullName.hidden = isIndividual; |
| 133 | + return {}; |
| 134 | + }, |
47 | 135 | async run({ $ }) {
|
48 |
| - const data = { |
49 |
| - constituentType: this.constituentType, |
50 |
| - name: this.name, |
51 |
| - contactDetails: JSON.parse(this.contactDetails), |
52 |
| - address: this.address |
53 |
| - ? JSON.parse(this.address) |
54 |
| - : undefined, |
55 |
| - tags: this.tags, |
56 |
| - customFields: this.customFields |
57 |
| - ? this.customFields.map(JSON.parse) |
58 |
| - : undefined, |
59 |
| - }; |
60 |
| - |
61 |
| - const response = await axios($, { |
62 |
| - method: "POST", |
63 |
| - url: `${this.bloomerang._baseUrl()}/constituents`, |
64 |
| - headers: { |
65 |
| - Authorization: `Bearer ${this.bloomerang.$auth.api_key}`, |
| 136 | + const response = await this.bloomerang.createConstituent({ |
| 137 | + $, |
| 138 | + data: { |
| 139 | + Type: this.type, |
| 140 | + Status: this.status, |
| 141 | + FullName: this.fullName, |
| 142 | + FirstName: this.firstName, |
| 143 | + LastName: this.lastName, |
| 144 | + MiddleName: this.middleName, |
| 145 | + Prefix: this.prefix, |
| 146 | + Suffix: this.suffix, |
| 147 | + JobTitle: this.jobTitle, |
| 148 | + Gender: this.gender, |
| 149 | + Birthdate: this.birthdate, |
| 150 | + Employer: this.employer, |
| 151 | + Website: this.website, |
| 152 | + FacebookId: this.facebookId, |
| 153 | + TwitterId: this.twitterId, |
| 154 | + LinkedInId: this.linkedInId, |
| 155 | + PreferredCommunicationChannel: this.preferredCommunicationChannel, |
66 | 156 | },
|
67 |
| - data, |
68 | 157 | });
|
69 | 158 |
|
70 |
| - $.export("$summary", `Successfully created constituent with ID ${response.id}`); |
| 159 | + $.export("$summary", `Successfully created constituent with ID ${response.Id}`); |
71 | 160 | return response;
|
72 | 161 | },
|
73 | 162 | };
|
0 commit comments