Spaces:
Runtime error
Runtime error
File size: 1,794 Bytes
3b6afc0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
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,
};
|