Send discord notif upon event creation

This commit is contained in:
MartinBraquet
2026-03-10 23:32:34 +01:00
parent 670e863bae
commit 0ef5ecea30

View File

@@ -1,4 +1,6 @@
import {APIErrors, APIHandler} from 'api/helpers/endpoint'
import {sendDiscordMessage} from 'common/discord/core'
import {DEPLOYED_WEB_URL} from 'common/envs/constants'
import {tryCatch} from 'common/util/try-catch'
import {createSupabaseDirectClient} from 'shared/supabase/init'
import {insert} from 'shared/supabase/utils'
@@ -45,5 +47,21 @@ export const createEvent: APIHandler<'create-event'> = async (body, auth) => {
throw APIErrors.internalServerError('Failed to create event: ' + error.message)
}
return {success: true, event: data}
const continuation = async () => {
try {
const user = await pg.oneOrNone(`select name from users where id = $1 `, [auth.uid])
const message: string = `${user.name} created a new [event](${DEPLOYED_WEB_URL}/events)!\n**${body.title}**\n${body.description}\nStart: ${body.eventStartTime.replace('T', ' @ ').replace('.000Z', ' UTC')}`
await sendDiscordMessage(message, 'general')
} catch (e) {
console.error('Failed to send discord event', e)
}
}
return {
result: {
success: true,
event: data,
},
continue: continuation,
}
}