users: add unset route for avatar

also add missing tests for avatar and profile locking
This commit is contained in:
Girish Ramakrishnan
2025-07-15 10:06:26 +02:00
parent be9adb64bb
commit 622aecfd6d
9 changed files with 122 additions and 3 deletions
+16
View File
@@ -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');