Skip to content

Commit

Permalink
♻️ Remove legacy start column (#1113)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukevella authored May 18, 2024
1 parent 14d0889 commit 533e347
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 128 deletions.
2 changes: 1 addition & 1 deletion apps/web/src/components/scheduled-event.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function FinalTime({ start, duration }: { start: Date; duration: number }) {
return <Trans i18nKey="allDay" />;
}
return (
<span>{`${adjustTimeZone(start, !poll.timeZone).format("LT")} - ${adjustTimeZone(dayjs(start).add(duration, "minutes"), !poll.timeZone).format("LT")}`}</span>
<span>{`${adjustTimeZone(start, !poll.timeZone).format("LT")} - ${adjustTimeZone(dayjs(start).add(duration, "minutes"), !poll.timeZone).format(poll.timeZone ? "LT z" : "LT")}`}</span>
);
}

Expand Down
5 changes: 0 additions & 5 deletions apps/web/src/contexts/current-event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ export type OptionScore = {
no: string[];
};

export const useCurrentPollOptions = () => {
const pollId = useCurrentEventId();
return trpc.polls.options.list.useQuery({ pollId });
};

export const useCreatePollLink = () => {
const pollId = useCurrentEventId();
const basePath = `/poll/${pollId}`;
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/utils/trpc/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export type GetPollApiResponse = {
title: string;
location: string | null;
description: string | null;
options: { id: string; start: Date; startTime: Date; duration: number }[];
options: { id: string; startTime: Date; duration: number }[];
user: User | null;
timeZone: string | null;
adminUrlId: string;
Expand Down
81 changes: 6 additions & 75 deletions packages/backend/trpc/routers/polls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
router,
} from "../trpc";
import { comments } from "./polls/comments";
import { options } from "./polls/options";
import { participants } from "./polls/participants";

dayjs.extend(toArray);
Expand All @@ -44,7 +43,6 @@ const getPollIdFromAdminUrlId = async (urlId: string) => {
export const polls = router({
participants,
comments,
options,
// START LEGACY ROUTES
create: possiblyPublicProcedure
.input(
Expand Down Expand Up @@ -101,7 +99,6 @@ export const polls = router({
options: {
createMany: {
data: input.options.map((option) => ({
start: dayjs(option.startDate).utc(true).toDate(),
startTime: input.timeZone
? dayjs(option.startDate).tz(input.timeZone, true).toDate()
: dayjs(option.startDate).utc(true).toDate(),
Expand Down Expand Up @@ -375,12 +372,11 @@ export const polls = router({
options: {
select: {
id: true,
start: true,
startTime: true,
duration: true,
},
orderBy: {
start: "asc",
startTime: "asc",
},
},
user: true,
Expand Down Expand Up @@ -514,13 +510,6 @@ export const polls = router({
duration: true,
},
},
options: {
select: {
id: true,
start: true,
duration: true,
},
},
closed: true,
participants: {
select: {
Expand Down Expand Up @@ -597,13 +586,6 @@ export const polls = router({
duration: true,
},
},
options: {
select: {
id: true,
start: true,
duration: true,
},
},
closed: true,
participants: {
select: {
Expand Down Expand Up @@ -631,58 +613,6 @@ export const polls = router({

return { total, rows };
}),
list: possiblyPublicProcedure.query(async ({ ctx }) => {
const polls = await prisma.poll.findMany({
where: {
userId: ctx.user.id,
deleted: false,
},
select: {
id: true,
title: true,
location: true,
createdAt: true,
timeZone: true,
adminUrlId: true,
participantUrlId: true,
status: true,
event: {
select: {
start: true,
duration: true,
},
},
options: {
select: {
id: true,
start: true,
duration: true,
},
},
closed: true,
participants: {
select: {
id: true,
name: true,
},
orderBy: [
{
createdAt: "desc",
},
{ name: "desc" },
],
},
},
orderBy: [
{
createdAt: "desc",
},
{ title: "asc" },
],
});

return polls;
}),
book: proProcedure
.input(
z.object({
Expand Down Expand Up @@ -743,7 +673,7 @@ export const polls = router({
id: input.optionId,
},
select: {
start: true,
startTime: true,
duration: true,
},
});
Expand All @@ -755,10 +685,12 @@ export const polls = router({
});
}

let eventStart = dayjs(option.start).utc();
let eventStart = dayjs(option.startTime);

if (poll.timeZone) {
eventStart = eventStart.tz(poll.timeZone, true);
eventStart = eventStart.tz(poll.timeZone);
} else {
eventStart = eventStart.utc();
}

await prisma.poll.update({
Expand Down Expand Up @@ -992,7 +924,6 @@ export const polls = router({
disableComments: true,
options: {
select: {
start: true,
startTime: true,
duration: true,
},
Expand Down
45 changes: 0 additions & 45 deletions packages/backend/trpc/routers/polls/options.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
Warnings:
- You are about to drop the column `start` on the `options` table. All the data in the column will be lost.
*/
-- AlterTable
ALTER TABLE "options" DROP COLUMN "start";
1 change: 0 additions & 1 deletion packages/database/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ model Participant {

model Option {
id String @id @default(cuid())
start DateTime @db.Timestamp(0) // @deprecated - use startTime
startTime DateTime @db.Timestamp(0) @map("start_time")
duration Int @default(0) @map("duration_minutes")
pollId String @map("poll_id")
Expand Down

0 comments on commit 533e347

Please sign in to comment.