UNPKG

@chevre/domain

Version:

Chevre Domain Library for Node.js

60 lines (51 loc) 1.88 kB
// 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 EXCLUDED_PROJECT_ID = process.env.EXCLUDED_PROJECT_ID; // tslint:disable-next-line:max-func-body-length async function main() { await mongoose.connect(<string>process.env.MONGOLAB_URI); const eventRepo = await chevre.repository.Event.createInstance(mongoose.connection); const cursor = eventRepo.getCursor( { endDate: { $gte: new Date() }, typeOf: { $eq: chevre.factory.eventType.ScreeningEvent }, eventStatus: { $eq: chevre.factory.eventStatusType.EventScheduled } // 'project.id': { $eq: project.id }, // 'project.id': { $ne: EXCLUDED_PROJECT_ID }, }, { startDate: 1, endDate: 1, 'project.id': 1, _id: 1 } ); console.log('events found'); let i = 0; let numLongEvents = 0; await cursor.eachAsync(async (doc) => { i += 1; const event: Pick< chevre.factory.event.IEvent<chevre.factory.eventType.ScreeningEvent>, 'startDate' | 'endDate' | 'project' | 'id' > = doc.toObject(); const endDateShouldBe = moment(event.startDate) // tslint:disable-next-line:no-magic-numbers .add(31, 'days'); // const duration = moment(event.endDate) // .diff(moment(event.startDate)); if (moment(event.endDate) .isAfter(endDateShouldBe)) { numLongEvents += 1; console.log(event.project.id, event.id, 'is long'); } }); console.log(i, 'events checked'); console.log(numLongEvents, 'long events found'); } main() .then() .catch(console.error);