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:
@@ -5,7 +5,7 @@ WORKDIR /app
|
||||
# --- Install + Build in one stage ---
|
||||
FROM base AS builder
|
||||
# CACHE_BUST: change this value to force a full rebuild (busts Docker layer cache)
|
||||
ARG CACHE_BUST=10
|
||||
ARG CACHE_BUST=11
|
||||
RUN echo "Cache bust: ${CACHE_BUST}"
|
||||
COPY . .
|
||||
RUN pnpm install --no-frozen-lockfile
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user