diff --git a/apps/availability/.env.local.template b/apps/availability/.env.local.template index 7ce2697..c5d7180 100644 --- a/apps/availability/.env.local.template +++ b/apps/availability/.env.local.template @@ -3,7 +3,7 @@ AIRTABLE_PERSONAL_ACCESS_TOKEN= # BlueDot Impact Slack, #tech-dev-alerts ALERTS_SLACK_CHANNEL_ID=C04SFUECECU -# For (local) BlueBot see https://airtable.com/appnNmNoNMB6crg6I/tbllthJ2YSPDsKWCt/viwfjWLvplq6Xw93D/recqurdJTPWzm5y4W -# For (prod) BlueBot see https://api.slack.com/apps/A04PV2GAQRY/install-on-team +# For (local) BlueBot see 1Password Team Vault "(local) BlueBot Slack App key" +# For (prod) BlueBot see 1Password Team Vault "(prod) BlueBot Slack App key" # Starts 'xoxb-' ALERTS_SLACK_BOT_TOKEN= diff --git a/apps/availability/src/pages/api/public/get-form.ts b/apps/availability/src/pages/api/public/get-form.ts index e45406e..8050b2d 100644 --- a/apps/availability/src/pages/api/public/get-form.ts +++ b/apps/availability/src/pages/api/public/get-form.ts @@ -13,17 +13,16 @@ export default apiRoute(async ( req: NextApiRequest, res: NextApiResponse, ) => { - const records = await db.scan(formConfigurationTable, { - filterByFormula: `{Slug} = "${req.query.slug}"`, - }); + const records = await db.scan(formConfigurationTable); + const targetRecord = records.find((record) => record.Slug === req.query.slug); - if (!records || records.length === 0) { + if (!targetRecord) { throw new createHttpError.NotFound('Form not found'); } res.status(200).json({ type: 'success', - title: records[0]?.Title || 'Unnamed form', - minimumLength: records[0]?.['Minimum length'] ?? 90, + title: targetRecord.Title || 'Unnamed form', // Title for the page + minimumLength: targetRecord['Minimum length'] ?? 90, // Min required time for form validation }); }, 'insecure_no_auth'); diff --git a/apps/availability/src/pages/api/public/submit.ts b/apps/availability/src/pages/api/public/submit.ts index fd93b57..4174f82 100644 --- a/apps/availability/src/pages/api/public/submit.ts +++ b/apps/availability/src/pages/api/public/submit.ts @@ -32,17 +32,15 @@ export default apiRoute(async ( return; } - const records = await db.scan(formConfigurationTable, { - filterByFormula: `{Slug} = "${req.query.slug}"`, - }); + const records = await db.scan(formConfigurationTable); + const targetRecord = records.find((record) => record.Slug === req.query.slug); - if (!records || records.length === 0) { + if (!targetRecord) { res.status(404).send({ type: 'error', message: 'Form not found' }); return; } - const record = records[0]!; - const webhookResponse = await axios.post(record.Webhook, { + const webhookResponse = await axios.post(targetRecord.Webhook, { Comments: data.comments, Email: data.email, 'Time availability in UTC': data.availability, @@ -50,7 +48,7 @@ export default apiRoute(async ( }); if (webhookResponse.status !== 200) { - throw new Error(`Unexpected response from form webhook (status ${webhookResponse.status}) for form ${record.id}`); + throw new Error(`Unexpected response from form webhook (status ${webhookResponse.status}) for form ${targetRecord.id}`); } res.status(200).json({ type: 'success' });