@chevre/domain
Version:
Chevre Domain Library for Node.js
202 lines (180 loc) • 9.12 kB
text/typescript
// tslint:disable:no-console
import * as mongoose from 'mongoose';
import { chevre } from '../../../../lib/index';
const EXCLUDED_PROJECT_ID = process.env.EXCLUDED_PROJECT_ID;
const AGGREGATE_DURATION_UNIT = <'days' | 'hours'>String(process.env.AGGREGATE_DURATION_UNIT);
const AGGREGATE_DAYS = Number(process.env.AGGREGATE_DAYS);
const AGGREGATE_CLIENT_IDS = (typeof process.env.AGGREGATE_CLIENT_IDS === 'string') ? process.env.AGGREGATE_CLIENT_IDS.split(' ') : [];
const ONE_DAY_IN_HOURS = 24;
console.log('AGGREGATE_CLIENT_IDS:', AGGREGATE_CLIENT_IDS);
// tslint:disable-next-line:max-func-body-length
async function main() {
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
const aggregationRepo = await chevre.repository.Aggregation.createInstance(mongoose.connection);
const eventRepo = await chevre.repository.Event.createInstance(mongoose.connection);
const orderRepo = await chevre.repository.Order.createInstance(mongoose.connection);
const transactionRepo = await chevre.repository.Transaction.createInstance(mongoose.connection);
const assetTransactionRepo = await chevre.repository.AssetTransaction.createInstance(mongoose.connection);
const actionRepo = await chevre.repository.Action.createInstance(mongoose.connection);
const taskRepo = await chevre.repository.Task.createInstance(mongoose.connection);
const aggregateDate = new Date();
let result: { aggregationCount: number; aggregateDuration: string };
result = await (await chevre.service.aggregation.createService()).system.aggregateOrder({
aggregateDate,
aggregateDurationUnit: AGGREGATE_DURATION_UNIT,
aggregationCount: (AGGREGATE_DURATION_UNIT === 'hours') ? AGGREGATE_DAYS * ONE_DAY_IN_HOURS : AGGREGATE_DAYS,
excludedProjectId: EXCLUDED_PROJECT_ID
})({
agregation: aggregationRepo,
order: orderRepo
});
console.log('aggregateOrder processed.', result);
// return;
result = await (await chevre.service.aggregation.createService()).system.aggregatePlaceOrder({
aggregateDate,
aggregateDurationUnit: AGGREGATE_DURATION_UNIT,
aggregationCount: (AGGREGATE_DURATION_UNIT === 'hours') ? AGGREGATE_DAYS * ONE_DAY_IN_HOURS : AGGREGATE_DAYS,
excludedProjectId: EXCLUDED_PROJECT_ID,
clientIds: AGGREGATE_CLIENT_IDS
})({
agregation: aggregationRepo,
transaction: transactionRepo
});
console.log('aggregatePlaceOrder processed.', result);
// return;
result = await (await chevre.service.aggregation.createService()).system.aggregateReserveAction({
aggregateDate,
aggregateDurationUnit: AGGREGATE_DURATION_UNIT,
aggregationCount: (AGGREGATE_DURATION_UNIT === 'hours') ? AGGREGATE_DAYS * ONE_DAY_IN_HOURS : AGGREGATE_DAYS,
excludedProjectId: EXCLUDED_PROJECT_ID
})({
agregation: aggregationRepo,
action: actionRepo
});
console.log('aggregateReserveAction processed.', result);
result = await (await chevre.service.aggregation.createService()).system.aggregateOrderAction({
aggregateDate,
aggregateDurationUnit: AGGREGATE_DURATION_UNIT,
aggregationCount: (AGGREGATE_DURATION_UNIT === 'hours') ? AGGREGATE_DAYS * ONE_DAY_IN_HOURS : AGGREGATE_DAYS,
excludedProjectId: EXCLUDED_PROJECT_ID
})({
agregation: aggregationRepo,
action: actionRepo
});
console.log('aggregateReserveAction processed.', result);
result = await (await chevre.service.aggregation.createService()).system.aggregateCancelReservationAction({
aggregateDate,
aggregateDurationUnit: AGGREGATE_DURATION_UNIT,
aggregationCount: (AGGREGATE_DURATION_UNIT === 'hours') ? AGGREGATE_DAYS * ONE_DAY_IN_HOURS : AGGREGATE_DAYS,
excludedProjectId: EXCLUDED_PROJECT_ID
})({
agregation: aggregationRepo,
action: actionRepo
});
console.log('aggregateCancelReservationAction processed.', result);
result = await (await chevre.service.aggregation.createService()).system.aggregateTask({
aggregateDate,
aggregateDurationUnit: AGGREGATE_DURATION_UNIT,
aggregationCount: (AGGREGATE_DURATION_UNIT === 'hours') ? AGGREGATE_DAYS * ONE_DAY_IN_HOURS : AGGREGATE_DAYS,
excludedProjectId: EXCLUDED_PROJECT_ID
})({
agregation: aggregationRepo,
task: taskRepo
});
console.log('aggregateTask processed.', result);
result = await (await chevre.service.aggregation.createService()).system.aggregatePayMovieTicketAction({
aggregateDate,
aggregateDurationUnit: AGGREGATE_DURATION_UNIT,
aggregationCount: (AGGREGATE_DURATION_UNIT === 'hours') ? AGGREGATE_DAYS * ONE_DAY_IN_HOURS : AGGREGATE_DAYS,
excludedProjectId: EXCLUDED_PROJECT_ID
})({
agregation: aggregationRepo,
action: actionRepo
});
console.log('aggregatePayMovieTicketAction processed.', result);
result = await (await chevre.service.aggregation.createService()).system.aggregatePayTransaction({
aggregateDate,
aggregateDurationUnit: AGGREGATE_DURATION_UNIT,
aggregationCount: (AGGREGATE_DURATION_UNIT === 'hours') ? AGGREGATE_DAYS * ONE_DAY_IN_HOURS : AGGREGATE_DAYS,
excludedProjectId: EXCLUDED_PROJECT_ID
})({
agregation: aggregationRepo,
assetTransaction: assetTransactionRepo
});
console.log('aggregatePayTransaction processed.', result);
result = await (await chevre.service.aggregation.createService()).system.aggregateEvent({
aggregateDate,
aggregateDurationUnit: AGGREGATE_DURATION_UNIT,
aggregationCount: (AGGREGATE_DURATION_UNIT === 'hours') ? AGGREGATE_DAYS * ONE_DAY_IN_HOURS : AGGREGATE_DAYS,
excludedProjectId: EXCLUDED_PROJECT_ID
})({
agregation: aggregationRepo,
event: eventRepo
});
console.log('aggregateEvent processed.', result);
result = await (await chevre.service.aggregation.createService()).system.aggregateReserveTransaction({
aggregateDate,
aggregateDurationUnit: AGGREGATE_DURATION_UNIT,
aggregationCount: (AGGREGATE_DURATION_UNIT === 'hours') ? AGGREGATE_DAYS * ONE_DAY_IN_HOURS : AGGREGATE_DAYS,
excludedProjectId: EXCLUDED_PROJECT_ID
})({
agregation: aggregationRepo,
assetTransaction: assetTransactionRepo
});
console.log('aggregateReserveTransaction processed.', result);
result = await (await chevre.service.aggregation.createService()).system.aggregateAuthorizeOrderAction({
aggregateDate,
aggregateDurationUnit: AGGREGATE_DURATION_UNIT,
aggregationCount: (AGGREGATE_DURATION_UNIT === 'hours') ? AGGREGATE_DAYS * ONE_DAY_IN_HOURS : AGGREGATE_DAYS,
excludedProjectId: EXCLUDED_PROJECT_ID
})({
agregation: aggregationRepo,
action: actionRepo
});
console.log('aggregateAuthorizeOrderAction processed.', result);
result = await (await chevre.service.aggregation.createService()).system.aggregateAuthorizeEventServiceOfferAction({
aggregateDate,
aggregateDurationUnit: AGGREGATE_DURATION_UNIT,
aggregationCount: (AGGREGATE_DURATION_UNIT === 'hours') ? AGGREGATE_DAYS * ONE_DAY_IN_HOURS : AGGREGATE_DAYS,
excludedProjectId: EXCLUDED_PROJECT_ID
})({
agregation: aggregationRepo,
action: actionRepo
});
console.log('aggregateAuthorizeEventServiceOfferAction processed.', result);
result = await (await chevre.service.aggregation.createService()).system.aggregateAuthorizePaymentAction({
aggregateDate,
aggregateDurationUnit: AGGREGATE_DURATION_UNIT,
aggregationCount: (AGGREGATE_DURATION_UNIT === 'hours') ? AGGREGATE_DAYS * ONE_DAY_IN_HOURS : AGGREGATE_DAYS,
excludedProjectId: EXCLUDED_PROJECT_ID
})({
agregation: aggregationRepo,
action: actionRepo
});
console.log('aggregateAuthorizePaymentAction processed.', result);
result = await (await chevre.service.aggregation.createService()).system.aggregateUseAction({
aggregateDate,
aggregateDurationUnit: AGGREGATE_DURATION_UNIT,
aggregationCount: (AGGREGATE_DURATION_UNIT === 'hours') ? AGGREGATE_DAYS * ONE_DAY_IN_HOURS : AGGREGATE_DAYS,
excludedProjectId: EXCLUDED_PROJECT_ID
})({
agregation: aggregationRepo,
action: actionRepo
});
console.log('aggregateUseAction processed.', result);
result = await (await chevre.service.aggregation.createService()).system.aggregateCheckMovieTicketAction({
aggregateDate,
aggregateDurationUnit: AGGREGATE_DURATION_UNIT,
aggregationCount: (AGGREGATE_DURATION_UNIT === 'hours') ? AGGREGATE_DAYS * ONE_DAY_IN_HOURS : AGGREGATE_DAYS,
excludedProjectId: EXCLUDED_PROJECT_ID
})({
agregation: aggregationRepo,
action: actionRepo
});
console.log('aggregateCheckMovieTicketAction processed.', result);
}
main()
.then(() => {
console.log('success!');
})
.catch(console.error);