Files
calendar/packages/trpc/server/routers/viewer/apps/locationOptions.handler.ts
T
e86ad03cde perf: Slim down logged in round 2 (#20535)
* perf: Slim down loggedInViewer some more

* Move locationOptions to apps router

* Moved calVideo related handlers to separate router

* Moved calendar related handlers to separate router

* Rename

* Moved deleteCredential to new router

* Moved updateProfile to me router

* fix unit test

* fix e2e test

* tweak

* missing

---------

Co-authored-by: Anik Dhabal Babu <81948346+anikdhabal@users.noreply.github.com>
Co-authored-by: unknown <adhabal2002@gmail.com>
2025-04-04 15:33:14 -04:00

31 lines
1.1 KiB
TypeScript

import { getLocationGroupedOptions } from "@calcom/app-store/server";
import { getTranslation } from "@calcom/lib/server/i18n";
import type { TrpcSessionUser } from "@calcom/trpc/server/types";
import type { TLocationOptionsInputSchema } from "./locationOptions.schema";
type LocationOptionsOptions = {
ctx: {
user: NonNullable<TrpcSessionUser>;
};
input: TLocationOptionsInputSchema;
};
export const locationOptionsHandler = async ({ ctx, input }: LocationOptionsOptions) => {
const { teamId } = input;
const t = await getTranslation(ctx.user.locale ?? "en", "common");
const locationOptions = await getLocationGroupedOptions(teamId ? { teamId } : { userId: ctx.user.id }, t);
// If it is a team event then move the "use host location" option to top
if (input.teamId) {
const conferencingIndex = locationOptions.findIndex((option) => option.label === "Conferencing");
if (conferencingIndex !== -1) {
const conferencingObject = locationOptions.splice(conferencingIndex, 1)[0];
locationOptions.unshift(conferencingObject);
}
}
return locationOptions;
};