mirror of
https://github.com/CompassConnections/Compass.git
synced 2026-03-24 17:41:27 -04:00
Send discord notif upon event creation
This commit is contained in:
@@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user