@chevre/domain
Version:
Chevre Domain Library for Node.js
51 lines (43 loc) • 1.82 kB
text/typescript
// tslint:disable:no-console
import * as moment from 'moment';
import * as mongoose from 'mongoose';
import { chevre } from '../../../lib/index';
const DAYS = 365;
async function main() {
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
const now = new Date();
let updateResult: any;
const actionRepo = await chevre.repository.Action.createInstance(mongoose.connection);
const startIndex = 8760;
// tslint:disable-next-line:no-magic-numbers
const hours = (DAYS * 24) + startIndex;
// tslint:disable-next-line:no-increment-decrement no-magic-numbers
for (let index = startIndex; index < hours; index++) {
// for (let index = 0; index < hours; index++) {
updateResult = await actionRepo.unsetUnnecessaryFields({
filter: {
// _id: { $eq: '667379e7be9a532411c29424' },
typeOf: { $eq: chevre.factory.actionType.CheckAction },
'object.typeOf': { $exists: true, $eq: chevre.factory.service.paymentService.PaymentServiceType.MovieTicket },
actionStatus: { $eq: chevre.factory.actionStatusType.CompletedActionStatus },
startDate: {
$gte: moment(now)
.add(-(index + 1), 'hours')
.toDate(),
$lt: moment(now)
.add(-index, 'hours')
.toDate()
}
},
$unset: {
'result.purchaseNumberAuthIn': 1,
'result.purchaseNumberAuthResult': 1
}
});
console.log('unset processed.', updateResult, -(index + 1), 'hours', -index, 'hours');
}
console.log(DAYS, 'days processed');
}
main()
.then()
.catch(console.error);