@chevre/domain 20.2.0-alpha.42 → 20.2.0-alpha.45

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.
@@ -0,0 +1,20 @@
1
+ // tslint:disable:no-console
2
+ import * as mongoose from 'mongoose';
3
+
4
+ import { chevre } from '../../../lib/index';
5
+
6
+ async function main() {
7
+ await mongoose.connect(<string>process.env.MONGOLAB_URI);
8
+
9
+ const orderRepo = new chevre.repository.Order(mongoose.connection);
10
+
11
+ const order = await orderRepo.findByOrderNumberAndReservationId({
12
+ orderNumber: 'CIN9-4783801-1618274',
13
+ reservationId: '139787058570943-0'
14
+ });
15
+ console.log('order found', order);
16
+ }
17
+
18
+ main()
19
+ .then()
20
+ .catch(console.error);
@@ -1,7 +1,7 @@
1
1
  import { Connection } from 'mongoose';
2
2
  import * as factory from '../factory';
3
3
  import { modelName } from './mongoose/model/authorization';
4
- export declare type IData = any;
4
+ export declare type IObject = factory.authorization.IObject;
5
5
  export declare type ICode = string;
6
6
  export { modelName };
7
7
  /**
@@ -19,7 +19,7 @@ export declare class MongoRepository {
19
19
  id: string;
20
20
  typeOf: factory.organizationType.Project;
21
21
  };
22
- data: IData;
22
+ object: IObject;
23
23
  validFrom: Date;
24
24
  expiresInSeconds: number;
25
25
  }[]): Promise<factory.authorization.IAuthorization[]>;
@@ -32,22 +32,9 @@ export declare class MongoRepository {
32
32
  typeOf: factory.organizationType.Project;
33
33
  };
34
34
  code: ICode;
35
- }): Promise<IData>;
35
+ }): Promise<IObject>;
36
36
  count(params: factory.authorization.ISearchConditions): Promise<number>;
37
37
  search(params: factory.authorization.ISearchConditions): Promise<factory.authorization.IAuthorization[]>;
38
- /**
39
- * コードを保管する
40
- */
41
- save(params: {
42
- project: {
43
- id: string;
44
- typeOf: factory.organizationType.Project;
45
- };
46
- code: ICode;
47
- data: IData;
48
- validFrom: Date;
49
- expiresInSeconds: number;
50
- }[]): Promise<factory.authorization.IAuthorization[]>;
51
38
  deleteByCode(params: {
52
39
  code: string;
53
40
  }): Promise<{
@@ -55,4 +42,14 @@ export declare class MongoRepository {
55
42
  ok?: number;
56
43
  deletedCount?: number;
57
44
  } | null>;
45
+ /**
46
+ * 有効期限を一定期間過ぎた承認を削除する
47
+ */
48
+ deleteValidUntilPassedCertainPeriod(params: {
49
+ $lt: Date;
50
+ }): Promise<void>;
51
+ /**
52
+ * コードを保管する
53
+ */
54
+ private save;
58
55
  }
@@ -134,7 +134,7 @@ class MongoRepository {
134
134
  return {
135
135
  project: p.project,
136
136
  code: code,
137
- data: p.data,
137
+ object: p.object,
138
138
  validFrom: p.validFrom,
139
139
  expiresInSeconds: p.expiresInSeconds
140
140
  };
@@ -204,6 +204,37 @@ class MongoRepository {
204
204
  .then((docs) => docs.map((doc) => doc.toObject()));
205
205
  });
206
206
  }
