Files
cal.diy/packages/trpc/server/routers/viewer/teams/getMembershipbyUser.handler.ts
T
1eeb91a793 perf: lazy load tRPC routes (#8167)
* experiment: cold start perf

* fix: update failing test

* chore: add database indexes

* chore: use json protocol and add query batching back

* Update [status].tsx

* Update [trpc].ts

* Delete getSlimSession.ts

* Update createContext.ts

* remove trpc caller

* correctly import Prisma

* lazy ethRouter

* replace crypto with md5

* import fixes

* public event endpoint refactor

* Update yarn.lock

* Update yarn.lock

* Using yarn.lock from main

---------

Co-authored-by: Omar López <[email protected]>
Co-authored-by: Peer Richelsen <[email protected]>
Co-authored-by: Efraín Rochín <[email protected]>
Co-authored-by: Keith Williams <[email protected]>
2023-04-25 19:39:47 -03:00

32 lines
815 B
TypeScript

import { prisma } from "@calcom/prisma";
import type { TrpcSessionUser } from "@calcom/trpc/server/trpc";
import { TRPCError } from "@trpc/server";
import type { TGetMembershipbyUserInputSchema } from "./getMembershipbyUser.schema";
type GetMembershipbyUserOptions = {
ctx: {
user: NonNullable<TrpcSessionUser>;
};
input: TGetMembershipbyUserInputSchema;
};
export const getMembershipbyUserHandler = async ({ ctx, input }: GetMembershipbyUserOptions) => {
if (ctx.user.id !== input.memberId) {
throw new TRPCError({
code: "UNAUTHORIZED",
message: "You cannot view memberships that are not your own.",
});
}
return await prisma.membership.findUnique({
where: {
userId_teamId: {
userId: input.memberId,
teamId: input.teamId,
},
},
});
};