-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathBookings.ts
More file actions
98 lines (90 loc) · 2.6 KB
/
Bookings.ts
File metadata and controls
98 lines (90 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import { Client } from '../../Client'
import { StaysBooking } from '../StaysTypes'
import { Resource } from '../../Resource'
import { DuffelResponse, PaginationMeta } from '../../types'
export interface StaysBookingPayload {
quote_id: string
loyalty_programme_account_number?: string
guests: Array<{
given_name: string
family_name: string
/**
* Creates an association between the guest and a previously created user.
* This is intended to allow guests the ability to manage their own bookings.
* @example ["icu_0000000000000000000000"]
*/
user_id?: string
}>
email: string
phone_number: string
accommodation_special_requests?: string
payment?: { card_id: string } | { three_d_secure_session_id: string }
metadata?: StaysBooking['metadata']
/**
* The ids of users that would be allowed to manage the booking.
* @example ["icu_0000000000000000000000"]
*/
users?: string[]
}
export class Bookings extends Resource {
/**
* Endpoint path
*/
path: string
constructor(client: Client) {
super(client)
this.path = 'stays/bookings'
}
/**
* Create a booking
* @param {object} payload - The booking payload, including quote id and guest information
*/
public create = async (
payload: StaysBookingPayload,
): Promise<DuffelResponse<StaysBooking>> =>
this.request({
method: 'POST',
path: this.path,
data: payload,
})
/**
* Get a booking
* @param {string} bookingId - The ID of the booking
*/
public get = async (
bookingId: string,
): Promise<DuffelResponse<StaysBooking>> =>
this.request({
method: 'GET',
path: `${this.path}/${bookingId}`,
})
/**
* List bookings
* @param {Object} [options] - Pagination options (optional: limit, after, before)
* @link https://duffel.com/docs/api/bookings/list-bookings
*/
public list = async (
options?: PaginationMeta,
): Promise<DuffelResponse<StaysBooking[]>> =>
this.request({ method: 'GET', path: this.path, params: options })
/**
* Retrieves a generator of all bookings. The results may be returned in any order.
* @link https://duffel.com/docs/api/bookings/list-bookings
*/
public listWithGenerator = (): AsyncGenerator<
DuffelResponse<StaysBooking>,
void,
unknown
> => this.paginatedRequest({ path: this.path })
/**
* Cancel a booking
* @param {string} bookingId - The ID of the booking
*/
public cancel = async (
bookingId: string,
): Promise<DuffelResponse<StaysBooking>> =>
this.request({
method: 'POST',
path: `${this.path}/${bookingId}/actions/cancel`,
})
}