* Revert "Revert "chore: Chore team metadata table + isOrganization migration from metadata (#12828)""
This reverts commit 2408338ed4.
* Remove constraint slug,isOrganization and reset migration
* fix: conflicts
* change schema to bust cache
* Fix issues reported by TS
* change schema to bust cache
* Review fixes
* Colaesce for orgAutoAcceptEmail as well
* Fix missing negation
---------
Co-authored-by: zomars <zomars@me.com>
Co-authored-by: Peer Richelsen <peeroke@gmail.com>
Co-authored-by: Keith Williams <keithwillcode@gmail.com>
Co-authored-by: Joe Au-Yeung <65426560+joeauyeung@users.noreply.github.com>
39 lines
1.2 KiB
TypeScript
39 lines
1.2 KiB
TypeScript
import type { NextApiRequest, NextApiResponse } from "next";
|
|
import z from "zod";
|
|
|
|
import { HttpError } from "@calcom/lib/http-error";
|
|
import { defaultHandler, defaultResponder } from "@calcom/lib/server";
|
|
import prisma from "@calcom/prisma";
|
|
|
|
const querySchema = z.object({
|
|
org: z.string({ required_error: "org slug is required" }),
|
|
});
|
|
|
|
async function handler(req: NextApiRequest, res: NextApiResponse) {
|
|
const parsedQuery = querySchema.safeParse(req.query);
|
|
|
|
if (!parsedQuery.success) throw new HttpError({ statusCode: 400, message: parsedQuery.error.message });
|
|
|
|
const {
|
|
data: { org: slug },
|
|
} = parsedQuery;
|
|
if (!slug) return res.status(400).json({ message: "Org is needed" });
|
|
|
|
const org = await prisma.team.findFirst({
|
|
where: { slug },
|
|
select: { children: true, isOrganization: true },
|
|
});
|
|
|
|
if (!org) return res.status(400).json({ message: "Org doesn't exist" });
|
|
|
|
const isOrganization = org.isOrganization;
|
|
|
|
if (!isOrganization) return res.status(400).json({ message: "Team is not an org" });
|
|
|
|
return res.status(200).json({ slugs: org.children.map((ch) => ch.slug) });
|
|
}
|
|
|
|
export default defaultHandler({
|
|
GET: Promise.resolve({ default: defaultResponder(handler) }),
|
|
});
|