-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New Appointment Trigger for Setmore #15315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8162a45
wip
michelle0927 87ceee1
pnpm-lock.yaml
michelle0927 ee4251c
updates
michelle0927 b12efd4
pnpm-lock.yaml
michelle0927 9a89201
Merge remote-tracking branch 'origin/master' into issue-15030
michelle0927 7860653
pnpm-lock.yaml
michelle0927 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
components/setmoreappointments/sources/new-appointment-created/new-appointment-created.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
}, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
sampleEmit, | ||
}; |
26 changes: 26 additions & 0 deletions
26
components/setmoreappointments/sources/new-appointment-created/test-event.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.