1 | const moment = require('moment');
|
2 | const mongoose = require('mongoose');
|
3 | const domain = require('../lib');
|
4 |
|
5 | const project = { typeOf: 'Project', id: 'cinerino' };
|
6 |
|
7 | async function main() {
|
8 | await mongoose.connect(process.env.MONGOLAB_URI);
|
9 |
|
10 | const attributes = {
|
11 | name: 'createOrderReport',
|
12 | status: domain.factory.taskStatus.Ready,
|
13 | runsAt: moment()
|
14 | .toDate(),
|
15 | remainingNumberOfTries: 1,
|
16 | numberOfTried: 0,
|
17 | executionResults: [],
|
18 | data: {
|
19 | typeOf: 'CreateAction',
|
20 | project: project,
|
21 | agent: { name: 'sampleCode' },
|
22 |
|
23 | object: {
|
24 | typeOf: 'Report',
|
25 | about: `OrderReport${moment().unix()}`,
|
26 | mentions: {
|
27 | typeOf: 'SearchAction',
|
28 | query: {
|
29 | orderDateFrom: moment().add(-1, 'week').toDate(),
|
30 | orderDateThrough: moment().toDate(),
|
31 | },
|
32 | object: {
|
33 | typeOf: 'Order'
|
34 | }
|
35 | },
|
36 |
|
37 | encodingFormat: domain.factory.encodingFormat.Text.csv,
|
38 | expires: moment().add(1, 'hour').toDate()
|
39 | },
|
40 | potentialActions: {
|
41 | sendEmailMessage: [
|
42 | {
|
43 | object: {
|
44 | about: 'レポートが使用可能です',
|
45 | sender: {
|
46 | name: 'Cinerino Report',
|
47 | email: 'noreply@example.com'
|
48 | },
|
49 | toRecipient: { email: 'ilovegadd@gmail.com' }
|
50 | }
|
51 | }
|
52 | ]
|
53 | }
|
54 | },
|
55 | project: project
|
56 | };
|
57 |
|
58 | const taskRepo = new domain.repository.Task(mongoose.connection);
|
59 | const task = await taskRepo.save(attributes);
|
60 | console.log('task created', task.id);
|
61 | }
|
62 |
|
63 | main().then(() => {
|
64 | console.log('success!');
|
65 | }).catch((error) => {
|
66 | console.error(error);
|
67 | process.exit(1);
|
68 | });
|