1
0
Fork 0
mirror of https://github.com/openstf/stf synced 2025-10-04 18:29:17 +02:00

move group endpoint from app unit to api unit

This commit is contained in:
Vishal Banthia 2015-12-02 23:06:14 +09:00
parent d6f37681ce
commit 5729095acb
4 changed files with 57 additions and 24 deletions

View file

@ -1,5 +1,14 @@
var Promise = require('bluebird')
var dbapi = require('../../../db/api')
var logger = require('../../../util/logger')
var datautil = require('../../../util/datautil')
var log = logger.createLogger('api:contoller:user')
module.exports = {
getCurrentUser: getCurrentUser
, getCurrentUserGroup: getCurrentUserGroup
};
function getCurrentUser(req, res) {
@ -8,3 +17,25 @@ function getCurrentUser(req, res) {
, user: req.user
})
}
function getCurrentUserGroup(req, res) {
dbapi.loadGroup(req.user.email)
.then(function(cursor) {
return Promise.promisify(cursor.toArray, cursor)()
.then(function(list) {
list.forEach(function(device) {
datautil.normalize(device, req.user)
})
res.json({
success: true
, devices: list
})
})
})
.catch(function(err) {
log.error('Failed to load group: ', err.stack)
res.json(500, {
success: false
})
})
}