mirror of
https://github.com/hanzoai/calendar.git
synced 2026-09-24 22:42:24 +00:00
* perf: Refactor bookings queries for API * fix syntax * fixing vars * Inverted the filter by attendees if * fixed prisma filter issue * Defaulting list of emails to empty array * Only running 2 queries if we have data to filter by * Reverted changes that have been separated out to other PR * fix: ts build error * adds tests + extracts logic for units * fix integration tests * fix tests expectes * Fix test * switching back * attempt : fix tests * test: add test for duplicate bookings (#21165) * feat: Add tests for booking and duration limits (#21158) * Add tests for booking and duration limits in getSchedule.test.ts Co-Authored-By: [email protected] <[email protected]> * fix: use SchedulingType enum instead of string for schedulingType Co-Authored-By: [email protected] <[email protected]> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: [email protected] <[email protected]> * test: add test to ensure no duplicate bookings when merging query results Co-Authored-By: [email protected] <[email protected]> --------- Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: [email protected] <[email protected]> Co-authored-by: Keith Williams <[email protected]> * fix: deduplicate bookings when merging results from multiple queries Co-Authored-By: [email protected] <[email protected]> * fix: ensure pagination works correctly when merging results from multiple queries (#21167) Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: [email protected] <[email protected]> --------- Co-authored-by: Tushar Bhatt <[email protected]> Co-authored-by: Tushar <[email protected]> Co-authored-by: sean-brydon <[email protected]> Co-authored-by: Peer Richelsen <[email protected]> Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: [email protected] <[email protected]>
38 lines
1.4 KiB
TypeScript
38 lines
1.4 KiB
TypeScript
/**
|
|
* Constructs the WHERE clause for Prisma booking findMany operation.
|
|
*
|
|
* @param userId - The ID of the user making the request. This is used to filter bookings where the user is either the host or an attendee.
|
|
* @param attendeeEmails - An array of emails provided in the request for filtering bookings by attendee emails, used in case of Admin calls.
|
|
* @param userIds - An array of user IDs to be included in the filter. Defaults to an empty array, and an array of user IDs in case of Admin call containing it.
|
|
* @param userEmails - An array of user emails to be included in the filter if it is an Admin call and contains userId in query parameter. Defaults to an empty array.
|
|
*
|
|
* @returns An object that represents the WHERE clause for the findMany/findUnique operation.
|
|
*/
|
|
export function buildWhereClause(userId: number | null, attendeeEmails: string[], userIds: number[] = []) {
|
|
const filterByAttendeeEmails = attendeeEmails.length > 0;
|
|
const userFilter = userIds.length > 0 ? { userId: { in: userIds } } : !!userId ? { userId } : {};
|
|
|
|
let whereClause = {};
|
|
|
|
if (filterByAttendeeEmails) {
|
|
whereClause = {
|
|
AND: [
|
|
userFilter,
|
|
{
|
|
attendees: {
|
|
some: {
|
|
email: { in: attendeeEmails },
|
|
},
|
|
},
|
|
},
|
|
],
|
|
};
|
|
} else {
|
|
whereClause = {
|
|
...userFilter,
|
|
};
|
|
}
|
|
|
|
return whereClause;
|
|
}
|