created list schema
This commit is contained in:
@@ -16,7 +16,7 @@ import { api } from "~/trpc/react";
|
||||
|
||||
const newName = "test new name";
|
||||
|
||||
export const ListButton = ({ id, name }: { id: number; name: string }) => {
|
||||
export const ListButton = ({ id, title }: { id: number; title: string }) => {
|
||||
const dialogConfirmation = useDialogConfirmation();
|
||||
|
||||
const { mutate: updateMutation } = api.list.update.useMutation({
|
||||
@@ -30,7 +30,7 @@ export const ListButton = ({ id, name }: { id: number; name: string }) => {
|
||||
},
|
||||
});
|
||||
|
||||
const handleRename = () => updateMutation({ listId: id, name: newName });
|
||||
const handleRename = () => updateMutation({ listId: id, title: newName });
|
||||
|
||||
const handleDelete = async () => {
|
||||
const didConfirm = await dialogConfirmation({});
|
||||
@@ -51,7 +51,7 @@ export const ListButton = ({ id, name }: { id: number; name: string }) => {
|
||||
href={`/list/${id}`}
|
||||
className="w-full text-left underline-offset-4 hover:underline"
|
||||
>
|
||||
{name}
|
||||
{title}
|
||||
</Link>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
|
||||
@@ -28,8 +28,8 @@ export default async function Home() {
|
||||
</div>
|
||||
|
||||
<div className="space-y-1">
|
||||
{allLists.map(({ id, name }) => (
|
||||
<ListButton key={id} id={id} name={name} />
|
||||
{allLists.map(({ id, title }) => (
|
||||
<ListButton key={id} id={id} title={title} />
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,29 +1,35 @@
|
||||
import { and, eq } from "drizzle-orm";
|
||||
import { z } from "zod";
|
||||
import {
|
||||
listCreationFormSchema,
|
||||
listNameSchema,
|
||||
listTitleSchema,
|
||||
} from "~/lib/schemas/list-creation-form";
|
||||
|
||||
import { createTRPCRouter, protectedProcedure } from "~/server/api/trpc";
|
||||
import { lists } from "~/server/db/schema";
|
||||
|
||||
export const listRouter = createTRPCRouter({
|
||||
create: protectedProcedure
|
||||
.input(listCreationFormSchema)
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
return [];
|
||||
}),
|
||||
.mutation(({ ctx, input }) =>
|
||||
ctx.db.insert(lists).values({
|
||||
userId: ctx.session.user.id,
|
||||
title: input.title,
|
||||
variant: input.variant,
|
||||
labels: input.labels.join(","),
|
||||
showId: input.id,
|
||||
idPrefix: input.idPrefix,
|
||||
}),
|
||||
),
|
||||
getAll: protectedProcedure.query(async ({ ctx }) => {
|
||||
return [
|
||||
{ id: 0, name: "Groceries" },
|
||||
{ id: 1, name: "Christmas" },
|
||||
{ id: 2, name: "Salt Seeker" },
|
||||
{ id: 3, name: "Maize Walker" },
|
||||
{ id: 4, name: "Sympathy for the Machine" },
|
||||
{
|
||||
id: 5,
|
||||
name: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor elit incididunt ut labore et dolore magna aliqua.",
|
||||
},
|
||||
];
|
||||
const allLists = await ctx.db.query.lists.findMany({
|
||||
where: and(eq(lists.userId, ctx.session.user.id)),
|
||||
});
|
||||
const formattedLists = allLists.map((list) => ({
|
||||
...list,
|
||||
labels: list.labels?.split(",") ?? [],
|
||||
}));
|
||||
return formattedLists;
|
||||
}),
|
||||
get: protectedProcedure
|
||||
.input(z.object({ listId: z.coerce.number() }))
|
||||
@@ -31,7 +37,7 @@ export const listRouter = createTRPCRouter({
|
||||
return { name: "Groceries", tasks: [] };
|
||||
}),
|
||||
update: protectedProcedure
|
||||
.input(z.object({ listId: z.number(), name: listNameSchema }))
|
||||
.input(z.object({ listId: z.number(), title: listTitleSchema }))
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
return [];
|
||||
}),
|
||||
|
||||
38
src/server/db/schema/app.ts
Normal file
38
src/server/db/schema/app.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { relations } from "drizzle-orm";
|
||||
import { boolean, integer, serial, text, varchar } from "drizzle-orm/pg-core";
|
||||
import { VARIANTS } from "~/lib/data/list-variants";
|
||||
import { LABELS } from "~/lib/data/task-labels";
|
||||
import { PRIORITIES } from "~/lib/data/task-priority";
|
||||
import { STATUSES } from "~/lib/data/task-status";
|
||||
import { users } from "~/server/db/schema/auth";
|
||||
import { createTable } from "~/server/db/schema/create-table";
|
||||
|
||||
export const lists = createTable("list", {
|
||||
id: serial("id").primaryKey(),
|
||||
userId: varchar("userId", { length: 255 }).notNull(),
|
||||
title: varchar("title", { length: 128 }).notNull(),
|
||||
variant: varchar("variant", { enum: VARIANTS }).notNull(),
|
||||
labels: text("labels"),
|
||||
showId: boolean("showId").default(false).notNull(),
|
||||
idPrefix: varchar("idPrefix", { length: 8 }),
|
||||
lastTaskId: integer("lastTaskId").default(0).notNull(),
|
||||
});
|
||||
|
||||
export const listRelations = relations(lists, ({ one }) => ({
|
||||
user: one(users, { fields: [lists.userId], references: [users.id] }),
|
||||
}));
|
||||
|
||||
export const tasks = createTable("task", {
|
||||
id: serial("id").primaryKey(),
|
||||
listId: serial("listId").notNull(),
|
||||
title: varchar("title", { length: 128 }).notNull(),
|
||||
isChecked: boolean("isChecked").default(false).notNull(),
|
||||
visibleId: varchar("visibleId", { length: 16 }),
|
||||
label: varchar("label", { enum: LABELS }),
|
||||
status: varchar("status", { enum: STATUSES }),
|
||||
priority: varchar("priority", { enum: PRIORITIES }),
|
||||
});
|
||||
|
||||
export const taskRelations = relations(tasks, ({ one }) => ({
|
||||
list: one(lists, { fields: [tasks.listId], references: [lists.id] }),
|
||||
}));
|
||||
@@ -1 +1,2 @@
|
||||
export * from "./auth";
|
||||
export * from "./app";
|
||||
|
||||
Reference in New Issue
Block a user