mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-09-22 08:12:00 +02:00
25 lines
665 B
JavaScript
25 lines
665 B
JavaScript
const User = require('../../models/User');
|
|||
|
|||
const updateUserPluginsService = async (user, pluginKey, action) => {
|
|||
try {
|
|||
if (action === 'install') {
|
|||
const response = await User.updateOne(
|
|||
{ _id: user._id },
|
|||
{ $set: { plugins: [...user.plugins, pluginKey] } }
|
|||
);
|
|||
return response;
|
|||
} else if (action === 'uninstall') {
|
|||
const response = await User.updateOne(
|
|||
{ _id: user._id },
|
|||
{ $set: { plugins: user.plugins.filter((plugin) => plugin !== pluginKey) } }
|
|||
);
|
|||
return response;
|
|||
}
|
|||
} catch (err) {
|
|||
console.log(err);
|
|||
return err;
|
|||
}
|
|||
};
|
|||
|
|||
module.exports = { updateUserPluginsService };
|