@chevre/domain 20.2.0-alpha.25 → 20.2.0-alpha.27

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.
@@ -18,7 +18,7 @@ async function main() {
18
18
  const taskRepo = new chevre.repository.Task(mongoose.connection);
19
19
 
20
20
  await aggregationRepo.aggregationModel.deleteMany({
21
- typeOf: { $in: ['AggregateOrder', 'AggregateReservation'] }
21
+ typeOf: { $in: ['AggregateOrder', 'AggregateReservation', 'AggregatePay', 'AggregateReserve'] }
22
22
  })
23
23
  .exec();
24
24
  await chevre.service.aggregation.system.aggregateReserveTransaction({
@@ -29,8 +29,14 @@ async function main() {
29
29
  assetTransaction: assetTransactionRepo
30
30
  });
31
31
 
32
- return;
33
-
32
+ await chevre.service.aggregation.system.aggregatePayTransaction({
33
+ aggregationDays: AGGREGATE_DAYS,
34
+ excludedProjectId: EXCLUDED_PROJECT_ID
35
+ })({
36
+ agregation: aggregationRepo,
37
+ assetTransaction: assetTransactionRepo
38
+ });
39
+ // return;
34
40
  await chevre.service.aggregation.system.aggregateTask({
35
41
  aggregationDays: AGGREGATE_DAYS,
36
42
  excludedProjectId: EXCLUDED_PROJECT_ID
@@ -0,0 +1,51 @@
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
+ // tslint:disable-next-line:max-func-body-length
8
+ async function main() {
9
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
10
+
11
+ const projectRepo = new chevre.repository.Project(mongoose.connection);
12
+
13
+ const cursor = projectRepo.getCursor(
14
+ {
15
+ },
16
+ {
17
+ // _id: 1,
18
+ }
19
+ );
20
+ console.log('projects found');
21
+
22
+ let i = 0;
23
+ let updateCount = 0;
24
+ // tslint:disable-next-line:max-func-body-length
25
+ await cursor.eachAsync(async (doc) => {
26
+ i += 1;
27
+ const project: chevre.factory.project.IProject = doc.toObject();
28
+
29
+ const useEventServiceAsProduct = project.subscription?.useEventServiceAsProduct;
30
+ const alreadyMigrated = useEventServiceAsProduct === true;
31
+
32
+ if (alreadyMigrated) {
33
+ console.log('already migrated.', project.id, i);
34
+ } else {
35
+ console.log(
36
+ 'updating product...', project.id, i);
37
+ await projectRepo.findByIdAndIUpdate({
38
+ id: project.id,
39
+ subscription: { useEventServiceAsProduct: true }
40
+ });
41
+ updateCount += 1;
42
+ console.log('updated...', project.id, i);
43
+ }
44
+ });
45
+ console.log(i, 'projects checked');
46
+ console.log(updateCount, 'projects updated');
47
+ }
48
+
49
+ main()
50
+ .then()
51
+ .catch(console.error);
@@ -5,6 +5,7 @@ export declare enum AggregationType {
5
5
  AggregateAuthorizeEventServiceOfferAction = "AggregateAuthorizeEventServiceOfferAction",
6
6
  AggregateAuthorizeOrderAction = "AggregateAuthorizeOrderAction",
7
7
  AggregateAuthorizePaymentAction = "AggregateAuthorizePaymentAction",
8
+ AggregatePay = "AggregatePay",
8
9
  AggregateReserve = "AggregateReserve",
9
10
  AggregateTask = "AggregateTask",
10
11
  AggregateUseAction = "AggregateUseAction"
@@ -28,6 +28,7 @@ var AggregationType;
28
28
  AggregationType["AggregateAuthorizeEventServiceOfferAction"] = "AggregateAuthorizeEventServiceOfferAction";
29
29
  AggregationType["AggregateAuthorizeOrderAction"] = "AggregateAuthorizeOrderAction";
30
30
  AggregationType["AggregateAuthorizePaymentAction"] = "AggregateAuthorizePaymentAction";
31
+ AggregationType["AggregatePay"] = "AggregatePay";
31
32
  AggregationType["AggregateReserve"] = "AggregateReserve";
32
33
  AggregationType["AggregateTask"] = "AggregateTask";
33
34
  AggregationType["AggregateUseAction"] = "AggregateUseAction";
@@ -144,7 +144,7 @@ export declare class MongoRepository {
144
144
  findByIdAndDelete(params: {
145
145
  id: string;
146
146
  }): Promise<void>;
147
- aggregateReserve(params: {
147
+ aggregateAssetTransaction(params: {
148
148
  project?: {
149
149
  id?: {
150
150
  $ne?: string;
@@ -536,7 +536,7 @@ class MongoRepository {
536
536
  .exec();
537
537
  });
538
538
  }
539
- aggregateReserve(params) {
539
+ aggregateAssetTransaction(params) {
540
540
  return __awaiter(this, void 0, void 0, function* () {
541
541
  const statuses = yield Promise.all([
542
542
  factory.transactionStatusType.Confirmed,
@@ -567,7 +567,13 @@ class MongoRepository {
567
567
  {
568
568
  $project: {
569
569
  duration: { $subtract: ['$endDate', '$startDate'] },
570
- graceTime: { $subtract: ['$object.reservationFor.startDate', '$startDate'] },
570
+ graceTime: {
571
+ $cond: {
572
+ if: { $eq: ['$typeOf', factory.assetTransactionType.Reserve] },
573
+ then: { $subtract: ['$object.reservationFor.startDate', '$startDate'] },
574
+ else: 0
575
+ }
576
+ },
571
577
  status: '$status',
572
578
  startDate: '$startDate',
573
579
  endDate: '$endDate',
@@ -10,6 +10,12 @@ const writeConcern = { j: true, w: 'majority', wtimeout: 10000 };
10
10
  */
11
11
  const schema = new mongoose.Schema({
12
12
  _id: String,
13
+ aggregateReservation: mongoose.SchemaTypes.Mixed,
14
+ alternateName: String,
15
+ logo: String,
16
+ name: String,
17
+ settings: mongoose.SchemaTypes.Mixed,
18
+ subscription: mongoose.SchemaTypes.Mixed,
13
19
  typeOf: {
14
20
  type: String,
15
21
  required: true
@@ -19,7 +25,7 @@ const schema = new mongoose.Schema({
19
25
  id: true,
20
26
  read: 'primaryPreferred',
21
27
  writeConcern: writeConcern,
22
- strict: false,
28
+ strict: true,
23
29
  useNestedStrict: true,
24
30
  timestamps: {
25
31
  createdAt: 'createdAt',
@@ -10,7 +10,6 @@ export declare class MongoRepository {
10
10
  findById(conditions: {
11
11
  id: string;
12
12
  }, projection?: any): Promise<factory.project.IProject>;
13
- count(params: factory.project.ISearchConditions): Promise<number>;
14
13
  /**
15
14
  * プロジェクト検索
16
15
  */
@@ -24,6 +23,9 @@ export declare class MongoRepository {
24
23
  settings?: {
25
24
  sendgridApiKey?: string;
26
25
  };
26
+ subscription?: {
27
+ useEventServiceAsProduct?: boolean;
28
+ };
27
29
  }): Promise<void>;
28
30
  updateAggregateReservation(params: {
29
31
  id: string;
@@ -32,4 +34,5 @@ export declare class MongoRepository {
32
34
  deleteById(params: {
33
35
  id: string;
34
36
  }): Promise<void>;
37
+ getCursor(conditions: any, projection: any): import("mongoose").QueryCursor<any>;
35
38
  }
@@ -61,14 +61,6 @@ class MongoRepository {
61
61
  return doc.toObject();
62
62
  });
63
63
  }
64
- count(params) {
65
- return __awaiter(this, void 0, void 0, function* () {
66
- const conditions = MongoRepository.CREATE_MONGO_CONDITIONS(params);
67
- return this.projectModel.countDocuments((conditions.length > 0) ? { $and: conditions } : {})
68
- .setOptions({ maxTimeMS: 10000 })
69
- .exec();
70
- });
71
- }
72
64
  /**
73
65
  * プロジェクト検索
74
66
  */
@@ -98,12 +90,14 @@ class MongoRepository {
98
90
  });
99
91
  }
100
92
  findByIdAndIUpdate(params) {
101
- var _a;
93
+ var _a, _b;
102
94
  return __awaiter(this, void 0, void 0, function* () {
103
- yield this.projectModel.findOneAndUpdate({ _id: params.id }, Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ updatedAt: new Date() }, (typeof params.alternateName === 'string' && params.alternateName.length > 0)
95
+ yield this.projectModel.findOneAndUpdate({ _id: params.id }, Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ updatedAt: new Date() }, (typeof params.alternateName === 'string' && params.alternateName.length > 0)
104
96
  ? { alternateName: params.alternateName }
105
97
  : undefined), (typeof params.name === 'string' && params.name.length > 0) ? { name: params.name } : undefined), (typeof params.logo === 'string' && params.logo.length > 0) ? { logo: params.logo } : undefined), (typeof ((_a = params.settings) === null || _a === void 0 ? void 0 : _a.sendgridApiKey) === 'string')
106
98
  ? { 'settings.sendgridApiKey': params.settings.sendgridApiKey }
99
+ : undefined), (typeof ((_b = params.subscription) === null || _b === void 0 ? void 0 : _b.useEventServiceAsProduct) === 'boolean')
100
+ ? { 'subscription.useEventServiceAsProduct': params.subscription.useEventServiceAsProduct }
107
101
  : undefined), {
108
102
  // ↓customerUserPoolは廃止
109
103
  $unset: {
@@ -131,5 +125,10 @@ class MongoRepository {
131
125
  .exec();
132
126
  });
133
127
  }
128
+ getCursor(conditions, projection) {
129
+ return this.projectModel.find(conditions, projection)
130
+ .sort({ _id: factory.sortType.Ascending })
131
+ .cursor();
132
+ }
134
133
  }
135
134
  exports.MongoRepository = MongoRepository;
@@ -51,6 +51,13 @@ declare function aggregateUseAction(params: {
51
51
  agregation: AggregationRepo;
52
52
  action: ActionRepo;
53
53
  }) => Promise<void>;
54
+ declare function aggregatePayTransaction(params: {
55
+ aggregationDays: number;
56
+ excludedProjectId?: string;
57
+ }): (repos: {
58
+ agregation: AggregationRepo;
59
+ assetTransaction: AssetTransactionRepo;
60
+ }) => Promise<void>;
54
61
  /**
55
62
  * 予約集計
56
63
  */
@@ -68,4 +75,4 @@ declare function aggregateTask(params: {
68
75
  agregation: AggregationRepo;
69
76
  task: TasKRepo;
70
77
  }) => Promise<void>;
71
- export { aggregateAuthorizeEventServiceOfferAction, aggregateAuthorizeOrderAction, aggregateAuthorizePaymentAction, aggregatePlaceOrder, aggregateReserveTransaction, aggregateTask, aggregateUseAction };
78
+ export { aggregateAuthorizeEventServiceOfferAction, aggregateAuthorizeOrderAction, aggregateAuthorizePaymentAction, aggregatePayTransaction, aggregatePlaceOrder, aggregateReserveTransaction, aggregateTask, aggregateUseAction };
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.aggregateUseAction = exports.aggregateTask = exports.aggregateReserveTransaction = exports.aggregatePlaceOrder = exports.aggregateAuthorizePaymentAction = exports.aggregateAuthorizeOrderAction = exports.aggregateAuthorizeEventServiceOfferAction = void 0;
12
+ exports.aggregateUseAction = exports.aggregateTask = exports.aggregateReserveTransaction = exports.aggregatePlaceOrder = exports.aggregatePayTransaction = exports.aggregateAuthorizePaymentAction = exports.aggregateAuthorizeOrderAction = exports.aggregateAuthorizeEventServiceOfferAction = void 0;
13
13
  const createDebug = require("debug");
14
14
  const moment = require("moment-timezone");
15
15
  const factory = require("../../factory");
@@ -28,11 +28,13 @@ function aggregatePlaceOrder(params) {
28
28
  while (i < params.aggregationDays) {
29
29
  i += 1;
30
30
  const startFrom = moment()
31
+ .utc()
31
32
  // .tz('Asia/Tokyo')
32
33
  .add(-i, 'days')
33
34
  .startOf('day')
34
35
  .toDate();
35
36
  const startThrough = moment()
37
+ .utc()
36
38
  // .tz('Asia/Tokyo')
37
39
  .add(-i, 'days')
38
40
  .endOf('day')
@@ -79,11 +81,13 @@ function aggregateAuthorizeEventServiceOfferAction(params) {
79
81
  while (i < params.aggregationDays) {
80
82
  i += 1;
81
83
  const startFrom = moment()
84
+ .utc()
82
85
  // .tz('Asia/Tokyo')
83
86
  .add(-i, 'days')
84
87
  .startOf('day')
85
88
  .toDate();
86
89
  const startThrough = moment()
90
+ .utc()
87
91
  // .tz('Asia/Tokyo')
88
92
  .add(-i, 'days')
89
93
  .endOf('day')
@@ -113,11 +117,13 @@ function aggregateAuthorizePaymentAction(params) {
113
117
  while (i < params.aggregationDays) {
114
118
  i += 1;
115
119
  const startFrom = moment()
120
+ .utc()
116
121
  // .tz('Asia/Tokyo')
117
122
  .add(-i, 'days')
118
123
  .startOf('day')
119
124
  .toDate();
120
125
  const startThrough = moment()
126
+ .utc()
121
127
  // .tz('Asia/Tokyo')
122
128
  .add(-i, 'days')
123
129
  .endOf('day')
@@ -144,11 +150,13 @@ function aggregateAuthorizeOrderAction(params) {
144
150
  while (i < params.aggregationDays) {
145
151
  i += 1;
146
152
  const startFrom = moment()
153
+ .utc()
147
154
  // .tz('Asia/Tokyo')
148
155
  .add(-i, 'days')
149
156
  .startOf('day')
150
157
  .toDate();
151
158
  const startThrough = moment()
159
+ .utc()
152
160
  // .tz('Asia/Tokyo')
153
161
  .add(-i, 'days')
154
162
  .endOf('day')
@@ -178,11 +186,13 @@ function aggregateUseAction(params) {
178
186
  while (i < params.aggregationDays) {
179
187
  i += 1;
180
188
  const startFrom = moment()
189
+ .utc()
181
190
  // .tz('Asia/Tokyo')
182
191
  .add(-i, 'days')
183
192
  .startOf('day')
184
193
  .toDate();
185
194
  const startThrough = moment()
195
+ .utc()
186
196
  // .tz('Asia/Tokyo')
187
197
  .add(-i, 'days')
188
198
  .endOf('day')
@@ -199,6 +209,39 @@ function aggregateUseAction(params) {
199
209
  });
200
210
  }
201
211
  exports.aggregateUseAction = aggregateUseAction;
212
+ function aggregatePayTransaction(params) {
213
+ return (repos) => __awaiter(this, void 0, void 0, function* () {
214
+ var _a;
215
+ const aggregateDate = new Date();
216
+ const aggregateDuration = moment.duration(1, 'days')
217
+ .toISOString();
218
+ let i = -1;
219
+ while (i < params.aggregationDays) {
220
+ i += 1;
221
+ const startFrom = moment()
222
+ .utc()
223
+ // .tz('Asia/Tokyo')
224
+ .add(-i, 'days')
225
+ .startOf('day')
226
+ .toDate();
227
+ const startThrough = moment()
228
+ .utc()
229
+ // .tz('Asia/Tokyo')
230
+ .add(-i, 'days')
231
+ .endOf('day')
232
+ .toDate();
233
+ const aggregateResult = yield repos.assetTransaction.aggregateAssetTransaction({
234
+ project: { id: { $ne: params.excludedProjectId } },
235
+ startFrom,
236
+ startThrough,
237
+ typeOf: factory.assetTransactionType.Pay
238
+ });
239
+ debug('aggregatePayTransaction:result', aggregateResult, (_a = aggregateResult.statuses[0]) === null || _a === void 0 ? void 0 : _a.aggregation, startFrom);
240
+ yield repos.agregation.saveAggregation(Object.assign({ typeOf: aggregation_1.AggregationType.AggregatePay, project: { id: '*', typeOf: factory.organizationType.Project }, aggregateDuration, aggregateStart: startFrom, aggregateDate }, aggregateResult));
241
+ }
242
+ });
243
+ }
244
+ exports.aggregatePayTransaction = aggregatePayTransaction;
202
245
  /**
203
246
  * 予約集計
204
247
  */
@@ -212,16 +255,18 @@ function aggregateReserveTransaction(params) {
212
255
  while (i < params.aggregationDays) {
213
256
  i += 1;
214
257
  const startFrom = moment()
258
+ .utc()
215
259
  // .tz('Asia/Tokyo')
216
260
  .add(-i, 'days')
217
261
  .startOf('day')
218
262
  .toDate();
219
263
  const startThrough = moment()
264
+ .utc()
220
265
  // .tz('Asia/Tokyo')
221
266
  .add(-i, 'days')
222
267
  .endOf('day')
223
268
  .toDate();
224
- const aggregateResult = yield repos.assetTransaction.aggregateReserve({
269
+ const aggregateResult = yield repos.assetTransaction.aggregateAssetTransaction({
225
270
  project: { id: { $ne: params.excludedProjectId } },
226
271
  startFrom,
227
272
  startThrough,
@@ -243,11 +288,13 @@ function aggregateTask(params) {
243
288
  while (i < params.aggregationDays) {
244
289
  i += 1;
245
290
  const runsFrom = moment()
291
+ .utc()
246
292
  // .tz('Asia/Tokyo')
247
293
  .add(-i, 'days')
248
294
  .startOf('day')
249
295
  .toDate();
250
296
  const runsThrough = moment()
297
+ .utc()
251
298
  // .tz('Asia/Tokyo')
252
299
  .add(-i, 'days')
253
300
  .endOf('day')
package/package.json CHANGED
@@ -120,5 +120,5 @@
120
120
  "postversion": "git push origin --tags",
121
121
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
122
122
  },
123
- "version": "20.2.0-alpha.25"
123
+ "version": "20.2.0-alpha.27"
124
124
  }
@@ -1,77 +0,0 @@
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
- const EXCLUDED_PROJECT_ID = process.env.EXCLUDED_PROJECT_ID;
9
-
10
- // tslint:disable-next-line:max-func-body-length
11
- async function main() {
12
- await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
13
-
14
- const productRepo = new chevre.repository.Product(mongoose.connection);
15
-
16
- const cursor = productRepo.getCursor(
17
- {
18
- // 'project.id': { $eq: project.id },
19
- 'project.id': { $ne: EXCLUDED_PROJECT_ID },
20
- typeOf: { $eq: chevre.factory.service.paymentService.PaymentServiceType.CreditCard }
21
- },
22
- {
23
- // _id: 1,
24
- }
25
- );
26
- console.log('products found');
27
-
28
- let i = 0;
29
- let updateCount = 0;
30
- // tslint:disable-next-line:max-func-body-length
31
- await cursor.eachAsync(async (doc) => {
32
- i += 1;
33
- const paymentService: chevre.factory.service.paymentService.IService = doc.toObject();
34
-
35
- const hasPaymentUrlExpiresInseconds = paymentService.provider?.some((provider) => {
36
- return typeof (<any>provider).credentials?.paymentUrlExpiresInSeconds === 'number';
37
- });
38
-
39
- if (!hasPaymentUrlExpiresInseconds) {
40
- console.log(
41
- 'no expiresInSeconds', paymentService.project.id, paymentService.id, paymentService.productID, i);
42
-
43
- return;
44
- }
45
-
46
- const alreadyMigrated = paymentService.provider?.filter((provider) => {
47
- return typeof (<any>provider).credentials?.paymentUrlExpiresInSeconds === 'number';
48
- })
49
- .every((provider) => {
50
- return typeof provider.credentials?.paymentUrl?.expiresInSeconds === 'number';
51
- });
52
-
53
- if (alreadyMigrated) {
54
- console.log(
55
- 'already exist...', paymentService.project.id, paymentService.id, paymentService.productID, i);
56
- } else {
57
- console.log(
58
- 'updating product...', paymentService.project.id, paymentService.id, paymentService.productID, i);
59
- // await eventRepo.updatePartiallyById({
60
- // id: event.id,
61
- // attributes: <any>{
62
- // typeOf: event.typeOf,
63
- // 'offers.itemOffered.availableChannel': newAvailableChannel
64
- // }
65
- // });
66
- updateCount += 1;
67
- console.log(
68
- 'updated...', paymentService.project.id, paymentService.id, paymentService.productID, i);
69
- }
70
- });
71
- console.log(i, 'products checked');
72
- console.log(updateCount, 'products updated');
73
- }
74
-
75
- main()
76
- .then()
77
- .catch(console.error);