Skip to content

Commit b9d1de3

Browse files
Update validaiton logic
Signed-off-by: Andy Kwok <[email protected]>
1 parent dfc224e commit b9d1de3

File tree

2 files changed

+12
-100
lines changed

2 files changed

+12
-100
lines changed

solutions/aws-neptune-analytics/app/api/node/route.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function validateId(id: string | null) {
5353
* Validate request body contains required id field
5454
*/
5555
function validateBody(body: any) {
56-
if (!body || !body.id) {
56+
if (!body?.id) {
5757
return NextResponse.json(
5858
{ error: 'Request body with id is required' },
5959
{ status: 400 }
@@ -67,8 +67,8 @@ export async function GET(request: Request) {
6767
const { searchParams } = new URL(request.url)
6868
const id = searchParams.get('id')
6969

70-
const validation = validateId(id)
71-
if (validation) return validation
70+
const error = validateId(id)
71+
if (error) return error
7272

7373
const result = await executeQuery(
7474
'MATCH(n) WHERE id(n) = $NODE_ID RETURN n',
@@ -85,8 +85,8 @@ export async function POST(request: Request) {
8585
try {
8686
const body = await request.json()
8787

88-
const validation = validateBody(body)
89-
if (validation) return validation
88+
const error = validateBody(body)
89+
if (error) return error
9090

9191
const result = await executeQuery(
9292
'CREATE (n {`~id`: $NODE_ID}) SET n += $PROPERTIES RETURN n',
@@ -103,8 +103,8 @@ export async function PUT(request: Request) {
103103
try {
104104
const body = await request.json()
105105

106-
const validation = validateBody(body)
107-
if (validation) return validation
106+
const error = validateBody(body)
107+
if (error) return error
108108

109109
const result = await executeQuery(
110110
'MATCH(n {`~id`: $NODE_ID}) SET n = $PROPERTIES RETURN n',
@@ -122,8 +122,8 @@ export async function DELETE(request: Request) {
122122
const { searchParams } = new URL(request.url)
123123
const id = searchParams.get('id')
124124

125-
const validation = validateId(id)
126-
if (validation) return validation
125+
const error = validateId(id)
126+
if (error) return error
127127

128128
const result = await executeQuery(
129129
'MATCH (n) WHERE id(n) = $NODE_ID DETACH DELETE n',

solutions/aws-neptune-analytics/pnpm-lock.yaml

Lines changed: 3 additions & 91 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)