Fix updatePrepaid.js user updates

This commit is contained in:
Scott Erickson 2016-07-22 09:33:44 -07:00
parent 1e0aa1a375
commit c3381c1274

View file

@ -54,13 +54,17 @@ var updatePrepaid = function updatePrepaid(stringID, originalUpdate) {
print('\nUpdate prepaid', print('\nUpdate prepaid',
JSON.stringify(prepaidUpdate, null, ' '), JSON.stringify(prepaidUpdate, null, ' '),
db.prepaids.update( db.prepaids.update(
{_id: id}, { _id: id },
{ $set: prepaidUpdate } { $set: prepaidUpdate }
) )
) )
} }
var userUpdate = _.pick(originalUpdate, 'startDate', 'endDate' ); var userUpdate = _(originalUpdate)
.pick('startDate', 'endDate' )
.transform(function(result, value, key) { result['coursePrepaid.'+key] = value })
.value();
if (_.isEmpty(userUpdate)) { if (_.isEmpty(userUpdate)) {
print('\nSkipping user update, nothing to update.') print('\nSkipping user update, nothing to update.')
} }
@ -69,8 +73,8 @@ var updatePrepaid = function updatePrepaid(stringID, originalUpdate) {
JSON.stringify(userUpdate, null, ' '), JSON.stringify(userUpdate, null, ' '),
db.users.update( db.users.update(
{'coursePrepaid._id': id}, {'coursePrepaid._id': id},
{$set: userUpdate}, { $set: userUpdate },
{multi: true} { multi: true }
) )
); );
} }