@chevre/domain 21.2.0-alpha.19 → 21.2.0-alpha.20

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.
@@ -17,6 +17,9 @@ interface IStatus {
17
17
  export interface IAggregateTask {
18
18
  statuses: IStatus[];
19
19
  }
20
+ interface IOptionOnCreate {
21
+ emitImmediately: boolean;
22
+ }
20
23
  /**
21
24
  * タスクリポジトリ
22
25
  */
@@ -24,10 +27,10 @@ export declare class MongoRepository {
24
27
  readonly taskModel: typeof Model;
25
28
  constructor(connection: Connection);
26
29
  static CREATE_MONGO_CONDITIONS(params: factory.task.ISearchConditions): any[];
27
- saveMany(taskAttributes: factory.task.IAttributes<factory.taskName>[]): Promise<{
30
+ saveMany(taskAttributes: factory.task.IAttributes<factory.taskName>[], options?: IOptionOnCreate): Promise<{
28
31
  id: string;
29
32
  }[]>;
30
- createInformTaskIfNotExist(params: factory.task.IAttributes<factory.taskName.TriggerWebhook>): Promise<void>;
33
+ createInformTaskIfNotExist(params: factory.task.IAttributes<factory.taskName.TriggerWebhook>, options: IOptionOnCreate): Promise<void>;
31
34
  executeById(params: {
32
35
  id: string;
33
36
  }): Promise<factory.task.ITask<factory.taskName> | null>;
@@ -150,8 +150,9 @@ class MongoRepository {
150
150
  }
151
151
  return andConditions;
152
152
  }
153
- saveMany(taskAttributes) {
153
+ saveMany(taskAttributes, options) {
154
154
  return __awaiter(this, void 0, void 0, function* () {
155
+ const emitImmediately = (options === null || options === void 0 ? void 0 : options.emitImmediately) === true;
155
156
  if (taskAttributes.length > 0) {
156
157
  const result = yield this.taskModel.insertMany(taskAttributes, { ordered: false, rawResult: true });
157
158
  if (result.insertedCount !== taskAttributes.length) {
@@ -161,18 +162,14 @@ class MongoRepository {
161
162
  .map((objectId) => {
162
163
  return { id: objectId.toHexString() };
163
164
  });
164
- taskAttributes.forEach((savedTask) => {
165
- task_2.taskEventEmitter.emitTaskStatusChanged({
166
- name: savedTask.name,
167
- status: factory.taskStatus.Ready
165
+ if (emitImmediately) {
166
+ taskAttributes.forEach((savedTask) => {
167
+ task_2.taskEventEmitter.emitTaskStatusChanged({
168
+ name: savedTask.name,
169
+ status: factory.taskStatus.Ready
170
+ });
168
171
  });
169
- });
170
- // savedTasks.forEach((savedTask) => {
171
- // taskEventEmitter.emitTaskStatusChanged({
172
- // id: savedTask.id,
173
- // status: factory.taskStatus.Ready
174
- // });
175
- // });
172
+ }
176
173
  // return result.ops;
177
174
  return savedTasks;
178
175
  }
@@ -181,9 +178,9 @@ class MongoRepository {
181
178
  }
182
179
  });
183
180
  }
184
- createInformTaskIfNotExist(params) {
181
+ createInformTaskIfNotExist(params, options) {
185
182
  return __awaiter(this, void 0, void 0, function* () {
186
- yield this.taskModel.findOneAndUpdate({
183
+ const createdTask = yield this.taskModel.findOneAndUpdate({
187
184
  'project.id': { $eq: params.project.id },
188
185
  name: params.name,
189
186
  'data.object.id': {
@@ -191,7 +188,15 @@ class MongoRepository {
191
188
  $eq: String(params.data.object.id)
192
189
  }
193
190
  }, { $setOnInsert: params }, { new: true, upsert: true })
191
+ .select({ _id: 1 })
194
192
  .exec();
193
+ if (options.emitImmediately) {
194
+ task_2.taskEventEmitter.emitTaskStatusChanged({
195
+ id: createdTask.id,
196
+ name: params.name,
197
+ status: factory.taskStatus.Ready
198
+ });
199
+ }
195
200
  });
196
201
  }
197
202
  executeById(params) {
@@ -208,7 +213,6 @@ class MongoRepository {
208
213
  numberOfTried: 1 // トライ回数増やす
209
214
  }
210
215
  }, { new: true })
211
- // .sort(sortOrder4executionOfTasks)
212
216
  .exec();
213
217
  if (doc === null) {
214
218
  // tslint:disable-next-line:no-null-keyword
@@ -13,13 +13,11 @@ exports.exportTasksById = exports.startAndConfirm = exports.confirm = exports.st
13
13
  /**
14
14
  * 予約取消取引サービス
15
15
  */
16
- const createDebug = require("debug");
17
16
  const moment = require("moment");
18
17
  const mongoose = require("mongoose");
19
18
  const factory = require("../../factory");
20
19
  const settings_1 = require("../../settings");
21
20
  const factory_1 = require("./cancelReservation/factory");
22
- const debug = createDebug('chevre-domain:service');
23
21
  function validateStartParams(params) {
24
22
  return (repos) => __awaiter(this, void 0, void 0, function* () {
25
23
  var _a, _b;
@@ -235,9 +233,7 @@ function exportTasksById(params) {
235
233
  default:
236
234
  throw new factory.errors.NotImplemented(`Transaction status "${transaction.status}" not implemented.`);
237
235
  }
238
- debug('taskAttributes prepared', taskAttributes);
239
- return repos.task.saveMany(taskAttributes);
240
- // return Promise.all(taskAttributes.map(async (a) => repos.task.save(a)));
236
+ return repos.task.saveMany(taskAttributes, { emitImmediately: true });
241
237
  });
242
238
  }
243
239
  exports.exportTasksById = exportTasksById;
@@ -430,7 +430,7 @@ function exportTasksById(params) {
430
430
  default:
431
431
  throw new factory.errors.NotImplemented(`Transaction status "${transaction.status}" not implemented.`);
432
432
  }
433
- return repos.task.saveMany(taskAttributes);
433
+ return repos.task.saveMany(taskAttributes, { emitImmediately: true });
434
434
  });
435
435
  }
436
436
  exports.exportTasksById = exportTasksById;
@@ -470,7 +470,7 @@ function exportTasksById(params) {
470
470
  default:
471
471
  throw new factory.errors.NotImplemented(`Transaction status "${transaction.status}" not implemented.`);
472
472
  }
473
- return repos.task.saveMany(taskAttributes);
473
+ return repos.task.saveMany(taskAttributes, { emitImmediately: true });
474
474
  });
475
475
  }
476
476
  exports.exportTasksById = exportTasksById;
@@ -218,7 +218,7 @@ function exportTasksById(params) {
218
218
  default:
219
219
  throw new factory.errors.NotImplemented(`Transaction status "${transaction.status}" not implemented.`);
220
220
  }
221
- return repos.task.saveMany(taskAttributes);
221
+ return repos.task.saveMany(taskAttributes, { emitImmediately: true });
222
222
  });
223
223
  }
224
224
  exports.exportTasksById = exportTasksById;
@@ -301,8 +301,7 @@ function exportTasksById(params) {
301
301
  default:
302
302
  throw new factory.errors.NotImplemented(`Transaction status "${transaction.status}" not implemented.`);
303
303
  }
304
- return repos.task.saveMany(taskAttributes);
305
- // return Promise.all(taskAttributes.map(async (a) => repos.task.save(a)));
304
+ return repos.task.saveMany(taskAttributes, { emitImmediately: true });
306
305
  });
