@@ -3,6 +3,7 @@ import { Mongo } from 'meteor/mongo'
3
3
import publicationFactory from './base/rest-resource-factory'
4
4
import { makeAssociationFactory , withUsers } from './base/associations-helper'
5
5
import { callAPI } from '../util/bugzilla-api'
6
+ import _ from 'lodash'
6
7
7
8
export const collectionName = 'units'
8
9
@@ -12,22 +13,35 @@ export const factoryOptions = {
12
13
dataResolver : data => data . products
13
14
}
14
15
15
- export const getUnitRoles = unit =>
16
- unit . components . reduce ( ( all , { default_assigned_to : assigned , default_qa_contact : qaContact , name} ) => {
16
+ export const getUnitRoles = unit => _ . uniqBy (
17
+ unit . components . reduce ( ( all , { default_assigned_to : assigned , name} ) => { // Getting names from the unit's components
17
18
if ( assigned ) {
18
19
all . push ( {
19
20
login : assigned ,
20
21
role : name
21
22
} )
22
23
}
23
- if ( qaContact ) {
24
- all . push ( {
25
- login : qaContact ,
26
- role : name
27
- } )
28
- }
29
24
return all
30
- } , [ ] )
25
+ } , [ ] ) . concat ( Meteor . users . find ( { // Getting more names of users with a finalized invitation to the unit
26
+ invitedToCases : {
27
+ $elemMatch : {
28
+ unitId : unit . id ,
29
+ done : true
30
+ }
31
+ }
32
+ } , Meteor . isServer ? { // Projection is only done on the server, as some features are not supported in Minimongo
33
+ fields : {
34
+ 'invitedToCases.$' : 1 ,
35
+ 'bugzillaCreds.login' : 1
36
+ }
37
+ } : { } ) . fetch ( )
38
+ // Mapping the users to the same interface as the first half of the array
39
+ . map ( ( { invitedToCases : [ { role } ] , bugzillaCreds : { login } } ) => ( {
40
+ login,
41
+ role
42
+ } ) ) ) ,
43
+ ( { login} ) => login // Filtering out duplicates in case a user shows up in a component and has a finalized invitation
44
+ )
31
45
32
46
if ( Meteor . isServer ) {
33
47
const factory = publicationFactory ( factoryOptions )
@@ -40,7 +54,19 @@ if (Meteor.isServer) {
40
54
params : { names : unitName }
41
55
} )
42
56
} ) ,
43
- withUsers ( unitItem => getUnitRoles ( unitItem ) . map ( u => u . login ) )
57
+ withUsers (
58
+ unitItem => getUnitRoles ( unitItem ) . map ( u => u . login ) ,
59
+ ( query , unitItem ) => Object . assign ( {
60
+ invitedToCases : {
61
+ $elemMatch : {
62
+ unitId : unitItem . id
63
+ }
64
+ }
65
+ } , query ) ,
66
+ ( projection , unitItem ) => Object . assign ( {
67
+ 'invitedToCases.$' : 1
68
+ } , projection )
69
+ )
44
70
) )
45
71
46
72
Meteor . publish ( `${ collectionName } .forReporting` , function ( ) {
@@ -51,7 +77,7 @@ if (Meteor.isServer) {
51
77
const listResponse = callAPI ( 'get' , '/rest/product_enterable' , { token} , false , true )
52
78
ids = listResponse . data . ids
53
79
} catch ( e ) {
54
- console . error ( 'API error encountered' , 'unitsForReporting' , this . userId )
80
+ console . error ( 'API error encountered' , ` ${ collectionName } .forReporting` , this . userId )
55
81
this . ready ( )
56
82
this . error ( new Meteor . Error ( { message : 'REST API error' , origError : e } ) )
57
83
}
0 commit comments