Skip to content

Commit e9532c3

Browse files
committed
Invert patch override check in POST routes
Simplify POST handlers for patch routes by inverting the rest.checkPatchOverrideSupport condition and moving the controller invocation out of the conditional in routes/patchSet.js, routes/patchUnset.js, and routes/patchUpdate.js. Behavior is preserved: if patch-override is not supported respond with 405, otherwise call the corresponding controller. This reduces nesting and improves readability.
1 parent ba758da commit e9532c3

3 files changed

Lines changed: 6 additions & 12 deletions

File tree

routes/patchSet.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,13 @@ import rest from '../rest.js'
88
router.route('/')
99
.patch(auth.checkJwt, rest.verifyJsonContentType, controller.patchSet)
1010
.post(auth.checkJwt, rest.verifyJsonContentType, (req, res, next) => {
11-
if (rest.checkPatchOverrideSupport(req, res)) {
12-
controller.patchSet(req, res, next)
13-
}
14-
else {
11+
if (!rest.checkPatchOverrideSupport(req, res)) {
1512
res.statusMessage = 'Improper request method for updating, please use PATCH to add new keys to this object.'
1613
res.status(405)
1714
next(res)
1815
return
1916
}
17+
controller.patchSet(req, res, next)
2018
})
2119
.all((req, res, next) => {
2220
res.statusMessage = 'Improper request method for updating, please use PATCH to add new keys to this object.'

routes/patchUnset.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,13 @@ import rest from '../rest.js'
88
router.route('/')
99
.patch(auth.checkJwt, rest.verifyJsonContentType, controller.patchUnset)
1010
.post(auth.checkJwt, rest.verifyJsonContentType, (req, res, next) => {
11-
if (rest.checkPatchOverrideSupport(req, res)) {
12-
controller.patchUnset(req, res, next)
13-
}
14-
else {
11+
if (!rest.checkPatchOverrideSupport(req, res)) {
1512
res.statusMessage = 'Improper request method for updating, please use PATCH to remove keys from this object.'
1613
res.status(405)
1714
next(res)
1815
return
1916
}
17+
controller.patchUnset(req, res, next)
2018
})
2119
.all((req, res, next) => {
2220
res.statusMessage = 'Improper request method for updating, please use PATCH to remove keys from this object.'

routes/patchUpdate.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,13 @@ import auth from '../auth/index.js'
99
router.route('/')
1010
.patch(auth.checkJwt, rest.verifyJsonContentType, controller.patchUpdate)
1111
.post(auth.checkJwt, rest.verifyJsonContentType, (req, res, next) => {
12-
if (rest.checkPatchOverrideSupport(req, res)) {
13-
controller.patchUpdate(req, res, next)
14-
}
15-
else {
12+
if (!rest.checkPatchOverrideSupport(req, res)) {
1613
res.statusMessage = 'Improper request method for updating, please use PATCH to alter the existing keys this object.'
1714
res.status(405)
1815
next(res)
1916
return
2017
}
18+
controller.patchUpdate(req, res, next)
2119
})
2220
.all((req, res, next) => {
2321
res.statusMessage = 'Improper request method for updating, please use PATCH to alter existing keys on this object.'

0 commit comments

Comments
 (0)