From ef25ccc1a919f49bc6a2dd287f94c098c7d63ca6 Mon Sep 17 00:00:00 2001 From: Matt Lewis Date: Wed, 20 Nov 2024 23:59:35 -0700 Subject: [PATCH] fix: types, db import --- NOTES.md | 1 + api/src/functions/graphql.ts | 2 +- api/src/lib/backend/email/send.test.ts | 2 +- api/src/lib/backend/email/send.ts | 2 +- api/src/lib/backend/schedule/reminder.test.ts | 2 +- api/src/lib/backend/schedule/reminder.ts | 2 +- api/src/lib/backend/tidy.test.ts | 3 ++- api/src/lib/backend/tidy.ts | 3 ++- api/src/lib/{backend => }/db.ts | 2 +- api/src/services/events/events.ts | 2 +- api/src/services/ignoredEmails/ignoredEmails.test.ts | 2 +- api/src/services/ignoredEmails/ignoredEmails.ts | 2 +- api/src/services/responses/responses.test.ts | 2 +- api/src/services/responses/responses.ts | 4 +++- scripts/seed.ts | 3 ++- web/src/components/PageHead/PageHead.tsx | 2 +- web/src/components/ResponseForm/ResponseForm.tsx | 7 +++++-- 17 files changed, 26 insertions(+), 17 deletions(-) rename api/src/lib/{backend => }/db.ts (91%) diff --git a/NOTES.md b/NOTES.md index 71f08dd..00735b9 100644 --- a/NOTES.md +++ b/NOTES.md @@ -46,6 +46,7 @@ - [ ] "Serious mode" for LoadingBuddy for e.g. unsubscribe requests - [ ] Notification when target email is denylisted on record creation - [ ] Replace shared API lib dir with Yarn "shared package" workspace +- [ ] Add advanced crash logging - [x] Resend confirmation if an RSVP enters an existing email - [x] Captcha - [x] Hold RSVP locally with cookie diff --git a/api/src/functions/graphql.ts b/api/src/functions/graphql.ts index 3618f9b..8e44cdd 100644 --- a/api/src/functions/graphql.ts +++ b/api/src/functions/graphql.ts @@ -6,9 +6,9 @@ import directives from 'src/directives/**/*.{js,ts}' import sdls from 'src/graphql/**/*.sdl.{js,ts}' import services from 'src/services/**/*.{js,ts}' -import { db } from 'src/lib/backend/db' import { logger } from 'src/lib/backend/logger' import { wrap } from 'src/lib/backend/sentry' +import { db } from 'src/lib/db' const baseHandler = createGraphQLHandler({ loggerConfig: { logger, options: {} }, diff --git a/api/src/lib/backend/email/send.test.ts b/api/src/lib/backend/email/send.test.ts index 5cc0a0f..acbc720 100644 --- a/api/src/lib/backend/email/send.test.ts +++ b/api/src/lib/backend/email/send.test.ts @@ -1,6 +1,6 @@ import { InMemoryMailHandler } from '@redwoodjs/mailer-handler-in-memory' -import { db } from '../db' +import { db } from '../../db' import { mailer } from '../mailer' import { sendEmail } from './send' diff --git a/api/src/lib/backend/email/send.ts b/api/src/lib/backend/email/send.ts index 870e05c..57b5394 100644 --- a/api/src/lib/backend/email/send.ts +++ b/api/src/lib/backend/email/send.ts @@ -1,7 +1,7 @@ import { MAIL_SENDER } from 'src/api.config' import { mailer } from 'src/lib/backend/mailer' -import { db } from '../db' +import { db } from '../../db' import { logger } from '../logger' import { Plain } from './plain' diff --git a/api/src/lib/backend/schedule/reminder.test.ts b/api/src/lib/backend/schedule/reminder.test.ts index 3538915..20df53b 100644 --- a/api/src/lib/backend/schedule/reminder.test.ts +++ b/api/src/lib/backend/schedule/reminder.test.ts @@ -1,4 +1,4 @@ -import { db } from '../db' +import { db } from '../../db' import { sendOutstandingReminders } from './reminder' diff --git a/api/src/lib/backend/schedule/reminder.ts b/api/src/lib/backend/schedule/reminder.ts index 2eb331a..19237a2 100644 --- a/api/src/lib/backend/schedule/reminder.ts +++ b/api/src/lib/backend/schedule/reminder.ts @@ -1,4 +1,4 @@ -import { db } from '../db' +import { db } from '../../db' import { sendReminder } from '../email/template/reminder' import { logger } from '../logger' diff --git a/api/src/lib/backend/tidy.test.ts b/api/src/lib/backend/tidy.test.ts index 9a20ad2..5e593e2 100644 --- a/api/src/lib/backend/tidy.test.ts +++ b/api/src/lib/backend/tidy.test.ts @@ -1,7 +1,8 @@ import { randomString, randomInteger } from 'remeda' import { Event, Response } from 'types/graphql' -import { db } from './db' +import { db } from '../db' + import { tidyUnconfirmedEvents, tidyUnconfirmedResponses } from './tidy' function buildEvent(overrides: Partial = {}): Omit { diff --git a/api/src/lib/backend/tidy.ts b/api/src/lib/backend/tidy.ts index 22fd4aa..febf5ad 100644 --- a/api/src/lib/backend/tidy.ts +++ b/api/src/lib/backend/tidy.ts @@ -1,6 +1,7 @@ import dayjs from 'src/lib/shared/dayjs' -import { db } from './db' +import { db } from '../db' + import { logger } from './logger' const UNCONFIRMED_EXPIRY = dayjs.duration(24, 'hours') diff --git a/api/src/lib/backend/db.ts b/api/src/lib/db.ts similarity index 91% rename from api/src/lib/backend/db.ts rename to api/src/lib/db.ts index 575721b..8bbfd5b 100644 --- a/api/src/lib/backend/db.ts +++ b/api/src/lib/db.ts @@ -5,7 +5,7 @@ import { PrismaClient } from '@prisma/client' import { emitLogLevels, handlePrismaLogging } from '@redwoodjs/api/logger' -import { logger } from './logger' +import { logger } from './backend/logger' const prismaClient = new PrismaClient({ log: emitLogLevels(['info', 'warn', 'error']), diff --git a/api/src/services/events/events.ts b/api/src/services/events/events.ts index d260f1e..797c368 100644 --- a/api/src/services/events/events.ts +++ b/api/src/services/events/events.ts @@ -7,7 +7,6 @@ import type { import { RedwoodError, validate } from '@redwoodjs/api' import { validateCaptcha } from 'src/lib/backend/captcha' -import { db } from 'src/lib/backend/db' import { sendEventDetails } from 'src/lib/backend/email/template/event' import { notifyEventCreated, @@ -15,6 +14,7 @@ import { } from 'src/lib/backend/notify/event' import { summarize } from 'src/lib/backend/response' import { generateToken, alphaLower } from 'src/lib/backend/token' +import { db } from 'src/lib/db' import dayjs from 'src/lib/shared/dayjs' import { checkVisibility } from 'src/lib/shared/visibility' diff --git a/api/src/services/ignoredEmails/ignoredEmails.test.ts b/api/src/services/ignoredEmails/ignoredEmails.test.ts index c4f9013..a26d61b 100644 --- a/api/src/services/ignoredEmails/ignoredEmails.test.ts +++ b/api/src/services/ignoredEmails/ignoredEmails.test.ts @@ -1,5 +1,5 @@ -import { db } from 'src/lib/backend/db' import { sign } from 'src/lib/backend/sign' +import { db } from 'src/lib/db' import { createIgnoredEmail, diff --git a/api/src/services/ignoredEmails/ignoredEmails.ts b/api/src/services/ignoredEmails/ignoredEmails.ts index 932eeda..fd6dfac 100644 --- a/api/src/services/ignoredEmails/ignoredEmails.ts +++ b/api/src/services/ignoredEmails/ignoredEmails.ts @@ -2,8 +2,8 @@ import type { QueryResolvers, MutationResolvers } from 'types/graphql' import { RedwoodError } from '@redwoodjs/api' -import { db } from 'src/lib/backend/db' import { verify } from 'src/lib/backend/sign' +import { db } from 'src/lib/db' const ERROR_MSG = 'Could not validate your request' diff --git a/api/src/services/responses/responses.test.ts b/api/src/services/responses/responses.test.ts index 0c3fd64..1863f16 100644 --- a/api/src/services/responses/responses.test.ts +++ b/api/src/services/responses/responses.test.ts @@ -1,6 +1,6 @@ import duration from 'dayjs/plugin/duration' -import { db } from 'src/lib/backend/db' +import { db } from 'src/lib/db' import dayjs from 'src/lib/shared/dayjs' import { diff --git a/api/src/services/responses/responses.ts b/api/src/services/responses/responses.ts index 0b92aff..fe654bd 100644 --- a/api/src/services/responses/responses.ts +++ b/api/src/services/responses/responses.ts @@ -8,7 +8,6 @@ import type { import { RedwoodError } from '@redwoodjs/api' import { validateCaptcha } from 'src/lib/backend/captcha' -import { db } from 'src/lib/backend/db' import { // sendNewResponseReceived, sendResponseConfirmation, @@ -19,6 +18,7 @@ import { notifyResponseDeleted, } from 'src/lib/backend/notify/response' import { generateToken } from 'src/lib/backend/token' +import { db } from 'src/lib/db' import dayjs from 'src/lib/shared/dayjs' import { reminderDurations } from 'src/lib/shared/reminder' @@ -59,6 +59,8 @@ export const responseByEditToken: QueryResolvers['responseByEditToken'] = include: { event: true, reminders: true }, }) + if (!resp) throw new RedwoodError("Sorry, we couldn't find that RSVP.") + if (!resp.confirmed) { const updated = await db.response.update({ where: { editToken }, diff --git a/scripts/seed.ts b/scripts/seed.ts index 1c220e6..2aaf5b6 100644 --- a/scripts/seed.ts +++ b/scripts/seed.ts @@ -1,5 +1,6 @@ import type { Prisma } from '@prisma/client' -import { db } from 'api/src/lib/db' + +import { db } from '../api/src/lib/backend/db' export default async () => { try { diff --git a/web/src/components/PageHead/PageHead.tsx b/web/src/components/PageHead/PageHead.tsx index 49e3f38..58d8e6e 100644 --- a/web/src/components/PageHead/PageHead.tsx +++ b/web/src/components/PageHead/PageHead.tsx @@ -1,6 +1,6 @@ import { Metadata } from '@redwoodjs/web' -import { SITE_URL } from 'src/lib/shared/shared.config' +import { SITE_URL } from 'src/apiLibShared/shared.config' import Typ from '../Typ/Typ' diff --git a/web/src/components/ResponseForm/ResponseForm.tsx b/web/src/components/ResponseForm/ResponseForm.tsx index 9090995..e9ae4b0 100644 --- a/web/src/components/ResponseForm/ResponseForm.tsx +++ b/web/src/components/ResponseForm/ResponseForm.tsx @@ -64,8 +64,11 @@ const ResponseForm = (props: Props) => { const { formState, getValues } = formMethods const { email } = getValues() - const forbidResubmit = - email === error?.cause?.extensions?.['forbidResubmitForEmail'] + const forbidResubmit = (() => { + if (!email) return false + return email === error?.cause?.extensions?.['forbidResubmitForEmail'] + })() + console.log({ email, error, forbidResubmit }) const [exampleName, setExampleName] = useState('') useEffect(() => {