From 0ef5ecea308ec9e43bf9ea06a96c4e22a5b7a448 Mon Sep 17 00:00:00 2001 From: MartinBraquet Date: Tue, 10 Mar 2026 23:32:34 +0100 Subject: [PATCH] Send discord notif upon event creation --- backend/api/src/create-event.ts | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/backend/api/src/create-event.ts b/backend/api/src/create-event.ts index 15594a81..0fd6f87b 100644 --- a/backend/api/src/create-event.ts +++ b/backend/api/src/create-event.ts @@ -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, + } }