@chevre/domain
Version:
Chevre Domain Library for Node.js
40 lines (32 loc) • 1.35 kB
text/typescript
// tslint:disable:no-console
import * as moment from 'moment';
import * as mongoose from 'mongoose';
import { chevre } from '../../../lib/index';
// const project = { id: String(process.env.PROJECT_ID) };
const STORAGE_PERIOD_IN_DAYS = 365;
// tslint:disable-next-line:max-func-body-length
async function main() {
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
const transactionRepo = await chevre.repository.Transaction.createInstance(mongoose.connection);
// tslint:disable-next-line:no-increment-decrement no-magic-numbers
for (let index = 0; index < 1800; index++) {
const updateResult = await transactionRepo.deleteEndDatePassedCertainPeriod({
typeOf: chevre.factory.transactionType.MoneyTransfer,
endDate: {
$gte: moment()
.add(-(index + STORAGE_PERIOD_IN_DAYS + 1), 'days')
.toDate(),
$lt: moment()
.add(-(index + STORAGE_PERIOD_IN_DAYS), 'days')
.toDate()
}
});
console.log(
'unset processed.', updateResult, -(index + STORAGE_PERIOD_IN_DAYS), 'days',
moment.duration(index + STORAGE_PERIOD_IN_DAYS, 'days')
.humanize());
}
}
main()
.then()
.catch(console.error);