* refactor: migrate listHandler to AttributeRepository Co-Authored-By: benny@cal.com <benny@cal.com> * cache attributes list --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: benny@cal.com <benny@cal.com> Co-authored-by: hbjORbj <sldisek783@gmail.com>
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;
|