@chevre/domain 20.2.0-alpha.41 → 20.2.0-alpha.43

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);
@@ -35,7 +35,7 @@ export declare class MongoRepository {
35
35
  /**
36
36
  * アクション検索
37
37
  */
38
- search<T extends factory.actionType>(params: factory.action.ISearchConditions, projection?: any): Promise<IAction<T>[]>;
38
+ search<T extends factory.actionType>(params: factory.action.ISearchConditions, inclusion: string[], exclusion: string[]): Promise<IAction<T>[]>;
39
39
  /**
40
40
  * アクション開始
41
41
  */
@@ -386,16 +386,28 @@ class MongoRepository {
386
386
  /**
387
387
  * アクション検索
388
388
  */
389
- search(params, projection) {
389
+ search(params, inclusion, exclusion) {
390
390
  return __awaiter(this, void 0, void 0, function* () {
391
391
  const conditions = MongoRepository.CREATE_MONGO_CONDITIONS(params);
392
- const query = this.actionModel.find((conditions.length > 0) ? { $and: conditions } : {}, (projection !== undefined && projection !== null)
393
- ? projection
394
- : {
392
+ let projection = {};
393
+ if (Array.isArray(inclusion) && inclusion.length > 0) {
394
+ inclusion.forEach((field) => {
395
+ projection[field] = 1;
396
+ });
397
+ }
398
+ else {
399
+ projection = {
395
400
  __v: 0,
396
401
  createdAt: 0,
397
402
  updatedAt: 0
398
- });
403
+ };
404
+ if (Array.isArray(exclusion) && exclusion.length > 0) {
405
+ exclusion.forEach((field) => {
406
+ projection[field] = 0;
407
+ });
408
+ }
409
+ }
410
+ const query = this.actionModel.find((conditions.length > 0) ? { $and: conditions } : {}, projection);
399
411
  if (typeof params.limit === 'number') {
400
412
  const page = (typeof params.page === 'number') ? params.page : 1;
401
413
  query.limit(params.limit)
@@ -507,7 +519,7 @@ class MongoRepository {
507
519
  project: { id: { $eq: params.project.id } },
508
520
  typeOf: { $eq: factory.actionType.PayAction },
509
521
  object: { paymentMethod: { paymentMethodId: { $eq: params.paymentMethodId } } }
510
- });
522
+ }, [], []);
511
523
  return payActions.shift();
512
524
  });
513
525
  }
@@ -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,8 @@ export declare class MongoRepository {
55
42
  ok?: number;
56
43
  deletedCount?: number;
57
44
  } | null>;
45
+ /**
46
+ * コードを保管する
47
+ */
48
+ private save;
58
49
  }
@@ -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,23 @@ 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
+ }
207
224
  /**
208
225
  * コードを保管する
209
226
  */
@@ -218,7 +235,7 @@ class MongoRepository {
218
235
  project: p.project,
219
236
  typeOf: 'Authorization',
220
237
  code: p.code,
221
- object: p.data,
238
+ object: p.object,
222
239
  validFrom: p.validFrom,
223
240
  validUntil: validUntil
224
241
  };
@@ -234,22 +251,5 @@ class MongoRepository {
234
251
  }
235
252
  });
236
253
  }
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
254
  }
255
255
  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
  */
@@ -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
  };
@@ -181,7 +181,7 @@ function createSellerFlow(measuredFrom, measuredThrough, sellerId) {
181
181
  const actionsOnExpiredTransactions = yield repos.action.search({
182
182
  typeOf: { $eq: factory.actionType.AuthorizeAction },
183
183
  purpose: { id: { $in: expiredTransactionIds } }
184
- });
184
+ }, [], []);
185
185
  debug(actionsOnExpiredTransactions.length, 'actionsOnExpiredTransactions found.');
186
186
  const numbersOfActionsOnExpired = expiredTransactionIds.map((transactionId) => {
187
187
  return actionsOnExpiredTransactions.filter((action) => action.purpose.id === transactionId).length;
@@ -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.41"
123
+ "version": "20.2.0-alpha.43"
124
124
  }