@chevre/domain 21.2.0-alpha.7 → 21.2.0-alpha.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,17 @@
1
+ // tslint:disable:no-console
2
+ import * as mongoose from 'mongoose';
3
+
4
+ import { chevre } from '../../../lib/index';
5
+
6
+ export async function main() {
7
+ await mongoose.connect(<string>process.env.MONGOLAB_URI);
8
+
9
+ const taskRepo = new chevre.repository.Task(mongoose.connection);
10
+
11
+ const count = await taskRepo.countDelayedTasks({ delayInSeconds: 60 });
12
+ console.log('count:', count);
13
+ }
14
+
15
+ main()
16
+ .then()
17
+ .catch(console.error);
@@ -0,0 +1,36 @@
1
+ // tslint:disable:no-console
2
+ import * as moment from 'moment';
3
+ import * as mongoose from 'mongoose';
4
+
5
+ import { chevre } from '../../../lib/index';
6
+
7
+ const project = { id: String(process.env.PROJECT_ID) };
8
+
9
+ // tslint:disable-next-line:max-func-body-length
10
+ export async function main() {
11
+ const now = new Date();
12
+ await mongoose.connect(<string>process.env.MONGOLAB_URI);
13
+
14
+ const transactionRepo = new chevre.repository.Transaction(mongoose.connection);
15
+
16
+ const transactions = await transactionRepo.search<chevre.factory.transactionType.MoneyTransfer>(
17
+ {
18
+ project: { id: { $eq: project.id } },
19
+ typeOf: chevre.factory.transactionType.MoneyTransfer,
20
+ statuses: [chevre.factory.transactionStatusType.Confirmed],
21
+ startFrom: moment(now)
22
+ .add(-1, 'year')
23
+ .toDate(),
24
+ startThrough: now,
25
+ inclusion: ['_id', 'startDate', 'typeOf', 'object'],
26
+ exclusion: []
27
+ }
28
+ );
29
+ const count = transactions.filter((t) => t.object.description === '受け取り')
30
+ .length;
31
+ console.log('transactions found', count);
32
+ }
33
+
34
+ main()
35
+ .then()
36
+ .catch(console.error);
@@ -61,6 +61,9 @@ export declare class MongoRepository {
61
61
  deleteByName(params: {
62
62
  name: factory.taskName;
63
63
  }): Promise<import("mongodb").DeleteResult>;
64
+ countDelayedTasks(params: {
65
+ delayInSeconds: number;
66
+ }): Promise<number>;
64
67
  aggregateTask(params: {
65
68
  project?: {
66
69
  id?: {
@@ -340,6 +340,18 @@ class MongoRepository {
340
340
  .exec();
341
341
  });
342
342
  }
343
+ countDelayedTasks(params) {
344
+ return __awaiter(this, void 0, void 0, function* () {
345
+ const runsAtLt = moment()
346
+ .add(-params.delayInSeconds, 'seconds')
347
+ .toDate();
348
+ return this.taskModel.count({
349
+ status: factory.taskStatus.Ready,
350
+ runsAt: { $lt: runsAtLt }
351
+ })
352
+ .exec();
353
+ });
354
+ }
343
355
  aggregateTask(params) {
344
356
  return __awaiter(this, void 0, void 0, function* () {
345
357
  const statuses = yield Promise.all([
package/package.json CHANGED
@@ -117,5 +117,5 @@
117
117
  "postversion": "git push origin --tags",
118
118
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
119
119
  },
120
- "version": "21.2.0-alpha.7"
120
+ "version": "21.2.0-alpha.8"
121
121
  }