fix: improve filters at /bookings (#18581)
* fix: improve filters at /bookings * fix type
This commit is contained in:
1 parent
8761b91f71
commit
1ffb376789
5 files changed
+47
-24
No files matched your search
@@ -15,7 +15,7 @@ import { ZGetUserConnectedAppsInputSchema } from "./getUserConnectedApps.schema"
|
||||
import { ZHasEditPermissionForUserSchema } from "./hasEditPermissionForUser.schema";
|
||||
import { ZInviteMemberInputSchema } from "./inviteMember/inviteMember.schema";
|
||||
import { ZInviteMemberByTokenSchemaInputSchema } from "./inviteMemberByToken.schema";
|
||||
import { ZListMembersInputSchema as ZLegegacyListMembers } from "./legacyListMembers.schema";
|
||||
import { ZLegacyListMembersInputSchema } from "./legacyListMembers.schema";
|
||||
import { ZGetListSchema } from "./list.schema";
|
||||
import { ZListMembersInputSchema } from "./listMembers.schema";
|
||||
import { hasTeamPlan } from "./procedures/hasTeamPlan";
|
||||
@@ -121,7 +121,7 @@ export const viewerTeamsRouter = router({
|
||||
const handler = await importHandler(namespaced("listMembers"), () => import("./listMembers.handler"));
|
||||
return handler(opts);
|
||||
}),
|
||||
legacyListMembers: authedProcedure.input(ZLegegacyListMembers).query(async (opts) => {
|
||||
legacyListMembers: authedProcedure.input(ZLegacyListMembersInputSchema).query(async (opts) => {
|
||||
const handler = await importHandler(
|
||||
namespaced("legacyListMembers"),
|
||||
() => import("./legacyListMembers.handler")
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
import type { Prisma } from "@prisma/client";
|
||||
|
||||
import { UserRepository } from "@calcom/lib/server/repository/user";
|
||||
import type { PrismaClient } from "@calcom/prisma";
|
||||
import type { TrpcSessionUser } from "@calcom/trpc/server/trpc";
|
||||
|
||||
import type { TListMembersInputSchema } from "./legacyListMembers.schema";
|
||||
import type { TLegacyListMembersInputSchema } from "./legacyListMembers.schema";
|
||||
|
||||
type ListMembersOptions = {
|
||||
ctx: {
|
||||
user: NonNullable<TrpcSessionUser>;
|
||||
prisma: PrismaClient;
|
||||
};
|
||||
input: TListMembersInputSchema;
|
||||
input: TLegacyListMembersInputSchema;
|
||||
};
|
||||
|
||||
export const legacyListMembers = async ({ ctx, input }: ListMembersOptions) => {
|
||||
@@ -57,6 +59,15 @@ export const legacyListMembers = async ({ ctx, input }: ListMembersOptions) => {
|
||||
};
|
||||
}
|
||||
|
||||
const searchTextClauses: Prisma.UserWhereInput[] = [
|
||||
{ name: { contains: input.searchText, mode: "insensitive" } },
|
||||
{ username: { contains: input.searchText, mode: "insensitive" } },
|
||||
];
|
||||
|
||||
if (input.includeEmail) {
|
||||
searchTextClauses.push({ email: { contains: input.searchText, mode: "insensitive" } });
|
||||
}
|
||||
|
||||
// Fetch unique users through memberships
|
||||
const memberships = await prisma.membership.findMany({
|
||||
where: {
|
||||
@@ -64,10 +75,7 @@ export const legacyListMembers = async ({ ctx, input }: ListMembersOptions) => {
|
||||
teamId: { in: teamsToQuery },
|
||||
user: input.searchText?.trim()?.length
|
||||
? {
|
||||
OR: [
|
||||
{ name: { contains: input.searchText, mode: "insensitive" } },
|
||||
{ username: { contains: input.searchText, mode: "insensitive" } },
|
||||
],
|
||||
OR: searchTextClauses,
|
||||
}
|
||||
: undefined,
|
||||
},
|
||||
@@ -80,6 +88,7 @@ export const legacyListMembers = async ({ ctx, input }: ListMembersOptions) => {
|
||||
name: true,
|
||||
username: true,
|
||||
avatarUrl: true,
|
||||
email: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -7,4 +7,9 @@ export const ZListMembersInputSchema = z.object({
|
||||
cursor: z.number().nullish(),
|
||||
});
|
||||
|
||||
export const ZLegacyListMembersInputSchema = ZListMembersInputSchema.extend({
|
||||
includeEmail: z.boolean().optional(),
|
||||
});
|
||||
|
||||
export type TListMembersInputSchema = z.infer<typeof ZListMembersInputSchema>;
|
||||
export type TLegacyListMembersInputSchema = z.infer<typeof ZLegacyListMembersInputSchema>;
|
||||
Reference in new issue
Block a user