@chevre/domain 21.7.0-alpha.13 → 21.7.0-alpha.14

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.
@@ -4,6 +4,8 @@ import * as mongoose from 'mongoose';
4
4
 
5
5
  import { chevre } from '../../../lib/index';
6
6
 
7
+ const ONE_YEAR_IN_DAYS = 365;
8
+
7
9
  // tslint:disable-next-line:max-func-body-length
8
10
  async function main() {
9
11
  await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
@@ -11,9 +13,9 @@ async function main() {
11
13
  const now = new Date();
12
14
  const endDateLt: Date = moment(now)
13
15
  // tslint:disable-next-line:no-magic-numbers
14
- .add(-365, 'days')
16
+ .add(-ONE_YEAR_IN_DAYS, 'days')
15
17
  .toDate();
16
- const startDateLt: Date = moment('2021-09-01T00:00:00Z')
18
+ const startDateLt: Date = moment('2022-01-01T00:00:00Z')
17
19
  .toDate();
18
20
 
19
21
  const taskRepo = new chevre.repository.Task(mongoose.connection);
@@ -23,7 +25,6 @@ async function main() {
23
25
  {
24
26
  typeOf: { $eq: chevre.factory.transactionType.PlaceOrder },
25
27
  startDate: {
26
- // $exists: true,
27
28
  $lt: startDateLt
28
29
  }
29
30
  // endDate: {
@@ -58,12 +59,16 @@ async function main() {
58
59
  const isEndDateBefore = transaction.endDate !== undefined && moment(transaction.endDate)
59
60
  .isBefore(endDateLt);
60
61
  if (isEndDateBefore) {
62
+ const runsAt: Date = moment(transaction.endDate)
63
+ .add(ONE_YEAR_IN_DAYS, 'days')
64
+ .toDate();
65
+
61
66
  updateCount += 1;
62
67
  const deleteTransactionTask: chevre.factory.task.deleteTransaction.IAttributes = {
63
68
  project: transaction.project,
64
69
  name: chevre.factory.taskName.DeleteTransaction,
65
70
  status: chevre.factory.taskStatus.Ready,
66
- runsAt: now,
71
+ runsAt,
67
72
  remainingNumberOfTries: 3,
68
73
  numberOfTried: 0,
69
74
  executionResults: [],
@@ -34,4 +34,10 @@ export declare function createOnPlaceOrderTasksByTransaction(params: {
34
34
  export declare function createOnOrderSentTasksByTransaction(params: {
35
35
  potentialActions?: factory.action.transfer.send.order.IPotentialActions;
36
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/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)[];
37
+ /**
38
+ * 注文返品後のアクション
39
+ */
40
+ export declare function createOnOrderReturnedTasksByTransaction(params: {
41
+ potentialActions?: factory.action.transfer.returnAction.order.IPotentialActions;
42
+ }): (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/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)[];
37
43
  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.createOnOrderSentTasksByTransaction = exports.createOnPlaceOrderTasksByTransaction = exports.createConfirmRegisterServiceActionObjectByOrder = exports.createConfirmReservationActionObject4COAByOrder = exports.createConfirmReservationActionObject4ChevreByOrder = exports.createInformTasks = exports.getOrderWithToken = void 0;
13
+ exports.createOnOrderReturnedTasksByTransaction = 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");
@@ -437,3 +437,63 @@ function createOnOrderSentTasksByTransaction(params) {
437
437
  return taskAttributes;
438
438
  }
439
439
  exports.createOnOrderSentTasksByTransaction = createOnOrderSentTasksByTransaction;
440
+ /**
441
+ * 注文返品後のアクション
442
+ */
443
+ function createOnOrderReturnedTasksByTransaction(params) {
444
+ const now = new Date();
445
+ const taskAttributes = [];
446
+ const potentialActions = params.potentialActions;
447
+ // 入金返却タスク
448
+ const returnMoneyTransferAttributes = potentialActions === null || potentialActions === void 0 ? void 0 : potentialActions.returnMoneyTransfer;
449
+ if (Array.isArray(returnMoneyTransferAttributes)) {
450
+ taskAttributes.push(...returnMoneyTransferAttributes.map((a) => {
451
+ return {
452
+ project: a.project,
453
+ name: factory.taskName.ReturnMoneyTransfer,
454
+ status: factory.taskStatus.Ready,
455
+ runsAt: now,
456
+ remainingNumberOfTries: 10,
457
+ numberOfTried: 0,
458
+ executionResults: [],
459
+ data: a
460
+ };
461
+ }));
462
+ }
463
+ // ポイント特典返却タスク
464
+ const returnPointAwardAttributes = potentialActions === null || potentialActions === void 0 ? void 0 : potentialActions.returnPointAward;
465
+ if (Array.isArray(returnPointAwardAttributes)) {
466
+ taskAttributes.push(...returnPointAwardAttributes.map((a) => {
467
+ return {
468
+ project: a.project,
469
+ name: factory.taskName.ReturnPointAward,
470
+ status: factory.taskStatus.Ready,
471
+ runsAt: now,
472
+ remainingNumberOfTries: 10,
473
+ numberOfTried: 0,
474
+ executionResults: [],
475
+ data: a
476
+ };
477
+ }));
478
+ }
479
+ const sendEmailMessageAttributes = potentialActions === null || potentialActions === void 0 ? void 0 : potentialActions.sendEmailMessage;
480
+ if (Array.isArray(sendEmailMessageAttributes)) {
481
+ sendEmailMessageAttributes.forEach((s) => {
482
+ const sendEmailMessageTask = {
483
+ project: s.project,
484
+ name: factory.taskName.SendEmailMessage,
485
+ status: factory.taskStatus.Ready,
486
+ runsAt: now,
487
+ remainingNumberOfTries: 3,
488
+ numberOfTried: 0,
489
+ executionResults: [],
490
+ data: {
491
+ actionAttributes: s
492
+ }
493
+ };
494
+ taskAttributes.push(sendEmailMessageTask);
495
+ });
496
+ }
497
+ return taskAttributes;
498
+ }
499
+ exports.createOnOrderReturnedTasksByTransaction = createOnOrderReturnedTasksByTransaction;
@@ -23,7 +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
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
27
27
  let tasks = [];
28
28
  const maskedCustomer = (0, order_1.createMaskedCustomer)(params.order, { noProfile: true });
29
29
  const simpleOrder = {
@@ -93,11 +93,16 @@ function onOrderStatusChanged(params) {
93
93
  ];
94
94
  break;
95
95
  case factory.orderStatus.OrderReturned:
96
+ const potentialActionsByTransaction = (_m = (_l = (_k = (_j = params.returnOrderTransaction) === null || _j === void 0 ? void 0 : _j.potentialActions) === null || _k === void 0 ? void 0 : _k.returnOrder) === null || _l === void 0 ? void 0 : _l.find((returnOrderActionByTransaction) => {
97
+ return returnOrderActionByTransaction.object.orderNumber === params.order.orderNumber;
98
+ })) === null || _m === void 0 ? void 0 : _m.potentialActions;
96
99
  tasks = [
97
100
  ...(0, factory_1.createInformTasks)(params.order),
98
- ...yield createReturnReserveTransactionTasks(params.order, simpleOrder)(repos),
101
+ ...createReturnReserveTransactionTasks(params.order, simpleOrder),
99
102
  // 決済取引返却タスクを作成(2022-06-09~)
100
- ...yield createReturnPayTransactionTasks(params.order, simpleOrder, params.returnOrderTransaction)(repos)
103
+ ...createReturnPayTransactionTasks(params.order, simpleOrder, params.returnOrderTransaction),
104
+ // 取引のpotentialActionsを適用(2023-08-19~)
105
+ ...(0, factory_1.createOnOrderReturnedTasksByTransaction)({ potentialActions: potentialActionsByTransaction })
101
106
  ];
102
107
  break;
103
108
  default:
@@ -267,112 +272,108 @@ function createConfirmRegisterServiceTransactionTasks(order, simpleOrder) {
267
272
  }
268
273
  const RETURN_COA_TASK_DELAY_IN_SECONDS = 0;
269
274
  function createReturnReserveTransactionTasks(order, simpleOrder) {
270
- return (__) => __awaiter(this, void 0, void 0, function* () {
271
- var _a, _b;
272
- const taskRunsAt = moment(order.dateReturned)
273
- .toDate();
274
- const taskRunsAt4coa = moment(order.dateReturned)
275
- .add(RETURN_COA_TASK_DELAY_IN_SECONDS, 'seconds')
276
- .toDate();
277
- const tasks = [];
278
- const returnActionRecipient = {
279
- typeOf: order.seller.typeOf,
280
- id: order.seller.id,
281
- name: order.seller.name
282
- };
283
- const reservationNumbers = [];
284
- // 注文アイテムから返却アクションを作成する
285
- const acceptedOffers = (Array.isArray(order.acceptedOffers)) ? order.acceptedOffers : [];
286
- for (const acceptedOffer of acceptedOffers) {
287
- if (acceptedOffer.itemOffered.typeOf === factory.reservationType.EventReservation
288
- || acceptedOffer.itemOffered.typeOf === factory.reservationType.BusReservation) {
289
- const reservation = acceptedOffer.itemOffered;
290
- const reservationNumber = reservation.reservationNumber;
291
- // 予約番号ごとに返却アクションを作成する
292
- if (!reservationNumbers.includes(reservationNumber)) {
293
- let returnReserveTransactionAction;
294
- switch ((_a = acceptedOffer.offeredThrough) === null || _a === void 0 ? void 0 : _a.identifier) {
295
- case factory.service.webAPI.Identifier.COA:
296
- const superEventLocationBranchCode = (_b = reservation.reservationFor) === null || _b === void 0 ? void 0 : _b.superEvent.location.branchCode;
297
- const phoneUtil = google_libphonenumber_1.PhoneNumberUtil.getInstance();
298
- const phoneNumber = phoneUtil.parse(order.customer.telephone, 'JP');
299
- let telNum = phoneUtil.format(phoneNumber, google_libphonenumber_1.PhoneNumberFormat.NATIONAL);
300
- // COAでは数字のみ受け付けるので数字以外を除去
301
- telNum = telNum.replace(/[^\d]/g, '');
302
- returnReserveTransactionAction = {
303
- project: order.project,
304
- typeOf: factory.actionType.ReturnAction,
305
- object: {
306
- theaterCode: superEventLocationBranchCode,
307
- reserveNum: reservationNumber,
308
- telNum: telNum,
309
- typeOf: 'COAReserveTransaction'
310
- },
311
- agent: order.project,
312
- // potentialActions: {},
313
- purpose: simpleOrder,
314
- instrument: { typeOf: 'WebAPI', identifier: factory.service.webAPI.Identifier.COA },
315
- recipient: returnActionRecipient
316
- };
317
- break;
318
- default:
319
- returnReserveTransactionAction = {
320
- project: order.project,
321
- typeOf: factory.actionType.ReturnAction,
322
- object: {
323
- typeOf: factory.assetTransactionType.Reserve,
324
- transactionNumber: reservationNumber
325
- },
326
- agent: order.project,
327
- // potentialActions: {},
328
- purpose: simpleOrder,
329
- instrument: { typeOf: 'WebAPI', identifier: factory.service.webAPI.Identifier.Chevre },
330
- recipient: returnActionRecipient
331
- };
332
- }
333
- tasks.push({
334
- project: order.project,
335
- name: factory.taskName.ReturnReserveTransaction,
336
- status: factory.taskStatus.Ready,
337
- runsAt: (returnReserveTransactionAction.object.typeOf === 'COAReserveTransaction')
338
- ? taskRunsAt4coa
339
- : taskRunsAt,
340
- remainingNumberOfTries: 10,
341
- numberOfTried: 0,
342
- executionResults: [],
343
- data: returnReserveTransactionAction
344
- });
345
- reservationNumbers.push(reservationNumber);
275
+ var _a, _b;
276
+ const taskRunsAt = moment(order.dateReturned)
277
+ .toDate();
278
+ const taskRunsAt4coa = moment(order.dateReturned)
279
+ .add(RETURN_COA_TASK_DELAY_IN_SECONDS, 'seconds')
280
+ .toDate();
281
+ const tasks = [];
282
+ const returnActionRecipient = {
283
+ typeOf: order.seller.typeOf,
284
+ id: order.seller.id,
285
+ name: order.seller.name
286
+ };
287
+ const reservationNumbers = [];
288
+ // 注文アイテムから返却アクションを作成する
289
+ const acceptedOffers = (Array.isArray(order.acceptedOffers)) ? order.acceptedOffers : [];
290
+ for (const acceptedOffer of acceptedOffers) {
291
+ if (acceptedOffer.itemOffered.typeOf === factory.reservationType.EventReservation
292
+ || acceptedOffer.itemOffered.typeOf === factory.reservationType.BusReservation) {
293
+ const reservation = acceptedOffer.itemOffered;
294
+ const reservationNumber = reservation.reservationNumber;
295
+ // 予約番号ごとに返却アクションを作成する
296
+ if (!reservationNumbers.includes(reservationNumber)) {
297
+ let returnReserveTransactionAction;
298
+ switch ((_a = acceptedOffer.offeredThrough) === null || _a === void 0 ? void 0 : _a.identifier) {
299
+ case factory.service.webAPI.Identifier.COA:
300
+ const superEventLocationBranchCode = (_b = reservation.reservationFor) === null || _b === void 0 ? void 0 : _b.superEvent.location.branchCode;
301
+ const phoneUtil = google_libphonenumber_1.PhoneNumberUtil.getInstance();
302
+ const phoneNumber = phoneUtil.parse(order.customer.telephone, 'JP');
303
+ let telNum = phoneUtil.format(phoneNumber, google_libphonenumber_1.PhoneNumberFormat.NATIONAL);
304
+ // COAでは数字のみ受け付けるので数字以外を除去
305
+ telNum = telNum.replace(/[^\d]/g, '');
306
+ returnReserveTransactionAction = {
307
+ project: order.project,
308
+ typeOf: factory.actionType.ReturnAction,
309
+ object: {
310
+ theaterCode: superEventLocationBranchCode,
311
+ reserveNum: reservationNumber,
312
+ telNum: telNum,
313
+ typeOf: 'COAReserveTransaction'
314
+ },
315
+ agent: order.project,
316
+ // potentialActions: {},
317
+ purpose: simpleOrder,
318
+ instrument: { typeOf: 'WebAPI', identifier: factory.service.webAPI.Identifier.COA },
319
+ recipient: returnActionRecipient
320
+ };
321
+ break;
322
+ default:
323
+ returnReserveTransactionAction = {
324
+ project: order.project,
325
+ typeOf: factory.actionType.ReturnAction,
326
+ object: {
327
+ typeOf: factory.assetTransactionType.Reserve,
328
+ transactionNumber: reservationNumber
329
+ },
330
+ agent: order.project,
331
+ // potentialActions: {},
332
+ purpose: simpleOrder,
333
+ instrument: { typeOf: 'WebAPI', identifier: factory.service.webAPI.Identifier.Chevre },
334
+ recipient: returnActionRecipient
335
+ };
346
336
  }
347
- }
348
- }
349
- return tasks;
350
- });
351
- }
352
- const RETURN_PAY_TASK_DELAY_IN_SECONDS = 0;
353
- function createReturnPayTransactionTasks(order, __, returnOrderTransaction) {
354
- return (__1) => __awaiter(this, void 0, void 0, function* () {
355
- var _a, _b;
356
- const taskRunsAt = moment(order.dateReturned)
357
- .add(RETURN_PAY_TASK_DELAY_IN_SECONDS, 'seconds')
358
- .toDate();
359
- const tasks = [];
360
- const returnOrderPotentialActions = (_b = (_a = returnOrderTransaction === null || returnOrderTransaction === void 0 ? void 0 : returnOrderTransaction.potentialActions) === null || _a === void 0 ? void 0 : _a.returnOrder.find((action) => action.object.orderNumber === order.orderNumber)) === null || _b === void 0 ? void 0 : _b.potentialActions;
361
- const returnPayActionsByReturnOrderTransaction = returnOrderPotentialActions === null || returnOrderPotentialActions === void 0 ? void 0 : returnOrderPotentialActions.returnPaymentMethod;
362
- if (Array.isArray(returnPayActionsByReturnOrderTransaction)) {
363
- tasks.push(...returnPayActionsByReturnOrderTransaction.map((a) => {
364
- return {
365
- project: a.project,
366
- name: factory.taskName.ReturnPayTransaction,
337
+ tasks.push({
338
+ project: order.project,
339
+ name: factory.taskName.ReturnReserveTransaction,
367
340
  status: factory.taskStatus.Ready,
368
- runsAt: taskRunsAt,
341
+ runsAt: (returnReserveTransactionAction.object.typeOf === 'COAReserveTransaction')
342
+ ? taskRunsAt4coa
343
+ : taskRunsAt,
369
344
  remainingNumberOfTries: 10,
370
345
  numberOfTried: 0,
371
346
  executionResults: [],
372
- data: a
373
- };
374
- }));
347
+ data: returnReserveTransactionAction
348
+ });
349
+ reservationNumbers.push(reservationNumber);
350
+ }
375
351
  }
376
- return tasks;
377
- });
352
+ }
353
+ return tasks;
354
+ }
355
+ const RETURN_PAY_TASK_DELAY_IN_SECONDS = 0;
356
+ function createReturnPayTransactionTasks(order, __, returnOrderTransaction) {
357
+ var _a, _b;
358
+ const taskRunsAt = moment(order.dateReturned)
359
+ .add(RETURN_PAY_TASK_DELAY_IN_SECONDS, 'seconds')
360
+ .toDate();
361
+ const tasks = [];
362
+ const returnOrderPotentialActions = (_b = (_a = returnOrderTransaction === null || returnOrderTransaction === void 0 ? void 0 : returnOrderTransaction.potentialActions) === null || _a === void 0 ? void 0 : _a.returnOrder.find((action) => action.object.orderNumber === order.orderNumber)) === null || _b === void 0 ? void 0 : _b.potentialActions;
363
+ const returnPayActionsByReturnOrderTransaction = returnOrderPotentialActions === null || returnOrderPotentialActions === void 0 ? void 0 : returnOrderPotentialActions.returnPaymentMethod;
364
+ if (Array.isArray(returnPayActionsByReturnOrderTransaction)) {
365
+ tasks.push(...returnPayActionsByReturnOrderTransaction.map((a) => {
366
+ return {
367
+ project: a.project,
368
+ name: factory.taskName.ReturnPayTransaction,
369
+ status: factory.taskStatus.Ready,
370
+ runsAt: taskRunsAt,
371
+ remainingNumberOfTries: 10,
372
+ numberOfTried: 0,
373
+ executionResults: [],
374
+ data: a
375
+ };
376
+ }));
377
+ }
378
+ return tasks;
378
379
  }
@@ -14,9 +14,12 @@ const order_1 = require("../../factory/order");
14
14
  const factory_1 = require("../delivery/factory");
15
15
  const onOrderStatusChanged_1 = require("./onOrderStatusChanged");
16
16
  const factory = require("../../factory");
17
- // tslint:disable-next-line:max-func-body-length
18
17
  function returnOrder(params) {
18
+ // tslint:disable-next-line:max-func-body-length
19
19
  return (repos) => __awaiter(this, void 0, void 0, function* () {
20
+ if (typeof params.useOnOrderStatusChanged !== 'boolean') {
21
+ throw new factory.errors.Argument('useOnOrderStatusChanged', 'must be boolean');
22
+ }
20
23
  const orderNumber = params.object.orderNumber;
21
24
  const dateReturned = (params.object.dateReturned instanceof Date)
22
25
  ? params.object.dateReturned
@@ -88,14 +91,15 @@ function returnOrder(params) {
88
91
  }
89
92
  const result = returnedOwnershipInfos;
90
93
  yield repos.action.complete({ typeOf: action.typeOf, id: action.id, result: result });
91
- if (params.useOnOrderStatusChanged || params.useOnOrderStatusChanged === undefined) {
94
+ if (params.useOnOrderStatusChanged) {
92
95
  yield (0, onOrderStatusChanged_1.onOrderStatusChanged)({ order, returnOrderTransaction })({
93
96
  registerActionInProgress: repos.registerServiceInProgress,
94
97
  task: repos.task
95
98
  });
96
99
  }
97
100
  // 潜在アクション
98
- yield onReturn(returnOrderActionAttributes)({ task: repos.task });
101
+ // onOrderStatusChangedへ移行(2023-08-19~)
102
+ // await onReturn(returnOrderActionAttributes)({ task: repos.task });
99
103
  });
100
104
  }
101
105
  exports.returnOrder = returnOrder;
@@ -122,98 +126,9 @@ function processReturnOrder(order, dateReturned) {
122
126
  return ownershipInfoByDB;
123
127
  }
124
128
  });
125
- // const ownershipInfoReturned: IOwnershipInfo = await repos.ownershipInfo.ownershipInfoModel.findOneAndUpdate(
126
- // {
127
- // 'project.id': { $eq: order.project.id },
128
- // identifier: String(ownershipInfo.identifier)
129
- // },
130
- // { ownedThrough: dateReturned },
131
- // { new: true }
132
- // )
133
- // .select({ __v: 0, createdAt: 0, updatedAt: 0 })
134
- // .exec()
135
- // .then((doc) => {
136
- // // 存在しない場合はいったん保留
137
- // if (doc === null) {
138
- // return ownershipInfo;
139
- // } else {
140
- // return doc.toObject();
141
- // }
142
- // });
143
129
  returnedOwnershipInfos.push(ownershipInfoReturned);
144
130
  })));
145
131
  }
146
132
  return returnedOwnershipInfos;
147
133
  });
148
134
  }
149
- /**
150
- * 返品アクション後の処理
151
- * 注文返品後に何をすべきかは返品アクションのpotentialActionsとして定義されているはずなので、それらをタスクとして登録します。
152
- */
153
- function onReturn(returnActionAttributes) {
154
- // tslint:disable-next-line:max-func-body-length
155
- return (repos) => __awaiter(this, void 0, void 0, function* () {
156
- const now = new Date();
157
- const taskAttributes = [];
158
- const potentialActions = returnActionAttributes.potentialActions;
159
- // tslint:disable-next-line:no-single-line-block-comment
160
- /* istanbul ignore else */
161
- if (potentialActions !== undefined) {
162
- // 入金返却タスク
163
- // tslint:disable-next-line:no-single-line-block-comment
164
- /* istanbul ignore else */
165
- if (Array.isArray(potentialActions.returnMoneyTransfer)) {
166
- taskAttributes.push(...potentialActions.returnMoneyTransfer.map((a) => {
167
- return {
168
- project: a.project,
169
- name: factory.taskName.ReturnMoneyTransfer,
170
- status: factory.taskStatus.Ready,
171
- runsAt: now,
172
- remainingNumberOfTries: 10,
173
- numberOfTried: 0,
174
- executionResults: [],
175
- data: a
176
- };
177
- }));
178
- }
179
- // ポイントインセンティブ返却タスク
180
- // tslint:disable-next-line:no-single-line-block-comment
181
- /* istanbul ignore else */
182
- if (Array.isArray(potentialActions.returnPointAward)) {
183
- taskAttributes.push(...potentialActions.returnPointAward.map((a) => {
184
- return {
185
- project: a.project,
186
- name: factory.taskName.ReturnPointAward,
187
- status: factory.taskStatus.Ready,
188
- runsAt: now,
189
- remainingNumberOfTries: 10,
190
- numberOfTried: 0,
191
- executionResults: [],
192
- data: a
193
- };
194
- }));
195
- }
196
- // tslint:disable-next-line:no-single-line-block-comment
197
- /* istanbul ignore else */
198
- if (Array.isArray(potentialActions.sendEmailMessage)) {
199
- potentialActions.sendEmailMessage.forEach((s) => {
200
- const sendEmailMessageTask = {
201
- project: s.project,
202
- name: factory.taskName.SendEmailMessage,
203
- status: factory.taskStatus.Ready,
204
- runsAt: now,
205
- remainingNumberOfTries: 3,
206
- numberOfTried: 0,
207
- executionResults: [],
208
- data: {
209
- actionAttributes: s
210
- }
211
- };
212
- taskAttributes.push(sendEmailMessageTask);
213
- });
214
- }
215
- }
216
- // タスク保管
217
- yield repos.task.saveMany(taskAttributes, { emitImmediately: true });
218
- });
219
- }
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.13"
120
+ "version": "21.7.0-alpha.14"
121
121
  }
@@ -1,65 +0,0 @@
1
- // tslint:disable:no-console
2
- import * as mongoose from 'mongoose';
3
- import * as redis from 'redis';
4
-
5
- import { chevre } from '../../../../lib/index';
6
-
7
- import { call } from '../../../../lib/chevre/service/task/orderProgramMembership';
8
-
9
- const project = { id: String(process.env.PROJECT_ID) };
10
- async function main() {
11
- await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
12
-
13
- const redisClient = redis.createClient<redis.RedisDefaultModules, Record<string, never>, Record<string, never>>({
14
- socket: {
15
- port: Number(<string>process.env.REDIS_PORT),
16
- host: <string>process.env.REDIS_HOST
17
- },
18
- password: <string>process.env.REDIS_KEY
19
- });
20
- await redisClient.connect();
21
-
22
- const result = await call(
23
- {
24
- agent: {
25
- typeOf: chevre.factory.personType.Person,
26
- id: 'b2bc2b6d-aea2-41fc-9f6e-e4ec89c11d2e',
27
- identifier: [
28
- {
29
- name: 'iss',
30
- value: String(process.env.ISS)
31
- }
32
- ]
33
- },
34
- object: {
35
- seller: {
36
- id: '5d0abf30ac3fb200198ebb2c'
37
- },
38
- typeOf: chevre.factory.offerType.Offer,
39
- itemOffered: {
40
- typeOf: chevre.factory.permit.PermitType.Permit,
41
- name: '[development]会員ポイントプログラム',
42
- issuedThrough: {
43
- id: '5afff104d51e59232c7b481b',
44
- typeOf: chevre.factory.product.ProductType.MembershipService
45
- }
46
- },
47
- id: '7k9f3ht34',
48
- identifier: 'AnnualPlan'
49
- },
50
- project: {
51
- typeOf: chevre.factory.organizationType.Project,
52
- id: project.id
53
- },
54
- typeOf: chevre.factory.actionType.OrderAction
55
- }
56
- )({
57
- connection: mongoose.connection,
58
- redisClient
59
- });
60
- console.log(result);
61
- }
62
-
63
- main()
64
- .then(console.log)
65
- .catch(console.error);
@@ -1,105 +0,0 @@
1
- // tslint:disable:no-console
2
- import * as mongoose from 'mongoose';
3
- import * as redis from 'redis';
4
-
5
- import { chevre } from '../../../../lib/index';
6
-
7
- import { orderProgramMembership } from '../../../../lib/chevre/service/transaction/orderProgramMembership';
8
-
9
- const project = { id: String(process.env.PROJECT_ID) };
10
- async function main() {
11
- await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
12
-
13
- const redisClient = redis.createClient<redis.RedisDefaultModules, Record<string, never>, Record<string, never>>({
14
- socket: {
15
- port: Number(<string>process.env.REDIS_PORT),
16
- host: <string>process.env.REDIS_HOST
17
- },
18
- password: <string>process.env.REDIS_KEY
19
- });
20
- await redisClient.connect();
21
-
22
- const personRepo = new chevre.repository.Person({ userPoolId: chevre.settings.settings.userPoolIdNew });
23
- const actionRepo = new chevre.repository.Action(mongoose.connection);
24
- const accountRepo = new chevre.repository.Account(mongoose.connection);
25
- const accountingReportRepo = new chevre.repository.AccountingReport(mongoose.connection);
26
- const assetTransactionRepo = new chevre.repository.AssetTransaction(mongoose.connection);
27
- const eventRepo = new chevre.repository.Event(mongoose.connection);
28
- const offerRepo = new chevre.repository.Offer(mongoose.connection);
29
- const offerCatalogRepo = new chevre.repository.OfferCatalog(mongoose.connection);
30
- const productRepo = new chevre.repository.Product(mongoose.connection);
31
- const projectRepo = new chevre.repository.Project(mongoose.connection);
32
- const ownershipInfoRepo = new chevre.repository.OwnershipInfo(mongoose.connection);
33
- const sellerRepo = new chevre.repository.Seller(mongoose.connection);
34
- const serviceOutputRepo = new chevre.repository.ServiceOutput(mongoose.connection);
35
- const taskRepo = new chevre.repository.Task(mongoose.connection);
36
- const transactionRepo = new chevre.repository.Transaction(mongoose.connection);
37
- const confirmationNumberRepo = new chevre.repository.ConfirmationNumber(redisClient);
38
- const orderNumberRepo = new chevre.repository.OrderNumber(redisClient);
39
- const registerServiceInProgressRepo = new chevre.repository.action.RegisterServiceInProgress(redisClient);
40
- const transactionNumberRepo = new chevre.repository.TransactionNumber(redisClient);
41
- const serviceOutputIdentifierRepo = new chevre.repository.ServiceOutputIdentifier(redisClient);
42
-
43
- const result = await orderProgramMembership(
44
- {
45
- agent: {
46
- typeOf: chevre.factory.personType.Person,
47
- id: 'b2bc2b6d-aea2-41fc-9f6e-e4ec89c11d2e',
48
- identifier: [
49
- {
50
- name: 'iss',
51
- value: String(process.env.ISS)
52
- }
53
- ]
54
- },
55
- object: {
56
- seller: {
57
- id: '5d0abf30ac3fb200198ebb2c'
58
- },
59
- typeOf: chevre.factory.offerType.Offer,
60
- itemOffered: {
61
- typeOf: chevre.factory.permit.PermitType.Permit,
62
- name: '[development]会員ポイントプログラム',
63
- issuedThrough: {
64
- id: '5afff104d51e59232c7b481b',
65
- typeOf: chevre.factory.product.ProductType.MembershipService
66
- }
67
- },
68
- id: '7k9f3ht34',
69
- identifier: 'AnnualPlan'
70
- },
71
- project: {
72
- typeOf: chevre.factory.organizationType.Project,
73
- id: project.id
74
- },
75
- typeOf: chevre.factory.actionType.OrderAction
76
- },
77
- 'CreditCard'
78
- )({
79
- account: accountRepo,
80
- accountingReport: accountingReportRepo,
81
- action: actionRepo,
82
- assetTransaction: assetTransactionRepo,
83
- confirmationNumber: confirmationNumberRepo,
84
- event: eventRepo,
85
- offer: offerRepo,
86
- offerCatalog: offerCatalogRepo,
87
- orderNumber: orderNumberRepo,
88
- ownershipInfo: ownershipInfoRepo,
89
- person: personRepo,
90
- product: productRepo,
91
- project: projectRepo,
92
- registerActionInProgress: registerServiceInProgressRepo,
93
- seller: sellerRepo,
94
- serviceOutput: serviceOutputRepo,
95
- serviceOutputIdentifier: serviceOutputIdentifierRepo,
96
- task: taskRepo,
97
- transaction: transactionRepo,
98
- transactionNumber: transactionNumberRepo
99
- });
100
- console.log(result);
101
- }
102
-
103
- main()
104
- .then(console.log)
105
- .catch(console.error);