Skip to content

Commit

Permalink
Update to avoid using filterByFormula
Browse files Browse the repository at this point in the history
  • Loading branch information
Tarin committed Oct 8, 2024
1 parent ede9fb3 commit 6fd2255
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
4 changes: 2 additions & 2 deletions apps/availability/.env.local.template
Original file line number Diff line number Diff line change
Expand Up @@ -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=
11 changes: 5 additions & 6 deletions apps/availability/src/pages/api/public/get-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,16 @@ export default apiRoute(async (
req: NextApiRequest,
res: NextApiResponse<GetFormResponse>,
) => {
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');
12 changes: 5 additions & 7 deletions apps/availability/src/pages/api/public/submit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,23 @@ 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,
Timezone: data.timezone,
});

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' });
Expand Down

0 comments on commit 6fd2255

Please sign in to comment.