Files
3c1297aa72 fix: calcom trpc sessio circle dep (#19893)
* fix trpc session circle dep

* fixes trpc session cirlce dep

* fix relative imports

* fix more imports to use types and not trpc

* fix exports

* Fixed types

---------

Co-authored-by: Keith Williams <[email protected]>
2025-03-19 05:50:22 -03:00

54 lines
1.3 KiB
TypeScript

import { safeStringify } from "@calcom/lib/safeStringify";
import { prisma } from "@calcom/prisma";
import { teamMetadataSchema } from "@calcom/prisma/zod-utils";
import type { TrpcSessionUser } from "../../../types";
type AdminGetAllOptions = {
ctx: {
user: NonNullable<TrpcSessionUser>;
};
};
export const adminGetUnverifiedHandler = async ({}: AdminGetAllOptions) => {
const allOrgs = await prisma.team.findMany({
where: {
isOrganization: true,
},
select: {
id: true,
name: true,
slug: true,
metadata: true,
organizationSettings: true,
members: {
where: {
role: "OWNER",
},
select: {
user: {
select: {
id: true,
name: true,
email: true,
},
},
},
},
},
});
return allOrgs
.map((org) => {
const parsed = teamMetadataSchema.safeParse(org.metadata);
if (!parsed.success) {
console.error(`Failed to parse metadata for org ${org.id}:`, safeStringify(parsed.error));
return null;
}
return { ...org, metadata: parsed.data };
})
.filter((org): org is NonNullable<typeof org> => org !== null);
};
export default adminGetUnverifiedHandler;