fix(api): return Zod validation errors from public API routes (#708)
* fix(api): return Zod validation errors from public API routes Public API handlers now surface ZodError details as 400 VALIDATION_ERROR responses instead of generic 500 INTERNAL_ERROR payloads. Course import services also rethrow ZodError so validation failures are not wrapped as server errors. Co-authored-by: Rotimi Best <[email protected]> * refactor(utils): centralize course type values without db dependency Define COURSE_TYPE_VALUES once in @cio/utils/constants and use it for ZCourseType validation and the Drizzle COURSE_TYPE pgEnum. Removes the circular @cio/utils -> @cio/db import while keeping course-import schemas aligned with all four course types including PUBLIC. Co-authored-by: Rotimi Best <[email protected]> * fix(validation): default missing course metadata allowNewStudent to true Courses stored without allowNewStudent in metadata failed structure export validation. Align Zod preprocessing with runtime behavior where absent values mean enrollments are open. Co-authored-by: Rotimi Best <[email protected]> * chore(db): drop unused COURSE_TYPE_VALUES re-export from schema Co-authored-by: Rotimi Best <[email protected]> --------- Co-authored-by: Cursor Agent <[email protected]> Co-authored-by: Rotimi Best <[email protected]>
This commit is contained in:
co-authored by
Rotimi Best
Cursor Agent
parent
a337363965
commit
0ed0e3864d
@@ -21,9 +21,10 @@ import {
|
||||
} from 'drizzle-orm/pg-core';
|
||||
|
||||
import type { AnswerData } from '@cio/question-types';
|
||||
import { COURSE_TYPE_VALUES } from '@cio/utils/constants/course-type';
|
||||
import { sql } from 'drizzle-orm';
|
||||
|
||||
export const courseType = pgEnum('COURSE_TYPE', ['SELF_PACED', 'LIVE_CLASS', 'COMPLIANCE', 'PUBLIC']);
|
||||
export const courseType = pgEnum('COURSE_TYPE', [...COURSE_TYPE_VALUES]);
|
||||
export const locale = pgEnum('LOCALE', ['en', 'hi', 'fr', 'pt', 'de', 'vi', 'ru', 'es', 'pl', 'da']);
|
||||
export const plan = pgEnum('PLAN', ['EARLY_ADOPTER', 'ENTERPRISE', 'BASIC']);
|
||||
export const courseImportSourceType = pgEnum('COURSE_IMPORT_SOURCE_TYPE', ['prompt', 'pdf', 'course']);
|
||||
@@ -686,7 +687,7 @@ export const course = pgTable(
|
||||
}[];
|
||||
grading?: boolean;
|
||||
lessonDownload?: boolean;
|
||||
allowNewStudent: boolean;
|
||||
allowNewStudent?: boolean;
|
||||
/** Teacher-authored HTML sent in the welcome email after a student enrolls. */
|
||||
welcomeEmailMessage?: string | null;
|
||||
/** IANA timezone for this course's live sessions (display + scheduling). */
|
||||
|
||||
Reference in New Issue
Block a user