From 7e5ea5df6fe7e3fdbea0ef5dd251fb2c5b0209be Mon Sep 17 00:00:00 2001 From: Willard Nilges Date: Sun, 13 Oct 2024 11:31:15 -0400 Subject: [PATCH] Stub out updating S3 submissions with httpCode --- app/data.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/app/data.ts b/app/data.ts index 201e965..92bd1b3 100644 --- a/app/data.ts +++ b/app/data.ts @@ -33,7 +33,7 @@ export async function recordJoinFormSubmissionToCSV( } // Records the submission we just got as a JSON object in an S3 bucket. -export async function recordJoinFormSubmissionToS3(submission: JoinFormValues) { +export async function recordJoinFormSubmissionToS3(submission: JoinFormValues, key: string = "", responseCode: string = "") { if (S3_ACCESS_KEY === undefined || S3_SECRET_KEY === undefined) { console.error( "S3 credentials not configured. I WILL NOT SAVE THIS SUBMISSION.", @@ -58,10 +58,14 @@ export async function recordJoinFormSubmissionToS3(submission: JoinFormValues) { .replace(/[-:T]/g, "/") .slice(0, 19); + key = key != "" ? key : `${S3_BASE_NAME}/${submissionKey}.json`; + + let body = responseCode != "" ? JSON.stringify(Object.assign(submission, {responseCode: responseCode})) : JSON.stringify(submission); + const command = new PutObjectCommand({ Bucket: S3_BUCKET_NAME, - Key: `${S3_BASE_NAME}/${submissionKey}.json`, - Body: JSON.stringify(submission), + Key: key, + Body: body, }); try { @@ -73,4 +77,7 @@ export async function recordJoinFormSubmissionToS3(submission: JoinFormValues) { recordJoinFormSubmissionToCSV(submission); throw err; } + + // Return the key later so we can update it. + return key; }