diff --git a/src/client/actions/RegistryUserActions.js b/src/client/actions/RegistryUserActions.js index a05e7b9a..e4254412 100644 --- a/src/client/actions/RegistryUserActions.js +++ b/src/client/actions/RegistryUserActions.js @@ -13,7 +13,7 @@ export function getRegistryUserActions(alt, registryUserResource, errorActions) loadRegistryUserList() { return dispatch => { dispatch(); - registryUserResource.findAll() + registryUserResource.findAll('includePresence=true') .then(registryUserList => this.registryUserListUpdated(registryUserList), err => errorActions.error(err, 'Käyttäjiä ei voitu ladata')); }; diff --git a/src/client/components/RegistryUserListPage/RegistryUserTable.jsx b/src/client/components/RegistryUserListPage/RegistryUserTable.jsx index 357444cd..322ef7af 100644 --- a/src/client/components/RegistryUserListPage/RegistryUserTable.jsx +++ b/src/client/components/RegistryUserListPage/RegistryUserTable.jsx @@ -1,5 +1,6 @@ import React from 'react'; import { Table, Button } from 'react-bootstrap'; +import { Presence } from '../../components'; const RegistryUserRow = props => { const { @@ -15,6 +16,7 @@ const RegistryUserRow = props => { phoneNumber, email, status, + presence, } = registryUser; const blockStatusToggleButton = status === 'blocked' @@ -23,6 +25,7 @@ const RegistryUserRow = props => { return (
Tila | Nimi | Jäsennumero | Puhelinnumero | diff --git a/src/common/models/registryuser.js b/src/common/models/registryuser.js index bbf3b236..ff45aaa4 100644 --- a/src/common/models/registryuser.js +++ b/src/common/models/registryuser.js @@ -2,6 +2,7 @@ import app from '../../server/server.js'; import Promise from 'bluebird'; import loopback from 'loopback'; import crypto from 'crypto'; +import _ from 'lodash'; export default function(Registryuser) { Registryuser.afterRemote('create', (ctx, registryuserInstance, next) => { @@ -61,6 +62,30 @@ export default function(Registryuser) { updateRegistryUser({ id: userId }, { status: null }).asCallback(callback); }; + Registryuser.afterRemote('find', (ctx, instance, next) => { + Promise.try(() => { + const includePresence = ctx && ctx.result && ctx.req && ctx.req.query && ctx.req.query.includePresence; + if (includePresence) { + const findParticipants = Promise.promisify(app.models.Participant.find, { context: app.models.Participant }); + + const memberNumbers = ctx.result.map(user => user.memberNumber); + + // To object is an undocumented function of loopback models, which is used here to force the model object into a plain javascript object. + // Without the call setting a new property on the objects below wouldn't work. + const keyedUsers = _.keyBy(ctx.result.map(user => user.toObject()), 'memberNumber'); + + return findParticipants({ where: { memberNumber: { inq: memberNumbers } } }) + .each(participant => { + const user = keyedUsers[participant.memberNumber]; + if (user) { + user.presence = participant.presence; + } + }) + .tap(() => ctx.result = _.values(keyedUsers)); + } + }).asCallback(next); + }); + Registryuser.remoteMethod('block', { http: { path: '/:id/block', verb: 'post' },
---|