Skip to content

Commit

Permalink
wrapping up addScanByProperty
Browse files Browse the repository at this point in the history
  • Loading branch information
azdak committed Dec 18, 2024
1 parent c065b71 commit 759e06a
Showing 1 changed file with 39 additions and 7 deletions.
46 changes: 39 additions & 7 deletions src/routes/addScansByProperty.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { jwtClaims } from "#src/app";
import { db, graphql, isStaging, validateUrl, validateUuid } from "#src/utils";
import { LambdaClient, InvokeCommand } from "@aws-sdk/client-lambda";
const lambda = new LambdaClient();

export const addScansByProperty = async ({ request, reply }) => {
if (!request.body.propertyId) {
Expand Down Expand Up @@ -33,11 +31,45 @@ export const addScansByProperty = async ({ request, reply }) => {
},
})).urls;

//console.log(urls);
//await db.clean();
// Below copied from addScansByPage, this should be consolidated/abstracted at some point
// send pages to scan
const jobIds = await (
await fetch(
`https://scan${isStaging ? "-dev" : ""}.equalify.app/generate/urls`, // multi-url endpoint
{
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
urls: urls,
userId: jwtClaims.sub,
}),
}
)
).json();

// save response in scan table
let addedJobsIds = [];
for (const { jobId, url } of jobIds?.jobs) {
const urlId =
(
await db.query({
text: `SELECT "id" FROM "urls" WHERE "user_id"=$1 AND "url"=$2`,
values: [jwtClaims.sub, url],
})
).rows?.[0]?.id
const scanJobId = (
await db.query({
text: `INSERT INTO "scans" ("user_id", "url_id", "job_id", "processing") VALUES ($1, $2, $3, $4) RETURNING "job_id"`,
values: [jwtClaims.sub, urlId, parseInt(jobId), "TRUE"],
})
).rows[0];
addedJobsIds.push(scanJobId);
}
return {
status: "success",
message: urls,
};
status:"success",
scansAdded:{
jobIds: addedJobsIds
}
}

};

0 comments on commit 759e06a

Please sign in to comment.