♻️ Remove legacy start column (#1113)

This commit is contained in:
Luke Vella 2024-05-18 17:32:49 +08:00 committed by GitHub
parent 14d0889a37
commit 533e347557
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 16 additions and 128 deletions

View file

@ -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>
);
}

View file

@ -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}`;

View file

@ -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;

View file

@ -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);
@ -44,7 +43,6 @@ const getPollIdFromAdminUrlId = async (urlId: string) => {
export const polls = router({
participants,
comments,
options,
// START LEGACY ROUTES
create: possiblyPublicProcedure
.input(
@ -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(),
@ -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,
@ -514,13 +510,6 @@ export const polls = router({
duration: true,
},
},
options: {
select: {
id: true,
start: true,
duration: true,
},
},
closed: true,
participants: {
select: {
@ -597,13 +586,6 @@ export const polls = router({
duration: true,
},
},
options: {
select: {
id: true,
start: true,
duration: true,
},
},
closed: true,
participants: {
select: {
@ -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({
@ -743,7 +673,7 @@ export const polls = router({
id: input.optionId,
},
select: {
start: true,
startTime: true,
duration: true,
},
});
@ -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({
@ -992,7 +924,6 @@ export const polls = router({
disableComments: true,
options: {
select: {
start: true,
startTime: true,
duration: true,
},

View file

@ -1,45 +0,0 @@
import { prisma } from "@rallly/database";
import { z } from "zod";
import { publicProcedure, router } from "../../trpc";
export const options = router({
list: publicProcedure
.input(
z.object({
pollId: z.string(),
}),
)
.query(async ({ input: { pollId } }) => {
const options = await prisma.option.findMany({
where: {
pollId,
},
select: {
id: true,
start: true,
duration: true,
},
orderBy: [
{
start: "asc",
},
],
});
return options;
}),
delete: publicProcedure
.input(
z.object({
optionId: z.string(),
}),
)
.mutation(async ({ input: { optionId } }) => {
await prisma.option.delete({
where: {
id: optionId,
},
});
}),
});

View file

@ -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";

View file

@ -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")