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 = {}
|
|
|
|
for (let key in features) {
|
|
|
|
const value = features[key]
|
|
|
|
update[`features.${key}`] = value
|
|
|
|
}
|
2020-11-02 05:53:57 -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-02 05:53:57 -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
|
|
|
)
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
}
|