user: add routes to set/clear avatar

This commit is contained in:
Girish Ramakrishnan
2020-07-10 07:23:33 -07:00
parent c6c584ff74
commit 8c7eff4e24
3 changed files with 38 additions and 12 deletions

View File

@@ -1,18 +1,20 @@
'use strict';
exports = module.exports = {
get: get,
update: update,
list: list,
create: create,
remove: remove,
changePassword: changePassword,
verifyPassword: verifyPassword,
createInvite: createInvite,
sendInvite: sendInvite,
setGroups: setGroups,
get,
update,
list,
create,
remove,
changePassword,
verifyPassword,
createInvite,
sendInvite,
setGroups,
setAvatar,
clearAvatar,
load: load
load
};
var assert = require('assert'),
@@ -192,3 +194,25 @@ function changePassword(req, res, next) {
next(new HttpSuccess(204));
});
}
function setAvatar(req, res, next) {
assert.strictEqual(typeof req.resource, 'object');
if (!req.files.avatar) return next(new HttpError(400, 'avatar is missing'));
users.setAvatar(req.resource.id, req.files.avatar.path, function (error) {
if (error) return next(BoxError.toHttpError(error));
next(new HttpSuccess(202, {}));
});
}
function clearAvatar(req, res, next) {
assert.strictEqual(typeof req.resource, 'object');
users.clearAvatar(req.resource.id, function (error) {
if (error) return next(BoxError.toHttpError(error));
next(new HttpSuccess(202, {}));
});
}