Files
calendar/packages/trpc/server/routers/viewer/teams/listOwnedTeams.handler.ts
T
0970c77009 fix: Revert -> "Revert "chore: Chore team metadata table + isOrganization migration (#13700)
* 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>
2024-03-01 15:04:28 +00:00

39 lines
777 B
TypeScript

import { prisma } from "@calcom/prisma";
import { MembershipRole } from "@calcom/prisma/enums";
import type { TrpcSessionUser } from "../../../trpc";
type ListOptions = {
ctx: {
user: NonNullable<TrpcSessionUser>;
};
};
export const listOwnedTeamsHandler = async ({ ctx }: ListOptions) => {
const user = await prisma.user.findFirst({
where: {
id: ctx.user.id,
},
select: {
id: true,
teams: {
where: {
accepted: true,
role: {
in: [MembershipRole.OWNER, MembershipRole.ADMIN],
},
},
select: {
team: true,
},
},
},
});
return user?.teams
?.filter((m) => {
return !m.team.isOrganization;
})
?.map(({ team }) => team);
};