diff --git a/apps/api/app/api/[[...route]]/route.ts b/apps/api/app/api/[[...route]]/route.ts index 80bf534..d9ad22f 100644 --- a/apps/api/app/api/[[...route]]/route.ts +++ b/apps/api/app/api/[[...route]]/route.ts @@ -6,51 +6,52 @@ export const runtime = "nodejs"; const app = new Hono().basePath("/api"); -app.get("/hello",async(c) => { - const test = await prisma.user.findMany() - return c.json({ - test - }); -}) -.patch( async(c) => { - const name = await c.req.json() - const test = await prisma.user.update({ - where: { - id: "123", - }, - data: { - name:name.name - } +app + .get("/hello", async (c) => { + const test = await prisma.user.findMany(); + return c.json({ + test, + }); }) - return c.json({ - test - }); -}) -.delete( async(c) => { - const test = await prisma.user.delete({ - where: { - id: "2", - } + .patch(async (c) => { + const name = await c.req.json(); + const test = await prisma.user.update({ + where: { + id: "123", + }, + data: { + name: name.name, + }, + }); + return c.json({ + test, + }); }) - return c.json({ - test - }); -}) -.post(async(c) => { - const body = await c.req.json() - console.log(body) - const test = await prisma.user.create({ - data: body + .delete(async (c) => { + const test = await prisma.user.delete({ + where: { + id: "2", + }, + }); + return c.json({ + test, + }); }) - return c.json({ - test + .post(async (c) => { + const body = await c.req.json(); + console.log(body); + const test = await prisma.user.create({ + data: body, + }); + return c.json({ + test, + }); }); -}); -app.get("/health", async(c) => { +app.get("/health", async (c) => { return c.json({ - message:"i am alive", - status:200 + message: "i am alive", + status: 200, }); }); @@ -59,4 +60,4 @@ const POST = handle(app); const PATCH = handle(app); const DELETE = handle(app); -export {GET, PATCH, POST, DELETE} \ No newline at end of file +export { GET, PATCH, POST, DELETE }; diff --git a/apps/api/tests/hello.test.ts b/apps/api/tests/hello.test.ts index dc952bd..89d267f 100644 --- a/apps/api/tests/hello.test.ts +++ b/apps/api/tests/hello.test.ts @@ -39,7 +39,9 @@ describe("API Routes", () => { const mockUsers = [{ id: "123", name: "New User" }]; prisma.user.findMany.mockResolvedValue(mockUsers); - const req = new Request("http:/localhost:3000/api/hello", { method: "GET" }); + const req = new Request("http:/localhost:3000/api/hello", { + method: "GET", + }); const res = await GET(req); expect(res.status).toBe(200); @@ -68,7 +70,9 @@ describe("API Routes", () => { const deletedUser = { id: "2", name: "Deleted User" }; prisma.user.delete.mockResolvedValue(deletedUser); - const req = new Request("http:/localhost:3000/api/hello", { method: "DELETE" }); + const req = new Request("http:/localhost:3000/api/hello", { + method: "DELETE", + }); const res = await DELETE(req); expect(res.status).toBe(200); @@ -77,7 +81,9 @@ describe("API Routes", () => { }); it("GET /api/health should return health status", async () => { - const req = new Request("http:/localhost:3000/api/health", { method: "GET" }); + const req = new Request("http:/localhost:3000/api/health", { + method: "GET", + }); const res = await GET(req); expect(res.status).toBe(200);