207
+ deleteByCode(params) {
208
+ return __awaiter(this, void 0, void 0, function* () {
209
+ return this.authorizationModel.deleteOne({
210
+ code: { $exists: true, $eq: params.code }
211
+ })
212
+ .exec()
213
+ .then((result) => {
214
+ return {
215
+ n: result === null || result === void 0 ? void 0 : result.n,
216
+ // opTime: result.opTime,
217
+ ok: result === null || result === void 0 ? void 0 : result.ok,
218
+ // operationTime,
219
+ deletedCount: result === null || result === void 0 ? void 0 : result.deletedCount
220
+ };
221
+ });
222
+ });
223
+ }
224
+ /**
225
+ * 有効期限を一定期間過ぎた承認を削除する
226
+ */
227
+ deleteValidUntilPassedCertainPeriod(params) {
228
+ return __awaiter(this, void 0, void 0, function* () {
229
+ yield this.authorizationModel.deleteMany({
230
+ validUntil: {
231
+ $exists: true,
232
+ $lt: params.$lt
233
+ }
234
+ })
235
+ .exec();
236
+ });
237
+ }
207
238
  /**
208
239
  * コードを保管する
209
240
  */
@@ -218,7 +249,7 @@ class MongoRepository {
218
249
  project: p.project,
219
250
  typeOf: 'Authorization',
220
251
  code: p.code,
221
- object: p.data,
252
+ object: p.object,
222
253
  validFrom: p.validFrom,
223
254
  validUntil: validUntil
224
255
  };
@@ -234,22 +265,5 @@ class MongoRepository {
234
265
  }
235
266
  });
236
267
  }
237
- deleteByCode(params) {
238
- return __awaiter(this, void 0, void 0, function* () {
239
- return this.authorizationModel.deleteOne({
240
- code: { $exists: true, $eq: params.code }
241
- })
242
- .exec()
243
- .then((result) => {
244
- return {
245
- n: result === null || result === void 0 ? void 0 : result.n,
246
- // opTime: result.opTime,
247
- ok: result === null || result === void 0 ? void 0 : result.ok,
248
- // operationTime,
249
- deletedCount: result === null || result === void 0 ? void 0 : result.deletedCount
250
- };
251
- });
252
- });
253
- }
254
268
  }
255
269
  exports.MongoRepository = MongoRepository;
@@ -44,6 +44,10 @@ export declare class MongoRepository {
44
44
  inclusion: string[];
45
45
  exclusion: string[];
46
46
  }): Promise<factory.order.IOrder>;
47
+ findByOrderNumberAndReservationId(params: {
48
+ orderNumber: string;
49
+ reservationId: string;
50
+ }): Promise<Pick<factory.order.IOrder, 'orderNumber' | 'orderStatus' | 'typeOf'>>;
47
51
  /**
48
52
  * 注文番号で削除する
49
53
  */
@@ -805,6 +805,30 @@ class MongoRepository {
805
805
  return doc.toObject();
806
806
  });
807
807
  }
808
+ findByOrderNumberAndReservationId(params) {
809
+ return __awaiter(this, void 0, void 0, function* () {
810
+ const projection = {
811
+ orderStatus: 1,
812
+ typeOf: 1,
813
+ orderNumber: 1,
814
+ _id: 0
815
+ };
816
+ const doc = yield this.orderModel.findOne({
817
+ orderNumber: { $eq: params.orderNumber },
818
+ acceptedOffers: {
819
+ $elemMatch: {
820
+ 'itemOffered.typeOf': { $in: [factory.reservationType.BusReservation, factory.reservationType.EventReservation] },
821
+ 'itemOffered.id': { $eq: params.reservationId }
822
+ }
823
+ }
824
+ }, projection)
825
+ .exec();
826
+ if (doc === null) {
827
+ throw new factory.errors.NotFound(this.orderModel.modelName);
828
+ }
829
+ return doc.toObject();
830
+ });
831
+ }
808
832
  /**
809
833
  * 注文番号で削除する
810
834
  */
