Skip to content

Commit 9a431f3

Browse files
committed
created backend for router and user schema via prisma
Coauthored: James Nghiem, Benjamin Margolius, Eric Yun, Wilton Lee
1 parent 3527ae8 commit 9a431f3

File tree

6 files changed

+49
-20
lines changed

6 files changed

+49
-20
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-- CreateTable
2+
CREATE TABLE "User" (
3+
"id" TEXT NOT NULL PRIMARY KEY,
4+
"name" TEXT NOT NULL,
5+
"email" TEXT NOT NULL,
6+
"admin" BOOLEAN NOT NULL DEFAULT false,
7+
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
8+
"updatedAt" DATETIME NOT NULL
9+
);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Please do not edit this file manually
2+
# It should be added in your version-control system (i.e. Git)
3+
provider = "sqlite"

www/prisma/schema.prisma

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ datasource db {
1010
url = env("DATABASE_URL")
1111
}
1212

13-
model Example {
14-
id String @id @default(cuid())
13+
model User {
14+
id String @id @default(cuid())
15+
name String
16+
email String
17+
admin Boolean @default(false)
1518
createdAt DateTime @default(now())
1619
updatedAt DateTime @updatedAt
1720
}

www/src/server/trpc/router/_app.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { router } from "../trpc";
2-
import { exampleRouter } from "./example";
2+
import { userRouter } from "./user";
33

44
export const appRouter = router({
5-
example: exampleRouter,
5+
user : userRouter,
66
});
77

88
// export type definition of API

www/src/server/trpc/router/example.ts

Lines changed: 0 additions & 16 deletions
This file was deleted.

www/src/server/trpc/router/user.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { z } from "zod";
2+
3+
import { router, publicProcedure } from "../trpc";
4+
5+
export const userRouter = router({
6+
createUser: publicProcedure
7+
.input(z.object({
8+
name: z.string(),
9+
email: z.string().email()})
10+
) // name and email
11+
.mutation(({ input, ctx }) => {
12+
// we want to add to our database with the name, email, admin defaulted to false as column values
13+
return ctx.prisma.user.create({
14+
data: {
15+
name: input.name,
16+
email: input.email,
17+
}
18+
})
19+
}),
20+
});
21+
22+
23+
//const greeting = trpc.userRouter.hello({text: ""});
24+
25+
/**
26+
* hello -- name of endpoint api
27+
* .input will be what we are going to be expecting
28+
* .query/.mutation will be what is going to happen once we go to this endpoint api
29+
* (differentiation is that query and mutation should be adjusted for read and CUD functionality)
30+
*/

0 commit comments

Comments
 (0)