UNPKG

@chevre/domain

Version:

Chevre Domain Library for Node.js

66 lines (56 loc) 2.37 kB
// tslint:disable:no-console import * as moment from 'moment'; import * as mongoose from 'mongoose'; import { chevre } from '../../../lib/index'; const CONSOLE_CLIENT_ID = 'xxx'; // const project = { id: String(process.env.PROJECT_ID) }; type IAction = chevre.factory.action.IAction<chevre.factory.action.IAttributes<chevre.factory.actionType, any, any>>; // tslint:disable-next-line:max-func-body-length async function main() { await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false }); const actionRepo = await chevre.repository.Action.createInstance(mongoose.connection); const cursor = actionRepo.getCursor( { typeOf: { $eq: chevre.factory.actionType.ReplaceAction }, 'object.typeOf': { $exists: true, $eq: chevre.factory.eventType.ScreeningEventSeries }, startDate: { $gte: moment() // tslint:disable-next-line:no-magic-numbers .add(-60, 'days') .toDate() } }, { } ); console.log('actions found'); let i = 0; await cursor.eachAsync(async (doc) => { i += 1; const action = <IAction>doc.toObject(); // const size = JSON.stringify(action).length; // // console.log(JSON.stringify(action).length); // if (action.typeOf !== chevre.factory.actionType.InformAction // && action.typeOf !== chevre.factory.actionType.AuthorizeAction // && action.typeOf !== chevre.factory.actionType.CheckAction // && size > 2000) { // console.log(action.typeOf, action.object?.typeOf); // console.log(size); // } const eventCount = (Array.isArray(action.object)) ? action.object.filter(({ typeOf }) => typeOf === chevre.factory.eventType.ScreeningEventSeries) .length : 0; if (action.instrument?.id !== CONSOLE_CLIENT_ID) { console.log(eventCount, 'events created', action.project.id, action.startDate, action.instrument?.id, i); // tslint:disable-next-line:no-magic-numbers if (eventCount > 20) { throw new Error('eventCount too large'); } } }); console.log(i, 'actions checked'); } main() .then() .catch(console.error);