2019-05-29 05:21:06 -04:00
|
|
|
const { User } = require('../../models/User')
|
|
|
|
|
|
|
|
module.exports = {
|
2020-01-07 06:03:14 -05:00
|
|
|
updateFeatures(userId, features, callback) {
|
|
|
|
const conditions = { _id: userId }
|
2019-05-29 05:21:06 -04:00
|
|
|
const update = {}
|
2021-05-05 09:05:04 -04:00
|
|
|
for (const key in features) {
|
2019-05-29 05:21:06 -04:00
|
|
|
const value = features[key]
|
|
|
|
update[`features.${key}`] = value
|
|
|
|
}
|
2020-11-03 04:19:05 -05:00
|
|
|
User.updateOne(conditions, update, (err, result) =>
|
2020-01-07 06:03:14 -05:00
|
|
|
callback(err, features, (result ? result.nModified : 0) === 1)
|
2019-05-29 05:21:06 -04:00
|
|
|
)
|
2019-12-16 05:55:10 -05:00
|
|
|
},
|
|
|
|
|
2020-01-07 06:03:14 -05:00
|
|
|
overrideFeatures(userId, features, callback) {
|
|
|
|
const conditions = { _id: userId }
|
2019-12-16 05:55:10 -05:00
|
|
|
const update = { features }
|
2020-11-03 04:19:05 -05:00
|
|
|
User.updateOne(conditions, update, (err, result) =>
|
2020-01-07 06:03:14 -05:00
|
|
|
callback(err, (result ? result.nModified : 0) === 1)
|
2019-12-16 05:55:10 -05:00
|
|
|
)
|
2021-04-27 03:52:58 -04:00
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|