@chevre/domain 21.8.0-alpha.22 → 21.8.0-alpha.24

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.
@@ -57,6 +57,7 @@ declare const schema: Schema<any, import("mongoose").Model<any, any, any, any, a
57
57
  status?: string | undefined;
58
58
  data?: any;
59
59
  project?: any;
60
+ identifier?: string | undefined;
60
61
  runsAt?: Date | undefined;
61
62
  remainingNumberOfTries?: number | undefined;
62
63
  lastTriedAt?: Date | undefined;
@@ -69,6 +70,7 @@ declare const schema: Schema<any, import("mongoose").Model<any, any, any, any, a
69
70
  status?: string | undefined;
70
71
  data?: any;
71
72
  project?: any;
73
+ identifier?: string | undefined;
72
74
  runsAt?: Date | undefined;
73
75
  remainingNumberOfTries?: number | undefined;
74
76
  lastTriedAt?: Date | undefined;
@@ -81,6 +83,7 @@ declare const schema: Schema<any, import("mongoose").Model<any, any, any, any, a
81
83
  status?: string | undefined;
82
84
  data?: any;
83
85
  project?: any;
86
+ identifier?: string | undefined;
84
87
  runsAt?: Date | undefined;
85
88
  remainingNumberOfTries?: number | undefined;
86
89
  lastTriedAt?: Date | undefined;
@@ -9,6 +9,7 @@ exports.modelName = modelName;
9
9
  * タスクスキーマ
10
10
  */
