* refactor: migrate listHandler to AttributeRepository Co-Authored-By: [email protected] <[email protected]> * cache attributes list --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: [email protected] <[email protected]> Co-authored-by: hbjORbj <[email protected]>
27 lines
625 B
TypeScript
27 lines
625 B
TypeScript
import { AttributeRepository } from "@calcom/lib/server/repository/attribute";
|
|
|
|
import { TRPCError } from "@trpc/server";
|
|
|
|
import type { TrpcSessionUser } from "../../../types";
|
|
|
|
type GetOptions = {
|
|
ctx: {
|
|
user: NonNullable<TrpcSessionUser>;
|
|
};
|
|
};
|
|
|
|
const listHandler = async (opts: GetOptions) => {
|
|
const org = opts.ctx.user.organization;
|
|
|
|
if (!org.id) {
|
|
throw new TRPCError({
|
|
code: "UNAUTHORIZED",
|
|
message: "You need to be apart of an organization to use this feature",
|
|
});
|
|
}
|
|
|
|
return await AttributeRepository.findAllByOrgIdWithOptions({ orgId: org.id });
|
|
};
|
|
|
|
export default listHandler;
|