Skip to content

Commit dc5b437

Browse files
committed
Hostaway new action
1 parent fe7b4bb commit dc5b437

File tree

3 files changed

+106
-0
lines changed

3 files changed

+106
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import hostaway from "../../hostaway.app.mjs";
2+
3+
export default {
4+
key: "hostaway-create-reservation",
5+
name: "Create Reservation",
6+
description: "Creates a new reservation in Hostaway. [See the documentation](https://api.hostaway.com/documentation#create-a-reservation)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
hostaway,
11+
channelId: {
12+
propDefinition: [
13+
hostaway,
14+
"channelId",
15+
],
16+
},
17+
listingMapId: {
18+
propDefinition: [
19+
hostaway,
20+
"listingId",
21+
],
22+
},
23+
arrivalDate: {
24+
type: "string",
25+
label: "Arrival Date",
26+
description: "Arrival date in `YYYY-MM-DD` format, e.g. `2024-08-15`",
27+
},
28+
departureDate: {
29+
type: "string",
30+
label: "Departure Date",
31+
description: "Departure date in `YYYY-MM-DD` format, e.g. `2024-08-19`",
32+
},
33+
guestName: {
34+
type: "string",
35+
label: "Guest Name",
36+
description: "Name of the guest",
37+
optional: true,
38+
},
39+
guestEmail: {
40+
type: "string",
41+
label: "Guest Email",
42+
description: "Email address of the guest",
43+
optional: true,
44+
},
45+
numberOfGuests: {
46+
type: "integer",
47+
label: "Number of Guests",
48+
description: "Number of guests for the reservation",
49+
optional: true,
50+
},
51+
additionalFields: {
52+
type: "object",
53+
label: "Additional Fields",
54+
description: "Additional fields to set for the reservation. [See the documentation](https://api.hostaway.com/documentation#reservation-object) for all available fields.",
55+
optional: true,
56+
}
57+
},
58+
async run({ $ }) {
59+
const { hostaway, additionalFields = {}, ...data } = this;
60+
const { result } = await hostaway.createReservation({
61+
$,
62+
data: {
63+
...data,
64+
...additionalFields
65+
},
66+
});
67+
68+
if (result?.id) {
69+
$.export("summary", `Successfully created reservation (ID: ${result.id})`);
70+
}
71+
72+
return result;
73+
},
74+
};

components/hostaway/common/constants.mjs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,28 @@ const COMMUNICATION_TYPES = [
4242
"whatsapp",
4343
];
4444

45+
const CHANNEL_OPTIONS = [
46+
{ value: 2018, label: "airbnbOfficial", },
47+
{ value: 2002, label: "homeaway", },
48+
{ value: 2005, label: "bookingcom", },
49+
{ value: 2007, label: "expedia", },
50+
{ value: 2009, label: "homeawayical", },
51+
{ value: 2010, label: "vrboical", },
52+
{ value: 2000, label: "direct", },
53+
{ value: 2013, label: "bookingengine", },
54+
{ value: 2015, label: "customIcal", },
55+
{ value: 2016, label: "tripadvisorical", },
56+
{ value: 2017, label: "wordpress", },
57+
{ value: 2019, label: "marriott", },
58+
{ value: 2020, label: "partner", },
59+
{ value: 2021, label: "gds", },
60+
{ value: 2022, label: "google", },
61+
]
62+
4563
export default {
4664
DEFAULT_LIMIT,
4765
CATEGORIES,
4866
TASK_STATUS,
4967
COMMUNICATION_TYPES,
68+
CHANNEL_OPTIONS,
5069
};

components/hostaway/hostaway.app.mjs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ export default {
118118
})) || [];
119119
},
120120
},
121+
channelId: {
122+
type: "integer",
123+
label: "Channel",
124+
description: "Identifier of the channel",
125+
options: constants.CHANNEL_OPTIONS
126+
},
121127
},
122128
methods: {
123129
_baseUrl() {
@@ -211,5 +217,12 @@ export default {
211217
...args,
212218
});
213219
},
220+
createReservation(args = {}) {
221+
return this._makeRequest({
222+
path: "/reservations",
223+
method: "POST",
224+
...args,
225+
});
226+
}
214227
},
215228
};

0 commit comments

Comments
 (0)