Add social links page

This commit is contained in:
alex 3
2023-11-05 23:53:51 -05:00
parent bdcd97576a
commit 50bca71a3f
9 changed files with 219 additions and 63 deletions
+2
View File
@@ -1,4 +1,5 @@
import { postRouter } from "@/server/api/routers/post";
import { linksRouter } from "./routers/links";
import { createTRPCRouter } from "@/server/api/trpc";
/**
@@ -8,6 +9,7 @@ import { createTRPCRouter } from "@/server/api/trpc";
*/
export const appRouter = createTRPCRouter({
post: postRouter,
links: linksRouter
});
// export type definition of API
+41
View File
@@ -0,0 +1,41 @@
import {z} from "zod";
import {
createTRPCRouter,
publicProcedure,
protectedProcedure
} from "@/server/api/trpc";
export const linksRouter = createTRPCRouter({
create: protectedProcedure
.input(
z.object({
name: z.string().min(1),
url: z.string().min(1),
type: z.string().min(1)
})
)
.mutation(async ({ctx, input}) => {
return ctx.db.socialLink.create({
data: {
name: input.name,
url: input.url,
type: input.type
}
})
}),
delete: protectedProcedure
.input(
z.string().min(1)
)
.query(async ({ctx, input}) => {
return ctx.db.socialLink.delete({
where: {
id: input
}
})
}),
getAll: publicProcedure
.query(async ({ctx}) => {
return ctx.db.socialLink.findMany()
})
})
+12
View File
@@ -28,6 +28,18 @@ export const postRouter = createTRPCRouter({
});
}),
delete: protectedProcedure
.input(
z.string().min(1)
)
.query(async ({ctx, input}) => {
return ctx.db.post.delete({
where: {
id: input
}
})
}),
getOne: publicProcedure
.input(String)
.query(({ ctx, input }) => {