@chevre/domain 21.6.0-alpha.1 → 21.6.0-alpha.2

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.
@@ -53,6 +53,15 @@ function onResourceDeleted(params) {
53
53
  ids: params.id
54
54
  })(repos);
55
55
  break;
56
+ case factory.product.ProductType.EventService:
57
+ case factory.product.ProductType.Product:
58
+ case factory.product.ProductType.Transportation:
59
+ yield deleteResourcesByProduct({
60
+ project: { id: params.project.id },
61
+ ids: params.id,
62
+ typeOf: params.typeOf
63
+ })(repos);
64
+ break;
56
65
  default:
57
66
  // no op
58
67
  throw new factory.errors.NotImplemented(`${params.typeOf} onDeleted not implemented`);
@@ -333,3 +342,46 @@ function deleteResourcesByOfferCatalog(params) {
333
342
  }
334
343
  });
335
344
  }
345
+ function deleteResourcesByProduct(params) {
346
+ return (repos) => __awaiter(this, void 0, void 0, function* () {
347
+ if (params.ids.length !== 1) {
348
+ throw new factory.errors.Argument('id', 'id.length must be 1');
349
+ }
350
+ for (const productId of params.ids) {
351
+ const deleteActionAttributes = {
352
+ agent: { id: params.project.id, typeOf: factory.organizationType.Project },
353
+ object: { id: productId, typeOf: params.typeOf },
354
+ project: { id: params.project.id, typeOf: factory.organizationType.Project },
355
+ typeOf: factory.actionType.DeleteAction
356
+ };
357
+ let deleteResult;
358
+ const action = yield repos.action.start(deleteActionAttributes);
359
+ try {
360
+ let deleteEventResult;
361
+ let updateOfferResult;
362
+ // 興行を設定されたイベント削除
363
+ deleteEventResult = yield repos.event.deleteManyByItemOfferedId({
364
+ project: { id: params.project.id },
365
+ offers: { itemOffered: { id: { $in: [productId] } } }
366
+ });
367
+ // アドオンから除外
368
+ updateOfferResult = yield repos.offer.pullAddOns({
369
+ project: { id: params.project.id },
370
+ addOn: { itemOffered: { id: { $in: [productId] } } }
371
+ });
372
+ deleteResult = { deleteEventResult, updateOfferResult };
373
+ }
374
+ catch (error) {
375
+ try {
376
+ const actionError = Object.assign(Object.assign({}, error), { message: error.message, name: error.name });
377
+ yield repos.action.giveUp({ typeOf: deleteActionAttributes.typeOf, id: action.id, error: actionError });
378
+ }
379
+ catch (_) {
380
+ // no op
381
+ }
382
+ throw error;
383
+ }
384
+ yield repos.action.complete({ typeOf: deleteActionAttributes.typeOf, id: action.id, result: deleteResult });
385
+ }
386
+ });
387
+ }
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.6.0-alpha.1"
120
+ "version": "21.6.0-alpha.2"
121
121
  }