Skip to content

Commit a8468bf

Browse files
committed
[ACTION] booking experts - filters
1 parent cb51427 commit a8468bf

File tree

3 files changed

+156
-18
lines changed

3 files changed

+156
-18
lines changed

components/booking_experts/actions/list-bookings/list-bookings.mjs

Lines changed: 108 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
key: "booking_experts-list-bookings",
55
name: "List Bookings",
66
description: "Returns a list of bookings for an administration. [See the documentation](https://developers.bookingexperts.com/reference/administration-bookings-index)",
7-
version: "0.0.4",
7+
version: "0.0.5",
88
annotations: {
99
destructiveHint: false,
1010
openWorldHint: true,
@@ -39,15 +39,28 @@ export default {
3939
],
4040
description: "Filter by channel",
4141
},
42-
reservationId: {
42+
reservationIds: {
43+
type: "string[]",
44+
label: "Reservation IDs",
45+
description: "Filter by reservation IDs",
4346
propDefinition: [
4447
bookingExperts,
4548
"reservationId",
4649
(c) => ({
4750
administrationId: c.administrationId,
4851
}),
4952
],
50-
description: "Filter by reservation",
53+
},
54+
createdAt: {
55+
type: "string",
56+
label: "Created At",
57+
description: "Filter by created at (ISO 8601 format, e.g., `2024-01-01T00:00:00Z`)",
58+
optional: true,
59+
},
60+
updatedAt: {
61+
type: "string",
62+
label: "Updated At",
63+
description: "Filter by updated at (ISO 8601 format, e.g., `2024-01-01T00:00:00Z`)",
5164
optional: true,
5265
},
5366
page: {
@@ -62,19 +75,103 @@ export default {
6275
"perPage",
6376
],
6477
},
78+
filterId: {
79+
optional: true,
80+
propDefinition: [
81+
bookingExperts,
82+
"bookingId",
83+
({ administrationId }) => ({
84+
administrationId,
85+
}),
86+
],
87+
},
88+
customerIds: {
89+
type: "string[]",
90+
label: "Customer IDs",
91+
description: "Filter by customer IDs",
92+
propDefinition: [
93+
bookingExperts,
94+
"customerId",
95+
({ administrationId }) => ({
96+
administrationId,
97+
}),
98+
],
99+
},
100+
bookingNr: {
101+
label: "Booking Number",
102+
description: "Filter by booking number",
103+
optional: true,
104+
propDefinition: [
105+
bookingExperts,
106+
"bookingId",
107+
({ administrationId }) => ({
108+
administrationId,
109+
mapper: ({ attributes: { booking_nr: value } }) => value,
110+
}),
111+
],
112+
},
113+
confirmedAt: {
114+
type: "string",
115+
label: "Confirmed At",
116+
description: "Filter by confirmed at (ISO 8601 format, e.g., `2024-01-01T00:00:00Z`)",
117+
optional: true,
118+
},
119+
fieldsBooking: {
120+
type: "string[]",
121+
label: "Fields Booking",
122+
description: "Fields to return for the booking",
123+
optional: true,
124+
},
125+
referenceNr: {
126+
type: "string",
127+
label: "Reference Number",
128+
description: "Filter by reference number",
129+
optional: true,
130+
},
131+
},
132+
methods: {
133+
commaSeparatedList(value) {
134+
return Array.isArray(value) && value?.length > 0
135+
? value.join(",")
136+
: value;
137+
},
65138
},
66139
async run({ $ }) {
140+
const {
141+
commaSeparatedList,
142+
administrationId,
143+
ownerId,
144+
administrationChannelId,
145+
reservationIds,
146+
createdAt,
147+
updatedAt,
148+
page,
149+
perPage,
150+
filterId,
151+
customerIds,
152+
bookingNr,
153+
confirmedAt,
154+
fieldsBooking,
155+
referenceNr,
156+
} = this;
157+
67158
const { data } = await this.bookingExperts.listBookings({
68159
$,
69-
administrationId: this.administrationId,
160+
administrationId,
70161
params: {
71-
"filter[owner]": this.ownerId,
72-
"filter[channel]": this.listAdministrationChannels,
73-
"filter[reservations]": this.reservationId,
74-
"filter[created_at]": this.createdAt,
75-
"filter[updated_at]": this.updatedAt,
76-
"page[number]": this.page,
77-
"page[size]": this.perPage,
162+
"filter[owner]": ownerId,
163+
"filter[channel]": administrationChannelId,
164+
"filter[created_at]": createdAt,
165+
"filter[updated_at]": updatedAt,
166+
"page[number]": page,
167+
"page[size]": perPage,
168+
"filter[ID]": filterId,
169+
"filter[reservations]": commaSeparatedList(reservationIds),
170+
"filter[customer]": commaSeparatedList(customerIds),
171+
"filter[booking_nr]": bookingNr,
172+
"filter[confirmed_at]": confirmedAt,
173+
"fields[booking]": commaSeparatedList(fieldsBooking),
174+
"filter[reference_nr]": referenceNr,
78175
},
79176
});
80177
$.export("$summary", `Found ${data.length} bookings`);

components/booking_experts/booking_experts.app.mjs

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,23 @@ export default {
7272
description: "The ID of a booking",
7373
async options({
7474
page, administrationId,
75+
mapper = ({
76+
id, attributes,
77+
}) => ({
78+
label: attributes.booking_nr,
79+
value: id,
80+
}),
7581
}) {
82+
if (!administrationId) {
83+
return [];
84+
}
7685
const { data } = await this.listBookings({
7786
administrationId,
7887
params: {
7988
"page[number]": page + 1,
8089
},
8190
});
82-
return data?.map(({
83-
id, attributes,
84-
}) => ({
85-
label: attributes.booking_nr,
86-
value: id,
87-
})) || [];
91+
return data?.map(mapper) || [];
8892
},
8993
},
9094
channelId: {
@@ -256,6 +260,35 @@ export default {
256260
max: 100,
257261
optional: true,
258262
},
263+
customerId: {
264+
type: "string",
265+
label: "Customer ID",
266+
description: "The ID of a customer",
267+
optional: true,
268+
async options({
269+
page, administrationId,
270+
}) {
271+
if (!administrationId) {
272+
return [];
273+
}
274+
const { data } = await this.listCustomers({
275+
administrationId,
276+
params: {
277+
"page[number]": page + 1,
278+
},
279+
});
280+
return data?.map(({
281+
id, attributes,
282+
}) => ({
283+
// if first_name and last_name are not empty, show them, otherwise show the email
284+
label: [
285+
attributes.first_name,
286+
attributes.last_name,
287+
].filter(Boolean).join(" ") || attributes.email || id,
288+
value: id,
289+
})) || [];
290+
},
291+
},
259292
},
260293
methods: {
261294
_baseUrl() {
@@ -443,5 +476,13 @@ export default {
443476
...opts,
444477
});
445478
},
479+
listCustomers({
480+
administrationId, ...opts
481+
}) {
482+
return this._makeRequest({
483+
path: `/administrations/${administrationId}/customers`,
484+
...opts,
485+
});
486+
},
446487
},
447488
};

components/booking_experts/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/booking_experts",
3-
"version": "0.3.0",
3+
"version": "0.3.1",
44
"description": "Pipedream Booking Experts Components",
55
"main": "booking_experts.app.mjs",
66
"keywords": [

0 commit comments

Comments
 (0)