@chevre/domain 21.2.0-alpha.80 → 21.2.0-alpha.82

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.
@@ -13,6 +13,16 @@ async function main() {
13
13
  hasMerchantReturnPolicy: { itemCondition: { id: { $eq: '646dc7848b3c1437d43dbfeb' } } }
14
14
  });
15
15
  console.log('sellers:', sellers);
16
+
17
+ const assetTransactionRepo = new chevre.repository.AssetTransaction(mongoose.connection);
18
+ const reserveTransactions = await assetTransactionRepo.search({
19
+ limit: 1,
20
+ typeOf: chevre.factory.assetTransactionType.Reserve,
21
+ object: {
22
+ reservationFor: { id: { $eq: 'xxx' } }
23
+ }
24
+ });
25
+ console.log('reserveTransactions:', reserveTransactions);
16
26
  }
17
27
 
18
28
  main()
@@ -75,7 +75,7 @@ export declare class MongoRepository {
75
75
  confirm<T extends factory.assetTransactionType>(params: {
76
76
  typeOf: T;
77
77
  id: string;
78
- object?: Pick<factory.action.reserve.IReservationPackageAsObject, 'underName'>;
78
+ object?: Pick<factory.assetTransaction.reserve.IObject, 'underName'>;
79
79
  result: factory.assetTransaction.IResult<T>;
80
80
  potentialActions: factory.assetTransaction.IPotentialActions<T>;
81
81
  }): Promise<void>;
@@ -327,14 +327,14 @@ class MongoRepository {
327
327
  * 取引を確定する
328
328
  */
329
329
  confirm(params) {
330
- var _a, _b, _c;
330
+ var _a, _b;
331
331
  return __awaiter(this, void 0, void 0, function* () {
332
332
  const doc = yield this.transactionModel.findOneAndUpdate({
333
333
  _id: { $eq: params.id },
334
334
  typeOf: { $eq: params.typeOf },
335
335
  status: { $eq: factory.transactionStatusType.InProgress }
336
336
  }, Object.assign({ status: factory.transactionStatusType.Confirmed, endDate: new Date(), result: params.result, potentialActions: params.potentialActions }, (typeof ((_b = (_a = params.object) === null || _a === void 0 ? void 0 : _a.underName) === null || _b === void 0 ? void 0 : _b.typeOf) === 'string')
337
- ? { 'object.underName': (_c = params.object) === null || _c === void 0 ? void 0 : _c.underName }
337
+ ? { 'object.underName': params.object.underName }
338
338
  : undefined), {
339
339
  new: true,
340
340
  projection: { _id: 1 }
@@ -135,6 +135,18 @@ schema.index({ 'object.reservationNumber': 1, startDate: -1 }, {
135
135
  'object.reservationNumber': { $exists: true }
136
136
  }
137
137
  });
138
+ schema.index({ 'object.reservations.id': 1, startDate: -1 }, {
139
+ name: 'searchByObjectReservationsId',
140
+ partialFilterExpression: { 'object.reservations.id': { $exists: true } }
141
+ });
142
+ schema.index({ 'object.reservations.reservationNumber': 1, startDate: -1 }, {
143
+ name: 'searchByObjectReservationsReservationNumber',
144
+ partialFilterExpression: { 'object.reservations.reservationNumber': { $exists: true } }
145
+ });
146
+ schema.index({ 'object.reservations.reservationFor.id': 1, startDate: -1 }, {
147
+ name: 'searchByObjectReservationsReservationForId',
148
+ partialFilterExpression: { 'object.reservations.reservationFor.id': { $exists: true } }
149
+ });
138
150
  schema.index({ 'object.membershipNumber': 1, startDate: -1 }, {
139
151
  name: 'searchByObjectMembershipNumber',
140
152
  partialFilterExpression: {
@@ -63,9 +63,9 @@ declare const schema: Schema<any, import("mongoose").Model<any, any, any, any, a
63
63
  reservationFor?: any;
64
64
  subReservation?: any;
65
65
  broker?: any;
66
+ underName?: any;
66
67
  price?: any;
67
68
  priceCurrency?: string | undefined;
68
- underName?: any;
69
69
  issuedThrough?: any;
70
70
  reservedTicket?: any;
71
71
  additionalTicketText?: string | undefined;
@@ -91,9 +91,9 @@ declare const schema: Schema<any, import("mongoose").Model<any, any, any, any, a
91
91
  reservationFor?: any;
92
92
  subReservation?: any;
93
93
  broker?: any;
94
+ underName?: any;
94
95
  price?: any;
95
96
  priceCurrency?: string | undefined;
96
- underName?: any;
97
97
  issuedThrough?: any;
98
98
  reservedTicket?: any;
99
99
  additionalTicketText?: string | undefined;
@@ -119,9 +119,9 @@ declare const schema: Schema<any, import("mongoose").Model<any, any, any, any, a
119
119
  reservationFor?: any;
120
120
  subReservation?: any;
121
121
  broker?: any;
122
+ underName?: any;
122
123
  price?: any;
123
124
  priceCurrency?: string | undefined;
124
- underName?: any;
125
125
  issuedThrough?: any;
126
126
  reservedTicket?: any;
127
127
  additionalTicketText?: string | undefined;
@@ -75,6 +75,7 @@ export declare function createPotentialActions(params: factory.assetTransaction.
75
75
  }): {
76
76
  potentialActions: factory.assetTransaction.reserve.IPotentialActions;
77
77
  reservationPackage?: factory.action.reserve.IReservationPackageAsObject;
78
+ underName?: factory.reservation.IUnderName<factory.reservationType.EventReservation>;
78
79
  };
79
80
  export declare function createPendingReservationAction(params: {
80
81
  transaction: factory.assetTransaction.ITransaction<factory.assetTransactionType.Reserve>;
@@ -449,9 +449,9 @@ function createPotentialActions(params) {
449
449
  const pendingReservations = (Array.isArray(transaction.object.subReservation)) ? transaction.object.subReservation : [];
450
450
  let reserveActionAttributes = [];
451
451
  let reservationPackage;
452
+ let underName;
452
453
  if (pendingReservations.length > 0) {
453
454
  // ReservationPackageに対応(2022-12-22~)
454
- let underName;
455
455
  // purpose:Orderの指定があれば、underName,issuedByを調整(2022-05-23~)
456
456
  if (typeof ((_a = params.order) === null || _a === void 0 ? void 0 : _a.typeOf) === 'string') {
457
457
  const ordre2reservationUnderNameResult = ordre2reservationUnderName({ order: params.order });
@@ -468,12 +468,18 @@ function createPotentialActions(params) {
468
468
  underName
469
469
  }));
470
470
  });
471
- reservationPackage = Object.assign({ reservationFor, reservationNumber: transaction.object.reservationNumber, reservationStatus: (typeof params.transaction.object.reservationStatus === 'string')
471
+ reservationPackage = {
472
+ reservationFor,
473
+ reservationNumber: transaction.object.reservationNumber,
474
+ reservationStatus: (typeof params.transaction.object.reservationStatus === 'string')
472
475
  ? params.transaction.object.reservationStatus
473
- : factory.reservationStatusType.ReservationPending,
476
+ : factory.reservationStatusType.ReservationPending,
474
477
  // 不要なので廃止(2023-01-19~)
475
478
  // subReservation: pendingReservations,
476
- typeOf: factory.reservationType.ReservationPackage }, (typeof (underName === null || underName === void 0 ? void 0 : underName.typeOf) === 'string') ? { underName } : undefined);
479
+ typeOf: factory.reservationType.ReservationPackage
480
+ // 廃止(2023-05-31~)→予約取引から取得に変更
481
+ // ...(typeof underName?.typeOf === 'string') ? { underName } : undefined
482
+ };
477
483
  reserveActionAttributes = [{
478
484
  project: transaction.project,
479
485
  typeOf: factory.actionType.ReserveAction,
@@ -490,7 +496,8 @@ function createPotentialActions(params) {
490
496
  potentialActions: {
491
497
  reserve: reserveActionAttributes
492
498
  },
493
- reservationPackage
499
+ reservationPackage,
500
+ underName
494
501
  };
495
502
  }
496
503
  exports.createPotentialActions = createPotentialActions;
@@ -698,7 +698,6 @@ function onReservationsCreated(params) {
698
698
  */
699
699
  function confirm(params) {
700
700
  return (repos) => __awaiter(this, void 0, void 0, function* () {
701
- var _a;
702
701
  let transaction;
703
702
  // 取引存在確認
704
703
  if (typeof params.id === 'string') {
@@ -717,17 +716,21 @@ function confirm(params) {
717
716
  throw new factory.errors.ArgumentNull('Transaction ID or Transaction Number');
718
717
  }
719
718
  const order = yield fixOrderAsPurpose(params, transaction)(repos);
720
- const { potentialActions, reservationPackage } = (0, factory_1.createPotentialActions)(Object.assign(Object.assign({}, params), { transaction: transaction, order }));
719
+ const { potentialActions, underName } = (0, factory_1.createPotentialActions)(Object.assign(Object.assign({}, params), { transaction,
720
+ order }));
721
721
  // 取引確定
722
722
  const result = {};
723
723
  yield repos.assetTransaction.confirm(Object.assign({ typeOf: factory.assetTransactionType.Reserve, id: transaction.id, result: result, potentialActions: (settings_1.USE_ASSET_TRANSACTION_SYNC_PROCESSING)
724
724
  ? { reserve: [] }
725
- : potentialActions }, (typeof ((_a = reservationPackage === null || reservationPackage === void 0 ? void 0 : reservationPackage.underName) === null || _a === void 0 ? void 0 : _a.typeOf) === 'string')
726
- ? { object: { underName: reservationPackage.underName } }
725
+ : potentialActions }, (typeof (underName === null || underName === void 0 ? void 0 : underName.typeOf) === 'string')
726
+ ? { object: { underName } }
727
727
  : undefined));
728
728
  if (settings_1.USE_ASSET_TRANSACTION_SYNC_PROCESSING) {
729
729
  // sync対応(2023-01-13~)
730
- yield (0, confirmReservation_1.confirmReservation)(potentialActions.reserve)(repos);
730
+ yield (0, confirmReservation_1.confirmReservation)({
731
+ actionAttributesList: potentialActions.reserve,
732
+ useOnReservationConfirmed: true
733
+ })(repos);
731
734
  }
732
735
  });
733
736
  }
@@ -9,7 +9,10 @@ import { MongoRepository as TaskRepo } from '../../repo/task';
9
9
  /**
10
10
  * 予約を確定する
11
11
  */
12
- export declare function confirmReservation(actionAttributesList: factory.action.reserve.IAttributes[]): (repos: {
12
+ export declare function confirmReservation(params: {
13
+ actionAttributesList: factory.action.reserve.IAttributes[];
14
+ useOnReservationConfirmed: boolean;
15
+ }): (repos: {
13
16
  action: ActionRepo;
14
17
  assetTransaction: AssetTrasactionRepo;
15
18
  reservation: ReservationRepo;
@@ -18,106 +18,131 @@ const onReservationConfirmed_1 = require("./potentialActions/onReservationConfir
18
18
  /**
19
19
  * 予約を確定する
20
20
  */
21
- function confirmReservation(actionAttributesList) {
22
- // tslint:disable-next-line:max-func-body-length
21
+ function confirmReservation(params) {
23
22
  return (repos) => __awaiter(this, void 0, void 0, function* () {
24
- let confirmedReservations = [];
25
- if (actionAttributesList.length > 0) {
26
- yield Promise.all(actionAttributesList.map((actionAttributes) => __awaiter(this, void 0, void 0, function* () {
27
- var _a, _b;
28
- const reservationPackage = actionAttributes.object;
29
- const action = yield repos.action.start(actionAttributes);
30
- try {
31
- const reserveTransactions = yield repos.assetTransaction.search({
32
- limit: 1,
33
- page: 1,
34
- typeOf: factory.assetTransactionType.Reserve,
35
- transactionNumber: { $eq: reservationPackage.reservationNumber }
23
+ if (params.actionAttributesList.length > 0) {
24
+ yield Promise.all(params.actionAttributesList.map((actionAttributes) => __awaiter(this, void 0, void 0, function* () {
25
+ yield reserveIfNotYet(actionAttributes)(repos);
26
+ if (params.useOnReservationConfirmed) {
27
+ yield (0, onReservationConfirmed_1.onReservationConfirmedByAction)(actionAttributes)({ task: repos.task });
28
+ }
29
+ })));
30
+ if (params.useOnReservationConfirmed) {
31
+ let confirmedReservations = [];
32
+ // 確定予約通知タスクを予約番号単位で作成する(2022-12-21~)
33
+ const reservationNumber = params.actionAttributesList[0].object.reservationNumber;
34
+ if (typeof reservationNumber === 'string' && reservationNumber.length > 0) {
35
+ // 最新のconfirmedReservationsを検索
36
+ confirmedReservations = yield repos.reservation.search({
37
+ reservationNumber: { $eq: reservationNumber },
38
+ typeOf: factory.reservationType.EventReservation
36
39
  });
37
- const reserveTransaction = reserveTransactions.shift();
38
- if (reserveTransaction === undefined) {
39
- throw new factory.errors.NotFound(factory.assetTransactionType.Reserve);
40
- }
41
- let underName;
42
- // 予約取引に保管されたunderNameを使用する(2023-05-30~)
43
- if (typeof ((_a = reserveTransaction.object.underName) === null || _a === void 0 ? void 0 : _a.typeOf) === 'string') {
44
- underName = reserveTransaction.object.underName;
45
- }
46
- else if (typeof ((_b = reservationPackage.underName) === null || _b === void 0 ? void 0 : _b.typeOf) === 'string') {
47
- underName = reservationPackage.underName;
48
- }
49
- // ReservationPackageに対応(2022-12-22~)
50
- if (reservationPackage.typeOf === factory.reservationType.ReservationPackage) {
51
- // Pendingの予約が存在しないバージョンに対応する(2023-05-29~)
52
- if (reserveTransaction.object.disablePendingReservations === true) {
53
- const reservationFor = reserveTransaction.object.reservationFor;
54
- const subReservations = reserveTransaction.object.subReservation;
55
- if (Array.isArray(subReservations)
56
- && typeof (reservationFor === null || reservationFor === void 0 ? void 0 : reservationFor.typeOf) === 'string') {
57
- yield Promise.all(subReservations.map((subReservation) => __awaiter(this, void 0, void 0, function* () {
58
- yield repos.reservation.confirmByIdIfNotExist({
59
- reservation: subReservation,
60
- reservationFor,
61
- underName
62
- });
63
- })));
64
- }
65
- }
66
- else {
67
- // 予約を確定状態に変更する
68
- yield repos.reservation.confirmByReservationNumber({
69
- reservationNumber: reservationPackage.reservationNumber,
70
- previousReservationStatus: reservationPackage.reservationStatus,
71
- underName
72
- });
40
+ confirmedReservations = confirmedReservations.map((r) => {
41
+ // _idは不要であり、存在すると予期せぬ影響を及ぼす可能性がある
42
+ delete r._id;
43
+ return r;
44
+ });
45
+ }
46
+ yield (0, onReservationConfirmed_1.onReservationConfirmed)(confirmedReservations)({ task: repos.task });
47
+ }
48
+ }
49
+ });
50
+ }
51
+ exports.confirmReservation = confirmReservation;
52
+ // tslint:disable-next-line:max-func-body-length
53
+ function reserveIfNotYet(params) {
54
+ return (repos) => __awaiter(this, void 0, void 0, function* () {
55
+ var _a;
56
+ const reservationPackage = params.object;
57
+ // 冪等性を担保(2023-05-31~)
58
+ const completedActions = yield repos.action.search({
59
+ limit: 1,
60
+ page: 1,
61
+ typeOf: { $eq: params.typeOf },
62
+ object: {
63
+ typeOf: { $eq: params.object.typeOf }
64
+ // reservationNumber: { $eq: params.object.reservationNumber }
65
+ },
66
+ purpose: {
67
+ id: { $in: [params.purpose.id] },
68
+ typeOf: { $in: [params.purpose.typeOf] }
69
+ }
70
+ }, ['_id'], []);
71
+ if (completedActions.length === 0) {
72
+ const action = yield repos.action.start(params);
73
+ try {
74
+ const reserveTransactions = yield repos.assetTransaction.search({
75
+ limit: 1,
76
+ page: 1,
77
+ typeOf: factory.assetTransactionType.Reserve,
78
+ transactionNumber: { $eq: reservationPackage.reservationNumber }
79
+ });
80
+ const reserveTransaction = reserveTransactions.shift();
81
+ if (reserveTransaction === undefined) {
82
+ throw new factory.errors.NotFound(factory.assetTransactionType.Reserve);
83
+ }
84
+ let underName;
85
+ // 予約取引に保管されたunderNameを使用する(2023-05-30~)
86
+ if (typeof ((_a = reserveTransaction.object.underName) === null || _a === void 0 ? void 0 : _a.typeOf) === 'string') {
87
+ underName = reserveTransaction.object.underName;
88
+ // 廃止(2023-05-31~)→予約取引から取得に変更
89
+ // } else if (typeof reservationPackage.underName?.typeOf === 'string') {
90
+ // underName = reservationPackage.underName;
91
+ }
92
+ // ReservationPackageに対応(2022-12-22~)
93
+ if (reservationPackage.typeOf === factory.reservationType.ReservationPackage) {
94
+ // Pendingの予約が存在しないバージョンに対応する(2023-05-29~)
95
+ if (reserveTransaction.object.disablePendingReservations === true) {
96
+ const reservationFor = reserveTransaction.object.reservationFor;
97
+ const subReservations = reserveTransaction.object.subReservation;
98
+ if (Array.isArray(subReservations)
99
+ && typeof (reservationFor === null || reservationFor === void 0 ? void 0 : reservationFor.typeOf) === 'string') {
100
+ yield Promise.all(subReservations.map((subReservation) => __awaiter(this, void 0, void 0, function* () {
101
+ yield repos.reservation.confirmByIdIfNotExist({
102
+ reservation: subReservation,
103
+ reservationFor,
104
+ underName
105
+ });
106
+ })));
73
107
  }
74
108
  }
75
109
  else {
76
- // 廃止(2023-01-18)
77
- throw new factory.errors.Forbidden(`${reservationPackage.typeOf} not acceptable`);
78
110
  // 予約を確定状態に変更する
79
- // await repos.reservation.confirm<factory.reservationType.EventReservation>({
80
- // id: reservation.id,
81
- // previousReservationStatus: reservation.reservationStatus,
82
- // underName: reservation.underName
83
- // });
84
- // _idは不要であり、存在すると予期せぬ影響を及ぼす可能性がある
85
- // delete (<any>reservation)._id;
86
- // confirmedReservations.push(reservation);
111
+ yield repos.reservation.confirmByReservationNumber({
112
+ reservationNumber: reservationPackage.reservationNumber,
113
+ previousReservationStatus: reservationPackage.reservationStatus,
114
+ underName
115
+ });
87
116
  }
88
117
  }
89
- catch (error) {
90
- // actionにエラー結果を追加
91
- try {
92
- const actionError = Object.assign(Object.assign({}, error), { message: error.message, name: error.name });
93
- yield repos.action.giveUp({ typeOf: action.typeOf, id: action.id, error: actionError });
94
- }
95
- catch (__) {
96
- // 失敗したら仕方ない
97
- }
98
- throw error;
99
- }
100
- // アクション完了
101
- const actionResult = {};
102
- yield repos.action.complete({ typeOf: action.typeOf, id: action.id, result: actionResult });
103
- yield (0, onReservationConfirmed_1.onReservationConfirmedByAction)(actionAttributes)({ task: repos.task });
104
- })));
105
- // 確定予約通知タスクを予約番号単位で作成する(2022-12-21~)
106
- const reservationNumber = actionAttributesList[0].object.reservationNumber;
107
- if (typeof reservationNumber === 'string' && reservationNumber.length > 0) {
108
- // 最新のconfirmedReservationsを検索
109
- confirmedReservations = yield repos.reservation.search({
110
- reservationNumber: { $eq: reservationNumber },
111
- typeOf: factory.reservationType.EventReservation
112
- });
113
- confirmedReservations = confirmedReservations.map((r) => {
118
+ else {
119
+ // 廃止(2023-01-18)
120
+ throw new factory.errors.Forbidden(`${reservationPackage.typeOf} not acceptable`);
121
+ // 予約を確定状態に変更する
122
+ // await repos.reservation.confirm<factory.reservationType.EventReservation>({
123
+ // id: reservation.id,
124
+ // previousReservationStatus: reservation.reservationStatus,
125
+ // underName: reservation.underName
126
+ // });
114
127
  // _idは不要であり、存在すると予期せぬ影響を及ぼす可能性がある
115
- delete r._id;
116
- return r;
117
- });
128
+ // delete (<any>reservation)._id;
129
+ // confirmedReservations.push(reservation);
130
+ }
131
+ }
132
+ catch (error) {
133
+ // actionにエラー結果を追加
134
+ try {
135
+ const actionError = Object.assign(Object.assign({}, error), { message: error.message, name: error.name });
136
+ yield repos.action.giveUp({ typeOf: action.typeOf, id: action.id, error: actionError });
137
+ }
138
+ catch (__) {
139
+ // 失敗したら仕方ない
140
+ }
141
+ throw error;
118
142
  }
119
- yield (0, onReservationConfirmed_1.onReservationConfirmed)(confirmedReservations)({ task: repos.task });
143
+ // アクション完了
144
+ const actionResult = {};
145
+ yield repos.action.complete({ typeOf: action.typeOf, id: action.id, result: actionResult });
120
146
  }
121
147
  });
122
148
  }
123
- exports.confirmReservation = confirmReservation;
@@ -20,7 +20,10 @@ const ReserveService = require("../reserve");
20
20
  */
21
21
  function call(data) {
22
22
  return (settings) => __awaiter(this, void 0, void 0, function* () {
23
- yield ReserveService.confirmReservation(data.actionAttributes)({
23
+ yield ReserveService.confirmReservation({
24
+ actionAttributesList: data.actionAttributes,
25
+ useOnReservationConfirmed: true
26
+ })({
24
27
  action: new action_1.MongoRepository(settings.connection),
25
28
  assetTransaction: new assetTransaction_1.MongoRepository(settings.connection),
26
29
  reservation: new reservation_1.MongoRepository(settings.connection),
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  }
10
10
  ],
11
11
  "dependencies": {
12
- "@chevre/factory": "4.313.0-alpha.19",
12
+ "@chevre/factory": "4.313.0-alpha.20",
13
13
  "@cinerino/sdk": "3.157.0-alpha.5",
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.80"
120
+ "version": "21.2.0-alpha.82"
121
121
  }