chore: get platform me from trpc instead of apiv2 (#16515)
This commit is contained in:
1 parent
f07b73dc79
commit
21ef1900e9
4 files changed
+60
-17
No files matched your search
@@ -16,6 +16,7 @@ import { ZLocationOptionsInputSchema } from "./locationOptions.schema";
|
||||
import { ZNoShowInputSchema } from "./markNoShow.schema";
|
||||
import { ZOutOfOfficeInputSchema, ZOutOfOfficeDelete } from "./outOfOffice.schema";
|
||||
import { me } from "./procedures/me";
|
||||
import { platformMe } from "./procedures/platformMe";
|
||||
import { teamsAndUserProfilesQuery } from "./procedures/teamsAndUserProfilesQuery";
|
||||
import { ZRemoveNotificationsSubscriptionInputSchema } from "./removeNotificationsSubscription.schema";
|
||||
import { ZRoutingFormOrderInputSchema } from "./routingFormOrder.schema";
|
||||
@@ -31,6 +32,7 @@ const namespaced = (s: string) => `${NAMESPACE}.${s}`;
|
||||
|
||||
type AppsRouterHandlerCache = {
|
||||
me?: typeof import("./me.handler").meHandler;
|
||||
platformMe?: typeof import("./platformMe.handler").platformMeHandler;
|
||||
shouldVerifyEmail?: typeof import("./shouldVerifyEmail.handler").shouldVerifyEmailHandler;
|
||||
deleteMe?: typeof import("./deleteMe.handler").deleteMeHandler;
|
||||
deleteMeWithoutPassword?: typeof import("./deleteMeWithoutPassword.handler").deleteMeWithoutPasswordHandler;
|
||||
@@ -70,6 +72,7 @@ const UNSTABLE_HANDLER_CACHE: AppsRouterHandlerCache = {};
|
||||
|
||||
export const loggedInViewerRouter = router({
|
||||
me,
|
||||
platformMe,
|
||||
|
||||
deleteMe: authedProcedure.input(ZDeleteMeInputSchema).mutation(async ({ ctx, input }) => {
|
||||
if (!UNSTABLE_HANDLER_CACHE.deleteMe) {
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
import type { Session } from "next-auth";
|
||||
|
||||
import { ProfileRepository } from "@calcom/lib/server/repository/profile";
|
||||
import type { TrpcSessionUser } from "@calcom/trpc/server/trpc";
|
||||
|
||||
type MeOptions = {
|
||||
ctx: {
|
||||
user: NonNullable<TrpcSessionUser>;
|
||||
session: Session;
|
||||
};
|
||||
};
|
||||
|
||||
export const platformMeHandler = async ({ ctx }: MeOptions) => {
|
||||
const { user: sessionUser } = ctx;
|
||||
|
||||
const allUserEnrichedProfiles = await ProfileRepository.findAllProfilesForUserIncludingMovedUser(
|
||||
sessionUser
|
||||
);
|
||||
|
||||
const mainProfile =
|
||||
allUserEnrichedProfiles.find((profile) => sessionUser.movedToProfileId === profile.id) ||
|
||||
allUserEnrichedProfiles.find((profile) => sessionUser.organizationId === profile.organizationId) ||
|
||||
allUserEnrichedProfiles[0];
|
||||
|
||||
return {
|
||||
id: sessionUser.id,
|
||||
username: sessionUser.username,
|
||||
email: sessionUser.email,
|
||||
timeFormat: sessionUser.timeFormat,
|
||||
timeZone: sessionUser.timeZone,
|
||||
defaultScheduleId: sessionUser.defaultScheduleId,
|
||||
weekStart: sessionUser.weekStart,
|
||||
organizationId: mainProfile.organizationId,
|
||||
organization: {
|
||||
isPlatform: mainProfile.organization?.isPlatform ?? false,
|
||||
id: mainProfile.organizationId ?? null,
|
||||
},
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,7 @@
|
||||
import authedProcedure from "../../../procedures/authedProcedure";
|
||||
|
||||
export const platformMe = authedProcedure.query(async ({ ctx }) => {
|
||||
const handler = (await import("../platformMe.handler")).platformMeHandler;
|
||||
|
||||
return handler({ ctx });
|
||||
});
|
||||
Reference in new issue
Block a user