@chevre/domain 20.1.0-alpha.36 → 20.1.0-alpha.37

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.
@@ -10,49 +10,70 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.confirmReservation = void 0;
13
+ /**
14
+ * 予約サービス
15
+ */
16
+ const factory = require("../../factory");
13
17
  const onReservationConfirmed_1 = require("./potentialActions/onReservationConfirmed");
14
18
  /**
15
19
  * 予約を確定する
16
20
  */
17
21
  function confirmReservation(actionAttributesList) {
18
22
  return (repos) => __awaiter(this, void 0, void 0, function* () {
19
- const confirmedReservations = [];
20
- yield Promise.all(actionAttributesList.map((actionAttributes) => __awaiter(this, void 0, void 0, function* () {
21
- let reservation = actionAttributes.object;
22
- const action = yield repos.action.start(actionAttributes);
23
- try {
24
- // 予約を確定状態に変更する
25
- reservation = yield repos.reservation.confirm({
26
- // 更新属性をwhitelist化(2022-06-13~)
27
- // ...actionAttributes.object,
28
- id: reservation.id,
29
- previousReservationStatus: reservation.reservationStatus,
30
- underName: reservation.underName,
31
- reservedTicket: reservation.reservedTicket
32
- });
33
- // _idは不要であり、存在すると予期せぬ影響を及ぼす可能性がある
34
- delete reservation._id;
35
- confirmedReservations.push(reservation);
36
- }
37
- catch (error) {
38
- // actionにエラー結果を追加
23
+ let confirmedReservations = [];
24
+ if (actionAttributesList.length > 0) {
25
+ yield Promise.all(actionAttributesList.map((actionAttributes) => __awaiter(this, void 0, void 0, function* () {
26
+ const reservation = actionAttributes.object;
27
+ const action = yield repos.action.start(actionAttributes);
39
28
  try {
40
- const actionError = Object.assign(Object.assign({}, error), { message: error.message, name: error.name });
41
- yield repos.action.giveUp({ typeOf: action.typeOf, id: action.id, error: actionError });
29
+ // 予約を確定状態に変更する
30
+ // reservation = await repos.reservation.confirm<factory.reservationType.EventReservation>({
31
+ yield repos.reservation.confirm({
32
+ // 更新属性をwhitelist化(2022-06-13~)
33
+ // ...actionAttributes.object,
34
+ id: reservation.id,
35
+ previousReservationStatus: reservation.reservationStatus,
36
+ underName: reservation.underName,
37
+ reservedTicket: reservation.reservedTicket
38
+ });
39
+ // _idは不要であり、存在すると予期せぬ影響を及ぼす可能性がある
40
+ // delete (<any>reservation)._id;
41
+ // confirmedReservations.push(reservation);
42
42
  }
43
- catch (__) {
44
- // 失敗したら仕方ない
43
+ catch (error) {
44
+ // actionにエラー結果を追加
45
+ try {
46
+ const actionError = Object.assign(Object.assign({}, error), { message: error.message, name: error.name });
47
+ yield repos.action.giveUp({ typeOf: action.typeOf, id: action.id, error: actionError });
48
+ }
49
+ catch (__) {
50
+ // 失敗したら仕方ない
51
+ }
52
+ throw error;
45
53
  }
46
- throw error;
54
+ // アクション完了
55
+ const actionResult = {
56
+ confirmedReservationId: reservation.id
57
+ };
58
+ yield repos.action.complete({ typeOf: action.typeOf, id: action.id, result: actionResult });
59
+ yield (0, onReservationConfirmed_1.onReservationConfirmedByAction)(actionAttributes)({ task: repos.task });
60
+ })));
61
+ // 確定予約通知タスクを予約番号単位で作成する(2022-12-21~)
62
+ const reservationNumber = actionAttributesList[0].object.reservationNumber;
63
+ if (typeof reservationNumber === 'string' && reservationNumber.length > 0) {
64
+ // 最新のconfirmedReservationsを検索
65
+ confirmedReservations = yield repos.reservation.search({
66
+ reservationNumber: { $eq: reservationNumber },
67
+ typeOf: factory.reservationType.EventReservation
68
+ });
69
+ confirmedReservations = confirmedReservations.map((r) => {
70
+ // _idは不要であり、存在すると予期せぬ影響を及ぼす可能性がある
71
+ delete r._id;
72
+ return r;
73
+ });
47
74
  }
48
- // アクション完了
49
- const actionResult = {
50
- confirmedReservationId: reservation.id
51
- };
52
- yield repos.action.complete({ typeOf: action.typeOf, id: action.id, result: actionResult });
53
- yield (0, onReservationConfirmed_1.onReservationConfirmedByAction)(actionAttributes, reservation)({ task: repos.task });
54
- })));
55
- yield (0, onReservationConfirmed_1.onReservationConfirmed)(confirmedReservations)({ task: repos.task });
75
+ yield (0, onReservationConfirmed_1.onReservationConfirmed)(confirmedReservations)({ task: repos.task });
76
+ }
56
77
  });
57
78
  }
58
79
  exports.confirmReservation = confirmReservation;
@@ -7,7 +7,7 @@ declare type IEventReservation = factory.reservation.IReservation<factory.reserv
7
7
  /**
8
8
  * 予約確定後のアクション
9
9
  */
10
- export declare function onReservationConfirmedByAction(actionAttributes: factory.action.reserve.IAttributes, confirmedReservation: IEventReservation): (repos: {
10
+ export declare function onReservationConfirmedByAction(actionAttributes: factory.action.reserve.IAttributes): (repos: {
11
11
  task: TaskRepo;
12
12
  }) => Promise<void>;
13
13
  export declare function onReservationConfirmed(confirmedReservations: IEventReservation[]): (repos: {
@@ -21,7 +21,9 @@ const informReservations = settings_1.settings.onReservationStatusChanged.inform
21
21
  /**
22
22
  * 予約確定後のアクション
23
23
  */
24
- function onReservationConfirmedByAction(actionAttributes, confirmedReservation) {
24
+ function onReservationConfirmedByAction(actionAttributes
25
+ // confirmedReservation: IEventReservation
26
+ ) {
25
27
  return (repos) => __awaiter(this, void 0, void 0, function* () {
26
28
  const potentialActions = actionAttributes.potentialActions;
27
29
  const now = new Date();
@@ -45,35 +47,34 @@ function onReservationConfirmedByAction(actionAttributes, confirmedReservation)
45
47
  }
46
48
  }
47
49
  // inform galobally
48
- if (Array.isArray(informReservations)) {
49
- const reservation4inform = (0, factory_1.maskUnderName)(confirmedReservation);
50
- taskAttributes.push(...informReservations.map((informReservation) => {
51
- var _a;
52
- const informUrl = String((_a = informReservation.recipient) === null || _a === void 0 ? void 0 : _a.url);
53
- const informReservationAttributes = {
54
- agent: confirmedReservation.project,
55
- object: [reservation4inform],
56
- project: confirmedReservation.project,
57
- recipient: {
58
- id: '',
59
- name: informUrl,
60
- typeOf: factory.creativeWorkType.WebApplication,
61
- url: informUrl
62
- },
63
- typeOf: factory.actionType.InformAction
64
- };
65
- return {
66
- project: actionAttributes.project,
67
- name: factory.taskName.TriggerWebhook,
68
- status: factory.taskStatus.Ready,
69
- runsAt: now,
70
- remainingNumberOfTries: factory_1.NUM_TRY_INFORM_RESERVATION,
71
- numberOfTried: 0,
72
- executionResults: [],
73
- data: informReservationAttributes
74
- };
75
- }));
76
- }
50
+ // if (Array.isArray(informReservations)) {
51
+ // const reservation4inform: IReservation4informConfirmed = maskUnderName(confirmedReservation);
52
+ // taskAttributes.push(...informReservations.map<ITriggerWebhookTaskAttributes>((informReservation) => {
53
+ // const informUrl: string = String(informReservation.recipient?.url);
54
+ // const informReservationAttributes: InformReservationActionattributes = {
55
+ // agent: confirmedReservation.project,
56
+ // object: [reservation4inform],
57
+ // project: confirmedReservation.project,
58
+ // recipient: {
59
+ // id: '',
60
+ // name: informUrl,
61
+ // typeOf: factory.creativeWorkType.WebApplication,
62
+ // url: informUrl
63
+ // },
64
+ // typeOf: factory.actionType.InformAction
65
+ // };
66
+ // return {
67
+ // project: actionAttributes.project,
68
+ // name: factory.taskName.TriggerWebhook,
69
+ // status: factory.taskStatus.Ready,
70
+ // runsAt: now,
71
+ // remainingNumberOfTries: NUM_TRY_INFORM_RESERVATION,
72
+ // numberOfTried: 0,
73
+ // executionResults: [],
74
+ // data: informReservationAttributes
75
+ // };
76
+ // }));
77
+ // }
77
78
  // タスク保管
78
79
  if (taskAttributes.length > 0) {
79
80
  yield repos.task.saveMany(taskAttributes);
@@ -88,6 +89,42 @@ function onReservationConfirmed(confirmedReservations) {
88
89
  project: confirmedReservations[0].project,
89
90
  reservationFor: { id: confirmedReservations[0].reservationFor.id }
90
91
  })({ task: repos.task });
92
+ const now = new Date();
93
+ const taskAttributes = [];
94
+ // inform galobally
95
+ if (Array.isArray(informReservations)) {
96
+ taskAttributes.push(...informReservations.map((informReservation) => {
97
+ var _a;
98
+ const informUrl = String((_a = informReservation.recipient) === null || _a === void 0 ? void 0 : _a.url);
99
+ const informObject = confirmedReservations.map(factory_1.maskUnderName);
100
+ const informReservationAttributes = {
101
+ agent: confirmedReservations[0].project,
102
+ object: informObject,
103
+ project: confirmedReservations[0].project,
104
+ recipient: {
105
+ id: '',
106
+ name: informUrl,
107
+ typeOf: factory.creativeWorkType.WebApplication,
108
+ url: informUrl
109
+ },
110
+ typeOf: factory.actionType.InformAction
111
+ };
112
+ return {
113
+ project: confirmedReservations[0].project,
114
+ name: factory.taskName.TriggerWebhook,
115
+ status: factory.taskStatus.Ready,
116
+ runsAt: now,
117
+ remainingNumberOfTries: factory_1.NUM_TRY_INFORM_RESERVATION,
118
+ numberOfTried: 0,
119
+ executionResults: [],
120
+ data: informReservationAttributes
121
+ };
122
+ }));
123
+ }
124
+ // タスク保管
125
+ if (taskAttributes.length > 0) {
126
+ yield repos.task.saveMany(taskAttributes);
127
+ }
91
128
  }
92
129
  });
93
130
  }
package/package.json CHANGED
@@ -120,5 +120,5 @@
120
120
  "postversion": "git push origin --tags",
121
121
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
122
122
  },
123
- "version": "20.1.0-alpha.36"
123
+ "version": "20.1.0-alpha.37"
124
124
  }