From a7378270a380a5770edee46d35ec95458cef97ae Mon Sep 17 00:00:00 2001 From: azdak Date: Fri, 18 Oct 2024 14:22:11 -0500 Subject: [PATCH] Scaffolded /get/pages endpoint --- src/app.ts | 5 +++-- src/routes/getPages.ts | 33 +++++++++++++++++++++++++++++++++ src/routes/index.ts | 1 + 3 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 src/routes/getPages.ts diff --git a/src/app.ts b/src/app.ts index 8caaacb..0acbb96 100644 --- a/src/app.ts +++ b/src/app.ts @@ -1,5 +1,5 @@ import Fastify from 'fastify'; -import { addProperties, addReports, addResults, addScans, deleteProperties, deleteReports, deleteUser, getApikey, getCharts, getFilters, getProperties, getReports, getResultsAll, getResultsMessages, getResultsSchema, getResultsTags, getResultsUrls, getScans, getUpdates, help, trackUser, updateProperties, updateReports } from '#src/routes'; +import { addProperties, addReports, addResults, addScans, deleteProperties, deleteReports, deleteUser, getApikey, getCharts, getFilters, getProperties, getReports, getResultsAll, getResultsMessages, getResultsSchema, getResultsTags, getResultsUrls, getScans, getUpdates, help, trackUser, updateProperties, updateReports, getPages } from '#src/routes'; import { CognitoJwtVerifier } from 'aws-jwt-verify'; import { db } from './utils'; import { getScan } from './routes/getScan'; @@ -39,6 +39,7 @@ fastify.get('/get/results/messages', {}, async (request, reply) => getResultsMes fastify.get('/get/results/tags', {}, async (request, reply) => getResultsTags({ request, reply })); fastify.get('/get/results/urls', {}, async (request, reply) => getResultsUrls({ request, reply })); fastify.get('/get/properties', {}, async (request, reply) => getProperties({ request, reply })); +fastify.get('/get/pages', {}, async (request, reply) => getPages({ request, reply })); fastify.get('/get/updates', {}, async (request, reply) => getUpdates({ request, reply })); fastify.get('/get/scans', {}, async (request, reply) => getScans({ request, reply })); fastify.get('/get/scan', {}, async (request, reply) => getScan({ request, reply })); @@ -67,6 +68,6 @@ fastify.post('/help', {}, async (request, reply) => help({ request, reply })); fastify.post('/track/user', {}, async (request, reply) => trackUser({ request, reply })); fastify.listen({ port: 3000 }, (err) => { - console.log(`Server listening on ${fastify.server.address().port}`) + console.log(`Server listening on ${fastify.server.address()}`) if (err) throw err }) \ No newline at end of file diff --git a/src/routes/getPages.ts b/src/routes/getPages.ts new file mode 100644 index 0000000..7c92dd6 --- /dev/null +++ b/src/routes/getPages.ts @@ -0,0 +1,33 @@ +import { graphql } from '#src/utils'; + +export const getPages = async ({ request, reply }) => { + const response = await graphql({ + request, + query: ` + query($limit: Int, $offset: Int){ + urls(limit: $limit, offset: $offset, order_by: {updated_at: desc}) { + url + property { + id + name + } + scans { + updated_at + } + } + } + `, + variables: { + limit: parseInt(request.query.limit ?? 100), + offset: parseInt(request.query.offset ?? 0), + }, + }); + + return { + status: 'success', + result: response?.properties?.nodes?.map(obj => ({ + ...obj, + })), + total: response?.properties?.totalCount?.count, + }; +} \ No newline at end of file diff --git a/src/routes/index.ts b/src/routes/index.ts index b5de00c..7486121 100644 --- a/src/routes/index.ts +++ b/src/routes/index.ts @@ -20,5 +20,6 @@ export * from './webhookMonitorUpdate' export * from './getFilters' export * from './getCharts' export * from './getApikey' +export * from './getPages' export * from './deleteUser' export * from './trackUser' \ No newline at end of file