Initial Commit

This commit is contained in:
2024-12-19 13:54:15 +05:30
commit 970a972b11
17 changed files with 1487 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
import { FastifyReply, FastifyRequest } from "fastify";
import { createUser, getUser } from "./user.service";
import { CreateUserInput } from "./user.schema";
export async function createUserHandler(
req: FastifyRequest<{
Body: CreateUserInput;
}>,
res: FastifyReply
) {
const body = req.body;
try {
const user = await createUser(body);
return res.code(201).send(user);
} catch (err) {
return err;
}
}
export async function getUserHandler(
req: FastifyRequest<{ Params: { userId: string } }>,
res: FastifyReply
) {
const { userId } = req.params;
try {
const user = await getUser(userId);
if (user == null) return res.code(404).send({ error: "user not found" });
return res.code(200).send(user);
} catch (err) {
return err;
}
}