|
|
@@ -10,17 +10,24 @@ module.exports = class MembershipService extends Schmervice.Service {
|
|
10
|
10
|
* @param {number} profileId
|
|
11
|
11
|
* @returns {Array} List of all grouping_ids for user
|
|
12
|
12
|
*/
|
|
13
|
|
- async _getGroupingIdsForProfileId(profileId, type) {
|
|
|
13
|
+ async _getGroupingIdsForProfileId(profileId, type, active) {
|
|
14
|
14
|
const { Membership } = this.server.models()
|
|
15
|
15
|
|
|
16
|
16
|
/** Grab every Membership associated with this id */
|
|
17
|
17
|
let allMemberships
|
|
18
|
18
|
|
|
19
|
|
- if(type) {
|
|
|
19
|
+ if(type && active == 'any') {
|
|
|
20
|
+ allMemberships = await Membership.query()
|
|
|
21
|
+ .where({ profile_id: profileId })
|
|
|
22
|
+ .where({ membership_type: type })
|
|
|
23
|
+ } else if (type) {
|
|
20
|
24
|
allMemberships = await Membership.query()
|
|
21
|
25
|
.where({ profile_id: profileId })
|
|
22
|
26
|
.where({ membership_type: type })
|
|
23
|
27
|
.where({ is_active: true })
|
|
|
28
|
+ } else if(active == 'any') {
|
|
|
29
|
+ allMemberships = await Membership.query()
|
|
|
30
|
+ .where({ profile_id: profileId })
|
|
24
|
31
|
} else {
|
|
25
|
32
|
allMemberships = await Membership.query()
|
|
26
|
33
|
.where({ profile_id: profileId })
|
|
|
@@ -74,7 +81,7 @@ module.exports = class MembershipService extends Schmervice.Service {
|
|
74
|
81
|
async findGroupingsByProfileId(profileId, type) {
|
|
75
|
82
|
const { Grouping } = this.server.models()
|
|
76
|
83
|
|
|
77
|
|
- const dedupedGroupings = await this._getGroupingIdsForProfileId(profileId, type)
|
|
|
84
|
+ const dedupedGroupings = await this._getGroupingIdsForProfileId(profileId, type, 'any')
|
|
78
|
85
|
|
|
79
|
86
|
/** Grab just the Groupings this id has a Membership for */
|
|
80
|
87
|
return await Grouping.query()
|