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

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

View File

@@ -31,12 +31,12 @@ export function createCourseManagementApi(client: SupabaseClient<Database>) {
async createCourse(input: CreateCourseInput) { async createCourse(input: CreateCourseInput) {
const { data, error } = await client.from('courses').insert({ const { data, error } = await client.from('courses').insert({
account_id: input.accountId, course_number: input.courseNumber, name: input.name, account_id: input.accountId, course_number: input.courseNumber || null, name: input.name,
description: input.description, category_id: input.categoryId, instructor_id: input.instructorId, description: input.description || null, category_id: input.categoryId || null, instructor_id: input.instructorId || null,
location_id: input.locationId, start_date: input.startDate, end_date: input.endDate, location_id: input.locationId || null, start_date: input.startDate || null, end_date: input.endDate || null,
fee: input.fee, reduced_fee: input.reducedFee, capacity: input.capacity, fee: input.fee, reduced_fee: input.reducedFee ?? null, capacity: input.capacity,
min_participants: input.minParticipants, status: input.status, 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(); }).select().single();
if (error) throw error; if (error) throw error;
return data; return data;

View File

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