Added token authentication, organization module. Moved server bootstrapping code to server.ts file

This commit is contained in:
2024-12-19 21:49:54 +05:30
parent 970a972b11
commit 4b49c43a0c
16 changed files with 652 additions and 22 deletions

View File

@@ -0,0 +1,33 @@
import { FastifyReply, FastifyRequest } from "fastify";
import { CreateTokenInput } from "./token.schema";
import { createToken, getToken } from "./token.service";
export async function createTokenHandler(
req: FastifyRequest<{ Body: CreateTokenInput }>,
res: FastifyReply
) {
const input = req.body;
try {
const result = await createToken(input);
return res.code(201).send(result);
} catch (err) {
return err;
}
}
export async function getTokenHandler(
req: FastifyRequest<{ Params: { tokenId: string } }>,
res: FastifyReply
) {
const { tokenId } = req.params;
try {
const token = await getToken(tokenId);
if (token === null) return res.code(404).send();
return res.code(200).send(token);
} catch (err) {
return err;
}
}