-
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.
Added createdAt/updatedAt to properties, worked on addScans/addResults
- Loading branch information
1 parent
816713d
commit 2a2e0a7
Showing
3 changed files
with
30 additions
and
5 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,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), | ||
}; | ||
} |
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,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), | ||
}; | ||
} |
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