|
1 | 1 | import alegra from "../../alegra.app.mjs"; |
2 | | -import { axios } from "@pipedream/platform"; |
| 2 | +import { |
| 3 | + STATUS_OPTIONS, |
| 4 | + TYPE_OPTIONS, |
| 5 | +} from "../../common/constants.mjs"; |
| 6 | +import { parseObject } from "../../common/utils.mjs"; |
3 | 7 |
|
4 | 8 | export default { |
5 | 9 | key: "alegra-create-contact", |
6 | 10 | name: "Create Contact", |
7 | | - description: "Adds a new contact to Alegra. [See the documentation]().", |
8 | | - version: "0.0.{{ts}}", |
| 11 | + description: "Adds a new contact to Alegra. [See the documentation](https://developer.alegra.com/reference/post_contacts).", |
| 12 | + version: "0.0.1", |
9 | 13 | type: "action", |
10 | 14 | props: { |
11 | 15 | alegra, |
12 | 16 | name: { |
13 | | - propDefinition: [ |
14 | | - "alegra", |
15 | | - "name", |
16 | | - ], |
| 17 | + type: "string", |
| 18 | + label: "Name", |
| 19 | + description: "Name of the contact", |
17 | 20 | }, |
18 | 21 | identification: { |
19 | | - propDefinition: [ |
20 | | - "alegra", |
21 | | - "identification", |
22 | | - ], |
| 22 | + type: "string", |
| 23 | + label: "Identification", |
| 24 | + description: "Identification of the contact", |
23 | 25 | optional: true, |
24 | 26 | }, |
25 | 27 | address: { |
26 | | - propDefinition: [ |
27 | | - "alegra", |
28 | | - "address", |
29 | | - ], |
| 28 | + type: "string", |
| 29 | + label: "Address", |
| 30 | + description: "Address of the contact", |
30 | 31 | optional: true, |
31 | 32 | }, |
32 | 33 | city: { |
33 | | - propDefinition: [ |
34 | | - "alegra", |
35 | | - "city", |
36 | | - ], |
| 34 | + type: "string", |
| 35 | + label: "City", |
| 36 | + description: "City of the contact", |
37 | 37 | optional: true, |
38 | 38 | }, |
39 | 39 | phonePrimary: { |
40 | | - propDefinition: [ |
41 | | - "alegra", |
42 | | - "phonePrimary", |
43 | | - ], |
| 40 | + type: "string", |
| 41 | + label: "Primary Phone", |
| 42 | + description: "Primary phone number of the contact", |
44 | 43 | optional: true, |
45 | 44 | }, |
46 | 45 | phoneSecondary: { |
47 | | - propDefinition: [ |
48 | | - "alegra", |
49 | | - "phoneSecondary", |
50 | | - ], |
| 46 | + type: "string", |
| 47 | + label: "Secondary Phone", |
| 48 | + description: "Secondary phone number of the contact", |
51 | 49 | optional: true, |
52 | 50 | }, |
53 | 51 | mobile: { |
54 | | - propDefinition: [ |
55 | | - "alegra", |
56 | | - "mobile", |
57 | | - ], |
| 52 | + type: "string", |
| 53 | + label: "Mobile", |
| 54 | + description: "Mobile phone number of the contact", |
58 | 55 | optional: true, |
59 | 56 | }, |
60 | 57 | email: { |
61 | | - propDefinition: [ |
62 | | - "alegra", |
63 | | - "email", |
64 | | - ], |
| 58 | + type: "string", |
| 59 | + label: "Email", |
| 60 | + description: "Email of the contact", |
65 | 61 | optional: true, |
66 | 62 | }, |
67 | 63 | type: { |
68 | | - propDefinition: [ |
69 | | - "alegra", |
70 | | - "type", |
71 | | - ], |
| 64 | + type: "string", |
| 65 | + label: "Type", |
| 66 | + description: "Type of the contact", |
| 67 | + options: TYPE_OPTIONS, |
72 | 68 | optional: true, |
73 | 69 | }, |
74 | 70 | status: { |
75 | | - propDefinition: [ |
76 | | - "alegra", |
77 | | - "status", |
78 | | - ], |
| 71 | + type: "string", |
| 72 | + label: "Status", |
| 73 | + description: "Status of the contact", |
| 74 | + options: STATUS_OPTIONS, |
79 | 75 | optional: true, |
80 | 76 | }, |
81 | 77 | fax: { |
82 | | - propDefinition: [ |
83 | | - "alegra", |
84 | | - "fax", |
85 | | - ], |
| 78 | + type: "string", |
| 79 | + label: "Fax", |
| 80 | + description: "Fax number of the contact", |
86 | 81 | optional: true, |
87 | 82 | }, |
88 | 83 | debtToPay: { |
89 | 84 | propDefinition: [ |
90 | | - "alegra", |
| 85 | + alegra, |
91 | 86 | "debtToPay", |
92 | 87 | ], |
93 | 88 | optional: true, |
94 | 89 | }, |
95 | 90 | accountReceivable: { |
96 | 91 | propDefinition: [ |
97 | | - "alegra", |
98 | | - "accountReceivable", |
| 92 | + alegra, |
| 93 | + "debtToPay", |
99 | 94 | ], |
| 95 | + label: "Account Receivable", |
| 96 | + description: "Id of the account receivable associated with the contact", |
100 | 97 | optional: true, |
101 | 98 | }, |
102 | 99 | internalContacts: { |
103 | | - propDefinition: [ |
104 | | - "alegra", |
105 | | - "internalContacts", |
106 | | - ], |
| 100 | + type: "string[]", |
| 101 | + label: "Internal Contacts", |
| 102 | + description: "A list of objects of internal contacts related to the contact. **Example: [ { name: \"John Doe\", email: \"[email protected]\"}]**. [See the documentation](https://developer.alegra.com/reference/post_contacts) for further information.", |
107 | 103 | optional: true, |
108 | 104 | }, |
109 | 105 | ignoreRepeated: { |
110 | | - propDefinition: [ |
111 | | - "alegra", |
112 | | - "ignoreRepeated", |
113 | | - ], |
| 106 | + type: "boolean", |
| 107 | + label: "Ignore Repeated", |
| 108 | + description: "Ignore repeated contacts", |
114 | 109 | optional: true, |
115 | 110 | }, |
116 | 111 | statementAttached: { |
117 | | - propDefinition: [ |
118 | | - "alegra", |
119 | | - "statementAttached", |
120 | | - ], |
| 112 | + type: "boolean", |
| 113 | + label: "Statement Attached", |
| 114 | + description: "Indicates whether to include a statement for the contact", |
121 | 115 | optional: true, |
122 | 116 | }, |
123 | 117 | seller: { |
124 | 118 | propDefinition: [ |
125 | | - "alegra", |
126 | | - "sellerContact", |
| 119 | + alegra, |
| 120 | + "seller", |
127 | 121 | ], |
128 | 122 | optional: true, |
129 | 123 | }, |
130 | 124 | priceList: { |
131 | 125 | propDefinition: [ |
132 | | - "alegra", |
133 | | - "priceListContact", |
| 126 | + alegra, |
| 127 | + "priceList", |
134 | 128 | ], |
135 | 129 | optional: true, |
136 | 130 | }, |
137 | 131 | term: { |
138 | 132 | propDefinition: [ |
139 | | - "alegra", |
140 | | - "termContact", |
| 133 | + alegra, |
| 134 | + "term", |
141 | 135 | ], |
142 | 136 | optional: true, |
143 | 137 | }, |
144 | 138 | }, |
145 | 139 | async run({ $ }) { |
146 | | - const response = await this.alegra.createContact(); |
| 140 | + const { |
| 141 | + alegra, |
| 142 | + city, |
| 143 | + address, |
| 144 | + debtToPay, |
| 145 | + accountReceivable, |
| 146 | + internalContacts, |
| 147 | + statementAttached, |
| 148 | + ...data |
| 149 | + } = this; |
| 150 | + |
| 151 | + const response = await alegra.createContact({ |
| 152 | + $, |
| 153 | + data: { |
| 154 | + ...data, |
| 155 | + address: { |
| 156 | + city, |
| 157 | + address, |
| 158 | + }, |
| 159 | + accounting: { |
| 160 | + debtToPay, |
| 161 | + accountReceivable, |
| 162 | + }, |
| 163 | + internalContacts: parseObject(internalContacts), |
| 164 | + statementAttached: statementAttached |
| 165 | + ? "yes" |
| 166 | + : "no", |
| 167 | + }, |
| 168 | + }); |
147 | 169 | $.export("$summary", `Created contact with ID ${response.id}`); |
148 | 170 | return response; |
149 | 171 | }, |
|
0 commit comments