@chevre/domain 21.2.0-alpha.72 → 21.2.0-alpha.74

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.
@@ -68,7 +68,8 @@ async function main() {
68
68
  },
69
69
  validateEvent: false,
70
70
  validateEventOfferPeriod: false,
71
- validateAppliesToMovieTicket: true
71
+ validateAppliesToMovieTicket: true,
72
+ disablePendingReservations: true
72
73
  })({
73
74
  stockHolder: itemAvailabilityRepo,
74
75
  event: eventRepo,
@@ -31,14 +31,16 @@ export declare class MongoRepository {
31
31
  inclusion?: string[];
32
32
  exclusion?: string[];
33
33
  }): Promise<factory.reservation.IReservation<T>>;
34
- /**
35
- * 予約確定
36
- */
37
34
  confirmByReservationNumber(params: {
38
35
  reservationNumber: string;
39
36
  previousReservationStatus: factory.reservationStatusType;
40
37
  underName?: factory.reservation.IUnderName<factory.reservationType.EventReservation>;
41
38
  }): Promise<void>;
39
+ confirmByIdIfNotExist(params: {
40
+ reservation: factory.assetTransaction.reserve.IObjectSubReservation;
41
+ reservationFor: factory.assetTransaction.reserve.IReservationFor;
42
+ underName?: factory.reservation.IUnderName<factory.reservationType.EventReservation>;
43
+ }): Promise<void>;
42
44
  /**
43
45
  * 予約取消
44
46
  */
@@ -910,48 +910,6 @@ class MongoRepository {
910
910
  return doc.toObject();
911
911
  });
912
912
  }
913
- /**
914
- * 予約確定
915
- */
916
- // public async confirm<T extends factory.reservationType>(params: {
917
- // id: string;
918
- // previousReservationStatus: factory.reservationStatusType;
919
- // underName?: factory.reservation.IUnderName<T>;
920
- // }): Promise<factory.reservation.IReservation<T>> {
921
- // const conditions = {
922
- // _id: { $eq: String(params.id) },
923
- // reservationStatus: { $eq: params.previousReservationStatus }
924
- // };
925
- // // 更新属性をwhitelist化(2022-06-13~)
926
- // const update = {
927
- // // previousReservationStatusを保管(2023-01-19~)
928
- // previousReservationStatus: params.previousReservationStatus,
929
- // reservationStatus: factory.reservationStatusType.ReservationConfirmed,
930
- // modifiedTime: new Date(),
931
- // ...(params.underName !== undefined) ? { underName: params.underName } : undefined
932
- // };
933
- // const doc = await this.reservationModel.findOneAndUpdate(
934
- // conditions,
935
- // update,
936
- // { new: true }
937
- // )
938
- // .select({ __v: 0, createdAt: 0, updatedAt: 0 })
939
- // .exec();
940
- // // NotFoundであれば状態確認
941
- // if (doc === null) {
942
- // const reservation = await this.findById<T>({ id: String(params.id) });
943
- // if (reservation.reservationStatus === factory.reservationStatusType.ReservationConfirmed) {
944
- // // すでに確定済の場合
945
- // return reservation;
946
- // } else {
947
- // throw new factory.errors.Argument(
948
- // 'id',
949
- // `Reservation ${reservation.id} already changed -> ${reservation.reservationStatus}`
950
- // );
951
- // }
952
- // }
953
- // return doc.toObject();
954
- // }
955
913
  confirmByReservationNumber(params) {
956
914
  return __awaiter(this, void 0, void 0, function* () {
957
915
  const conditions = {
@@ -965,6 +923,14 @@ class MongoRepository {
965
923
  .exec();
966
924
  });
967
925
  }
926
+ confirmByIdIfNotExist(params) {
927
+ return __awaiter(this, void 0, void 0, function* () {
928
+ yield this.reservationModel.findByIdAndUpdate({ _id: { $eq: params.reservation.id } }, {
929
+ $setOnInsert: Object.assign(Object.assign(Object.assign({}, params.reservation), { _id: params.reservation.id, reservationFor: params.reservationFor, reservationStatus: factory.reservationStatusType.ReservationConfirmed, modifiedTime: new Date() }), (params.underName !== undefined) ? { underName: params.underName } : undefined)
930
+ })
931
+ .exec();
932
+ });
933
+ }
968
934
  /**
969
935
  * 予約取消
970
936
  */
@@ -4,6 +4,7 @@ type IObjectSubReservation = factory.assetTransaction.reserve.IObjectSubReservat
4
4
  export { IAcceptedAddOn };
5
5
  export declare function createStartParams(params: factory.assetTransaction.reserve.IStartParamsWithoutDetail & {
6
6
  reservationNumber: string;
7
+ disablePendingReservations: boolean;
7
8
  }): factory.assetTransaction.IStartParams<factory.assetTransactionType.Reserve>;
8
9
  /**
9
10
  * ポイント特典を作成する
@@ -13,7 +13,7 @@ function createStartParams(params) {
13
13
  const reservationNumber = params.reservationNumber;
14
14
  const reservationPackage = Object.assign({
15
15
  // project: params.project,
16
- reservationNumber: reservationNumber, reservationStatus: factory.reservationStatusType.ReservationPending, typeOf: factory.reservationType.ReservationPackage }, (typeof ((_a = params.object.broker) === null || _a === void 0 ? void 0 : _a.typeOf) === 'string') ? { broker: params.object.broker } : undefined);
16
+ reservationNumber: reservationNumber, reservationStatus: factory.reservationStatusType.ReservationPending, disablePendingReservations: params.disablePendingReservations, typeOf: factory.reservationType.ReservationPackage }, (typeof ((_a = params.object.broker) === null || _a === void 0 ? void 0 : _a.typeOf) === 'string') ? { broker: params.object.broker } : undefined);
17
17
  return {
18
18
  project: { id: params.project.id, typeOf: factory.organizationType.Project },
19
19
  typeOf: factory.assetTransactionType.Reserve,
@@ -95,7 +95,9 @@ type IStartParams = factory.assetTransaction.reserve.IStartParamsWithoutDetail &
95
95
  /**
96
96
  * 取引開始
97
97
  */
98
- export declare function start(params: IStartParams): IStartOperation<{
98
+ export declare function start(params: IStartParams & {
99
+ disablePendingReservations: boolean;
100
+ }): IStartOperation<{
99
101
  transaction: factory.assetTransaction.ITransaction<factory.assetTransactionType.Reserve>;
100
102
  objectSubReservations: IObjectSubReservation[];
101
103
  }>;
@@ -152,9 +152,10 @@ function addReservations(params) {
152
152
  acceptedOffer: acceptedOffers4transactionObject,
153
153
  reservationFor,
154
154
  // subReservationにreservationForを保管しない(2021-10-19~)
155
- // 最適化(2023-05-29~)
156
- // subReservation: objectSubReservations
157
- subReservation: minimizedObjectSubReservations
155
+ subReservation: (transaction.object.disablePendingReservations === true)
156
+ ? objectSubReservations
157
+ : minimizedObjectSubReservations
158
+ // subReservation: minimizedObjectSubReservations
158
159
  }
159
160
  });
160
161
  }
