Skip to content

Commit

Permalink
refactor: remove /users/{uid}/settings/{setting} route
Browse files Browse the repository at this point in the history
@baris Also, I am now allowing the following properties to be saved in User.saveSettings:
- categoryTopicSort
- topicPostSort
- setCategorySort
- setTopicSort
  • Loading branch information
julianlam committed Oct 28, 2020
1 parent e0b6781 commit aa8faf5
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 55 deletions.
2 changes: 0 additions & 2 deletions public/openapi/write.yaml
Expand Up @@ -34,8 +34,6 @@ paths:
$ref: 'write/users/uid.yaml'
/users/{uid}/settings:
$ref: 'write/users/uid/settings.yaml'
/users/{uid}/settings/{setting}:
$ref: 'write/users/uid/settings/setting.yaml'
/users/{uid}/password:
$ref: 'write/users/uid/password.yaml'
/users/{uid}/follow:
Expand Down
40 changes: 0 additions & 40 deletions public/openapi/write/users/uid/settings/setting.yaml

This file was deleted.

6 changes: 3 additions & 3 deletions public/src/modules/sort.js
Expand Up @@ -20,9 +20,9 @@ define('sort', ['components', 'api'], function (components, api) {
}
var newSetting = $(this).attr('data-sort');
if (app.user.uid) {
api.put(`/users/${app.user.uid}/settings/${field}`, {
value: newSetting,
}).then(() => {
const payload = { settings: {} };
payload.settings[field] = newSetting;
api.put(`/users/${app.user.uid}/settings`, payload).then(() => {
refresh(newSetting, utils.params());
});
} else {
Expand Down
4 changes: 0 additions & 4 deletions src/api/users.js
Expand Up @@ -106,10 +106,6 @@ usersAPI.updateSettings = async function (caller, data) {
return await user.saveSettings(data.uid, payload);
};

usersAPI.updateSetting = async function (caller, data) {
await user.setSetting(data.uid, data.setting, data.value);
};

usersAPI.changePassword = async function (caller, data) {
await user.changePassword(caller.uid, Object.assign(data, { ip: caller.ip }));
await events.log({
Expand Down
5 changes: 0 additions & 5 deletions src/controllers/write/users.js
Expand Up @@ -33,11 +33,6 @@ Users.updateSettings = async (req, res) => {
helpers.formatApiResponse(200, res, settings);
};

Users.updateSetting = async (req, res) => {
await api.users.updateSetting(req, { ...req.params, value: req.body.value });
helpers.formatApiResponse(200, res);
};

Users.changePassword = async (req, res) => {
await api.users.changePassword(req, { ...req.body, uid: req.params.uid });
helpers.formatApiResponse(200, res);
Expand Down
1 change: 0 additions & 1 deletion src/routes/write/users.js
Expand Up @@ -22,7 +22,6 @@ function authenticatedRoutes() {
setupApiRoute(router, 'delete', '/:uid', [...middlewares, middleware.assert.user, middleware.exposePrivileges], controllers.write.users.delete);

setupApiRoute(router, 'put', '/:uid/settings', [...middlewares, middleware.checkRequired.bind(null, ['settings'])], controllers.write.users.updateSettings);
setupApiRoute(router, 'put', '/:uid/settings/:setting', [...middlewares, middleware.checkRequired.bind(null, ['value'])], controllers.write.users.updateSetting);

setupApiRoute(router, 'put', '/:uid/password', [...middlewares, middleware.checkRequired.bind(null, ['newPassword']), middleware.assert.user], controllers.write.users.changePassword);

Expand Down
4 changes: 4 additions & 0 deletions src/user/settings.js
Expand Up @@ -121,6 +121,10 @@ module.exports = function (User) {
upvoteNotifFreq: data.upvoteNotifFreq,
bootswatchSkin: data.bootswatchSkin,
categoryWatchState: data.categoryWatchState,
categoryTopicSort: data.categoryTopicSort,
topicPostSort: data.topicPostSort,
setCategorySort: data.setCategorySort,
setTopicSort: data.setTopicSort,
};
const notificationTypes = await notifications.getAllNotificationTypes();
notificationTypes.forEach(function (notificationType) {
Expand Down

0 comments on commit aa8faf5

Please sign in to comment.