-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ft(update trip request): user should be able update trip request
- squash commit [finishes #168781705]
- Loading branch information
1 parent
2cde6f6
commit 66706f4
Showing
16 changed files
with
242 additions
and
215 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 |
---|---|---|
@@ -1,4 +0,0 @@ | ||
import models from '../database/models'; | ||
|
||
export default class CommentsController { | ||
} | ||
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
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,12 @@ | ||
import models from '../database/models'; | ||
|
||
|
||
const findOneRequest = properties => { | ||
const request = models.requests.findOne({ | ||
where: properties, | ||
raw: true | ||
}); | ||
return request; | ||
}; | ||
|
||
export default { findOneRequest }; |
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 |
---|---|---|
@@ -1,38 +1,57 @@ | ||
/* eslint-disable no-irregular-whitespace */ | ||
import responseError from '../utils/responseError'; | ||
import string from '../utils/stringsUtil'; | ||
import models from '../database/models'; | ||
|
||
const { requests } = models; | ||
/* eslint-disable no-irregular-whitespace */ | ||
import responseError from '../utils/responseError'; | ||
import string from '../utils/stringsUtil'; | ||
import models from '../database/models'; | ||
import requestHelper from '../helpers/requestHelper'; | ||
|
||
const request = { | ||
async selectPending(req, res, next) { | ||
const userId = req.user.payload.id; | ||
const id = parseInt(req.params.id, 10); | ||
const requester = await requests.findOne({ | ||
where: { id, userId }, | ||
raw: true | ||
}); | ||
if (requester.statusId !== 1) { | ||
return responseError(res, 400, string.users.error.NO_PENDED_REQUEST); | ||
const { requests } = models; | ||
const { findOneRequest } = requestHelper; | ||
|
||
const request = { | ||
async selectPending(req, res, next) { | ||
const id = parseInt(req.params.id, 10); | ||
const reques = await findOneRequest({ id }); | ||
|
||
if (reques.statusId !== 1) { | ||
return responseError(res, 400, string.users.error.NO_PENDED_REQUEST); | ||
} | ||
next(); | ||
}, | ||
|
||
async requestOwner(req, res, next) { | ||
const { id } = req.params; | ||
const request = await requests.findOne({ | ||
where: { id }, | ||
}); | ||
if (!request) { | ||
return responseError(res, 400, 'string.request.error.EDIT_YOUR_REQUEST'); | ||
async requestOwner(req, res, next) { | ||
const { id } = req.params; | ||
const request = await findOneRequest({ id }); | ||
if (!request) { | ||
return responseError(res, 400, string.request.error.NO_REQUEST); | ||
} | ||
if (request.userId !== req.user.payload.id) { | ||
return responseError(res, 400, string.request.error.EDIT_YOUR_REQUEST); | ||
if (request.userId !== req.user.payload.id) { | ||
return responseError(res, 400, string.request.error.EDIT_YOUR_REQUEST); | ||
} | ||
req.request = request; | ||
req.request = request; | ||
next(); | ||
}, | ||
|
||
async validateBody(req, res, next) { | ||
const { id } = req.params; | ||
const destination = req.body; | ||
await requests.findOne({ | ||
where: { id }, | ||
}); | ||
const destinationArray = destination.destinations; | ||
destinationArray.forEach(async element => { | ||
await models.destinations.findOne({ | ||
where: { | ||
requestId: id, id: element.id | ||
}, | ||
}).then(destination => { | ||
if (!destination) { | ||
return responseError(res, 403, `Destination of id ${element.id} does not belong to this request`); | ||
} | ||
}); | ||
}); | ||
next(); | ||
} | ||
}; | ||
|
||
export default request; | ||
export default request; |
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
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
Oops, something went wrong.