🧹 Remove legacy user preferences (#1035)

This commit is contained in:
Luke Vella 2024-02-24 10:44:53 +08:00 committed by GitHub
parent 27dda65ca5
commit 44a0d95355
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 2 additions and 71 deletions

View file

@ -2,14 +2,12 @@ import { mergeRouters, router } from "../trpc";
import { auth } from "./auth";
import { polls } from "./polls";
import { user } from "./user";
import { userPreferences } from "./user-preferences";
export const appRouter = mergeRouters(
router({
auth,
polls,
user,
userPreferences,
}),
);

View file

@ -1,58 +0,0 @@
import { prisma } from "@rallly/database";
import z from "zod";
import { publicProcedure, router } from "../trpc";
export const userPreferences = router({
get: publicProcedure.query(async ({ ctx }) => {
if (ctx.user.isGuest) {
return null;
} else {
return await prisma.userPreferences.findUnique({
where: {
userId: ctx.user.id,
},
select: {
timeZone: true,
weekStart: true,
timeFormat: true,
},
});
}
}),
update: publicProcedure
.input(
z.object({
timeZone: z.string().optional(),
weekStart: z.number().min(0).max(6).optional(),
timeFormat: z.enum(["hours12", "hours24"]).optional(),
}),
)
.mutation(async ({ input, ctx }) => {
if (ctx.user.isGuest === false) {
await prisma.userPreferences.upsert({
where: {
userId: ctx.user.id,
},
create: {
userId: ctx.user.id,
...input,
},
update: {
...input,
},
});
}
}),
delete: publicProcedure.mutation(async ({ ctx }) => {
if (ctx.user.isGuest) {
// delete guest preferences
} else {
await prisma.userPreferences.delete({
where: {
userId: ctx.user.id,
},
});
}
}),
});

View file

@ -0,0 +1,2 @@
-- DropTable
DROP TABLE "user_preferences";

View file

@ -99,17 +99,6 @@ model Subscription {
@@map("subscriptions")
}
// @deprecated
model UserPreferences {
userId String @id @map("user_id")
timeZone String? @map("time_zone")
weekStart Int? @map("week_start")
timeFormat TimeFormat? @map("time_format")
createdAt DateTime @default(now()) @map("created_at")
@@map("user_preferences")
}
enum ParticipantVisibility {
full
scoresOnly