307
306
  }
308
307
  exports.exportTasksById = exportTasksById;
@@ -860,7 +860,7 @@ function exportTasksById(params) {
860
860
  default:
861
861
  throw new factory.errors.NotImplemented(`Transaction status "${transaction.status}" not implemented.`);
862
862
  }
863
- return repos.task.saveMany(taskAttributes);
863
+ return repos.task.saveMany(taskAttributes, { emitImmediately: true });
864
864
  });
865
865
  }
866
866
  exports.exportTasksById = exportTasksById;
@@ -89,7 +89,7 @@ function onOrderStatusChanged(params) {
89
89
  break;
90
90
  default:
91
91
  }
92
- yield repos.task.saveMany(tasks);
92
+ yield repos.task.saveMany(tasks, { emitImmediately: true });
93
93
  });
94
94
  }
95
95
  exports.onOrderStatusChanged = onOrderStatusChanged;
@@ -269,6 +269,6 @@ function onPlaceOrder(params) {
269
269
  }
270
270
  }
271
271
  // タスク保管
272
- yield repos.task.saveMany(taskAttributes);
272
+ yield repos.task.saveMany(taskAttributes, { emitImmediately: true });
273
273
  });
274
274
  }
@@ -204,10 +204,6 @@ function onReturn(returnActionAttributes) {
204
204
  }
