Skip to content

Commit a20b084

Browse files
authored
New Appointment Trigger for Setmore (#15315)
* wip * pnpm-lock.yaml * updates * pnpm-lock.yaml * pnpm-lock.yaml
1 parent 8d6bee5 commit a20b084

File tree

7 files changed

+142
-6
lines changed

7 files changed

+142
-6
lines changed

components/setmoreappointments/actions/create-appointment/create-appointment.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
key: "setmoreappointments-create-appointment",
66
name: "Create Appointment",
77
description: "Create a new appointment in Setmore Appointments. [See the documentation](https://setmore.docs.apiary.io/#introduction/appointments/create-an-appointment)",
8-
version: "0.0.1",
8+
version: "0.0.2",
99
type: "action",
1010
props: {
1111
setmore,

components/setmoreappointments/actions/create-customer/create-customer.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
key: "setmoreappointments-create-customer",
55
name: "Create Customer",
66
description: "Create a new customer in Setmore Appointments. [See the documentation](https://setmore.docs.apiary.io/#introduction/customers/create-a-customer)",
7-
version: "0.0.1",
7+
version: "0.0.2",
88
type: "action",
99
props: {
1010
setmore,

components/setmoreappointments/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/setmoreappointments",
3-
"version": "0.1.0",
3+
"version": "0.2.0",
44
"description": "Pipedream Setmore Components",
55
"main": "setmoreappointments.app.mjs",
66
"keywords": [
@@ -13,6 +13,6 @@
1313
"access": "public"
1414
},
1515
"dependencies": {
16-
"@pipedream/platform": "^1.5.1"
16+
"@pipedream/platform": "^3.0.3"
1717
}
1818
}

components/setmoreappointments/setmoreappointments.app.mjs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ export default {
8989
...args,
9090
});
9191
},
92+
listAppointments(args = {}) {
93+
return this._makeRequest({
94+
path: "/appointments",
95+
...args,
96+
});
97+
},
9298
createCustomer(args = {}) {
9399
return this._makeRequest({
94100
path: "/customer/create",
@@ -103,5 +109,21 @@ export default {
103109
...args,
104110
});
105111
},
112+
async *paginate({
113+
resourceFn,
114+
params,
115+
resourceKey,
116+
}) {
117+
do {
118+
const { data } = await resourceFn({
119+
params,
120+
});
121+
const items = data[resourceKey];
122+
for (const item of items) {
123+
yield item;
124+
}
125+
params.cursor = data.cursor;
126+
} while (params.cursor);
127+
},
106128
},
107129
};
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import setmore from "../../setmoreappointments.app.mjs";
2+
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
3+
import sampleEmit from "./test-event.mjs";
4+
5+
export default {
6+
key: "setmoreappointments-new-appointment-created",
7+
name: "New Appointment Created",
8+
description: "Emit new event when a new appointment is created in Setmore. [See the documentation](https://setmore.docs.apiary.io/#introduction/appointments/fetch-appointments-by-date-range)",
9+
version: "0.0.1",
10+
type: "source",
11+
dedupe: "unique",
12+
props: {
13+
setmore,
14+
db: "$.service.db",
15+
timer: {
16+
type: "$.interface.timer",
17+
default: {
18+
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
19+
},
20+
},
21+
staffKey: {
22+
propDefinition: [
23+
setmore,
24+
"staffKey",
25+
],
26+
optional: true,
27+
},
28+
},
29+
methods: {
30+
_getLastDate() {
31+
return this.db.get("lastDate") || this.getMonthAgo();
32+
},
33+
_setLastDate(lastDate) {
34+
this.db.set("lastDate", lastDate);
35+
},
36+
getMonthAgo() {
37+
const now = new Date();
38+
const oneMonthAgo = new Date(now);
39+
oneMonthAgo.setMonth(oneMonthAgo.getMonth() - 1);
40+
return this.formatDate(oneMonthAgo);
41+
},
42+
getToday() {
43+
const now = new Date();
44+
return this.formatDate(now);
45+
},
46+
getYearFromNow() {
47+
const now = new Date();
48+
now.setFullYear(now.getFullYear() + 1);
49+
return this.formatDate(now);
50+
},
51+
formatDate(date) {
52+
const day = String(date.getDate()).padStart(2, "0");
53+
const month = String(date.getMonth() + 1).padStart(2, "0");
54+
const year = date.getFullYear();
55+
return `${day}-${month}-${year}`;
56+
},
57+
generateMeta(appointment) {
58+
return {
59+
id: appointment.key,
60+
summary: `New Appointment with Key: ${appointment.key}`,
61+
ts: Date.now(),
62+
};
63+
},
64+
},
65+
async run() {
66+
const startDate = this._getLastDate();
67+
const endDate = this.getYearFromNow();
68+
69+
const appointments = this.setmore.paginate({
70+
resourceFn: this.setmore.listAppointments,
71+
resourceKey: "appointments",
72+
params: {
73+
startDate,
74+
endDate,
75+
staff_key: this.staffKey,
76+
customerDetails: true,
77+
},
78+
});
79+
80+
for await (const appointment of appointments) {
81+
const meta = this.generateMeta(appointment);
82+
this.$emit(appointment, meta);
83+
}
84+
85+
this._setLastDate(this.getToday());
86+
},
87+
sampleEmit,
88+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
export default {
2+
"key": "94eb4230-40d5-4651-b59a-0cccb7d9ab4d",
3+
"duration": 15,
4+
"customer": {
5+
"key": "c291f522b55b2e4a4a579300cdd57455a4316873d",
6+
"address": "",
7+
"city": "",
8+
"state": "",
9+
"comment": "test",
10+
"company_key": "c5247961-06b5-46e3-9cdb-e5187a02b67f",
11+
"contact_type": "Customer",
12+
"first_name": "Test",
13+
"last_name": "Customer",
14+
"email_id": "test@test.com",
15+
"postal_code": "",
16+
"image_url": ""
17+
},
18+
"cost": 0,
19+
"currency": "MXN",
20+
"start_time": "2025-01-16T12:00Z",
21+
"end_time": "2025-01-16T12:15Z",
22+
"staff_key": "r91e68f3227a75e4b066822ea7e649709376a8244-d",
23+
"service_key": "s8353404352c72fdc85ae4ebc786e4e74ec5c4e7c",
24+
"customer_key": "c291f522b55b2e4a4a579300cdd57455a4316873d",
25+
"label": "No Label"
26+
}

pnpm-lock.yaml

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)