Yes I did:
In the GET route I need to enrich my record to add the userEmail
router.get('/places/:place_id/relationships/contracts', (request, response, next) => {
const place_id = request.params.place_id;
const limit = parseInt(request.query.page.size, 10) || 20;
const offset = (parseInt(request.query.page.number, 10) - 1) * limit;
const recordsGetter = new RecordsGetter(models.contracts);
const where = { place_id };
// find the buildingEquipments for the requested page and page size
const findAll = models.contracts.findAll({
where,
offset,
limit,
});
// count all buildingEquipments for pagination
const count = models.contracts.count({ where });
// resolve the two promises and serialize the response
Promise.all([findAll, count])
.then(([contractsFound, contractsCount]) => {
const recordsWithUser = contractsFound.map(record => {
record.userEmail = request.user.email;
return record;
});
return recordsGetter.serialize(recordsWithUser, { count: contractsCount });
})
.then((recordsSerialized) => response.send(recordsSerialized))
.catch(next);
});
In the POST route I had to do that in order to prevent a “permission denied” error when I create a contract within a place
router.post('/places/:place_id/relationships/contracts', (req, res, next) => {
res.sendStatus(200);
});