2019-05-29 05:21:06 -04:00
|
|
|
let InstitutionsGetter
|
|
|
|
const UserGetter = require('../User/UserGetter')
|
|
|
|
const UserMembershipsHandler = require('../UserMembership/UserMembershipsHandler')
|
|
|
|
const UserMembershipEntityConfigs = require('../UserMembership/UserMembershipEntityConfigs')
|
|
|
|
|
|
|
|
module.exports = InstitutionsGetter = {
|
2020-02-18 06:36:53 -05:00
|
|
|
getConfirmedAffiliations(userId, callback) {
|
2021-04-14 09:17:21 -04:00
|
|
|
UserGetter.getUserFullEmails(userId, function (error, emailsData) {
|
2020-06-01 04:37:56 -04:00
|
|
|
if (error) {
|
2019-05-29 05:21:06 -04:00
|
|
|
return callback(error)
|
|
|
|
}
|
|
|
|
|
2020-02-18 06:36:53 -05:00
|
|
|
const confirmedAffiliations = emailsData
|
2019-05-29 05:21:06 -04:00
|
|
|
.filter(
|
|
|
|
emailData =>
|
2020-06-01 04:37:56 -04:00
|
|
|
emailData.confirmedAt &&
|
|
|
|
emailData.affiliation &&
|
|
|
|
emailData.affiliation.institution &&
|
|
|
|
emailData.affiliation.institution.confirmed
|
2019-05-29 05:21:06 -04:00
|
|
|
)
|
2020-02-18 06:36:53 -05:00
|
|
|
.map(emailData => emailData.affiliation)
|
|
|
|
|
2020-06-01 04:37:56 -04:00
|
|
|
callback(null, confirmedAffiliations)
|
2020-02-18 06:36:53 -05:00
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
getConfirmedInstitutions(userId, callback) {
|
|
|
|
InstitutionsGetter.getConfirmedAffiliations(
|
|
|
|
userId,
|
|
|
|
(error, confirmedAffiliations) => {
|
2020-06-01 04:37:56 -04:00
|
|
|
if (error) {
|
2020-02-18 06:36:53 -05:00
|
|
|
return callback(error)
|
|
|
|
}
|
|
|
|
|
|
|
|
const confirmedInstitutions = confirmedAffiliations.map(
|
|
|
|
confirmedAffiliation =>
|
2020-06-01 04:37:56 -04:00
|
|
|
confirmedAffiliation ? confirmedAffiliation.institution : undefined
|
2019-05-29 05:21:06 -04:00
|
|
|
)
|
|
|
|
|
2020-06-01 04:37:56 -04:00
|
|
|
callback(null, confirmedInstitutions)
|
2020-02-18 06:36:53 -05:00
|
|
|
}
|
|
|
|
)
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
|
2020-06-01 04:37:56 -04:00
|
|
|
getManagedInstitutions(userId, callback) {
|
|
|
|
UserMembershipsHandler.getEntitiesByUser(
|
2019-05-29 05:21:06 -04:00
|
|
|
UserMembershipEntityConfigs.institution,
|
2020-06-01 04:37:56 -04:00
|
|
|
userId,
|
2019-05-29 05:21:06 -04:00
|
|
|
callback
|
|
|
|
)
|
2021-04-27 03:52:58 -04:00
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|