@chevre/domain 21.8.0-alpha.13 → 21.8.0-alpha.15

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,82 @@
1
+ // tslint:disable:no-console
2
+ import * as moment from 'moment';
3
+ import * as mongoose from 'mongoose';
4
+
5
+ import { chevre } from '../../../lib/index';
6
+
7
+ // const project = { id: String(process.env.PROJECT_ID) };
8
+ const EXCLUDED_PROJECT_ID = process.env.EXCLUDED_PROJECT_ID;
9
+
10
+ // tslint:disable-next-line:max-func-body-length
11
+ async function main() {
12
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
13
+
14
+ const orderRepo = new chevre.repository.Order(mongoose.connection);
15
+
16
+ const cursor = orderRepo.getCursor(
17
+ {
18
+ // 'project.id': { $eq: project.id },
19
+ 'project.id': { $ne: EXCLUDED_PROJECT_ID },
20
+ orderDate: {
21
+ $gte: moment()
22
+ // tslint:disable-next-line:no-magic-numbers
23
+ .add(-3, 'months')
24
+ .toDate()
25
+ }
26
+ },
27
+ {
28
+ // _id: 1,
29
+ // project: 1,
30
+ // location: 1,
31
+ // superEvent: 1,
32
+ // startDate: 1,
33
+ // typeOf: 1,
34
+ // organizer: 1
35
+ }
36
+ );
37
+ console.log('orders found');
38
+
39
+ let i = 0;
40
+ const updateCount = 0;
41
+ await cursor.eachAsync(async (doc) => {
42
+ i += 1;
43
+ const order: Pick<
44
+ chevre.factory.order.IOrder,
45
+ 'orderDate' | 'orderNumber' | 'project'
46
+ > = doc.toObject();
47
+
48
+ const alreadyMigrated = typeof order.orderNumber === 'string';
49
+
50
+ if (alreadyMigrated) {
51
+ console.log('already exist...', order.project.id, order.orderNumber, order.orderDate, i);
52
+ } else {
53
+ throw new Error('not implemented');
54
+ // if (typeof sellerId !== 'string') {
55
+ // throw new Error('movieTheater not found');
56
+ // }
57
+ // if (typeof sellerId === 'string') {
58
+ // const newOrganizer: chevre.factory.event.screeningEventSeries.IOrganizer = {
59
+ // id: sellerId
60
+ // };
61
+ // console.log('updating event...', event.project.id, event.id, event.startDate, i);
62
+ // await eventRepo.updatePartiallyById({
63
+ // project: { id: event.project.id },
64
+ // id: event.id,
65
+ // attributes: <any>{
66
+ // typeOf: event.typeOf,
67
+ // organizer: newOrganizer
68
+ // }
69
+ // });
70
+ // updateCount += 1;
71
+ // console.log('updated.', event.project.id, event.id, event.startDate, i);
72
+ // }
73
+ }
74
+ });
75
+
76
+ console.log(i, 'orders checked');
77
+ console.log(updateCount, 'orders updated');
78
+ }
79
+
80
+ main()
81
+ .then()
82
+ .catch(console.error);
@@ -36,8 +36,8 @@ export declare class MongoRepository {
36
36
  */
37
37
  createDeleteTransactionTaskIfNotExist(params: factory.task.IAttributes<factory.taskName.DeleteTransaction>, options: IOptionOnCreate): Promise<void>;
38
38
  createConfirmReserveTransactionTaskIfNotExist(params: factory.task.IAttributes<factory.taskName.ConfirmReserveTransaction>, options: IOptionOnCreate): Promise<void>;
39
+ createOnAssetTransactionStatusChangedTaskIfNotExist(params: factory.task.IAttributes<factory.taskName.OnAssetTransactionStatusChanged>, options: IOptionOnCreate): Promise<void>;
39
40
  createSendOrderTaskIfNotExist(params: factory.task.IAttributes<factory.taskName.SendOrder>, options: IOptionOnCreate): Promise<void>;
40
- createOnOrderPaymentCompletedTaskIfNotExist(params: factory.task.IAttributes<factory.taskName.OnOrderPaymentCompleted>, options: IOptionOnCreate): Promise<void>;
41
41
  executeById(params: {
42
42
  id: string;
43
43
  executor: {
@@ -70,7 +70,7 @@ export declare class MongoRepository {
70
70
  */
71
71
  $nin?: factory.taskName[];
72
72
  };
73
- }): Promise<Pick<import("@chevre/factory/lib/task").ITask | import("@chevre/factory/lib/task/confirmMoneyTransfer").ITask | import("@chevre/factory/lib/task/confirmRegisterService").ITask | import("@chevre/factory/lib/task/confirmPayTransaction").ITask | import("@chevre/factory/lib/task/confirmRegisterServiceTransaction").ITask | import("@chevre/factory/lib/task/confirmReserveTransaction").ITask | import("@chevre/factory/lib/task/createEvent").ITask | import("@chevre/factory/lib/task/deleteTransaction").ITask | import("@chevre/factory/lib/task/givePointAward").ITask | import("@chevre/factory/lib/task/onAuthorizationCreated").ITask | import("@chevre/factory/lib/task/onEventChanged").ITask | import("@chevre/factory/lib/task/onResourceUpdated").ITask | import("@chevre/factory/lib/task/onOrderPaymentCompleted").ITask | import("@chevre/factory/lib/task/placeOrder").ITask | import("@chevre/factory/lib/task/returnOrder").ITask | import("@chevre/factory/lib/task/returnMoneyTransfer").ITask | import("@chevre/factory/lib/task/returnPayTransaction").ITask | import("@chevre/factory/lib/task/returnPointAward").ITask | import("@chevre/factory/lib/task/returnReserveTransaction").ITask | import("@chevre/factory/lib/task/sendEmailMessage").ITask | import("@chevre/factory/lib/task/sendOrder").ITask | import("@chevre/factory/lib/task/syncScreeningRooms").ITask | import("@chevre/factory/lib/task/triggerWebhook").ITask | import("@chevre/factory/lib/task/useReservation").ITask | import("@chevre/factory/lib/task/voidMoneyTransferTransaction").ITask | import("@chevre/factory/lib/task/voidPayTransaction").ITask | import("@chevre/factory/lib/task/voidRegisterServiceTransaction").ITask | import("@chevre/factory/lib/task/voidReserveTransaction").ITask, "id" | "name" | "status">[]>;
73
+ }): Promise<Pick<import("@chevre/factory/lib/task").ITask | import("@chevre/factory/lib/task/confirmMoneyTransfer").ITask | import("@chevre/factory/lib/task/confirmRegisterService").ITask | import("@chevre/factory/lib/task/confirmPayTransaction").ITask | import("@chevre/factory/lib/task/confirmRegisterServiceTransaction").ITask | import("@chevre/factory/lib/task/confirmReserveTransaction").ITask | import("@chevre/factory/lib/task/createEvent").ITask | import("@chevre/factory/lib/task/deleteTransaction").ITask | import("@chevre/factory/lib/task/givePointAward").ITask | import("@chevre/factory/lib/task/onAssetTransactionStatusChanged").ITask | import("@chevre/factory/lib/task/onAuthorizationCreated").ITask | import("@chevre/factory/lib/task/onEventChanged").ITask | import("@chevre/factory/lib/task/onResourceUpdated").ITask | import("@chevre/factory/lib/task/onOrderPaymentCompleted").ITask | import("@chevre/factory/lib/task/placeOrder").ITask | import("@chevre/factory/lib/task/returnOrder").ITask | import("@chevre/factory/lib/task/returnMoneyTransfer").ITask | import("@chevre/factory/lib/task/returnPayTransaction").ITask | import("@chevre/factory/lib/task/returnPointAward").ITask | import("@chevre/factory/lib/task/returnReserveTransaction").ITask | import("@chevre/factory/lib/task/sendEmailMessage").ITask | import("@chevre/factory/lib/task/sendOrder").ITask | import("@chevre/factory/lib/task/syncScreeningRooms").ITask | import("@chevre/factory/lib/task/triggerWebhook").ITask | import("@chevre/factory/lib/task/useReservation").ITask | import("@chevre/factory/lib/task/voidMoneyTransferTransaction").ITask | import("@chevre/factory/lib/task/voidPayTransaction").ITask | import("@chevre/factory/lib/task/voidRegisterServiceTransaction").ITask | import("@chevre/factory/lib/task/voidReserveTransaction").ITask, "id" | "name" | "status">[]>;
74
74
  retry(params: {
75
75
  intervalInMinutes: number;
76
76
  }): Promise<void>;
