Spaces:
Sleeping
Sleeping
File size: 667 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 |
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 };
|