UNPKG

2.2 kBJavaScriptView Raw
1const moment = require('moment');
2const mongoose = require('mongoose');
3const domain = require('../');
4
5async function main() {
6 await mongoose.connect(process.env.MONGOLAB_URI);
7
8 const actionRepo = new domain.repository.Action(mongoose.connection);
9 const orderRepo = new domain.repository.Order(mongoose.connection);
10 const taskRepo = new domain.repository.Task(mongoose.connection);
11
12 // await domain.service.task.executeByName({
13 // project: { id: 'cinerino' },
14 // name: 'createOrderReport'
15 // })({ connection: mongoose.connection });
16
17 // return;
18
19 await domain.service.report.order.createReport({
20 typeOf: 'CreateAction',
21 project: { id: 'cinerino' },
22 agent: { name: 'sampleCode' },
23 // recipient: { name: 'recipientName' },
24 object: {
25 typeOf: 'Report',
26 about: 'OrderReport',
27 mentions: {
28 typeOf: 'SearchAction',
29 query: {
30 orderDateFrom: moment().add(-3, 'years').toDate(),
31 orderDateThrough: moment().toDate(),
32 },
33 object: {
34 typeOf: 'Order'
35 }
36 },
37 // format: domain.factory.encodingFormat.Application.json
38 encodingFormat: domain.factory.encodingFormat.Text.csv,
39 expires: moment().add(1, 'hour').toDate()
40 },
41 potentialActions: {
42 sendEmailMessage: [
43 {
44 object: {
45 about: 'レポートが使用可能です',
46 sender: {
47 name: 'Cinerino Report',
48 email: 'noreply@example.com'
49 },
50 toRecipient: { email: 'ilovegadd@gmail.com' }
51 }
52 }
53 ]
54 }
55 })({
56 action: actionRepo,
57 order: orderRepo,
58 task: taskRepo
59 });
60
61 // readable.on('data', function (data) {
62 // console.log(data);
63 // });
64}
65
66main().then(() => {
67 console.log('success!');
68}).catch((error) => {
69 console.error(error);
70 process.exit(1);
71});