Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { Trans } from "@/i18n/client";

const Page = () => {
const { poll } = usePoll();
const urlId = poll.adminUrlId;
const { mutate: updatePollMutation, isPending: isUpdating } =
useUpdatePollMutation();
const router = useRouter();
Expand All @@ -46,7 +45,7 @@ const Page = () => {
onSubmit={form.handleSubmit((data) => {
//submit
updatePollMutation(
{ urlId, ...data },
{ pollId: poll.id, ...data },
{
onSuccess: (res) => {
if (res.ok) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ const Page = () => {
const onOk = () => {
updatePollMutation(
{
urlId: poll.adminUrlId,
pollId: poll.id,
timeZone: data.timeZone,
optionsToDelete: optionsToDelete.map(({ id }) => id),
optionsToAdd,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const Page = () => {
onSubmit={form.handleSubmit(async (data) => {
//submit
const res = await update.mutateAsync({
urlId: poll.adminUrlId,
pollId: poll.id,
...data,
});
if (res.ok) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default async function Layout(
trpc.polls.comments.list.prefetch({ pollId: params.urlId }),
]);

if (!poll.adminUrlId) {
if (!poll.canManage) {
redirect(`/invite/${params.urlId}`);
}

Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/trpc/client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export type GetPollApiResponse = {
banned: boolean;
} | null;
timeZone: string | null;
adminUrlId: string;
canManage: boolean;
status: PollStatus;
participantUrlId: string;
createdAt: Date;
Expand Down
40 changes: 9 additions & 31 deletions apps/web/src/trpc/routers/polls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,6 @@ import { participants } from "./polls/participants";

const collapseNewlines = (s: string) => s.replace(/\n{3,}/g, "\n\n");

const getPollIdFromAdminUrlId = async (urlId: string) => {
const res = await prisma.poll.findUnique({
select: {
id: true,
},
where: { adminUrlId: urlId },
});

if (!res) {
throw new TRPCError({
code: "NOT_FOUND",
message: "Poll not found",
});
}
return res.id;
};

export const polls = router({
participants,
comments,
Expand Down Expand Up @@ -289,7 +272,7 @@ export const polls = router({
modify: possiblyPublicProcedure
.input(
z.object({
urlId: z.string(),
pollId: z.string(),
title: z.string().trim().optional(),
timeZone: z.string().optional(),
location: z.string().trim().optional(),
Expand All @@ -305,7 +288,7 @@ export const polls = router({
.use(requireUserMiddleware)
.use(createRateLimitMiddleware("update_poll", 10, "1 m"))
.mutation(async ({ input, ctx }) => {
const pollId = await getPollIdFromAdminUrlId(input.urlId);
const pollId = input.pollId;

if (!(await hasPollAdminAccess(pollId, ctx.user.id))) {
throw new TRPCError({
Expand Down Expand Up @@ -570,7 +553,6 @@ export const polls = router({
.input(
z.object({
urlId: z.string(),
adminToken: z.string().optional(),
}),
)
.query(async ({ input, ctx }) => {
Expand All @@ -582,7 +564,6 @@ export const polls = router({
location: true,
description: true,
createdAt: true,
adminUrlId: true,
participantUrlId: true,
status: true,
hideParticipants: true,
Expand Down Expand Up @@ -652,7 +633,7 @@ export const polls = router({
}
const inviteLink = shortUrl(`/invite/${res.id}`);

const canManagePoll = ctx.user
const canManage = ctx.user
? await canUserManagePoll(ctx.user, res)
: false;

Expand Down Expand Up @@ -680,15 +661,12 @@ export const polls = router({
}
: null;

if (canManagePoll || res.adminUrlId === input.adminToken) {
return {
...res,
inviteLink,
event,
};
} else {
return { ...res, adminUrlId: "", inviteLink, event };
}
return {
...res,
canManage,
inviteLink,
event,
};
}),
book: proProcedure
.input(
Expand Down
Loading