@chevre/domain 21.29.0-alpha.15 → 21.29.0-alpha.17

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.
@@ -29,7 +29,7 @@ async function main() {
29
29
  orderDate: {
30
30
  $gte: moment()
31
31
  // tslint:disable-next-line:no-magic-numbers
32
- .add(-36, 'months')
32
+ .add(-13, 'months')
33
33
  .toDate()
34
34
  }
35
35
  },
@@ -0,0 +1,95 @@
1
+ // tslint:disable:no-console
2
+ import * as moment from 'moment';
3
+ import * as mongoose from 'mongoose';
4
+
5
+ import { chevre } from '../../../lib/index';
6
+
7
+ // const project = { id: String(process.env.PROJECT_ID) };
8
+
9
+ function createReservedTicketIdentifier(movieTicket: chevre.factory.action.trade.pay.IMovieTicket) {
10
+ return `${movieTicket.serviceOutput.reservationFor.id}:${movieTicket.serviceOutput.reservedTicket.ticketedSeat.seatSection}:${movieTicket.serviceOutput.reservedTicket.ticketedSeat.seatNumber}`;
11
+ }
12
+
13
+ async function main() {
14
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
15
+
16
+ const assetTransactionRepo = await chevre.repository.AssetTransaction.createInstance(mongoose.connection);
17
+
18
+ const cursor = assetTransactionRepo.getCursor(
19
+ {
20
+ typeOf: { $eq: chevre.factory.assetTransactionType.Pay },
21
+ startDate: {
22
+ $gte: moment()
23
+ // tslint:disable-next-line:no-magic-numbers
24
+ .add(-13, 'months')
25
+ .toDate()
26
+ }
27
+ // 'project.id': { $eq: project.id },
28
+ // transactionNumber: { $exists: true, $eq: '642463069394964' }
29
+ },
30
+ {
31
+ startDate: 1,
32
+ transactionNumber: 1,
33
+ project: 1,
34
+ object: 1
35
+ }
36
+ );
37
+ console.log('transactions found');
38
+
39
+ let i = 0;
40
+ let updateCount = 0;
41
+ await cursor.eachAsync(async (doc) => {
42
+ i += 1;
43
+ const payTransaction: Pick<
44
+ chevre.factory.assetTransaction.pay.ITransaction,
45
+ 'startDate' | 'transactionNumber' | 'project' | 'object'
46
+ > = doc.toObject();
47
+
48
+ const movieTicketsInTransaction = payTransaction.object.paymentMethod.movieTickets;
49
+ const alreadyMigrated = (!Array.isArray(movieTicketsInTransaction)) || movieTicketsInTransaction.every((movieTicket) => {
50
+ const reservedTicketIdentifierShouldBe = createReservedTicketIdentifier(movieTicket);
51
+
52
+ return typeof movieTicket.serviceOutput.reservedTicket.identifier === 'string'
53
+ && movieTicket.serviceOutput.reservedTicket.identifier.length > 0
54
+ && movieTicket.serviceOutput.reservedTicket.identifier === reservedTicketIdentifierShouldBe;
55
+ });
56
+
57
+ if (alreadyMigrated) {
58
+ console.log('already exist.', payTransaction.project.id, payTransaction.transactionNumber, payTransaction.startDate, i);
59
+ } else {
60
+ const newMovieTickets: chevre.factory.action.trade.pay.IMovieTicket[] = movieTicketsInTransaction.map((movieTicket) => {
61
+ return {
62
+ ...movieTicket,
63
+ serviceOutput: {
64
+ ...movieTicket.serviceOutput,
65
+ reservedTicket: {
66
+ ...movieTicket.serviceOutput.reservedTicket,
67
+ identifier: createReservedTicketIdentifier(movieTicket)
68
+ }
69
+ }
70
+ };
71
+ });
72
+ console.log(
73
+ 'updating...',
74
+ payTransaction.project.id, payTransaction.transactionNumber, payTransaction.startDate,
75
+ newMovieTickets, i);
76
+ // console.dir(newMovieTickets, { depth: null });
77
+ await assetTransactionRepo.fixReservedTicketIdentifier({
78
+ project: { id: payTransaction.project.id },
79
+ transactionNumber: payTransaction.transactionNumber,
80
+ object: {
81
+ paymentMethod: { movieTickets: newMovieTickets }
82
+ }
83
+ });
84
+ updateCount += 1;
85
+ console.log('updated.', payTransaction.project.id, payTransaction.transactionNumber, payTransaction.startDate, i);
86
+ }
87
+ });
88
+
89
+ console.log(i, 'transactions checked');
90
+ console.log(updateCount, 'transactions updated');
91
+ }
92
+
93
+ main()
94
+ .then()
95
+ .catch(console.error);
@@ -0,0 +1,38 @@
1
+ // tslint:disable:no-console
2
+ import * as mongoose from 'mongoose';
3
+
4
+ import { chevre } from '../../../lib/index';
5
+
6
+ const project = { id: String(process.env.PROJECT_ID) };
7
+
8
+ mongoose.Model.on('index', (...args) => {
9
+ console.error('******** index event emitted. ********\n', args);
10
+ });
11
+
12
+ async function main() {
13
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
14
+
15
+ const indexes = await mongoose.connection.db.collection('assetTransactions')
16
+ .indexes();
17
+ // console.log(indexes);
18
+ console.log(indexes.length, 'indexes found');
19
+
20
+ const assetTransactionRepo = await chevre.repository.AssetTransaction.createInstance(mongoose.connection);
21
+
22
+ const assetTransactions = await assetTransactionRepo.search<chevre.factory.assetTransactionType.Pay>(
23
+ {
24
+ limit: 10,
25
+ project: { id: { $eq: project.id } },
26
+ typeOf: chevre.factory.assetTransactionType.Pay,
27
+ object: { typeOf: { $eq: chevre.factory.service.paymentService.PaymentServiceType.MovieTicket } }
28
+ },
29
+ ['object'],
30
+ []
31
+ );
32
+ console.log('assetTransactions found', assetTransactions.map(({ object }) => object.typeOf));
33
+ console.log(assetTransactions.length, 'assetTransactions found');
34
+ }
35
+
36
+ main()
37
+ .then()
38
+ .catch(console.error);
@@ -24,6 +24,11 @@ async function main() {
24
24
  limit: 10,
25
25
  project: { id: { $eq: project.id } },
26
26
  acceptedOffers: {
27
+ itemOffered: {
28
+ reservedTicket: {
29
+ identifier: { $eq: 'bls2qevbb:Default:B-9' }
30
+ }
31
+ }
27
32
  // $size: 1
28
33
  // itemOffered: {
29
34
  // issuedThrough: { typeOf: { $eq: chevre.factory.product.ProductType.MembershipService } }
@@ -47,7 +52,7 @@ async function main() {
47
52
  customer: 1
48
53
  }
49
54
  );
50
- // console.log('orders found', orders);
55
+ console.log('orders found', orders);
51
56
  console.log(orders.length, 'orders found');
52
57
  }
