feat: add new board form
This commit is contained in:
@@ -1,14 +1,38 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import { boards } from "~/server/db/schema";
|
||||
import { generateUID } from "~/utils/generateUID";
|
||||
|
||||
import {
|
||||
createTRPCRouter,
|
||||
publicProcedure,
|
||||
} from "~/server/api/trpc";
|
||||
|
||||
export const boardRouter = createTRPCRouter({
|
||||
all: publicProcedure.query(({ ctx }) => {
|
||||
all: publicProcedure.query(async ({ ctx }) => {
|
||||
const userId = ctx.session?.user.id;
|
||||
|
||||
if (!userId) return;
|
||||
|
||||
return ctx.db.query.boards.findMany();
|
||||
})
|
||||
const boards = await ctx.db.query.boards.findMany();
|
||||
|
||||
return boards.map((board) => ({ ...board, id: board.publicId }))
|
||||
}),
|
||||
create: publicProcedure
|
||||
.input(
|
||||
z.object({
|
||||
name: z.string().min(1),
|
||||
}),
|
||||
)
|
||||
.mutation(({ ctx, input }) => {
|
||||
const userId = ctx.session?.user.id;
|
||||
|
||||
if (!userId) return;
|
||||
|
||||
return ctx.db.insert(boards).values({
|
||||
publicId: generateUID(),
|
||||
name: input.name,
|
||||
createdBy: userId,
|
||||
});
|
||||
}),
|
||||
});
|
||||
|
||||
@@ -22,10 +22,11 @@ export const mysqlTable = mysqlTableCreator((name) => `kan.${name}`);
|
||||
export const boards = mysqlTable(
|
||||
"board",
|
||||
{
|
||||
id: varchar("id", { length: 12 }).notNull().primaryKey(),
|
||||
id: bigint("id", { mode: "number" }).primaryKey().autoincrement(),
|
||||
publicId: varchar("publicId", { length: 12 }).notNull(),
|
||||
name: varchar("name", { length: 255 }),
|
||||
createdBy: varchar("createdBy", { length: 255 }).notNull(),
|
||||
createdAt: timestamp("created_at")
|
||||
createdAt: timestamp("createdAt")
|
||||
.default(sql`CURRENT_TIMESTAMP`)
|
||||
.notNull(),
|
||||
updatedAt: timestamp("updatedAt").onUpdateNow(),
|
||||
|
||||
Reference in New Issue
Block a user