diff --git a/backend/api/src/contact.ts b/backend/api/src/contact.ts index a55bd1fd..af4a289c 100644 --- a/backend/api/src/contact.ts +++ b/backend/api/src/contact.ts @@ -25,8 +25,13 @@ export const contact: APIHandler<'contact'> = async ( const continuation = async () => { try { + let user = null + if (userId) { + user = await pg.oneOrNone(` select name from users where id = $1 `, [userId]) + } const md = jsonToMarkdown(content) - const message: string = `**New Contact Message**\n${md}` + const tile = user ? `New message from ${user.name}` : 'New message' + const message: string = `**${tile}**\n${md}` await sendDiscordMessage(message, 'contact') } catch (e) { console.error('Failed to send discord contact', e) diff --git a/backend/supabase/contact.sql b/backend/supabase/contact.sql index ab33b511..69c070e8 100644 --- a/backend/supabase/contact.sql +++ b/backend/supabase/contact.sql @@ -8,7 +8,7 @@ create table if not exists -- Foreign Keys alter table contact -add constraint contact_user_id_fkey foreign key (user_id) references users (id); +add constraint contact_user_id_fkey foreign key (user_id) references users (id) on delete set null; -- Row Level Security alter table contact enable row level security; diff --git a/backend/supabase/reports.sql b/backend/supabase/reports.sql index 6490a641..6d4866ca 100644 --- a/backend/supabase/reports.sql +++ b/backend/supabase/reports.sql @@ -8,15 +8,15 @@ create table if not exists id text default uuid_generate_v4 () not null, parent_id text, parent_type text, - user_id text not null + user_id text ); -- Foreign Keys alter table reports -add constraint reports_content_owner_id_fkey foreign key (content_owner_id) references users (id); +add constraint reports_content_owner_id_fkey foreign key (content_owner_id) references users (id) on delete set null; alter table reports -add constraint reports_user_id_fkey foreign key (user_id) references users (id); +add constraint reports_user_id_fkey foreign key (user_id) references users (id) on delete set null; -- Row Level Security alter table reports enable row level security;