53
58
 
@@ -197,6 +197,20 @@ export declare class MongoRepository {
197
197
  };
198
198
  };
199
199
  }): Promise<any>;
200
+ /**
201
+ * 互換性維持対応専用
202
+ */
203
+ fixReservedTicketIdentifier(params: {
204
+ project: {
205
+ id: string;
206
+ };
207
+ transactionNumber: string;
208
+ object: {
209
+ paymentMethod: {
210
+ movieTickets: factory.action.trade.pay.IMovieTicket[];
211
+ };
212
+ };
213
+ }): Promise<void>;
200
214
  findByIdAndDelete(params: {
201
215
  id: string;
202
216
  }): Promise<void>;
@@ -24,7 +24,7 @@ class MongoRepository {
24
24
  }
25
25
  // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
26
26
  static CREATE_MONGO_CONDITIONS(params) {
27
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25;
27
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27;
28
28
  const andConditions = [
29
29
  {
30
30
  typeOf: params.typeOf
@@ -112,16 +112,15 @@ class MongoRepository {
112
112
  case factory.assetTransactionType.Pay:
113
113
  const objectAccountIdEq = (_f = (_e = params.object) === null || _e === void 0 ? void 0 : _e.accountId) === null || _f === void 0 ? void 0 : _f.$eq;
114
114
  if (typeof objectAccountIdEq === 'string') {
115
- andConditions.push({
116
- 'object.accountId': {
117
- $exists: true,
118
- $eq: objectAccountIdEq
119
- }
120
- });
115
+ andConditions.push({ 'object.accountId': { $exists: true, $eq: objectAccountIdEq } });
116
+ }
117
+ const objectTypeOfEq = (_h = (_g = params.object) === null || _g === void 0 ? void 0 : _g.typeOf) === null || _h === void 0 ? void 0 : _h.$eq;
118
+ if (typeof objectTypeOfEq === 'string') {
119
+ andConditions.push({ 'object.typeOf': { $exists: true, $eq: objectTypeOfEq } });
121
120
  }
122
121
  break;
123
122
  case factory.assetTransactionType.Refund:
124
- const objectAccountIdEq4refund = (_h = (_g = params.object) === null || _g === void 0 ? void 0 : _g.accountId) === null || _h === void 0 ? void 0 : _h.$eq;
123
+ const objectAccountIdEq4refund = (_k = (_j = params.object) === null || _j === void 0 ? void 0 : _j.accountId) === null || _k === void 0 ? void 0 : _k.$eq;
125
124
  if (typeof objectAccountIdEq4refund === 'string') {
126
125
  andConditions.push({
127
126
  'object.accountId': {
@@ -130,13 +129,13 @@ class MongoRepository {
130
129
  }
131
130
  });
132
131
  }
133
- const objectPaymentMethodIdEq4refund = (_k = (_j = params.object) === null || _j === void 0 ? void 0 : _j.paymentMethodId) === null || _k === void 0 ? void 0 : _k.$eq;
132
+ const objectPaymentMethodIdEq4refund = (_m = (_l = params.object) === null || _l === void 0 ? void 0 : _l.paymentMethodId) === null || _m === void 0 ? void 0 : _m.$eq;
134
133
  if (typeof objectPaymentMethodIdEq4refund === 'string') {
135
134
  andConditions.push({
136
135
  'object.paymentMethodId': { $exists: true, $eq: objectPaymentMethodIdEq4refund }
137
136
  });
138
137
  }
139
- const objectPaymentMethodIdIn4refund = (_m = (_l = params.object) === null || _l === void 0 ? void 0 : _l.paymentMethodId) === null || _m === void 0 ? void 0 : _m.$in;
138
+ const objectPaymentMethodIdIn4refund = (_p = (_o = params.object) === null || _o === void 0 ? void 0 : _o.paymentMethodId) === null || _p === void 0 ? void 0 : _p.$in;
140
139
  if (Array.isArray(objectPaymentMethodIdIn4refund)) {
141
140
  andConditions.push({
142
141
  'object.paymentMethodId': { $exists: true, $in: objectPaymentMethodIdIn4refund }
@@ -144,7 +143,7 @@ class MongoRepository {
144
143
  }
145
144
  break;
146
145
  case factory.assetTransactionType.MoneyTransfer:
147
- const fromLocationIdentifierEq = (_q = (_p = (_o = params.object) === null || _o === void 0 ? void 0 : _o.fromLocation) === null || _p === void 0 ? void 0 : _p.identifier) === null || _q === void 0 ? void 0 : _q.$eq;
146
+ const fromLocationIdentifierEq = (_s = (_r = (_q = params.object) === null || _q === void 0 ? void 0 : _q.fromLocation) === null || _r === void 0 ? void 0 : _r.identifier) === null || _s === void 0 ? void 0 : _s.$eq;
148
147
  if (typeof fromLocationIdentifierEq === 'string') {
149
148
  andConditions.push({
150
149
  'object.fromLocation.identifier': {
@@ -153,7 +152,7 @@ class MongoRepository {
153
152
  }
154
153
  });
155
154
  }
156
- const toLocationIdentifierEq = (_t = (_s = (_r = params.object) === null || _r === void 0 ? void 0 : _r.toLocation) === null || _s === void 0 ? void 0 : _s.identifier) === null || _t === void 0 ? void 0 : _t.$eq;
155
+ const toLocationIdentifierEq = (_v = (_u = (_t = params.object) === null || _t === void 0 ? void 0 : _t.toLocation) === null || _u === void 0 ? void 0 : _u.identifier) === null || _v === void 0 ? void 0 : _v.$eq;
157
156
  if (typeof toLocationIdentifierEq === 'string') {
158
157
  andConditions.push({
159
158
  'object.toLocation.identifier': {
@@ -162,7 +161,7 @@ class MongoRepository {
162
161
  }
163
162
  });
164
163
  }
165
- const pendingTransactionIdentifierEq = (_w = (_v = (_u = params.object) === null || _u === void 0 ? void 0 : _u.pendingTransaction) === null || _v === void 0 ? void 0 : _v.identifier) === null || _w === void 0 ? void 0 : _w.$eq;
164
+ const pendingTransactionIdentifierEq = (_y = (_x = (_w = params.object) === null || _w === void 0 ? void 0 : _w.pendingTransaction) === null || _x === void 0 ? void 0 : _x.identifier) === null || _y === void 0 ? void 0 : _y.$eq;
166
165
  if (typeof pendingTransactionIdentifierEq === 'string') {
167
166
  andConditions.push({
168
167
  'object.pendingTransaction.identifier': {
@@ -175,11 +174,11 @@ class MongoRepository {
175
174
  case factory.assetTransactionType.CancelReservation:
176
175
  break;
177
176
  case factory.assetTransactionType.Reserve:
178
- const objectProviderIdEq = (_z = (_y = (_x = params.object) === null || _x === void 0 ? void 0 : _x.provider) === null || _y === void 0 ? void 0 : _y.id) === null || _z === void 0 ? void 0 : _z.$eq;
177
+ const objectProviderIdEq = (_1 = (_0 = (_z = params.object) === null || _z === void 0 ? void 0 : _z.provider) === null || _0 === void 0 ? void 0 : _0.id) === null || _1 === void 0 ? void 0 : _1.$eq;
179
178
  if (typeof objectProviderIdEq === 'string') {
180
179
  andConditions.push({ 'object.provider.id': { $exists: true, $eq: objectProviderIdEq } });
181
180
  }
182
- const objectReservationForIdEq = (_2 = (_1 = (_0 = params.object) === null || _0 === void 0 ? void 0 : _0.reservationFor) === null || _1 === void 0 ? void 0 : _1.id) === null || _2 === void 0 ? void 0 : _2.$eq;
181
+ const objectReservationForIdEq = (_4 = (_3 = (_2 = params.object) === null || _2 === void 0 ? void 0 : _2.reservationFor) === null || _3 === void 0 ? void 0 : _3.id) === null || _4 === void 0 ? void 0 : _4.$eq;
183
182
  if (typeof objectReservationForIdEq === 'string') {
184
183
  andConditions.push({
185
184
  'object.reservationFor.id': {
@@ -188,7 +187,7 @@ class MongoRepository {
188
187
  }
189
188
  });
190
189
  }
191
- const objectReservationNumberIn = (_4 = (_3 = params.object) === null || _3 === void 0 ? void 0 : _3.reservationNumber) === null || _4 === void 0 ? void 0 : _4.$in;
190
+ const objectReservationNumberIn = (_6 = (_5 = params.object) === null || _5 === void 0 ? void 0 : _5.reservationNumber) === null || _6 === void 0 ? void 0 : _6.$in;
192
191
  if (Array.isArray(objectReservationNumberIn)) {
193
192
  andConditions.push({
194
193
  'object.reservationNumber': {
@@ -197,7 +196,7 @@ class MongoRepository {
197
196
  }
198
197
  });
199
198
  }
200
- const objectReservationNumberEq = (_6 = (_5 = params.object) === null || _5 === void 0 ? void 0 : _5.reservationNumber) === null || _6 === void 0 ? void 0 : _6.$eq;
199
+ const objectReservationNumberEq = (_8 = (_7 = params.object) === null || _7 === void 0 ? void 0 : _7.reservationNumber) === null || _8 === void 0 ? void 0 : _8.$eq;
201
200
  if (typeof objectReservationNumberEq === 'string') {
202
201
  andConditions.push({
203
202
  'object.reservationNumber': {
@@ -206,7 +205,7 @@ class MongoRepository {
206
205
  }
207
206
  });
208
207
  }
209
- const objectSubReservationIdIn = (_9 = (_8 = (_7 = params.object) === null || _7 === void 0 ? void 0 : _7.reservations) === null || _8 === void 0 ? void 0 : _8.id) === null || _9 === void 0 ? void 0 : _9.$in;
208
+ const objectSubReservationIdIn = (_11 = (_10 = (_9 = params.object) === null || _9 === void 0 ? void 0 : _9.reservations) === null || _10 === void 0 ? void 0 : _10.id) === null || _11 === void 0 ? void 0 : _11.$in;
210
209
  if (Array.isArray(objectSubReservationIdIn)) {
211
210
  andConditions.push({
212
211
  'object.subReservation.id': {
@@ -241,7 +240,7 @@ class MongoRepository {
241
240
  }
242
241
  }
243
242
  }
244
- const objectUnderNameIdEq = (_12 = (_11 = (_10 = params.object) === null || _10 === void 0 ? void 0 : _10.underName) === null || _11 === void 0 ? void 0 : _11.id) === null || _12 === void 0 ? void 0 : _12.$eq;
243
+ const objectUnderNameIdEq = (_14 = (_13 = (_12 = params.object) === null || _12 === void 0 ? void 0 : _12.underName) === null || _13 === void 0 ? void 0 : _13.id) === null || _14 === void 0 ? void 0 : _14.$eq;
245
244
  if (typeof objectUnderNameIdEq === 'string') {
246
245
  andConditions.push({
247
246
  'object.underName.id': {
@@ -250,7 +249,7 @@ class MongoRepository {
250
249
  }
251
250
  });
252
251
  }
253
- const objectSubReservationSeatNumberEq = (_17 = (_16 = (_15 = (_14 = (_13 = params.object) === null || _13 === void 0 ? void 0 : _13.reservations) === null || _14 === void 0 ? void 0 : _14.reservedTicket) === null || _15 === void 0 ? void 0 : _15.ticketedSeat) === null || _16 === void 0 ? void 0 : _16.seatNumber) === null || _17 === void 0 ? void 0 : _17.$eq;
252
+ const objectSubReservationSeatNumberEq = (_19 = (_18 = (_17 = (_16 = (_15 = params.object) === null || _15 === void 0 ? void 0 : _15.reservations) === null || _16 === void 0 ? void 0 : _16.reservedTicket) === null || _17 === void 0 ? void 0 : _17.ticketedSeat) === null || _18 === void 0 ? void 0 : _18.seatNumber) === null || _19 === void 0 ? void 0 : _19.$eq;
254
253
  if (typeof objectSubReservationSeatNumberEq === 'string') {
255
254
  andConditions.push({
256
255
  'object.subReservation.reservedTicket.ticketedSeat.seatNumber': {
@@ -261,7 +260,7 @@ class MongoRepository {
261
260
  }
262
261
  break;
263
262
  case factory.assetTransactionType.RegisterService:
264
- const objectItemOfferedServiceOutputIdentifierEq = (_21 = (_20 = (_19 = (_18 = params.object) === null || _18 === void 0 ? void 0 : _18.itemOffered) === null || _19 === void 0 ? void 0 : _19.serviceOutput) === null || _20 === void 0 ? void 0 : _20.identifier) === null || _21 === void 0 ? void 0 : _21.$eq;
263
+ const objectItemOfferedServiceOutputIdentifierEq = (_23 = (_22 = (_21 = (_20 = params.object) === null || _20 === void 0 ? void 0 : _20.itemOffered) === null || _21 === void 0 ? void 0 : _21.serviceOutput) === null || _22 === void 0 ? void 0 : _22.identifier) === null || _23 === void 0 ? void 0 : _23.$eq;
265
264
  if (typeof objectItemOfferedServiceOutputIdentifierEq === 'string') {
266
265
  andConditions.push({
267
266
  'object.itemOffered.serviceOutput.identifier': {
@@ -270,7 +269,7 @@ class MongoRepository {
270
269
  }
271
270
  });
272
271
  }
273
- const objectItemOfferedServiceOutputIdentifierIn = (_25 = (_24 = (_23 = (_22 = params.object) === null || _22 === void 0 ? void 0 : _22.itemOffered) === null || _23 === void 0 ? void 0 : _23.serviceOutput) === null || _24 === void 0 ? void 0 : _24.identifier) === null || _25 === void 0 ? void 0 : _25.$in;
272
+ const objectItemOfferedServiceOutputIdentifierIn = (_27 = (_26 = (_25 = (_24 = params.object) === null || _24 === void 0 ? void 0 : _24.itemOffered) === null || _25 === void 0 ? void 0 : _25.serviceOutput) === null || _26 === void 0 ? void 0 : _26.identifier) === null || _27 === void 0 ? void 0 : _27.$in;
274
273
  if (Array.isArray(objectItemOfferedServiceOutputIdentifierIn)) {
275
274
  andConditions.push({
276
275
  'object.itemOffered.serviceOutput.identifier': {
@@ -724,37 +723,32 @@ class MongoRepository {
724
723
  });
725
724
  });
726
725
  }
727
- // public async migratePaymentMethodIdentifierMany() {
728
- // // return this.transactionModel.updateMany(
729
- // // {
730
- // // typeOf: { $eq: factory.assetTransactionType.Pay }
731
- // // // 'object.paymentMethod.identifier': { $exists: false }
732
- // // },
733
- // // { $set: { 'object.paymentMethod.identifier': '$object.paymentMethod.typeOf' } }
734
- // // )
735
- // // .exec();
736
- // return this.transactionModel.aggregate([
737
- // {
738
- // $match: {
739
- // typeOf: { $eq: factory.assetTransactionType.Pay }
740
- // }
741
- // },
742
- // {
743
- // $project: {
744
- // paymentMethodIdentifier: '$object.paymentMethod.typeOf'
745
- // }
746
- // },
747
- // {
748
- // $unset: ['object.paymentMethod.identifier']
749
- // }
750
- // // {
751
- // // $set: {
752
- // // 'object.paymentMethod.identifier': '$paymentMethodIdentifier'
753
- // // }
754
- // // }
755
- // ])
756
- // .exec();
757
- // }
726
+ /**
727
+ * 互換性維持対応専用
728
+ */
729
+ fixReservedTicketIdentifier(params) {
730
+ return __awaiter(this, void 0, void 0, function* () {
731
+ const doc = yield this.transactionModel.findOneAndUpdate({
732
+ transactionNumber: { $exists: true, $eq: params.transactionNumber },
733
+ 'project.id': { $eq: params.project.id },
734
+ typeOf: { $eq: factory.assetTransactionType.Pay }
735
+ }, {
736
+ $set: {
737
+ 'object.paymentMethod.movieTickets': params.object.paymentMethod.movieTickets
738
+ }
739
+ }, {
740
+ timestamps: false,
741
+ new: true,
742
+ projection: {
743
+ _id: 1
744
+ }
745
+ })
746
+ .exec();
747
+ if (doc === null) {
748
+ throw new factory.errors.NotFound(this.transactionModel.modelName);
749
+ }
750
+ });
751
+ }
758
752
  findByIdAndDelete(params) {
759
753
  return __awaiter(this, void 0, void 0, function* () {
760
754
  yield this.transactionModel.findByIdAndDelete(params.id)
@@ -763,8 +757,8 @@ class MongoRepository {
763
757
  }
764
758
  getCursor(conditions, projection) {
765
759
  return this.transactionModel.find(conditions, projection)
766
- .sort({ startDate: factory.sortType.Ascending })
767
- // .sort({ startDate: factory.sortType.Descending })
760
+ // .sort({ startDate: factory.sortType.Ascending })
761
+ .sort({ startDate: factory.sortType.Descending })
768
762
  .cursor();
769
763
  }
770
764
  aggregateAssetTransaction(params) {
@@ -1,5 +1,5 @@
1
1
  import { IndexDefinition, IndexOptions, Schema } from 'mongoose';
2
2
  declare const modelName = "AssetTransaction";
3
- declare function createSchema(): Schema;
4
3
  declare const indexes: [d: IndexDefinition, o: IndexOptions][];
4
+ declare function createSchema(): Schema;
5
5
  export { modelName, indexes, createSchema };
@@ -53,17 +53,6 @@ const schemaOptions = {
53
53
  versionKey: false
54
54
  }
55
55
  };
56
- /**
57
- * 資産取引スキーマ
58
- */
59
- let schema;
60
- function createSchema() {
61
- if (schema === undefined) {
62
- schema = new mongoose_1.Schema(schemaDefinition, schemaOptions);
63
- }
64
- return schema;
65
- }
66
- exports.createSchema = createSchema;
67
56
  const indexes = [
68
57
  [
69
58
  { createdAt: 1 },
@@ -290,6 +279,15 @@ const indexes = [
290
279
  }
291
280
  }
292
281
  ],
282
+ [
283
+ { 'object.typeOf': 1, startDate: -1 },
284
+ {
285
+ name: 'searchByObjectTypeOf',
286
+ partialFilterExpression: {
287
+ 'object.typeOf': { $exists: true }
288
+ }
289
+ }
290
+ ],
293
291
  [
294
292
  { typeOf: 1, status: 1, tasksExportationStatus: 1 },
295
293
  { name: 'startExportTasks' }
@@ -304,3 +302,19 @@ const indexes = [
304
302
  ]
305
303
  ];
306
304
  exports.indexes = indexes;
305
+ /**
306
+ * 資産取引スキーマ
307
+ */
308
+ let schema;
309
+ function createSchema() {
310
+ if (schema === undefined) {
311
+ schema = new mongoose_1.Schema(schemaDefinition, schemaOptions);
312
+ if (settings_1.MONGO_AUTO_INDEX) {
313
+ indexes.forEach((indexParams) => {
314
+ schema === null || schema === void 0 ? void 0 : schema.index(...indexParams);
315
+ });
316
+ }
317
+ }
318
+ return schema;
319
+ }
320
+ exports.createSchema = createSchema;
@@ -434,6 +434,15 @@ const indexes = [
434
434
  }
435
435
  }
436
436
  ],
437
+ [
438
+ { 'acceptedOffers.itemOffered.reservedTicket.identifier': 1, orderDate: -1 },
439
+ {
440
+ name: 'searchByReservedTicketIdentifier',
441
+ partialFilterExpression: {
442
+ 'acceptedOffers.itemOffered.reservedTicket.identifier': { $exists: true }
443
+ }
444
+ }
445
+ ],
437
446
  [
438
447
  { 'acceptedOffers.serialNumber': 1, orderDate: -1 },
439
448
  {
@@ -23,7 +23,7 @@ class MongoRepository {
23
23
  }
24
24
  // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
25
25
  static CREATE_MONGO_CONDITIONS(params) {
26
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22;
26
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26;
27
27
  const andConditions = [
28
28
  { typeOf: { $eq: factory.order.OrderType.Order } }
29
29
  ];
@@ -412,6 +412,15 @@ class MongoRepository {
412
412
  }
413
413
  });
414
414
  }
415
+ const itemOfferedReservedTicketIdentifierEq = (_18 = (_17 = (_16 = (_15 = params.acceptedOffers) === null || _15 === void 0 ? void 0 : _15.itemOffered) === null || _16 === void 0 ? void 0 : _16.reservedTicket) === null || _17 === void 0 ? void 0 : _17.identifier) === null || _18 === void 0 ? void 0 : _18.$eq;
416
+ if (typeof itemOfferedReservedTicketIdentifierEq === 'string') {
417
+ andConditions.push({
418
+ 'acceptedOffers.itemOffered.reservedTicket.identifier': {
419
+ $exists: true,
420
+ $eq: itemOfferedReservedTicketIdentifierEq
421
+ }
422
+ });
423
+ }
415
424
  // tslint:disable-next-line:no-single-line-block-comment
416
425
  /* istanbul ignore else */
417
426
  if (params.acceptedOffers !== undefined) {
@@ -565,11 +574,11 @@ class MongoRepository {
565
574
  }
566
575
  }
567
576
  }
568
- const paymentMethodIdentifierIn = (_17 = (_16 = (_15 = params.paymentMethods) === null || _15 === void 0 ? void 0 : _15.paymentMethod) === null || _16 === void 0 ? void 0 : _16.identifier) === null || _17 === void 0 ? void 0 : _17.$in;
577
+ const paymentMethodIdentifierIn = (_21 = (_20 = (_19 = params.paymentMethods) === null || _19 === void 0 ? void 0 : _19.paymentMethod) === null || _20 === void 0 ? void 0 : _20.identifier) === null || _21 === void 0 ? void 0 : _21.$in;
569
578
  if (Array.isArray(paymentMethodIdentifierIn)) {
570
579
  andConditions.push({ 'paymentMethods.paymentMethod.identifier': { $exists: true, $in: paymentMethodIdentifierIn } });
571
580
  }
572
- const paymentMethodsTypeOfIn = (_18 = params.paymentMethods) === null || _18 === void 0 ? void 0 : _18.typeOfs;
581
+ const paymentMethodsTypeOfIn = (_22 = params.paymentMethods) === null || _22 === void 0 ? void 0 : _22.typeOfs;
573
582
  if (Array.isArray(paymentMethodsTypeOfIn)) {
574
583
  // paymentMethod.identifierで検索(2023-11-15~)
575
584
  // andConditions.push({ 'paymentMethods.typeOf': { $exists: true, $in: paymentMethodsTypeOfIn } });
@@ -599,7 +608,7 @@ class MongoRepository {
599
608
  });
600
609
  }
601
610
  }
602
- const paymentMethodAdditionalPropertyAll = (_20 = (_19 = params.paymentMethods) === null || _19 === void 0 ? void 0 : _19.additionalProperty) === null || _20 === void 0 ? void 0 : _20.$all;
611
+ const paymentMethodAdditionalPropertyAll = (_24 = (_23 = params.paymentMethods) === null || _23 === void 0 ? void 0 : _23.additionalProperty) === null || _24 === void 0 ? void 0 : _24.$all;
603
612
  if (Array.isArray(paymentMethodAdditionalPropertyAll)) {
604
613
  andConditions.push({
605
614
  'paymentMethods.additionalProperty': {
@@ -608,7 +617,7 @@ class MongoRepository {
608
617
  }
609
618
  });
610
619
  }
611
- const paymentMethodAdditionalPropertyIn = (_22 = (_21 = params.paymentMethods) === null || _21 === void 0 ? void 0 : _21.additionalProperty) === null || _22 === void 0 ? void 0 : _22.$in;
620
+ const paymentMethodAdditionalPropertyIn = (_26 = (_25 = params.paymentMethods) === null || _25 === void 0 ? void 0 : _25.additionalProperty) === null || _26 === void 0 ? void 0 : _26.$in;
612
621
  if (Array.isArray(paymentMethodAdditionalPropertyIn)) {
613
622
  andConditions.push({
614
623
  'paymentMethods.additionalProperty': {
@@ -109,7 +109,7 @@ class MongoRepository {
109
109
  let doc;
110
110
  if (typeof params.id === 'string') {
111
111
  // 上書き禁止属性を除外
112
- const _a = params.$set, { id, project, typeOf, offers } = _a, setFields = __rest(_a, ["id", "project", "typeOf", "offers"]);
112
+ const _a = params.$set, { id, project, typeOf } = _a, setFields = __rest(_a, ["id", "project", "typeOf"]);
113
113
  doc = yield this.productModelModel.findOneAndUpdate({ _id: { $eq: params.id } }, {
114
114
  $set: setFields
115
115
  // $unset: params.$unset
@@ -1,4 +1,8 @@
1
1
  import * as factory from '../../../../factory';
2
+ /**
3
+ * PayAction.object.serviceOutputを作成する
4
+ * 決済カード決済の場合のみ、対象予約情報をserviceOutputに持つ決済カード情報として存在する
5
+ */
2
6
  declare function createPayObjectServiceOutput(params: {
3
7
  transaction: factory.assetTransaction.ITransaction<factory.assetTransactionType.Pay>;
4
8
  order: {
@@ -2,6 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createPayObjectServiceOutput = void 0;
4
4
  const factory = require("../../../../factory");
5
+ const settings_1 = require("../../../../settings");
6
+ /**
7
+ * PayAction.object.serviceOutputを作成する
8
+ * 決済カード決済の場合のみ、対象予約情報をserviceOutputに持つ決済カード情報として存在する
9
+ */
5
10
  function createPayObjectServiceOutput(params) {
6
11
  const transaction = params.transaction;
7
12
  const paymentMethod = transaction.object.paymentMethod;
@@ -19,7 +24,7 @@ function createPayObjectServiceOutput(params) {
19
24
  paymentServiceOutput = movieTickets.map((movieTicket) => {
20
25
  var _a;
21
26
  const amount = movieTicket2amount(transaction, movieTicket);
22
- const reservation4invoice = movieTicket2reservation4invoice(movieTicket, order, String(paymentMethodType));
27
+ const reservation4invoice = movieTicket2reservation4invoice(movieTicket, order, String(paymentMethodType), transaction.transactionNumber);
23
28
  return Object.assign(Object.assign({ identifier: movieTicket.identifier }, (typeof (amount === null || amount === void 0 ? void 0 : amount.value) === 'number') ? { amount } : undefined), (typeof ((_a = reservation4invoice.priceSpecification) === null || _a === void 0 ? void 0 : _a.typeOf) === 'string')
24
29
  ? { serviceOutput: reservation4invoice }
25
30
  : undefined);
@@ -88,11 +93,11 @@ function reservationPriceComponent2invoicePriceComponent(component) {
88
93
  throw new factory.errors.NotImplemented(`unexpected priceComponent: ${component.typeOf}`);
89
94
  }
90
95
  }
91
- function movieTicket2reservation4invoice(movieTicket, order, paymentMethodType) {
96
+ /**
97
+ * 決済カードの対象予約情報を作成する
98
+ */
99
+ function movieTicket2reservation4invoice(movieTicket, order, paymentMethodType, payTransactionNumber) {
92
100
  var _a;
93
- let ticketToken;
94
- let reservationNumber = '';
95
- let priceComponents4invoice = [];
96
101
  // Orderから対象予約を取得
97
102
  const reservationOffer = order.acceptedOffersMovieTicketUsed.find(({ itemOffered, priceSpecification }) => {
98
103
  var _a, _b;
@@ -101,9 +106,6 @@ function movieTicket2reservation4invoice(movieTicket, order, paymentMethodType)
101
106
  if ((priceSpecification === null || priceSpecification === void 0 ? void 0 : priceSpecification.typeOf) === factory.priceSpecificationType.CompoundPriceSpecification) {
102
107
  // 適用購入管理番号が一致、かつ、決済方法区分が一致、の単価仕様を検索
103
108
  mvtkUnitPriceSpec = (_a = priceSpecification === null || priceSpecification === void 0 ? void 0 : priceSpecification.priceComponent) === null || _a === void 0 ? void 0 : _a.find((p) => {
104
- // if (p.typeOf !== factory.priceSpecificationType.UnitPriceSpecification) {
105
- // return false;
106
- // }
107
109
  return p.typeOf === factory.priceSpecificationType.UnitPriceSpecification
108
110
  && Array.isArray(p.appliesToMovieTicket)
109
111
  && p.appliesToMovieTicket.some((appliesToMovieTicket) => {
@@ -112,32 +114,38 @@ function movieTicket2reservation4invoice(movieTicket, order, paymentMethodType)
112
114
  });
113
115
  });
114
116
  }
115
- return (itemOffered.typeOf === factory.reservationType.EventReservation
116
- || itemOffered.typeOf === factory.reservationType.BusReservation)
117
- && mvtkUnitPriceSpec !== undefined
117
+ let isMovieTicketServiceOutput = mvtkUnitPriceSpec !== undefined
118
118
  && itemOffered.reservationFor.id === movieTicket.serviceOutput.reservationFor.id
119
119
  && ((_b = itemOffered.reservedTicket.ticketedSeat) === null || _b === void 0 ? void 0 : _b.seatNumber) === movieTicket.serviceOutput.reservedTicket.ticketedSeat.seatNumber
120
120
  && itemOffered.reservedTicket.ticketedSeat.seatSection === movieTicket.serviceOutput.reservedTicket.ticketedSeat.seatSection;
121
- });
122
- if (reservationOffer !== undefined) {
123
- // if (reservationOffer.itemOffered.typeOf !== factory.reservationType.EventReservation
124
- // && reservationOffer.itemOffered.typeOf !== factory.reservationType.BusReservation) {
125
- // throw new factory.errors.NotImplemented(`itemOffered.typeOf: ${reservationOffer.itemOffered.typeOf} not implemented`);
126
- // }
127
- const ticketTokenByReservationOffer = reservationOffer.itemOffered.reservedTicket.ticketToken;
128
- if (typeof ticketTokenByReservationOffer === 'string' && ticketTokenByReservationOffer.length > 0) {
129
- ticketToken = ticketTokenByReservationOffer;
130
- }
131
- reservationNumber = reservationOffer.itemOffered.reservationNumber;
132
- const priceComponent = (_a = reservationOffer.priceSpecification) === null || _a === void 0 ? void 0 : _a.priceComponent;
133
- if (Array.isArray(priceComponent)) {
134
- priceComponents4invoice = priceComponent.map(reservationPriceComponent2invoicePriceComponent);
121
+ // チケット識別子で照合(2024-04-17~)
122
+ if (settings_1.USE_VALIDATE_MOVIE_TICKET_BY_TICKET_IDENTIFIER) {
123
+ isMovieTicketServiceOutput = isMovieTicketServiceOutput
124
+ && typeof itemOffered.reservedTicket.identifier === 'string'
125
+ && itemOffered.reservedTicket.identifier === movieTicket.serviceOutput.reservedTicket.identifier;
135
126
  }
127
+ return isMovieTicketServiceOutput;
128
+ });
129
+ // 対象予約は存在必須(2024-04-17~)
130
+ if (reservationOffer === undefined) {
131
+ throw new factory.errors.NotFound(factory.offerType.Offer, `acceptedOffer for the movieTicket not found at movieTicket2reservation4invoice. [movieTicket.identifier:${movieTicket.identifier} movieTicket.serviceType:${movieTicket.serviceType} paymentMethodType:${paymentMethodType} payTransactionNumber:${payTransactionNumber}]`);
132
+ }
133
+ /**
134
+ * COAの場合のみ予約のチケットトークンが存在
135
+ */
136
+ let ticketToken;
137
+ const ticketTokenByReservationOffer = reservationOffer.itemOffered.reservedTicket.ticketToken;
138
+ if (typeof ticketTokenByReservationOffer === 'string' && ticketTokenByReservationOffer.length > 0) {
139
+ ticketToken = ticketTokenByReservationOffer;
140
+ }
141
+ const reservationNumber = reservationOffer.itemOffered.reservationNumber;
142
+ let priceComponents4invoice = [];
143
+ const priceComponent = (_a = reservationOffer.priceSpecification) === null || _a === void 0 ? void 0 : _a.priceComponent;
144
+ if (Array.isArray(priceComponent)) {
145
+ priceComponents4invoice = priceComponent.map(reservationPriceComponent2invoicePriceComponent);
136
146
  }
137
147
  return Object.assign({ priceSpecification: {
138
148
  typeOf: factory.priceSpecificationType.CompoundPriceSpecification,
139
149
  priceComponent: priceComponents4invoice
140
- },
141
- // add reservationNumber(2023-03-20~)
142
- reservationNumber }, (typeof ticketToken === 'string') ? { reservedTicket: { ticketToken } } : undefined);
150
+ }, reservationNumber }, (typeof ticketToken === 'string') ? { reservedTicket: { ticketToken } } : undefined);
143
151
  }
package/package.json CHANGED
@@ -10,7 +10,7 @@
10
10
  ],
11
11
  "dependencies": {
12
12
  "@aws-sdk/credential-providers": "3.433.0",
13
- "@chevre/factory": "4.367.0-alpha.7",
13
+ "@chevre/factory": "4.367.0-alpha.9",
14
14
  "@cinerino/sdk": "5.17.1",
15
15
  "@motionpicture/coa-service": "9.4.0",
16
16
  "@motionpicture/gmo-service": "5.3.0",
@@ -110,5 +110,5 @@
110
110
  "postversion": "git push origin --tags",
111
111
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
112
112
  },
113
- "version": "21.29.0-alpha.15"
113
+ "version": "21.29.0-alpha.17"
114
114
  }