Add authorization
This commit is contained in:
@@ -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" });
|
||||
|
||||
|
||||
Reference in New Issue
Block a user