@@ -56,7 +56,7 @@ export declare class MongoRepository {
56
56
  /**
57
57
  * 発券する
58
58
  */
59
- checkIn(params: {
59
+ checkInIfNot(params: {
60
60
  id?: string | {
61
61
  $in?: string[];
62
62
  };
@@ -68,6 +68,9 @@ export declare class MongoRepository {
68
68
  */
69
69
  now: Date;
70
70
  }): Promise<void>;
71
+ /**
72
+ * 発券する
73
+ */
71
74
  /**
72
75
  * 入場する
73
76
  */
@@ -1027,7 +1027,7 @@ class MongoRepository {
1027
1027
  /**
1028
1028
  * 発券する
1029
1029
  */
1030
- checkIn(params) {
1030
+ checkInIfNot(params) {
1031
1031
  var _a, _b;
1032
1032
  return __awaiter(this, void 0, void 0, function* () {
1033
1033
  const conditions = [];
@@ -1055,6 +1055,8 @@ class MongoRepository {
1055
1055
  }
1056
1056
  // 無条件で実行されないように
1057
1057
  if (conditions.length > 0) {
1058
+ // false->trueのみ(2023-01-31~)
1059
+ conditions.push({ checkedIn: { $eq: false } });
1058
1060
  yield this.reservationModel.updateMany({ $and: conditions }, {
1059
1061
  checkedIn: true,
1060
1062
  modifiedTime: params.now
@@ -1063,6 +1065,50 @@ class MongoRepository {
1063
1065
  }
1064
1066
  });
1065
1067
  }
1068
+ /**
1069
+ * 発券する
1070
+ */
1071
+ // public async checkIn(params: {
1072
+ // id?: string | { $in?: string[] };
1073
+ // reservationNumber?: string | { $in?: string[] };
1074
+ // /**
1075
+ // * modifiedTime
1076
+ // */
1077
+ // now: Date;
1078
+ // }): Promise<void> {
1079
+ // const conditions: any[] = [];
1080
+ // if (typeof params.id === 'string') {
1081
+ // if (params.id.length > 0) {
1082
+ // conditions.push({ _id: { $eq: params.id } });
1083
+ // }
1084
+ // } else {
1085
+ // const idIn = params.id?.$in;
1086
+ // if (Array.isArray(idIn)) {
1087
+ // conditions.push({ _id: { $in: idIn } });
1088
+ // }
1089
+ // }
1090
+ // if (typeof params.reservationNumber === 'string') {
1091
+ // if (params.reservationNumber.length > 0) {
1092
+ // conditions.push({ reservationNumber: { $eq: params.reservationNumber } });
1093
+ // }
1094
+ // } else {
1095
+ // const reservationNumberIn = params.reservationNumber?.$in;
1096
+ // if (Array.isArray(reservationNumberIn)) {
1097
+ // conditions.push({ reservationNumber: { $in: reservationNumberIn } });
1098
+ // }
1099
+ // }
1100
+ // // 無条件で実行されないように
1101
+ // if (conditions.length > 0) {
1102
+ // await this.reservationModel.updateMany(
1103
+ // { $and: conditions },
1104
+ // {
1105
+ // checkedIn: true,
1106
+ // modifiedTime: params.now
1107
+ // }
1108
+ // )
1109
+ // .exec();
1110
+ // }
1111
+ // }
1066
1112
  /**
1067
1113
  * 入場する
1068
1114
  */
@@ -117,7 +117,8 @@ function addReservations(params) {
117
117
  event: { id: event.id },
118
118
  // 対応アプリケーション条件追加(2023-01-27~)
119
119
  store: { id: (_a = params.availableAtOrFrom) === null || _a === void 0 ? void 0 : _a.id },
120
- sort: false // ソート不要(2023-01-27~)
120
+ sort: false,
121
+ validateOfferRateLimit: true
121
122
  })(repos);
122
123
  ticketOffers = searchEventTicketOffersResult.ticketOffers;
123
124
  availableOffers = searchEventTicketOffersResult.unitPriceOffers;
@@ -2,7 +2,6 @@ import { MongoRepository as ActionRepo } from '../repo/action';
2
2
  import { MongoRepository as AuthorizationRepo } from '../repo/code';
3
3
  import * as factory from '../factory';
4
4
  export declare type IToken = string;
5
- export declare type IData = any;
6
5
  export declare type ICode = string;
7
6
  /**
8
7
  * 承認を削除する
@@ -24,7 +23,7 @@ export declare function getToken(params: {
24
23
  }): (repos: {
25
24
  authorization: AuthorizationRepo;
26
25
  }) => Promise<IToken>;
27
- export declare function verifyToken<T>(params: {
26
+ export declare function verifyToken<T = factory.authorization.IObject>(params: {
28
27
  project: {
29
28
  id: string;
30
29
  };
@@ -219,7 +219,8 @@ function validateAcceptedOffers(params) {
219
219
  event: { id: params.event.id },
220
220
  // seller: params.seller,
221
221
  store: params.store,
222
- sort: false // ソート不要(2023-01-27~)
222
+ sort: false,
223
+ validateOfferRateLimit: true
223
224
  })(repos);
224
225
  // 利用可能なチケットオファーであれば受け入れる
225
226
  const acceptedOffers = (Array.isArray(acceptedOffersWithoutDetail))
@@ -75,6 +75,7 @@ declare function searchEventTicketOffers(params: {
75
75
  kbnEisyahousiki: string;
76
76
  };
77
77
  sort: boolean;
78
+ validateOfferRateLimit: boolean;
78
79
  }): ISearchEventTicketOffersOperation<{
79
80
  ticketOffers: factory.product.ITicketOffer[];
80
81
  unitPriceOffers: factory.unitPriceOffer.IUnitPriceOffer[];
@@ -101,10 +101,12 @@ function searchTransportationEventTicketOffers(params) {
101
101
  videoFormatTypes
102
102
  });
103
103
  });
104
- // レート制限を確認
105
- offers4event = yield Promise.all(offers4event.map((offer) => __awaiter(this, void 0, void 0, function* () {
106
- return checkAvailability({ event: screeningEvent, offer })(repos);
107
- })));
104
+ if (params.validateOfferRateLimit) {
105
+ // レート制限を確認
106
+ offers4event = yield Promise.all(offers4event.map((offer) => __awaiter(this, void 0, void 0, function* () {
107
+ return checkAvailability({ event: screeningEvent, offer })(repos);
108
+ })));
109
+ }
108
110
  // アドオン設定があれば、プロダクトオファーを検索
109
111
  for (const offer of offers4event) {
110
112
  const offerAddOn = [];
@@ -220,10 +222,12 @@ function searchScreeningEventTicketOffers(params) {
220
222
  videoFormatTypes
221
223
  });
222
224
  });
223
- // レート制限を確認
224
- offers4event = yield Promise.all(offers4event.map((offer) => __awaiter(this, void 0, void 0, function* () {
225
- return checkAvailability({ event: screeningEvent, offer })(repos);
226
- })));
225
+ if (params.validateOfferRateLimit) {
226
+ // レート制限を確認
227
+ offers4event = yield Promise.all(offers4event.map((offer) => __awaiter(this, void 0, void 0, function* () {
228
+ return checkAvailability({ event: screeningEvent, offer })(repos);
229
+ })));
230
+ }
227
231
  // アドオン設定があれば、プロダクトオファーを検索
228
232
  for (const offer of offers4event) {
229
233
  const offerAddOn = [];
@@ -390,7 +394,8 @@ function searchEventTicketOffers(params) {
390
394
  ids: params.ids,
391
395
  event,
392
396
  store: params.store,
393
- sort: params.sort
397
+ sort: params.sort,
398
+ validateOfferRateLimit: params.validateOfferRateLimit
394
399
  })(repos);
395
400
  offers = searchOffersResult.ticketOffers;
396
401
  unitPriceOffers = searchOffersResult.unitPriceOffers;
@@ -400,7 +405,8 @@ function searchEventTicketOffers(params) {
400
405
  ids: params.ids,
401
406
  event,
402
407
  store: params.store,
403
- sort: params.sort
408
+ sort: params.sort,
409
+ validateOfferRateLimit: params.validateOfferRateLimit
404
410
  })(repos);
405
411
  offers = searchOffersResult.ticketOffers;
406
412
  unitPriceOffers = searchOffersResult.unitPriceOffers;
@@ -17,11 +17,11 @@ function checkInRerservation(params) {
17
17
  // 発券処理(Array対応)
18
18
  let checkedInReservationIds;
19
19
  if (Array.isArray(params.object.ids) && params.object.ids.length > 0) {
20
- yield repos.reservation.checkIn({ id: { $in: params.object.ids }, now });
20
+ yield repos.reservation.checkInIfNot({ id: { $in: params.object.ids }, now });
21
21
  checkedInReservationIds = params.object.ids;
22
22
  }
23
23
  if (Array.isArray(params.object.reservationNumbers) && params.object.reservationNumbers.length > 0) {
24
- yield repos.reservation.checkIn({ reservationNumber: { $in: params.object.reservationNumbers }, now });
24
+ yield repos.reservation.checkInIfNot({ reservationNumber: { $in: params.object.reservationNumbers }, now });
25
25
  // 予約番号リストを予約IDリストに変換
26
26
  checkedInReservationIds = yield repos.reservation.searchIdsByReservationNumber({
27
27
  reservationNumber: { $in: params.object.reservationNumbers }
@@ -26,12 +26,18 @@ function verifyToken4reservation(params) {
26
26
  })({});
27
27
  switch (payload.typeOf) {
28
28
  case factory.order.OrderType.Order:
29
- // 注文検索
30
- const order = yield repos.order.findByOrderNumber({
29
+ // reservationIdを含む注文の存在を確認するだけでよい(2023-01-31~)
30
+ const order = yield repos.order.findByOrderNumberAndReservationId({
31
31
  orderNumber: payload.orderNumber,
32
- inclusion: ['orderStatus', 'acceptedOffers'],
33
- exclusion: []
32
+ reservationId: params.reservationId
34
33
  });
34
+ // 注文検索
35
+ // const order: Pick<factory.order.IOrder, 'orderStatus' | 'acceptedOffers'> =
36
+ // await repos.order.findByOrderNumber({
37
+ // orderNumber: payload.orderNumber,
38
+ // inclusion: ['orderStatus', 'acceptedOffers'],
39
+ // exclusion: []
40
+ // });
35
41
  // ステータス検証
36
42
  switch (order.orderStatus) {
37
43
  case factory.orderStatus.OrderDelivered:
@@ -39,15 +45,17 @@ function verifyToken4reservation(params) {
39
45
  default:
40
46
  throw new factory.errors.Argument('token', `invalid orderStatus '${order.orderStatus}'`);
41
47
  }
42
- const acceptedOffers = (Array.isArray(order.acceptedOffers)) ? order.acceptedOffers : [];
43
- const reservationExistsInOrder = acceptedOffers.some((offer) => {
44
- return (offer.itemOffered.typeOf === factory.reservationType.EventReservation
45
- || offer.itemOffered.typeOf === factory.reservationType.BusReservation)
46
- && offer.itemOffered.id === params.reservationId;
47
- });
48
- if (!reservationExistsInOrder) {
49
- throw new factory.errors.NotFound('AcceptedOffer');
50
- }
48
+ // const acceptedOffers = (Array.isArray(order.acceptedOffers)) ? order.acceptedOffers : [];
49
+ // const reservationExistsInOrder = acceptedOffers.some((offer) => {
50
+ // return (
51
+ // offer.itemOffered.typeOf === factory.reservationType.EventReservation
52
+ // || offer.itemOffered.typeOf === factory.reservationType.BusReservation
53
+ // )
54
+ // && offer.itemOffered.id === params.reservationId;
55
+ // });
56
+ // if (!reservationExistsInOrder) {
57
+ // throw new factory.errors.NotFound('AcceptedOffer');
58
+ // }
51
59
  break;
52
60
  default:
53
61
  throw new factory.errors.NotImplemented(`Payload type ${payload.typeOf} not implemented`);
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  }
10
10
  ],
11
11
  "dependencies": {
12
- "@chevre/factory": "4.284.0-alpha.1",
12
+ "@chevre/factory": "4.284.0-alpha.2",
13
13
  "@cinerino/sdk": "3.136.0",
14
14
  "@motionpicture/coa-service": "9.2.0",
15
15
  "@motionpicture/gmo-service": "5.2.0",
@@ -120,5 +120,5 @@
120
120
  "postversion": "git push origin --tags",
121
121
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
122
122
  },
123
- "version": "20.2.0-alpha.42"
123
+ "version": "20.2.0-alpha.45"
124
124
  }