Skip to content
This repository was archived by the owner on May 28, 2024. It is now read-only.

Commit fac1f0b

Browse files
Ft dsk 972 venue features api (#38)
* feat: new features api and changes for auth works with POST, PUT and DELETE with raw json body * fix: version in package.json * fix: features urls in readme.md * fix: more fields on data layout and some pr recomendations * fix: bugs found while integration with the frontend * fix: version number
1 parent 3eb9c76 commit fac1f0b

File tree

12 files changed

+575
-36
lines changed

12 files changed

+575
-36
lines changed

.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ API_HTTPS=true
33
API_HOST=
44
API_AVAILABILITY_HOST=localhost:3005
55
API_AVAILABILITY_PATH=
6+
API_FEATURE_HOST=localhost:3007
7+
API_FEATURE_PATH=
68

79
# Availability
810
AVAILABILITY_VENUE_ID=12686

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
## 3.1.0 - 2017-06-22
8+
### Changes
9+
- Added `Resources` resource
10+
711
## 3.0.0 - 2017-06-13
812
### Changes
913
- Renamed `Workplaces` resource to `Spaces`

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,11 @@ for (let workplace of workplaces) {
6161
* [`retrieve(tabId, limit)`](docs/events.md#retrievetabid-limit)
6262
* [`list(limit, offset, tags)`](docs/events.md#listlimit-offset-tags)
6363
* [`markAllAsRead(tags)`](docs/events.md#mark-all-as-read)
64+
* features
65+
* [`list(type)`](docs/features.md#listtype)
66+
* [`create(feature)`](docs/features.md#createfeature)
67+
* [`update(featureName, feature)`](docs/features.md#updatefeaturename-feature)
68+
* [`delete(featureName)`](docs/features.md#deletefeaturename)
69+
* [`listByVenue(venueId)`](docs/features.md#listbyvenuevenueid)
70+
* [`checkFeatureByVenue(venueId, featureName)`](docs/features.md#checkfeaturebyvenuevenueid-featureName)
71+
* [`updateFeatureByVenue(venueId, featureName, feature)`](docs/features.md#updatefeaturebyvenuevenueid-featurename-feature)

docs/features.md

Lines changed: 275 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,275 @@
1+
# Features
2+
3+
## `list(type)`
4+
List all avaiable features for a given `type`(optional).
5+
6+
```js
7+
const data = await deskbookers.feature.list()
8+
```
9+
#### Example response
10+
```json
11+
[
12+
{
13+
"description": "Review widgets",
14+
"id": 3,
15+
"name": "reviewWidgets",
16+
"parentId": null,
17+
"readonly": false,
18+
"type": "venue"
19+
},
20+
{
21+
"description": "Book button widgets",
22+
"id": 4,
23+
"name": "bookButtonWidgets",
24+
"parentId": null,
25+
"readonly": false,
26+
"type": "venue"
27+
},
28+
{
29+
"description": "Regular customer discounts",
30+
"features": [
31+
{
32+
"description": "Regular customer discounts son 1",
33+
"features": [
34+
{
35+
"description": "Regular customer discounts grandson 1",
36+
"id": 7,
37+
"name": "rcdGrandson1",
38+
"parentId": 5,
39+
"readonly": true,
40+
"type": "venue"
41+
}
42+
],
43+
"id": 5,
44+
"name": "rcdSon1",
45+
"parentId": 1,
46+
"readonly": true,
47+
"type": "venue"
48+
},
49+
{
50+
"description": "Regular customer discounts son 2",
51+
"id": 6,
52+
"name": "rcdSon2",
53+
"parentId": 1,
54+
"readonly": true,
55+
"type": "venue"
56+
}
57+
],
58+
"id": 1,
59+
"name": "regularCustomerDiscounts",
60+
"parentId": null,
61+
"readonly": true,
62+
"type": "venue"
63+
},
64+
{
65+
"description": "Booking tool",
66+
"features": [
67+
{
68+
"description": "Booking Tool Son 1",
69+
"id": 8,
70+
"name": "btSon1",
71+
"parentId": 2,
72+
"readonly": true,
73+
"type": "booking"
74+
}
75+
],
76+
"id": 2,
77+
"name": "bookingTool",
78+
"parentId": null,
79+
"readonly": true,
80+
"type": "booking"
81+
}
82+
]
83+
```
84+
85+
```js
86+
const data = await deskbookers.feature.list('booking')
87+
```
88+
#### Example response
89+
```json
90+
[
91+
{
92+
"description": "Booking tool",
93+
"features": [
94+
{
95+
"description": "Booking Tool Son 1",
96+
"id": 8,
97+
"name": "btSon1",
98+
"parentId": 2,
99+
"readonly": true,
100+
"type": "booking"
101+
}
102+
],
103+
"id": 2,
104+
"name": "bookingTool",
105+
"parentId": null,
106+
"readonly": true,
107+
"type": "booking"
108+
}
109+
]
110+
```
111+
112+
## `create(feature)`
113+
Create a new feature for a given `Object`.
114+
115+
#### Body (feature)
116+
Name | Type | Description | Required
117+
--- | --- | --- | ---
118+
name | String | Alphanumeric feature name | Yes
119+
parentId | Integer | Id of the parent feature | No
120+
description | String | Short description of the feature | No
121+
type | String | Alphanumeric type name | Yes
122+
123+
```js
124+
const data = await deskbookers.feature.create(
125+
{
126+
name: 'testName',
127+
description: 'teste description',
128+
type: 'venue'
129+
}
130+
)
131+
```
132+
#### Example response
133+
```json
134+
{
135+
"status": "ok"
136+
}
137+
```
138+
139+
## `update(featureName, feature)`
140+
Update a feature for a given `featureName` with the `Object`.
141+
142+
#### Body (feature)
143+
Name | Type | Description | Required
144+
--- | --- | --- | ---
145+
name | String | Alphanumeric feature name | Yes
146+
parentId | Integer | Id of the parent feature | No
147+
description | String | Short description of the feature | No
148+
type | String | Alphanumeric type name | Yes
149+
150+
```js
151+
const data = await deskbookers.feature.update(
152+
'testName',
153+
{
154+
name: 'testName',
155+
description: 'teste description 2',
156+
type: 'venue2',
157+
parentId: null
158+
}
159+
)
160+
```
161+
#### Example response
162+
```json
163+
{
164+
"status": "ok"
165+
}
166+
```
167+
168+
## `delete(featureName)`
169+
Delete a feature for a given `featureName`.
170+
171+
```js
172+
const data = await deskbookers.feature.delete('testName')
173+
```
174+
#### Example response
175+
```json
176+
{
177+
"status": "ok"
178+
}
179+
```
180+
181+
## `listByVenue(venueId)`
182+
List all active features for a given `venueId`.
183+
184+
```js
185+
const data = await deskbookers.feature.listByVenue(1)
186+
```
187+
#### Example response
188+
```json
189+
[
190+
{
191+
"description": "Regular custumer discounts",
192+
"end": null,
193+
"features": [
194+
{
195+
"description": "Regular custumer discounts son 1",
196+
"end": null,
197+
"features": [
198+
{
199+
"description": "Regular custumer discounts grandson 1",
200+
"end": "2017-07-20T10:37:17.313Z",
201+
"id": 7,
202+
"name": "rcdGrandson1",
203+
"parentId": 5,
204+
"start": "2017-06-20T10:37:17.313Z",
205+
"type": "venue"
206+
}
207+
],
208+
"id": 5,
209+
"name": "rcdSon1",
210+
"parentId": 1,
211+
"start": "2017-06-20T10:37:17.217Z",
212+
"type": "venue"
213+
},
214+
{
215+
"description": "Regular custumer discounts son 2",
216+
"end": null,
217+
"id": 6,
218+
"name": "rcdSon2",
219+
"parentId": 1,
220+
"start": "2017-06-20T10:37:17.260Z",
221+
"type": "venue"
222+
}
223+
],
224+
"id": 1,
225+
"name": "regularCustumerDiscounts",
226+
"parentId": null,
227+
"start": "2017-06-20T10:37:17.172Z",
228+
"type": "venue"
229+
}
230+
]
231+
```
232+
233+
## `checkFeatureByVenue(venueId, featureName)`
234+
List all active features for a given `venueId` and `featureName`.
235+
236+
```js
237+
const data = await deskbookers.feature.checkFeatureByVenue(
238+
1,
239+
'regularCustumerDiscounts'
240+
)
241+
```
242+
#### Example response
243+
```json
244+
false
245+
```
246+
247+
## `updateFeatureByVenue(venueId, featureName, feature)`
248+
Update features for a given `venueId`, `featureName` and `feature`.
249+
250+
#### Body (feature)
251+
Name | Type | Description | Required
252+
--- | --- | --- | ---
253+
enabled | boolean | Set enabled status | Yes
254+
start | Timestamp | Feature active start date | No
255+
end | Timestamp | Feature active end date | No
256+
257+
```js
258+
let start = new Date().setDate(new Date().getDate()-20)
259+
let end = new Date().setDate(new Date().getDate()+5)
260+
const data = await deskbookers.feature.updateFeatureByVenue(
261+
2,
262+
'bookingTool',
263+
{
264+
enabled: true,
265+
start,
266+
end
267+
}
268+
)
269+
```
270+
#### Example response
271+
```json
272+
{
273+
"status": "ok"
274+
}
275+
```

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
{
22
"name": "deskbookers",
3-
"version": "3.0.2",
3+
"version": "3.1.2",
44
"description": "Deskbookers API JavaScript SDK",
55
"main": "dist/index.js",
66
"scripts": {
77
"test": "ava -c 2",
8+
"test:watch": "ava -c 2 --watch --verbose",
89
"build": "rm -rf dist/*; babel src --out-dir dist",
910
"prepublish": "npm run build"
1011
},

src/index.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ const API_HOST = 'backoffice.2cnnct.com'
55
const API_VERSION = 1
66
const API_LANGUAGE = 'en-gb'
77
const API_RESELLER_ID = 10000
8-
const API_AVAILABILITY_HOST = 'api-availability.2cnnct.com'
8+
const API_AVAILABILITY_HOST = 'api-availability.deskbookers.com'
99
const API_AVAILABILITY_PATH = ''
10+
const API_FEATURE_HOST = 'api-features.deskbookers.com'
11+
const API_FEATURE_PATH = ''
1012

1113
export default class Deskbookers {
1214
constructor ({
@@ -19,6 +21,10 @@ export default class Deskbookers {
1921
availability: {
2022
host: API_AVAILABILITY_HOST,
2123
path: API_AVAILABILITY_PATH
24+
},
25+
feature: {
26+
host: API_FEATURE_HOST,
27+
path: API_FEATURE_PATH
2228
}
2329
}
2430
}) {
@@ -49,7 +55,7 @@ export default class Deskbookers {
4955
* @param String hash The hash to compare the check hash to
5056
* @return Bool
5157
*/
52-
export function authenticate (url, method, data, timestamp, privateKey, hash) {
53-
const checkData = buildCheckData(url, { method }, data, timestamp)
58+
export function authenticate (url, method, data, timestamp, privateKey, hash, rawBody = false) {
59+
const checkData = buildCheckData(url, { method, rawBody }, data, timestamp)
5460
return signData(checkData, privateKey) === hash
5561
}

0 commit comments

Comments
 (0)