eduproj/api/index.ts

33 lines
595 B
TypeScript

import express, { json } from "express";
import { PrismaClient } from "@prisma/client";
const prisma = new PrismaClient();
const app = express();
app.use(json());
app.get("/hello", (_, res) => {
res.send("hellosu there");
});
app.get("/user/:userId(\\d+)", async (req, res) => {
const userId = parseInt(req.params.userId);
const thisUser = await prisma.user.findFirst({
where: { id: userId },
});
if (!thisUser) {
return res.sendStatus(404);
}
res.send(thisUser);
});
/**
* logic for our api will go here
*/
export default {
"path": "/api",
"handler": app,
};