@chevre/domain 21.26.0-alpha.0 → 21.26.0-alpha.2

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,75 @@
1
+ // tslint:disable:no-console
2
+ import * as moment from 'moment';
3
+ import * as mongoose from 'mongoose';
4
+
5
+ import { chevre } from '../../../lib/index';
6
+
7
+ // const project = { id: String(process.env.PROJECT_ID) };
8
+
9
+ // tslint:disable-next-line:max-func-body-length
10
+ async function main() {
11
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
12
+
13
+ const actionRepo = await chevre.repository.Action.createInstance(mongoose.connection);
14
+
15
+ const cursor = actionRepo.getCursor(
16
+ {
17
+ typeOf: { $eq: chevre.factory.actionType.AuthorizeAction },
18
+ 'object.typeOf': { $eq: chevre.factory.action.authorize.paymentMethod.any.ResultType.Payment },
19
+ startDate: {
20
+ $gte: moment()
21
+ // tslint:disable-next-line:no-magic-numbers
22
+ .add(-180, 'days')
23
+ .toDate()
24
+ }
25
+ },
26
+ {
27
+ typeOf: 1,
28
+ project: 1,
29
+ instrument: 1,
30
+ startDate: 1,
31
+ object: 1
32
+ }
33
+ );
34
+ console.log('actions found');
35
+
36
+ let i = 0;
37
+ let updateCount = 0;
38
+ await cursor.eachAsync(async (doc) => {
39
+ i += 1;
40
+ const authorizeAction: Pick<
41
+ chevre.factory.action.authorize.paymentMethod.any.IAction,
42
+ 'project' | 'typeOf' | 'instrument' | 'startDate' | 'object'
43
+ > = doc.toObject();
44
+
45
+ const alreadyMigrated =
46
+ authorizeAction.instrument.identifier === chevre.factory.action.authorize.paymentMethod.any.ServiceIdentifier.Chevre;
47
+
48
+ if (alreadyMigrated) {
49
+ console.log(
50
+ 'already exist.',
51
+ authorizeAction.project.id,
52
+ authorizeAction.object.typeOf, authorizeAction.object.paymentMethodId, authorizeAction.startDate, i, updateCount
53
+ );
54
+ } else {
55
+ console.log(
56
+ 'updating...',
57
+ authorizeAction.project.id,
58
+ authorizeAction.object.typeOf, authorizeAction.object.paymentMethodId, authorizeAction.startDate, i, updateCount
59
+ );
60
+ updateCount += 1;
61
+ console.log(
62
+ 'updated.',
63
+ authorizeAction.project.id,
64
+ authorizeAction.object.typeOf, authorizeAction.object.paymentMethodId, authorizeAction.startDate, i, updateCount
65
+ );
66
+ }
67
+ });
68
+
69
+ console.log(i, 'actions checked');
70
+ console.log(updateCount, 'actions updated');
71
+ }
72
+
73
+ main()
74
+ .then()
75
+ .catch(console.error);
@@ -20,11 +20,11 @@ async function main() {
20
20
  runsAt: {
21
21
  $gte: moment()
22
22
  // tslint:disable-next-line:no-magic-numbers
23
- .add(299, 'days')
23
+ .add(329, 'days')
24
24
  .toDate(),
25
25
  $lte: moment()
26
26
  // tslint:disable-next-line:no-magic-numbers
27
- .add(330, 'days')
27
+ .add(365, 'days')
28
28
  .toDate()
29
29
  }
30
30
  // _id: { $eq: '64aba5f37b8b8ef9eca60be5' }
@@ -28,9 +28,13 @@ export declare namespace placeOrder {
28
28
  /**
29
29
  * オファー制約
30
30
  */
31
- numItems?: {
32
- maxValue?: number;
33
- minValue?: number;
31
+ numItems: {
32
+ maxValue: number;
33
+ minValue: number;
34
+ /**
35
+ * 最大COA予約数
36
+ */
37
+ maxNumCOAReservationNumbers: number;
34
38
  };
35
39
  /**
36
40
  * 注文アイテム制約
@@ -152,7 +152,10 @@ function createAuthorizeMoneyTransferOfferActionattributes(params) {
152
152
  ? seller.name
153
153
  : String((_b = seller.name) === null || _b === void 0 ? void 0 : _b.ja)
154
154
  },
155
- recipient: transaction.agent,
155
+ recipient: {
156
+ id: transaction.agent.id,
157
+ typeOf: transaction.agent.typeOf
158
+ },
156
159
  purpose: { typeOf: transaction.typeOf, id: transaction.id }
157
160
  };
158
161
  }
@@ -44,7 +44,6 @@ function createActionAttributes(params) {
44
44
  return {
45
45
  project: transaction.project,
46
46
  typeOf: factory.actionType.AuthorizeAction,
47
- // Chevreサービス登録取引を使用して
48
47
  instrument: {
49
48
  typeOf: factory.assetTransactionType.RegisterService,
50
49
  transactionNumber: params.transactionNumber
@@ -57,7 +56,10 @@ function createActionAttributes(params) {
57
56
  ? transaction.seller.name
58
57
  : String((_a = transaction.seller.name) === null || _a === void 0 ? void 0 : _a.ja)
59
58
  },
60
- recipient: transaction.agent,
59
+ recipient: {
60
+ id: transaction.agent.id,
61
+ typeOf: transaction.agent.typeOf
62
+ },
61
63
  purpose: { typeOf: transaction.typeOf, id: transaction.id }
62
64
  };
63
65
  }
@@ -80,12 +80,12 @@ function createConfirmPayTransactionTasks(order, simpleOrder) {
80
80
  object: [{ typeOf: factory.assetTransactionType.Pay, transactionNumber: invoice.paymentMethodId }],
81
81
  agent: order.project,
82
82
  purpose: Object.assign(Object.assign({}, simpleOrder), { confirmationNumber: order.confirmationNumber }),
83
- instrument: {
84
- // typeOf: 'WebAPI',
85
- typeOf: factory.assetTransactionType.Pay,
86
- identifier: factory.action.authorize.paymentMethod.any.ServiceIdentifier.Chevre,
87
- transactionNumber: invoice.paymentMethodId
88
- },
83
+ // 廃止(2024-03-12~)
84
+ // instrument: {
85
+ // typeOf: factory.assetTransactionType.Pay, // 産取引化(2024-03-11~)
86
+ // identifier: factory.action.authorize.paymentMethod.any.ServiceIdentifier.Chevre,
87
+ // transactionNumber: invoice.paymentMethodId
88
+ // },
89
89
  processOrder: order.orderStatus === factory.orderStatus.OrderPaymentDue,
90
90
  useOnOrderStatusChanged: true
91
91
  };
@@ -23,7 +23,7 @@ const factory_1 = require("./onOrderProcessing/factory");
23
23
  const debug = createDebug('chevre-domain:service:order');
24
24
  function onOrderProcessing(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;
27
27
  debug('onOrderStatusChanged called.', params.order.orderNumber, params.order.orderStatus, params.order.orderDate);
28
28
  let tasks = [];
29
29
  const sendOrderPotentialActions = (_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;
@@ -64,9 +64,10 @@ function onOrderProcessing(params) {
64
64
  else if (params.order.itemOfferedTypeOf === factory.permit.PermitType.Permit) {
65
65
  yield createConfirmRegisterServiceTasksIfNotExist(params.order, simpleOrder)(repos);
66
66
  }
67
- yield createGivePointAwardTaskIfNotExist({
68
- 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
69
- })(repos);
67
+ // 完全廃止(2024-03-12~)
68
+ // await createGivePointAwardTaskIfNotExist({
69
+ // potentialActions: params.placeOrderTransaction?.potentialActions?.order?.potentialActions
70
+ // })(repos);
70
71
  // OrderProcessingにおけるEメール送信に対応(2024-01-17~)
71
72
  if (settings_1.USE_SEND_EMAIL_MESSAGE_ON_ORDER_PROCESSING) {
72
73
  yield (0, createSendEmailMessageTaskIfNotExist_1.createSendEmailMessageTaskIfNotExist)({ potentialActions: sendOrderPotentialActions })(repos);
@@ -180,32 +181,3 @@ function createConfirmRegisterServiceTasksIfNotExist(order, simpleOrder) {
180
181
  })));
181
182
  });
182
183
  }
183
- function createGivePointAwardTaskIfNotExist(params) {
184
- return (repos) => __awaiter(this, void 0, void 0, function* () {
185
- var _a;
186
- const now = new Date();
187
- const givePointAwardsByTransaction = (_a = params.potentialActions) === null || _a === void 0 ? void 0 : _a.givePointAward;
188
- if (Array.isArray(givePointAwardsByTransaction)) {
189
- for (const givePointAwardByTransaction of givePointAwardsByTransaction) {
190
- let taskIdentifier = `${givePointAwardByTransaction.project.id}:${factory.taskName.GivePointAward}:${Date.now()}`;
191
- if (typeof givePointAwardByTransaction.object.identifier === 'string'
192
- && givePointAwardByTransaction.object.identifier.length > 0) {
193
- taskIdentifier = `${givePointAwardByTransaction.project.id}:${factory.taskName.GivePointAward}:${givePointAwardByTransaction.object.identifier}`;
194
- }
195
- const givePointAwardTask = {
196
- identifier: taskIdentifier,
197
- project: givePointAwardByTransaction.project,
198
- name: factory.taskName.GivePointAward,
199
- status: factory.taskStatus.Ready,
200
- runsAt: now,
201
- remainingNumberOfTries: 10,
202
- numberOfTried: 0,
203
- executionResults: [],
204
- data: givePointAwardByTransaction
205
- };
206
- // 冗長なgivePointAwardタスク作成を回避(2023-09-01~)
207
- yield repos.task.createIfNotExistByIdentifier(givePointAwardTask, { emitImmediately: true });
208
- }
209
- }
210
- });
211
- }
@@ -27,23 +27,27 @@ Object.defineProperty(exports, "person2username", { enumerable: true, get: funct
27
27
  */
28
28
  function voidPayTransaction(params) {
29
29
  return (repos) => __awaiter(this, void 0, void 0, function* () {
30
+ // 決済承認アクション確認不要(2024-03-12~)
30
31
  // 決済承認アクションを検索
31
- let authorizeActions = yield repos.action.searchByPurpose({
32
- typeOf: factory.actionType.AuthorizeAction,
33
- purpose: {
34
- typeOf: params.purpose.typeOf,
35
- id: params.purpose.id
36
- }
37
- });
38
- authorizeActions = authorizeActions.filter((a) => a.object.typeOf === factory.action.authorize.paymentMethod.any.ResultType.Payment);
39
- // Chevreを使用した承認を取り消し
40
- const authorizeActionsWithChevre = authorizeActions.filter((a) => {
41
- var _a;
42
- return ((_a = a.instrument) === null || _a === void 0 ? void 0 : _a.identifier) === factory.action.authorize.paymentMethod.any.ServiceIdentifier.Chevre;
43
- });
44
- if (authorizeActionsWithChevre.length > 0) {
45
- yield processVoidPayTransaction(params)(repos);
46
- }
32
+ // let authorizeActions = <factory.action.authorize.paymentMethod.any.IAction[]>
33
+ // await repos.action.searchByPurpose({
34
+ // typeOf: factory.actionType.AuthorizeAction,
35
+ // purpose: {
36
+ // typeOf: params.purpose.typeOf,
37
+ // id: params.purpose.id
38
+ // }
39
+ // });
40
+ // authorizeActions = authorizeActions.filter(
41
+ // (a) => a.object.typeOf === factory.action.authorize.paymentMethod.any.ResultType.Payment
42
+ // );
43
+ // // Chevreを使用した承認を取り消し
44
+ // const authorizeActionsWithChevre = authorizeActions.filter((a) => {
45
+ // return a.instrument?.identifier === factory.action.authorize.paymentMethod.any.ServiceIdentifier.Chevre;
46
+ // });
47
+ // if (authorizeActionsWithChevre.length > 0) {
48
+ // await processVoidPayTransaction(params)(repos);
49
+ // }
50
+ yield processVoidPayTransaction(params)(repos);
47
51
  // 決済URL無効化もここで処理
48
52
  yield invalidatePaymentUrl(params)(repos);
49
53
  });
@@ -140,7 +144,11 @@ function processVoidPayTransaction(params) {
140
144
  },
141
145
  object: { typeOf: { $eq: factory.action.authorize.paymentMethod.any.ResultType.Payment } }
142
146
  });
143
- authorizeActions = authorizeActionsOnTransaction.filter((a) => { var _a; return ((_a = a.instrument) === null || _a === void 0 ? void 0 : _a.identifier) === factory.action.authorize.paymentMethod.any.ServiceIdentifier.Chevre; });
147
+ // filter不要(2024-03-12~)
148
+ // authorizeActions = authorizeActionsOnTransaction.filter(
149
+ // (a) => a.instrument?.identifier === factory.action.authorize.paymentMethod.any.ServiceIdentifier.Chevre
150
+ // );
151
+ authorizeActions = authorizeActionsOnTransaction;
144
152
  switch (transaction.status) {
145
153
  case factory.transactionStatusType.InProgress:
146
154
  throw new factory.errors.NotImplemented(`${transaction.status} not implemented`);
@@ -136,8 +136,10 @@ function fixOrderAsPurpose(params) {
136
136
  function confirmReserveTransaction(params, options) {
137
137
  return (repos) => __awaiter(this, void 0, void 0, function* () {
138
138
  let confirmActionObject;
139
- switch (params.instrument.identifier) {
140
- case factory.service.webAPI.Identifier.COA:
139
+ switch (params.object.typeOf) {
140
+ // switch (params.instrument.identifier) {
141
+ case 'COAReserveTransaction':
142
+ // case factory.service.webAPI.Identifier.COA:
141
143
  // 最適化されたタスクに対応するため、ここでIObject4COAを注文から生成する(2024-01-24~)
142
144
  const order = yield fixOrderAsPurpose({
143
145
  project: { id: params.project.id },
@@ -171,8 +173,10 @@ function confirmReserveTransaction(params, options) {
171
173
  let updReserveResult;
172
174
  try {
173
175
  const object = confirmActionAttributes.object;
174
- switch (params.instrument.identifier) {
175
- case factory.service.webAPI.Identifier.COA:
176
+ switch (object.typeOf) {
177
+ // switch (params.instrument.identifier) {
178
+ case 'COAReserveTransaction':
179
+ // case factory.service.webAPI.Identifier.COA:
176
180
  // COA本予約
177
181
  updReserveResult = yield COAReserveService.confirm({
178
182
  project: { id: confirmActionAttributes.project.id },
@@ -10,7 +10,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.createPotentialActions = void 0;
13
- const givePointAward_1 = require("./potentialActions/givePointAward");
14
13
  const sendEmailMessage_1 = require("./potentialActions/sendEmailMessage");
15
14
  /**
16
15
  * 取引のポストアクションを作成する
@@ -18,7 +17,7 @@ const sendEmailMessage_1 = require("./potentialActions/sendEmailMessage");
18
17
  function createPotentialActions(params) {
19
18
  return __awaiter(this, void 0, void 0, function* () {
20
19
  // ポイントインセンティブに対する承認アクションの分だけ、ポイントインセンティブ付与アクションを作成する
21
- const givePointAwardActions = yield (0, givePointAward_1.createGivePointAwardActions)(params);
20
+ // const givePointAwardActions = await createGivePointAwardActions(params); // 完全廃止(2024-03-12~)
22
21
  // 注文配送メール送信設定
23
22
  const sendEmailMessageActions = yield (0, sendEmailMessage_1.createSendEmailMessageActions)(params);
24
23
  const sendOrderActionAttributes = {
@@ -32,7 +31,7 @@ function createPotentialActions(params) {
32
31
  return {
33
32
  order: {
34
33
  potentialActions: {
35
- givePointAward: givePointAwardActions,
34
+ // givePointAward: givePointAwardActions, // 完全廃止(2024-03-12~)
36
35
  sendOrder: sendOrderActionAttributes // optimize(2024-01-16~)
37
36
  }
38
37
  }
@@ -9,6 +9,9 @@ export type IAuthorizePaymentAction = factory.action.authorize.paymentMethod.any
9
9
  */
10
10
  export declare function validateTransaction(transaction: factory.transaction.placeOrder.ITransaction, authorizePaymentActions: IAuthorizePaymentAction[], authorizeEventServiceOfferActions: IAuthorizeEventServiceOffer[], authorizeMoneyTansferActions: IAuthorizeMoneyTransferOffer[], authorizeProductOfferActions: IAuthorizeProductOffer[], eventReservationAcceptedOffers: factory.order.IAcceptedOffer<factory.order.IReservation>[]): void;
11
11
  export type IOrderURLGenerator = (order: factory.order.IOrder) => string;
12
+ /**
13
+ * 注文オファー数検証
14
+ */
12
15
  export declare function validateNumItems(params: {
13
16
  result: {
14
17
  order: PlaceOrderFactory.IResultOrderParams;
@@ -199,8 +199,11 @@ function validateMonetaryAmount(authorizePaymentActions, authorizeEventServiceOf
199
199
  throw new factory.errors.Argument('Transaction', 'Required MonetaryAmount not satisfied');
200
200
  }
201
201
  }
202
+ /**
203
+ * 注文オファー数検証
204
+ */
202
205
  function validateNumItems(params) {
203
- var _a, _b;
206
+ var _a, _b, _c;
204
207
  if (!Array.isArray(params.acceptedOffers)) {
205
208
  throw new factory.errors.Argument('order.acceptedOffers', 'must be array');
206
209
  }
@@ -223,6 +226,21 @@ function validateNumItems(params) {
223
226
  if (itemOfferedTypeOfs.length > 1) {
224
227
  throw new factory.errors.Argument('Transaction', `different itemOffered.typeOfs contained. [${itemOfferedTypeOfs.join(',')}]`);
225
228
  }
229
+ const maxNumCOAReservationNumbers = (_c = params.result.order.numItems) === null || _c === void 0 ? void 0 : _c.maxNumCOAReservationNumbers;
230
+ if (typeof maxNumCOAReservationNumbers === 'number') {
231
+ // COA予約数検証(2024-03-12~)
232
+ let coaSerialNumbers = [];
233
+ params.acceptedOffers.forEach(({ offeredThrough, serialNumber }) => {
234
+ if ((offeredThrough === null || offeredThrough === void 0 ? void 0 : offeredThrough.identifier) === factory.service.webAPI.Identifier.COA
235
+ && typeof serialNumber === 'string') {
236
+ coaSerialNumbers.push(serialNumber);
237
+ }
238
+ });
239
+ coaSerialNumbers = [...new Set(coaSerialNumbers)];
240
+ if (coaSerialNumbers.length > maxNumCOAReservationNumbers) {
241
+ throw new factory.errors.Argument('Transaction', (0, util_1.format)('Number of reservationNumbers must be less than or equal to %s', maxNumCOAReservationNumbers));
242
+ }
243
+ }
226
244
  }
227
245
  exports.validateNumItems = validateNumItems;
228
246
  function validateOrderedItem(params) {
@@ -1,48 +1,9 @@
1
1
  /**
2
2
  * 進行中注文取引サービス
3
3
  */
4
- import type { MongoRepository as TransactionRepo } from '../../repo/transaction';
5
- import * as factory from '../../factory';
6
4
  import { POINT_AWARD_IDENTIFIER_NAME } from '../../factory/order';
7
5
  import { confirm } from './placeOrderInProgress/confirm';
8
6
  import { publishConfirmationNumberIfNotExist } from './placeOrderInProgress/publishConfirmationNumberIfNotExist';
9
7
  import { publishOrderNumberIfNotExist } from './placeOrderInProgress/publishOrderNumberIfNotExist';
10
8
  import { start } from './placeOrderInProgress/start';
11
- /**
12
- * インセンティブ承認
13
- */
14
- declare function authorizeAward(params: {
15
- transaction: {
16
- id: string;
17
- };
18
- agent: {
19
- id: string;
20
- };
21
- object?: {
22
- potentialActions?: {
23
- givePointAwardParams?: factory.transaction.placeOrder.IGivePointAwardParams[];
24
- };
25
- };
26
- }): (repos: {
27
- transaction: TransactionRepo;
28
- }) => Promise<void>;
29
- /**
30
- * インセンティブ承認を取り消す
31
- */
32
- declare function voidAward(params: {
33
- /**
34
- * 取引進行者
35
- */
36
- agent: {
37
- id: string;
38
- };
39
- /**
40
- * 取引
41
- */
42
- transaction: {
43
- id: string;
44
- };
45
- }): (repos: {
46
- transaction: TransactionRepo;
47
- }) => Promise<void>;
48
- export { authorizeAward, confirm, POINT_AWARD_IDENTIFIER_NAME, publishConfirmationNumberIfNotExist, publishOrderNumberIfNotExist, start, voidAward };
9
+ export { confirm, POINT_AWARD_IDENTIFIER_NAME, publishConfirmationNumberIfNotExist, publishOrderNumberIfNotExist, start };
@@ -1,16 +1,9 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.voidAward = exports.start = exports.publishOrderNumberIfNotExist = exports.publishConfirmationNumberIfNotExist = exports.POINT_AWARD_IDENTIFIER_NAME = exports.confirm = exports.authorizeAward = void 0;
13
- const factory = require("../../factory");
3
+ exports.start = exports.publishOrderNumberIfNotExist = exports.publishConfirmationNumberIfNotExist = exports.POINT_AWARD_IDENTIFIER_NAME = exports.confirm = void 0;
4
+ /**
5
+ * 進行中注文取引サービス
6
+ */
14
7
  const order_1 = require("../../factory/order");
15
8
  Object.defineProperty(exports, "POINT_AWARD_IDENTIFIER_NAME", { enumerable: true, get: function () { return order_1.POINT_AWARD_IDENTIFIER_NAME; } });
16
9
  const confirm_1 = require("./placeOrderInProgress/confirm");
@@ -21,67 +14,3 @@ const publishOrderNumberIfNotExist_1 = require("./placeOrderInProgress/publishOr
21
14
  Object.defineProperty(exports, "publishOrderNumberIfNotExist", { enumerable: true, get: function () { return publishOrderNumberIfNotExist_1.publishOrderNumberIfNotExist; } });
22
15
  const start_1 = require("./placeOrderInProgress/start");
23
16
  Object.defineProperty(exports, "start", { enumerable: true, get: function () { return start_1.start; } });
24
- /**
25
- * インセンティブ承認
26
- */
27
- function authorizeAward(params) {
28
- return (repos) => __awaiter(this, void 0, void 0, function* () {
29
- var _a, _b;
30
- const transaction = yield repos.transaction.findInProgressById({
31
- typeOf: factory.transactionType.PlaceOrder,
32
- id: params.transaction.id
33
- });
34
- // tslint:disable-next-line:no-single-line-block-comment
35
- /* istanbul ignore if: please write tests */
36
- if (transaction.agent.id !== params.agent.id) {
37
- throw new factory.errors.Forbidden('Transaction not yours');
38
- }
39
- if (transaction.agent.typeOf !== factory.personType.Person) {
40
- throw new factory.errors.Forbidden('Membership required');
41
- }
42
- // いったん特典リセット
43
- yield voidAward(params)(repos);
44
- const givePointAwardParams = (_b = (_a = params.object) === null || _a === void 0 ? void 0 : _a.potentialActions) === null || _b === void 0 ? void 0 : _b.givePointAwardParams;
45
- if (Array.isArray(givePointAwardParams)) {
46
- const pointAwardIdentifiers = givePointAwardParams.map((g) => { var _a; return String((_a = g.object) === null || _a === void 0 ? void 0 : _a.identifier); });
47
- // 取引にインセンティブ付与アクションパラメータを保管する
48
- yield repos.transaction.findByIdAndUpdateInProgress({
49
- id: transaction.id,
50
- update: {
51
- $set: {
52
- 'object.potentialActions.givePointAward': givePointAwardParams
53
- },
54
- // order.identifierに入金識別子を保管する
55
- $push: { 'object.identifier': { name: order_1.POINT_AWARD_IDENTIFIER_NAME, value: JSON.stringify(pointAwardIdentifiers) } }
56
- }
57
- });
58
- }
59
- });
60
- }
61
- exports.authorizeAward = authorizeAward;
62
- /**
63
- * インセンティブ承認を取り消す
64
- */
65
- function voidAward(params) {
66
- return (repos) => __awaiter(this, void 0, void 0, function* () {
67
- const transaction = yield repos.transaction.findInProgressById({
68
- typeOf: factory.transactionType.PlaceOrder,
69
- id: params.transaction.id
70
- });
71
- // tslint:disable-next-line:no-single-line-block-comment
72
- /* istanbul ignore if */
73
- if (transaction.agent.id !== params.agent.id) {
74
- throw new factory.errors.Forbidden('Transaction not yours');
75
- }
76
- yield repos.transaction.findByIdAndUpdateInProgress({
77
- id: transaction.id,
78
- update: {
79
- $unset: {
80
- 'object.potentialActions.givePointAward': 1
81
- },
82
- $pull: { 'object.identifier': { name: order_1.POINT_AWARD_IDENTIFIER_NAME } }
83
- }
84
- });
85
- });
86
- }
87
- exports.voidAward = voidAward;
package/package.json CHANGED
@@ -10,8 +10,8 @@
10
10
  ],
11
11
  "dependencies": {
12
12
  "@aws-sdk/credential-providers": "3.433.0",
13
- "@chevre/factory": "4.361.0",
14
- "@cinerino/sdk": "5.13.0",
13
+ "@chevre/factory": "4.362.0-alpha.2",
14
+ "@cinerino/sdk": "5.14.0-alpha.0",
15
15
  "@motionpicture/coa-service": "9.4.0",
16
16
  "@motionpicture/gmo-service": "5.3.0",
17
17
  "@sendgrid/mail": "6.4.0",
@@ -110,5 +110,5 @@
110
110
  "postversion": "git push origin --tags",
111
111
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
112
112
  },
113
- "version": "21.26.0-alpha.0"
113
+ "version": "21.26.0-alpha.2"
114
114
  }
@@ -1,72 +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
-
9
- // tslint:disable-next-line:max-func-body-length
10
- async function main() {
11
- await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
12
-
13
- const assetTransactionRepo = await chevre.repository.AssetTransaction.createInstance(mongoose.connection);
14
-
15
- const cursor = assetTransactionRepo.getCursor(
16
- {
17
- typeOf: { $eq: chevre.factory.assetTransactionType.Pay },
18
- // 'object.paymentMethodId': { $exists: false },
19
- // 'project.id': { $eq: project.id },
20
- startDate: {
21
- $gte: moment()
22
- // tslint:disable-next-line:no-magic-numbers
23
- .add(-12, 'months')
24
- .toDate()
25
- }
26
- },
27
- {
28
- typeOf: 1,
29
- project: 1,
30
- object: 1,
31
- transactionNumber: 1,
32
- startDate: 1
33
- }
34
- );
35
- console.log('transactions found');
36
-
37
- let i = 0;
38
- let updateCount = 0;
39
- await cursor.eachAsync(async (doc) => {
40
- i += 1;
41
- const payTransaction: Pick<
42
- chevre.factory.assetTransaction.pay.ITransaction,
43
- 'project' | 'object' | 'transactionNumber' | 'startDate' | 'typeOf'
44
- > = doc.toObject();
45
-
46
- const alreadyMigrated = typeof payTransaction.object.paymentMethodId === 'string'
47
- && payTransaction.object.paymentMethodId === (<any>payTransaction.object.paymentMethod).paymentMethodId;
48
-
49
- if (alreadyMigrated) {
50
- console.log(
51
- 'already exist.',
52
- payTransaction.project.id, payTransaction.typeOf, payTransaction.transactionNumber, payTransaction.startDate, i);
53
- } else {
54
- const paymentMethodIdentifier = (<any>payTransaction.object.paymentMethod).typeOf;
55
- console.log(
56
- 'updating...',
57
- payTransaction.project.id, payTransaction.typeOf, payTransaction.transactionNumber, payTransaction.startDate, i,
58
- paymentMethodIdentifier);
59
- updateCount += 1;
60
- console.log(
61
- 'updated.',
62
- payTransaction.project.id, payTransaction.typeOf, payTransaction.transactionNumber, payTransaction.startDate, i);
63
- }
64
- });
65
-
66
- console.log(i, 'transactions checked');
67
- console.log(updateCount, 'transactions updated');
68
- }
69
-
70
- main()
71
- .then()
72
- .catch(console.error);
@@ -1,5 +0,0 @@
1
- import * as factory from '../../../../factory';
2
- export declare function createGivePointAwardActions(params: {
3
- order: factory.order.IOrder;
4
- transaction: factory.transaction.placeOrder.ITransaction;
5
- }): Promise<factory.action.transfer.give.pointAward.IAttributes[]>;
@@ -1,70 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.createGivePointAwardActions = void 0;
13
- const factory = require("../../../../factory");
14
- // import { createMaskedCustomer } from '../../../../factory/order';
15
- function createGivePointAwardActions(params) {
16
- var _a;
17
- return __awaiter(this, void 0, void 0, function* () {
18
- const actions = [];
19
- // インセンティブ付与アクションの指定があればそちらを反映
20
- const givePointAwardParams = (_a = params.transaction.object.potentialActions) === null || _a === void 0 ? void 0 : _a.givePointAward;
21
- if (Array.isArray(givePointAwardParams)) {
22
- const givePointAwardPurpose = {
23
- typeOf: params.order.typeOf,
24
- // seller: {
25
- // id: params.order.seller.id,
26
- // typeOf: params.order.seller.typeOf,
27
- // name: params.order.seller.name
28
- // }, // 廃止(2024-03-06~)
29
- // mask
30
- // customer: createMaskedCustomer(params.order, { noProfile: true }), // 廃止(2024-03-06~)
31
- orderNumber: params.order.orderNumber,
32
- price: params.order.price,
33
- priceCurrency: params.order.priceCurrency,
34
- orderDate: params.order.orderDate
35
- };
36
- // メンバーシップごとに、特典を確認してインセンティブ付与
37
- givePointAwardParams.forEach((givePointAwardParam) => {
38
- var _a, _b, _c, _d, _e, _f, _g, _h;
39
- const amount = (_a = givePointAwardParam.object) === null || _a === void 0 ? void 0 : _a.amount;
40
- const pointAwardIdentifier = (_b = givePointAwardParam.object) === null || _b === void 0 ? void 0 : _b.identifier;
41
- const accountNumber = (_d = (_c = givePointAwardParam.object) === null || _c === void 0 ? void 0 : _c.toLocation) === null || _d === void 0 ? void 0 : _d.accountNumber;
42
- const description = (_e = givePointAwardParam.object) === null || _e === void 0 ? void 0 : _e.description;
43
- if (typeof amount === 'number' && typeof accountNumber === 'string') {
44
- actions.push({
45
- project: params.transaction.project,
46
- typeOf: factory.actionType.GiveAction,
47
- // agent: params.transaction.project,
48
- agent: {
49
- id: params.order.seller.id,
50
- typeOf: params.order.seller.typeOf,
51
- name: params.order.seller.name
52
- },
53
- recipient: {
54
- typeOf: params.order.customer.typeOf,
55
- id: params.order.customer.id,
56
- name: String(params.order.customer.name)
57
- },
58
- object: Object.assign({ typeOf: factory.action.transfer.give.pointAward.ObjectType.PointAward, amount: amount, toLocation: {
59
- accountNumber: accountNumber,
60
- issuedThrough: { id: String((_h = (_g = (_f = givePointAwardParam.object) === null || _f === void 0 ? void 0 : _f.toLocation) === null || _g === void 0 ? void 0 : _g.issuedThrough) === null || _h === void 0 ? void 0 : _h.id) }
61
- }, description: (typeof description === 'string') ? description : '' }, (typeof pointAwardIdentifier === 'string') ? { identifier: pointAwardIdentifier } : undefined),
62
- purpose: givePointAwardPurpose
63
- });
64
- }
65
- });
66
- }
67
- return actions;
68
- });
69
- }
70
- exports.createGivePointAwardActions = createGivePointAwardActions;