@chevre/domain 24.0.0-alpha.46 → 24.0.0-alpha.47

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.
@@ -63,7 +63,7 @@ function validateStartParams(params) {
63
63
  if (reserveTransaction === undefined) {
64
64
  // 予約存在確認
65
65
  if (typeof params.object.reservation?.id === 'string') {
66
- const reservation = await repos.reservation.projectFieldsById({
66
+ const reservation = await repos.reservation.findReservationById({
67
67
  id: params.object.reservation.id,
68
68
  inclusion: [
69
69
  'issuedThrough', 'typeOf', 'reservationNumber', 'reservationFor.id', 'reservationFor.typeOf', 'provider', 'reservationStatus'
@@ -244,7 +244,7 @@ function cancelReservation(actionAttributesList) {
244
244
  });
245
245
  }
246
246
  else {
247
- const reservation = await repos.reservation.projectFieldsById({
247
+ const reservation = await repos.reservation.findReservationById({
248
248
  id: actionAttributes.object.id,
249
249
  inclusion: ['reservationNumber', 'reservationStatus', 'project', 'reservedTicket', 'subReservation', 'reservationFor']
250
250
  });
@@ -332,7 +332,7 @@ function cancelReservation(actionAttributesList) {
332
332
  }
333
333
  }
334
334
  else {
335
- const canceledReservation = await repos.reservation.projectFieldsById({
335
+ const canceledReservation = await repos.reservation.findReservationById({
336
336
  id: actionAttributes.object.id,
337
337
  inclusion: ['project', 'typeOf', 'modifiedTime', 'reservationNumber']
338
338
  });
@@ -68,10 +68,10 @@ function confirmReservation(params) {
68
68
  const priceByTransaction = subReservationByTransaction?.price;
69
69
  const underNameByTransaction = reserveTransaction.object.underName;
70
70
  const ticketTypeByTransaction = subReservationByTransaction?.reservedTicket.ticketType;
71
- console.log('creating confirmedReservation...', rawReservation, priceByTransaction, underNameByTransaction, ticketTypeByTransaction);
71
+ // console.log('creating confirmedReservation...', rawReservation, priceByTransaction, underNameByTransaction, ticketTypeByTransaction);
72
72
  return {
73
73
  ...rawReservation,
74
- ...(priceByTransaction) ? { price: priceByTransaction } : undefined,
74
+ ...(priceByTransaction !== undefined) ? { price: priceByTransaction } : undefined,
75
75
  ...(underNameByTransaction !== undefined) ? { underName: underNameByTransaction } : undefined,
76
76
  reservedTicket: {
77
77
  ...rawReservation.reservedTicket,
@@ -82,7 +82,7 @@ function findByCode(params) {
82
82
  default:
83
83
  throw new factory.errors.NotImplemented(`authorization object typeOf: ${authorization.object.typeOf} not implemented`);
84
84
  }
85
- const reservationFromRepo = await repos.reservation.projectFieldsById({
85
+ const reservationFromRepo = await repos.reservation.findReservationById({
86
86
  id: reservationId,
87
87
  inclusion: [
88
88
  'additionalTicketText', 'checkedIn', 'reservationStatus',
@@ -0,0 +1,19 @@
1
+ import * as factory from '../../factory';
2
+ import type { ReserveTransactionRepo } from '../../repo/assetTransaction/reserve';
3
+ import type { IDeprecatedField, IKeyOfProjection, ReservationRepo } from '../../repo/reservation';
4
+ type IReservationAsFindResult = Omit<factory.reservation.eventReservation.IReservation, 'price'> & {
5
+ price?: factory.reservation.eventReservation.IPrice;
6
+ };
7
+ /**
8
+ * 予約を検索する
9
+ */
10
+ export declare function findReservations(params: factory.reservation.eventReservation.ISearchConditions, options: {
11
+ inclusion: Partial<Record<IKeyOfProjection | IDeprecatedField, 1>>;
12
+ useReserveTransaction: boolean;
13
+ }): (repos: {
14
+ assetTransaction: {
15
+ reserve: ReserveTransactionRepo;
16
+ };
17
+ reservation: ReservationRepo;
18
+ }) => Promise<IReservationAsFindResult[]>;
19
+ export {};
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.findReservations = findReservations;
7
+ const debug_1 = __importDefault(require("debug"));
8
+ const util_1 = require("util");
9
+ const debug = (0, debug_1.default)('chevre-domain:service:reserve:findReservations');
10
+ /**
11
+ * 予約を検索する
12
+ */
13
+ function findReservations(params, options) {
14
+ return async (repos) => {
15
+ const { inclusion, useReserveTransaction } = options;
16
+ let reservations = await repos.reservation.findReservations(params, inclusion);
17
+ if (useReserveTransaction) {
18
+ if (reservations.length > 0) {
19
+ const requirePrice = Object.keys(inclusion).includes('price');
20
+ const requireUnderName = Object.keys(inclusion).includes('underName');
21
+ const requireReservedTicket = Object.keys(inclusion).includes('reservedTicket');
22
+ const reservationIds = reservations.map(({ id }) => id);
23
+ const subReservations = await repos.assetTransaction.reserve.findSubReservationsById({
24
+ ids: reservationIds
25
+ });
26
+ // 予約取引から参照した予約数と同じはず
27
+ debug('useReserveTransaction: true. reservations.length === subReservations.length?', reservations.length === subReservations.length);
28
+ reservations = reservations.map((reservation) => {
29
+ const subReservationByTransaction = subReservations.find((s) => s.id === reservation.id);
30
+ const priceByTransaction = subReservationByTransaction?.price;
31
+ const underNameByTransaction = subReservationByTransaction?.underName;
32
+ const ticketTypeByTransaction = subReservationByTransaction?.reservedTicket?.ticketType;
33
+ // 予約取引から参照した属性と全く等しいはず
34
+ if (requirePrice) {
35
+ const priceMatched = (0, util_1.isDeepStrictEqual)(reservation.price, priceByTransaction);
36
+ debug('requirePrice. priceMatched?', priceMatched);
37
+ if (!priceMatched) {
38
+ console.error('priceMatched: false!!!', reservation.id);
39
+ }
40
+ }
41
+ if (requireUnderName) {
42
+ const underNameMatched = (0, util_1.isDeepStrictEqual)(reservation.underName, underNameByTransaction);
43
+ debug('requireUnderName. underNameMatched?', underNameMatched);
44
+ if (!underNameMatched) {
45
+ console.error('underNameMatched: false!!!', reservation.id);
46
+ }
47
+ }
48
+ if (requireReservedTicket) {
49
+ const ticketTypeMatched = (0, util_1.isDeepStrictEqual)(reservation.reservedTicket.ticketType, ticketTypeByTransaction);
50
+ debug('requireReservedTicket. ticketTypeMatched?', ticketTypeMatched);
51
+ if (!ticketTypeMatched) {
52
+ console.error('ticketTypeMatched: false!!!', reservation.id);
53
+ }
54
+ }
55
+ return {
56
+ ...reservation, // 予約ドキュメントはそのまま返す
57
+ ...(requirePrice && priceByTransaction !== undefined) ? { price: priceByTransaction } : undefined, // priceがあれば上書き
58
+ ...(requireUnderName && underNameByTransaction !== undefined) ? { underName: underNameByTransaction } : undefined, // underNameがあれば上書き
59
+ ...(requireReservedTicket && ticketTypeByTransaction !== undefined) // ticketTypeがあれば上書き
60
+ ? {
61
+ reservedTicket: {
62
+ ...reservation.reservedTicket, // 予約ドキュメントのreservedTicketはそのまま返す
63
+ ticketType: ticketTypeByTransaction
64
+ }
65
+ }
66
+ : undefined
67
+ };
68
+ });
69
+ }
70
+ ;
71
+ }
72
+ return reservations;
73
+ };
74
+ }
@@ -55,7 +55,7 @@ function useReservation(params) {
55
55
  // confirmReservationが間に合わない可能性を考慮する(2023-06-01~)
56
56
  await reserveIfNotYet({ object: params.object })(repos);
57
57
  // 予約検索
58
- const reservation = await repos.reservation.projectFieldsById({
58
+ const reservation = await repos.reservation.findReservationById({
59
59
  id: reservationId,
60
60
  inclusion: ['issuedThrough', 'project', 'reservationFor', 'reservationNumber', 'reservedTicket', 'typeOf']
61
61
  });
@@ -5,6 +5,7 @@ import { cancelPendingReservation, cancelReservation } from './reserve/cancelRes
5
5
  import { checkInReservation } from './reserve/checkInReservation';
6
6
  import { confirmReservation } from './reserve/confirmReservation';
7
7
  import { findByCode } from './reserve/findByCode';
8
+ import { findReservations } from './reserve/findReservations';
8
9
  import { searchByOrder } from './reserve/searchByOrder';
9
10
  import { verifyToken4reservation } from './reserve/verifyToken4reservation';
10
- export { cancelPendingReservation, cancelReservation, checkInReservation, confirmReservation, findByCode, searchByOrder, verifyToken4reservation };
11
+ export { cancelPendingReservation, cancelReservation, checkInReservation, confirmReservation, findByCode, findReservations, searchByOrder, verifyToken4reservation };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.verifyToken4reservation = exports.searchByOrder = exports.findByCode = exports.confirmReservation = exports.checkInReservation = exports.cancelReservation = exports.cancelPendingReservation = void 0;
3
+ exports.verifyToken4reservation = exports.searchByOrder = exports.findReservations = exports.findByCode = exports.confirmReservation = exports.checkInReservation = exports.cancelReservation = exports.cancelPendingReservation = void 0;
4
4
  /**
5
5
  * 予約サービス
6
6
  */
@@ -13,6 +13,8 @@ const confirmReservation_1 = require("./reserve/confirmReservation");
13
13
  Object.defineProperty(exports, "confirmReservation", { enumerable: true, get: function () { return confirmReservation_1.confirmReservation; } });
14
14
  const findByCode_1 = require("./reserve/findByCode");
15
15
  Object.defineProperty(exports, "findByCode", { enumerable: true, get: function () { return findByCode_1.findByCode; } });
16
+ const findReservations_1 = require("./reserve/findReservations");
17
+ Object.defineProperty(exports, "findReservations", { enumerable: true, get: function () { return findReservations_1.findReservations; } });
16
18
  const searchByOrder_1 = require("./reserve/searchByOrder");
17
19
  Object.defineProperty(exports, "searchByOrder", { enumerable: true, get: function () { return searchByOrder_1.searchByOrder; } });
18
20
  const verifyToken4reservation_1 = require("./reserve/verifyToken4reservation");
package/package.json CHANGED
@@ -99,5 +99,5 @@
99
99
  "postversion": "git push origin --tags",
100
100
  "prepublishOnly": "npm run clean && npm run build"
101
101
  },
102
- "version": "24.0.0-alpha.46"
102
+ "version": "24.0.0-alpha.47"
103
103
  }