-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7fde0fd
commit f55f44a
Showing
1 changed file
with
28 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,34 @@ | ||
import { jwtClaims } from '#src/app'; | ||
import { db } from '#src/utils'; | ||
|
||
export const getCharts = async ({ request, reply }) => { | ||
await db.connect(); | ||
const report = (await db.query(`SELECT "id", "name", "filters" FROM "reports" WHERE "id" = $1`, [request.query.reportId])).rows?.[0]?.filters; | ||
// const nodeIds = (await db.query(`SELECT "id" FROM "enodes" WHERE "user_id"=$1`, [jwtClaims.sub])).rows; | ||
const report = (await db.query(`SELECT "id", "name", "filters" FROM "reports" WHERE "id" = $1`, [request.query.reportId])).rows?.[0]; | ||
|
||
const types = ['properties', 'urls', 'messages', 'nodes', 'tags']; | ||
const filters = Object.fromEntries(types.map(obj => [obj, []])); | ||
for (const type of types) { | ||
filters[type].push(...report.filters.filter(obj => obj.type === type).map(obj => obj.value)); | ||
} | ||
|
||
const urlIds = (await db.query({ | ||
text: `SELECT "id" FROM "urls" WHERE "id" = ANY($1::uuid[]) OR "property_id" = ANY($2::uuid[])`, | ||
values: [filters.urls, filters.properties], | ||
})).rows.map(obj => obj.id); | ||
|
||
const enodeIds = (await db.query({ | ||
text: `SELECT id FROM enodes WHERE url_id = ANY($1::uuid[])`, | ||
values: [urlIds], | ||
})).rows.map(obj => obj.id); | ||
|
||
const enodeUpdates = (await db.query({ | ||
text: `SELECT created_at as date, equalified FROM enode_updates WHERE enode_id = ANY($1::uuid[]) ORDER BY created_at desc`, | ||
values: [enodeIds], | ||
})).rows; | ||
|
||
await db.clean(); | ||
return { report }; | ||
return { | ||
status: 'success', | ||
result: enodeUpdates, | ||
total: enodeUpdates.length, | ||
}; | ||
} |