-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add public services to add and remove user realms
- Loading branch information
1 parent
585c4d5
commit 88ca174
Showing
6 changed files
with
334 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
'use strict'; | ||
|
||
const userMng = require('../../managers/user'); | ||
const _ = require('lodash'); | ||
|
||
module.exports = function (req, res, next) { | ||
const name = req.body.name; | ||
|
||
if (_.isEmpty(name)) { | ||
res.send(400, { | ||
err: 'BadRequestError', | ||
des: 'Missing name in request body' | ||
}); | ||
return next(); | ||
} | ||
|
||
userMng().addRealmToUser(req.user._id, name, function (err) { | ||
if (err) { | ||
if (!err.code) { | ||
res.send(500, err); | ||
return next(err); | ||
} | ||
|
||
const errCode = err.code; | ||
delete(err.code); | ||
res.send(errCode, err); | ||
return next(err); | ||
} | ||
|
||
res.send(204); | ||
return next(); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
'use strict'; | ||
|
||
const userMng = require('../../managers/user'); | ||
const _ = require('lodash'); | ||
|
||
module.exports = function (req, res, next) { | ||
const name = req.body.name; | ||
|
||
if (_.isEmpty(name)) { | ||
res.send(400, { | ||
err: 'BadRequestError', | ||
des: 'Missing name in request body' | ||
}); | ||
return next(); | ||
} | ||
|
||
userMng().removeRealmFromUser(req.user._id, req.body.name, function (err) { | ||
if (err) { | ||
if (!err.code) { | ||
res.send(500, err); | ||
return next(err); | ||
} | ||
|
||
const errCode = err.code; | ||
delete(err.code); | ||
res.send(errCode, err); | ||
return next(err); | ||
} | ||
|
||
res.send(200); | ||
return next(); | ||
}); | ||
}; |
Oops, something went wrong.