Skip to content

Commit b1f3dbf

Browse files
authored
Exclude officer field from committee model and requests (#103)
1 parent 7aa5bb6 commit b1f3dbf

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

models/committee.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ export default sequelize.define('committees', {
2424
return {
2525
include: [{
2626
model: Officer.scope({ method: ['active', date] }),
27+
attributes: [],
28+
includeIgnoreAttributes: false,
2729
}],
2830
};
2931
},

routes/committees.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,20 @@ router
1313
Committee
1414
.scope(scopes)
1515
.findAndCountAll()
16-
.then(result => res.send({
17-
total: result.count,
18-
perPage: req.query.perPage,
19-
currentPage: req.query.page,
20-
data: result.rows.map((committee) => {
16+
.then(result => {
17+
const uniqueCommittees = {};
18+
result.rows.forEach((committee) => {
2119
const c = committee.get({ plain: true });
2220
Reflect.deleteProperty(c, 'officer');
23-
return c;
24-
}),
25-
}))
21+
uniqueCommittees[c.name] = c;
22+
});
23+
return res.send({
24+
total: Object.keys(uniqueCommittees).length,
25+
perPage: req.query.perPage,
26+
currentPage: req.query.page,
27+
data: Object.values(uniqueCommittees),
28+
})
29+
})
2630
.catch(err => next(err));
2731
});
2832

0 commit comments

Comments
 (0)