Added token authentication, organization module. Moved server bootstrapping code to server.ts file
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { FastifyRequest, FastifyReply } from "fastify";
|
||||
import { CreateOrgInput } from "./organization.schema";
|
||||
import { createOrg } from "./organization.service";
|
||||
import { createOrg, getOrg } from "./organization.service";
|
||||
|
||||
export async function createOrgHandler(
|
||||
req: FastifyRequest<{ Body: CreateOrgInput }>,
|
||||
@@ -15,3 +15,20 @@ export async function createOrgHandler(
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
export async function getOrgHandler(
|
||||
req: FastifyRequest<{ Params: { orgId: string } }>,
|
||||
res: FastifyReply
|
||||
) {
|
||||
const { orgId } = req.params;
|
||||
|
||||
try {
|
||||
const org = await getOrg(orgId);
|
||||
if (org === null)
|
||||
return res.code(404).send({ error: "resource not found" });
|
||||
|
||||
return res.code(200).send(org);
|
||||
} catch (err) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { FastifyInstance } from "fastify";
|
||||
import { $org } from "./organization.schema";
|
||||
import { createOrgHandler } from "./organization.controller";
|
||||
import { createOrgHandler, getOrgHandler } from "./organization.controller";
|
||||
|
||||
export default function organizationRoutes(fastify: FastifyInstance) {
|
||||
fastify.post(
|
||||
@@ -15,4 +15,19 @@ export default function organizationRoutes(fastify: FastifyInstance) {
|
||||
},
|
||||
createOrgHandler
|
||||
);
|
||||
|
||||
fastify.get(
|
||||
"/:orgId",
|
||||
{
|
||||
schema: {
|
||||
params: {
|
||||
type: "object",
|
||||
properties: {
|
||||
orgId: { type: "string" },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
getOrgHandler
|
||||
);
|
||||
}
|
||||
|
||||
@@ -11,3 +11,7 @@ export async function createOrg(input: CreateOrgInput) {
|
||||
|
||||
return org;
|
||||
}
|
||||
|
||||
export async function getOrg(orgId: string) {
|
||||
return await orgModel.findOne({ pid: orgId });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user