Skip to content

Commit

Permalink
Fix blog validations on client
Browse files Browse the repository at this point in the history
  • Loading branch information
ssihala committed Feb 19, 2025
1 parent c97859e commit d354c3a
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion src/client/routes/blogs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const Route = createFileRoute("/blogs")({
title: newBlogTitle,
content: newBlogContent,
tags: newBlogTags.split(",").map((tag) => tag.trim()),
authorId: "SASE Historian", // TODO: This should be optional
author_id: "SASE Historian", // TODO: This should be optional
},
{
onError: (error: Error) => {
Expand Down
2 changes: 1 addition & 1 deletion src/server/api/blogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const blogRoutes = new Hono();
blogRoutes.get("/blogs/all", async (c) => {
try {
const result = await db.select().from(Schema.blogs);
return c.json(result);
return c.json({ data: result });
} catch (error) {
console.log(error);
return createErrorResponse(c, "MISSING_BLOG", "Cannot fetch blogs", 400);
Expand Down
18 changes: 9 additions & 9 deletions src/shared/schema/blogSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ export const blogSchema = z.object({
id: z.string().min(1, "Blog ID is required."),
title: z.string().min(1, "Title is required."),
content: z.string().min(1, "Content cannot be empty."),
authorId: z.string().min(1, "Author ID is required."),
publishedDate: z.number().int().min(0, "Published date must be a valid timestamp."),
timeUpdated: z.number().int().min(0, "Update time must be a valid timestamp."),
lastUpdateDate: z.string().min(1, "Last update date must be a valid date.").optional(),
author_id: z.string().min(1, "Author ID is required."),
published_date: z.string().min(0, "Published date must be a valid timestamp."),
time_updated: z.string().min(0, "Update time must be a valid timestamp."),
last_update_date: z.string().min(1, "Last update date must be a valid date.").optional(),
});

export const blogTitleSchema = z.object({
Expand All @@ -20,18 +20,18 @@ export const blogTitleSchema = z.object({
export const createBlogSchema = blogSchema
.omit({
id: true,
timeUpdated: true,
publishedDate: true,
lastUpdateDate: true,
time_updated: true,
published_date: true,
last_update_date: true,
})
.extend({
tags: z.array(z.string()).optional(),
});

export const updateBlogSchema = blogSchema.partial().omit({
id: true, // Immutable fields
authorId: true,
publishedDate: true,
author_id: true,
published_date: true,
});

// Export TypeScript types
Expand Down
2 changes: 1 addition & 1 deletion src/shared/schema/responseSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type ApiResponse<T> = {

export const successResponseSchema = z.object({
data: z.any(),
message: z.string(),
message: z.string().optional(),
meta: z.object({}).optional(), // Optional metadata, e.g., pagination details
});

Expand Down

0 comments on commit d354c3a

Please sign in to comment.