@chevre/domain 21.7.0-alpha.10 → 21.7.0-alpha.12

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,103 @@
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 now = new Date();
12
+ const endDateLt: Date = moment(now)
13
+ // tslint:disable-next-line:no-magic-numbers
14
+ .add(-365, 'days')
15
+ .toDate();
16
+ const startDateLt: Date = moment('2021-02-01T00:00:00Z')
17
+ .toDate();
18
+
19
+ const taskRepo = new chevre.repository.Task(mongoose.connection);
20
+ const transactionRepo = new chevre.repository.Transaction(mongoose.connection);
21
+
22
+ const cursor = transactionRepo.getCursor(
23
+ {
24
+ typeOf: { $eq: chevre.factory.transactionType.PlaceOrder },
25
+ startDate: {
26
+ // $exists: true,
27
+ $lt: startDateLt
28
+ }
29
+ // endDate: {
30
+ // $exists: true,
31
+ // $lt: moment(now)
32
+ // // tslint:disable-next-line:no-magic-numbers
33
+ // .add(-365, 'days')
34
+ // .toDate()
35
+ // }
36
+ },
37
+ {
38
+ _id: 1,
39
+ typeOf: 1,
40
+ project: 1,
41
+ startDate: 1,
42
+ endDate: 1,
43
+ object: 1
44
+ }
45
+ );
46
+ console.log('transactions found');
47
+
48
+ let i = 0;
49
+ let updateCount = 0;
50
+ await cursor.eachAsync(async (doc) => {
51
+ i += 1;
52
+ const transaction: Pick<
53
+ chevre.factory.transaction.placeOrder.ITransaction,
54
+ 'id' | 'project' | 'typeOf' | 'startDate' | 'endDate' | 'object'
55
+ > = doc.toObject();
56
+ console.log('checking...', transaction.project.id, transaction.id, transaction.startDate, transaction.endDate, i);
57
+
58
+ const isEndDateBefore = transaction.endDate !== undefined && moment(transaction.endDate)
59
+ .isBefore(endDateLt);
60
+ if (isEndDateBefore) {
61
+ updateCount += 1;
62
+ const deleteTransactionTask: chevre.factory.task.deleteTransaction.IAttributes = {
63
+ project: transaction.project,
64
+ name: chevre.factory.taskName.DeleteTransaction,
65
+ status: chevre.factory.taskStatus.Ready,
66
+ runsAt: now,
67
+ remainingNumberOfTries: 3,
68
+ numberOfTried: 0,
69
+ executionResults: [],
70
+ data: {
71
+ object: {
72
+ specifyingMethod: chevre.factory.task.deleteTransaction.SpecifyingMethod.Id,
73
+ endDate: transaction.endDate,
74
+ id: transaction.id,
75
+ object: {
76
+ ...(typeof transaction.object.confirmationNumber === 'string')
77
+ ? { confirmationNumber: transaction.object.confirmationNumber }
78
+ : undefined,
79
+ ...(typeof transaction.object.orderNumber === 'string')
80
+ ? { orderNumber: transaction.object.orderNumber }
81
+ : undefined
82
+ },
83
+ project: transaction.project,
84
+ startDate: transaction.startDate,
85
+ typeOf: transaction.typeOf
86
+ }
87
+ }
88
+ };
89
+ console.log(
90
+ 'saving task...',
91
+ deleteTransactionTask, transaction.project.id, transaction.id, transaction.startDate, transaction.endDate, i);
92
+ await taskRepo.saveMany([deleteTransactionTask], { emitImmediately: false });
93
+ console.log('task saved', transaction.project.id, transaction.id, transaction.startDate, transaction.endDate, i);
94
+ }
95
+ });
96
+
97
+ console.log(i, 'transactions checked');
98
+ console.log(updateCount, 'transactions updated');
99
+ }
100
+
101
+ main()
102
+ .then()
103
+ .catch(console.error);
@@ -14,7 +14,7 @@ async function main() {
14
14
  let updateResult: any;
15
15
  updateResult = await transactionRepo.unsetUnnecessaryFields({
16
16
  filter: {
17
- 'project.id': { $eq: PROJECT_ID },
17
+ // 'project.id': { $eq: PROJECT_ID },
18
18
  typeOf: { $eq: chevre.factory.transactionType.PlaceOrder },
19
19
  status: { $eq: chevre.factory.transactionStatusType.Confirmed },
20
20
  startDate: {
@@ -1,3 +1,27 @@
1
+ /// <reference types="mongoose/types/aggregate" />
2
+ /// <reference types="mongoose/types/callback" />
3
+ /// <reference types="mongoose/types/collection" />
4
+ /// <reference types="mongoose/types/connection" />
5
+ /// <reference types="mongoose/types/cursor" />
6
+ /// <reference types="mongoose/types/document" />
7
+ /// <reference types="mongoose/types/error" />
8
+ /// <reference types="mongoose/types/expressions" />
9
+ /// <reference types="mongoose/types/helpers" />
10
+ /// <reference types="mongoose/types/middlewares" />
11
+ /// <reference types="mongoose/types/indexes" />
12
+ /// <reference types="mongoose/types/models" />
13
+ /// <reference types="mongoose/types/mongooseoptions" />
14
+ /// <reference types="mongoose/types/pipelinestage" />
15
+ /// <reference types="mongoose/types/populate" />
16
+ /// <reference types="mongoose/types/query" />
17
+ /// <reference types="mongoose/types/schemaoptions" />
18
+ /// <reference types="mongoose/types/schematypes" />
19
+ /// <reference types="mongoose/types/session" />
20
+ /// <reference types="mongoose/types/types" />
21
+ /// <reference types="mongoose/types/utility" />
22
+ /// <reference types="mongoose/types/validation" />
23
+ /// <reference types="mongoose/types/virtuals" />
24
+ /// <reference types="mongoose/types/inferschematype" />
1
25
  import { Connection } from 'mongoose';
2
26
  import * as factory from '../factory';
3
27
  interface IAggregationByStatus {
@@ -193,6 +217,7 @@ export declare class MongoRepository {
193
217
  filter: any;
194
218
  $unset: any;
195
219
  }): Promise<import("mongodb").UpdateResult>;
220
+ getCursor(conditions: any, projection: any): import("mongoose").Cursor<any, import("mongoose").QueryOptions<any>>;
196
221
  aggregatePlaceOrder(params: {
197
222
  project?: {
198
223
  id?: {
@@ -776,6 +776,11 @@ class MongoRepository {
776
776
  .exec();
777
777
  });
778
778
  }
779
+ getCursor(conditions, projection) {
780
+ return this.transactionModel.find(conditions, projection)
781
+ .sort({ startDate: factory.sortType.Descending })
782
+ .cursor();
783
+ }
779
784
  aggregatePlaceOrder(params) {
780
785
  return __awaiter(this, void 0, void 0, function* () {
781
786
  const statuses = yield Promise.all([
@@ -20,4 +20,18 @@ export declare function createConfirmReservationActionObject4COAByOrder(params:
20
20
  export declare function createConfirmRegisterServiceActionObjectByOrder(params: {
21
21
  order: factory.order.IOrder;
22
22
  }): factory.action.interact.confirm.registerService.IObject[];
23
+ export type IExternalOrder = Pick<factory.order.IOrder, 'project' | 'typeOf' | 'seller' | 'customer' | 'confirmationNumber' | 'orderNumber' | 'price' | 'priceCurrency' | 'orderDate' | 'name' | 'orderStatus' | 'orderedItem' | 'paymentMethods'>;
24
+ /**
25
+ * 注文作成後のアクション
26
+ */
27
+ export declare function createOnPlaceOrderTasksByTransaction(params: {
28
+ object: factory.order.IOrder | IExternalOrder;
29
+ potentialActions?: factory.action.trade.order.IPotentialActions;
30
+ }): factory.task.IAttributes<factory.taskName>[];
31
+ /**
32
+ * 注文配送後のアクション
33
+ */
34
+ export declare function createOnOrderSentTasksByTransaction(params: {
35
+ potentialActions?: factory.action.transfer.send.order.IPotentialActions;
36
+ }): (import("@chevre/factory/lib/task").IAttributes | import("@chevre/factory/lib/task/confirmMoneyTransfer").IAttributes | import("@chevre/factory/lib/task/confirmRegisterService").IAttributes | import("@chevre/factory/lib/task/confirmPayTransaction").IAttributes | import("@chevre/factory/lib/task/confirmRegisterServiceTransaction").IAttributes | import("@chevre/factory/lib/task/confirmReserveTransaction").IAttributes | import("@chevre/factory/lib/task/createEvent").IAttributes | import("@chevre/factory/lib/task/deleteTransaction").IAttributes | import("@chevre/factory/lib/task/givePointAward").IAttributes | import("@chevre/factory/lib/task/onAuthorizationCreated").IAttributes | import("@chevre/factory/lib/task/onEventChanged").IAttributes | import("@chevre/factory/lib/task/onResourceUpdated").IAttributes | import("@chevre/factory/lib/task/orderProgramMembership").IAttributes | import("@chevre/factory/lib/task/placeOrder").IAttributes | import("@chevre/factory/lib/task/returnOrder").IAttributes | import("@chevre/factory/lib/task/returnMoneyTransfer").IAttributes | import("@chevre/factory/lib/task/returnPayTransaction").IAttributes | import("@chevre/factory/lib/task/returnPointAward").IAttributes | import("@chevre/factory/lib/task/returnReserveTransaction").IAttributes | import("@chevre/factory/lib/task/sendEmailMessage").IAttributes | import("@chevre/factory/lib/task/sendOrder").IAttributes | import("@chevre/factory/lib/task/syncScreeningRooms").IAttributes | import("@chevre/factory/lib/task/triggerWebhook").IAttributes | import("@chevre/factory/lib/task/useReservation").IAttributes | import("@chevre/factory/lib/task/voidMoneyTransferTransaction").IAttributes | import("@chevre/factory/lib/task/voidPayTransaction").IAttributes | import("@chevre/factory/lib/task/voidRegisterServiceTransaction").IAttributes | import("@chevre/factory/lib/task/voidReserveTransaction").IAttributes)[];
23
37
  export {};
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  var _a;
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.createConfirmRegisterServiceActionObjectByOrder = exports.createConfirmReservationActionObject4COAByOrder = exports.createConfirmReservationActionObject4ChevreByOrder = exports.createInformTasks = exports.getOrderWithToken = void 0;
13
+ exports.createOnOrderSentTasksByTransaction = exports.createOnPlaceOrderTasksByTransaction = exports.createConfirmRegisterServiceActionObjectByOrder = exports.createConfirmReservationActionObject4COAByOrder = exports.createConfirmReservationActionObject4ChevreByOrder = exports.createInformTasks = exports.getOrderWithToken = void 0;
14
14
  const google_libphonenumber_1 = require("google-libphonenumber");
15
15
  const jwt = require("jsonwebtoken");
16
16
  const util_1 = require("util");
@@ -262,3 +262,178 @@ function createConfirmRegisterServiceActionObjectByOrder(params) {
262
262
  });
263
263
  }
264
264
  exports.createConfirmRegisterServiceActionObjectByOrder = createConfirmRegisterServiceActionObjectByOrder;
265
+ /**
266
+ * 注文作成後のアクション
267
+ */
268
+ // export function onPlaceOrder(params: {
269
+ // object: factory.order.IOrder | IExternalOrder;
270
+ // potentialActions?: factory.action.trade.order.IPotentialActions;
271
+ // }) {
272
+ // return async (repos: {
273
+ // task: TaskRepo;
274
+ // }) => {
275
+ // const potentialActions = params.potentialActions;
276
+ // const now = new Date();
277
+ // // potentialActionsのためのタスクを生成
278
+ // const taskAttributes: factory.task.IAttributes<factory.taskName>[] = [];
279
+ // // tslint:disable-next-line:no-single-line-block-comment
280
+ // /* istanbul ignore else */
281
+ // if (potentialActions !== undefined) {
282
+ // // tslint:disable-next-line:no-single-line-block-comment
283
+ // /* istanbul ignore else */
284
+ // if (potentialActions.sendOrder !== undefined) {
285
+ // const sendOrderTask: factory.task.IAttributes<factory.taskName.SendOrder> = {
286
+ // project: potentialActions.sendOrder.project,
287
+ // name: factory.taskName.SendOrder,
288
+ // status: factory.taskStatus.Ready,
289
+ // runsAt: now, // なるはやで実行
290
+ // remainingNumberOfTries: 10,
291
+ // numberOfTried: 0,
292
+ // executionResults: [],
293
+ // // data: potentialActions.sendOrder
294
+ // data: {
295
+ // project: potentialActions.sendOrder.project,
296
+ // object: {
297
+ // ...potentialActions.sendOrder.object,
298
+ // confirmationNumber: params.object.confirmationNumber
299
+ // },
300
+ // ...(potentialActions.sendOrder.potentialActions !== undefined)
301
+ // ? { potentialActions: potentialActions.sendOrder.potentialActions }
302
+ // : undefined
303
+ // }
304
+ // };
305
+ // taskAttributes.push(sendOrderTask);
306
+ // }
307
+ // // ポイント付与
308
+ // // tslint:disable-next-line:no-single-line-block-comment
309
+ // /* istanbul ignore else */
310
+ // if (Array.isArray(potentialActions.givePointAward)) {
311
+ // taskAttributes.push(...potentialActions.givePointAward.map(
312
+ // (a): factory.task.IAttributes<factory.taskName.GivePointAward> => {
313
+ // return {
314
+ // project: a.project,
315
+ // name: factory.taskName.GivePointAward,
316
+ // status: factory.taskStatus.Ready,
317
+ // runsAt: now, // なるはやで実行
318
+ // remainingNumberOfTries: 10,
319
+ // numberOfTried: 0,
320
+ // executionResults: [],
321
+ // data: a
322
+ // };
323
+ // }));
324
+ // }
325
+ // }
326
+ // // タスク保管
327
+ // await repos.task.saveMany(taskAttributes, { emitImmediately: true });
328
+ // };
329
+ // }
330
+ function createOnPlaceOrderTasksByTransaction(params) {
331
+ const potentialActions = params.potentialActions;
332
+ const now = new Date();
333
+ // potentialActionsのためのタスクを生成
334
+ const taskAttributes = [];
335
+ // tslint:disable-next-line:no-single-line-block-comment
336
+ /* istanbul ignore else */
337
+ if (potentialActions !== undefined) {
338
+ // tslint:disable-next-line:no-single-line-block-comment
339
+ /* istanbul ignore else */
340
+ if (potentialActions.sendOrder !== undefined) {
341
+ const sendOrderTask = {
342
+ project: potentialActions.sendOrder.project,
343
+ name: factory.taskName.SendOrder,
344
+ status: factory.taskStatus.Ready,
345
+ runsAt: now,
346
+ remainingNumberOfTries: 10,
347
+ numberOfTried: 0,
348
+ executionResults: [],
349
+ data: Object.assign({ project: potentialActions.sendOrder.project, object: Object.assign(Object.assign({}, potentialActions.sendOrder.object), { confirmationNumber: params.object.confirmationNumber }) }, (potentialActions.sendOrder.potentialActions !== undefined)
350
+ ? { potentialActions: potentialActions.sendOrder.potentialActions }
351
+ : undefined)
352
+ };
353
+ taskAttributes.push(sendOrderTask);
354
+ }
355
+ // ポイント付与
356
+ // tslint:disable-next-line:no-single-line-block-comment
357
+ /* istanbul ignore else */
358
+ if (Array.isArray(potentialActions.givePointAward)) {
359
+ taskAttributes.push(...potentialActions.givePointAward.map((a) => {
360
+ return {
361
+ project: a.project,
362
+ name: factory.taskName.GivePointAward,
363
+ status: factory.taskStatus.Ready,
364
+ runsAt: now,
365
+ remainingNumberOfTries: 10,
366
+ numberOfTried: 0,
367
+ executionResults: [],
368
+ data: a
369
+ };
370
+ }));
371
+ }
372
+ }
373
+ return taskAttributes;
374
+ }
375
+ exports.createOnPlaceOrderTasksByTransaction = createOnPlaceOrderTasksByTransaction;
376
+ /**
377
+ * 注文配送後のアクション
378
+ */
379
+ function createOnOrderSentTasksByTransaction(params) {
380
+ const potentialActions = params.potentialActions;
381
+ const now = new Date();
382
+ const taskAttributes = [];
383
+ // tslint:disable-next-line:no-single-line-block-comment
384
+ /* istanbul ignore else */
385
+ if (potentialActions !== undefined) {
386
+ if (Array.isArray(potentialActions.registerService)) {
387
+ taskAttributes.push(...potentialActions.registerService.map((a) => {
388
+ return {
389
+ project: a.project,
390
+ name: factory.taskName.ConfirmRegisterService,
391
+ status: factory.taskStatus.Ready,
392
+ runsAt: now,
393
+ remainingNumberOfTries: 10,
394
+ numberOfTried: 0,
395
+ executionResults: [],
396
+ data: a
397
+ };
398
+ }));
399
+ }
400
+ // 通貨転送
401
+ // tslint:disable-next-line:no-single-line-block-comment
402
+ /* istanbul ignore else */
403
+ if (Array.isArray(potentialActions.moneyTransfer)) {
404
+ taskAttributes.push(...potentialActions.moneyTransfer.map((a) => {
405
+ return {
406
+ project: a.project,
407
+ name: factory.taskName.ConfirmMoneyTransfer,
408
+ status: factory.taskStatus.Ready,
409
+ runsAt: now,
410
+ remainingNumberOfTries: 10,
411
+ numberOfTried: 0,
412
+ executionResults: [],
413
+ data: a
414
+ };
415
+ }));
416
+ }
417
+ // tslint:disable-next-line:no-single-line-block-comment
418
+ /* istanbul ignore else */
419
+ if (Array.isArray(potentialActions.sendEmailMessage)) {
420
+ potentialActions.sendEmailMessage.forEach((s) => {
421
+ const sendEmailMessageTask = {
422
+ project: s.project,
423
+ name: factory.taskName.SendEmailMessage,
424
+ status: factory.taskStatus.Ready,
425
+ runsAt: now,
426
+ remainingNumberOfTries: 3,
427
+ numberOfTried: 0,
428
+ executionResults: [],
429
+ data: {
430
+ actionAttributes: s
431
+ }
432
+ };
433
+ taskAttributes.push(sendEmailMessageTask);
434
+ });
435
+ }
436
+ }
437
+ return taskAttributes;
438
+ }
439
+ exports.createOnOrderSentTasksByTransaction = createOnOrderSentTasksByTransaction;
@@ -1,6 +1,7 @@
1
1
  import { RedisRepository as RegisterServiceInProgressRepo } from '../../repo/action/registerServiceInProgress';
2
2
  import { MongoRepository as TaskRepo } from '../../repo/task';
3
3
  import * as factory from '../../factory';
4
+ import { IExternalOrder } from './onOrderStatusChanged/factory';
4
5
  type IPlaceOrderTransaction = factory.transaction.ITransaction<factory.transactionType.PlaceOrder>;
5
6
  type IReturnOrderTransaction = factory.transaction.ITransaction<factory.transactionType.ReturnOrder>;
6
7
  export declare function onOrderStatusChanged(params: {
@@ -11,4 +12,4 @@ export declare function onOrderStatusChanged(params: {
11
12
  registerActionInProgress: RegisterServiceInProgressRepo;
12
13
  task: TaskRepo;
13
14
  }) => Promise<void>;
14
- export {};
15
+ export { IExternalOrder };
@@ -23,6 +23,7 @@ const USE_CONFIRM_REGISTER_SERVICE_TRANSACTION = process.env.USE_CONFIRM_REGISTE
23
23
  const TOKEN_EXPIRES_IN = 604800;
24
24
  function onOrderStatusChanged(params) {
25
25
  return (repos) => __awaiter(this, void 0, void 0, function* () {
26
+ var _a, _b, _c, _d, _e, _f, _g, _h;
26
27
  let tasks = [];
27
28
  const maskedCustomer = (0, order_1.createMaskedCustomer)(params.order, { noProfile: true });
28
29
  const simpleOrder = {
@@ -40,7 +41,13 @@ function onOrderStatusChanged(params) {
40
41
  };
41
42
  switch (params.order.orderStatus) {
42
43
  case factory.orderStatus.OrderDelivered:
43
- tasks = (0, factory_1.createInformTasks)(params.order);
44
+ tasks = [
45
+ ...(0, factory_1.createInformTasks)(params.order),
46
+ // 取引のpotentialActionsを適用(2023-08-17~)
47
+ ...(0, factory_1.createOnOrderSentTasksByTransaction)({
48
+ potentialActions: (_e = (_d = (_c = (_b = (_a = params.placeOrderTransaction) === null || _a === void 0 ? void 0 : _a.potentialActions) === null || _b === void 0 ? void 0 : _b.order) === null || _c === void 0 ? void 0 : _c.potentialActions) === null || _d === void 0 ? void 0 : _d.sendOrder) === null || _e === void 0 ? void 0 : _e.potentialActions
49
+ })
50
+ ];
44
51
  // プロダクト登録プロセスロック解除
45
52
  try {
46
53
  const placeOrderTransaction = params.placeOrderTransaction;
@@ -76,7 +83,13 @@ function onOrderStatusChanged(params) {
76
83
  ...(0, factory_1.createInformTasks)(orderWithToken),
77
84
  ...yield createConfirmPayTransactionTasks(params.order, simpleOrder)(repos),
78
85
  ...yield createConfirmReserveTransactionTasks(params.order, simpleOrder)(repos),
79
- ...yield createConfirmRegisterServiceTransactionTasks(params.order, simpleOrder)(repos)
86
+ ...yield createConfirmRegisterServiceTransactionTasks(params.order, simpleOrder)(repos),
87
+ // 取引のpotentialActionsを適用(2023-08-17~)
88
+ ...(0, factory_1.createOnPlaceOrderTasksByTransaction)({
89
+ object: params.order,
90
+ // potentialActions: params.potentialActions
91
+ potentialActions: (_h = (_g = (_f = params.placeOrderTransaction) === null || _f === void 0 ? void 0 : _f.potentialActions) === null || _g === void 0 ? void 0 : _g.order) === null || _h === void 0 ? void 0 : _h.potentialActions
92
+ })
80
93
  ];
81
94
  break;
82
95
  case factory.orderStatus.OrderReturned:
@@ -4,8 +4,8 @@ import { RedisRepository as RegisterServiceInProgressRepo } from '../../repo/act
4
4
  import { MongoRepository as OrderRepo } from '../../repo/order';
5
5
  import { MongoRepository as TaskRepo } from '../../repo/task';
6
6
  import { MongoRepository as TransactionRepo } from '../../repo/transaction';
7
+ import { IExternalOrder } from './onOrderStatusChanged';
7
8
  import * as factory from '../../factory';
8
- type IExternalOrder = Pick<factory.order.IOrder, 'project' | 'typeOf' | 'seller' | 'customer' | 'confirmationNumber' | 'orderNumber' | 'price' | 'priceCurrency' | 'orderDate' | 'name' | 'orderStatus' | 'orderedItem' | 'paymentMethods'>;
9
9
  /**
10
10
  * 注文取引なしに注文を作成する
11
11
  */
@@ -15,7 +15,6 @@ declare function placeOrderWithoutTransaction(params: {
15
15
  id: string;
16
16
  };
17
17
  object: IExternalOrder;
18
- potentialActions?: factory.action.trade.order.IPotentialActions;
19
18
  }): (repos: {
20
19
  accountingReport: AccountingReportRepo;
21
20
  action: ActionRepo;
@@ -35,7 +34,6 @@ declare function placeOrder(params: {
35
34
  confirmationNumber: string;
36
35
  orderNumber: string;
37
36
  };
38
- potentialActions?: factory.action.trade.order.IPotentialActions;
39
37
  useOnOrderStatusChanged: boolean;
40
38
  }): (repos: {
41
39
  accountingReport: AccountingReportRepo;
@@ -98,12 +98,6 @@ function placeOrderWithoutTransaction(params) {
98
98
  return (repos) => __awaiter(this, void 0, void 0, function* () {
99
99
  var _a;
100
100
  const order = params.object;
101
- // 注文番号から取引と注文をfixする
102
- // const { order, placeOrderTransaction } = await createOrderFromBody({
103
- // project: { id: params.project.id },
104
- // confirmationNumber: params.object.confirmationNumber,
105
- // orderNumber: params.object.orderNumber
106
- // })({ transaction: repos.transaction });
107
101
  // アクションを作成する(2022-04-11~)
108
102
  const maskedCustomer = (0, order_1.createMaskedCustomer)(order, { noProfile: true });
109
103
  const simpleOrder = {
@@ -145,24 +139,23 @@ function placeOrderWithoutTransaction(params) {
145
139
  yield repos.action.complete({ typeOf: orderActionAttributes.typeOf, id: action.id, result: {} });
146
140
  // 経理レポートを保管
147
141
  yield (0, createAccountingReportIfNotExist_1.createAccountingReportIfNotExist)(order)({ accountingReport: repos.accountingReport });
148
- yield (0, onOrderStatusChanged_1.onOrderStatusChanged)({ order: order })({
149
- registerActionInProgress: repos.registerActionInProgress,
150
- task: repos.task
151
- });
152
- // 潜在アクション
153
- yield onPlaceOrder({
154
- object: order,
155
- potentialActions: params.potentialActions
156
- })(repos);
142
+ // await onOrderStatusChanged({ order: <factory.order.IOrder>order })({
143
+ // registerActionInProgress: repos.registerActionInProgress,
144
+ // task: repos.task
145
+ // });
157
146
  });
158
147
  }
159
148
  exports.placeOrderWithoutTransaction = placeOrderWithoutTransaction;
160
149
  /**
161
150
  * 注文を作成する
162
151
  */
152
+ // tslint:disable-next-line:max-func-body-length
163
153
  function placeOrder(params) {
164
154
  return (repos) => __awaiter(this, void 0, void 0, function* () {
165
155
  var _a;
156
+ if (typeof params.useOnOrderStatusChanged !== 'boolean') {
157
+ throw new factory.errors.Argument('useOnOrderStatusChanged', 'must be boolean');
158
+ }
166
159
  // 注文番号から取引と注文をfixする
167
160
  const { order, placeOrderTransaction } = yield createOrderFromBody({
168
161
  project: { id: params.project.id },
@@ -226,71 +219,19 @@ function placeOrder(params) {
226
219
  }
227
220
  yield repos.action.complete({ typeOf: orderActionAttributes.typeOf, id: action.id, result: {} });
228
221
  }
229
- if (params.useOnOrderStatusChanged || params.useOnOrderStatusChanged === undefined) {
222
+ if (params.useOnOrderStatusChanged) {
230
223
  // 経理レポートを保管
231
224
  yield (0, createAccountingReportIfNotExist_1.createAccountingReportIfNotExist)(order)({ accountingReport: repos.accountingReport });
232
- yield (0, onOrderStatusChanged_1.onOrderStatusChanged)({ order })({
225
+ yield (0, onOrderStatusChanged_1.onOrderStatusChanged)({ order, placeOrderTransaction })({
233
226
  registerActionInProgress: repos.registerActionInProgress,
234
227
  task: repos.task
235
228
  });
236
229
  }
237
- // 潜在アクション
238
- yield onPlaceOrder({
239
- object: order,
240
- potentialActions: params.potentialActions
241
- })(repos);
230
+ // onOrderStatusChangedへ移行(2023-08-17~)
231
+ // await onPlaceOrder({
232
+ // object: order,
233
+ // potentialActions: params.potentialActions
234
+ // })(repos);
242
235
  });
243
236
  }
244
237
  exports.placeOrder = placeOrder;
245
- /**
246
- * 注文作成後のアクション
247
- */
248
- function onPlaceOrder(params) {
249
- return (repos) => __awaiter(this, void 0, void 0, function* () {
250
- const potentialActions = params.potentialActions;
251
- const now = new Date();
252
- // potentialActionsのためのタスクを生成
253
- const taskAttributes = [];
254
- // tslint:disable-next-line:no-single-line-block-comment
255
- /* istanbul ignore else */
256
- if (potentialActions !== undefined) {
257
- // tslint:disable-next-line:no-single-line-block-comment
258
- /* istanbul ignore else */
259
- if (potentialActions.sendOrder !== undefined) {
260
- const sendOrderTask = {
261
- project: potentialActions.sendOrder.project,
262
- name: factory.taskName.SendOrder,
263
- status: factory.taskStatus.Ready,
264
- runsAt: now,
265
- remainingNumberOfTries: 10,
266
- numberOfTried: 0,
267
- executionResults: [],
268
- // data: potentialActions.sendOrder
269
- data: Object.assign({ project: potentialActions.sendOrder.project, object: Object.assign(Object.assign({}, potentialActions.sendOrder.object), { confirmationNumber: params.object.confirmationNumber }) }, (potentialActions.sendOrder.potentialActions !== undefined)
270
- ? { potentialActions: potentialActions.sendOrder.potentialActions }
271
- : undefined)
272
- };
273
- taskAttributes.push(sendOrderTask);
274
- }
275
- // ポイント付与
276
- // tslint:disable-next-line:no-single-line-block-comment
277
- /* istanbul ignore else */
278
- if (Array.isArray(potentialActions.givePointAward)) {
279
- taskAttributes.push(...potentialActions.givePointAward.map((a) => {
280
- return {
281
- project: a.project,
282
- name: factory.taskName.GivePointAward,
283
- status: factory.taskStatus.Ready,
284
- runsAt: now,
285
- remainingNumberOfTries: 10,
286
- numberOfTried: 0,
287
- executionResults: [],
288
- data: a
289
- };
290
- }));
291
- }
292
- }
293
- // タスク保管
294
- yield repos.task.saveMany(taskAttributes, { emitImmediately: true });
295
- });
296
- }
@@ -25,7 +25,6 @@ declare function sendOrder(params: {
25
25
  confirmationNumber: string;
26
26
  orderNumber: string;
27
27
  };
28
- potentialActions?: factory.action.transfer.send.order.IPotentialActions;
29
28
  useOnOrderStatusChanged: boolean;
30
29
  }): ISendOperation<void>;
31
30
  export { sendOrder };
@@ -22,6 +22,9 @@ function sendOrder(params) {
22
22
  // tslint:disable-next-line:max-func-body-length
23
23
  return (repos) => __awaiter(this, void 0, void 0, function* () {
24
24
  var _a;
25
+ if (typeof params.useOnOrderStatusChanged !== 'boolean') {
26
+ throw new factory.errors.Argument('useOnOrderStatusChanged', 'must be boolean');
27
+ }
25
28
  try {
26
29
  const orderNumber = params.object.orderNumber;
27
30
  const confirmationNumber = params.object.confirmationNumber;
@@ -96,7 +99,7 @@ function sendOrder(params) {
96
99
  }
97
100
  const result = ownershipInfos;
98
101
  yield repos.action.complete({ typeOf: sendOrderActionAttributes.typeOf, id: action.id, result: result });
99
- if (params.useOnOrderStatusChanged || params.useOnOrderStatusChanged === undefined) {
102
+ if (params.useOnOrderStatusChanged) {
100
103
  yield (0, onOrderStatusChanged_1.onOrderStatusChanged)({ order, placeOrderTransaction })({
101
104
  registerActionInProgress: repos.registerActionInProgress,
102
105
  task: repos.task
@@ -119,73 +122,8 @@ function sendOrder(params) {
119
122
  throw error;
120
123
  }
121
124
  }
122
- yield onSend(params)({ task: repos.task });
125
+ // onOrderStatusChangedへ移行(2023-08-17~)
126
+ // await onSend(params)({ task: repos.task });
123
127
  });
124
128
  }
125
129
  exports.sendOrder = sendOrder;
126
- /**
127
- * 注文配送後のアクション
128
- */
129
- function onSend(params) {
130
- return (repos) => __awaiter(this, void 0, void 0, function* () {
131
- const potentialActions = params.potentialActions;
132
- const now = new Date();
133
- const taskAttributes = [];
134
- // tslint:disable-next-line:no-single-line-block-comment
135
- /* istanbul ignore else */
136
- if (potentialActions !== undefined) {
137
- if (Array.isArray(potentialActions.registerService)) {
138
- taskAttributes.push(...potentialActions.registerService.map((a) => {
139
- return {
140
- project: a.project,
141
- name: factory.taskName.ConfirmRegisterService,
142
- status: factory.taskStatus.Ready,
143
- runsAt: now,
144
- remainingNumberOfTries: 10,
145
- numberOfTried: 0,
146
- executionResults: [],
147
- data: a
148
- };
149
- }));
150
- }
151
- // 通貨転送
152
- // tslint:disable-next-line:no-single-line-block-comment
153
- /* istanbul ignore else */
154
- if (Array.isArray(potentialActions.moneyTransfer)) {
155
- taskAttributes.push(...potentialActions.moneyTransfer.map((a) => {
156
- return {
157
- project: a.project,
158
- name: factory.taskName.ConfirmMoneyTransfer,
159
- status: factory.taskStatus.Ready,
160
- runsAt: now,
161
- remainingNumberOfTries: 10,
162
- numberOfTried: 0,
163
- executionResults: [],
164
- data: a
165
- };
166
- }));
167
- }
168
- // tslint:disable-next-line:no-single-line-block-comment
169
- /* istanbul ignore else */
170
- if (Array.isArray(potentialActions.sendEmailMessage)) {
171
- potentialActions.sendEmailMessage.forEach((s) => {
172
- const sendEmailMessageTask = {
173
- project: s.project,
174
- name: factory.taskName.SendEmailMessage,
175
- status: factory.taskStatus.Ready,
176
- runsAt: now,
177
- remainingNumberOfTries: 3,
178
- numberOfTried: 0,
179
- executionResults: [],
180
- data: {
181
- actionAttributes: s
182
- }
183
- };
184
- taskAttributes.push(sendEmailMessageTask);
185
- });
186
- }
187
- }
188
- // タスク保管
189
- yield repos.task.saveMany(taskAttributes, { emitImmediately: true });
190
- });
191
- }
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.7.0-alpha.10"
120
+ "version": "21.7.0-alpha.12"
121
121
  }