Added token authentication, organization module. Moved server bootstrapping code to server.ts file
This commit is contained in:
33
src/tokens/token.controller.ts
Normal file
33
src/tokens/token.controller.ts
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user