Modified the view to use UNION for user/team bookings (#16558)
This commit is contained in:
@@ -363,12 +363,13 @@ class EventsInsights {
|
||||
userId: {
|
||||
in: userIdsFromOrg,
|
||||
},
|
||||
teamId: null,
|
||||
isTeamBooking: false,
|
||||
},
|
||||
{
|
||||
teamId: {
|
||||
in: [organizationId, ...teamsFromOrg.map((t) => t.id)],
|
||||
},
|
||||
isTeamBooking: true,
|
||||
},
|
||||
],
|
||||
};
|
||||
@@ -390,12 +391,13 @@ class EventsInsights {
|
||||
OR: [
|
||||
{
|
||||
teamId,
|
||||
isTeamBooking: true,
|
||||
},
|
||||
{
|
||||
userId: {
|
||||
in: userIdsFromTeam,
|
||||
},
|
||||
teamId: null,
|
||||
isTeamBooking: false,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
@@ -213,12 +213,13 @@ export const insightsRouter = router({
|
||||
userId: {
|
||||
in: userIdsFromOrg,
|
||||
},
|
||||
teamId: null,
|
||||
isTeamBooking: false,
|
||||
},
|
||||
{
|
||||
teamId: {
|
||||
in: [ctx.user.organizationId, ...teamsFromOrg.map((t) => t.id)],
|
||||
},
|
||||
isTeamBooking: true,
|
||||
},
|
||||
],
|
||||
};
|
||||
@@ -240,12 +241,13 @@ export const insightsRouter = router({
|
||||
OR: [
|
||||
{
|
||||
teamId,
|
||||
isTeamBooking: true,
|
||||
},
|
||||
{
|
||||
userId: {
|
||||
in: userIdsFromTeam,
|
||||
},
|
||||
teamId: null,
|
||||
isTeamBooking: false,
|
||||
},
|
||||
],
|
||||
};
|
||||
@@ -438,12 +440,13 @@ export const insightsRouter = router({
|
||||
userId: {
|
||||
in: userIdsFromOrg,
|
||||
},
|
||||
teamId: null,
|
||||
isTeamBooking: false,
|
||||
},
|
||||
{
|
||||
teamId: {
|
||||
in: [ctx.user.organizationId, ...teamsFromOrg.map((t) => t.id)],
|
||||
},
|
||||
isTeamBooking: true,
|
||||
},
|
||||
],
|
||||
};
|
||||
@@ -465,12 +468,13 @@ export const insightsRouter = router({
|
||||
OR: [
|
||||
{
|
||||
teamId,
|
||||
isTeamBooking: true,
|
||||
},
|
||||
{
|
||||
userId: {
|
||||
in: userIdsFromTeams,
|
||||
},
|
||||
teamId: null,
|
||||
isTeamBooking: false,
|
||||
},
|
||||
],
|
||||
};
|
||||
@@ -614,12 +618,13 @@ export const insightsRouter = router({
|
||||
userId: {
|
||||
in: userIdsFromOrg,
|
||||
},
|
||||
teamId: null,
|
||||
isTeamBooking: false,
|
||||
},
|
||||
{
|
||||
teamId: {
|
||||
in: [ctx.user.organizationId, ...teamsFromOrg.map((t) => t.id)],
|
||||
},
|
||||
isTeamBooking: true,
|
||||
},
|
||||
],
|
||||
};
|
||||
@@ -642,12 +647,13 @@ export const insightsRouter = router({
|
||||
OR: [
|
||||
{
|
||||
teamId,
|
||||
isTeamBooking: true,
|
||||
},
|
||||
{
|
||||
userId: {
|
||||
in: userIdsFromTeams,
|
||||
},
|
||||
teamId: null,
|
||||
isTeamBooking: false,
|
||||
},
|
||||
],
|
||||
};
|
||||
@@ -815,10 +821,11 @@ export const insightsRouter = router({
|
||||
teamId: {
|
||||
in: [ctx.user?.organizationId, ...teamsFromOrg.map((t) => t.id)],
|
||||
},
|
||||
isTeamBooking: true,
|
||||
},
|
||||
{
|
||||
userId: ctx.user?.id,
|
||||
teamId: null,
|
||||
isTeamBooking: false,
|
||||
},
|
||||
],
|
||||
};
|
||||
@@ -841,12 +848,13 @@ export const insightsRouter = router({
|
||||
OR: [
|
||||
{
|
||||
teamId,
|
||||
isTeamBooking: true,
|
||||
},
|
||||
{
|
||||
userId: {
|
||||
in: userIdsFromTeams,
|
||||
},
|
||||
teamId: null,
|
||||
isTeamBooking: false,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
CREATE OR REPLACE VIEW public."BookingTimeStatus"
|
||||
AS
|
||||
SELECT
|
||||
"Booking".id,
|
||||
"Booking".uid,
|
||||
"Booking"."eventTypeId",
|
||||
"Booking".title,
|
||||
"Booking".description,
|
||||
"Booking"."startTime",
|
||||
"Booking"."endTime",
|
||||
"Booking"."createdAt",
|
||||
"Booking".location,
|
||||
"Booking".paid,
|
||||
"Booking".status,
|
||||
"Booking".rescheduled,
|
||||
"Booking"."userId",
|
||||
et."teamId",
|
||||
et.length AS "eventLength",
|
||||
CASE
|
||||
WHEN "Booking".rescheduled IS TRUE THEN 'rescheduled'::text
|
||||
WHEN "Booking".status = 'cancelled'::"BookingStatus" AND "Booking".rescheduled IS NULL THEN 'cancelled'::text
|
||||
WHEN "Booking"."endTime" < now() THEN 'completed'::text
|
||||
WHEN "Booking"."endTime" > now() THEN 'uncompleted'::text
|
||||
ELSE NULL::text
|
||||
END AS "timeStatus",
|
||||
et."parentId" AS "eventParentId",
|
||||
"u"."email" AS "userEmail",
|
||||
"u"."username" AS "username",
|
||||
"Booking"."ratingFeedback",
|
||||
"Booking"."rating",
|
||||
"Booking"."noShowHost",
|
||||
false as "isTeamBooking"
|
||||
FROM "Booking"
|
||||
LEFT JOIN "EventType" et ON "Booking"."eventTypeId" = et.id
|
||||
LEFT JOIN users u ON u.id = "Booking"."userId"
|
||||
WHERE et."teamId" IS NULL
|
||||
UNION
|
||||
SELECT
|
||||
"Booking".id,
|
||||
"Booking".uid,
|
||||
"Booking"."eventTypeId",
|
||||
"Booking".title,
|
||||
"Booking".description,
|
||||
"Booking"."startTime",
|
||||
"Booking"."endTime",
|
||||
"Booking"."createdAt",
|
||||
"Booking".location,
|
||||
"Booking".paid,
|
||||
"Booking".status,
|
||||
"Booking".rescheduled,
|
||||
"Booking"."userId",
|
||||
et."teamId",
|
||||
et.length AS "eventLength",
|
||||
CASE
|
||||
WHEN "Booking".rescheduled IS TRUE THEN 'rescheduled'::text
|
||||
WHEN "Booking".status = 'cancelled'::"BookingStatus" AND "Booking".rescheduled IS NULL THEN 'cancelled'::text
|
||||
WHEN "Booking"."endTime" < now() THEN 'completed'::text
|
||||
WHEN "Booking"."endTime" > now() THEN 'uncompleted'::text
|
||||
ELSE NULL::text
|
||||
END AS "timeStatus",
|
||||
et."parentId" AS "eventParentId",
|
||||
"u"."email" AS "userEmail",
|
||||
"u"."username" AS "username",
|
||||
"Booking"."ratingFeedback",
|
||||
"Booking"."rating",
|
||||
"Booking"."noShowHost",
|
||||
true as "isTeamBooking"
|
||||
FROM "Booking"
|
||||
LEFT JOIN "EventType" et ON "Booking"."eventTypeId" = et.id
|
||||
LEFT JOIN users u ON u.id = "Booking"."userId"
|
||||
WHERE "et"."teamId" IS NOT NULL
|
||||
@@ -1229,6 +1229,7 @@ view BookingTimeStatus {
|
||||
ratingFeedback String?
|
||||
rating Int?
|
||||
noShowHost Boolean?
|
||||
isTeamBooking Boolean
|
||||
}
|
||||
|
||||
model CalendarCache {
|
||||
|
||||
Reference in New Issue
Block a user