Skip to content

Commit

Permalink
Added createdAt/updatedAt to properties, worked on addScans/addResults
Browse files Browse the repository at this point in the history
  • Loading branch information
heythisischris committed May 26, 2024
1 parent 816713d commit 2a2e0a7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
12 changes: 10 additions & 2 deletions src/routes/addResults.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import { jwtClaims } from '../app.js';
import { pgClient, validateUuid } from '../utils/index.js';
import { formatId, pgClient } from '../utils/index.js';

export const addResults = async ({ request, reply }) => {
await pgClient.connect();
const id = (await pgClient.query(`
INSERT INTO "results" ("user_id") VALUES ($1) RETURNING "id"
`, [jwtClaims.sub])).rows?.[0]?.id;
await pgClient.clean();
return;

return {
status: 'success',
message: 'Result added successfully',
result: formatId(id),
};
}
19 changes: 17 additions & 2 deletions src/routes/addScans.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
import { jwtClaims } from '../app.js';
import { pgClient, validateUuid } from '../utils/index.js';
import { formatId, pgClient } from '../utils/index.js';

export const addScans = async ({ request, reply }) => {
if (!(request.body.propertyIds || request.body.urlIds)) {
return {
status: 'error',
message: 'propertyIds or urlIds required.',
}
}

await pgClient.connect();
const id = (await pgClient.query(`
INSERT INTO "scans" ("user_id", "property_ids", "url_ids") VALUES ($1, $2, $3) RETURNING "id"
`, [jwtClaims.sub, request.body.propertyIds, request.body.urlIds])).rows?.[0]?.id;
await pgClient.clean();
return;

return {
status: 'success',
message: 'Scan added successfully',
result: formatId(id),
};
}
4 changes: 3 additions & 1 deletion src/routes/getProperties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { graphqlQuery } from '../utils/index.js';
export const getProperties = async ({ request, reply }) => {
const response = (await graphqlQuery({
query: `query($first: Int, $offset: Int){
properties(first: $first, offset: $offset,
properties(first: $first, offset: $offset, orderBy: UPDATED_AT_DESC,
${(request.query.propertyIds || request.query.propertyDiscovery || request.query.propertyUrls) ? `
filter: {
${request.query.propertyIds ? `id: {in: [
Expand All @@ -21,6 +21,8 @@ export const getProperties = async ({ request, reply }) => {
archived
discovery
processed
updatedAt
createdAt
}
totalCount
}
Expand Down

0 comments on commit 2a2e0a7

Please sign in to comment.