fix(api): convert empty strings to null for date/optional DB columns
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:
@@ -31,12 +31,12 @@ export function createCourseManagementApi(client: SupabaseClient<Database>) {
|
||||
|
||||
async createCourse(input: CreateCourseInput) {
|
||||
const { data, error } = await client.from('courses').insert({
|
||||
account_id: input.accountId, course_number: input.courseNumber, name: input.name,
|
||||
description: input.description, category_id: input.categoryId, instructor_id: input.instructorId,
|
||||
location_id: input.locationId, start_date: input.startDate, end_date: input.endDate,
|
||||
fee: input.fee, reduced_fee: input.reducedFee, capacity: input.capacity,
|
||||
account_id: input.accountId, course_number: input.courseNumber || null, name: input.name,
|
||||
description: input.description || null, category_id: input.categoryId || null, instructor_id: input.instructorId || null,
|
||||
location_id: input.locationId || null, start_date: input.startDate || null, end_date: input.endDate || null,
|
||||
fee: input.fee, reduced_fee: input.reducedFee ?? null, capacity: input.capacity,
|
||||
min_participants: input.minParticipants, status: input.status,
|
||||
registration_deadline: input.registrationDeadline, notes: input.notes,
|
||||
registration_deadline: input.registrationDeadline || null, notes: input.notes || null,
|
||||
}).select().single();
|
||||
if (error) throw error;
|
||||
return data;
|
||||
|
||||
Reference in New Issue
Block a user