Skip to content

Commit eb962d8

Browse files
Copilotcubap
andcommitted
Refactor route files to use guard clauses instead of if/else
Co-authored-by: cubap <1119165+cubap@users.noreply.github.com>
1 parent fa5ba18 commit eb962d8

3 files changed

Lines changed: 9 additions & 12 deletions

File tree

routes/patchSet.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ import rest from '../rest.js'
88
router.route('/')
99
.patch(auth.checkJwt, controller.patchSet)
1010
.post(auth.checkJwt, (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)
15+
return
1816
}
17+
controller.patchSet(req, res, next)
1918
})
2019
.all((req, res, next) => {
2120
res.statusMessage = 'Improper request method for updating, please use PATCH to add new keys to this object.'

routes/patchUnset.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ import rest from '../rest.js'
88
router.route('/')
99
.patch(auth.checkJwt, controller.patchUnset)
1010
.post(auth.checkJwt, (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)
15+
return
1816
}
17+
controller.patchUnset(req, res, next)
1918
})
2019
.all((req, res, next) => {
2120
res.statusMessage = 'Improper request method for updating, please use PATCH to remove keys from this object.'

routes/patchUpdate.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@ import auth from '../auth/index.js'
99
router.route('/')
1010
.patch(auth.checkJwt, controller.patchUpdate)
1111
.post(auth.checkJwt, (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)
16+
return
1917
}
18+
controller.patchUpdate(req, res, next)
2019
})
2120
.all((req, res, next) => {
2221
res.statusMessage = 'Improper request method for updating, please use PATCH to alter existing keys on this object.'

0 commit comments

Comments
 (0)