Skip to content

Commit

Permalink
Merge 37c82e5 into 2b57644
Browse files Browse the repository at this point in the history
  • Loading branch information
sabin18 committed Nov 11, 2019
2 parents 2b57644 + 37c82e5 commit dc318d9
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions src/controllers/requestController.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ import findOneRequest from '../helpers/findOneRequest';
import findUser from '../helpers/findUser';
import requestHelper from '../helpers/requestHelper';
import notifSender from '../helpers/notifSender';
import notifServices from '../services/notifServices';

const { Op } = Sequelize;
const { SUCCESSFULLY_RETRIEVED_REQUESTS } = strings.requests;
const { NO_REQUESTS, ASSIGNED_REQUESTS } = text.user.requests;

const { notifSaver, notifBuilder } = notifServices;
const { allSearch } = searchRequestsServices;

export default class requestController {
Expand Down Expand Up @@ -90,23 +91,35 @@ export default class requestController {

static async updateRequest(req, res) {
const { id } = req.request;

try {
await models.requests.update(req.body, {
where: { id }, returning: true, raw: true,
});

const destination = req.body.destinations;
const { lineManager } = req.user.payload;
const APP_URL_BACKEND = `${req.protocol}://${req.headers.host}`;

destination.forEach(async element => {
await models.destinations.update(element, {
where: {
[Op.and]: [{ requestId: id }, { id: element.id }]
},
where: { [Op.and]: [{ requestId: id }, { id: element.id }] },
});
});

const request = await allSearch({ id });
const requestData = request[0].dataValues;

const notification = await notifBuilder(
requestData,
lineManager,
`request ${id} has been edited . Click here to view: ${APP_URL_BACKEND}/api/v1/requests/${id}.`
);
await notifSaver(notification);

return responseUtil(res, 200, strings.request.success.SUCCESS_UPDATE_REQUEST, request);
} catch (error) {
return res.status(500).json({ error: 'Something wrong' });
}

} catch (error) { return res.status(500).json({ error: 'Something wrong' }); }
}

static async searchRequests(req, res) {
Expand Down

0 comments on commit dc318d9

Please sign in to comment.