@@ -173,10 +174,12 @@ function addReservations(params) {
173
174
  reservations: objectSubReservations,
174
175
  transaction: transaction
175
176
  })(repos);
176
- // 予約作成(insertManyで実装)
177
- yield repos.reservation.createMany({ reservationFor, reservations: objectSubReservations });
178
- // 予約作成後処理
179
- yield onReservationsCreated({ event })(repos);
177
+ if (transaction.object.disablePendingReservations !== true) {
178
+ // 予約作成(insertManyで実装)
179
+ yield repos.reservation.createMany({ reservationFor, reservations: objectSubReservations });
180
+ // 予約作成後処理
181
+ yield onReservationsCreated({ event })(repos);
182
+ }
180
183
  return { transaction, objectSubReservations };
181
184
  });
182
185
  }
@@ -57,5 +57,6 @@ declare function authorize(params: {
57
57
  */
58
58
  id: string;
59
59
  };
60
+ disablePendingReservations: boolean;
60
61
  }): IAuthorizeOperation<IAuthorizeOfferAction>;
61
62
  export { authorize };
@@ -66,7 +66,8 @@ function authorize(params) {
66
66
  ticketOffers,
67
67
  unitPriceOffers,
68
68
  validateEvent: params.validateEvent === true,
69
- validateEventOfferPeriod: params.validateEventOfferPeriod === true
69
+ validateEventOfferPeriod: params.validateEventOfferPeriod === true,
70
+ disablePendingReservations: params.disablePendingReservations
70
71
  })(repos);
71
72
  // requestBody = processStartReserveResult.requestBody;
72
73
  // responseBody = processStartReserveResult.responseBody;