11
11
  const schema = new mongoose_1.Schema({
12
+ identifier: String,
12
13
  project: mongoose_1.SchemaTypes.Mixed,
13
14
  name: String,
14
15
  status: String,
@@ -52,6 +53,13 @@ schema.index({ 'project.id': 1, runsAt: -1 }, { name: 'searchByProjectId-v202207
52
53
  schema.index({ name: 1, runsAt: -1 }, { name: 'searchByName-v2' });
53
54
  schema.index({ status: 1, runsAt: -1 }, { name: 'searchByStatus-v2' });
54
55
  schema.index({ runsAt: -1 }, { name: 'searchByRunsAt-v2' });
56
+ // identifier追加(2023-09-01~)
57
+ schema.index({ identifier: 1, runsAt: -1 }, {
58
+ name: 'searchByIdentifier',
59
+ partialFilterExpression: {
60
+ identifier: { $exists: true }
61
+ }
62
+ });
55
63
  schema.index({ dateAborted: 1, runsAt: -1 }, {
56
64
  name: 'searchByDateAborted',
57
65
  partialFilterExpression: {
@@ -30,6 +30,10 @@ export declare class MongoRepository {
30
30
  saveMany(taskAttributes: factory.task.IAttributes<factory.taskName>[], options: IOptionOnCreate): Promise<{
31
31
  id: string;
32
32
  }[]>;
33
+ /**
34
+ * タスク識別子から冪等作成する
35
+ */
36
+ createIfNotExistByIdentifier(params: factory.task.IAttributes<factory.taskName>, options: IOptionOnCreate): Promise<void>;
33
37
  createInformTaskIfNotExist(params: factory.task.IAttributes<factory.taskName.TriggerWebhook>, options: IOptionOnCreate): Promise<void>;
34
38
  /**
35
39
  * 取引削除タスク冪等作成
@@ -174,6 +174,30 @@ class MongoRepository {
174
174
  }
175
175
  });
176
176
  }
177
+ /**
178
+ * タスク識別子から冪等作成する
179
+ */
180
+ createIfNotExistByIdentifier(params, options) {
181
+ return __awaiter(this, void 0, void 0, function* () {
182
+ if (typeof params.identifier !== 'string' || params.identifier.length === 0) {
183
+ throw new factory.errors.ArgumentNull('identifier');
184
+ }
185
+ const createdTask = yield this.taskModel.findOneAndUpdate({
186
+ 'project.id': { $eq: params.project.id },
187
+ name: { $eq: params.name },
188
+ identifier: { $exists: true, $eq: params.identifier }
189
+ }, { $setOnInsert: params }, { new: true, upsert: true })
190
+ .select({ _id: 1 })
191
+ .exec();
192
+ if (options.emitImmediately) {
193
+ task_2.taskEventEmitter.emitTaskStatusChanged({
194
+ id: createdTask.id,
195
+ name: params.name,
196
+ status: factory.taskStatus.Ready
197
+ });
198
+ }
199
+ });
200
+ }
177
201
  createInformTaskIfNotExist(params, options) {
178
202
  return __awaiter(this, void 0, void 0, function* () {
179
203
  const createdTask = yield this.taskModel.findOneAndUpdate({
@@ -8,7 +8,7 @@ const factory = require("../../../factory");
8
8
  const settings_1 = require("../../../settings");
9
9
  // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
10
10
  function createStartParams(params) {
11
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1;
11
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0;
12
12
  const paymentServiceId = (params.paymentService !== undefined)
13
13
  ? String(params.paymentService.id)
14
14
  : '';
@@ -68,10 +68,16 @@ function createStartParams(params) {
68
68
  }
69
69
  }
70
70
  else if (params.paymentServiceType === factory.service.paymentService.PaymentServiceType.CreditCard) {
71
+ const creditCardPaymentServiceOutput = (_l = params.paymentService) === null || _l === void 0 ? void 0 : _l.serviceOutput;
72
+ const invoiceAsServiceOutput = (Array.isArray(creditCardPaymentServiceOutput))
73
+ ? creditCardPaymentServiceOutput.find((output) => output.typeOf === 'Invoice')
74
+ : creditCardPaymentServiceOutput;
71
75
  // カード通貨区分が存在すれば適用
72
- const creditCardAsPaymentServiceOutputCurrency = (_p = (_o = (_m = (_l = params.paymentService) === null || _l === void 0 ? void 0 : _l.serviceOutput) === null || _m === void 0 ? void 0 : _m.paymentMethod) === null || _o === void 0 ? void 0 : _o.amount) === null || _p === void 0 ? void 0 : _p.currency;
73
- if (typeof creditCardAsPaymentServiceOutputCurrency === 'string') {
74
- paymentMethodCurrency = creditCardAsPaymentServiceOutputCurrency;
76
+ if ((invoiceAsServiceOutput === null || invoiceAsServiceOutput === void 0 ? void 0 : invoiceAsServiceOutput.typeOf) === 'Invoice') {
77
+ const creditCardAsPaymentServiceOutputCurrency = (_o = (_m = invoiceAsServiceOutput.paymentMethod) === null || _m === void 0 ? void 0 : _m.amount) === null || _o === void 0 ? void 0 : _o.currency;
78
+ if (typeof creditCardAsPaymentServiceOutputCurrency === 'string') {
79
+ paymentMethodCurrency = creditCardAsPaymentServiceOutputCurrency;
80
+ }
75
81
  }
76
82
  }
77
83
  const paymentMethodAmount = {
@@ -79,24 +85,24 @@ function createStartParams(params) {
79
85
  currency: paymentMethodCurrency,
80
86
  value: params.amount
81
87
  };
82
- const paymentMethod = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ additionalProperty: (Array.isArray((_q = params.object.paymentMethod) === null || _q === void 0 ? void 0 : _q.additionalProperty))
83
- ? (_r = params.object.paymentMethod) === null || _r === void 0 ? void 0 : _r.additionalProperty
84
- : [], name: (typeof ((_s = params.object.paymentMethod) === null || _s === void 0 ? void 0 : _s.name) === 'string')
88
+ const paymentMethod = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ additionalProperty: (Array.isArray((_p = params.object.paymentMethod) === null || _p === void 0 ? void 0 : _p.additionalProperty))
89
+ ? (_q = params.object.paymentMethod) === null || _q === void 0 ? void 0 : _q.additionalProperty
90
+ : [], name: (typeof ((_r = params.object.paymentMethod) === null || _r === void 0 ? void 0 : _r.name) === 'string')
85
91
  ? params.object.paymentMethod.name
86
92
  : paymentMethodType,
87
93
  // MonetaryAmount対応(2023-08-14~)
88
94
  amount: (settings_1.USE_OBJECT_AS_PAY_TRANSACTION_AMOUNT) ? paymentMethodAmount : params.amount,
89
95
  // paymentMethodId: params.transactionNumber, // object.paymentMethodIdへ完全移行(2023-08-30~)
90
- identifier: paymentMethodType }, (typeof ((_t = params.object.paymentMethod) === null || _t === void 0 ? void 0 : _t.description) === 'string')
91
- ? { description: (_u = params.object.paymentMethod) === null || _u === void 0 ? void 0 : _u.description }
96
+ identifier: paymentMethodType }, (typeof ((_s = params.object.paymentMethod) === null || _s === void 0 ? void 0 : _s.description) === 'string')
97
+ ? { description: (_t = params.object.paymentMethod) === null || _t === void 0 ? void 0 : _t.description }
92
98
  : undefined), (totalPaymentDue !== undefined)
93
99
  ? { totalPaymentDue: totalPaymentDue }
94
- : undefined), (typeof accountId === 'string') ? { accountId: accountId } : undefined), (typeof ((_v = params.object.paymentMethod) === null || _v === void 0 ? void 0 : _v.method) === 'string')
95
- ? { method: (_w = params.object.paymentMethod) === null || _w === void 0 ? void 0 : _w.method }
96
- : undefined), (((_x = params.object.paymentMethod) === null || _x === void 0 ? void 0 : _x.creditCard) !== undefined)
97
- ? { creditCard: (_y = params.object.paymentMethod) === null || _y === void 0 ? void 0 : _y.creditCard }
98
- : undefined), (Array.isArray((_z = params.object.paymentMethod) === null || _z === void 0 ? void 0 : _z.movieTickets))
99
- ? { movieTickets: (_0 = params.object.paymentMethod) === null || _0 === void 0 ? void 0 : _0.movieTickets }
100
+ : undefined), (typeof accountId === 'string') ? { accountId: accountId } : undefined), (typeof ((_u = params.object.paymentMethod) === null || _u === void 0 ? void 0 : _u.method) === 'string')
101
+ ? { method: (_v = params.object.paymentMethod) === null || _v === void 0 ? void 0 : _v.method }
102
+ : undefined), (((_w = params.object.paymentMethod) === null || _w === void 0 ? void 0 : _w.creditCard) !== undefined)
103
+ ? { creditCard: (_x = params.object.paymentMethod) === null || _x === void 0 ? void 0 : _x.creditCard }
104
+ : undefined), (Array.isArray((_y = params.object.paymentMethod) === null || _y === void 0 ? void 0 : _y.movieTickets))
105
+ ? { movieTickets: (_z = params.object.paymentMethod) === null || _z === void 0 ? void 0 : _z.movieTickets }
100
106
  : undefined);
101
107
  const object = {
102
108
  // パラメータから必要なもののみ取り込む
@@ -107,7 +113,7 @@ function createStartParams(params) {
107
113
  onPaymentStatusChanged: { informPayment: informPaymentParams },
108
114
  paymentMethod
109
115
  };
110
- return Object.assign({ project: { typeOf: factory.organizationType.Project, id: params.project.id }, transactionNumber: params.transactionNumber, typeOf: factory.assetTransactionType.Pay, agent: params.agent, recipient: params.recipient, object, expires: params.expires }, (typeof ((_1 = params.location) === null || _1 === void 0 ? void 0 : _1.typeOf) === 'string')
116
+ return Object.assign({ project: { typeOf: factory.organizationType.Project, id: params.project.id }, transactionNumber: params.transactionNumber, typeOf: factory.assetTransactionType.Pay, agent: params.agent, recipient: params.recipient, object, expires: params.expires }, (typeof ((_0 = params.location) === null || _0 === void 0 ? void 0 : _0.typeOf) === 'string')
111
117
  ? { location: params.location }
112
118
  : undefined);
113
119
  }
@@ -6,7 +6,7 @@ exports.createStartParams = void 0;
6
6
  */
7
7
  const factory = require("../../../factory");
8
8
  function createStartParams(params) {
9
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
9
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
10
10
  const paymentMethodType = (_a = params.object.paymentMethod) === null || _a === void 0 ? void 0 : _a.typeOf;
11
11
  if (typeof paymentMethodType !== 'string') {
12
12
  throw new factory.errors.ArgumentNull('object.paymentMethod.typeOf');
@@ -23,7 +23,13 @@ function createStartParams(params) {
23
23
  let refundFee;
24
24
  if (((_g = params.paymentService) === null || _g === void 0 ? void 0 : _g.typeOf) === factory.service.paymentService.PaymentServiceType.CreditCard) {
25
25
  // カード通貨区分の存在する決済サービスを考慮(2023-08-09~)
26
- const paymentServiceOutputAmountCurrency = (_k = (_j = (_h = params.paymentService.serviceOutput) === null || _h === void 0 ? void 0 : _h.paymentMethod) === null || _j === void 0 ? void 0 : _j.amount) === null || _k === void 0 ? void 0 : _k.currency;
26
+ const invoiceAsServiceOutput = (Array.isArray(params.paymentService.serviceOutput))
27
+ ? params.paymentService.serviceOutput.find((output) => output.typeOf === 'Invoice')
28
+ : params.paymentService.serviceOutput;
29
+ let paymentServiceOutputAmountCurrency;
30
+ if ((invoiceAsServiceOutput === null || invoiceAsServiceOutput === void 0 ? void 0 : invoiceAsServiceOutput.typeOf) === 'Invoice') {
31
+ paymentServiceOutputAmountCurrency = (_j = (_h = invoiceAsServiceOutput === null || invoiceAsServiceOutput === void 0 ? void 0 : invoiceAsServiceOutput.paymentMethod) === null || _h === void 0 ? void 0 : _h.amount) === null || _j === void 0 ? void 0 : _j.currency;
32
+ }
27
33
  if (typeof paymentServiceOutputAmountCurrency !== 'string') {
28
34
  if (typeof params.object.refundFee === 'number') {
29
35
  refundFee = params.object.refundFee;
@@ -571,31 +571,64 @@ function validateProgramMembershipUsed(params) {
571
571
  if (typeof issuedThroughId !== 'string' || issuedThroughId.length === 0) {
572
572
  throw new factory.errors.ArgumentNull('acceptedOffer.itemOffered.serviceOutput.programMembershipUsed.issuedThrough.id');
573
573
  }
574
- // requestedProgramMembershipUsedの発行サービスIDから外部連携設定を取得する
575
- const permitService = yield createPermitService({ issuedThrough: { id: issuedThroughId } })(repos);
576
- // メンバーシップの存在確認
577
- const serviceOutput = yield permitService.findByIdentifier({
578
- project: { id: params.project.id },
579
- identifier: programMembershipUsedIdentifier,
580
- issuedThrough: { typeOf: factory.product.ProductType.MembershipService }
581
- });
582
- // 有効期間のチェック
583
- if (serviceOutput.validFrom === undefined || serviceOutput.validFrom === null
584
- || serviceOutput.validUntil === undefined || serviceOutput.validUntil === null) {
585
- throw new factory.errors.Argument('acceptedOffer.itemOffered.serviceOutput.programMembershipUsed', 'not valid programMembership');
586
- }
587
- if (moment(serviceOutput.validFrom)
588
- .isAfter(moment(now))
589
- || moment(serviceOutput.validUntil)
590
- .isBefore(moment(now))) {
591
- throw new factory.errors.Argument('acceptedOffer.itemOffered.serviceOutput.programMembershipUsed', 'unavailable programMembership');
574
+ const permitIssuedThrough = yield repos.product.findById({ id: issuedThroughId }, ['_id', 'typeOf', 'project', 'serviceType', 'serviceOutput'], []);
575
+ switch (permitIssuedThrough.typeOf) {
576
+ // 発行サービスがCreditCardのケースに対応(2023-09-01~)
577
+ case factory.service.paymentService.PaymentServiceType.CreditCard:
578
+ // 決済サービスのserviceOutputにPermitが存在すれば、設定されたメンバーシップ区分のPermitをprogramMembershipUsedとして適用する
579
+ let issuedThroughServiceType;
580
+ if (Array.isArray(permitIssuedThrough.serviceOutput)) {
581
+ const serviceOutputAsPermit = permitIssuedThrough.serviceOutput.find((output) => output.typeOf === factory.permit.PermitType.Permit);
582
+ if ((serviceOutputAsPermit === null || serviceOutputAsPermit === void 0 ? void 0 : serviceOutputAsPermit.typeOf) === factory.permit.PermitType.Permit) {
583
+ issuedThroughServiceType = serviceOutputAsPermit.issuedThrough.serviceType;
584
+ }
585
+ }
586
+ if ((issuedThroughServiceType === null || issuedThroughServiceType === void 0 ? void 0 : issuedThroughServiceType.typeOf) === 'CategoryCode') {
587
+ programMembershipUsed = {
588
+ project: permitIssuedThrough.project,
589
+ typeOf: factory.permit.PermitType.Permit,
590
+ identifier: programMembershipUsedIdentifier,
591
+ issuedThrough: {
592
+ id: permitIssuedThrough.id,
593
+ serviceType: issuedThroughServiceType,
594
+ typeOf: permitIssuedThrough.typeOf
595
+ }
596
+ };
597
+ }
598
+ else {
599
+ throw new factory.errors.Argument('acceptedOffer.itemOffered.serviceOutput.programMembershipUsed', 'issuedThrough has no serviceOutput as Permit');
600
+ }
601
+ break;
602
+ case factory.product.ProductType.MembershipService:
603
+ // requestedProgramMembershipUsedの発行サービスIDから外部連携設定を取得する
604
+ const permitService = yield createPermitService({ issuedThrough: { id: issuedThroughId } })(repos);
605
+ // メンバーシップの存在確認
606
+ const serviceOutput = yield permitService.findByIdentifier({
607
+ project: { id: params.project.id },
608
+ identifier: programMembershipUsedIdentifier,
609
+ issuedThrough: { typeOf: factory.product.ProductType.MembershipService }
610
+ });
611
+ // 有効期間のチェック
612
+ if (serviceOutput.validFrom === undefined || serviceOutput.validFrom === null
613
+ || serviceOutput.validUntil === undefined || serviceOutput.validUntil === null) {
614
+ throw new factory.errors.Argument('acceptedOffer.itemOffered.serviceOutput.programMembershipUsed', 'not valid programMembership');
615
+ }
616
+ if (moment(serviceOutput.validFrom)
617
+ .isAfter(moment(now))
618
+ || moment(serviceOutput.validUntil)
619
+ .isBefore(moment(now))) {
620
+ throw new factory.errors.Argument('acceptedOffer.itemOffered.serviceOutput.programMembershipUsed', 'unavailable programMembership');
621
+ }
622
+ programMembershipUsed = {
623
+ project: serviceOutput.project,
624
+ typeOf: serviceOutput.typeOf,
625
+ identifier: serviceOutput.identifier,
626
+ issuedThrough: serviceOutput.issuedThrough
627
+ };
628
+ break;
629
+ default:
630
+ throw new factory.errors.Argument('acceptedOffer.itemOffered.serviceOutput.programMembershipUsed', `${permitIssuedThrough.typeOf} not implemented`);
592
631
  }
593
- programMembershipUsed = {
594
- project: serviceOutput.project,
595
- typeOf: serviceOutput.typeOf,
596
- identifier: serviceOutput.identifier,
597
- issuedThrough: serviceOutput.issuedThrough
598
- };
599
632
  }
600
633
  return programMembershipUsed;
601
634
  });
@@ -21,10 +21,6 @@ export declare function createConfirmRegisterServiceActionObjectByOrder(params:
21
21
  order: factory.order.IOrder;
22
22
  }): factory.action.interact.confirm.registerService.IObject[];
23
23
  export type IExternalOrder = Pick<factory.order.IOrder, 'project' | 'typeOf' | 'seller' | 'customer' | 'confirmationNumber' | 'orderNumber' | 'price' | 'priceCurrency' | 'orderDate' | 'name' | 'orderStatus' | 'orderedItem' | 'paymentMethods'>;
24
- export declare function createOnPlaceOrderTasksByTransaction(params: {
25
- object: factory.order.IOrder | IExternalOrder;
26
- potentialActions?: factory.action.trade.order.IPotentialActions;
27
- }): factory.task.IAttributes<factory.taskName>[];
28
24
  /**
29
25
  * 注文配送後のアクション
30
26
  */
@@ -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.createOnOrderCancelledTasksByTransaction = exports.createOnOrderReturnedTasksByTransaction = exports.createOnOrderSentTasksByTransaction = exports.createOnPlaceOrderTasksByTransaction = exports.createConfirmRegisterServiceActionObjectByOrder = exports.createConfirmReservationActionObject4COAByOrder = exports.createConfirmReservationActionObject4ChevreByOrder = exports.createInformTasks = exports.getOrderWithToken = void 0;
13
+ exports.createOnOrderCancelledTasksByTransaction = exports.createOnOrderReturnedTasksByTransaction = exports.createOnOrderSentTasksByTransaction = 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,62 +262,38 @@ function createConfirmRegisterServiceActionObjectByOrder(params) {
262
262
  });
263
263
  }
264
264
  exports.createConfirmRegisterServiceActionObjectByOrder = createConfirmRegisterServiceActionObjectByOrder;
265
- function createOnPlaceOrderTasksByTransaction(params) {
266
- const potentialActions = params.potentialActions;
267
- const now = new Date();
268
- // potentialActionsのためのタスクを生成
269
- const taskAttributes = [];
270
- // tslint:disable-next-line:no-single-line-block-comment
271
- /* istanbul ignore else */
272
- if (potentialActions !== undefined) {
273
- // 冗長なsendOrderタスク作成を回避(createSendOrderTransactionTaskIfNotExistへ移行)(2023-08-25~)
274
- // tslint:disable-next-line:no-single-line-block-comment
275
- /* istanbul ignore else */
276
- // if (potentialActions.sendOrder !== undefined) {
277
- // const sendOrderTaskData: factory.task.IData<factory.taskName.SendOrder> = {
278
- // project: potentialActions.sendOrder.project,
279
- // object: {
280
- // ...potentialActions.sendOrder.object,
281
- // confirmationNumber: params.object.confirmationNumber
282
- // }
283
- // // 廃止(2023-08-21~)
284
- // // ...(potentialActions.sendOrder.potentialActions !== undefined)
285
- // // ? { potentialActions: potentialActions.sendOrder.potentialActions }
286
- // // : undefined
287
- // };
288
- // const sendOrderTask: factory.task.IAttributes<factory.taskName.SendOrder> = {
289
- // project: potentialActions.sendOrder.project,
290
- // name: factory.taskName.SendOrder,
291
- // status: factory.taskStatus.Ready,
292
- // runsAt: now, // なるはやで実行
293
- // remainingNumberOfTries: 10,
294
- // numberOfTried: 0,
295
- // executionResults: [],
296
- // data: sendOrderTaskData
297
- // };
298
- // taskAttributes.push(sendOrderTask);
299
- // }
300
- // ポイント付与
301
- // tslint:disable-next-line:no-single-line-block-comment
302
- /* istanbul ignore else */
303
- if (Array.isArray(potentialActions.givePointAward)) {
304
- taskAttributes.push(...potentialActions.givePointAward.map((a) => {
305
- return {
306
- project: a.project,
307
- name: factory.taskName.GivePointAward,
308
- status: factory.taskStatus.Ready,
309
- runsAt: now,
310
- remainingNumberOfTries: 10,
311
- numberOfTried: 0,
312
- executionResults: [],
313
- data: a
314
- };
315
- }));
316
- }
317
- }
318
- return taskAttributes;
319
- }
320
- exports.createOnPlaceOrderTasksByTransaction = createOnPlaceOrderTasksByTransaction;
265
+ // export function createOnPlaceOrderTasksByTransaction(params: {
266
+ // object: factory.order.IOrder | IExternalOrder;
267
+ // potentialActions?: factory.action.trade.order.IPotentialActions;
268
+ // }): factory.task.IAttributes<factory.taskName>[] {
269
+ // const potentialActions = params.potentialActions;
270
+ // const now = new Date();
271
+ // // potentialActionsのためのタスクを生成
272
+ // const taskAttributes: factory.task.IAttributes<factory.taskName>[] = [];
273
+ // // tslint:disable-next-line:no-single-line-block-comment
274
+ // /* istanbul ignore else */
275
+ // if (potentialActions !== undefined) {
276
+ // // ポイント付与
277
+ // // tslint:disable-next-line:no-single-line-block-comment
278
+ // /* istanbul ignore else */
279
+ // if (Array.isArray(potentialActions.givePointAward)) {
280
+ // taskAttributes.push(...potentialActions.givePointAward.map(
281
+ // (a): factory.task.IAttributes<factory.taskName.GivePointAward> => {
282
+ // return {
283
+ // project: a.project,
284
+ // name: factory.taskName.GivePointAward,
285
+ // status: factory.taskStatus.Ready,
286
+ // runsAt: now, // なるはやで実行
287
+ // remainingNumberOfTries: 10,
288
+ // numberOfTried: 0,
289
+ // executionResults: [],
290
+ // data: a
291
+ // };
292
+ // }));
293
+ // }
294
+ // }
295
+ // return taskAttributes;
296
+ // }
321
297
  /**
322
298
  * 注文配送後のアクション
323
299
  */
@@ -94,19 +94,19 @@ function onOrderStatusChanged(params) {
94
94
  // ...await createConfirmPayTransactionTasks(params.order, simpleOrder)(repos),
95
95
  // createConfirmReserveTransactionTasksIfNotExistへ移行(2023-08-25~)
96
96
  // ...await createConfirmReserveTransactionTasks(params.order, simpleOrder)(repos),
97
- ...yield createConfirmRegisterServiceTransactionTasks(params.order, simpleOrder)(repos),
97
+ ...yield createConfirmRegisterServiceTransactionTasks(params.order, simpleOrder)(repos)
98
98
  // 取引のpotentialActionsを適用(2023-08-17~)
99
- ...(0, factory_1.createOnPlaceOrderTasksByTransaction)({
100
- object: params.order,
101
- // potentialActions: params.potentialActions
102
- 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
103
- })
99
+ // createGivePointAwardTaskIfNotExistへ移行(2023-09-01~)
100
+ // ...createOnPlaceOrderTasksByTransaction({
101
+ // object: params.order,
102
+ // potentialActions: params.placeOrderTransaction?.potentialActions?.order?.potentialActions
103
+ // })
104
104
  ];
105
105
  break;
106
106
  case factory.orderStatus.OrderReturned:
107
- 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) => {
107
+ const potentialActionsByTransaction = (_j = (_h = (_g = (_f = params.returnOrderTransaction) === null || _f === void 0 ? void 0 : _f.potentialActions) === null || _g === void 0 ? void 0 : _g.returnOrder) === null || _h === void 0 ? void 0 : _h.find((returnOrderActionByTransaction) => {
108
108
  return returnOrderActionByTransaction.object.orderNumber === params.order.orderNumber;
109
- })) === null || _m === void 0 ? void 0 : _m.potentialActions;
109
+ })) === null || _j === void 0 ? void 0 : _j.potentialActions;
110
110
  tasks = [
111
111
  ...(0, factory_1.createInformTasks)(params.order),
112
112
  ...createReturnReserveTransactionTasks(params.order, simpleOrder),
@@ -133,6 +133,9 @@ function onOrderStatusChanged(params) {
133
133
  // 冗長なsendOrderタスク作成を回避(2023-08-25~)
134
134
  yield createSendOrderTransactionTaskIfNotExist({
135
135
  object: params.order,
136
+ potentialActions: (_m = (_l = (_k = params.placeOrderTransaction) === null || _k === void 0 ? void 0 : _k.potentialActions) === null || _l === void 0 ? void 0 : _l.order) === null || _m === void 0 ? void 0 : _m.potentialActions
137
+ })(repos);
138
+ yield createGivePointAwardTaskIfNotExist({
136
139
  potentialActions: (_q = (_p = (_o = params.placeOrderTransaction) === null || _o === void 0 ? void 0 : _o.potentialActions) === null || _p === void 0 ? void 0 : _p.order) === null || _q === void 0 ? void 0 : _q.potentialActions
137
140
  })(repos);
138
141
  break;
@@ -309,6 +312,35 @@ function createSendOrderTransactionTaskIfNotExist(params) {
309
312
  }
310
313
  });
311
314
  }
315
+ function createGivePointAwardTaskIfNotExist(params) {
316
+ return (repos) => __awaiter(this, void 0, void 0, function* () {
317
+ var _a;
318
+ const now = new Date();
319
+ const givePointAwardsByTransaction = (_a = params.potentialActions) === null || _a === void 0 ? void 0 : _a.givePointAward;
320
+ if (Array.isArray(givePointAwardsByTransaction)) {
321
+ for (const givePointAwardByTransaction of givePointAwardsByTransaction) {
322
+ let taskIdentifier = `${givePointAwardByTransaction.project.id}:${factory.taskName.GivePointAward}:${Date.now()}`;
323
+ if (typeof givePointAwardByTransaction.object.identifier === 'string'
324
+ && givePointAwardByTransaction.object.identifier.length > 0) {
325
+ taskIdentifier = `${givePointAwardByTransaction.project.id}:${factory.taskName.GivePointAward}:${givePointAwardByTransaction.object.identifier}`;
326
+ }
327
+ const givePointAwardTask = {
328
+ identifier: taskIdentifier,
329
+ project: givePointAwardByTransaction.project,
330
+ name: factory.taskName.GivePointAward,
331
+ status: factory.taskStatus.Ready,
332
+ runsAt: now,
333
+ remainingNumberOfTries: 10,
334
+ numberOfTried: 0,
335
+ executionResults: [],
336
+ data: givePointAwardByTransaction
337
+ };
338
+ // 冗長なgivePointAwardタスク作成を回避(2023-09-01~)
339
+ yield repos.task.createIfNotExistByIdentifier(givePointAwardTask, { emitImmediately: true });
340
+ }
341
+ }
342
+ });
343
+ }
312
344
  // const RETURN_COA_TASK_DELAY_IN_SECONDS = 0;
313
345
  function createReturnReserveTransactionTasks(order, simpleOrder) {
314
346
  var _a, _b;
package/package.json CHANGED
@@ -9,8 +9,8 @@
9
9
  }
10
10
  ],
11
11
  "dependencies": {
12
- "@chevre/factory": "4.329.0-alpha.0",
13
- "@cinerino/sdk": "3.166.0-alpha.3",
12
+ "@chevre/factory": "4.329.0-alpha.2",
13
+ "@cinerino/sdk": "3.166.0-alpha.5",
14
14
  "@motionpicture/coa-service": "9.2.0",
15
15
  "@motionpicture/gmo-service": "5.2.0",
16
16
  "@sendgrid/mail": "6.4.0",
@@ -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.8.0-alpha.22"
120
+ "version": "21.8.0-alpha.24"
121
121
  }