Skip to content

Commit c8949d2

Browse files
Removed "Discovery Process", now passing correct user ID in processScans
1 parent e110a69 commit c8949d2

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

src/routes/addScans.ts

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ export const addScans = async ({ request, reply }) => {
3131
const discoveryDict = {
3232
single: 'url',
3333
sitemap: 'sitemapurl',
34-
discovery_process: 'sitemapurl',
3534
}
3635

3736
const scanResponse = await (await fetch(`https://scan.equalify.app/generate/${discoveryDict?.[propertyDiscovery] ?? 'url'}`, {

src/scheduled/processScans.ts

+11-12
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import { jwtClaims } from '#src/app';
21
import { db } from '#src/utils';
32

43
export const processScans = async () => {
54
// This route is called once every minute by Amazon EventBridge Scheduler
65
await db.connect();
7-
const scans = (await db.query(`SELECT "id", "job_id", "property_id" FROM "scans" WHERE "processing"=TRUE ORDER BY "created_at" DESC`)).rows;
6+
const scans = (await db.query(`SELECT "id", "job_id", "property_id", "user_id" FROM "scans" WHERE "processing"=TRUE ORDER BY "created_at" DESC`)).rows;
87
await Promise.allSettled(scans.map(scan => new Promise(async (res) => {
98
try {
109
const { result, status } = await (await fetch(`https://scan.equalify.app/results/${scan.job_id}`)).json();
@@ -38,60 +37,60 @@ const scanProcessor = async ({ result, scan }) => {
3837
row.id =
3938
(await db.query({
4039
text: `SELECT "id" FROM "urls" WHERE "user_id"=$1 AND "url"=$2 AND "property_id"=$3`,
41-
values: [jwtClaims.sub, row.url, scan.property_id],
40+
values: [scan.user_id, row.url, scan.property_id],
4241
})).rows?.[0]?.id
4342
??
4443
(await db.query({
4544
text: `INSERT INTO "urls" ("user_id", "url", "property_id") VALUES ($1, $2, $3) RETURNING "id"`,
46-
values: [jwtClaims.sub, row.url, scan.property_id]
45+
values: [scan.user_id, row.url, scan.property_id]
4746
})).rows?.[0]?.id;
4847
}
4948
for (const row of result.nodes) {
5049
row.id =
5150
(await db.query({
5251
text: `SELECT "id" FROM "enodes" WHERE "user_id"=$1 AND "html"=$2 AND "targets"=$3 AND "url_id"=$4`,
53-
values: [jwtClaims.sub, row.html, JSON.stringify(row.targets), row.url_id],
52+
values: [scan.user_id, row.html, JSON.stringify(row.targets), row.url_id],
5453
})).rows?.[0]?.id
5554
??
5655
(await db.query({
5756
text: `INSERT INTO "enodes" ("user_id", "html", "targets", "url_id") VALUES ($1, $2, $3, $4) RETURNING "id"`,
58-
values: [jwtClaims.sub, row.html, JSON.stringify(row.targets), result.urls.find(obj => obj.urlId === row.relatedUrlId).id],
57+
values: [scan.user_id, row.html, JSON.stringify(row.targets), result.urls.find(obj => obj.urlId === row.relatedUrlId).id],
5958
})).rows?.[0]?.id;
6059
}
6160
for (const row of result.tags) {
6261
row.id =
6362
(await db.query({
6463
text: `SELECT "id" FROM "tags" WHERE "user_id"=$1 AND "tag"=$2`,
65-
values: [jwtClaims.sub, row.tag],
64+
values: [scan.user_id, row.tag],
6665
})).rows?.[0]?.id
6766
??
6867
(await db.query({
6968
text: `INSERT INTO "tags" ("user_id", "tag") VALUES ($1, $2) RETURNING "id"`,
70-
values: [jwtClaims.sub, row.tag],
69+
values: [scan.user_id, row.tag],
7170
})).rows?.[0]?.id;
7271
}
7372
for (const row of result.messages) {
7473
row.id =
7574
(await db.query({
7675
text: `SELECT "id" FROM "messages" WHERE "user_id"=$1 AND "message"=$2 AND "type"=$3`,
77-
values: [jwtClaims.sub, row.message, row.type],
76+
values: [scan.user_id, row.message, row.type],
7877
})).rows?.[0]?.id
7978
??
8079
(await db.query({
8180
text: `INSERT INTO "messages" ("user_id", "message", "type") VALUES ($1, $2, $3) RETURNING "id"`,
82-
values: [jwtClaims.sub, row.message, row.type],
81+
values: [scan.user_id, row.message, row.type],
8382
})).rows?.[0]?.id;
8483

8584
for (const relatedNodeId of row.relatedNodeIds) {
8685
await db.query({
8786
text: `INSERT INTO "message_nodes" ("user_id", "message_id", "enode_id") VALUES ($1, $2, $3)`,
88-
values: [jwtClaims.sub, row.id, result.nodes.find(obj => obj.nodeId === relatedNodeId).id]
87+
values: [scan.user_id, row.id, result.nodes.find(obj => obj.nodeId === relatedNodeId).id]
8988
})
9089
}
9190
for (const relatedTagId of row.relatedTagIds) {
9291
await db.query({
9392
text: `INSERT INTO "message_tags" ("user_id", "message_id", "tag_id") VALUES ($1, $2, $3)`,
94-
values: [jwtClaims.sub, row.id, result.tags.find(obj => obj.tagId === relatedTagId).id]
93+
values: [scan.user_id, row.id, result.tags.find(obj => obj.tagId === relatedTagId).id]
9594
})
9695
}
9796
}

0 commit comments

Comments
 (0)