responsive navbar
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
import { router } from "../trpc";
|
||||
import { CvCategoryRouter } from "./cvCategory";
|
||||
import { publicProcedure } from "~/server/trpc";
|
||||
import { CvRouter } from "./cv";
|
||||
|
||||
export const trpcRouter = router({
|
||||
hello: publicProcedure.query(async () => "world"),
|
||||
cvCategory: CvCategoryRouter
|
||||
cv: CvRouter
|
||||
})
|
||||
|
||||
export type TrpcRouter = typeof trpcRouter
|
||||
|
||||
45
src/server/routers/cv/category.ts
Normal file
45
src/server/routers/cv/category.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import { db } from "~/server/db";
|
||||
import { publicProcedure, router } from "~/server/trpc";
|
||||
import { cvCategory } from "~/server/db/schema";
|
||||
import { createInsertSchema, createUpdateSchema, createSelectSchema} from 'drizzle-zod'
|
||||
import { z } from 'zod'
|
||||
import { eq } from "drizzle-orm";
|
||||
|
||||
const selectShema = createSelectSchema(cvCategory)
|
||||
const insertShema = createInsertSchema(cvCategory)
|
||||
const updateSchema = createUpdateSchema(cvCategory)
|
||||
|
||||
export const CategoryRouter = router({
|
||||
list: publicProcedure.query(async () => {
|
||||
const categories = await db.query.cvCategory.findMany({
|
||||
orderBy: (model, {desc} ) => desc(model.name)
|
||||
});
|
||||
return categories;
|
||||
}),
|
||||
get: publicProcedure.input(selectShema.pick({id: true})).query(async (opts) => {
|
||||
const { input } = opts
|
||||
const category = await db.query.cvCategory.findFirst({
|
||||
where: eq(cvCategory.id,input.id)
|
||||
})
|
||||
return category;
|
||||
}),
|
||||
create: publicProcedure.input(insertShema).mutation(async (opts) => {
|
||||
const { input } = opts;
|
||||
const category = await db.insert(cvCategory).values(input).returning().execute()
|
||||
return category
|
||||
}),
|
||||
update: publicProcedure
|
||||
.input(z.object({
|
||||
by: selectShema.pick({id:true}),
|
||||
update: updateSchema
|
||||
}))
|
||||
.mutation(async (opts) => {
|
||||
const {input} = opts;
|
||||
const category = await db.update(cvCategory)
|
||||
.set(input.update)
|
||||
.returning()
|
||||
.where(eq(cvCategory.id,input.by.id))
|
||||
return category
|
||||
})
|
||||
})
|
||||
|
||||
6
src/server/routers/cv/index.ts
Normal file
6
src/server/routers/cv/index.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { router } from "~/server/trpc"
|
||||
import { CategoryRouter } from "./category"
|
||||
|
||||
export const CvRouter = router({
|
||||
category: CategoryRouter
|
||||
})
|
||||
@@ -1,12 +0,0 @@
|
||||
import { db } from "~/server/db";
|
||||
import { publicProcedure, router } from "~/server/trpc";
|
||||
|
||||
export const CvCategoryRouter = router({
|
||||
get: publicProcedure.query(async () => {
|
||||
const categories = await db.query.cvCategory.findMany({
|
||||
orderBy: (model, {desc} ) => desc(model.name)
|
||||
});
|
||||
return categories;
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user