Initial Commit
This commit is contained in:
35
src/user/user.controller.ts
Normal file
35
src/user/user.controller.ts
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user