From 0a835eb025648cb3c086f11c38ae4198f3740ea5 Mon Sep 17 00:00:00 2001 From: Jun-te kim Date: Wed, 20 Aug 2025 11:56:52 +0000 Subject: [PATCH] upload --- .../[propertyId]/documents/UploadModal.tsx | 25 ++++++++++++++++++- src/app/utils/sqs.ts | 6 ++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/app/portfolio/[slug]/building-passport/[propertyId]/documents/UploadModal.tsx b/src/app/portfolio/[slug]/building-passport/[propertyId]/documents/UploadModal.tsx index c44e654..e7dd19a 100644 --- a/src/app/portfolio/[slug]/building-passport/[propertyId]/documents/UploadModal.tsx +++ b/src/app/portfolio/[slug]/building-passport/[propertyId]/documents/UploadModal.tsx @@ -41,6 +41,18 @@ async function generatePresignedUrls({ return res.json() as Promise<{ url: string }>; } +// fetch sqs quess and show it in logs for testing purposes +export async function fetchQueuesAndLog() { + try { + const res = await fetch("/db/surveyDB/api/show_all_sqs_available"); + if (!res.ok) throw new Error("Failed to fetch queues"); + const data = await res.json(); + console.log("✅ Available SQS queues:", data.queues); + } catch (err) { + console.error("❌ Error fetching queues:", err); + } +} + // Decide content-type from file extension function contentTypeFor(ext: string): string { const e = ext.toLowerCase(); @@ -128,7 +140,18 @@ export const UploadModal = ({ open, onClose, documentType, uprn }: UploadModalPr console.error("DB insert failed:", err); throw new Error("Failed to insert uploaded file record"); } - console.log("returned",res.json()); + const { id: db_id } = await res.json() + console.log("db_id is ", db_id); + // SQS list + console.log("Sending request to sqs") + + // enqueue only the id + await fetch("/db/surveyDB/api/send_to_extractor_loader", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ id: db_id }), // 👈 only id + }); + console.log(`sent request with ${db_id} check with aws sqs queue`); // Success — close the dialog and let parent refresh UI onClose(); } catch (err) { diff --git a/src/app/utils/sqs.ts b/src/app/utils/sqs.ts index c2fa0b0..dff14ae 100644 --- a/src/app/utils/sqs.ts +++ b/src/app/utils/sqs.ts @@ -9,7 +9,11 @@ import { // If you prefer explicit creds via env, keep your current config; // otherwise, this ctor will use the default credential chain (env vars, shared profile, role, etc.) const sqsClient = new SQSClient({ - region: process.env.AWS_REGION, + region: process.env.SQS_AWS_REGION, + credentials: { + accessKeyId: process.env.SQS_AWS_ACCESS_KEY_ID as string, + secretAccessKey: process.env.SQS_AWS_SECRET_ACCESS_KEY as string, + }, }); let cachedQueueUrl: string | null = null;