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

Commit 3b04e24

Browse files
Merge pull request #77 from deskbookers/develop
merge
2 parents 5c0152e + fabe6b5 commit 3b04e24

File tree

4 files changed

+190
-2
lines changed

4 files changed

+190
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "deskbookers",
3-
"version": "5.9.4",
3+
"version": "5.10.1",
44
"description": "Deskbookers API JavaScript SDK",
55
"homepage": "https://www.deskbookers.com/",
66
"main": "dist/index.js",
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import Resource from './Resource'
2+
import { DeskbookersError } from '../errors'
3+
4+
export default class TermsAndConditions extends Resource {
5+
constructor(api) {
6+
super(api)
7+
this.endpoint = 'tc'
8+
}
9+
10+
async listActive() {
11+
return await this.request({
12+
method: 'GET',
13+
path: `/${this.endpoint}/active`,
14+
fields: []
15+
})
16+
}
17+
18+
async userPending(userId) {
19+
return await this.request({
20+
method: 'GET',
21+
path: `/${this.endpoint}/userPending`,
22+
params: { userId }
23+
})
24+
}
25+
26+
async userAccepted(userId) {
27+
return await this.request({
28+
method: 'GET',
29+
path: `/${this.endpoint}/userAccepted`,
30+
params: { userId }
31+
})
32+
}
33+
34+
async userAccept({ userId, tcId }) {
35+
return await this.request({
36+
method: 'POST',
37+
path: `/${this.endpoint}/userAccept`,
38+
params: {
39+
userId,
40+
tcId
41+
}
42+
})
43+
}
44+
45+
async venuePending(venueId) {
46+
return await this.request({
47+
method: 'GET',
48+
path: `/${this.endpoint}/venuePending`,
49+
params: { venueId }
50+
})
51+
}
52+
53+
async venueAccepted(venueId) {
54+
return await this.request({
55+
method: 'GET',
56+
path: `/${this.endpoint}/venueAccepted`,
57+
params: { venueId }
58+
})
59+
}
60+
61+
async venueAccept({ venueId, tcId }) {
62+
return await this.request({
63+
method: 'POST',
64+
path: `/${this.endpoint}/venueAccept`,
65+
params: {
66+
venueId,
67+
tcId
68+
}
69+
})
70+
}
71+
72+
async emailSettings(userId) {
73+
return await this.request({
74+
method: 'GET',
75+
path: `/${this.endpoint}/emailSettings`,
76+
params: { userId }
77+
})
78+
}
79+
80+
async saveEmailSettings({ userId, emails }) {
81+
return await this.request({
82+
method: 'POST',
83+
path: `/${this.endpoint}/emailSettings`,
84+
params: { userId, emails }
85+
})
86+
}
87+
}

src/resources/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import Venues from './Venues'
1111
import Payments from './payments'
1212
import Reports from './reports'
1313
import Search from './Search'
14+
import TermsAndConditions from './TermsAndConditions'
1415

1516
export default {
1617
account: Account,
@@ -25,5 +26,6 @@ export default {
2526
venues: Venues,
2627
payments: Payments,
2728
reports: Reports,
28-
search: Search
29+
search: Search,
30+
termsAndConditions: TermsAndConditions
2931
}

test/terms.js

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import dotenv from 'dotenv'
2+
import 'fetch-everywhere'
3+
import test from 'ava'
4+
import moment from 'moment'
5+
import Deskbookers from '../src'
6+
dotenv.load()
7+
8+
async function client(login = false) {
9+
const deskbookers = new Deskbookers({
10+
https: process.env.API_HTTPS === 'true',
11+
host: process.env.API_HOST
12+
})
13+
14+
if (login) {
15+
await deskbookers.account.login(
16+
process.env.LOGIN_EMAIL,
17+
process.env.LOGIN_PASSWORD
18+
)
19+
}
20+
return deskbookers
21+
}
22+
23+
test('Get active terms', async t => {
24+
const deskbookers = await client(true)
25+
26+
const terms = await deskbookers.termsAndConditions.listActive()
27+
console.log('active', JSON.stringify(terms))
28+
})
29+
30+
test('Get pending terms by user', async t => {
31+
const deskbookers = await client(true)
32+
33+
const terms = await deskbookers.termsAndConditions.userPending(49889)
34+
console.log('user pending', JSON.stringify(terms))
35+
})
36+
37+
test('Get accepted terms by user', async t => {
38+
const deskbookers = await client(true)
39+
40+
const terms = await deskbookers.termsAndConditions.userAccepted(49889)
41+
console.log('user accepted', JSON.stringify(terms))
42+
})
43+
44+
test('Post accepted terms by user', async t => {
45+
const deskbookers = await client(true)
46+
47+
const ok = await deskbookers.termsAndConditions.userAccept({
48+
userId: 49889,
49+
tcId: 1
50+
})
51+
console.log('user accepted', ok)
52+
})
53+
54+
test('Get email settings', async t => {
55+
const deskbookers = await client(true)
56+
const settings = await deskbookers.termsAndConditions.emailSettings(
57+
deskbookers.session.user.id
58+
)
59+
console.log('email settings', JSON.stringify(settings))
60+
})
61+
62+
//test('Save email settings', async t => {
63+
//const deskbookers = await client(true)
64+
//const emails = [
65+
//{ category: 'Promotions', enabled: true },
66+
//{ category: 'Participants', enabled: false },
67+
//{ category: 'Reviews', enabled: true }
68+
//]
69+
70+
//const settings = await deskbookers.termsAndConditions.saveEmailSettings({
71+
//userId: deskbookers.session.user.id,
72+
//emails
73+
//})
74+
//console.log('email settings', JSON.stringify(settings))
75+
//})
76+
77+
test('Get pending terms by venue', async t => {
78+
const deskbookers = await client(true)
79+
80+
const terms = await deskbookers.termsAndConditions.venuePending(11707)
81+
console.log('venue pending', JSON.stringify(terms))
82+
})
83+
84+
test('Get accepted terms by venue', async t => {
85+
const deskbookers = await client(true)
86+
87+
const terms = await deskbookers.termsAndConditions.venueAccepted(11707)
88+
console.log('venue accepted', JSON.stringify(terms))
89+
})
90+
91+
//test('Post accepted terms by venue', async t => {
92+
//const deskbookers = await client(true)
93+
94+
//const ok = await deskbookers.termsAndConditions.venueAccept({
95+
//venueId: 11707,
96+
//tcId: 11
97+
//})
98+
//console.log('venue accepted', ok)
99+
//})

0 commit comments

Comments
 (0)