-
Notifications
You must be signed in to change notification settings - Fork 9
homepage & user-details page. Along with backend. #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
33e9b43
cc40bca
accb2de
f1f767f
c334efa
b2b06c6
6d04345
32cbdb0
9bbc7ed
c3c399c
bd2e12b
d489862
ca32065
0cb9b80
52c9a82
68825da
c437057
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| node_modules | ||
| .turbo | ||
| .DS_Store | ||
| .DS_Store | ||
| todo.md | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,16 +13,18 @@ import { users } from "./user.schema"; | |
| export const posts = pgTable( | ||
| "post", | ||
| { | ||
| id: uuid("id").primaryKey().notNull().unique(), | ||
| id: uuid("id").primaryKey().notNull().unique().defaultRandom(), | ||
|
|
||
| threadId: uuid("thread_id") | ||
| .references(() => threads.id) | ||
| .notNull(), | ||
|
|
||
| vote: integer("vote"), | ||
| content: text("content"), | ||
| vote: integer("vote").default(0), | ||
| content: text("content").notNull(), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's great that you've made the You've correctly defined
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes yes thought of this will add it
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ujsquared ye wala kardiyo |
||
|
|
||
| createdAt: timestamp("created_at", { mode: "string" }).notNull(), | ||
| createdAt: timestamp("created_at", { mode: "string" }) | ||
| .notNull() | ||
| .defaultNow(), | ||
| updatedAt: timestamp("updated_at", { mode: "string" }), | ||
| deletedAt: timestamp("deleted_at", { mode: "string" }), | ||
|
|
||
|
|
@@ -32,7 +34,7 @@ export const posts = pgTable( | |
| updatedBy: uuid("updated_by").references(() => users.id), | ||
| deletedBy: uuid("deleted_by").references(() => users.id), | ||
|
|
||
| isApproved: boolean("is_approved"), | ||
| isApproved: boolean("is_approved").default(false), | ||
| }, | ||
| (table) => [ | ||
| index("idx_post_created_by").on(table.createdBy), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import { z } from "zod"; | ||
| import type { posts } from "@/db/schema/post.schema"; | ||
|
|
||
| export type Post = typeof posts.$inferSelect; | ||
|
|
||
| export const createPostSchema = z.object({ | ||
| threadId: z.string().uuid(), | ||
| content: z.string().min(1, "Content is required").max(10_000), | ||
| }); | ||
| export type CreatePostInput = z.infer<typeof createPostSchema>; | ||
|
|
||
| export const updatePostSchema = z | ||
| .object({ | ||
| content: z.string().min(1).max(10_000).optional(), | ||
| }) | ||
| .refine((data) => Object.keys(data).length > 0, { | ||
| message: "At least one field must be provided", | ||
| }); | ||
| export type UpdatePostInput = z.infer<typeof updatePostSchema>; | ||
|
|
||
| export const postIdParamsSchema = z.object({ | ||
| id: z.string().uuid(), | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import { z } from "zod"; | ||
| import type { threads } from "@/db/schema/thread.schema"; | ||
|
|
||
| export type Thread = typeof threads.$inferSelect; | ||
|
|
||
| // threadIdParamsSchema already declared above | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment is misleading as export const threadIdParamsSchema = z.object({
id: z.string().uuid(),
});
// threadIdParamsSchema already declared above
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @iamanishx PTAL |
||
|
|
||
| export const createThreadSchema = z.object({ | ||
| threadTitle: z.string().min(1).max(255), | ||
| topicId: z.string().uuid(), | ||
| }); | ||
|
|
||
| export type CreateThreadInput = z.infer<typeof createThreadSchema>; | ||
|
|
||
| export const updateThreadSchema = z | ||
| .object({ | ||
| threadTitle: z.string().min(1).max(255).optional(), | ||
| // optionally allow moving thread to another topic | ||
| topicId: z.string().uuid().optional(), | ||
| // lock/pin handled by separate endpoints in many systems, skip for now | ||
| }) | ||
| .refine((data) => Object.keys(data).length > 0, { | ||
| message: "At least one field must be provided", | ||
| }); | ||
| export type UpdateThreadInput = z.infer<typeof updateThreadSchema>; | ||
|
|
||
| export const threadIdParamsSchema = z.object({ | ||
| id: z.string().uuid(), | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import { z } from "zod"; | ||
| import type { topics } from "@/db/schema/topic.schema"; | ||
|
|
||
| export type Topic = typeof topics.$inferSelect; | ||
|
|
||
| export const topicIdParamsSchema = z.object({ | ||
| id: z.string().uuid(), | ||
| }); | ||
|
|
||
| export const createTopicSchema = z.object({ | ||
| name: z.string().min(1).max(100), | ||
| description: z.string().min(1).max(500), | ||
| }); | ||
|
|
||
| export type CreateTopicInput = z.infer<typeof createTopicSchema>; | ||
|
|
||
| export const updateTopicSchema = z | ||
| .object({ | ||
| name: z.string().min(1).max(100).optional(), | ||
| description: z.string().min(1).max(500).optional(), | ||
| }) | ||
| .refine((data) => Object.keys(data).length > 0, { | ||
| message: "At least one field must be provided", | ||
| }); | ||
| export type UpdateTopicInput = z.infer<typeof updateTopicSchema>; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import { z } from "zod"; | ||
| import type { users } from "@/db/schema/user.schema"; | ||
|
|
||
| export type User = typeof users.$inferSelect; | ||
| export const userDetailsParamsSchema = z.object({ | ||
| username: z | ||
| .string() | ||
| .min(3) | ||
| .max(32) | ||
| .regex( | ||
| /^[a-zA-Z0-9_]+$/, | ||
| "Only letters, numbers, and underscore are allowed", | ||
| ), | ||
| }); | ||
| export type UserDetailsParams = z.infer<typeof userDetailsParamsSchema>; | ||
|
|
||
| export const userIdParamsSchema = z.object({ | ||
| id: z.string().uuid(), | ||
| }); | ||
| export type UserIdParams = z.infer<typeof userIdParamsSchema>; | ||
| export const userUpdateSchema = z | ||
| .object({ | ||
| username: z | ||
| .string() | ||
| .min(3) | ||
| .max(32) | ||
| .regex( | ||
| /^[a-zA-Z0-9_]+$/, | ||
| "Only letters, numbers, and underscore are allowed", | ||
| ) | ||
| .optional(), | ||
| firstName: z.string().max(50).nullable().optional(), | ||
| lastName: z.string().max(50).nullable().optional(), | ||
| pronouns: z.string().max(50).nullable().optional(), | ||
| bio: z.string().max(280).nullable().optional(), | ||
| branch: z.string().max(100).nullable().optional(), | ||
| passingOutYear: z.number().int().min(2000).max(2100).nullable().optional(), | ||
| }) | ||
| .strict(); | ||
| export type UserUpdateInput = z.infer<typeof userUpdateSchema>; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,17 @@ | ||
| import type { FastifyInstance } from "fastify"; | ||
| import { authRoutes } from "./auth"; | ||
| import { postRoutes } from "./posts"; | ||
| import { threadRoutes } from "./threads"; | ||
| import { topicRoutes } from "./topics"; | ||
| import { userRoutes } from "./user"; | ||
|
|
||
| export async function appRouter(fastify: FastifyInstance) { | ||
| // Ensure the request object has a userId property at runtime | ||
| // Middleware will assign the real ID when authenticated | ||
| fastify.decorateRequest("userId", undefined); | ||
| fastify.register(authRoutes, { prefix: "/auth" }); | ||
| fastify.register(userRoutes, { prefix: "/user" }); | ||
| fastify.register(topicRoutes); | ||
| fastify.register(threadRoutes); | ||
| fastify.register(postRoutes); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i need to remove this from commit history so bad. ; (