profile: store preferred language in the database

This commit is contained in:
Girish Ramakrishnan
2024-02-26 12:32:14 +01:00
parent 6d6107161e
commit 6525504923
10 changed files with 150 additions and 14 deletions
+14
View File
@@ -8,6 +8,7 @@ exports = module.exports = {
setFallbackEmail,
getAvatar,
setAvatar,
setLanguage,
getBackgroundImage,
setBackgroundImage,
setPassword,
@@ -65,6 +66,7 @@ async function get(req, res, next) {
role: req.user.role,
source: req.user.source,
hasBackgroundImage: !!backgroundImage,
language: req.user.language,
avatarUrl: `https://${dashboardFqdn}/api/v1/profile/avatar/${req.user.id}`,
avatarType: avatarType.toString() // this is a Buffer
}));
@@ -106,6 +108,18 @@ async function setDisplayName(req, res, next) {
next(new HttpSuccess(204));
}
async function setLanguage(req, res, next) {
assert.strictEqual(typeof req.user, 'object');
assert.strictEqual(typeof req.body, 'object');
if ('language' in req.body && typeof req.body.language !== 'string') return next(new HttpError(400, 'language must be string'));
const [error] = await safe(users.update(req.user, { language: req.body.language }, AuditSource.fromRequest(req)));
if (error) return next(BoxError.toHttpError(error));
next(new HttpSuccess(204));
}
async function setAvatar(req, res, next) {
assert.strictEqual(typeof req.user, 'object');