@@ -244,14 +244,18 @@ class MongoRepository {
244
244
  }
245
245
  });
246
246
  }
247
- createSendOrderTaskIfNotExist(params, options) {
247
+ createOnAssetTransactionStatusChangedTaskIfNotExist(params, options) {
248
248
  return __awaiter(this, void 0, void 0, function* () {
249
249
  const createdTask = yield this.taskModel.findOneAndUpdate({
250
250
  'project.id': { $eq: params.project.id },
251
251
  name: { $eq: params.name },
252
- 'data.object.orderNumber': {
252
+ 'data.object.transactionNumber': {
253
253
  $exists: true,
254
- $eq: String(params.data.object.orderNumber)
254
+ $eq: String(params.data.object.transactionNumber)
255
+ },
256
+ 'data.purpose.orderNumber': {
257
+ $exists: true,
258
+ $eq: String(params.data.purpose.orderNumber)
255
259
  }
256
260
  }, { $setOnInsert: params }, { new: true, upsert: true })
257
261
  .select({ _id: 1 })
@@ -265,7 +269,7 @@ class MongoRepository {
265
269
  }
266
270
  });
267
271
  }
268
- createOnOrderPaymentCompletedTaskIfNotExist(params, options) {
272
+ createSendOrderTaskIfNotExist(params, options) {
269
273
  return __awaiter(this, void 0, void 0, function* () {
270
274
  const createdTask = yield this.taskModel.findOneAndUpdate({
271
275
  'project.id': { $eq: params.project.id },
@@ -286,6 +290,32 @@ class MongoRepository {
286
290
  }
287
291
  });
288
292
  }
293
+ // public async createOnOrderPaymentCompletedTaskIfNotExist(
294
+ // params: factory.task.IAttributes<factory.taskName.OnOrderPaymentCompleted>,
295
+ // options: IOptionOnCreate
296
+ // ): Promise<void> {
297
+ // const createdTask = await this.taskModel.findOneAndUpdate(
298
+ // {
299
+ // 'project.id': { $eq: params.project.id },
300
+ // name: { $eq: params.name },
301
+ // 'data.object.orderNumber': {
302
+ // $exists: true,
303
+ // $eq: String(params.data.object.orderNumber)
304
+ // }
305
+ // },
306
+ // { $setOnInsert: params },
307
+ // { new: true, upsert: true }
308
+ // )
309
+ // .select({ _id: 1 })
310
+ // .exec();
311
+ // if (options.emitImmediately) {
312
+ // taskEventEmitter.emitTaskStatusChanged({
313
+ // id: createdTask.id,
314
+ // name: params.name,
315
+ // status: factory.taskStatus.Ready
316
+ // });
317
+ // }
318
+ // }
289
319
  executeById(params) {
290
320
  return __awaiter(this, void 0, void 0, function* () {
291
321
  const doc = yield this.taskModel.findOneAndUpdate({
@@ -1,7 +1,6 @@
1
1
  import * as factory from '../../factory';
2
2
  import { MongoRepository as AccountingReportRepo } from '../../repo/accountingReport';
3
3
  import { MongoRepository as ActionRepo } from '../../repo/action';
4
- import { RedisRepository as RegisterServiceInProgressRepo } from '../../repo/action/registerServiceInProgress';
5
4
  import { MongoRepository as AssetTransactionRepo } from '../../repo/assetTransaction';
6
5
  import { MongoRepository as EventRepo } from '../../repo/event';
7
6
  import { MongoRepository as OrderRepo } from '../../repo/order';
@@ -21,6 +20,5 @@ declare function confirmPayTransaction(data: factory.task.IData<factory.taskName
21
20
  seller: SellerRepo;
22
21
  task: TaskRepo;
23
22
  transaction: TransactionRepo;
24
- registerServiceInProgress: RegisterServiceInProgressRepo;
25
23
  }) => Promise<void>;
26
24
  export { confirmPayTransaction };
@@ -10,10 +10,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.confirmPayTransaction = void 0;
13
- const createDebug = require("debug");
14
13
  const factory = require("../../factory");
15
14
  const PayTransactionService = require("../assetTransaction/pay");
16
- const debug = createDebug('chevre-domain:service:order');
17
15
  function confirmPayTransaction(data) {
18
16
  return (repos) => __awaiter(this, void 0, void 0, function* () {
19
17
  // アクション開始
@@ -60,11 +58,7 @@ function confirmPayTransaction(data) {
60
58
  yield repos.action.complete({ typeOf: action.typeOf, id: action.id, result: actionResult });
61
59
  // processOrder連携(2023-08-23~)
62
60
  yield onConfirmed(data)({
63
- assetTransaction: repos.assetTransaction,
64
- order: repos.order,
65
- registerActionInProgress: repos.registerServiceInProgress,
66
- task: repos.task,
67
- transaction: repos.transaction
61
+ task: repos.task
68
62
  });
69
63
  });
70
64
  }
@@ -72,52 +66,33 @@ exports.confirmPayTransaction = confirmPayTransaction;
72
66
  function onConfirmed(params) {
73
67
  return (repos) => __awaiter(this, void 0, void 0, function* () {
74
68
  if (params.processOrder === true) {
75
- // 注文のpaymentMethodIdを取得
76
- const order = yield repos.order.findByOrderNumber({
77
- orderNumber: params.purpose.orderNumber,
78
- project: { id: params.project.id },
79
- inclusion: ['paymentMethods'],
80
- exclusion: []
81
- });
82
- // PayTransactionのステータス検証
83
- let allPayTransactionConfirmed = false;
84
- const paymentMethodIds = order.paymentMethods.filter((invoice) => typeof invoice.paymentMethodId === 'string' && invoice.paymentMethodId.length > 0)
85
- .map((invoice) => invoice.paymentMethodId);
86
- if (paymentMethodIds.length > 0) {
87
- debug('checking allPayTransactionConfirmed...', 'orderNumber:', params.purpose.orderNumber);
88
- const referencedPayTransactions = yield repos.assetTransaction.search({
89
- project: { id: { $eq: params.project.id } },
90
- typeOf: factory.assetTransactionType.Pay,
91
- transactionNumber: { $in: paymentMethodIds }
92
- }, ['status']);
93
- allPayTransactionConfirmed =
94
- referencedPayTransactions.every((payTransation) => payTransation.status === factory.transactionStatusType.Confirmed);
95
- debug('allPayTransactionConfirmed?:', allPayTransactionConfirmed, 'referencedPayTransactions:', JSON.stringify(referencedPayTransactions), 'orderNumber:', params.purpose.orderNumber);
96
- }
97
- else {
98
- allPayTransactionConfirmed = true;
99
- }
100
- if (allPayTransactionConfirmed) {
101
- // onOrderPaymentCompletedタスク冪等作成
102
- const onPaymentCompletedTaskData = {
69
+ for (const confirmingTransaction of params.object) {
70
+ // タスク冪等作成
71
+ const onAssetTransactionStatusChangedTaskData = {
103
72
  project: { id: params.project.id, typeOf: factory.organizationType.Project },
104
73
  object: {
74
+ typeOf: factory.assetTransactionType.Pay,
75
+ transactionNumber: confirmingTransaction.transactionNumber,
76
+ status: factory.transactionStatusType.Confirmed
77
+ },
78
+ purpose: {
105
79
  confirmationNumber: params.purpose.confirmationNumber,
106
- orderNumber: params.purpose.orderNumber
80
+ orderNumber: params.purpose.orderNumber,
81
+ typeOf: 'Order'
107
82
  },
108
83
  useOnOrderStatusChanged: params.useOnOrderStatusChanged === true
109
84
  };
110
- const onPaymentCompletedTaskAttributes = {
85
+ const onAssetTransactionStatusChangedTask = {
111
86
  project: { id: params.project.id, typeOf: factory.organizationType.Project },
112
- name: factory.taskName.OnOrderPaymentCompleted,
87
+ name: factory.taskName.OnAssetTransactionStatusChanged,
113
88
  status: factory.taskStatus.Ready,
114
89
  runsAt: new Date(),
115
90
  remainingNumberOfTries: 10,
116
91
  numberOfTried: 0,
117
92
  executionResults: [],
118
- data: onPaymentCompletedTaskData
93
+ data: onAssetTransactionStatusChangedTaskData
119
94
  };
120
- yield repos.task.createOnOrderPaymentCompletedTaskIfNotExist(onPaymentCompletedTaskAttributes, { emitImmediately: true });
95
+ yield repos.task.createOnAssetTransactionStatusChangedTaskIfNotExist(onAssetTransactionStatusChangedTask, { emitImmediately: true });
121
96
  }
122
97
  }
123
98
  });
@@ -0,0 +1,27 @@
1
+ import { RedisRepository as RegisterServiceInProgressRepo } from '../../repo/action/registerServiceInProgress';
2
+ import { MongoRepository as AssetTransactionRepo } from '../../repo/assetTransaction';
3
+ import { MongoRepository as OrderRepo } from '../../repo/order';
4
+ import { MongoRepository as TaskRepo } from '../../repo/task';
5
+ import { MongoRepository as TransactionRepo } from '../../repo/transaction';
6
+ import * as factory from '../../factory';
7
+ declare function onAssetTransactionStatusChanged(params: factory.task.IData<factory.taskName.OnAssetTransactionStatusChanged>): (repos: {
8
+ assetTransaction: AssetTransactionRepo;
9
+ order: OrderRepo;
10
+ registerActionInProgress: RegisterServiceInProgressRepo;
11
+ task: TaskRepo;
12
+ transaction: TransactionRepo;
13
+ }) => Promise<void>;
14
+ declare function paymentDue2Processing(params: {
15
+ project: {
16
+ id: string;
17
+ };
18
+ confirmationNumber: string;
19
+ orderNumber: string;
20
+ useOnOrderStatusChanged: boolean;
21
+ }): (repos: {
22
+ order: OrderRepo;
23
+ registerActionInProgress: RegisterServiceInProgressRepo;
24
+ task: TaskRepo;
25
+ transaction: TransactionRepo;
26
+ }) => Promise<void>;
27
+ export { onAssetTransactionStatusChanged, paymentDue2Processing };
@@ -0,0 +1,129 @@
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.paymentDue2Processing = exports.onAssetTransactionStatusChanged = void 0;
13
+ const findPlaceOrderTransaction_1 = require("./findPlaceOrderTransaction");
14
+ const onOrderStatusChanged_1 = require("./onOrderStatusChanged");
15
+ const factory = require("../../factory");
16
+ function onAssetTransactionStatusChanged(params) {
17
+ return (repos) => __awaiter(this, void 0, void 0, function* () {
18
+ var _a, _b;
19
+ if (typeof params.useOnOrderStatusChanged !== 'boolean') {
20
+ throw new factory.errors.Argument('useOnOrderStatusChanged', 'must be boolean');
21
+ }
22
+ switch (params.object.status) {
23
+ case factory.transactionStatusType.Confirmed:
24
+ switch (params.object.typeOf) {
25
+ case factory.assetTransactionType.Pay:
26
+ const orderNumber = (_a = params.purpose) === null || _a === void 0 ? void 0 : _a.orderNumber;
27
+ const confirmationNumber = (_b = params.purpose) === null || _b === void 0 ? void 0 : _b.confirmationNumber;
28
+ if (typeof orderNumber === 'string' && typeof confirmationNumber === 'string') {
29
+ // PayTransactionのステータス検証
30
+ const processable = yield isProcessable({ project: { id: params.project.id }, orderNumber })(repos);
31
+ if (processable) {
32
+ yield paymentDue2Processing({
33
+ project: { id: params.project.id },
34
+ confirmationNumber,
35
+ orderNumber,
36
+ useOnOrderStatusChanged: params.useOnOrderStatusChanged
37
+ })(repos);
38
+ }
39
+ }
40
+ break;
41
+ default:
42
+ // no op
43
+ }
44
+ break;
45
+ default:
46
+ // no op
47
+ }
48
+ });
49
+ }
50
+ exports.onAssetTransactionStatusChanged = onAssetTransactionStatusChanged;
51
+ function isProcessable(params) {
52
+ return (repos) => __awaiter(this, void 0, void 0, function* () {
53
+ // 注文のpaymentMethodIdを取得
54
+ const order = yield repos.order.findByOrderNumber({
55
+ orderNumber: params.orderNumber,
56
+ project: { id: params.project.id },
57
+ inclusion: ['paymentMethods'],
58
+ exclusion: []
59
+ });
60
+ // PayTransactionのステータス検証
61
+ let allPayTransactionConfirmed = false;
62
+ const paymentMethodIds = order.paymentMethods.filter((invoice) => typeof invoice.paymentMethodId === 'string' && invoice.paymentMethodId.length > 0)
63
+ .map((invoice) => invoice.paymentMethodId);
64
+ if (paymentMethodIds.length > 0) {
65
+ const referencedPayTransactions = yield repos.assetTransaction.search({
66
+ project: { id: { $eq: params.project.id } },
67
+ typeOf: factory.assetTransactionType.Pay,
68
+ transactionNumber: { $in: paymentMethodIds }
69
+ }, ['status']);
70
+ allPayTransactionConfirmed =
71
+ referencedPayTransactions.every((payTransation) => payTransation.status === factory.transactionStatusType.Confirmed);
72
+ }
73
+ else {
74
+ allPayTransactionConfirmed = true;
75
+ }
76
+ return allPayTransactionConfirmed;
77
+ });
78
+ }
79
+ function paymentDue2Processing(params) {
80
+ return (repos) => __awaiter(this, void 0, void 0, function* () {
81
+ const placeOrderTransaction = yield (0, findPlaceOrderTransaction_1.findPlaceOrderTransaction)({
82
+ project: { id: params.project.id },
83
+ confirmationNumber: params.confirmationNumber,
84
+ orderNumber: params.orderNumber
85
+ })({ transaction: repos.transaction });
86
+ let order = yield repos.order.findByOrderNumber({
87
+ orderNumber: params.orderNumber,
88
+ project: { id: params.project.id },
89
+ inclusion: [],
90
+ exclusion: []
91
+ });
92
+ try {
93
+ order = yield repos.order.changeStatus({
94
+ project: { id: order.project.id },
95
+ orderNumber: params.orderNumber,
96
+ orderStatus: factory.orderStatus.OrderProcessing,
97
+ previousOrderStatus: factory.orderStatus.OrderPaymentDue
98
+ });
99
+ }
100
+ catch (error) {
101
+ let throwsError = true;
102
+ // すでにステータスが煤でいた場合、OrderPaymentDue->OrderProcessingの処理自体は成功しているので、後処理を続行する
103
+ order = yield repos.order.findByOrderNumber({
104
+ orderNumber: params.orderNumber,
105
+ project: { id: params.project.id },
106
+ inclusion: [],
107
+ exclusion: []
108
+ });
109
+ if (order.orderStatus === factory.orderStatus.OrderDelivered
110
+ || order.orderStatus === factory.orderStatus.OrderReturned) {
111
+ throwsError = false;
112
+ }
113
+ if (throwsError) {
114
+ throw error;
115
+ }
116
+ }
117
+ if (params.useOnOrderStatusChanged) {
118
+ yield (0, onOrderStatusChanged_1.onOrderStatusChanged)({
119
+ order: Object.assign(Object.assign({}, order), { orderStatus: factory.orderStatus.OrderProcessing // 強制的にOrderProcessingとして処理する
120
+ }),
121
+ placeOrderTransaction
122
+ })({
123
+ registerActionInProgress: repos.registerActionInProgress,
124
+ task: repos.task
125
+ });
126
+ }
127
+ });
128
+ }
129
+ exports.paymentDue2Processing = paymentDue2Processing;
@@ -30,11 +30,11 @@ export declare function createOnPlaceOrderTasksByTransaction(params: {
30
30
  */
31
31
  export declare function createOnOrderSentTasksByTransaction(params: {
32
32
  potentialActions?: factory.action.transfer.send.order.IPotentialActions;
33
- }): (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/onOrderPaymentCompleted").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)[];
33
+ }): (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/onAssetTransactionStatusChanged").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/onOrderPaymentCompleted").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)[];
34
34
  /**
35
35
  * 注文返品後のアクション
36
36
  */
37
37
  export declare function createOnOrderReturnedTasksByTransaction(params: {
38
38
  potentialActions?: factory.action.transfer.returnAction.order.IPotentialActions;
39
- }): (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/onOrderPaymentCompleted").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)[];
39
+ }): (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/onAssetTransactionStatusChanged").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/onOrderPaymentCompleted").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)[];
40
40
  export {};
@@ -10,8 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.payOrder = void 0;
13
- const findPlaceOrderTransaction_1 = require("./findPlaceOrderTransaction");
14
- const onOrderStatusChanged_1 = require("./onOrderStatusChanged");
13
+ const onAssetTransactionStatusChanged_1 = require("./onAssetTransactionStatusChanged");
15
14
  const factory = require("../../factory");
16
15
  /**
17
16
  * 注文を決済する
@@ -23,52 +22,12 @@ function payOrder(params) {
23
22
  }
24
23
  const orderNumber = params.object.orderNumber;
25
24
  const confirmationNumber = params.object.confirmationNumber;
26
- const placeOrderTransaction = yield (0, findPlaceOrderTransaction_1.findPlaceOrderTransaction)({
25
+ yield (0, onAssetTransactionStatusChanged_1.paymentDue2Processing)({
27
26
  project: { id: params.project.id },
28
27
  confirmationNumber,
29
- orderNumber
30
- })({ transaction: repos.transaction });
31
- let order = yield repos.order.findByOrderNumber({
32
28
  orderNumber,
33
- project: { id: params.project.id },
34
- inclusion: [],
35
- exclusion: []
36
- });
37
- try {
38
- order = yield repos.order.changeStatus({
39
- project: { id: order.project.id },
40
- orderNumber,
41
- orderStatus: factory.orderStatus.OrderProcessing,
42
- previousOrderStatus: factory.orderStatus.OrderPaymentDue
43
- });
44
- }
45
- catch (error) {
46
- let throwsError = true;
47
- // すでにステータスが煤でいた場合、OrderPaymentDue->OrderProcessingの処理自体は成功しているので、後処理を続行する
48
- order = yield repos.order.findByOrderNumber({
49
- orderNumber: params.object.orderNumber,
50
- project: { id: params.project.id },
51
- inclusion: [],
52
- exclusion: []
53
- });
54
- if (order.orderStatus === factory.orderStatus.OrderDelivered
55
- || order.orderStatus === factory.orderStatus.OrderReturned) {
56
- throwsError = false;
57
- }
58
- if (throwsError) {
59
- throw error;
60
- }
61
- }
62
- if (params.useOnOrderStatusChanged) {
63
- yield (0, onOrderStatusChanged_1.onOrderStatusChanged)({
64
- order: Object.assign(Object.assign({}, order), { orderStatus: factory.orderStatus.OrderProcessing // 強制的にOrderProcessingとして処理する
65
- }),
66
- placeOrderTransaction
67
- })({
68
- registerActionInProgress: repos.registerActionInProgress,
69
- task: repos.task
70
- });
71
- }
29
+ useOnOrderStatusChanged: params.useOnOrderStatusChanged
30
+ })(repos);
72
31
  });
73
32
  }
74
33
  exports.payOrder = payOrder;
@@ -14,6 +14,7 @@ const moment = require("moment");
14
14
  const order_1 = require("../../factory/order");
15
15
  const createAccountingReportIfNotExist_1 = require("./createAccountingReportIfNotExist");
16
16
  const findPlaceOrderTransaction_1 = require("./findPlaceOrderTransaction");
17
+ const onAssetTransactionStatusChanged_1 = require("./onAssetTransactionStatusChanged");
17
18
  const onOrderStatusChanged_1 = require("./onOrderStatusChanged");
18
19
  const factory = require("../../factory");
19
20
  function createOrder(params) {
@@ -246,27 +247,13 @@ function placeOrder(params) {
246
247
  }
247
248
  // paymentMethods.length: 0の場合を考慮(2023-08-24~)
248
249
  if (order.paymentMethods.length === 0) {
249
- // paymentMethods.length: 0の場合に、confirmPayTransactionは実行されないので、ここで強制的にpayOrderを実行する必要がある
250
- // onOrderPaymentCompletedタスク作成
251
- const onPaymentCompletedTaskData = {
252
- project: { id: order.project.id, typeOf: factory.organizationType.Project },
253
- object: {
254
- confirmationNumber: order.confirmationNumber,
255
- orderNumber: order.orderNumber
256
- },
250
+ // paymentMethods.length: 0の場合に、confirmPayTransactionは実行されないので、ここで強制的にpaymentDue2Processingを実行する必要がある
251
+ yield (0, onAssetTransactionStatusChanged_1.paymentDue2Processing)({
252
+ project: { id: order.project.id },
253
+ confirmationNumber: order.confirmationNumber,
254
+ orderNumber: order.orderNumber,
257
255
  useOnOrderStatusChanged: params.useOnOrderStatusChanged === true
258
- };
259
- const onPaymentCompletedTaskAttributes = {
260
- project: { id: order.project.id, typeOf: factory.organizationType.Project },
261
- name: factory.taskName.OnOrderPaymentCompleted,
262
- status: factory.taskStatus.Ready,
263
- runsAt: new Date(),
264
- remainingNumberOfTries: 10,
265
- numberOfTried: 0,
266
- executionResults: [],
267
- data: onPaymentCompletedTaskData
268
- };
269
- yield repos.task.createOnOrderPaymentCompletedTaskIfNotExist(onPaymentCompletedTaskAttributes, { emitImmediately: true });
256
+ })(repos);
270
257
  }
271
258
  }
272
259
  // onOrderStatusChangedへ移行(2023-08-17~)
@@ -3,9 +3,10 @@
3
3
  */
4
4
  import { confirmPayTransaction } from './order/confirmPayTransaction';
5
5
  import { deleteOrder } from './order/deleteOrder';
6
+ import { onAssetTransactionStatusChanged, paymentDue2Processing } from './order/onAssetTransactionStatusChanged';
6
7
  import { onOrderStatusChanged } from './order/onOrderStatusChanged';
7
8
  import { onOrderUpdated } from './order/onOrderUpdated';
8
9
  import { payOrder } from './order/payOrder';
9
10
  import { placeOrder, placeOrderWithoutTransaction } from './order/placeOrder';
10
11
  import { sendOrder } from './order/sendOrder';
11
- export { confirmPayTransaction, deleteOrder, onOrderStatusChanged, onOrderUpdated, payOrder, placeOrder, placeOrderWithoutTransaction, sendOrder };
12
+ export { confirmPayTransaction, deleteOrder, onAssetTransactionStatusChanged, onOrderStatusChanged, onOrderUpdated, paymentDue2Processing, payOrder, placeOrder, placeOrderWithoutTransaction, sendOrder };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sendOrder = exports.placeOrderWithoutTransaction = exports.placeOrder = exports.payOrder = exports.onOrderUpdated = exports.onOrderStatusChanged = exports.deleteOrder = exports.confirmPayTransaction = void 0;
3
+ exports.sendOrder = exports.placeOrderWithoutTransaction = exports.placeOrder = exports.payOrder = exports.paymentDue2Processing = exports.onOrderUpdated = exports.onOrderStatusChanged = exports.onAssetTransactionStatusChanged = exports.deleteOrder = exports.confirmPayTransaction = void 0;
4
4
  /**
5
5
  * 注文サービス
6
6
  */
@@ -8,6 +8,9 @@ const confirmPayTransaction_1 = require("./order/confirmPayTransaction");
8
8
  Object.defineProperty(exports, "confirmPayTransaction", { enumerable: true, get: function () { return confirmPayTransaction_1.confirmPayTransaction; } });
9
9
  const deleteOrder_1 = require("./order/deleteOrder");
10
10
  Object.defineProperty(exports, "deleteOrder", { enumerable: true, get: function () { return deleteOrder_1.deleteOrder; } });
11
+ const onAssetTransactionStatusChanged_1 = require("./order/onAssetTransactionStatusChanged");
12
+ Object.defineProperty(exports, "onAssetTransactionStatusChanged", { enumerable: true, get: function () { return onAssetTransactionStatusChanged_1.onAssetTransactionStatusChanged; } });
13
+ Object.defineProperty(exports, "paymentDue2Processing", { enumerable: true, get: function () { return onAssetTransactionStatusChanged_1.paymentDue2Processing; } });
11
14
  const onOrderStatusChanged_1 = require("./order/onOrderStatusChanged");
12
15
  Object.defineProperty(exports, "onOrderStatusChanged", { enumerable: true, get: function () { return onOrderStatusChanged_1.onOrderStatusChanged; } });
13
16
  const onOrderUpdated_1 = require("./order/onOrderUpdated");
@@ -13,7 +13,6 @@ exports.call = void 0;
13
13
  const factory = require("../../factory");
14
14
  const accountingReport_1 = require("../../repo/accountingReport");
15
15
  const action_1 = require("../../repo/action");
16
- const registerServiceInProgress_1 = require("../../repo/action/registerServiceInProgress");
17
16
  const assetTransaction_1 = require("../../repo/assetTransaction");
18
17
  const event_1 = require("../../repo/event");
19
18
  const order_1 = require("../../repo/order");
@@ -41,8 +40,7 @@ function call(data) {
41
40
  project: new project_1.MongoRepository(settings.connection),
42
41
  seller: new seller_1.MongoRepository(settings.connection),
43
42
  task: new task_1.MongoRepository(settings.connection),
44
- transaction: new transaction_1.MongoRepository(settings.connection),
45
- registerServiceInProgress: new registerServiceInProgress_1.RedisRepository(settings.redisClient)
43
+ transaction: new transaction_1.MongoRepository(settings.connection)
46
44
  });
47
45
  });
48
46
  }
@@ -0,0 +1,6 @@
1
+ import { IOperation } from '../task';
2
+ import * as factory from '../../factory';
3
+ /**
4
+ * タスク実行関数
5
+ */
6
+ export declare function call(data: factory.task.IData<factory.taskName.OnAssetTransactionStatusChanged>): IOperation<void>;
@@ -0,0 +1,37 @@
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.call = void 0;
13
+ const factory = require("../../factory");
14
+ const registerServiceInProgress_1 = require("../../repo/action/registerServiceInProgress");
15
+ const assetTransaction_1 = require("../../repo/assetTransaction");
16
+ const order_1 = require("../../repo/order");
17
+ const task_1 = require("../../repo/task");
18
+ const transaction_1 = require("../../repo/transaction");
19
+ const onAssetTransactionStatusChanged_1 = require("../order/onAssetTransactionStatusChanged");
20
+ /**
21
+ * タスク実行関数
22
+ */
23
+ function call(data) {
24
+ return (settings) => __awaiter(this, void 0, void 0, function* () {
25
+ if (settings.redisClient === undefined) {
26
+ throw new factory.errors.Argument('settings', 'redisClient required');
27
+ }
28
+ yield (0, onAssetTransactionStatusChanged_1.onAssetTransactionStatusChanged)(data)({
29
+ assetTransaction: new assetTransaction_1.MongoRepository(settings.connection),
30
+ order: new order_1.MongoRepository(settings.connection),
31
+ registerActionInProgress: new registerServiceInProgress_1.RedisRepository(settings.redisClient),
32
+ task: new task_1.MongoRepository(settings.connection),
33
+ transaction: new transaction_1.MongoRepository(settings.connection)
34
+ });
35
+ });
36
+ }
37
+ exports.call = call;
@@ -73,15 +73,27 @@ function createPaymentMethods(params) {
73
73
  var _a, _b, _c;
74
74
  const result = a.result;
75
75
  const paymentMethodAmountCurrencyByAuthorizeAction = (_b = (_a = result.paymentMethodAsObject) === null || _a === void 0 ? void 0 : _a.amount) === null || _b === void 0 ? void 0 : _b.currency;
76
- const paymentMethodOfInvoice = (typeof paymentMethodAmountCurrencyByAuthorizeAction === 'string') ?
77
- { amount: { currency: paymentMethodAmountCurrencyByAuthorizeAction } }
78
- : undefined;
79
76
  // 決済方法区分は必ず存在するはず(2023-08-15~)
80
77
  const paymentMethodType = (_c = result.paymentMethodAsObject) === null || _c === void 0 ? void 0 : _c.typeOf;
81
78
  if (typeof paymentMethodType !== 'string') {
82
79
  throw new factory.errors.NotFound('authorizePaymentAction.result.paymentMethodAsObject.typeOf');
83
80
  }
84
- paymentMethods.push(Object.assign({ accountId: result.accountId, additionalProperty: (Array.isArray(result.additionalProperty)) ? result.additionalProperty : [], issuedThrough: result.issuedThrough, name: result.name, paymentMethodId: result.paymentMethodId, paymentStatus: result.paymentStatus, totalPaymentDue: result.totalPaymentDue, typeOf: paymentMethodType }, (paymentMethodOfInvoice !== undefined) ? { paymentMethod: paymentMethodOfInvoice } : undefined));
81
+ const paymentMethodOfInvoice = Object.assign({ identifier: paymentMethodType }, (typeof paymentMethodAmountCurrencyByAuthorizeAction === 'string') ?
82
+ { amount: { currency: paymentMethodAmountCurrencyByAuthorizeAction } }
83
+ : undefined);
84
+ paymentMethods.push({
85
+ accountId: result.accountId,
86
+ additionalProperty: (Array.isArray(result.additionalProperty)) ? result.additionalProperty : [],
87
+ issuedThrough: result.issuedThrough,
88
+ name: result.name,
89
+ paymentMethodId: result.paymentMethodId,
90
+ paymentStatus: result.paymentStatus,
91
+ totalPaymentDue: result.totalPaymentDue,
92
+ typeOf: paymentMethodType,
93
+ // CreditCardIFのカード通貨区分を追加(2023-08-15~)
94
+ // 決済方法区分を保証(2023-08-28~)
95
+ paymentMethod: paymentMethodOfInvoice
96
+ });
85
97
  });
86
98
  // 決済方法から注文金額の計算
87
99
  // price += authorizePaymentActions
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  }
10
10
  ],
11
11
  "dependencies": {
12
- "@chevre/factory": "4.327.0-alpha.3",
12
+ "@chevre/factory": "4.327.0-alpha.5",
13
13
  "@cinerino/sdk": "3.165.0",
14
14
  "@motionpicture/coa-service": "9.2.0",
15
15
  "@motionpicture/gmo-service": "5.2.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.13"
120
+ "version": "21.8.0-alpha.15"
121
121
  }
@@ -1,154 +0,0 @@
1
- // tslint:disable:no-console
2
- import * as moment from 'moment';
3
- import * as mongoose from 'mongoose';
4
-
5
- import { chevre } from '../../../lib/index';
6
-
7
- // const project = { id: String(process.env.PROJECT_ID) };
8
- const EXCLUDED_PROJECT_ID = process.env.EXCLUDED_PROJECT_ID;
9
-
10
- // tslint:disable-next-line:max-func-body-length
11
- async function main() {
12
- await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
13
-
14
- const eventRepo = new chevre.repository.Event(mongoose.connection);
15
- const placeRepo = new chevre.repository.Place(mongoose.connection);
16
-
17
- const cursor = eventRepo.getCursor(
18
- {
19
- // 'project.id': { $eq: project.id },
20
- 'project.id': { $ne: EXCLUDED_PROJECT_ID },
21
- typeOf: {
22
- $in: [
23
- // chevre.factory.eventType.ScreeningEvent,
24
- chevre.factory.eventType.ScreeningEventSeries
25
- ]
26
- },
27
- organizer: { $exists: true },
28
- startDate: {
29
- $gte: moment()
30
- // tslint:disable-next-line:no-magic-numbers
31
- .add(-3, 'months')
32
- .toDate()
33
- }
34
- },
35
- {
36
- _id: 1,
37
- project: 1,
38
- location: 1,
39
- superEvent: 1,
40
- startDate: 1,
41
- typeOf: 1,
42
- organizer: 1
43
- }
44
- );
45
- console.log('events found');
46
-
47
- let i = 0;
48
- let updateCount = 0;
49
- let invalidOrganizerCount = 0;
50
- await cursor.eachAsync(async (doc) => {
51
- i += 1;
52
- const event: Pick<
53
- chevre.factory.event.IEvent<chevre.factory.eventType.ScreeningEvent>,
54
- 'id' | 'project' | 'location' | 'startDate' | 'typeOf' | 'organizer' | 'superEvent'
55
- > | Pick<
56
- chevre.factory.event.IEvent<chevre.factory.eventType.ScreeningEventSeries>,
57
- 'id' | 'project' | 'location' | 'startDate' | 'typeOf' | 'organizer'
58
- > = doc.toObject();
59
-
60
- const organizerId = event.organizer?.id;
61
-
62
- let movieTheaterId: string;
63
- let movieTheaterBranchCode: string;
64
- if (event.typeOf === chevre.factory.eventType.ScreeningEventSeries) {
65
- movieTheaterId = event.location.id;
66
- movieTheaterBranchCode = event.location.branchCode;
67
- } else {
68
- movieTheaterId = event.superEvent.location.id;
69
- movieTheaterBranchCode = event.superEvent.location.branchCode;
70
- }
71
- const movieTheaters = <Pick<
72
- chevre.factory.place.movieTheater.IPlaceWithoutScreeningRoom,
73
- 'parentOrganization' | 'branchCode'
74
- >[]>
75
- await placeRepo.searchMovieTheaters(
76
- {
77
- limit: 1,
78
- page: 1,
79
- project: { id: { $eq: event.project.id } },
80
- id: { $eq: movieTheaterId }
81
- },
82
- ['parentOrganization', 'branchCode'],
83
- []
84
- );
85
- const movieTheater = movieTheaters.shift();
86
- const sellerId = movieTheater?.parentOrganization?.id;
87
- console.log(
88
- 'movieTheater found',
89
- event.project.id, event.id, event.startDate, 'sellerId:', sellerId,
90
- 'movieTheaterId:', movieTheaterId,
91
- 'movieTheaterBranchCode:', movieTheaterBranchCode,
92
- i
93
- );
94
-
95
- const alreadyMigrated = typeof organizerId === 'string';
96
-
97
- if (alreadyMigrated) {
98
- console.log('already exist...', event.project.id, event.id, event.startDate, organizerId, i);
99
- if (organizerId === sellerId) {
100
- console.log('organizerId is valid', event.project.id, event.id, event.startDate, organizerId, i);
101
- } else {
102
- invalidOrganizerCount += 1;
103
-
104
- // organizerを修正する
105
- if (typeof sellerId !== 'string') {
106
- throw new Error('movieTheater not found');
107
- }
108
- const fixedOrganizer: chevre.factory.event.screeningEventSeries.IOrganizer = {
109
- id: sellerId
110
- };
111
- console.log('updating event...', event.project.id, event.id, event.startDate, i);
112
- await eventRepo.updatePartiallyById({
113
- project: { id: event.project.id },
114
- id: event.id,
115
- attributes: <any>{
116
- typeOf: event.typeOf,
117
- organizer: fixedOrganizer
118
- }
119
- });
120
- updateCount += 1;
121
- console.log('updated.', event.project.id, event.id, event.startDate, i);
122
- }
123
- } else {
124
- throw new Error('organizer not found');
125
- // if (typeof sellerId !== 'string') {
126
- // throw new Error('movieTheater not found');
127
- // }
128
- // if (typeof sellerId === 'string') {
129
- // const newOrganizer: chevre.factory.event.screeningEventSeries.IOrganizer = {
130
- // id: sellerId
131
- // };
132
- // console.log('updating event...', event.project.id, event.id, event.startDate, i);
133
- // await eventRepo.updatePartiallyById({
134
- // project: { id: event.project.id },
135
- // id: event.id,
136
- // attributes: <any>{
137
- // typeOf: event.typeOf,
138
- // organizer: newOrganizer
139
- // }
140
- // });
141
- // updateCount += 1;
142
- // console.log('updated.', event.project.id, event.id, event.startDate, i);
143
- // }
144
- }
145
- });
146
-
147
- console.log(i, 'events checked');
148
- console.log(updateCount, 'events updated');
149
- console.log(invalidOrganizerCount, 'invalid');
150
- }
151
-
152
- main()
153
- .then()
154
- .catch(console.error);