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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -57,6 +57,7 @@ declare const schema: Schema<any, import("mongoose").Model<any, any, any, any, a
57
57
  status?: string | undefined;
58
58
  data?: any;
59
59
  project?: any;
60
+ identifier?: string | undefined;
60
61
  runsAt?: Date | undefined;
61
62
  remainingNumberOfTries?: number | undefined;
62
63
  lastTriedAt?: Date | undefined;
@@ -69,6 +70,7 @@ declare const schema: Schema<any, import("mongoose").Model<any, any, any, any, a
69
70
  status?: string | undefined;
70
71
  data?: any;
71
72
  project?: any;
73
+ identifier?: string | undefined;
72
74
  runsAt?: Date | undefined;
73
75
  remainingNumberOfTries?: number | undefined;
74
76
  lastTriedAt?: Date | undefined;
@@ -81,6 +83,7 @@ declare const schema: Schema<any, import("mongoose").Model<any, any, any, any, a
81
83
  status?: string | undefined;
82
84
  data?: any;
83
85
  project?: any;
86
+ identifier?: string | undefined;
84
87
  runsAt?: Date | undefined;
85
88
  remainingNumberOfTries?: number | undefined;
86
89
  lastTriedAt?: Date | undefined;
@@ -9,6 +9,7 @@ exports.modelName = modelName;
9
9
  * タスクスキーマ
10
10
  */
