@chevre/domain 21.2.0-alpha.76 → 21.2.0-alpha.78

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.
@@ -75,6 +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
79
  result: factory.assetTransaction.IResult<T>;
79
80
  potentialActions: factory.assetTransaction.IPotentialActions<T>;
80
81
  }): Promise<void>;
@@ -311,17 +311,15 @@ class MongoRepository {
311
311
  * 取引を確定する
312
312
  */
313
313
  confirm(params) {
314
+ var _a, _b, _c;
314
315
  return __awaiter(this, void 0, void 0, function* () {
315
316
  const doc = yield this.transactionModel.findOneAndUpdate({
316
317
  _id: { $eq: params.id },
317
318
  typeOf: { $eq: params.typeOf },
318
319
  status: { $eq: factory.transactionStatusType.InProgress }
319
- }, {
320
- status: factory.transactionStatusType.Confirmed,
321
- endDate: new Date(),
322
- result: params.result,
323
- potentialActions: params.potentialActions // resultを更新
324
- }, {
320
+ }, 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')
321
+ ? { 'object.underName': (_c = params.object) === null || _c === void 0 ? void 0 : _c.underName }
322
+ : undefined), {
325
323
  new: true,
326
324
  projection: { _id: 1 }
327
325
  })
@@ -65,6 +65,7 @@ declare const schema: Schema<any, import("mongoose").Model<any, any, any, any, a
65
65
  broker?: any;
66
66
  price?: any;
67
67
  priceCurrency?: string | undefined;
68
+ underName?: any;
68
69
  issuedThrough?: any;
69
70
  reservedTicket?: any;
70
71
  additionalTicketText?: string | undefined;
@@ -72,7 +73,6 @@ declare const schema: Schema<any, import("mongoose").Model<any, any, any, any, a
72
73
  modifiedTime?: Date | undefined;
73
74
  numSeats?: number | undefined;
74
75
  programMembershipUsed?: any;
75
- underName?: any;
76
76
  bookingAgent?: any;
77
77
  cancelReservationUrl?: string | undefined;
78
78
  checkinUrl?: string | undefined;
@@ -93,6 +93,7 @@ declare const schema: Schema<any, import("mongoose").Model<any, any, any, any, a
93
93
  broker?: any;
94
94
  price?: any;
95
95
  priceCurrency?: string | undefined;
96
+ underName?: any;
96
97
  issuedThrough?: any;
97
98
  reservedTicket?: any;
98
99
  additionalTicketText?: string | undefined;
@@ -100,7 +101,6 @@ declare const schema: Schema<any, import("mongoose").Model<any, any, any, any, a
100
101
  modifiedTime?: Date | undefined;
101
102
  numSeats?: number | undefined;
102
103
  programMembershipUsed?: any;
103
- underName?: any;
104
104
  bookingAgent?: any;
105
105
  cancelReservationUrl?: string | undefined;
106
106
  checkinUrl?: string | undefined;
@@ -121,6 +121,7 @@ declare const schema: Schema<any, import("mongoose").Model<any, any, any, any, a
121
121
  broker?: any;
122
122
  price?: any;
123
123
  priceCurrency?: string | undefined;
124
+ underName?: any;
124
125
  issuedThrough?: any;
125
126
  reservedTicket?: any;
126
127
  additionalTicketText?: string | undefined;
@@ -128,7 +129,6 @@ declare const schema: Schema<any, import("mongoose").Model<any, any, any, any, a
128
129
  modifiedTime?: Date | undefined;
129
130
  numSeats?: number | undefined;
130
131
  programMembershipUsed?: any;
131
- underName?: any;
132
132
  bookingAgent?: any;
133
133
  cancelReservationUrl?: string | undefined;
134
134
  checkinUrl?: string | undefined;
@@ -86,7 +86,9 @@ export declare class MongoRepository {
86
86
  /**
87
87
  * 注文を検索する
88
88
  */
89
- search(params: factory.order.ISearchConditions, projection?: any): Promise<factory.order.IOrder[]>;
89
+ search(params: factory.order.ISearchConditions, projection?: {
90
+ [key: string]: 0 | 1;
91
+ }): Promise<factory.order.IOrder[]>;
90
92
  /**
91
93
  * 注文の受入オファーIDリストを検索する
92
94
  */
@@ -896,8 +896,15 @@ class MongoRepository {
896
896
  var _a;
897
897
  return __awaiter(this, void 0, void 0, function* () {
898
898
  const conditions = MongoRepository.CREATE_MONGO_CONDITIONS(params);
899
+ const projectionSpecified = projection !== undefined && projection !== null;
900
+ const positiveProjectionExists = (projectionSpecified)
901
+ ? Object.values(projection)
902
+ .some((value) => value !== 0)
903
+ : false;
899
904
  const query = this.orderModel.find((conditions.length > 0) ? { $and: conditions } : {})
900
- .select(Object.assign({ __v: 0, createdAt: 0, updatedAt: 0 }, projection));
905
+ .select((projectionSpecified && positiveProjectionExists)
906
+ ? projection
907
+ : Object.assign({ __v: 0, createdAt: 0, updatedAt: 0 }, projection));
901
908
  if (typeof params.limit === 'number' && params.limit > 0) {
902
909
  const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
903
910
  query.limit(params.limit)
@@ -63,7 +63,7 @@ export declare class MongoRepository {
63
63
  */
64
64
  $nin?: factory.taskName[];
65
65
  };
66
- }): Promise<Pick<import("@chevre/factory/lib/task").ITask | import("@chevre/factory/lib/task/confirmMoneyTransfer").ITask | import("@chevre/factory/lib/task/confirmRegisterService").ITask | import("@chevre/factory/lib/task/confirmPayTransaction").ITask | import("@chevre/factory/lib/task/confirmRegisterServiceTransaction").ITask | import("@chevre/factory/lib/task/confirmReserveTransaction").ITask | import("@chevre/factory/lib/task/deleteMember").ITask | import("@chevre/factory/lib/task/deleteTransaction").ITask | import("@chevre/factory/lib/task/givePointAward").ITask | import("@chevre/factory/lib/task/onAuthorizationCreated").ITask | import("@chevre/factory/lib/task/orderProgramMembership").ITask | import("@chevre/factory/lib/task/placeOrder").ITask | import("@chevre/factory/lib/task/returnOrder").ITask | import("@chevre/factory/lib/task/returnMoneyTransfer").ITask | import("@chevre/factory/lib/task/returnPayTransaction").ITask | import("@chevre/factory/lib/task/returnPointAward").ITask | import("@chevre/factory/lib/task/returnReserveTransaction").ITask | import("@chevre/factory/lib/task/sendEmailMessage").ITask | import("@chevre/factory/lib/task/sendOrder").ITask | import("@chevre/factory/lib/task/triggerWebhook").ITask | import("@chevre/factory/lib/task/voidMoneyTransferTransaction").ITask | import("@chevre/factory/lib/task/voidPayTransaction").ITask | import("@chevre/factory/lib/task/voidRegisterServiceTransaction").ITask | import("@chevre/factory/lib/task/voidReserveTransaction").ITask, "id" | "name" | "status">[]>;
66
+ }): Promise<Pick<import("@chevre/factory/lib/task").ITask | import("@chevre/factory/lib/task/confirmMoneyTransfer").ITask | import("@chevre/factory/lib/task/confirmRegisterService").ITask | import("@chevre/factory/lib/task/confirmPayTransaction").ITask | import("@chevre/factory/lib/task/confirmRegisterServiceTransaction").ITask | import("@chevre/factory/lib/task/confirmReserveTransaction").ITask | import("@chevre/factory/lib/task/deleteMember").ITask | import("@chevre/factory/lib/task/deleteTransaction").ITask | import("@chevre/factory/lib/task/givePointAward").ITask | import("@chevre/factory/lib/task/onAuthorizationCreated").ITask | import("@chevre/factory/lib/task/orderProgramMembership").ITask | import("@chevre/factory/lib/task/placeOrder").ITask | import("@chevre/factory/lib/task/returnOrder").ITask | import("@chevre/factory/lib/task/returnMoneyTransfer").ITask | import("@chevre/factory/lib/task/returnPayTransaction").ITask | import("@chevre/factory/lib/task/returnPointAward").ITask | import("@chevre/factory/lib/task/returnReserveTransaction").ITask | import("@chevre/factory/lib/task/sendEmailMessage").ITask | import("@chevre/factory/lib/task/sendOrder").ITask | import("@chevre/factory/lib/task/triggerWebhook").ITask | import("@chevre/factory/lib/task/useReservation").ITask | import("@chevre/factory/lib/task/voidMoneyTransferTransaction").ITask | import("@chevre/factory/lib/task/voidPayTransaction").ITask | import("@chevre/factory/lib/task/voidRegisterServiceTransaction").ITask | import("@chevre/factory/lib/task/voidReserveTransaction").ITask, "id" | "name" | "status">[]>;
67
67
  retry(params: {
68
68
  intervalInMinutes: number;
69
69
  }): Promise<void>;
@@ -71,8 +71,11 @@ export declare function createReservation(params: {
71
71
  }): IObjectSubReservation;
72
72
  export declare function createPotentialActions(params: factory.assetTransaction.reserve.IConfirmParams & {
73
73
  transaction: factory.assetTransaction.ITransaction<factory.assetTransactionType.Reserve>;
74
- order?: factory.order.IOrder;
75
- }): factory.assetTransaction.reserve.IPotentialActions;
74
+ order?: Pick<factory.order.IOrder, 'orderNumber' | 'customer' | 'typeOf'>;
75
+ }): {
76
+ potentialActions: factory.assetTransaction.reserve.IPotentialActions;
77
+ reservationPackage?: factory.action.reserve.IReservationPackageAsObject;
78
+ };
76
79
  export declare function createPendingReservationAction(params: {
77
80
  transaction: factory.assetTransaction.ITransaction<factory.assetTransactionType.Reserve>;
78
81
  }): factory.action.cancel.reservation.IAttributes[];
@@ -448,6 +448,7 @@ function createPotentialActions(params) {
448
448
  // 予約アクション属性作成
449
449
  const pendingReservations = (Array.isArray(transaction.object.subReservation)) ? transaction.object.subReservation : [];
450
450
  let reserveActionAttributes = [];
451
+ let reservationPackage;
451
452
  if (pendingReservations.length > 0) {
452
453
  // ReservationPackageに対応(2022-12-22~)
453
454
  let underName;
@@ -467,7 +468,7 @@ function createPotentialActions(params) {
467
468
  underName
468
469
  }));
469
470
  });
