Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default {
key: "setmoreappointments-create-appointment",
name: "Create Appointment",
description: "Create a new appointment in Setmore Appointments. [See the documentation](https://setmore.docs.apiary.io/#introduction/appointments/create-an-appointment)",
version: "0.0.1",
version: "0.0.2",
type: "action",
props: {
setmore,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "setmoreappointments-create-customer",
name: "Create Customer",
description: "Create a new customer in Setmore Appointments. [See the documentation](https://setmore.docs.apiary.io/#introduction/customers/create-a-customer)",
version: "0.0.1",
version: "0.0.2",
type: "action",
props: {
setmore,
Expand Down
4 changes: 2 additions & 2 deletions components/setmoreappointments/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/setmoreappointments",
"version": "0.1.0",
"version": "0.2.0",
"description": "Pipedream Setmore Components",
"main": "setmoreappointments.app.mjs",
"keywords": [
Expand All @@ -13,6 +13,6 @@
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^1.5.1"
"@pipedream/platform": "^3.0.3"
}
}
22 changes: 22 additions & 0 deletions components/setmoreappointments/setmoreappointments.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ export default {
...args,
});
},
listAppointments(args = {}) {
return this._makeRequest({
path: "/appointments",
...args,
});
},
createCustomer(args = {}) {
return this._makeRequest({
path: "/customer/create",
Expand All @@ -103,5 +109,21 @@ export default {
...args,
});
},
async *paginate({
resourceFn,
params,
resourceKey,
}) {
do {
const { data } = await resourceFn({
params,
});
const items = data[resourceKey];
for (const item of items) {
yield item;
}
params.cursor = data.cursor;
} while (params.cursor);
},
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import setmore from "../../setmoreappointments.app.mjs";
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
import sampleEmit from "./test-event.mjs";

export default {
key: "setmoreappointments-new-appointment-created",
name: "New Appointment Created",
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)",
version: "0.0.1",
type: "source",
dedupe: "unique",
props: {
setmore,
db: "$.service.db",
timer: {
type: "$.interface.timer",
default: {
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
},
},
staffKey: {
propDefinition: [
setmore,
"staffKey",
],
optional: true,
},
},
methods: {
_getLastDate() {
return this.db.get("lastDate") || this.getMonthAgo();
},
_setLastDate(lastDate) {
this.db.set("lastDate", lastDate);
},
getMonthAgo() {
const now = new Date();
const oneMonthAgo = new Date(now);
oneMonthAgo.setMonth(oneMonthAgo.getMonth() - 1);
return this.formatDate(oneMonthAgo);
},
getToday() {
const now = new Date();
return this.formatDate(now);
},
getYearFromNow() {
const now = new Date();
now.setFullYear(now.getFullYear() + 1);
return this.formatDate(now);
},
formatDate(date) {
const day = String(date.getDate()).padStart(2, "0");
const month = String(date.getMonth() + 1).padStart(2, "0");
const year = date.getFullYear();
return `${day}-${month}-${year}`;
},
generateMeta(appointment) {
return {
id: appointment.key,
summary: `New Appointment with Key: ${appointment.key}`,
ts: Date.now(),
};
},
},
async run() {
const startDate = this._getLastDate();
const endDate = this.getYearFromNow();

const appointments = this.setmore.paginate({
resourceFn: this.setmore.listAppointments,
resourceKey: "appointments",
params: {
startDate,
endDate,
staff_key: this.staffKey,
customerDetails: true,
},
});

for await (const appointment of appointments) {
const meta = this.generateMeta(appointment);
this.$emit(appointment, meta);
}

this._setLastDate(this.getToday());
},
sampleEmit,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export default {
"key": "94eb4230-40d5-4651-b59a-0cccb7d9ab4d",
"duration": 15,
"customer": {
"key": "c291f522b55b2e4a4a579300cdd57455a4316873d",
"address": "",
"city": "",
"state": "",
"comment": "test",
"company_key": "c5247961-06b5-46e3-9cdb-e5187a02b67f",
"contact_type": "Customer",
"first_name": "Test",
"last_name": "Customer",
"email_id": "[email protected]",
"postal_code": "",
"image_url": ""
},
"cost": 0,
"currency": "MXN",
"start_time": "2025-01-16T12:00Z",
"end_time": "2025-01-16T12:15Z",
"staff_key": "r91e68f3227a75e4b066822ea7e649709376a8244-d",
"service_key": "s8353404352c72fdc85ae4ebc786e4e74ec5c4e7c",
"customer_key": "c291f522b55b2e4a4a579300cdd57455a4316873d",
"label": "No Label"
}
4 changes: 2 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading