1 | const fs = require('fs');
|
2 | const moment = require('moment');
|
3 | const mongoose = require('mongoose');
|
4 |
|
5 | const domain = require('../');
|
6 |
|
7 | async function main() {
|
8 | await mongoose.connect(process.env.MONGOLAB_URI, {
|
9 | useUnifiedTopology: true
|
10 | });
|
11 |
|
12 | const ownershipInfoRepo = new domain.repository.OwnershipInfo(mongoose.connection);
|
13 |
|
14 | const now = moment('2020-05-30T15:00:00Z')
|
15 | .toDate();
|
16 |
|
17 | const readable = await domain.service.report.ownershipInfo.stream({
|
18 | conditions: {
|
19 | project: { id: { $eq: 'sskts-production' } },
|
20 | typeOfGood: {
|
21 | typeOf: 'ProgramMembership'
|
22 | },
|
23 | ownedFrom: now,
|
24 | ownedThrough: now,
|
25 |
|
26 | },
|
27 | format: domain.factory.encodingFormat.Text.csv
|
28 | })({
|
29 | ownershipInfo: ownershipInfoRepo
|
30 | });
|
31 |
|
32 | readable.on('data', function (data) {
|
33 | console.log(data);
|
34 | });
|
35 | readable.on('end', function (data) {
|
36 | console.log('all read!');
|
37 | });
|
38 |
|
39 | const stream = fs.createWriteStream('test.csv');
|
40 | readable.pipe(stream);
|
41 |
|
42 |
|
43 |
|
44 | }
|
45 |
|
46 | main().then(() => {
|
47 | console.log('success!');
|
48 | }).catch((error) => {
|
49 | console.error(error);
|
50 | process.exit(1);
|
51 | });
|