Skip to content

Commit

Permalink
koala: initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
bangarang authored and carlbrugger committed Oct 8, 2024
1 parent 235b584 commit 6a19760
Showing 1 changed file with 6 additions and 17 deletions.
23 changes: 6 additions & 17 deletions validate/PDFReportGenerator/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,11 @@ const defaultStyle: ReportStyle = {
}

export default function (listener: FlatfileListener) {
listener.use(
recordHook('contacts', async (record) => {
const email = record.get('email') as string

const validEmailAddress = /^[^\s@]+@[^\s@]+\.[^\s@]+$/
if (!email || !validEmailAddress.test(email)) {
record.addError('email', 'Invalid email address')
}

return record
})
)

listener.on('action:custom', async (event: FlatfileEvent) => {
const { action, context } = event
if (action.operation === 'generate_pdf') {
listener.on(
'job:ready',
{ job: `sheet:generate_pdf` },
async (event: FlatfileEvent) => {
const { action, context } = event
try {
const userStyle: Partial<ReportStyle> = action.payload?.style || {}
const style: ReportStyle = { ...defaultStyle, ...userStyle }
Expand Down Expand Up @@ -194,5 +183,5 @@ export default function (listener: FlatfileListener) {
await event.reply('Error generating or uploading PDF')
}
}
})
)
}

0 comments on commit 6a19760

Please sign in to comment.