users: add unset route for avatar
also add missing tests for avatar and profile locking
This commit is contained in:
@@ -10,6 +10,7 @@ exports = module.exports = {
|
||||
setActive,
|
||||
getAvatar,
|
||||
setAvatar,
|
||||
unsetAvatar,
|
||||
updateProfile,
|
||||
|
||||
setPassword,
|
||||
@@ -112,10 +113,13 @@ async function getAvatar(req, res, next) {
|
||||
assert.strictEqual(typeof req.resources.user, 'object');
|
||||
assert.strictEqual(typeof req.user, 'object');
|
||||
|
||||
console.log('HERE');
|
||||
const [avatarError, avatar] = await safe(users.getAvatar(req.resources.user));
|
||||
if (avatarError) return next(BoxError.toHttpError(avatarError));
|
||||
if (!avatar) return next(new HttpError(404, 'no avatar'));
|
||||
|
||||
console.log('GETT AVATAR TO', avatar.length, req.resources.user.id);
|
||||
|
||||
res.set('Content-Type', 'image/png');
|
||||
res.status(200).send(avatar);
|
||||
}
|
||||
@@ -129,12 +133,24 @@ async function setAvatar(req, res, next) {
|
||||
safe.fs.unlinkSync(req.files.avatar.path);
|
||||
if (!avatar) return next(BoxError.toHttpError(new BoxError(BoxError.FS_ERROR, safe.error.message)));
|
||||
|
||||
console.log('SETTING AVATAR TO', avatar.length, req.resources.user.id);
|
||||
|
||||
const [error] = await safe(users.setAvatar(req.resources.user, avatar));
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(204, {}));
|
||||
}
|
||||
|
||||
async function unsetAvatar(req, res, next) {
|
||||
assert.strictEqual(typeof req.resources.user, 'object');
|
||||
assert.strictEqual(typeof req.user, 'object');
|
||||
|
||||
const [error] = await safe(users.setAvatar(req.resources.user, null));
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(204, {}));
|
||||
}
|
||||
|
||||
async function updateProfile(req, res, next) {
|
||||
assert.strictEqual(typeof req.resources.user, 'object');
|
||||
assert.strictEqual(typeof req.user, 'object');
|
||||
|
||||
Reference in New Issue
Block a user