mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-03-24 19:59:53 -04:00
updatePrepaid function can modify creator property
This commit is contained in:
parent
2b09a24436
commit
e19d31b9b2
1 changed files with 15 additions and 4 deletions
|
@ -7,14 +7,14 @@
|
||||||
// In mongo shell
|
// In mongo shell
|
||||||
//
|
//
|
||||||
// > db.loadServerScripts();
|
// > db.loadServerScripts();
|
||||||
// > updatePrepaid('<prepaid id string>', { endDate: "2017-07-01T00:00:00.000Z", maxRedeemers: 10 });
|
// > updatePrepaid('<prepaid id string>', { endDate: "2017-07-01T00:00:00.000Z", maxRedeemers: 10, creator: '56141d0a7291607006ad8412' });
|
||||||
|
|
||||||
var updatePrepaid = function updatePrepaid(stringID, originalUpdate) {
|
var updatePrepaid = function updatePrepaid(stringID, originalUpdate) {
|
||||||
try {
|
try {
|
||||||
load('./bower_components/lodash/dist/lodash.js')
|
load('./bower_components/lodash/dist/lodash.js')
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
print('Lodash could not be loaded, ensure you are in codecombat project directory.')
|
print('Lodash could not be loaded, ensure you are in codecombat project directory.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,9 +33,20 @@ var updatePrepaid = function updatePrepaid(stringID, originalUpdate) {
|
||||||
}
|
}
|
||||||
|
|
||||||
print('Found prepaid', JSON.stringify(_.omit(prepaid, 'redeemers'), null, ' '));
|
print('Found prepaid', JSON.stringify(_.omit(prepaid, 'redeemers'), null, ' '));
|
||||||
print('-- has', prepaid.redeemers.length, 'redeemers.');
|
print('-- has', _.size(prepaid.redeemers), 'redeemers.');
|
||||||
|
|
||||||
|
var prepaidUpdate = _.pick(originalUpdate, 'maxRedeemers', 'startDate', 'endDate', 'creator');
|
||||||
|
|
||||||
|
if (_.isString(prepaidUpdate.creator)) {
|
||||||
|
try {
|
||||||
|
prepaidUpdate.creator = ObjectId(prepaidUpdate.creator);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
print('Invalid creator given:', stringID);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var prepaidUpdate = _.pick(originalUpdate, 'maxRedeemers', 'startDate', 'endDate' );
|
|
||||||
if (_.isEmpty(prepaidUpdate)) {
|
if (_.isEmpty(prepaidUpdate)) {
|
||||||
print('\nSkipping prepaid update, nothing to update.')
|
print('\nSkipping prepaid update, nothing to update.')
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue