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

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,98 @@
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 ONE_YEAR_IN_DAYS = 365;
8
+ type IDeletingTransaction = Pick<
9
+ chevre.factory.transaction.placeOrder.ITransaction,
10
+ 'id' | 'project' | 'typeOf' | 'startDate' | 'endDate' | 'object'
11
+ >;
12
+
13
+ async function main() {
14
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
15
+
16
+ const now = new Date();
17
+ const endDateLt: Date = moment(now)
18
+ // tslint:disable-next-line:no-magic-numbers
19
+ .add(-ONE_YEAR_IN_DAYS, 'days')
20
+ .toDate();
21
+
22
+ const taskRepo = new chevre.repository.Task(mongoose.connection);
23
+ const transactionRepo = new chevre.repository.Transaction(mongoose.connection);
24
+
25
+ const deletingTransactions = <IDeletingTransaction[]>await transactionRepo.search<chevre.factory.transactionType.PlaceOrder>(
26
+ {
27
+ limit: 100,
28
+ page: 1,
29
+ sort: { startDate: chevre.factory.sortType.Ascending },
30
+ typeOf: chevre.factory.transactionType.PlaceOrder,
31
+ statuses: [
32
+ chevre.factory.transactionStatusType.Canceled,
33
+ chevre.factory.transactionStatusType.Confirmed,
34
+ chevre.factory.transactionStatusType.Expired
35
+ ],
36
+ endThrough: endDateLt,
37
+ inclusion: ['_id', 'project', 'typeOf', 'startDate', 'endDate', 'object'],
38
+ exclusion: []
39
+ }
40
+ );
41
+
42
+ let i = 0;
43
+ let updateCount = 0;
44
+ for (const deletingTransaction of deletingTransactions) {
45
+ i += 1;
46
+ const transaction: IDeletingTransaction = deletingTransaction;
47
+ console.log('checking...', transaction.project.id, transaction.id, transaction.startDate, transaction.endDate, i);
48
+
49
+ const isEndDateBefore = transaction.endDate !== undefined && moment(transaction.endDate)
50
+ .isBefore(endDateLt);
51
+ if (isEndDateBefore) {
52
+ const runsAt: Date = moment(transaction.endDate)
53
+ .add(ONE_YEAR_IN_DAYS, 'days')
54
+ .toDate();
55
+
56
+ updateCount += 1;
57
+ const deleteTransactionTask: chevre.factory.task.deleteTransaction.IAttributes = {
58
+ project: transaction.project,
59
+ name: chevre.factory.taskName.DeleteTransaction,
60
+ status: chevre.factory.taskStatus.Ready,
61
+ runsAt,
62
+ remainingNumberOfTries: 3,
63
+ numberOfTried: 0,
64
+ executionResults: [],
65
+ data: {
66
+ object: {
67
+ specifyingMethod: chevre.factory.task.deleteTransaction.SpecifyingMethod.Id,
68
+ endDate: transaction.endDate,
69
+ id: transaction.id,
70
+ object: {
71
+ ...(typeof transaction.object.confirmationNumber === 'string')
72
+ ? { confirmationNumber: transaction.object.confirmationNumber }
73
+ : undefined,
74
+ ...(typeof transaction.object.orderNumber === 'string')
75
+ ? { orderNumber: transaction.object.orderNumber }
76
+ : undefined
77
+ },
78
+ project: transaction.project,
79
+ startDate: transaction.startDate,
80
+ typeOf: transaction.typeOf
81
+ }
82
+ }
83
+ };
84
+ console.log(
85
+ 'saving task...',
86
+ deleteTransactionTask.runsAt, transaction.project.id, transaction.id, transaction.startDate, transaction.endDate, i);
87
+ await taskRepo.createDeleteTransactionTaskIfNotExist(deleteTransactionTask, { emitImmediately: false });
88
+ console.log('task saved', transaction.project.id, transaction.id, transaction.startDate, transaction.endDate, i);
89
+ }
90
+ }
91
+
92
+ console.log(i, 'transactions checked');
93
+ console.log(updateCount, 'transactions updated');
94
+ }
95
+
96
+ main()
97
+ .then()
98
+ .catch(console.error);
@@ -31,6 +31,10 @@ export declare class MongoRepository {
31
31
  id: string;
32
32
  }[]>;
33
33
  createInformTaskIfNotExist(params: factory.task.IAttributes<factory.taskName.TriggerWebhook>, options: IOptionOnCreate): Promise<void>;
34
+ /**
35
+ * 取引削除タスク冪等作成
36
+ */
37
+ createDeleteTransactionTaskIfNotExist(params: factory.task.IAttributes<factory.taskName.DeleteTransaction>, options: IOptionOnCreate): Promise<void>;
34
38
  executeById(params: {
35
39
  id: string;
36
40
  executor: {
@@ -206,6 +206,30 @@ class MongoRepository {
206
206
  }
207
207
  });
208
208
  }
