Skip to content
Source
Sign inSign up
TanStack/db
Open History to see the last commit

users.ts

36 lines961 Bytes

1import { router, authedProcedure } from "@/lib/trpc"
2import { z } from "zod"
3import { TRPCError } from "@trpc/server"
4import { users } from "@/db/schema"
5​
6export const usersRouter = router({
7 getAll: authedProcedure.query(async ({ ctx }) => {
8 const allUsers = await ctx.db.select().from(users)
9 return allUsers
10 }),
11​
12 create: authedProcedure.input(z.any()).mutation(async () => {
13 throw new TRPCError({
14 code: "FORBIDDEN",
15 message: "Can't create new users through API",
16 })
17 }),
18​
19 update: authedProcedure
20 .input(z.object({ id: z.string(), data: z.any() }))
21 .mutation(async () => {
22 throw new TRPCError({
23 code: "FORBIDDEN",
24 message: "Can't edit users through API",
25 })
26 }),
27​
28 delete: authedProcedure
29 .input(z.object({ id: z.string() }))
30 .mutation(async () => {
31 throw new TRPCError({
32 code: "FORBIDDEN",
33 message: "Can't delete users through API",
34 })
35 }),
36})