Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
Turn on notifications for legacy polls
Luke Vella8675798c1857
diff --git a/pages/api/legacy/[urlId].ts b/pages/api/legacy/[urlId].tsindex 0e4997812..21f3bdae1 100644--- a/pages/api/legacy/[urlId].ts+++ b/pages/api/legacy/[urlId].ts@@ -130,6 +130,7 @@ export default async function handler(},},},+ notifications: legacyPoll.creator.allowNotifications,verificationCode: await nanoid(), // can't get it from apioptions: {createMany: {diff --git a/pages/api/poll/[urlId]/comments/index.ts b/pages/api/poll/[urlId]/comments/index.tsindex c3f929340..e3041365e 100644--- a/pages/api/poll/[urlId]/comments/index.ts+++ b/pages/api/poll/[urlId]/comments/index.ts@@ -31,47 +31,45 @@ export default withLink(async (req, res, link) => {},});- if (link.role === "participant") {- const poll = await prisma.poll.findUnique({- where: {- urlId: link.pollId,- },- include: {- links: true,- user: true,- },- });+ const poll = await prisma.poll.findUnique({+ where: {+ urlId: link.pollId,+ },+ include: {+ links: true,+ user: true,+ },+ });- if (poll?.notifications && poll.verified && !poll.demo) {- // Get the admin link- const adminLink = getAdminLink(poll.links);+ if (poll?.notifications && poll.verified && !poll.demo) {+ // Get the admin link+ const adminLink = getAdminLink(poll.links);- if (adminLink) {- const homePageUrl = absoluteUrl(req).origin;- const pollUrl = `${homePageUrl}/admin/${adminLink.urlId}`;- const unsubscribeUrl = `${pollUrl}?unsubscribe=true`;+ if (adminLink) {+ const homePageUrl = absoluteUrl(req).origin;+ const pollUrl = `${homePageUrl}/admin/${adminLink.urlId}`;+ const unsubscribeUrl = `${pollUrl}?unsubscribe=true`;- try {- await sendEmailTemplate({- templateName: "new-comment",- to: poll.user.email,- subject: `Rallly: ${poll.title} - New Comment`,- templateVars: {- title: poll.title,- name: poll.authorName,- author: newComment.authorName,- pollUrl,- homePageUrl: absoluteUrl(req).origin,- supportEmail: process.env.NEXT_PUBLIC_SUPPORT_EMAIL,- unsubscribeUrl,- },- });- } catch (e) {- console.error(e);- }- } else {- console.log(`Missing admin link for poll: ${link.pollId}`);+ try {+ await sendEmailTemplate({+ templateName: "new-comment",+ to: poll.user.email,+ subject: `Rallly: ${poll.title} - New Comment`,+ templateVars: {+ title: poll.title,+ name: poll.authorName,+ author: newComment.authorName,+ pollUrl,+ homePageUrl: absoluteUrl(req).origin,+ supportEmail: process.env.NEXT_PUBLIC_SUPPORT_EMAIL,+ unsubscribeUrl,+ },+ });+ } catch (e) {+ console.error(e);}+ } else {+ console.log(`Missing admin link for poll: ${link.pollId}`);}}diff --git a/pages/api/poll/[urlId]/participant/index.ts b/pages/api/poll/[urlId]/participant/index.tsindex de3e47a47..b31bae2d0 100644--- a/pages/api/poll/[urlId]/participant/index.ts+++ b/pages/api/poll/[urlId]/participant/index.ts@@ -30,47 +30,45 @@ export default withLink(async (req, res, link) => {},});- if (link.role === "participant") {- const poll = await prisma.poll.findUnique({- where: {- urlId: link.pollId,- },- include: {- user: true,- links: true,- },- });+ const poll = await prisma.poll.findUnique({+ where: {+ urlId: link.pollId,+ },+ include: {+ user: true,+ links: true,+ },+ });- if (poll?.notifications && poll.verified && !poll.demo) {- // Get the admin link- const adminLink = getAdminLink(poll.links);+ if (poll?.notifications && poll.verified && !poll.demo) {+ // Get the admin link+ const adminLink = getAdminLink(poll.links);- if (adminLink) {- const homePageUrl = absoluteUrl(req).origin;- const pollUrl = `${homePageUrl}/admin/${adminLink.urlId}`;- const unsubscribeUrl = `${pollUrl}?unsubscribe=true`;+ if (adminLink) {+ const homePageUrl = absoluteUrl(req).origin;+ const pollUrl = `${homePageUrl}/admin/${adminLink.urlId}`;+ const unsubscribeUrl = `${pollUrl}?unsubscribe=true`;- try {- await sendEmailTemplate({- templateName: "new-participant",- to: poll.user.email,- subject: `Rallly: ${poll.title} - New Participant`,- templateVars: {- title: poll.title,- name: poll.authorName,- participantName: participant.name,- pollUrl,- homePageUrl: absoluteUrl(req).origin,- supportEmail: process.env.NEXT_PUBLIC_SUPPORT_EMAIL,- unsubscribeUrl,- },- });- } catch (e) {- console.error(e);- }- } else {- console.error(`Missing admin link for poll: ${link.pollId}`);+ try {+ await sendEmailTemplate({+ templateName: "new-participant",+ to: poll.user.email,+ subject: `Rallly: ${poll.title} - New Participant`,+ templateVars: {+ title: poll.title,+ name: poll.authorName,+ participantName: participant.name,+ pollUrl,+ homePageUrl: absoluteUrl(req).origin,+ supportEmail: process.env.NEXT_PUBLIC_SUPPORT_EMAIL,+ unsubscribeUrl,+ },+ });+ } catch (e) {+ console.error(e);}+ } else {+ console.error(`Missing admin link for poll: ${link.pollId}`);}}