Skip to content

Commit

Permalink
Scaffolded /get/pages endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
azdak committed Oct 18, 2024
1 parent 3fd15c3 commit a737827
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/app.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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 }));
Expand Down Expand Up @@ -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
})
33 changes: 33 additions & 0 deletions src/routes/getPages.ts
Original file line number Diff line number Diff line change
@@ -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,
};
}
1 change: 1 addition & 0 deletions src/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

0 comments on commit a737827

Please sign in to comment.