@chevre/domain 21.8.0-alpha.2 → 21.8.0-alpha.4

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,22 @@
1
+ // tslint:disable:no-console
2
+ import * as mongoose from 'mongoose';
3
+
4
+ const KILO_BYTES = 1024;
5
+ async function main() {
6
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
7
+
8
+ const stats = await mongoose.connection.db.collection('tasks')
9
+ .stats({
10
+ scale: KILO_BYTES * KILO_BYTES
11
+ });
12
+ console.log('scaleFactor:', stats.scaleFactor);
13
+ console.log('avgObjSize:', stats.avgObjSize);
14
+ console.log('count:', stats.count);
15
+ console.log('size:', stats.size);
16
+ }
17
+
18
+ main()
19
+ .then(() => {
20
+ console.log('success!');
21
+ })
22
+ .catch(console.error);
@@ -0,0 +1,31 @@
1
+ // tslint:disable:no-console
2
+ import * as mongoose from 'mongoose';
3
+
4
+ import { chevre } from '../../../lib/index';
5
+
6
+ const project = { id: String(process.env.PROJECT_ID) };
7
+
8
+ async function main() {
9
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: true });
10
+
11
+ const taskRepo = new chevre.repository.Task(mongoose.connection);
12
+
13
+ const tasks = await taskRepo.search(
14
+ {
15
+ limit: 1,
16
+ project: { id: { $eq: project.id } },
17
+ name: { $in: [chevre.factory.taskName.SendOrder] },
18
+ data: {
19
+ object: {
20
+ orderNumber: { $eq: 'xxx' }
21
+ }
22
+ }
23
+ }
24
+ );
25
+ console.log('tasks found', tasks);
26
+ console.log(tasks.length, 'tasks found');
27
+ }
28
+
29
+ main()
30
+ .then()
31
+ .catch(console.error);
@@ -83,6 +83,12 @@ schema.index({ 'data.object.itemOffered.membershipFor.id': 1, runsAt: -1 }, {
83
83
  'data.object.itemOffered.membershipFor.id': { $exists: true }
84
84
  }
85
85
  });