11
11
  const schema = new mongoose_1.Schema({
12
+ identifier: String,
12
13
  project: mongoose_1.SchemaTypes.Mixed,
13
14
  name: String,
14
15
  status: String,
@@ -52,6 +53,13 @@ schema.index({ 'project.id': 1, runsAt: -1 }, { name: 'searchByProjectId-v202207
52
53
  schema.index({ name: 1, runsAt: -1 }, { name: 'searchByName-v2' });
53
54
  schema.index({ status: 1, runsAt: -1 }, { name: 'searchByStatus-v2' });
54
55
  schema.index({ runsAt: -1 }, { name: 'searchByRunsAt-v2' });
56
+ // identifier追加(2023-09-01~)
57
+ schema.index({ identifier: 1, runsAt: -1 }, {
58
+ name: 'searchByIdentifier',
59
+ partialFilterExpression: {
60
+ identifier: { $exists: true }
61
+ }
62
+ });
55
63
  schema.index({ dateAborted: 1, runsAt: -1 }, {
56
64
  name: 'searchByDateAborted',
57
65
  partialFilterExpression: {
@@ -30,6 +30,10 @@ export declare class MongoRepository {
30
30
  saveMany(taskAttributes: factory.task.IAttributes<factory.taskName>[], options: IOptionOnCreate): Promise<{
31
31
  id: string;
32
32
  }[]>;
33
+ /**
34
+ * タスク識別子から冪等作成する
35
+ */
36
+ createIfNotExistByIdentifier(params: factory.task.IAttributes<factory.taskName>, options: IOptionOnCreate): Promise<void>;
33
37
  createInformTaskIfNotExist(params: factory.task.IAttributes<factory.taskName.TriggerWebhook>, options: IOptionOnCreate): Promise<void>;
34
38
  /**
35
39
  * 取引削除タスク冪等作成
@@ -174,6 +174,30 @@ class MongoRepository {
174
174
  }
175
175
  });
176
176
  }
177
+ /**
178
+ * タスク識別子から冪等作成する
179
+ */
180
+ createIfNotExistByIdentifier(params, options) {
181
+ return __awaiter(this, void 0, void 0, function* () {
182
+ if (typeof params.identifier !== 'string' || params.identifier.length === 0) {
183
+ throw new factory.errors.ArgumentNull('identifier');
184
+ }
185
+ const createdTask = yield this.taskModel.findOneAndUpdate({
186
+ 'project.id': { $eq: params.project.id },
187
+ name: { $eq: params.name },
188
+ identifier: { $exists: true, $eq: params.identifier }
189
+ }, { $setOnInsert: params }, { new: true, upsert: true })
190
+ .select({ _id: 1 })
191
+ .exec();
192
+ if (options.emitImmediately) {
193
+ task_2.taskEventEmitter.emitTaskStatusChanged({
194
+ id: createdTask.id,
195
+ name: params.name,
196
+ status: factory.taskStatus.Ready
197
+ });
198
+ }
199
+ });
200
+ }
177
201
  createInformTaskIfNotExist(params, options) {
178
202
  return __awaiter(this, void 0, void 0, function* () {
179
203
  const createdTask = yield this.taskModel.findOneAndUpdate({
@@ -21,10 +21,6 @@ export declare function createConfirmRegisterServiceActionObjectByOrder(params:
21
21
  order: factory.order.IOrder;
22
22
  }): factory.action.interact.confirm.registerService.IObject[];
23
23
  export type IExternalOrder = Pick<factory.order.IOrder, 'project' | 'typeOf' | 'seller' | 'customer' | 'confirmationNumber' | 'orderNumber' | 'price' | 'priceCurrency' | 'orderDate' | 'name' | 'orderStatus' | 'orderedItem' | 'paymentMethods'>;
24
- export declare function createOnPlaceOrderTasksByTransaction(params: {
25
- object: factory.order.IOrder | IExternalOrder;
26
- potentialActions?: factory.action.trade.order.IPotentialActions;
27
- }): factory.task.IAttributes<factory.taskName>[];
28
24
  /**
29
25
  * 注文配送後のアクション
30
26
  */
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  var _a;
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.createOnOrderCancelledTasksByTransaction = exports.createOnOrderReturnedTasksByTransaction = exports.createOnOrderSentTasksByTransaction = exports.createOnPlaceOrderTasksByTransaction = exports.createConfirmRegisterServiceActionObjectByOrder = exports.createConfirmReservationActionObject4COAByOrder = exports.createConfirmReservationActionObject4ChevreByOrder = exports.createInformTasks = exports.getOrderWithToken = void 0;
13
+ exports.createOnOrderCancelledTasksByTransaction = exports.createOnOrderReturnedTasksByTransaction = exports.createOnOrderSentTasksByTransaction = exports.createConfirmRegisterServiceActionObjectByOrder = exports.createConfirmReservationActionObject4COAByOrder = exports.createConfirmReservationActionObject4ChevreByOrder = exports.createInformTasks = exports.getOrderWithToken = void 0;
14
14
  const google_libphonenumber_1 = require("google-libphonenumber");
15
15
  const jwt = require("jsonwebtoken");
16
16
  const util_1 = require("util");
@@ -262,62 +262,38 @@ function createConfirmRegisterServiceActionObjectByOrder(params) {
262
262
  });
263
263
  }
264
264
  exports.createConfirmRegisterServiceActionObjectByOrder = createConfirmRegisterServiceActionObjectByOrder;
265
- function createOnPlaceOrderTasksByTransaction(params) {
266
- const potentialActions = params.potentialActions;
267
- const now = new Date();
268
- // potentialActionsのためのタスクを生成
269
- const taskAttributes = [];
270
- // tslint:disable-next-line:no-single-line-block-comment
271
- /* istanbul ignore else */
272
- if (potentialActions !== undefined) {
273
- // 冗長なsendOrderタスク作成を回避(createSendOrderTransactionTaskIfNotExistへ移行)(2023-08-25~)
274
- // tslint:disable-next-line:no-single-line-block-comment
275
- /* istanbul ignore else */
276
- // if (potentialActions.sendOrder !== undefined) {
277
- // const sendOrderTaskData: factory.task.IData<factory.taskName.SendOrder> = {
278
- // project: potentialActions.sendOrder.project,
279
- // object: {
280
- // ...potentialActions.sendOrder.object,
281
- // confirmationNumber: params.object.confirmationNumber
282
- // }
283
- // // 廃止(2023-08-21~)
284
- // // ...(potentialActions.sendOrder.potentialActions !== undefined)
285
- // // ? { potentialActions: potentialActions.sendOrder.potentialActions }
286
- // // : undefined
287
- // };
288
- // const sendOrderTask: factory.task.IAttributes<factory.taskName.SendOrder> = {
289
- // project: potentialActions.sendOrder.project,
290
- // name: factory.taskName.SendOrder,
291
- // status: factory.taskStatus.Ready,
292
- // runsAt: now, // なるはやで実行
293
- // remainingNumberOfTries: 10,
294
- // numberOfTried: 0,
295
- // executionResults: [],
296
- // data: sendOrderTaskData
297
- // };
298
- // taskAttributes.push(sendOrderTask);
299
- // }
300
- // ポイント付与
301
- // tslint:disable-next-line:no-single-line-block-comment
302
- /* istanbul ignore else */
303
- if (Array.isArray(potentialActions.givePointAward)) {
304
- taskAttributes.push(...potentialActions.givePointAward.map((a) => {
305
- return {
306
- project: a.project,
307
- name: factory.taskName.GivePointAward,
308
- status: factory.taskStatus.Ready,
309
- runsAt: now,
310
- remainingNumberOfTries: 10,
311
- numberOfTried: 0,
312
- executionResults: [],
313
- data: a
314
- };
315
- }));
316
- }
317
- }
318
- return taskAttributes;
319
- }
320
- exports.createOnPlaceOrderTasksByTransaction = createOnPlaceOrderTasksByTransaction;
265
+ // export function createOnPlaceOrderTasksByTransaction(params: {
266
+ // object: factory.order.IOrder | IExternalOrder;
267
+ // potentialActions?: factory.action.trade.order.IPotentialActions;
268
+ // }): factory.task.IAttributes<factory.taskName>[] {
269
+ // const potentialActions = params.potentialActions;
270
+ // const now = new Date();
271
+ // // potentialActionsのためのタスクを生成
272
+ // const taskAttributes: factory.task.IAttributes<factory.taskName>[] = [];
273
+ // // tslint:disable-next-line:no-single-line-block-comment
274
+ // /* istanbul ignore else */
275
+ // if (potentialActions !== undefined) {
276
+ // // ポイント付与
277
+ // // tslint:disable-next-line:no-single-line-block-comment
278
+ // /* istanbul ignore else */
279
+ // if (Array.isArray(potentialActions.givePointAward)) {
280
+ // taskAttributes.push(...potentialActions.givePointAward.map(
281
+ // (a): factory.task.IAttributes<factory.taskName.GivePointAward> => {
282
+ // return {
283
+ // project: a.project,
284
+ // name: factory.taskName.GivePointAward,
285
+ // status: factory.taskStatus.Ready,
286
+ // runsAt: now, // なるはやで実行
287
+ // remainingNumberOfTries: 10,
288
+ // numberOfTried: 0,
289
+ // executionResults: [],
290
+ // data: a
291
+ // };
292
+ // }));
293
+ // }
294
+ // }
295
+ // return taskAttributes;
296
+ // }
321
297
  /**
322
298
  * 注文配送後のアクション
323
299
  */
@@ -94,19 +94,19 @@ function onOrderStatusChanged(params) {
94
94
  // ...await createConfirmPayTransactionTasks(params.order, simpleOrder)(repos),
95
95
  // createConfirmReserveTransactionTasksIfNotExistへ移行(2023-08-25~)
96
96
  // ...await createConfirmReserveTransactionTasks(params.order, simpleOrder)(repos),
97
- ...yield createConfirmRegisterServiceTransactionTasks(params.order, simpleOrder)(repos),
97
+ ...yield createConfirmRegisterServiceTransactionTasks(params.order, simpleOrder)(repos)
98
98
  // 取引のpotentialActionsを適用(2023-08-17~)
99
- ...(0, factory_1.createOnPlaceOrderTasksByTransaction)({
100
- object: params.order,
101
- // potentialActions: params.potentialActions
102
- potentialActions: (_h = (_g = (_f = params.placeOrderTransaction) === null || _f === void 0 ? void 0 : _f.potentialActions) === null || _g === void 0 ? void 0 : _g.order) === null || _h === void 0 ? void 0 : _h.potentialActions
103
- })
99
+ // createGivePointAwardTaskIfNotExistへ移行(2023-09-01~)
100
+ // ...createOnPlaceOrderTasksByTransaction({
101
+ // object: params.order,
102
+ // potentialActions: params.placeOrderTransaction?.potentialActions?.order?.potentialActions
103
+ // })
104
104
  ];
105
105
  break;
106
106
  case factory.orderStatus.OrderReturned:
107
- const potentialActionsByTransaction = (_m = (_l = (_k = (_j = params.returnOrderTransaction) === null || _j === void 0 ? void 0 : _j.potentialActions) === null || _k === void 0 ? void 0 : _k.returnOrder) === null || _l === void 0 ? void 0 : _l.find((returnOrderActionByTransaction) => {
107
+ const potentialActionsByTransaction = (_j = (_h = (_g = (_f = params.returnOrderTransaction) === null || _f === void 0 ? void 0 : _f.potentialActions) === null || _g === void 0 ? void 0 : _g.returnOrder) === null || _h === void 0 ? void 0 : _h.find((returnOrderActionByTransaction) => {
108
108
  return returnOrderActionByTransaction.object.orderNumber === params.order.orderNumber;
109
- })) === null || _m === void 0 ? void 0 : _m.potentialActions;
109
+ })) === null || _j === void 0 ? void 0 : _j.potentialActions;
110
110
  tasks = [
111
111
  ...(0, factory_1.createInformTasks)(params.order),
112
112
  ...createReturnReserveTransactionTasks(params.order, simpleOrder),
@@ -133,6 +133,9 @@ function onOrderStatusChanged(params) {
133
133
  // 冗長なsendOrderタスク作成を回避(2023-08-25~)
134
134
  yield createSendOrderTransactionTaskIfNotExist({
135
135
  object: params.order,
136
+ potentialActions: (_m = (_l = (_k = params.placeOrderTransaction) === null || _k === void 0 ? void 0 : _k.potentialActions) === null || _l === void 0 ? void 0 : _l.order) === null || _m === void 0 ? void 0 : _m.potentialActions
137
+ })(repos);
138
+ yield createGivePointAwardTaskIfNotExist({
136
139
  potentialActions: (_q = (_p = (_o = params.placeOrderTransaction) === null || _o === void 0 ? void 0 : _o.potentialActions) === null || _p === void 0 ? void 0 : _p.order) === null || _q === void 0 ? void 0 : _q.potentialActions
137
140
  })(repos);
138
141
  break;
@@ -309,6 +312,35 @@ function createSendOrderTransactionTaskIfNotExist(params) {
309
312
  }
310
313
  });
311
314
  }
315
+ function createGivePointAwardTaskIfNotExist(params) {
316
+ return (repos) => __awaiter(this, void 0, void 0, function* () {
317
+ var _a;
318
+ const now = new Date();
319
+ const givePointAwardsByTransaction = (_a = params.potentialActions) === null || _a === void 0 ? void 0 : _a.givePointAward;
320
+ if (Array.isArray(givePointAwardsByTransaction)) {
321
+ for (const givePointAwardByTransaction of givePointAwardsByTransaction) {
322
+ let taskIdentifier = `${givePointAwardByTransaction.project.id}:${factory.taskName.GivePointAward}:${Date.now()}`;
323
+ if (typeof givePointAwardByTransaction.object.identifier === 'string'
324
+ && givePointAwardByTransaction.object.identifier.length > 0) {
325
+ taskIdentifier = `${givePointAwardByTransaction.project.id}:${factory.taskName.GivePointAward}:${givePointAwardByTransaction.object.identifier}`;
326
+ }
327
+ const givePointAwardTask = {
328
+ identifier: taskIdentifier,
329
+ project: givePointAwardByTransaction.project,
330
+ name: factory.taskName.GivePointAward,
331
+ status: factory.taskStatus.Ready,
332
+ runsAt: now,
333
+ remainingNumberOfTries: 10,
334
+ numberOfTried: 0,
335
+ executionResults: [],
336
+ data: givePointAwardByTransaction
337
+ };
338
+ // 冗長なgivePointAwardタスク作成を回避(2023-09-01~)
339
+ yield repos.task.createIfNotExistByIdentifier(givePointAwardTask, { emitImmediately: true });
340
+ }
341
+ }
342
+ });
343
+ }
312
344
  // const RETURN_COA_TASK_DELAY_IN_SECONDS = 0;
313
345
  function createReturnReserveTransactionTasks(order, simpleOrder) {
314
346
  var _a, _b;
package/package.json CHANGED
@@ -9,8 +9,8 @@
9
9
  }
10
10
  ],
11
11
  "dependencies": {
12
- "@chevre/factory": "4.329.0-alpha.1",
13
- "@cinerino/sdk": "3.166.0-alpha.4",
12
+ "@chevre/factory": "4.329.0-alpha.2",
13
+ "@cinerino/sdk": "3.166.0-alpha.5",
14
14
  "@motionpicture/coa-service": "9.2.0",
15
15
  "@motionpicture/gmo-service": "5.2.0",
16
16
  "@sendgrid/mail": "6.4.0",
@@ -117,5 +117,5 @@
117
117
  "postversion": "git push origin --tags",
118
118
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
119
119
  },
120
- "version": "21.8.0-alpha.23"
120
+ "version": "21.8.0-alpha.24"
121
121
  }