205
205
  }
206
206
  // タスク保管
207
- // saveManyに変更(2023-02-01~)
208
- yield repos.task.saveMany(taskAttributes);
209
- // await Promise.all(taskAttributes.map(async (taskAttribute) => {
210
- // return repos.task.save(taskAttribute);
211
- // }));
207
+ yield repos.task.saveMany(taskAttributes, { emitImmediately: true });
212
208
  });
213
209
  }
@@ -178,6 +178,6 @@ function onSend(params) {
178
178
  }
179
179
  }
180
180
  // タスク保管
181
- yield repos.task.saveMany(taskAttributes);
181
+ yield repos.task.saveMany(taskAttributes, { emitImmediately: true });
182
182
  });
183
183
  }
@@ -576,9 +576,7 @@ function exportTasksById(params) {
576
576
  transaction,
577
577
  runsAt: taskRunsAt
578
578
  });
579
- // saveManyに変更(2023-02-01~)
580
- yield repos.task.saveMany(taskAttributes);
581
- // await Promise.all(taskAttributes.map(async (a) => repos.task.save(a)));
579
+ yield repos.task.saveMany(taskAttributes, { emitImmediately: true });
582
580
  });
583
581
  }
584
582
  exports.exportTasksById = exportTasksById;
@@ -36,11 +36,7 @@ function exportTasksById(params) {
36
36
  transaction,
37
37
  runsAt: taskRunsAt
38
38
  });
39
- // saveManyに変更(2023-02-01~)
40
- yield repos.task.saveMany(taskAttributes);
41
- // await Promise.all(taskAttributes.map(async (taskAttribute) => {
42
- // await repos.task.save(taskAttribute);
43
- // }));
39
+ yield repos.task.saveMany(taskAttributes, { emitImmediately: true });
44
40
  });
45
41
  }
46
42
  exports.exportTasksById = exportTasksById;
@@ -384,11 +384,7 @@ function exportTasksById(params) {
384
384
  transaction,
385
385
  runsAt: taskRunsAt
386
386
  });
387
- // saveManyに変更(2023-02-01~)
388
- yield repos.task.saveMany(taskAttributes);
389
- // await Promise.all(taskAttributes.map(async (taskAttribute) => {
390
- // await repos.task.save(taskAttribute);
391
- // }));
387
+ yield repos.task.saveMany(taskAttributes, { emitImmediately: true });
392
388
  });
393
389
  }
394
390
  exports.exportTasksById = exportTasksById;
package/package.json CHANGED
@@ -117,5 +117,5 @@
117
117
  "postversion": "git push origin --tags",
118
118
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
119
119
  },
120
- "version": "21.2.0-alpha.19"
120
+ "version": "21.2.0-alpha.20"
121
121
  }