Skip to content

Commit 8c66e63

Browse files
authored
Mews - Additional components (#18120)
1 parent a692936 commit 8c66e63

File tree

32 files changed

+3906
-223
lines changed

32 files changed

+3906
-223
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import app from "../../mews.app.mjs";
2+
import utils from "../../common/utils.mjs";
3+
4+
export default {
5+
name: "Add Customer File",
6+
description: "Add a customer file to the Mews system. [See the documentation](https://mews-systems.gitbook.io/connector-api/operations/customers#add-customer-file)",
7+
key: "mews-add-customer-file",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
app,
12+
customerId: {
13+
propDefinition: [
14+
app,
15+
"customerId",
16+
],
17+
},
18+
name: {
19+
type: "string",
20+
label: "File Name",
21+
description: "Name of the file.",
22+
},
23+
type: {
24+
type: "string",
25+
label: "File Type",
26+
description: "Type of the file (e.g., image/png, application/pdf).",
27+
options: [
28+
"application/pdf",
29+
"image/bmp",
30+
"image/gif",
31+
"image/jpeg",
32+
"image/png",
33+
"image/tiff",
34+
],
35+
},
36+
filePath: {
37+
propDefinition: [
38+
app,
39+
"filePath",
40+
],
41+
},
42+
},
43+
async run({ $ }) {
44+
const {
45+
app,
46+
customerId,
47+
name,
48+
type,
49+
filePath,
50+
} = this;
51+
52+
const data = await utils.fromFilePathToBase64(filePath);
53+
54+
const response = await app.customersAddFile({
55+
$,
56+
data: {
57+
CustomerId: customerId,
58+
Name: name,
59+
Type: type,
60+
Data: data,
61+
},
62+
});
63+
64+
$.export("$summary", `Successfully added file with ID \`${response.FileId}\``);
65+
return response;
66+
},
67+
};
Lines changed: 237 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
1+
import { ConfigurationError } from "@pipedream/platform";
2+
import app from "../../mews.app.mjs";
3+
import utils from "../../common/utils.mjs";
4+
5+
export default {
6+
name: "Add Customer",
7+
description: "Adds a new customer to the system. [See the documentation](https://mews-systems.gitbook.io/connector-api/operations/customers#add-customer)",
8+
key: "mews-add-customer",
9+
version: "0.0.1",
10+
type: "action",
11+
props: {
12+
app,
13+
overwriteExisting: {
14+
type: "boolean",
15+
label: "Overwrite Existing",
16+
description: "Whether an existing customer should be overwritten in case of duplicity. This applies only to basic personal information",
17+
},
18+
lastName: {
19+
optional: false,
20+
propDefinition: [
21+
app,
22+
"lastName",
23+
],
24+
},
25+
firstName: {
26+
propDefinition: [
27+
app,
28+
"firstName",
29+
],
30+
},
31+
secondLastName: {
32+
propDefinition: [
33+
app,
34+
"secondLastName",
35+
],
36+
},
37+
title: {
38+
propDefinition: [
39+
app,
40+
"title",
41+
],
42+
},
43+
nationalityCode: {
44+
propDefinition: [
45+
app,
46+
"countryCode",
47+
],
48+
label: "Nationality Code",
49+
description: "ISO 3166-1 code of the Country",
50+
},
51+
sex: {
52+
propDefinition: [
53+
app,
54+
"sex",
55+
],
56+
},
57+
birthDate: {
58+
propDefinition: [
59+
app,
60+
"birthDate",
61+
],
62+
},
63+
birthPlace: {
64+
propDefinition: [
65+
app,
66+
"birthPlace",
67+
],
68+
},
69+
occupation: {
70+
propDefinition: [
71+
app,
72+
"occupation",
73+
],
74+
},
75+
email: {
76+
propDefinition: [
77+
app,
78+
"email",
79+
],
80+
},
81+
phone: {
82+
propDefinition: [
83+
app,
84+
"phone",
85+
],
86+
},
87+
loyaltyCode: {
88+
propDefinition: [
89+
app,
90+
"loyaltyCode",
91+
],
92+
},
93+
notes: {
94+
description: "Internal notes about the customer",
95+
propDefinition: [
96+
app,
97+
"notes",
98+
],
99+
optional: true,
100+
},
101+
carRegistrationNumber: {
102+
propDefinition: [
103+
app,
104+
"carRegistrationNumber",
105+
],
106+
},
107+
dietaryRequirements: {
108+
propDefinition: [
109+
app,
110+
"dietaryRequirements",
111+
],
112+
},
113+
taxIdentificationNumber: {
114+
propDefinition: [
115+
app,
116+
"taxIdentificationNumber",
117+
],
118+
},
119+
companyId: {
120+
propDefinition: [
121+
app,
122+
"companyId",
123+
],
124+
optional: true,
125+
},
126+
address: {
127+
propDefinition: [
128+
app,
129+
"address",
130+
],
131+
},
132+
classifications: {
133+
propDefinition: [
134+
app,
135+
"classifications",
136+
],
137+
},
138+
options: {
139+
propDefinition: [
140+
app,
141+
"options",
142+
],
143+
},
144+
italianDestinationCode: {
145+
propDefinition: [
146+
app,
147+
"italianDestinationCode",
148+
],
149+
},
150+
italianFiscalCode: {
151+
propDefinition: [
152+
app,
153+
"italianFiscalCode",
154+
],
155+
},
156+
},
157+
async run({ $ }) {
158+
const {
159+
app,
160+
title,
161+
firstName,
162+
lastName,
163+
secondLastName,
164+
nationalityCode,
165+
sex,
166+
birthDate,
167+
birthPlace,
168+
occupation,
169+
email,
170+
phone,
171+
loyaltyCode,
172+
notes,
173+
carRegistrationNumber,
174+
dietaryRequirements,
175+
taxIdentificationNumber,
176+
companyId,
177+
address,
178+
classifications,
179+
options,
180+
overwriteExisting,
181+
italianDestinationCode,
182+
italianFiscalCode,
183+
} = this;
184+
185+
const parsedClassifications = classifications
186+
? utils.parseArray(classifications)
187+
: undefined;
188+
189+
// Validate array
190+
if (parsedClassifications && !Array.isArray(parsedClassifications)) {
191+
throw new ConfigurationError("**Classifications** must be an array when provided");
192+
}
193+
194+
const parsedAddress = address
195+
? utils.parseJson(address)
196+
: undefined;
197+
198+
// Validate address
199+
if (parsedAddress && typeof parsedAddress !== "object") {
200+
throw new ConfigurationError("**Address** must be a valid address object");
201+
}
202+
203+
const response = await app.customersAdd({
204+
$,
205+
data: {
206+
LastName: lastName,
207+
FirstName: firstName,
208+
SecondLastName: secondLastName,
209+
Title: title,
210+
NationalityCode: nationalityCode,
211+
Sex: sex,
212+
BirthDate: birthDate,
213+
BirthPlace: birthPlace,
214+
Occupation: occupation,
215+
Email: email,
216+
Phone: phone,
217+
LoyaltyCode: loyaltyCode,
218+
Notes: notes,
219+
CarRegistrationNumber: carRegistrationNumber,
220+
DietaryRequirements: dietaryRequirements,
221+
TaxIdentificationNumber: taxIdentificationNumber,
222+
CompanyId: companyId,
223+
Address: parsedAddress,
224+
Classifications: parsedClassifications,
225+
Options: options,
226+
OverwriteExisting: overwriteExisting,
227+
ItalianDestinationCode: italianDestinationCode,
228+
ItalianFiscalCode: italianFiscalCode,
229+
},
230+
});
231+
232+
$.export("$summary", `Successfully added customer${response.Email
233+
? ` with email ${response.Email}`
234+
: ""}`);
235+
return response;
236+
},
237+
};
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import app from "../../mews.app.mjs";
2+
3+
export default {
4+
name: "Add Reservation Companion",
5+
description: "Add a customer as a companion to a reservation. [See the documentation](https://mews-systems.gitbook.io/connector-api/operations/reservations#add-reservation-companion)",
6+
key: "mews-add-reservation-companion",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
reservationId: {
12+
propDefinition: [
13+
app,
14+
"reservationId",
15+
],
16+
description: "Identifier of the reservation to add the companion to.",
17+
},
18+
customerId: {
19+
propDefinition: [
20+
app,
21+
"customerId",
22+
],
23+
description: "Identifier of the customer who will be the companion.",
24+
},
25+
},
26+
async run({ $ }) {
27+
const {
28+
app,
29+
reservationId,
30+
customerId,
31+
} = this;
32+
33+
const response = await app.reservationsAddCompanion({
34+
$,
35+
data: {
36+
ReservationId: reservationId,
37+
CustomerId: customerId,
38+
},
39+
});
40+
41+
$.export("$summary", `Successfully added reservation companion with ID \`${response.CompanionshipId}\``);
42+
return response;
43+
},
44+
};

0 commit comments

Comments
 (0)