UserRepository handles updating db settings better.
Moved the plex_userid to settings to expanded with functions for updating and fetching settings, each with its own helper function towards the database. Since we had a linkPlexUserId function and we dont want plex_userid to be updated from the updatesettings function we moved unlinking to a separate endpoint and class function. Also a new controller and endpoints for getting and updating settings.
This commit is contained in:
@@ -57,7 +57,7 @@ function plexAuthenticate(username, password) {
|
||||
.then(resp => handleResponse(resp))
|
||||
}
|
||||
|
||||
function authenticatePlexAccountController(req, res) {
|
||||
function link(req, res) {
|
||||
const user = req.loggedInUser;
|
||||
const { username, password } = req.body;
|
||||
|
||||
@@ -70,4 +70,18 @@ function authenticatePlexAccountController(req, res) {
|
||||
.catch(error => handleError(error, res))
|
||||
}
|
||||
|
||||
module.exports = authenticatePlexAccountController;
|
||||
function link(req, res) {
|
||||
const user = req.loggedInUser;
|
||||
|
||||
return userRepository.unlinkPlexUserId(user.username)
|
||||
.then(response => res.send({
|
||||
success: true,
|
||||
message: "Successfully unlinked plex account from seasoned request."
|
||||
}))
|
||||
.catch(error => handleError(error, res))
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
link,
|
||||
unlink
|
||||
};
|
||||
|
||||
42
seasoned_api/src/webserver/controllers/user/settings.js
Normal file
42
seasoned_api/src/webserver/controllers/user/settings.js
Normal file
@@ -0,0 +1,42 @@
|
||||
const UserRepository = require('src/user/userRepository');
|
||||
const userRepository = new UserRepository();
|
||||
/**
|
||||
* Controller: Retrieves settings of a logged in user
|
||||
* @param {Request} req http request variable
|
||||
* @param {Response} res
|
||||
* @returns {Callback}
|
||||
*/
|
||||
const getSettingsController = (req, res) => {
|
||||
const user = req.loggedInUser;
|
||||
const username = user === undefined ? undefined : user.username;
|
||||
|
||||
userRepository.getSettings(username)
|
||||
.then(settings => {
|
||||
res.send({ success: true, settings });
|
||||
})
|
||||
.catch(error => {
|
||||
res.status(404).send({ success: false, message: error.message });
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
const updateSettingsController = (req, res) => {
|
||||
const user = req.loggedInUser;
|
||||
const username = user === undefined ? undefined : user.username;
|
||||
|
||||
const idempotencyKey = req.headers('Idempotency-Key'); // TODO implement better transactions
|
||||
const { dark_mode, emoji } = req.body;
|
||||
|
||||
userRepository.updateSettings(username, dark_mode, emoji)
|
||||
.then(settings => {
|
||||
res.send({ success: true, settings });
|
||||
})
|
||||
.catch(error => {
|
||||
res.status(404).send({ success: false, message: error.message });
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getSettingsController,
|
||||
updateSettingsController
|
||||
}
|
||||
Reference in New Issue
Block a user