Feature/116 webinars backend - #122
Open
achneerov wants to merge 2 commits into
Open
Conversation
added 2 commits
August 8, 2026 22:02
martin0024
requested changes
Aug 10, 2026
| webinar_id: z.string().uuid("Invalid webinar"), | ||
| }); | ||
|
|
||
| export function parseBooleanField(value: FormDataEntryValue | null): boolean { |
Contributor
There was a problem hiding this comment.
remove the parseBooleanField
| tier: webinarTierSchema, | ||
| duration_minutes: durationSchema, | ||
| youtube_url: youtubeUrlSchema.optional(), | ||
| is_active: z.boolean().default(true), |
Contributor
There was a problem hiding this comment.
Suggested change
| is_active: z.boolean().default(true), | |
| is_active: z.enum(["true", "false"]).optional(), |
| tier: webinarTierSchema.optional(), | ||
| duration_minutes: durationSchema.optional(), | ||
| youtube_url: z.union([youtubeUrlSchema, z.literal("")]).optional(), | ||
| is_active: z.boolean().optional(), |
Contributor
There was a problem hiding this comment.
Suggested change
| is_active: z.boolean().optional(), | |
| is_active: z.enum(["true", "false"]).optional(), |
| tier: field(formData, "tier"), | ||
| duration_minutes: field(formData, "duration_minutes"), | ||
| youtube_url: field(formData, "youtube_url") || undefined, | ||
| is_active: formData.has("is_active") |
Contributor
There was a problem hiding this comment.
Suggested change
| is_active: formData.has("is_active") | |
| is_active: field(formData, "is_active"), |
| tier: parsed.data.tier, | ||
| durationMinutes: parsed.data.duration_minutes, | ||
| youtubeUrl: parsed.data.youtube_url || null, | ||
| isActive: parsed.data.is_active, |
Contributor
There was a problem hiding this comment.
Suggested change
| isActive: parsed.data.is_active, | |
| isActive: parsed.data.is_active !== "false", |
| patch.youtubeUrl = parsed.data.youtube_url || null; | ||
| } | ||
| if (parsed.data.is_active !== undefined) { | ||
| patch.isActive = parsed.data.is_active; |
Contributor
There was a problem hiding this comment.
Suggested change
| patch.isActive = parsed.data.is_active; | |
| patch.isActive = parsed.data.is_active === "true"; |
Comment on lines
+170
to
+173
| const deleted = await db | ||
| .delete(webinars) | ||
| .where(eq(webinars.id, parsed.data.webinar_id)) | ||
| .returning({ id: webinars.id }); |
Contributor
There was a problem hiding this comment.
Suggested change
| const deleted = await db | |
| .delete(webinars) | |
| .where(eq(webinars.id, parsed.data.webinar_id)) | |
| .returning({ id: webinars.id }); | |
| let deleted; | |
| try { | |
| deleted = await db | |
| .delete(webinars) | |
| .where(eq(webinars.id, parsed.data.webinar_id)) | |
| .returning({ id: webinars.id }); | |
| } catch (error) { | |
| console.error(error); | |
| return { errors: { _form: ["Could not delete webinar"] } }; | |
| } |
Comment on lines
+138
to
+146
| try { | ||
| await db | ||
| .update(webinars) | ||
| .set(patch) | ||
| .where(eq(webinars.id, parsed.data.webinar_id)); | ||
| } catch (error) { | ||
| console.error(error); | ||
| return { errors: { _form: ["Could not update webinar"] } }; | ||
| } |
Contributor
There was a problem hiding this comment.
Suggested change
| try { | |
| await db | |
| .update(webinars) | |
| .set(patch) | |
| .where(eq(webinars.id, parsed.data.webinar_id)); | |
| } catch (error) { | |
| console.error(error); | |
| return { errors: { _form: ["Could not update webinar"] } }; | |
| } | |
| const updated = await db | |
| .update(webinars) | |
| .set(patch) | |
| .where(eq(webinars.id, parsed.data.webinar_id)) | |
| .returning({ id: webinars.id }); | |
| if (!updated.length) return { errors: { _form: ["Webinar not found"] } }; |
Comment on lines
+110
to
+118
| const [existing] = await db | ||
| .select({ id: webinars.id }) | ||
| .from(webinars) | ||
| .where(eq(webinars.id, parsed.data.webinar_id)) | ||
| .limit(1); | ||
|
|
||
| if (!existing) { | ||
| return { errors: { _form: ["Webinar not found"] } }; | ||
| } |
Contributor
There was a problem hiding this comment.
remove it
Suggested change
| const [existing] = await db | |
| .select({ id: webinars.id }) | |
| .from(webinars) | |
| .where(eq(webinars.id, parsed.data.webinar_id)) | |
| .limit(1); | |
| if (!existing) { | |
| return { errors: { _form: ["Webinar not found"] } }; | |
| } | |
Comment on lines
+5
to
+23
| const youtubeUrlSchema = z | ||
| .string() | ||
| .url("Enter a valid YouTube URL") | ||
| .refine( | ||
| (value) => { | ||
| try { | ||
| const hostname = new URL(value).hostname.toLowerCase(); | ||
| return [ | ||
| "youtube.com", | ||
| "www.youtube.com", | ||
| "youtu.be", | ||
| "www.youtu.be", | ||
| ].includes(hostname); | ||
| } catch { | ||
| return false; | ||
| } | ||
| }, | ||
| { message: "URL must be a YouTube URL" }, | ||
| ); |
Contributor
There was a problem hiding this comment.
Suggested change
| const youtubeUrlSchema = z | |
| .string() | |
| .url("Enter a valid YouTube URL") | |
| .refine( | |
| (value) => { | |
| try { | |
| const hostname = new URL(value).hostname.toLowerCase(); | |
| return [ | |
| "youtube.com", | |
| "www.youtube.com", | |
| "youtu.be", | |
| "www.youtu.be", | |
| ].includes(hostname); | |
| } catch { | |
| return false; | |
| } | |
| }, | |
| { message: "URL must be a YouTube URL" }, | |
| ); | |
| const youtubeUrlSchema = z | |
| .string() | |
| .url("Enter a valid YouTube URL") | |
| .refine( | |
| (value) => { | |
| const hostname = new URL(value).hostname.toLowerCase(); | |
| return [ | |
| "youtube.com", | |
| "www.youtube.com", | |
| "youtu.be", | |
| "www.youtu.be", | |
| ].includes(hostname); | |
| }, | |
| { message: "URL must be a YouTube URL" }, | |
| ); |
Contributor
Author
There was a problem hiding this comment.
Dude I tried that before and it lowkey crashes because if const hostname = new URL(value).hostname.toLowerCase(); fails then this crashes:
return [
"youtube.com",
"www.youtube.com",
"youtu.be",
"www.youtu.be",
].includes(hostname);
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #116
Overview
Make webinars table in DB (was already done) and backend actions (also added schema evaluation in zod)
Testing
Made a dummy page and tested all three endpoints create, modify and delete.
Screenshots / Screencasts
none
Checklist
Tip: You can make the issue and then check them after the fact or replace
[ ]with[x]to check it!