fix(api): convert empty strings to null for date/optional DB columns
Some checks failed
Workflow / ʦ TypeScript (push) Failing after 5m37s
Workflow / ⚫️ Test (push) Has been skipped

Course and event creation Server Actions were failing with 'Something went
wrong' because empty form strings ('') were being inserted into date/uuid
columns which reject empty strings. Now converts '' to null for all
optional fields (dates, descriptions, IDs, contact info).
This commit is contained in:
Zaid Marzguioui
2026-04-01 13:14:53 +02:00
parent 72227b5aab
commit 8d8f4e94ee
3 changed files with 12 additions and 12 deletions

View File

@@ -47,12 +47,12 @@ export function createEventManagementApi(client: SupabaseClient<Database>) {
async createEvent(input: CreateEventInput) {
const { data, error } = await client.from('events').insert({
account_id: input.accountId, name: input.name, description: input.description,
event_date: input.eventDate, event_time: input.eventTime, end_date: input.endDate,
location: input.location, capacity: input.capacity, min_age: input.minAge,
max_age: input.maxAge, fee: input.fee, status: input.status,
registration_deadline: input.registrationDeadline,
contact_name: input.contactName, contact_email: input.contactEmail, contact_phone: input.contactPhone,
account_id: input.accountId, name: input.name, description: input.description || null,
event_date: input.eventDate || null, event_time: input.eventTime || null, end_date: input.endDate || null,
location: input.location || null, capacity: input.capacity, min_age: input.minAge ?? null,
max_age: input.maxAge ?? null, fee: input.fee, status: input.status,
registration_deadline: input.registrationDeadline || null,
contact_name: input.contactName || null, contact_email: input.contactEmail || null, contact_phone: input.contactPhone || null,
}).select().single();
if (error) throw error;
return data;