* Replace ctx.user.credentials to fetch in their own usecases * Remove rawavatar from return * Remove avatar rawAvatar from handler * Fix fallback avatars * fix: profile.slug already includes /team * perf: Deprecate useAvatarQuery hook * Extract to reusable credential func * Fix type errors for credentials * credentialOwner was inferred incorrectly, string non-nullable --------- Co-authored-by: Keith Williams <keithwillcode@gmail.com> Co-authored-by: Alex van Andel <me@alexvanandel.com>
33 lines
1011 B
TypeScript
33 lines
1011 B
TypeScript
import getApps from "@calcom/app-store/utils";
|
|
import { getUsersCredentials } from "@calcom/lib/server/getUsersCredentials";
|
|
import type { TrpcSessionUser } from "@calcom/trpc/server/trpc";
|
|
|
|
import { TRPCError } from "@trpc/server";
|
|
|
|
import type { TAppByIdInputSchema } from "./appById.schema";
|
|
|
|
type AppByIdOptions = {
|
|
ctx: {
|
|
user: NonNullable<TrpcSessionUser>;
|
|
};
|
|
input: TAppByIdInputSchema;
|
|
};
|
|
|
|
export const appByIdHandler = async ({ ctx, input }: AppByIdOptions) => {
|
|
const { user } = ctx;
|
|
const appId = input.appId;
|
|
const credentials = await getUsersCredentials(user.id);
|
|
const apps = getApps(credentials);
|
|
const appFromDb = apps.find((app) => app.slug === appId);
|
|
if (!appFromDb) {
|
|
throw new TRPCError({ code: "BAD_REQUEST", message: `Could not find app ${appId}` });
|
|
}
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
const { credential: _, credentials: _1, ...app } = appFromDb;
|
|
return {
|
|
isInstalled: appFromDb.credentials.length,
|
|
...app,
|
|
};
|
|
};
|