-
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.
Scaffolded all API routes, worked on DELETE requests, added nodemon/uuid
- Loading branch information
1 parent
8f13660
commit 841da5b
Showing
18 changed files
with
439 additions
and
19 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 |
---|---|---|
|
@@ -6,8 +6,8 @@ | |
"author": "Christopher Aitken <[email protected]>", | ||
"license": "AGPL-3.0-only", | ||
"scripts": { | ||
"start:prod": "esbuild --format=esm src/**/*.ts --outdir=dist && node --env-file=.env.production dist/app.js", | ||
"start:staging": "esbuild --format=esm src/**/*.ts --platform=node --outdir=dist && node --env-file=.env.staging dist/app.js", | ||
"start:prod": "esbuild --format=esm src/**/*.ts --outdir=dist && nodemon --env-file=.env.production dist/app.js", | ||
"start:staging": "esbuild --format=esm src/**/*.ts --outdir=dist && nodemon --env-file=.env.staging dist/app.js", | ||
"build:prod": "esbuild src/*.ts --bundle --platform=node --outdir=dist --external:@aws-sdk && cd dist && zip -r lambda.zip * > /dev/null && aws --profile equalify lambda update-function-code --function-name equalify-api --zip-file \"fileb://lambda.zip\" > /dev/null && rm -rf lambda.zip", | ||
"build:staging": "esbuild src/*.ts --bundle --platform=node --outdir=dist --external:@aws-sdk && cd dist && zip -r lambda.zip * > /dev/null && aws --profile equalify lambda update-function-code --function-name equalify-api-staging --zip-file \"fileb://lambda.zip\" > /dev/null && rm -rf lambda.zip" | ||
}, | ||
|
@@ -21,14 +21,25 @@ | |
"esbuild": "^0.20.1", | ||
"fastify": "^4.26.2", | ||
"graphql": "^16.8.1", | ||
"nodemon": "^3.1.0", | ||
"openai": "^4.36.0", | ||
"pg": "^8.11.5", | ||
"postgraphile": "^4.13.0", | ||
"postgraphile-plugin-connection-filter": "^2.3.0", | ||
"serverless-postgres": "^2.1.0", | ||
"string-strip-html": "^13.4.8" | ||
"string-strip-html": "^13.4.8", | ||
"uuid": "^9.0.1" | ||
}, | ||
"resolutions": { | ||
"graphql": "16.x" | ||
}, | ||
"nodemonConfig": { | ||
"ext": "ts,js,json", | ||
"watch": [ | ||
"src/" | ||
], | ||
"events": { | ||
"restart": "esbuild --format=esm src/**/*.ts --outdir=dist" | ||
} | ||
} | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { jwtClaims } from '../app.js'; | ||
import { pgClient, validateUuid } from '../utils/index.js'; | ||
|
||
export const addProperties = async ({ request, reply }) => { | ||
await pgClient.connect(); | ||
await pgClient.clean(); | ||
return; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { jwtClaims } from '../app.js'; | ||
import { pgClient, validateUuid } from '../utils/index.js'; | ||
|
||
export const addReports = async ({ request, reply }) => { | ||
await pgClient.connect(); | ||
await pgClient.clean(); | ||
return; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { jwtClaims } from '../app.js'; | ||
import { pgClient, validateUuid } from '../utils/index.js'; | ||
|
||
export const addResults = async ({ request, reply }) => { | ||
await pgClient.connect(); | ||
await pgClient.clean(); | ||
return; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { jwtClaims } from '../app.js'; | ||
import { pgClient, validateUuid } from '../utils/index.js'; | ||
|
||
export const addScans = async ({ request, reply }) => { | ||
await pgClient.connect(); | ||
await pgClient.clean(); | ||
return; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { jwtClaims } from '../app.js'; | ||
import { pgClient, validateUuid } from '../utils/index.js'; | ||
|
||
export const deleteProperties = async ({ request, reply }) => { | ||
if (!request.query.propertyId) { | ||
return { | ||
status: 'error', | ||
message: 'Property ID is required.', | ||
} | ||
} | ||
else if (!validateUuid(request.query.propertyId)) { | ||
return { | ||
status: 'error', | ||
message: 'Property ID is not a valid UUID.', | ||
} | ||
} | ||
|
||
await pgClient.connect(); | ||
const deletedIds = (await pgClient.query(` | ||
DELETE FROM "properties" WHERE "id"=$1 AND "user_id"=$2 RETURNING "id" | ||
`, [request.query.propertyId, jwtClaims.sub])).rows.map(obj => obj.id); | ||
await pgClient.clean(); | ||
|
||
if (deletedIds.length === 0) { | ||
return { | ||
status: 'error', | ||
message: 'propertyId not found, no properties deleted', | ||
} | ||
} | ||
else { | ||
return { | ||
status: 'success', | ||
message: 'Property deletion successful', | ||
result: deletedIds, | ||
}; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { jwtClaims } from '../app.js'; | ||
import { pgClient, validateUuid } from '../utils/index.js'; | ||
|
||
export const deleteReports = async ({ request, reply }) => { | ||
if (!request.query.reportId) { | ||
return { | ||
status: 'error', | ||
message: 'Property ID is required.', | ||
} | ||
} | ||
else if (!validateUuid(request.query.reportId)) { | ||
return { | ||
status: 'error', | ||
message: 'Property ID is not a valid UUID.', | ||
} | ||
} | ||
|
||
await pgClient.connect(); | ||
const deletedIds = (await pgClient.query(` | ||
DELETE FROM "reports" WHERE "id"=$1 AND "user_id"=$2 RETURNING "id" | ||
`, [request.query.reportId, jwtClaims.sub])).rows.map(obj => obj.id); | ||
await pgClient.clean(); | ||
|
||
if (deletedIds.length === 0) { | ||
return { | ||
status: 'error', | ||
message: 'reportId not found, no reports deleted.', | ||
} | ||
} | ||
else { | ||
return { | ||
status: 'success', | ||
message: 'Property deletion successful', | ||
result: deletedIds, | ||
}; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { jwtClaims } from '../app.js'; | ||
import { pgClient } from '../utils/index.js'; | ||
|
||
export const getProperties = async ({ request, reply }) => { | ||
await pgClient.connect(); | ||
await pgClient.clean(); | ||
return; | ||
} |
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,12 +1,46 @@ | ||
import { jwtClaims } from '../app.js'; | ||
import { graphqlQuery, pgClient } from '../utils/index.js'; | ||
import { graphqlQuery } from '../utils/index.js'; | ||
|
||
export const getResults = async ({ request, reply }) => { | ||
await pgClient.connect(); | ||
const { rows } = await pgClient.query(`SELECT * FROM "users"`); | ||
console.log(rows); | ||
await pgClient.clean(); | ||
console.log(jwtClaims); | ||
/* | ||
Ability to filter by propertyIds, urlIds, nodeIds, nodeUpdateIds, messageIds, and tagIds | ||
Messages, Tags, Properties, Pages are sorted by properties related to the most nodes w/ nodeEqualified set to false (most to least) | ||
*/ | ||
const response = await graphqlQuery({ query: `{allUsers {nodes {name}}}` }); | ||
return { response }; | ||
/* | ||
// Return should follow the Equalify Schema: | ||
{ | ||
urls: [ | ||
{ | ||
urlId: 'uuid', | ||
url: 'string', | ||
}, | ||
], | ||
messages: [ | ||
{ | ||
message: 'string', | ||
relatedTagIds: ['uuid'], | ||
relatedNodeIds: ['uuid'], | ||
type: 'enum (pass/error/violation)', | ||
}, | ||
], | ||
tags: [ | ||
{ | ||
tagId: 'uuid', | ||
tag: 'string', | ||
}, | ||
], | ||
nodes: [ | ||
{ | ||
nodeId: 'uuid', | ||
html: 'string', | ||
targets: ['string'], // OPTIONAL | ||
relatedUrlId: 'uuid', | ||
equalified: 'boolean', | ||
} | ||
] | ||
} | ||
*/ | ||
return { | ||
response | ||
}; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { jwtClaims } from '../app.js'; | ||
import { pgClient } from '../utils/index.js'; | ||
|
||
export const getScans = async ({ request, reply }) => { | ||
await pgClient.connect(); | ||
await pgClient.clean(); | ||
return; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { jwtClaims } from '../app.js'; | ||
import { pgClient } from '../utils/index.js'; | ||
|
||
export const getUpdates = async ({ request, reply }) => { | ||
await pgClient.connect(); | ||
await pgClient.clean(); | ||
return; | ||
} |
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,4 +1,15 @@ | ||
export * from './addProperties.js' | ||
export * from './addReports.js' | ||
export * from './addResults.js' | ||
export * from './addScans.js' | ||
export * from './deleteProperties.js' | ||
export * from './deleteReports.js' | ||
export * from './getProperties.js' | ||
export * from './getReports.js' | ||
export * from './getResults.js' | ||
export * from './getScans.js' | ||
export * from './getUpdates.js' | ||
export * from './graphql.js' | ||
export * from './getReports.js' | ||
export * from './help.js' | ||
export * from './help.js' | ||
export * from './updateProperties.js' | ||
export * from './updateReports.js' |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { jwtClaims } from '../app.js'; | ||
import { pgClient, validateUuid } from '../utils/index.js'; | ||
|
||
export const updateProperties = async ({ request, reply }) => { | ||
await pgClient.connect(); | ||
await pgClient.clean(); | ||
return; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { jwtClaims } from '../app.js'; | ||
import { pgClient, validateUuid } from '../utils/index.js'; | ||
|
||
export const updateReports = async ({ request, reply }) => { | ||
await pgClient.connect(); | ||
await pgClient.clean(); | ||
return; | ||
} |
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,3 +1,4 @@ | ||
export * from './graphqlQuery.js' | ||
export * from './pgClient.js' | ||
export * from './openai.js' | ||
export * from './openai.js' | ||
export * from './validateUuid.js' |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { validate } from 'uuid'; | ||
|
||
export const validateUuid = (value) => { | ||
if (!value.includes('-')) { | ||
value = value.substr(0, 8) + '-' + value.substr(8, 4) + '-' + value.substr(12, 4) + '-' + value.substr(16, 4) + '-' + value.substr(20, 12) | ||
} | ||
return validate(value); | ||
} |
Oops, something went wrong.