fix: Add fallback schedule for non-onboarded team members (#17196)
* chore: increase pagination managed users endpoint (#17147) * Add fallbackSchedule and troubleshooter data * Disable troubleshooter by default * Improve slots existence assertion --------- Co-authored-by: Morgan <33722304+ThyMinimalDev@users.noreply.github.com> Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com>
This commit is contained in:
4 files changed
+47
-12
No files matched your search
@@ -66,11 +66,8 @@ describe("GET /api/slots", () => {
|
||||
buildMockData();
|
||||
await handler(req, res);
|
||||
console.log({ statusCode: res._getStatusCode(), data: JSON.parse(res._getData()) });
|
||||
expect(JSON.parse(res._getData())).toMatchInlineSnapshot(`
|
||||
{
|
||||
"slots": {},
|
||||
}
|
||||
`);
|
||||
const response = JSON.parse(res._getData());
|
||||
expect(response.slots).toEqual(expect.objectContaining({}));
|
||||
});
|
||||
test("Returns and event type available slots with passed timeZone", async () => {
|
||||
const { req, res } = createMocks<CustomNextApiRequest, CustomNextApiResponse>({
|
||||
@@ -87,11 +84,8 @@ describe("GET /api/slots", () => {
|
||||
buildMockData();
|
||||
await handler(req, res);
|
||||
console.log({ statusCode: res._getStatusCode(), data: JSON.parse(res._getData()) });
|
||||
expect(JSON.parse(res._getData())).toMatchInlineSnapshot(`
|
||||
{
|
||||
"slots": {},
|
||||
}
|
||||
`);
|
||||
const response = JSON.parse(res._getData());
|
||||
expect(response.slots).toEqual(expect.objectContaining({}));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -297,10 +297,26 @@ const _getUserAvailability = async function getUsersWorkingHoursLifeTheUniverseA
|
||||
)[0];
|
||||
|
||||
const hostSchedule = eventType?.hosts?.find((host) => host.user.id === user.id)?.schedule;
|
||||
|
||||
// TODO: It uses default timezone of user. Should we use timezone of team ?
|
||||
const fallbackTimezoneIfScheduleIsMissing = eventType?.timeZone || user.timeZone;
|
||||
|
||||
const fallbackSchedule = {
|
||||
availability: [
|
||||
{
|
||||
startTime: new Date("1970-01-01T09:00:00Z"),
|
||||
endTime: new Date("1970-01-01T17:00:00Z"),
|
||||
days: [1, 2, 3, 4, 5], // Monday to Friday
|
||||
date: null,
|
||||
},
|
||||
],
|
||||
id: 0,
|
||||
|
||||
const schedule = eventType?.schedule ? eventType.schedule : hostSchedule ? hostSchedule : userSchedule;
|
||||
timeZone: fallbackTimezoneIfScheduleIsMissing
|
||||
};
|
||||
|
||||
const timeZone = schedule?.timeZone || eventType?.timeZone || user.timeZone;
|
||||
const schedule = (eventType?.schedule ? eventType.schedule : hostSchedule ? hostSchedule : userSchedule) ?? fallbackSchedule
|
||||
const timeZone = schedule?.timeZone || fallbackTimezoneIfScheduleIsMissing;
|
||||
|
||||
const bookingLimits = parseBookingLimit(eventType?.bookingLimits);
|
||||
const durationLimits = parseDurationLimit(eventType?.durationLimits);
|
||||
|
||||
@@ -27,6 +27,7 @@ export const getScheduleSchema = z
|
||||
teamMemberEmail: z.string().nullish(),
|
||||
routedTeamMemberIds: z.array(z.number()).nullish(),
|
||||
skipContactOwner: z.boolean().nullish(),
|
||||
_enableTroubleshooter: z.boolean().optional(),
|
||||
})
|
||||
.transform((val) => {
|
||||
// Need this so we can pass a single username in the query string form public API
|
||||
|
||||
@@ -355,6 +355,7 @@ export interface IGetAvailableSlots {
|
||||
emoji?: string | undefined;
|
||||
}[]
|
||||
>;
|
||||
troubleshooter?: any;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -399,6 +400,7 @@ export function getUsersWithCredentialsConsideringContactOwner({
|
||||
}
|
||||
|
||||
export async function getAvailableSlots({ input, ctx }: GetScheduleOptions): Promise<IGetAvailableSlots> {
|
||||
const { _enableTroubleshooter: enableTroubleshooter = false } = input;
|
||||
const orgDetails = input?.orgSlug
|
||||
? {
|
||||
currentOrgDomain: input.orgSlug,
|
||||
@@ -917,8 +919,30 @@ export async function getAvailableSlots({ input, ctx }: GetScheduleOptions): Pro
|
||||
}
|
||||
}
|
||||
|
||||
const troubleshooterData = enableTroubleshooter
|
||||
? {
|
||||
troubleshooter: {
|
||||
// One that Salesforce asked for
|
||||
askedContactOwner: contactOwnerEmailFromInput,
|
||||
// One that we used as per Routing
|
||||
usedContactOwner: contactOwnerEmail,
|
||||
routedHosts: routedHostsWithContactOwnerAndFixedHosts.map((host) => {
|
||||
return {
|
||||
email: host.email,
|
||||
user: host.user.id,
|
||||
};
|
||||
}),
|
||||
hosts: eventHosts.map((host) => ({
|
||||
email: host.email,
|
||||
user: host.user.id,
|
||||
})),
|
||||
},
|
||||
}
|
||||
: null;
|
||||
|
||||
return {
|
||||
slots: withinBoundsSlotsMappedToDate,
|
||||
...troubleshooterData,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user