@@ -162,7 +163,7 @@ function processStartReserve4chevre(params) {
162
163
  // requestBody = startParams;
163
164
  const startParamObject = yield validateObjectWithoutDetail(startParams)(repos);
164
165
  // 予約取引開始
165
- const startReserveTransactionResult = yield ReserveTransactionService.start(Object.assign(Object.assign({}, startParams), { object: startParamObject, preSearchedEvent: event, preSearchedTicketOffers: params.ticketOffers, preSearchedUnitPriceOffers: params.unitPriceOffers, availableAtOrFrom: { id: params.availableAtOrFrom.id }, validateEvent: params.validateEvent, validateEventOfferPeriod: params.validateEventOfferPeriod, validateAppliesToMovieTicket: true }))(repos);
166
+ const startReserveTransactionResult = yield ReserveTransactionService.start(Object.assign(Object.assign({}, startParams), { object: startParamObject, preSearchedEvent: event, preSearchedTicketOffers: params.ticketOffers, preSearchedUnitPriceOffers: params.unitPriceOffers, availableAtOrFrom: { id: params.availableAtOrFrom.id }, validateEvent: params.validateEvent, validateEventOfferPeriod: params.validateEventOfferPeriod, validateAppliesToMovieTicket: true, disablePendingReservations: params.disablePendingReservations }))(repos);
166
167
  responseBody = startReserveTransactionResult.transaction;
167
168
  // 予約取引からオファー情報を生成する
168
169
  acceptedOffers4result = (0, factory_1.responseBody2acceptedOffers4result)({
@@ -3,6 +3,7 @@
3
3
  */
4
4
  import * as factory from '../../factory';
5
5
  import { MongoRepository as ActionRepo } from '../../repo/action';
6
+ import { MongoRepository as AssetTrasactionRepo } from '../../repo/assetTransaction';
6
7
  import { MongoRepository as ReservationRepo } from '../../repo/reservation';
7
8
  import { MongoRepository as TaskRepo } from '../../repo/task';
8
9
  /**
@@ -10,6 +11,7 @@ import { MongoRepository as TaskRepo } from '../../repo/task';
10
11
  */
11
12
  export declare function confirmReservation(actionAttributesList: factory.action.reserve.IAttributes[]): (repos: {
12
13
  action: ActionRepo;
14
+ assetTransaction: AssetTrasactionRepo;
13
15
  reservation: ReservationRepo;
14
16
  task: TaskRepo;
15
17
  }) => Promise<void>;
@@ -27,14 +27,41 @@ function confirmReservation(actionAttributesList) {
27
27
  const reservation = actionAttributes.object;
28
28
  const action = yield repos.action.start(actionAttributes);
29
29
  try {
30
+ const reserveTransactions = yield repos.assetTransaction.search({
31
+ limit: 1,
32
+ page: 1,
33
+ typeOf: factory.assetTransactionType.Reserve,
34
+ transactionNumber: { $eq: reservation.reservationNumber }
35
+ });
36
+ const reserveTransaction = reserveTransactions.shift();
37
+ if (reserveTransaction === undefined) {
38
+ throw new factory.errors.NotFound(factory.assetTransactionType.Reserve);
39
+ }
30
40
  // ReservationPackageに対応(2022-12-22~)
31
41
  if (reservation.typeOf === factory.reservationType.ReservationPackage) {
32
- // 予約を確定状態に変更する
33
- yield repos.reservation.confirmByReservationNumber({
34
- reservationNumber: reservation.reservationNumber,
35
- previousReservationStatus: reservation.reservationStatus,
36
- underName: reservation.underName
37
- });
42
+ // Pendingの予約が存在しないバージョンに対応する(2023-05-29~)
43
+ if (reserveTransaction.object.disablePendingReservations === true) {
44
+ const reservationFor = reserveTransaction.object.reservationFor;
45
+ const subReservations = reserveTransaction.object.subReservation;
46
+ if (Array.isArray(subReservations)
47
+ && typeof (reservationFor === null || reservationFor === void 0 ? void 0 : reservationFor.typeOf) === 'string') {
48
+ yield Promise.all(subReservations.map((subReservation) => __awaiter(this, void 0, void 0, function* () {
49
+ yield repos.reservation.confirmByIdIfNotExist({
50
+ reservation: subReservation,
51
+ reservationFor,
52
+ underName: reservation.underName
53
+ });
54
+ })));
55
+ }
56
+ }
57
+ else {
58
+ // 予約を確定状態に変更する
59
+ yield repos.reservation.confirmByReservationNumber({
60
+ reservationNumber: reservation.reservationNumber,
61
+ previousReservationStatus: reservation.reservationStatus,
62
+ underName: reservation.underName
63
+ });
64
+ }
38
65
  }
39
66
  else {
40
67
  // 廃止(2023-01-18)
@@ -11,6 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.call = void 0;
13
13
  const action_1 = require("../../repo/action");
14
+ const assetTransaction_1 = require("../../repo/assetTransaction");
14
15
  const reservation_1 = require("../../repo/reservation");
15
16
  const task_1 = require("../../repo/task");
16
17
  const ReserveService = require("../reserve");
@@ -19,13 +20,11 @@ const ReserveService = require("../reserve");
19
20
  */
20
21
  function call(data) {
21
22
  return (settings) => __awaiter(this, void 0, void 0, function* () {
22
- const actionRepo = new action_1.MongoRepository(settings.connection);
23
- const reservationRepo = new reservation_1.MongoRepository(settings.connection);
24
- const taskRepo = new task_1.MongoRepository(settings.connection);
25
23
  yield ReserveService.confirmReservation(data.actionAttributes)({
26
- action: actionRepo,
27
- reservation: reservationRepo,
28
- task: taskRepo
24
+ action: new action_1.MongoRepository(settings.connection),
25
+ assetTransaction: new assetTransaction_1.MongoRepository(settings.connection),
26
+ reservation: new reservation_1.MongoRepository(settings.connection),
27
+ task: new task_1.MongoRepository(settings.connection)
29
28
  });
30
29
  });
31
30
  }
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  }
10
10
  ],
11
11
  "dependencies": {
12
- "@chevre/factory": "4.313.0-alpha.13",
12
+ "@chevre/factory": "4.313.0-alpha.14",
13
13
  "@cinerino/sdk": "3.157.0-alpha.2",
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.2.0-alpha.72"
120
+ "version": "21.2.0-alpha.74"
121
121
  }