mirror of
https://github.com/lukevella/rallly.git
synced 2025-08-06 09:59:00 +02:00
🔥 Remove deprecated event model (#1775)
This commit is contained in:
parent
b1b76b4bec
commit
37b7ed5e19
14 changed files with 85 additions and 248 deletions
|
@ -48,12 +48,6 @@ export async function getPolls({
|
|||
image: true,
|
||||
},
|
||||
},
|
||||
event: {
|
||||
select: {
|
||||
start: true,
|
||||
duration: true,
|
||||
},
|
||||
},
|
||||
participants: {
|
||||
where: {
|
||||
deleted: false,
|
||||
|
@ -95,7 +89,6 @@ export async function getPolls({
|
|||
email: participant.email ?? undefined,
|
||||
image: participant.user?.image ?? undefined,
|
||||
})),
|
||||
event: poll.event ?? undefined,
|
||||
};
|
||||
}),
|
||||
hasNextPage,
|
||||
|
|
|
@ -1,99 +0,0 @@
|
|||
import type { Prisma } from "@rallly/database";
|
||||
import { prisma } from "@rallly/database";
|
||||
import { unstable_cache } from "next/cache";
|
||||
|
||||
type PollFilters = {
|
||||
userId: string;
|
||||
limit?: number;
|
||||
};
|
||||
|
||||
export const getRecentlyUpdatedPolls = async ({
|
||||
userId,
|
||||
limit = 3,
|
||||
}: PollFilters) => {
|
||||
// Build the where clause based on filters
|
||||
const where: Prisma.PollWhereInput = {
|
||||
userId,
|
||||
deleted: false,
|
||||
};
|
||||
|
||||
const data = await prisma.poll.findMany({
|
||||
where,
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
status: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
event: {
|
||||
select: {
|
||||
start: true,
|
||||
duration: true,
|
||||
},
|
||||
},
|
||||
participants: {
|
||||
where: {
|
||||
deleted: false,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
user: {
|
||||
select: {
|
||||
image: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
orderBy: {
|
||||
createdAt: "desc",
|
||||
},
|
||||
},
|
||||
options: {
|
||||
select: {
|
||||
id: true,
|
||||
startTime: true,
|
||||
duration: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
orderBy: {
|
||||
updatedAt: "desc",
|
||||
},
|
||||
take: limit,
|
||||
});
|
||||
|
||||
return data.map((poll) => {
|
||||
const { options, ...rest } = poll;
|
||||
const durations = new Set<number>();
|
||||
for (const option of options) {
|
||||
durations.add(option.duration);
|
||||
}
|
||||
return {
|
||||
...rest,
|
||||
participants: poll.participants.map((participant) => ({
|
||||
id: participant.id,
|
||||
name: participant.name,
|
||||
image: participant.user?.image ?? undefined,
|
||||
})),
|
||||
dateOptions: {
|
||||
first: options[0]?.startTime,
|
||||
last: options[options.length - 1]?.startTime,
|
||||
count: options.length,
|
||||
duration:
|
||||
durations.size === 1
|
||||
? (durations.values().next().value as number)
|
||||
: Array.from(durations),
|
||||
},
|
||||
event: poll.event ?? undefined,
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
export const getCachedRecentlyUpdatedPolls = unstable_cache(
|
||||
getRecentlyUpdatedPolls,
|
||||
undefined,
|
||||
{
|
||||
revalidate: 60 * 5,
|
||||
tags: ["polls"],
|
||||
},
|
||||
);
|
|
@ -31,11 +31,24 @@ export async function getScheduledEvents({
|
|||
}) {
|
||||
const now = new Date();
|
||||
|
||||
const todayStart = dayjs().startOf("day").toDate();
|
||||
const todayEnd = dayjs().endOf("day").toDate();
|
||||
|
||||
const where: Prisma.ScheduledEventWhereInput = {
|
||||
userId,
|
||||
deletedAt: null,
|
||||
...(status !== "past" && { start: { gte: now } }),
|
||||
...(status === "past" && { start: { lt: now } }),
|
||||
...(status === "upcoming" && {
|
||||
OR: [
|
||||
{ allDay: false, start: { gte: now } },
|
||||
{ allDay: true, start: { gte: todayStart, lte: todayEnd } },
|
||||
],
|
||||
}),
|
||||
...(status === "past" && {
|
||||
OR: [
|
||||
{ allDay: false, start: { lt: now } },
|
||||
{ allDay: true, start: { lt: todayStart } },
|
||||
],
|
||||
}),
|
||||
...(search && { title: { contains: search, mode: "insensitive" } }),
|
||||
status: mapStatus[status],
|
||||
};
|
||||
|
@ -76,10 +89,6 @@ export async function getScheduledEvents({
|
|||
|
||||
const events = rawEvents.map((event) => ({
|
||||
...event,
|
||||
status:
|
||||
event.status === "confirmed"
|
||||
? ((event.start < now ? "past" : "upcoming") as Status)
|
||||
: event.status,
|
||||
invites: event.invites.map((invite) => ({
|
||||
id: invite.id,
|
||||
inviteeName: invite.inviteeName,
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
import { ParticipantAvatarBar } from "@/components/participant-avatar-bar";
|
||||
import { StackedList } from "@/components/stacked-list";
|
||||
import { Trans } from "@/components/trans";
|
||||
import { ScheduledEventStatusBadge } from "@/features/scheduled-event/components/scheduled-event-status-badge";
|
||||
import type { Status } from "@/features/scheduled-event/schema";
|
||||
import { FormattedDateTime } from "@/features/timezone/client/formatted-date-time";
|
||||
|
||||
export const ScheduledEventList = StackedList;
|
||||
|
@ -11,7 +9,6 @@ export function ScheduledEventListItem({
|
|||
title,
|
||||
start,
|
||||
end,
|
||||
status,
|
||||
allDay,
|
||||
invites,
|
||||
floating: isFloating,
|
||||
|
@ -20,7 +17,6 @@ export function ScheduledEventListItem({
|
|||
title: string;
|
||||
start: Date;
|
||||
end: Date;
|
||||
status: Status;
|
||||
allDay: boolean;
|
||||
invites: { id: string; inviteeName: string; inviteeImage?: string }[];
|
||||
floating: boolean;
|
||||
|
@ -30,9 +26,6 @@ export function ScheduledEventListItem({
|
|||
<div className="flex flex-1 flex-col gap-y-1 lg:flex-row-reverse lg:justify-end lg:gap-x-4">
|
||||
<div className="flex items-center gap-4 text-sm">
|
||||
<div>{title}</div>
|
||||
<div>
|
||||
<ScheduledEventStatusBadge status={status} />
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center whitespace-nowrap text-sm lg:min-w-40">
|
||||
<div>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue