Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

membership.js 939B

12345678910111213141516171819202122232425262728
  1. 'use strict';
  2. const Schmervice = require('@hapipal/schmervice');
  3. module.exports = class MembershipService extends Schmervice.Service {
  4. constructor(...args) {
  5. super(...args)
  6. }
  7. async findGroupingsById(id) {
  8. const { Membership, Grouping } = this.server.models()
  9. /** Grab every Membership associated with this id */
  10. const allMemberships = await Membership.query()
  11. .throwIfNotFound()
  12. .where('user_id', id)
  13. /** Copy a list of the just the Groupings */
  14. const groupingIdsToGrab = allMemberships.map(membership => membership.grouping_id)
  15. /** Uncomment to dedupe the list just in case */
  16. const dedupedGroupings = [...new Set(groupingIdsToGrab)]
  17. /** Grab just the Groupings this id has a Membership for */
  18. return await Grouping.query()
  19. .throwIfNotFound()
  20. .whereIn('grouping_id', dedupedGroupings)
  21. }
  22. }