feat(about): Submit new 'about' settings
This commit is contained in:
@ -1,8 +1,12 @@
|
||||
import debug from 'debug';
|
||||
import { check } from 'express-validator/check';
|
||||
|
||||
import { ifNoUser401, createValidatorErrorHandler } from '../utils/middleware';
|
||||
import { themes } from '../../common/utils/themes.js';
|
||||
import { alertTypes } from '../../common/utils/flash.js';
|
||||
|
||||
const log = debug('fcc:boot:settings');
|
||||
|
||||
export default function settingsController(app) {
|
||||
const api = app.loopback.Router();
|
||||
|
||||
@ -47,6 +51,7 @@ export default function settingsController(app) {
|
||||
createValidatorErrorHandler(alertTypes.danger),
|
||||
updateMyTheme
|
||||
);
|
||||
api.put('/update-my-about', ifNoUser401, updateMyAbout);
|
||||
api.put('/update-my-username', ifNoUser401, updateMyUsername);
|
||||
|
||||
app.use('/internal', api);
|
||||
@ -59,6 +64,11 @@ const standardErrorMessage = {
|
||||
'Something went wrong updating your account. Please check and try again'
|
||||
};
|
||||
|
||||
const standardSuccessMessage = {
|
||||
type: 'success',
|
||||
message: 'We have updated your preferences'
|
||||
};
|
||||
|
||||
const toggleUserFlag = (flag, req, res, next) => {
|
||||
const { user } = req;
|
||||
const currentValue = user[flag];
|
||||
@ -180,6 +190,21 @@ function updateMyProjects(req, res, next) {
|
||||
.subscribe(message => res.json({ message }), next);
|
||||
}
|
||||
|
||||
function updateMyAbout(req, res, next) {
|
||||
const {
|
||||
user,
|
||||
body: { name, location, about, picture }
|
||||
} = req;
|
||||
log(name, location, picture, about)
|
||||
return user.updateAttributes({ name, location, about, picture }, err => {
|
||||
if (err) {
|
||||
res.status(500).json(standardErrorMessage);
|
||||
return next(err);
|
||||
}
|
||||
return res.status(200).json(standardSuccessMessage);
|
||||
});
|
||||
}
|
||||
|
||||
function createUpdateMyUsername(app) {
|
||||
const { User } = app.models;
|
||||
return async function updateMyUsername(req, res, next) {
|
||||
|
Reference in New Issue
Block a user