ti2 1.0.36 → 1.0.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/controllers/bookings.js +22 -0
- package/controllers/graphql-schemas/availability.js +61 -0
- package/controllers/graphql-schemas/booking.js +94 -0
- package/controllers/graphql-schemas/product.js +64 -0
- package/controllers/graphql-schemas/rate.js +33 -0
- package/index.js +41 -14
- package/package.json +1 -1
package/controllers/bookings.js
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
const assert = require('assert');
|
|
2
2
|
|
|
3
3
|
const { UserAppKey } = require('../models/index');
|
|
4
|
+
const { typeDefs: productTypeDefs, query: productQuery } = require('./graphql-schemas/product');
|
|
5
|
+
const { typeDefs: availTypeDefs, query: availQuery } = require('./graphql-schemas/availability');
|
|
6
|
+
const { typeDefs: bookingTypeDefs, query: bookingQuery } = require('./graphql-schemas/booking');
|
|
7
|
+
const { typeDefs: rateTypeDefs, query: rateQuery } = require('./graphql-schemas/rate');
|
|
8
|
+
|
|
9
|
+
const typeDefsAndQueries = {
|
|
10
|
+
productTypeDefs,
|
|
11
|
+
productQuery,
|
|
12
|
+
availTypeDefs,
|
|
13
|
+
availQuery,
|
|
14
|
+
bookingTypeDefs,
|
|
15
|
+
bookingQuery,
|
|
16
|
+
rateTypeDefs,
|
|
17
|
+
rateQuery,
|
|
18
|
+
};
|
|
4
19
|
|
|
5
20
|
const bookingsSearch = plugins => async (req, res, next) => {
|
|
6
21
|
const {
|
|
@@ -22,6 +37,7 @@ const bookingsSearch = plugins => async (req, res, next) => {
|
|
|
22
37
|
const results = await search({
|
|
23
38
|
token,
|
|
24
39
|
payload: body,
|
|
40
|
+
typeDefsAndQueries,
|
|
25
41
|
});
|
|
26
42
|
return res.json(results);
|
|
27
43
|
} catch (err) {
|
|
@@ -49,6 +65,7 @@ const bookingsCancel = plugins => async (req, res, next) => {
|
|
|
49
65
|
const results = await app.cancelBooking({
|
|
50
66
|
token,
|
|
51
67
|
payload: body,
|
|
68
|
+
typeDefsAndQueries,
|
|
52
69
|
});
|
|
53
70
|
return res.json(results);
|
|
54
71
|
} catch (err) {
|
|
@@ -76,6 +93,7 @@ const $bookingsProductSearch = plugins => async ({
|
|
|
76
93
|
const results = await app.searchProducts({
|
|
77
94
|
token,
|
|
78
95
|
payload,
|
|
96
|
+
typeDefsAndQueries,
|
|
79
97
|
});
|
|
80
98
|
return results;
|
|
81
99
|
};
|
|
@@ -112,6 +130,7 @@ const bookingsAvailabilitySearch = plugins => async (req, res, next) => {
|
|
|
112
130
|
const results = await app.searchAvailability({
|
|
113
131
|
token,
|
|
114
132
|
payload,
|
|
133
|
+
typeDefsAndQueries,
|
|
115
134
|
});
|
|
116
135
|
return res.json(results);
|
|
117
136
|
} catch (err) {
|
|
@@ -139,6 +158,7 @@ const $bookingsAvailabilityCalendar = plugins => async ({
|
|
|
139
158
|
return app.availabilityCalendar({
|
|
140
159
|
token,
|
|
141
160
|
payload,
|
|
161
|
+
typeDefsAndQueries,
|
|
142
162
|
});
|
|
143
163
|
};
|
|
144
164
|
|
|
@@ -175,6 +195,7 @@ const searchQuote = plugins => async (req, res, next) => {
|
|
|
175
195
|
const results = await app.searchQuote({
|
|
176
196
|
token,
|
|
177
197
|
payload,
|
|
198
|
+
typeDefsAndQueries,
|
|
178
199
|
});
|
|
179
200
|
return res.json(results);
|
|
180
201
|
} catch (err) {
|
|
@@ -203,6 +224,7 @@ const createBooking = plugins => async (req, res, next) => {
|
|
|
203
224
|
const results = await app.createBooking({
|
|
204
225
|
token,
|
|
205
226
|
payload,
|
|
227
|
+
typeDefsAndQueries,
|
|
206
228
|
});
|
|
207
229
|
return res.json(results);
|
|
208
230
|
} catch (err) {
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
const typeDefs = `
|
|
2
|
+
input UnitWithQuantity {
|
|
3
|
+
unitId: ID
|
|
4
|
+
quantity: Int
|
|
5
|
+
}
|
|
6
|
+
type Pricing {
|
|
7
|
+
unitId: ID
|
|
8
|
+
original: Int
|
|
9
|
+
retail: Int
|
|
10
|
+
net: Int
|
|
11
|
+
currencyPrecision: Int
|
|
12
|
+
}
|
|
13
|
+
type Offer {
|
|
14
|
+
offerId: ID
|
|
15
|
+
title: String
|
|
16
|
+
description: String
|
|
17
|
+
}
|
|
18
|
+
type Query {
|
|
19
|
+
key(productId: String, optionId: String, currency: String, unitsWithQuantity: [UnitWithQuantity], jwtKey: String): String
|
|
20
|
+
dateTimeStart: String
|
|
21
|
+
dateTimeEnd: String
|
|
22
|
+
allDay: Boolean
|
|
23
|
+
vacancies: Int
|
|
24
|
+
available: Boolean
|
|
25
|
+
pricing: Pricing
|
|
26
|
+
unitPricing: [Pricing]
|
|
27
|
+
offer: Offer
|
|
28
|
+
}
|
|
29
|
+
`;
|
|
30
|
+
|
|
31
|
+
const query = `query getAvailability ($pId: String, $oId: String, $currency: String, $unitsWithQuantity: [UnitWithQuantity], $jwtKey: String) {
|
|
32
|
+
key (productId: $pId, optionId: $oId, currency: $currency, unitsWithQuantity: $unitsWithQuantity, jwtKey: $jwtKey)
|
|
33
|
+
dateTimeStart
|
|
34
|
+
dateTimeEnd
|
|
35
|
+
allDay
|
|
36
|
+
vacancies
|
|
37
|
+
available
|
|
38
|
+
pricing {
|
|
39
|
+
...pricingFields
|
|
40
|
+
}
|
|
41
|
+
unitPricing {
|
|
42
|
+
...pricingFields
|
|
43
|
+
}
|
|
44
|
+
offer {
|
|
45
|
+
offerId
|
|
46
|
+
title
|
|
47
|
+
description
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
fragment pricingFields on Pricing {
|
|
51
|
+
unitId
|
|
52
|
+
original
|
|
53
|
+
retail
|
|
54
|
+
net
|
|
55
|
+
currencyPrecision
|
|
56
|
+
}
|
|
57
|
+
`;
|
|
58
|
+
module.exports = {
|
|
59
|
+
typeDefs,
|
|
60
|
+
query,
|
|
61
|
+
};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
const typeDefs = `
|
|
2
|
+
type Holder {
|
|
3
|
+
name: String
|
|
4
|
+
surname: String
|
|
5
|
+
fullName: String
|
|
6
|
+
phoneNumber: String
|
|
7
|
+
emailAddress: String
|
|
8
|
+
}
|
|
9
|
+
type UnitItem {
|
|
10
|
+
unitItemId: ID
|
|
11
|
+
unitId: ID
|
|
12
|
+
unitName: String
|
|
13
|
+
}
|
|
14
|
+
type Price {
|
|
15
|
+
original: Int
|
|
16
|
+
retail: Int
|
|
17
|
+
net: Int
|
|
18
|
+
currencyPrecision: Int
|
|
19
|
+
currency: String
|
|
20
|
+
}
|
|
21
|
+
type Query {
|
|
22
|
+
id: ID
|
|
23
|
+
orderId: ID
|
|
24
|
+
bookingId: ID
|
|
25
|
+
supplierBookingId: ID
|
|
26
|
+
status: String
|
|
27
|
+
productId: String
|
|
28
|
+
productName: String
|
|
29
|
+
optionId: String
|
|
30
|
+
optionName: String
|
|
31
|
+
cancellable: Boolean
|
|
32
|
+
editable: Boolean
|
|
33
|
+
unitItems: [UnitItem]
|
|
34
|
+
start: String
|
|
35
|
+
end: String
|
|
36
|
+
allDay: Boolean
|
|
37
|
+
bookingDate: String
|
|
38
|
+
holder: Holder
|
|
39
|
+
notes: String
|
|
40
|
+
price: Price
|
|
41
|
+
cancelPolicy: String
|
|
42
|
+
resellerReference: String
|
|
43
|
+
publicUrl: String
|
|
44
|
+
privateUrl: String
|
|
45
|
+
}
|
|
46
|
+
`;
|
|
47
|
+
|
|
48
|
+
const query = `{
|
|
49
|
+
id
|
|
50
|
+
orderId
|
|
51
|
+
bookingId
|
|
52
|
+
supplierBookingId
|
|
53
|
+
status
|
|
54
|
+
productId
|
|
55
|
+
productName
|
|
56
|
+
optionId
|
|
57
|
+
optionName
|
|
58
|
+
cancellable
|
|
59
|
+
editable
|
|
60
|
+
unitItems {
|
|
61
|
+
unitItemId
|
|
62
|
+
unitId
|
|
63
|
+
unitName
|
|
64
|
+
}
|
|
65
|
+
start
|
|
66
|
+
end
|
|
67
|
+
allDay
|
|
68
|
+
bookingDate
|
|
69
|
+
holder {
|
|
70
|
+
name
|
|
71
|
+
surname
|
|
72
|
+
fullName
|
|
73
|
+
phoneNumber
|
|
74
|
+
emailAddress
|
|
75
|
+
}
|
|
76
|
+
notes
|
|
77
|
+
price {
|
|
78
|
+
original
|
|
79
|
+
retail
|
|
80
|
+
net
|
|
81
|
+
currencyPrecision
|
|
82
|
+
currency
|
|
83
|
+
}
|
|
84
|
+
cancelPolicy
|
|
85
|
+
optionId
|
|
86
|
+
resellerReference
|
|
87
|
+
publicUrl
|
|
88
|
+
privateUrl
|
|
89
|
+
}`;
|
|
90
|
+
|
|
91
|
+
module.exports = {
|
|
92
|
+
typeDefs,
|
|
93
|
+
query,
|
|
94
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
const typeDefs = `
|
|
2
|
+
type Restriction {
|
|
3
|
+
paxCount: Int
|
|
4
|
+
minAge: Int
|
|
5
|
+
maxAge: Int
|
|
6
|
+
}
|
|
7
|
+
type Pricing {
|
|
8
|
+
original: Int
|
|
9
|
+
retail: Int
|
|
10
|
+
currency: Int
|
|
11
|
+
currencyPrecision: Int
|
|
12
|
+
}
|
|
13
|
+
type Unit {
|
|
14
|
+
unitId: ID
|
|
15
|
+
unitName: String
|
|
16
|
+
subtitle: String!
|
|
17
|
+
restrictions: Restriction
|
|
18
|
+
pricing: [Pricing]
|
|
19
|
+
}
|
|
20
|
+
type Option {
|
|
21
|
+
optionId: ID
|
|
22
|
+
optionName: String
|
|
23
|
+
units: [Unit]
|
|
24
|
+
}
|
|
25
|
+
type Query {
|
|
26
|
+
productId: ID
|
|
27
|
+
productName: String
|
|
28
|
+
availableCurrencies: [String]
|
|
29
|
+
defaultCurrency: String
|
|
30
|
+
options: [Option]
|
|
31
|
+
}
|
|
32
|
+
`;
|
|
33
|
+
|
|
34
|
+
const query = `{
|
|
35
|
+
productId
|
|
36
|
+
productName
|
|
37
|
+
availableCurrencies
|
|
38
|
+
defaultCurrency
|
|
39
|
+
options {
|
|
40
|
+
optionId
|
|
41
|
+
optionName
|
|
42
|
+
units {
|
|
43
|
+
unitId
|
|
44
|
+
unitName
|
|
45
|
+
subtitle
|
|
46
|
+
pricing {
|
|
47
|
+
original
|
|
48
|
+
retail
|
|
49
|
+
currencyPrecision
|
|
50
|
+
currency
|
|
51
|
+
}
|
|
52
|
+
restrictions {
|
|
53
|
+
paxCount
|
|
54
|
+
minAge
|
|
55
|
+
maxAge
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}`;
|
|
60
|
+
|
|
61
|
+
module.exports = {
|
|
62
|
+
typeDefs,
|
|
63
|
+
query,
|
|
64
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const typeDefs = `
|
|
2
|
+
type Pricing {
|
|
3
|
+
original: Int
|
|
4
|
+
retail: Int
|
|
5
|
+
currency: Int
|
|
6
|
+
currencyPrecision: Int
|
|
7
|
+
}
|
|
8
|
+
type Query {
|
|
9
|
+
rateId: ID
|
|
10
|
+
rateName: String
|
|
11
|
+
unitId: ID
|
|
12
|
+
unitName: String
|
|
13
|
+
pricing: [Pricing]
|
|
14
|
+
}
|
|
15
|
+
`;
|
|
16
|
+
|
|
17
|
+
const query = `{
|
|
18
|
+
rateId
|
|
19
|
+
rateName
|
|
20
|
+
unitId
|
|
21
|
+
unitName
|
|
22
|
+
pricing {
|
|
23
|
+
original
|
|
24
|
+
retail
|
|
25
|
+
currencyPrecision
|
|
26
|
+
currency
|
|
27
|
+
}
|
|
28
|
+
}`;
|
|
29
|
+
|
|
30
|
+
module.exports = {
|
|
31
|
+
typeDefs,
|
|
32
|
+
query,
|
|
33
|
+
};
|
package/index.js
CHANGED
|
@@ -130,6 +130,21 @@ module.exports = async ({
|
|
|
130
130
|
notImplemented: (req, res) => res.sendStatus(501),
|
|
131
131
|
});
|
|
132
132
|
if (elasticLogsClient) { // API request logs are saved on elastic
|
|
133
|
+
const mappings = {
|
|
134
|
+
dynamic: true,
|
|
135
|
+
properties: {
|
|
136
|
+
body: { type: 'object' },
|
|
137
|
+
client: { type: 'keyword' },
|
|
138
|
+
date: { type: 'long' },
|
|
139
|
+
method: { type: 'keyword' },
|
|
140
|
+
operationId: { type: 'keyword' },
|
|
141
|
+
params: { type: 'object' },
|
|
142
|
+
query: { type: 'object' },
|
|
143
|
+
url: { type: 'text' },
|
|
144
|
+
responseStatusCode: { type: 'long' },
|
|
145
|
+
responseTimeInMs: { type: 'long' },
|
|
146
|
+
},
|
|
147
|
+
};
|
|
133
148
|
// setup the index
|
|
134
149
|
elasticLogsClient.indices.existsTemplate({
|
|
135
150
|
name: 'apilog',
|
|
@@ -144,22 +159,32 @@ module.exports = async ({
|
|
|
144
159
|
settings: {
|
|
145
160
|
number_of_shards: 1,
|
|
146
161
|
},
|
|
147
|
-
mappings
|
|
148
|
-
dynamic: true,
|
|
149
|
-
properties: {
|
|
150
|
-
body: { type: 'object' },
|
|
151
|
-
client: { type: 'keyword' },
|
|
152
|
-
date: { type: 'long' },
|
|
153
|
-
method: { type: 'keyword' },
|
|
154
|
-
params: { type: 'object' },
|
|
155
|
-
query: { type: 'object' },
|
|
156
|
-
url: { type: 'text' },
|
|
157
|
-
responseStatusCode: { type: 'long' },
|
|
158
|
-
responseTimeInMs: { type: 'long' },
|
|
159
|
-
},
|
|
160
|
-
},
|
|
162
|
+
mappings,
|
|
161
163
|
},
|
|
162
164
|
});
|
|
165
|
+
console.log('index template created');
|
|
166
|
+
} else {
|
|
167
|
+
// index exists, we might have to updated it
|
|
168
|
+
const current = R.path(
|
|
169
|
+
['body', 'apilog', 'mappings'],
|
|
170
|
+
await elasticLogsClient.indices.getTemplate({
|
|
171
|
+
name: 'apilog',
|
|
172
|
+
}),
|
|
173
|
+
);
|
|
174
|
+
if (!R.equals(current, mappings)) {
|
|
175
|
+
console.log('=- updating index template -=');
|
|
176
|
+
await elasticLogsClient.indices.putTemplate({
|
|
177
|
+
name: 'apilog',
|
|
178
|
+
body: {
|
|
179
|
+
index_patterns: [`${elasticLogIndex}*`],
|
|
180
|
+
settings: {
|
|
181
|
+
number_of_shards: 1,
|
|
182
|
+
},
|
|
183
|
+
mappings,
|
|
184
|
+
},
|
|
185
|
+
});
|
|
186
|
+
console.log('updated');
|
|
187
|
+
}
|
|
163
188
|
}
|
|
164
189
|
const exists = await elasticLogsClient.indices.exists({
|
|
165
190
|
index: elasticLogIndex,
|
|
@@ -169,6 +194,7 @@ module.exports = async ({
|
|
|
169
194
|
await elasticLogsClient.indices.create({
|
|
170
195
|
index: elasticLogIndex,
|
|
171
196
|
});
|
|
197
|
+
console.log('index created');
|
|
172
198
|
}
|
|
173
199
|
}).catch(console.log);
|
|
174
200
|
app.use((req, res, next) => {
|
|
@@ -181,6 +207,7 @@ module.exports = async ({
|
|
|
181
207
|
query: req.query,
|
|
182
208
|
appRecord: req.appRecord,
|
|
183
209
|
method: req.method,
|
|
210
|
+
operationId: R.path(['openapi', 'operation', 'operationId'], req),
|
|
184
211
|
client: req.headers['x-forwarded-for'] || req.connection.remoteAddress,
|
|
185
212
|
};
|
|
186
213
|
elasticLogsClient.index({
|