Add authorization

This commit is contained in:
2024-12-20 13:17:53 +05:30
parent 4b49c43a0c
commit a584fc91b5
16 changed files with 112 additions and 58 deletions

View File

@@ -2,28 +2,24 @@ import { FastifyRequest, FastifyReply } from "fastify";
import { CreateOrgInput } from "./organization.schema";
import { createOrg, getOrg } from "./organization.service";
export async function createOrgHandler(
req: FastifyRequest<{ Body: CreateOrgInput }>,
res: FastifyReply
) {
const input = req.body;
export async function createOrgHandler(req: FastifyRequest, res: FastifyReply) {
const input = req.body as CreateOrgInput;
try {
const org = await createOrg(input);
const authUser = req.user;
const org = await createOrg(input, authUser.tenantId);
return res.code(201).send(org);
} catch (err) {
return err;
}
}
export async function getOrgHandler(
req: FastifyRequest<{ Params: { orgId: string } }>,
res: FastifyReply
) {
const { orgId } = req.params;
export async function getOrgHandler(req: FastifyRequest, res: FastifyReply) {
const { orgId } = req.params as { orgId: string };
try {
const org = await getOrg(orgId);
const authUser = req.user;
const org = await getOrg(orgId, authUser.tenantId);
if (org === null)
return res.code(404).send({ error: "resource not found" });