feat: extend schema with list and cards
This commit is contained in:
@@ -1,3 +1,15 @@
|
||||
export default function BoardPage() {
|
||||
"use client";
|
||||
|
||||
import { api } from "~/trpc/react";
|
||||
|
||||
export default function BoardPage({ params }: { params: { id: string[] } }) {
|
||||
const boardId = params.id[0];
|
||||
|
||||
if (!boardId) return <></>;
|
||||
|
||||
const { data } = api.board.byId.useQuery({ id: boardId });
|
||||
|
||||
console.log({ data });
|
||||
|
||||
return <></>;
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ export default async function Layout(props: { children: React.ReactNode }) {
|
||||
</div>
|
||||
|
||||
<div className="flex h-full w-full">
|
||||
<nav className="flex w-64 flex-col justify-between border-r border-dark-600 px-5 py-5">
|
||||
<nav className="flex w-72 flex-col justify-between border-r border-dark-600 px-5 py-5">
|
||||
<div>
|
||||
<ul role="list" className="-mx-2 my-6 space-y-1">
|
||||
{navigation.map((item) => (
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { z } from "zod";
|
||||
import { eq } from "drizzle-orm";
|
||||
|
||||
import { boards } from "~/server/db/schema";
|
||||
import { generateUID } from "~/utils/generateUID";
|
||||
@@ -18,6 +19,20 @@ export const boardRouter = createTRPCRouter({
|
||||
|
||||
return boards.map((board) => ({ ...board, id: board.publicId }))
|
||||
}),
|
||||
byId: publicProcedure
|
||||
.input(z.object({ id: z.string().min(12) }))
|
||||
.query(({ ctx, input }) =>
|
||||
ctx.db.query.boards.findFirst({
|
||||
where: eq(boards.publicId, input.id),
|
||||
with: {
|
||||
lists: {
|
||||
with: {
|
||||
cards: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
),
|
||||
create: publicProcedure
|
||||
.input(
|
||||
z.object({
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
} from "next-auth";
|
||||
|
||||
import { db } from "~/server/db";
|
||||
import { mysqlTable } from "~/server/db/schema";
|
||||
import { mySqlTable } from "~/server/db/schema";
|
||||
|
||||
/**
|
||||
* Module augmentation for `next-auth` types. Allows us to add custom properties to the `session`
|
||||
@@ -44,7 +44,7 @@ export const authOptions: NextAuthOptions = {
|
||||
},
|
||||
}),
|
||||
},
|
||||
adapter: DrizzleAdapter(db, mysqlTable),
|
||||
adapter: DrizzleAdapter(db, mySqlTable),
|
||||
pages: {
|
||||
signIn: "/auth/login",
|
||||
// signOut: "/auth/signout",
|
||||
|
||||
@@ -17,13 +17,13 @@ import { type AdapterAccount } from "next-auth/adapters";
|
||||
*
|
||||
* @see https://orm.drizzle.team/docs/goodies#multi-project-schema
|
||||
*/
|
||||
export const mysqlTable = mysqlTableCreator((name) => `kan.${name}`);
|
||||
export const mySqlTable = mysqlTableCreator((name) => `kan.${name}`);
|
||||
|
||||
export const boards = mysqlTable(
|
||||
export const boards = mySqlTable(
|
||||
"board",
|
||||
{
|
||||
id: bigint("id", { mode: "number" }).primaryKey().autoincrement(),
|
||||
publicId: varchar("publicId", { length: 12 }).notNull(),
|
||||
publicId: varchar("publicId", { length: 12 }).notNull().unique(),
|
||||
name: varchar("name", { length: 255 }),
|
||||
createdBy: varchar("createdBy", { length: 255 }).notNull(),
|
||||
createdAt: timestamp("createdAt")
|
||||
@@ -33,10 +33,72 @@ export const boards = mysqlTable(
|
||||
},
|
||||
);
|
||||
|
||||
export const users = mysqlTable("user", {
|
||||
export const boardsRelations = relations(boards, ({ one, many }) => ({
|
||||
createdBy: one(users, {
|
||||
fields: [boards.createdBy],
|
||||
references: [users.id],
|
||||
}),
|
||||
lists: many(lists),
|
||||
}));
|
||||
|
||||
export const lists = mySqlTable(
|
||||
"list",
|
||||
{
|
||||
id: bigint("id", { mode: "number" }).primaryKey().autoincrement(),
|
||||
publicId: varchar("publicId", { length: 12 }).notNull().unique(),
|
||||
name: varchar("name", { length: 256 }).notNull(),
|
||||
createdBy: varchar("createdBy", { length: 256 }).notNull(),
|
||||
createdAt: timestamp("createdAt")
|
||||
.default(sql`CURRENT_TIMESTAMP`)
|
||||
.notNull(),
|
||||
updatedAt: timestamp("updatedAt").onUpdateNow(),
|
||||
boardId: varchar("boardId", { length: 256 }).notNull(),
|
||||
}
|
||||
);
|
||||
|
||||
export const listsRelations = relations(lists, ({ one, many }) => ({
|
||||
createdBy: one(users, {
|
||||
fields: [lists.createdBy],
|
||||
references: [users.id],
|
||||
}),
|
||||
board: one(boards, {
|
||||
fields: [lists.boardId],
|
||||
references: [boards.id],
|
||||
}),
|
||||
cards: many(cards)
|
||||
}));
|
||||
|
||||
export const cards = mySqlTable(
|
||||
"card",
|
||||
{
|
||||
id: bigint("id", { mode: "number" }).primaryKey().autoincrement(),
|
||||
publicId: varchar("publicId", { length: 12 }).notNull().unique(),
|
||||
title: varchar("title", { length: 256 }).notNull(),
|
||||
description: varchar("description", { length: 256 }),
|
||||
createdBy: varchar("createdBy", { length: 256 }).notNull(),
|
||||
createdAt: timestamp("createdAt")
|
||||
.default(sql`CURRENT_TIMESTAMP`)
|
||||
.notNull(),
|
||||
updatedAt: timestamp("updatedAt").onUpdateNow(),
|
||||
listId: varchar("listId", { length: 256 }).notNull(),
|
||||
}
|
||||
);
|
||||
|
||||
export const cardsRelations = relations(cards, ({ one }) => ({
|
||||
createdBy: one(users, {
|
||||
fields: [cards.createdBy],
|
||||
references: [users.id],
|
||||
}),
|
||||
list: one(lists, {
|
||||
fields: [cards.listId],
|
||||
references: [lists.id],
|
||||
}),
|
||||
}));
|
||||
|
||||
export const users = mySqlTable("user", {
|
||||
id: varchar("id", { length: 255 }).notNull().primaryKey(),
|
||||
name: varchar("name", { length: 255 }),
|
||||
email: varchar("email", { length: 255 }).notNull(),
|
||||
email: varchar("email", { length: 255 }).notNull().unique(),
|
||||
emailVerified: timestamp("emailVerified", {
|
||||
mode: "date",
|
||||
fsp: 3,
|
||||
@@ -46,9 +108,12 @@ export const users = mysqlTable("user", {
|
||||
|
||||
export const usersRelations = relations(users, ({ many }) => ({
|
||||
accounts: many(accounts),
|
||||
boards: many(boards),
|
||||
cards: many(cards),
|
||||
lists: many(lists),
|
||||
}));
|
||||
|
||||
export const accounts = mysqlTable(
|
||||
export const accounts = mySqlTable(
|
||||
"account",
|
||||
{
|
||||
userId: varchar("userId", { length: 255 }).notNull(),
|
||||
@@ -75,7 +140,7 @@ export const accountsRelations = relations(accounts, ({ one }) => ({
|
||||
user: one(users, { fields: [accounts.userId], references: [users.id] }),
|
||||
}));
|
||||
|
||||
export const sessions = mysqlTable(
|
||||
export const sessions = mySqlTable(
|
||||
"session",
|
||||
{
|
||||
sessionToken: varchar("sessionToken", { length: 255 })
|
||||
@@ -93,7 +158,7 @@ export const sessionsRelations = relations(sessions, ({ one }) => ({
|
||||
user: one(users, { fields: [sessions.userId], references: [users.id] }),
|
||||
}));
|
||||
|
||||
export const verificationTokens = mysqlTable(
|
||||
export const verificationTokens = mySqlTable(
|
||||
"verificationToken",
|
||||
{
|
||||
identifier: varchar("identifier", { length: 255 }).notNull(),
|
||||
|
||||
Reference in New Issue
Block a user