470
- const reservationPackage = Object.assign({ reservationFor, reservationNumber: transaction.object.reservationNumber, reservationStatus: (typeof params.transaction.object.reservationStatus === 'string')
471
+ reservationPackage = Object.assign({ reservationFor, reservationNumber: transaction.object.reservationNumber, reservationStatus: (typeof params.transaction.object.reservationStatus === 'string')
471
472
  ? params.transaction.object.reservationStatus
472
473
  : factory.reservationStatusType.ReservationPending,
473
474
  // 不要なので廃止(2023-01-19~)
@@ -486,7 +487,10 @@ function createPotentialActions(params) {
486
487
  }];
487
488
  }
488
489
  return {
489
- reserve: reserveActionAttributes
490
+ potentialActions: {
491
+ reserve: reserveActionAttributes
492
+ },
493
+ reservationPackage
490
494
  };
491
495
  }
492
496
  exports.createPotentialActions = createPotentialActions;
@@ -505,10 +509,6 @@ function createReservationUnderName(params) {
505
509
  */
506
510
  function ordre2reservationUnderName(params) {
507
511
  return {
508
- // issuedBy: {
509
- // typeOf: params.order.seller.typeOf,
510
- // name: params.order.seller.name
511
- // },
512
512
  underName: createReservationUnderName({ order: params.order })
513
513
  };
514
514
  }
@@ -698,6 +698,7 @@ function onReservationsCreated(params) {
698
698
  */
699
699
  function confirm(params) {
700
700
  return (repos) => __awaiter(this, void 0, void 0, function* () {
701
+ var _a;
701
702
  let transaction;
702
703
  // 取引存在確認
703
704
  if (typeof params.id === 'string') {
@@ -716,17 +717,14 @@ function confirm(params) {
716
717
  throw new factory.errors.ArgumentNull('Transaction ID or Transaction Number');
717
718
  }
718
719
  const order = yield fixOrderAsPurpose(params, transaction)(repos);
719
- const potentialActions = (0, factory_1.createPotentialActions)(Object.assign(Object.assign({}, params), { transaction: transaction, order }));
720
+ const { potentialActions, reservationPackage } = (0, factory_1.createPotentialActions)(Object.assign(Object.assign({}, params), { transaction: transaction, order }));
720
721
  // 取引確定
721
722
  const result = {};
722
- yield repos.assetTransaction.confirm({
723
- typeOf: factory.assetTransactionType.Reserve,
724
- id: transaction.id,
725
- result: result,
726
- potentialActions: (settings_1.USE_ASSET_TRANSACTION_SYNC_PROCESSING)
723
+ yield repos.assetTransaction.confirm(Object.assign({ typeOf: factory.assetTransactionType.Reserve, id: transaction.id, result: result, potentialActions: (settings_1.USE_ASSET_TRANSACTION_SYNC_PROCESSING)
727
724
  ? { reserve: [] }
728
- : potentialActions
729
- });
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 } }
727
+ : undefined));
730
728
  if (settings_1.USE_ASSET_TRANSACTION_SYNC_PROCESSING) {
731
729
  // sync対応(2023-01-13~)
732
730
  yield (0, confirmReservation_1.confirmReservation)(potentialActions.reserve)(repos);
@@ -750,7 +748,7 @@ function fixOrderAsPurpose(params, transaction) {
750
748
  project: { id: { $eq: transaction.project.id } },
751
749
  confirmationNumbers: [payPurposeConfirmationNumber],
752
750
  orderNumbers: [payPurposeOrderNumber]
753
- });
751
+ }, { customer: 1, orderNumber: 1, typeOf: 1 });
754
752
  order = orders.shift();
755
753
  if (order === undefined) {
756
754
  throw new factory.errors.NotFound('Order as purpose');
@@ -1,6 +1,3 @@
1
- /**
2
- * 予約サービス
3
- */
4
1
  import { MongoRepository as ReservationRepo } from '../../repo/reservation';
5
2
  import { MongoRepository as TaskRepo } from '../../repo/task';
6
3
  export declare function checkInRerservation(params: {
@@ -1,4 +1,5 @@
1
1
  "use strict";
2
+ // import * as factory from '../../factory';
2
3
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
4
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
5
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -10,6 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
11
  };
11
12
  Object.defineProperty(exports, "__esModule", { value: true });
12
13
  exports.checkInRerservation = void 0;
14
+ // import { confirmReservation } from './confirmReservation';
13
15
  const onReservationCheckedIn_1 = require("./potentialActions/onReservationCheckedIn");
14
16
  function checkInRerservation(params) {
15
17
  return (repos) => __awaiter(this, void 0, void 0, function* () {
@@ -17,6 +19,28 @@ function checkInRerservation(params) {
17
19
  // 発券処理(Array対応)
18
20
  let checkedInReservationIds;
19
21
  if (Array.isArray(params.object.ids) && params.object.ids.length > 0) {
22
+ // confirmReservationが間に合わない可能性を考慮する(2023-05-30~)
23
+ // const reserveTransactions = await repos.assetTransaction.search<factory.assetTransactionType.Reserve>({
24
+ // typeOf: factory.assetTransactionType.Reserve,
25
+ // object: {
26
+ // reservations: {
27
+ // id: { $in: params.object.ids }
28
+ // }
29
+ // }
30
+ // });
31
+ // await Promise.all(reserveTransactions.map(async (reserveTransaction) => {
32
+ // await confirmReservation([{
33
+ // project: reserveTransaction.project,
34
+ // typeOf: <factory.actionType.ReserveAction>factory.actionType.ReserveAction,
35
+ // // result: {},
36
+ // object: reservationPackage,
37
+ // agent: reserveTransaction.project,
38
+ // potentialActions: {
39
+ // moneyTransfer: moneyTransferActions
40
+ // },
41
+ // purpose: { typeOf: transaction.typeOf, id: transaction.id }
42
+ // }])(repos);
43
+ // }))
20
44
  yield repos.reservation.checkInIfNot({ id: { $in: params.object.ids }, now });
21
45
  checkedInReservationIds = params.object.ids;
22
46
  }
@@ -24,21 +24,30 @@ function confirmReservation(actionAttributesList) {
24
24
  let confirmedReservations = [];
25
25
  if (actionAttributesList.length > 0) {
26
26
  yield Promise.all(actionAttributesList.map((actionAttributes) => __awaiter(this, void 0, void 0, function* () {
27
- const reservation = actionAttributes.object;
27
+ var _a, _b;
28
+ const reservationPackage = actionAttributes.object;
28
29
  const action = yield repos.action.start(actionAttributes);
29
30
  try {
30
31
  const reserveTransactions = yield repos.assetTransaction.search({
31
32
  limit: 1,
32
33
  page: 1,
33
34
  typeOf: factory.assetTransactionType.Reserve,
34
- transactionNumber: { $eq: reservation.reservationNumber }
35
+ transactionNumber: { $eq: reservationPackage.reservationNumber }
35
36
  });
36
37
  const reserveTransaction = reserveTransactions.shift();
37
38
  if (reserveTransaction === undefined) {
38
39
  throw new factory.errors.NotFound(factory.assetTransactionType.Reserve);
39
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
+ }
40
49
  // ReservationPackageに対応(2022-12-22~)
41
- if (reservation.typeOf === factory.reservationType.ReservationPackage) {
50
+ if (reservationPackage.typeOf === factory.reservationType.ReservationPackage) {
42
51
  // Pendingの予約が存在しないバージョンに対応する(2023-05-29~)
43
52
  if (reserveTransaction.object.disablePendingReservations === true) {
44
53
  const reservationFor = reserveTransaction.object.reservationFor;
@@ -49,7 +58,7 @@ function confirmReservation(actionAttributesList) {
49
58
  yield repos.reservation.confirmByIdIfNotExist({
50
59
  reservation: subReservation,
51
60
  reservationFor,
52
- underName: reservation.underName
61
+ underName
53
62
  });
54
63
  })));
55
64
  }
@@ -57,15 +66,15 @@ function confirmReservation(actionAttributesList) {
57
66
  else {
58
67
  // 予約を確定状態に変更する
59
68
  yield repos.reservation.confirmByReservationNumber({
60
- reservationNumber: reservation.reservationNumber,
61
- previousReservationStatus: reservation.reservationStatus,
62
- underName: reservation.underName
69
+ reservationNumber: reservationPackage.reservationNumber,
70
+ previousReservationStatus: reservationPackage.reservationStatus,
71
+ underName
63
72
  });
64
73
  }
65
74
  }
66
75
  else {
67
76
  // 廃止(2023-01-18)
68
- throw new factory.errors.Forbidden(`${reservation.typeOf} not acceptable`);
77
+ throw new factory.errors.Forbidden(`${reservationPackage.typeOf} not acceptable`);
69
78
  // 予約を確定状態に変更する
70
79
  // await repos.reservation.confirm<factory.reservationType.EventReservation>({
71
80
  // id: reservation.id,
@@ -1,6 +1,3 @@
1
- /**
2
- * 予約サービス
3
- */
4
1
  import * as factory from '../../factory';
5
2
  import { MongoRepository as ActionRepo } from '../../repo/action';
6
3
  import { MongoRepository as OrderRepo } from '../../repo/order';
@@ -11,6 +8,9 @@ import { IUseReservationAction } from './potentialActions/onReservationUsed';
11
8
  * 予約使用
12
9
  */
13
10
  export declare function useReservation(params: {
11
+ project: {
12
+ id: string;
13
+ };
14
14
  agent: factory.action.consume.use.reservation.IAgent;
15
15
  object: {
16
16
  /**
@@ -24,6 +24,7 @@ export declare function useReservation(params: {
24
24
  location?: {
25
25
  identifier?: string;
26
26
  };
27
+ verifyToken: boolean;
27
28
  }): (repos: {
28
29
  action: ActionRepo;
29
30
  order: OrderRepo;
@@ -10,51 +10,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.useReservation = void 0;
13
- /**
14
- * 予約サービス
15
- */
16
13
  const factory = require("../../factory");
17
- const code_1 = require("../code");
18
- // import { maskUnderName } from './factory';
19
14
  const onReservationUsed_1 = require("./potentialActions/onReservationUsed");
20
- function verifyToken4reservation(params) {
21
- return (repos) => __awaiter(this, void 0, void 0, function* () {
22
- const payload = yield (0, code_1.verifyToken)({
23
- project: params.project,
24
- agent: params.agent,
25
- token: params.token
26
- })({});
27
- switch (payload.typeOf) {
28
- case factory.order.OrderType.Order:
29
- // reservationIdを含む注文の存在を確認するだけでよい(2023-01-31~)
30
- const order = yield repos.order.findByOrderNumberAndReservationId({
31
- orderNumber: payload.orderNumber,
32
- reservationId: params.reservationId
33
- });
34
- // ステータス検証
35
- switch (order.orderStatus) {
36
- case factory.orderStatus.OrderDelivered:
37
- break;
38
- default:
39
- throw new factory.errors.Argument('token', `invalid orderStatus '${order.orderStatus}'`);
40
- }
41
- // const acceptedOffers = (Array.isArray(order.acceptedOffers)) ? order.acceptedOffers : [];
42
- // const reservationExistsInOrder = acceptedOffers.some((offer) => {
43
- // return (
44
- // offer.itemOffered.typeOf === factory.reservationType.EventReservation
45
- // || offer.itemOffered.typeOf === factory.reservationType.BusReservation
46
- // )
47
- // && offer.itemOffered.id === params.reservationId;
48
- // });
49
- // if (!reservationExistsInOrder) {
50
- // throw new factory.errors.NotFound('AcceptedOffer');
51
- // }
52
- break;
53
- default:
54
- throw new factory.errors.NotImplemented(`Payload type ${payload.typeOf} not implemented`);
55
- }
56
- });
57
- }
15
+ const verifyToken4reservation_1 = require("./verifyToken4reservation");
58
16
  /**
59
17
  * 予約使用
60
18
  */
@@ -64,22 +22,24 @@ function useReservation(params) {
64
22
  var _a, _b;
65
23
  const now = new Date();
66
24
  const reservationId = params.object.id;
25
+ const token = (_a = params === null || params === void 0 ? void 0 : params.instrument) === null || _a === void 0 ? void 0 : _a.token;
26
+ if (params.verifyToken === true) {
27
+ // instrument?.tokenを検証
28
+ if (typeof token === 'string') {
29
+ yield (0, verifyToken4reservation_1.verifyToken4reservation)({
30
+ project: { id: params.project.id },
31
+ agent: params.agent,
32
+ reservationId,
33
+ token
34
+ })({ order: repos.order });
35
+ }
36
+ }
67
37
  // 予約検索
68
38
  // 取得属性最適化(2023-01-30~)
69
39
  const reservation = yield repos.reservation.findById({
70
40
  id: reservationId,
71
41
  inclusion: ['_id', 'issuedThrough', 'project', 'reservationFor', 'reservationNumber', 'reservedTicket', 'typeOf']
72
42
  });
73
- // instrument?.tokenを検証
74
- const token = (_a = params === null || params === void 0 ? void 0 : params.instrument) === null || _a === void 0 ? void 0 : _a.token;
75
- if (typeof token === 'string') {
76
- yield verifyToken4reservation({
77
- project: { id: reservation.project.id },
78
- agent: params.agent,
79
- reservationId,
80
- token
81
- })({ order: repos.order });
82
- }
83
43
  // UseActionを作成する
84
44
  const reservationAsObject = {
85
45
  id: reservation.id,
@@ -92,8 +52,6 @@ function useReservation(params) {
92
52
  const actionAttributes = Object.assign({ project: reservation.project, typeOf: factory.actionType.UseAction, agent: params.agent, instrument: Object.assign(Object.assign({}, (typeof token === 'string') ? { token } : undefined), { typeOf: factory.action.check.token.ObjectType.Ticket }),
93
53
  // object最適化(2023-01-30~)
94
54
  // どの予約を
95
- // mask
96
- // object: [maskUnderName(reservation)],
97
55
  object: [reservationAsObject] }, (typeof ((_b = params.location) === null || _b === void 0 ? void 0 : _b.identifier) === 'string')
98
56
  ? {
99
57
  location: {
@@ -111,14 +69,6 @@ function useReservation(params) {
111
69
  try {
112
70
  // 使用日時と同時更新(2023-01-30~)
113
71
  attendedReservation = (yield repos.reservation.attendIfNotAttended({ id: reservationId, now }));
114
- // attendedReservation = <IEventReservation>await repos.reservation.attend({ id: reservationId, now });
115
- // // 使用日時がなければ追加
116
- // if (attendedReservation.reservedTicket?.dateUsed === undefined) {
117
- // attendedReservation = await repos.reservation.updatePartiallyById({
118
- // id: attendedReservation.id,
119
- // update: { 'reservedTicket.dateUsed': now }
120
- // });
121
- // }
122
72
  }
123
73
  catch (error) {
124
74
  // actionにエラー結果を追加
@@ -0,0 +1,15 @@
1
+ import * as factory from '../../factory';
2
+ import { MongoRepository as OrderRepo } from '../../repo/order';
3
+ /**
4
+ * 予約使用のためのチケットトークンを検証する
5
+ */
6
+ export declare function verifyToken4reservation(params: {
7
+ project: {
8
+ id: string;
9
+ };
10
+ agent: factory.action.check.token.IAgent;
11
+ reservationId: string;
12
+ token: string;
13
+ }): (repos: {
14
+ order: OrderRepo;
15
+ }) => Promise<void>;
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.verifyToken4reservation = void 0;
13
+ const factory = require("../../factory");
14
+ const code_1 = require("../code");
15
+ /**
16
+ * 予約使用のためのチケットトークンを検証する
17
+ */
18
+ function verifyToken4reservation(params) {
19
+ return (repos) => __awaiter(this, void 0, void 0, function* () {
20
+ const payload = yield (0, code_1.verifyToken)({
21
+ project: params.project,
22
+ agent: params.agent,
23
+ token: params.token
24
+ })({});
25
+ switch (payload.typeOf) {
26
+ case factory.order.OrderType.Order:
27
+ // reservationIdを含む注文の存在を確認するだけでよい(2023-01-31~)
28
+ const order = yield repos.order.findByOrderNumberAndReservationId({
29
+ orderNumber: payload.orderNumber,
30
+ reservationId: params.reservationId
31
+ });
32
+ // ステータス検証
33
+ switch (order.orderStatus) {
34
+ case factory.orderStatus.OrderDelivered:
35
+ break;
36
+ default:
37
+ throw new factory.errors.Argument('token', `invalid orderStatus '${order.orderStatus}'`);
38
+ }
39
+ // const acceptedOffers = (Array.isArray(order.acceptedOffers)) ? order.acceptedOffers : [];
40
+ // const reservationExistsInOrder = acceptedOffers.some((offer) => {
41
+ // return (
42
+ // offer.itemOffered.typeOf === factory.reservationType.EventReservation
43
+ // || offer.itemOffered.typeOf === factory.reservationType.BusReservation
44
+ // )
45
+ // && offer.itemOffered.id === params.reservationId;
46
+ // });
47
+ // if (!reservationExistsInOrder) {
48
+ // throw new factory.errors.NotFound('AcceptedOffer');
49
+ // }
50
+ break;
51
+ default:
52
+ throw new factory.errors.NotImplemented(`Payload type ${payload.typeOf} not implemented`);
53
+ }
54
+ });
55
+ }
56
+ exports.verifyToken4reservation = verifyToken4reservation;
@@ -6,4 +6,5 @@ import { cancelPendingReservation, cancelReservation } from './reserve/cancelRes
6
6
  import { checkInRerservation } from './reserve/checkInReservation';
7
7
  import { confirmReservation } from './reserve/confirmReservation';
8
8
  import { useReservation } from './reserve/useReservation';
9
- export { maskUnderName, cancelPendingReservation, cancelReservation, checkInRerservation, confirmReservation, useReservation };
9
+ import { verifyToken4reservation } from './reserve/verifyToken4reservation';
10
+ export { maskUnderName, cancelPendingReservation, cancelReservation, checkInRerservation, confirmReservation, useReservation, verifyToken4reservation };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useReservation = exports.confirmReservation = exports.checkInRerservation = exports.cancelReservation = exports.cancelPendingReservation = exports.maskUnderName = void 0;
3
+ exports.verifyToken4reservation = exports.useReservation = exports.confirmReservation = exports.checkInRerservation = exports.cancelReservation = exports.cancelPendingReservation = exports.maskUnderName = void 0;
4
4
  /**
5
5
  * 予約サービス
6
6
  */
@@ -15,3 +15,5 @@ const confirmReservation_1 = require("./reserve/confirmReservation");
15
15
  Object.defineProperty(exports, "confirmReservation", { enumerable: true, get: function () { return confirmReservation_1.confirmReservation; } });
16
16
  const useReservation_1 = require("./reserve/useReservation");
17
17
  Object.defineProperty(exports, "useReservation", { enumerable: true, get: function () { return useReservation_1.useReservation; } });
18
+ const verifyToken4reservation_1 = require("./reserve/verifyToken4reservation");
19
+ Object.defineProperty(exports, "verifyToken4reservation", { enumerable: true, get: function () { return verifyToken4reservation_1.verifyToken4reservation; } });
@@ -0,0 +1,7 @@
1
+ import * as factory from '../../factory';
2
+ import { IConnectionSettings } from '../task';
3
+ export type IOperation<T> = (settings: IConnectionSettings) => Promise<T>;
4
+ /**
5
+ * タスク実行関数
6
+ */
7
+ export declare function call(data: factory.task.useReservation.IData): IOperation<void>;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.call = void 0;
13
+ const action_1 = require("../../repo/action");
14
+ const order_1 = require("../../repo/order");
15
+ const reservation_1 = require("../../repo/reservation");
16
+ const task_1 = require("../../repo/task");
17
+ const reserve_1 = require("../reserve");
18
+ /**
19
+ * タスク実行関数
20
+ */
21
+ function call(data) {
22
+ return (settings) => __awaiter(this, void 0, void 0, function* () {
23
+ var _a, _b;
24
+ yield (0, reserve_1.useReservation)(Object.assign(Object.assign({ project: data.project, agent: data.agent, object: data.object,
25
+ // タスク作成前に検証済なので検証不要
26
+ verifyToken: false }, (typeof ((_a = data.instrument) === null || _a === void 0 ? void 0 : _a.typeOf) === 'string') ? { instrument: data.instrument } : undefined), (typeof ((_b = data.location) === null || _b === void 0 ? void 0 : _b.typeOf) === 'string') ? { location: data.location } : undefined))({
27
+ action: new action_1.MongoRepository(settings.connection),
28
+ order: new order_1.MongoRepository(settings.connection),
29
+ reservation: new reservation_1.MongoRepository(settings.connection),
30
+ task: new task_1.MongoRepository(settings.connection)
31
+ });
32
+ });
33
+ }
34
+ exports.call = call;
package/package.json CHANGED
@@ -9,8 +9,8 @@
9
9
  }
10
10
  ],
11
11
  "dependencies": {
12
- "@chevre/factory": "4.313.0-alpha.15",
13
- "@cinerino/sdk": "3.157.0-alpha.2",
12
+ "@chevre/factory": "4.313.0-alpha.17",
13
+ "@cinerino/sdk": "3.157.0-alpha.3",
14
14
  "@motionpicture/coa-service": "9.2.0",
15
15
  "@motionpicture/gmo-service": "5.2.0",
16
16
  "@sendgrid/mail": "6.4.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.76"
120
+ "version": "21.2.0-alpha.78"
121
121
  }