86
+ schema.index({ 'data.object.orderNumber': 1, runsAt: -1 }, {
87
+ name: 'searchByDataObjectOrderNumber',
88
+ partialFilterExpression: {
89
+ 'data.object.orderNumber': { $exists: true }
90
+ }
91
+ });
86
92
  schema.index({ 'data.object.transactionNumber': 1, runsAt: -1 }, {
87
93
  name: 'searchByDataObjectTransactionNumber',
88
94
  partialFilterExpression: {
@@ -35,6 +35,7 @@ export declare class MongoRepository {
35
35
  * 取引削除タスク冪等作成
36
36
  */
37
37
  createDeleteTransactionTaskIfNotExist(params: factory.task.IAttributes<factory.taskName.DeleteTransaction>, options: IOptionOnCreate): Promise<void>;
38
+ createSendOrderTaskIfNotExist(params: factory.task.IAttributes<factory.taskName.SendOrder>, options: IOptionOnCreate): Promise<void>;
38
39
  executeById(params: {
39
40
  id: string;
40
41
  executor: {
@@ -31,7 +31,7 @@ class MongoRepository {
31
31
  }
32
32
  // tslint:disable-next-line:max-func-body-length
33
33
  static CREATE_MONGO_CONDITIONS(params) {
34
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
34
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
35
35
  const andConditions = [];
36
36
  const idEq = (_a = params.id) === null || _a === void 0 ? void 0 : _a.$eq;
37
37
  if (typeof idEq === 'string') {
@@ -115,32 +115,21 @@ class MongoRepository {
115
115
  }
116
116
  const objectIdEq = (_k = (_j = (_h = params.data) === null || _h === void 0 ? void 0 : _h.object) === null || _j === void 0 ? void 0 : _j.id) === null || _k === void 0 ? void 0 : _k.$eq;
117
117
  if (typeof objectIdEq === 'string') {
118
- andConditions.push({
119
- 'data.object.id': {
120
- $exists: true,
121
- $eq: objectIdEq
122
- }
123
- });
118
+ andConditions.push({ 'data.object.id': { $exists: true, $eq: objectIdEq } });
119
+ }
120
+ const objectOrderNumberEq = (_o = (_m = (_l = params.data) === null || _l === void 0 ? void 0 : _l.object) === null || _m === void 0 ? void 0 : _m.orderNumber) === null || _o === void 0 ? void 0 : _o.$eq;
121
+ if (typeof objectOrderNumberEq === 'string') {
122
+ andConditions.push({ 'data.object.orderNumber': { $exists: true, $eq: objectOrderNumberEq } });
124
123
  }
125
- const objectTransactionNumberEq = (_o = (_m = (_l = params.data) === null || _l === void 0 ? void 0 : _l.object) === null || _m === void 0 ? void 0 : _m.transactionNumber) === null || _o === void 0 ? void 0 : _o.$eq;
124
+ const objectTransactionNumberEq = (_r = (_q = (_p = params.data) === null || _p === void 0 ? void 0 : _p.object) === null || _q === void 0 ? void 0 : _q.transactionNumber) === null || _r === void 0 ? void 0 : _r.$eq;
126
125
  if (typeof objectTransactionNumberEq === 'string') {
127
- andConditions.push({
128
- 'data.object.transactionNumber': {
129
- $exists: true,
130
- $eq: objectTransactionNumberEq
131
- }
132
- });
126
+ andConditions.push({ 'data.object.transactionNumber': { $exists: true, $eq: objectTransactionNumberEq } });
133
127
  }
134
- const objectPurposeIdEq = (_r = (_q = (_p = params.data) === null || _p === void 0 ? void 0 : _p.purpose) === null || _q === void 0 ? void 0 : _q.id) === null || _r === void 0 ? void 0 : _r.$eq;
128
+ const objectPurposeIdEq = (_u = (_t = (_s = params.data) === null || _s === void 0 ? void 0 : _s.purpose) === null || _t === void 0 ? void 0 : _t.id) === null || _u === void 0 ? void 0 : _u.$eq;
135
129
  if (typeof objectPurposeIdEq === 'string') {
136
- andConditions.push({
137
- 'data.purpose.id': {
138
- $exists: true,
139
- $eq: objectPurposeIdEq
140
- }
141
- });
130
+ andConditions.push({ 'data.purpose.id': { $exists: true, $eq: objectPurposeIdEq } });
142
131
  }
143
- const objectPurposeOrderNumberEq = (_u = (_t = (_s = params.data) === null || _s === void 0 ? void 0 : _s.purpose) === null || _t === void 0 ? void 0 : _t.orderNumber) === null || _u === void 0 ? void 0 : _u.$eq;
132
+ const objectPurposeOrderNumberEq = (_x = (_w = (_v = params.data) === null || _v === void 0 ? void 0 : _v.purpose) === null || _w === void 0 ? void 0 : _w.orderNumber) === null || _x === void 0 ? void 0 : _x.$eq;
144
133
  if (typeof objectPurposeOrderNumberEq === 'string') {
145
134
  andConditions.push({
146
135
  'data.purpose.orderNumber': {
@@ -230,6 +219,27 @@ class MongoRepository {
230
219
  }
231
220
  });
232
221
  }
222
+ createSendOrderTaskIfNotExist(params, options) {
223
+ return __awaiter(this, void 0, void 0, function* () {
224
+ const createdTask = yield this.taskModel.findOneAndUpdate({
225
+ 'project.id': { $eq: params.project.id },
226
+ name: { $eq: params.name },
227
+ 'data.object.orderNumber': {
228
+ $exists: true,
229
+ $eq: String(params.data.object.orderNumber)
230
+ }
231
+ }, { $setOnInsert: params }, { new: true, upsert: true })
232
+ .select({ _id: 1 })
233
+ .exec();
234
+ if (options.emitImmediately) {
235
+ task_2.taskEventEmitter.emitTaskStatusChanged({
236
+ id: createdTask.id,
237
+ name: params.name,
238
+ status: factory.taskStatus.Ready
239
+ });
240
+ }
241
+ });
242
+ }
233
243
  executeById(params) {
234
244
  return __awaiter(this, void 0, void 0, function* () {
235
245
  const doc = yield this.taskModel.findOneAndUpdate({
@@ -21,9 +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
- /**
25
- * 注文作成後のアクション
26
- */
27
24
  export declare function createOnPlaceOrderTasksByTransaction(params: {
28
25
  object: factory.order.IOrder | IExternalOrder;
29
26
  potentialActions?: factory.action.trade.order.IPotentialActions;
@@ -262,71 +262,6 @@ function createConfirmRegisterServiceActionObjectByOrder(params) {
262
262
  });
263
263
  }
264
264
  exports.createConfirmRegisterServiceActionObjectByOrder = createConfirmRegisterServiceActionObjectByOrder;
265
- /**
266
- * 注文作成後のアクション
267
- */
268
- // export function onPlaceOrder(params: {
269
- // object: factory.order.IOrder | IExternalOrder;
270
- // potentialActions?: factory.action.trade.order.IPotentialActions;
271
- // }) {
272
- // return async (repos: {
273
- // task: TaskRepo;
274
- // }) => {
275
- // const potentialActions = params.potentialActions;
276
- // const now = new Date();
277
- // // potentialActionsのためのタスクを生成
278
- // const taskAttributes: factory.task.IAttributes<factory.taskName>[] = [];
279
- // // tslint:disable-next-line:no-single-line-block-comment
280
- // /* istanbul ignore else */
281
- // if (potentialActions !== undefined) {
282
- // // tslint:disable-next-line:no-single-line-block-comment
283
- // /* istanbul ignore else */
284
- // if (potentialActions.sendOrder !== undefined) {
285
- // const sendOrderTask: factory.task.IAttributes<factory.taskName.SendOrder> = {
286
- // project: potentialActions.sendOrder.project,
287
- // name: factory.taskName.SendOrder,
288
- // status: factory.taskStatus.Ready,
289
- // runsAt: now, // なるはやで実行
290
- // remainingNumberOfTries: 10,
291
- // numberOfTried: 0,
292
- // executionResults: [],
293
- // // data: potentialActions.sendOrder
294
- // data: {
295
- // project: potentialActions.sendOrder.project,
296
- // object: {
297
- // ...potentialActions.sendOrder.object,
298
- // confirmationNumber: params.object.confirmationNumber
299
- // },
300
- // ...(potentialActions.sendOrder.potentialActions !== undefined)
301
- // ? { potentialActions: potentialActions.sendOrder.potentialActions }
302
- // : undefined
303
- // }
304
- // };
305
- // taskAttributes.push(sendOrderTask);
306
- // }
307
- // // ポイント付与
308
- // // tslint:disable-next-line:no-single-line-block-comment
309
- // /* istanbul ignore else */
310
- // if (Array.isArray(potentialActions.givePointAward)) {
311
- // taskAttributes.push(...potentialActions.givePointAward.map(
312
- // (a): factory.task.IAttributes<factory.taskName.GivePointAward> => {
313
- // return {
314
- // project: a.project,
315
- // name: factory.taskName.GivePointAward,
316
- // status: factory.taskStatus.Ready,
317
- // runsAt: now, // なるはやで実行
318
- // remainingNumberOfTries: 10,
319
- // numberOfTried: 0,
320
- // executionResults: [],
321
- // data: a
322
- // };
323
- // }));
324
- // }
325
- // }
326
- // // タスク保管
327
- // await repos.task.saveMany(taskAttributes, { emitImmediately: true });
328
- // };
329
- // }
330
265
  function createOnPlaceOrderTasksByTransaction(params) {
331
266
  const potentialActions = params.potentialActions;
332
267
  const now = new Date();
@@ -335,29 +270,33 @@ function createOnPlaceOrderTasksByTransaction(params) {
335
270
  // tslint:disable-next-line:no-single-line-block-comment
336
271
  /* istanbul ignore else */
337
272
  if (potentialActions !== undefined) {
273
+ // 冗長なsendOrderタスク作成を回避(createSendOrderTransactionTaskIfNotExistへ移行)(2023-08-24~)
338
274
  // tslint:disable-next-line:no-single-line-block-comment
339
275
  /* istanbul ignore else */
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
- };
349
- const sendOrderTask = {
350
- project: potentialActions.sendOrder.project,
351
- name: factory.taskName.SendOrder,
352
- status: factory.taskStatus.Ready,
353
- runsAt: now,
354
- remainingNumberOfTries: 10,
355
- numberOfTried: 0,
356
- executionResults: [],
357
- data: sendOrderTaskData
358
- };
359
- taskAttributes.push(sendOrderTask);
360
- }
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
+ // }
361
300
  // ポイント付与
362
301
  // tslint:disable-next-line:no-single-line-block-comment
363
302
  /* istanbul ignore else */
@@ -24,7 +24,7 @@ const TOKEN_EXPIRES_IN = 604800;
24
24
  function onOrderStatusChanged(params) {
25
25
  // tslint:disable-next-line:max-func-body-length
26
26
  return (repos) => __awaiter(this, void 0, void 0, function* () {
27
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
27
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
28
28
  let tasks = [];
29
29
  const maskedCustomer = (0, order_1.createMaskedCustomer)(params.order, { noProfile: true });
30
30
  const simpleOrder = {
@@ -115,6 +115,16 @@ function onOrderStatusChanged(params) {
115
115
  default:
116
116
  }
117
117
  yield repos.task.saveMany(tasks, { emitImmediately: true });
118
+ switch (params.order.orderStatus) {
119
+ case factory.orderStatus.OrderProcessing:
120
+ // 冗長なsendOrderタスク作成を回避(2023-08-24~)
121
+ yield createSendOrderTransactionTaskIfNotExist({
122
+ object: params.order,
123
+ 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
124
+ })(repos);
125
+ break;
126
+ default:
127
+ }
118
128
  });
119
129
  }
120
130
  exports.onOrderStatusChanged = onOrderStatusChanged;
@@ -285,6 +295,30 @@ function createConfirmRegisterServiceTransactionTasks(order, simpleOrder) {
285
295
  }
286
296
  });
287
297
  }
298
+ function createSendOrderTransactionTaskIfNotExist(params) {
299
+ return (repos) => __awaiter(this, void 0, void 0, function* () {
300
+ var _a;
301
+ const now = new Date();
302
+ const sendOrderByTransaction = (_a = params.potentialActions) === null || _a === void 0 ? void 0 : _a.sendOrder;
303
+ if (sendOrderByTransaction !== undefined) {
304
+ const sendOrderTaskData = {
305
+ project: sendOrderByTransaction.project,
306
+ object: Object.assign(Object.assign({}, sendOrderByTransaction.object), { confirmationNumber: params.object.confirmationNumber })
307
+ };
308
+ const sendOrderTask = {
309
+ project: sendOrderByTransaction.project,
310
+ name: factory.taskName.SendOrder,
311
+ status: factory.taskStatus.Ready,
312
+ runsAt: now,
313
+ remainingNumberOfTries: 10,
314
+ numberOfTried: 0,
315
+ executionResults: [],
316
+ data: sendOrderTaskData
317
+ };
318
+ yield repos.task.createSendOrderTaskIfNotExist(sendOrderTask, { emitImmediately: true });
319
+ }
320
+ });
321
+ }
288
322
  const RETURN_COA_TASK_DELAY_IN_SECONDS = 0;
289
323
  function createReturnReserveTransactionTasks(order, simpleOrder) {
290
324
  var _a, _b;
@@ -232,6 +232,7 @@ function placeOrder(params) {
232
232
  });
233
233
  }
234
234
  else if (order.orderStatus === factory.orderStatus.OrderProcessing) {
235
+ // OrderPaymentDueをスキップしてOrderProcessingから開始する場合(2023-08-23~)
235
236
  // OrderPaymentDueに対する処理をまず強制的に実行する(2023-08-24~)
236
237
  yield (0, onOrderStatusChanged_1.onOrderStatusChanged)({
237
238
  order: Object.assign(Object.assign({}, order), { orderStatus: factory.orderStatus.OrderPaymentDue }),
@@ -240,16 +241,18 @@ function placeOrder(params) {
240
241
  registerActionInProgress: repos.registerActionInProgress,
241
242
  task: repos.task
242
243
  });
243
- // OrderPaymentDueをスキップしてOrderProcessingから開始する場合(2023-08-23~)
244
- // paymentMethods.length: 0の場合に、confirmPayTransactionは実行されないので、ここで強制的にpayOrderを実行する必要がある
245
- yield (0, payOrder_1.payOrder)({
246
- project: { id: order.project.id },
247
- object: {
248
- confirmationNumber: order.confirmationNumber,
249
- orderNumber: order.orderNumber
250
- },
251
- useOnOrderStatusChanged: params.useOnOrderStatusChanged
252
- })(repos);
244
+ // paymentMethods.length: 0の場合を考慮(2023-08-24~)
245
+ if (order.paymentMethods.length === 0) {
246
+ // paymentMethods.length: 0の場合に、confirmPayTransactionは実行されないので、ここで強制的にpayOrderを実行する必要がある
247
+ yield (0, payOrder_1.payOrder)({
248
+ project: { id: order.project.id },
249
+ object: {
250
+ confirmationNumber: order.confirmationNumber,
251
+ orderNumber: order.orderNumber
252
+ },
253
+ useOnOrderStatusChanged: params.useOnOrderStatusChanged
254
+ })(repos);
255
+ }
253
256
  }
254
257
  else {
255
258
  throw new factory.errors.NotImplemented(`placing an order on the status '${order.orderStatus}' not implemented`);
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  }
10
10
  ],
11
11
  "dependencies": {
12
- "@chevre/factory": "4.327.0-alpha.1",
12
+ "@chevre/factory": "4.327.0-alpha.2",
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.2"
120
+ "version": "21.8.0-alpha.4"
121
121
  }