* perf: Don't process date overrides outside of requested boundaries * Added ability to skip override calculations when not used * Only instantiating utc date for overrides once * Removed performance tracing * Cleanup * Fixed broken tests * Fix type * In process of fixing types * Types * Fixed types * Removed unnecessary performance.now() call * Changed override date check to use isBetween * Attempting to fix availability test * Put code back to test availability * Put back isBetween because confirmed it wasn't triggering the new test failures * Removed date check to see if this is breaking it * Put the code back since the test failed without it too * Skipping test to unblock pipeline unless research is done * Removed steps to test * Removing the piece around the troubleshooter * 1 more try * Adding an extra wait * Took out the boolean check to see if that's the issue * Put back the check * Trying to isolate the problem * Changed how the test loads the troubleshooter * Changed to OR to capture range better * Using the proper date instead of 1/1/1970 * Update availability.e2e.ts
55 lines
1.8 KiB
TypeScript
55 lines
1.8 KiB
TypeScript
import { getUserAvailability } from "@calcom/core/getUserAvailability";
|
|
import { isTeamMember } from "@calcom/lib/server/queries/teams";
|
|
import { availabilityUserSelect } from "@calcom/prisma";
|
|
import { prisma } from "@calcom/prisma";
|
|
import { credentialForCalendarServiceSelect } from "@calcom/prisma/selects/credential";
|
|
import type { TrpcSessionUser } from "@calcom/trpc/server/trpc";
|
|
|
|
import { TRPCError } from "@trpc/server";
|
|
|
|
import type { TGetMemberAvailabilityInputSchema } from "./getMemberAvailability.schema";
|
|
|
|
type GetMemberAvailabilityOptions = {
|
|
ctx: {
|
|
user: NonNullable<TrpcSessionUser>;
|
|
};
|
|
input: TGetMemberAvailabilityInputSchema;
|
|
};
|
|
|
|
export const getMemberAvailabilityHandler = async ({ ctx, input }: GetMemberAvailabilityOptions) => {
|
|
const team = await isTeamMember(ctx.user?.id, input.teamId);
|
|
if (!team) throw new TRPCError({ code: "UNAUTHORIZED" });
|
|
|
|
// verify member is in team
|
|
const members = await prisma.membership.findMany({
|
|
where: { teamId: input.teamId },
|
|
include: {
|
|
user: {
|
|
select: {
|
|
credentials: {
|
|
select: credentialForCalendarServiceSelect,
|
|
}, // needed for getUserAvailability
|
|
...availabilityUserSelect,
|
|
},
|
|
},
|
|
},
|
|
});
|
|
const member = members?.find((m) => m.userId === input.memberId);
|
|
if (!member) throw new TRPCError({ code: "NOT_FOUND", message: "Member not found" });
|
|
if (!member.user.username)
|
|
throw new TRPCError({ code: "BAD_REQUEST", message: "Member doesn't have a username" });
|
|
|
|
// get availability for this member
|
|
return await getUserAvailability(
|
|
{
|
|
username: member.user.username,
|
|
dateFrom: input.dateFrom,
|
|
dateTo: input.dateTo,
|
|
returnDateOverrides: true,
|
|
},
|
|
{ user: member.user, busyTimesFromLimitsBookings: [] }
|
|
);
|
|
};
|
|
|
|
export default getMemberAvailabilityHandler;
|