| 12345678910111213141516171819202122232425262728 |
- 'use strict';
-
- const Schmervice = require('@hapipal/schmervice');
-
- module.exports = class MembershipService extends Schmervice.Service {
- constructor(...args) {
- super(...args)
- }
- async findGroupingsById(id) {
- const { Membership, Grouping } = this.server.models()
-
- /** Grab every Membership associated with this id */
- const allMemberships = await Membership.query()
- .throwIfNotFound()
- .where('user_id', id)
-
- /** Copy a list of the just the Groupings */
- const groupingIdsToGrab = allMemberships.map(membership => membership.grouping_id)
-
- /** Uncomment to dedupe the list just in case */
- const dedupedGroupings = [...new Set(groupingIdsToGrab)]
-
- /** Grab just the Groupings this id has a Membership for */
- return await Grouping.query()
- .throwIfNotFound()
- .whereIn('grouping_id', dedupedGroupings)
- }
- }
|