LibreChat/api/server/controllers/UserController.js
Danny Avila e5336039fc
ci(backend-review.yml): add linter step to the backend review workflow (#625)
* ci(backend-review.yml): add linter step to the backend review workflow

* chore(backend-review.yml): remove prettier from lint-action configuration

* chore: apply new linting workflow

* chore(lint-staged.config.js): reorder lint-staged tasks for JavaScript and TypeScript files

* chore(eslint): update ignorePatterns in .eslintrc.js
chore(lint-action): remove prettier option in backend-review.yml
chore(package.json): add lint and lint:fix scripts

* chore(lint-staged.config.js): remove prettier --write command for js, jsx, ts, tsx files

* chore(titleConvo.js): remove unnecessary console.log statement
chore(titleConvo.js): add missing comma in options object

* chore: apply linting to all files

* chore(lint-staged.config.js): update lint-staged configuration to include prettier formatting
2023-07-14 09:36:49 -04:00

55 lines
1.8 KiB
JavaScript

const { updateUserPluginsService } = require('../services/UserService');
const { updateUserPluginAuth, deleteUserPluginAuth } = require('../services/PluginService');
const getUserController = async (req, res) => {
res.status(200).send(req.user);
};
const updateUserPluginsController = async (req, res) => {
const { user } = req;
const { pluginKey, action, auth } = req.body;
let authService;
try {
const userPluginsService = await updateUserPluginsService(user, pluginKey, action);
if (userPluginsService instanceof Error) {
console.log(userPluginsService);
const { status, message } = userPluginsService;
res.status(status).send({ message });
}
if (auth) {
const keys = Object.keys(auth);
const values = Object.values(auth);
if (action === 'install' && keys.length > 0) {
for (let i = 0; i < keys.length; i++) {
authService = await updateUserPluginAuth(user.id, keys[i], pluginKey, values[i]);
if (authService instanceof Error) {
console.log(authService);
const { status, message } = authService;
res.status(status).send({ message });
}
}
}
if (action === 'uninstall' && keys.length > 0) {
for (let i = 0; i < keys.length; i++) {
authService = await deleteUserPluginAuth(user.id, keys[i]);
if (authService instanceof Error) {
console.log(authService);
const { status, message } = authService;
res.status(status).send({ message });
}
}
}
}
res.status(200).send();
} catch (err) {
console.log(err);
res.status(500).json({ message: err.message });
}
};
module.exports = {
getUserController,
updateUserPluginsController,
};