Skip to content

Commit

Permalink
Reorders validation to check existence first
Browse files Browse the repository at this point in the history
  • Loading branch information
abtestingalpha committed Sep 19, 2024
1 parent 4ed82b0 commit 4200b0f
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 37 deletions.
12 changes: 6 additions & 6 deletions packages/rest-api/src/routes/bridgeRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ router.get(
checksumAddresses(['fromToken', 'toToken']),
[
check('fromChain')
.exists()
.withMessage('fromChain is required')
.isNumeric()
.custom((value) => CHAINS_ARRAY.some((c) => c.id === Number(value)))
.withMessage('Unsupported fromChain')
.exists()
.withMessage('fromChain is required'),
.withMessage('Unsupported fromChain'),
check('toChain')
.exists()
.withMessage('toChain is required')
.isNumeric()
.custom((value) => CHAINS_ARRAY.some((c) => c.id === Number(value)))
.withMessage('Unsupported toChain')
.exists()
.withMessage('toChain is required'),
.withMessage('Unsupported toChain'),
check('fromToken')
.exists()
.withMessage('fromToken is required')
Expand Down
14 changes: 7 additions & 7 deletions packages/rest-api/src/routes/bridgeTxInfoRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ router.get(
checksumAddresses(['fromToken', 'toToken']),
[
check('fromChain')
.exists()
.withMessage('fromChain is required')
.isNumeric()
.custom((value) => CHAINS_ARRAY.some((c) => c.id === Number(value)))
.withMessage('Unsupported fromChain')
.exists()
.withMessage('fromChain is required'),
.withMessage('Unsupported fromChain'),
check('toChain')
.exists()
.withMessage('toChain is required')
.isNumeric()
.custom((value) => CHAINS_ARRAY.some((c) => c.id === Number(value)))
.withMessage('Unsupported toChain')
.exists()
.withMessage('toChain is required'),
.withMessage('Unsupported toChain'),
check('fromToken')
.exists()
.withMessage('fromToken is required')
Expand All @@ -45,7 +45,7 @@ router.get(
isTokenSupportedOnChain(value, req.query.toChain as string)
)
.withMessage('Token not supported on specified chain'),
check('amount').isNumeric().exists().withMessage('amount is required'),
check('amount').exists().withMessage('amount is required').isNumeric(),
check('destAddress')
.exists()
.withMessage('destAddress is required')
Expand Down
16 changes: 8 additions & 8 deletions packages/rest-api/src/routes/getBridgeTxStatusRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,24 @@ router.get(
'/',
[
check('destChainId')
.exists()
.withMessage('destChainId is required')
.isNumeric()
.custom((value) => CHAINS_ARRAY.some((c) => c.id === Number(value)))
.withMessage('Unsupported destChainId')
.exists()
.withMessage('destChainId is required'),
.withMessage('Unsupported destChainId'),
check('bridgeModule')
.exists()
.withMessage('bridgeModule is required')
.isString()
.isIn(VALID_BRIDGE_MODULES)
.withMessage(
'Invalid bridge module. Must be one of: ' +
VALID_BRIDGE_MODULES.join(', ')
)
.exists()
.withMessage('bridgeModule is required'),
),
check('synapseTxId')
.isString()
.exists()
.withMessage('synapseTxId is required'),
.withMessage('synapseTxId is required')
.isString(),
],
showFirstValidationError,
getBridgeTxStatusController
Expand Down
6 changes: 3 additions & 3 deletions packages/rest-api/src/routes/getDestinationTxRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ router.get(
'/',
[
check('originChainId')
.isNumeric()
.exists()
.withMessage('originChainId is required'),
check('txHash').isString().exists().withMessage('txHash is required'),
.withMessage('originChainId is required')
.isNumeric(),
check('txHash').exists().withMessage('txHash is required').isString(),
],
showFirstValidationError,
getDestinationTxController
Expand Down
12 changes: 6 additions & 6 deletions packages/rest-api/src/routes/getSynapseTxIdRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ router.get(
'/',
[
check('originChainId')
.isNumeric()
.exists()
.withMessage('originChainId is required'),
.withMessage('originChainId is required')
.isNumeric(),
check('bridgeModule')
.exists()
.withMessage('bridgeModule is required')
.isString()
.isIn(VALID_BRIDGE_MODULES)
.withMessage(
'Invalid bridge module. Must be one of: ' +
VALID_BRIDGE_MODULES.join(', ')
)
.exists()
.withMessage('bridgeModule is required'),
check('txHash').isString().exists().withMessage('txHash is required'),
),
check('txHash').exists().withMessage('txHash is required').isString(),
],
showFirstValidationError,
getSynapseTxIdController
Expand Down
8 changes: 4 additions & 4 deletions packages/rest-api/src/routes/swapRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ router.get(
checksumAddresses(['fromToken', 'toToken']),
[
check('chain')
.exists()
.withMessage('chain is required')
.isNumeric()
.custom((value) => CHAINS_ARRAY.some((c) => c.id === Number(value)))
.withMessage('Unsupported chain')
.exists()
.withMessage('chain is required'),
.withMessage('Unsupported chain'),
check('fromToken')
.exists()
.withMessage('fromToken is required')
Expand All @@ -38,7 +38,7 @@ router.get(
isTokenSupportedOnChain(value, req.query.chain as string)
)
.withMessage('Token not supported on specified chain'),
check('amount').isNumeric().exists().withMessage('amount is required'),
check('amount').exists().withMessage('amount is required').isNumeric(),
],
showFirstValidationError,
swapController
Expand Down
6 changes: 3 additions & 3 deletions packages/rest-api/src/routes/swapTxInfoRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ router.get(
checksumAddresses(['fromToken', 'toToken']),
[
check('chain')
.exists()
.withMessage('chain is required')
.isNumeric()
.custom((value) => CHAINS_ARRAY.some((c) => c.id === Number(value)))
.withMessage('Unsupported chain')
.exists()
.withMessage('chain is required'),
.withMessage('Unsupported chain'),
check('fromToken')
.exists()
.withMessage('fromToken is required')
Expand Down

0 comments on commit 4200b0f

Please sign in to comment.