209
+ /**
210
+ * 取引削除タスク冪等作成
211
+ */
212
+ createDeleteTransactionTaskIfNotExist(params, options) {
213
+ return __awaiter(this, void 0, void 0, function* () {
214
+ if (params.data.object.specifyingMethod !== factory.task.deleteTransaction.SpecifyingMethod.Id) {
215
+ throw new factory.errors.NotImplemented(`only ${factory.task.deleteTransaction.SpecifyingMethod.Id} implemented`);
216
+ }
217
+ const createdTask = yield this.taskModel.findOneAndUpdate({
218
+ 'project.id': { $eq: params.project.id },
219
+ name: { $eq: params.name },
220
+ 'data.object.id': { $exists: true, $eq: params.data.object.id }
221
+ }, { $setOnInsert: params }, { new: true, upsert: true })
222
+ .select({ _id: 1 })
223
+ .exec();
224
+ if (options.emitImmediately) {
225
+ task_2.taskEventEmitter.emitTaskStatusChanged({
226
+ id: createdTask.id,
227
+ name: params.name,
228
+ status: factory.taskStatus.Ready
229
+ });
230
+ }
231
+ });
232
+ }
209
233
  executeById(params) {
210
234
  return __awaiter(this, void 0, void 0, function* () {
211
235
  const doc = yield this.taskModel.findOneAndUpdate({
@@ -338,6 +338,14 @@ function createOnPlaceOrderTasksByTransaction(params) {
338
338
  // tslint:disable-next-line:no-single-line-block-comment
339
339
  /* istanbul ignore else */
340
340
  if (potentialActions.sendOrder !== undefined) {
341
+ const sendOrderTaskData = {
342
+ project: potentialActions.sendOrder.project,
343
+ object: Object.assign(Object.assign({}, potentialActions.sendOrder.object), { confirmationNumber: params.object.confirmationNumber })
344
+ // 廃止(2023-08-21~)
345
+ // ...(potentialActions.sendOrder.potentialActions !== undefined)
346
+ // ? { potentialActions: potentialActions.sendOrder.potentialActions }
347
+ // : undefined
348
+ };
341
349
  const sendOrderTask = {
342
350
  project: potentialActions.sendOrder.project,
343
351
  name: factory.taskName.SendOrder,
@@ -346,9 +354,7 @@ function createOnPlaceOrderTasksByTransaction(params) {
346
354
  remainingNumberOfTries: 10,
347
355
  numberOfTried: 0,
348
356
  executionResults: [],
349
- data: Object.assign({ project: potentialActions.sendOrder.project, object: Object.assign(Object.assign({}, potentialActions.sendOrder.object), { confirmationNumber: params.object.confirmationNumber }) }, (potentialActions.sendOrder.potentialActions !== undefined)
350
- ? { potentialActions: potentialActions.sendOrder.potentialActions }
351
- : undefined)
357
+ data: sendOrderTaskData
352
358
  };
353
359
  taskAttributes.push(sendOrderTask);
354
360
  }
@@ -130,6 +130,17 @@ function createTasks(params) {
130
130
  throw new factory.errors.NotFound('Transaction Result');
131
131
  }
132
132
  const orderActionAttributes = potentialActions.order;
133
+ const placeOrderTaskData = {
134
+ project: orderActionAttributes.project,
135
+ object: {
136
+ confirmationNumber: orderFromTransaction.confirmationNumber,
137
+ orderNumber: orderActionAttributes.object.orderNumber
138
+ }
139
+ // 廃止(2023-08-21~)
140
+ // ...(orderActionAttributes.potentialActions !== undefined)
141
+ // ? { potentialActions: orderActionAttributes.potentialActions }
142
+ // : undefined
143
+ };
133
144
  const placeOrderTaskAttributes = {
134
145
  project: transaction.project,
135
146
  name: factory.taskName.PlaceOrder,
@@ -138,12 +149,7 @@ function createTasks(params) {
138
149
  remainingNumberOfTries: 10,
139
150
  numberOfTried: 0,
140
151
  executionResults: [],
141
- data: Object.assign({ project: orderActionAttributes.project, object: {
142
- confirmationNumber: orderFromTransaction.confirmationNumber,
143
- orderNumber: orderActionAttributes.object.orderNumber
144
- } }, (orderActionAttributes.potentialActions !== undefined)
145
- ? { potentialActions: orderActionAttributes.potentialActions }
146
- : undefined)
152
+ data: placeOrderTaskData
147
153
  };
148
154
  taskAttributes.push(placeOrderTaskAttributes);
149
155
  break;
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  }
10
10
  ],
11
11
  "dependencies": {
12
- "@chevre/factory": "4.326.0-alpha.0",
12
+ "@chevre/factory": "4.326.0-alpha.1",
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.7.0-alpha.14"
120
+ "version": "21.7.0-alpha.16"
121
121
  }