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

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,22 @@
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 reservationRepo = new chevre.repository.Reservation(mongoose.connection);
10
+
11
+ const reservation = await reservationRepo.attendIfNotAttended(
12
+ {
13
+ id: '864318975593476-0',
14
+ now: new Date()
15
+ }
16
+ );
17
+ console.log('event found', reservation);
18
+ }
19
+
20
+ main()
21
+ .then(console.log)
22
+ .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
  }
@@ -26,6 +26,8 @@ export declare class MongoRepository {
26
26
  search<T extends factory.reservationType>(params: factory.reservation.ISearchConditions<T>, projection?: any): Promise<factory.reservation.IReservation<factory.reservationType.EventReservation>[]>;
27
27
  findById<T extends factory.reservationType>(params: {
28
28
  id: string;
29
+ inclusion?: string[];
30
+ exclusion?: string[];
29
31
  }): Promise<factory.reservation.IReservation<T>>;
30
32
  /**
31
33
  * 予約確定
@@ -69,7 +71,7 @@ export declare class MongoRepository {
69
71
  /**
70
72
  * 入場する
71
73
  */
72
- attend(params: {
74
+ attendIfNotAttended(params: {
73
75
  id: string;
74
76
  /**
75
77
  * modifiedTime
@@ -900,11 +900,25 @@ class MongoRepository {
900
900
  // }
901
901
  findById(params) {
902
902
  return __awaiter(this, void 0, void 0, function* () {
903
- const doc = yield this.reservationModel.findById(params.id, {
904
- __v: 0,
905
- createdAt: 0,
906
- updatedAt: 0
907
- })
903
+ let projection = {};
904
+ if (Array.isArray(params.inclusion) && params.inclusion.length > 0) {
905
+ params.inclusion.forEach((field) => {
906
+ projection[field] = 1;
907
+ });
908
+ }
909
+ else {
910
+ projection = {
911
+ __v: 0,
912
+ createdAt: 0,
913
+ updatedAt: 0
914
+ };
915
+ if (Array.isArray(params.exclusion) && params.exclusion.length > 0) {
916
+ params.exclusion.forEach((field) => {
917
+ projection[field] = 0;
918
+ });
919
+ }
920
+ }
921
+ const doc = yield this.reservationModel.findById(params.id, projection)
908
922
  .exec();
909
923
  if (doc === null) {
910
924
  throw new factory.errors.NotFound(this.reservationModel.modelName);
@@ -1052,16 +1066,21 @@ class MongoRepository {
1052
1066
  /**
1053
1067
  * 入場する
1054
1068
  */
1055
- attend(params) {
1069
+ attendIfNotAttended(params) {
1056
1070
  return __awaiter(this, void 0, void 0, function* () {
1057
- const doc = yield this.reservationModel.findByIdAndUpdate(String(params.id), {
1071
+ const doc = yield this.reservationModel.findOneAndUpdate({
1072
+ _id: { $eq: params.id },
1073
+ attended: { $eq: false }
1074
+ }, {
1058
1075
  attended: true,
1059
- modifiedTime: params.now
1076
+ modifiedTime: params.now,
1077
+ 'reservedTicket.dateUsed': params.now
1060
1078
  }, { new: true })
1061
1079
  .select({ __v: 0, createdAt: 0, updatedAt: 0 })
1062
1080
  .exec();
1063
1081
  if (doc === null) {
1064
- throw new factory.errors.NotFound(this.reservationModel.modelName);
1082
+ return this.findById({ id: params.id });
1083
+ // throw new factory.errors.NotFound(this.reservationModel.modelName);
1065
1084
  }
1066
1085
  return doc.toObject();
1067
1086
  });
@@ -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;
@@ -8,7 +8,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var _a;
12
11
  Object.defineProperty(exports, "__esModule", { value: true });
13
12
  exports.onReservationUsed = void 0;
14
13
  /**
@@ -20,7 +19,6 @@ const settings_1 = require("../../../settings");
20
19
  const offer_1 = require("../../offer");
21
20
  const factory_1 = require("../factory");
22
21
  const informReservations = settings_1.settings.onReservationStatusChanged.informReservation;
23
- const informUseReservations = (_a = settings_1.settings.onReservationUsed) === null || _a === void 0 ? void 0 : _a.informAction;
24
22
  const INFORM_TASK_DELAY_IN_SECONDS = 30;
25
23
  /**
26
24
  * 予約使用
@@ -28,41 +26,39 @@ const INFORM_TASK_DELAY_IN_SECONDS = 30;
28
26
  function onReservationUsed(action, attendedReservation) {
29
27
  // tslint:disable-next-line:max-func-body-length
30
28
  return (repos) => __awaiter(this, void 0, void 0, function* () {
31
- // const reservation = action.object[0];
32
29
  const tasks = [];
33
30
  const now = new Date();
31
+ // INFORM_USE_RESERVATION_URL廃止(2023-01-30~)
34
32
  // アクション通知タスク作成
35
- if (Array.isArray(informUseReservations)) {
36
- informUseReservations.filter((informUseReservation) => {
37
- var _a;
38
- return typeof ((_a = informUseReservation.recipient) === null || _a === void 0 ? void 0 : _a.url) === 'string'
39
- && informUseReservation.recipient.url.length > 0;
40
- })
41
- .forEach((informUseReservation) => {
42
- var _a, _b;
43
- const triggerWebhookTask = {
44
- project: action.project,
45
- name: factory.taskName.TriggerWebhook,
46
- status: factory.taskStatus.Ready,
47
- runsAt: now,
48
- remainingNumberOfTries: 3,
49
- numberOfTried: 0,
50
- executionResults: [],
51
- data: {
52
- project: action.project,
53
- typeOf: factory.actionType.InformAction,
54
- agent: action.project,
55
- recipient: {
56
- typeOf: factory.personType.Person,
57
- id: String((_a = informUseReservation.recipient) === null || _a === void 0 ? void 0 : _a.url),
58
- url: String((_b = informUseReservation.recipient) === null || _b === void 0 ? void 0 : _b.url)
59
- },
60
- object: action
61
- }
62
- };
63
- tasks.push(triggerWebhookTask);
64
- });
65
- }
33
+ // if (Array.isArray(informUseReservations)) {
34
+ // informUseReservations.filter((informUseReservation) => {
35
+ // return typeof informUseReservation.recipient?.url === 'string'
36
+ // && informUseReservation.recipient.url.length > 0;
37
+ // })
38
+ // .forEach((informUseReservation) => {
39
+ // const triggerWebhookTask: factory.task.triggerWebhook.IAttributes = {
40
+ // project: action.project,
41
+ // name: factory.taskName.TriggerWebhook,
42
+ // status: factory.taskStatus.Ready,
43
+ // runsAt: now,
44
+ // remainingNumberOfTries: 3,
45
+ // numberOfTried: 0,
46
+ // executionResults: [],
47
+ // data: {
48
+ // project: action.project,
49
+ // typeOf: factory.actionType.InformAction,
50
+ // agent: action.project,
51
+ // recipient: {
52
+ // typeOf: factory.personType.Person,
53
+ // id: String(informUseReservation.recipient?.url),
54
+ // url: String(informUseReservation.recipient?.url)
55
+ // },
56
+ // object: action
57
+ // }
58
+ // };
59
+ // tasks.push(triggerWebhookTask);
60
+ // });
61
+ // }
66
62
  // inform galobally
67
63
  if (Array.isArray(informReservations)) {
68
64
  // やや遅延させる(確定通知が未達の可能性を考慮して)
@@ -11,9 +11,6 @@ import { IUseReservationAction } from './potentialActions/onReservationUsed';
11
11
  * 予約使用
12
12
  */
13
13
  export declare function useReservation(params: {
14
- project: {
15
- id: string;
16
- };
17
14
  agent: factory.action.consume.use.reservation.IAgent;
18
15
  object: {
19
16
  /**
@@ -15,7 +15,7 @@ exports.useReservation = void 0;
15
15
  */
16
16
  const factory = require("../../factory");
17
17
  const code_1 = require("../code");
18
- const factory_1 = require("./factory");
18
+ // import { maskUnderName } from './factory';
19
19
  const onReservationUsed_1 = require("./potentialActions/onReservationUsed");
20
20
  function verifyToken4reservation(params) {
21
21
  return (repos) => __awaiter(this, void 0, void 0, function* () {
@@ -57,54 +57,67 @@ function verifyToken4reservation(params) {
57
57
  /**
58
58
  * 予約使用
59
59
  */
60
- // export function useReservation(actionAttributes: factory.action.consume.use.reservation.IAttributes) {
60
+ // tslint:disable-next-line:max-func-body-length
61
61
  function useReservation(params) {
62
62
  return (repos) => __awaiter(this, void 0, void 0, function* () {
63
- var _a, _b, _c;
63
+ var _a, _b;
64
64
  const now = new Date();
65
+ const reservationId = params.object.id;
65
66
  // 予約検索
66
- let reservation = yield repos.reservation.findById({ id: params.object.id });
67
+ // 取得属性最適化(2023-01-30~)
68
+ const reservation = yield repos.reservation.findById({
69
+ id: reservationId,
70
+ inclusion: ['id', 'issuedThrough', 'project', 'reservationFor', 'reservationNumber', 'reservedTicket', 'typeOf']
71
+ });
67
72
  // instrument?.tokenを検証
68
73
  const token = (_a = params === null || params === void 0 ? void 0 : params.instrument) === null || _a === void 0 ? void 0 : _a.token;
69
74
  if (typeof token === 'string') {
70
75
  yield verifyToken4reservation({
71
- project: { id: params.project.id },
76
+ project: { id: reservation.project.id },
72
77
  agent: params.agent,
73
- reservationId: params.object.id,
78
+ reservationId,
74
79
  token
75
80
  })({ order: repos.order });
76
81
  }
77
82
  // UseActionを作成する
78
- const actionAttributes = Object.assign({ project: reservation.project, typeOf: factory.actionType.UseAction, agent: params.agent, instrument: Object.assign(Object.assign({}, (typeof token === 'string') ? { token } : undefined), {
79
- typeOf: factory.action.check.token.ObjectType.Ticket
80
- }),
83
+ const reservationAsObject = {
84
+ id: reservation.id,
85
+ issuedThrough: reservation.issuedThrough,
86
+ reservationFor: reservation.reservationFor,
87
+ reservationNumber: reservation.reservationNumber,
88
+ reservedTicket: reservation.reservedTicket,
89
+ typeOf: reservation.typeOf
90
+ };
91
+ 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 }),
92
+ // object最適化(2023-01-30~)
81
93
  // どの予約を
82
94
  // mask
83
- object: [(0, factory_1.maskUnderName)(reservation)] }, (typeof ((_b = params.location) === null || _b === void 0 ? void 0 : _b.identifier) === 'string')
95
+ // object: [maskUnderName(reservation)],
96
+ object: [reservationAsObject] }, (typeof ((_b = params.location) === null || _b === void 0 ? void 0 : _b.identifier) === 'string')
84
97
  ? {
85
98
  location: {
86
99
  typeOf: factory.placeType.Place,
87
100
  identifier: params.location.identifier
88
101
  }
89
102
  }
90
- : undefined
91
- // purpose: params.purpose
92
- );
103
+ : undefined);
93
104
  let action = yield repos.action.start(actionAttributes);
94
105
  // ひとまず予約数:1に限定する
95
106
  if (actionAttributes.object.length !== 1) {
96
107
  throw new factory.errors.Argument('object', 'number of using reservations must be 1');
97
108
  }
98
- reservation = actionAttributes.object[0];
109
+ let attendedReservation;
99
110
  try {
100
- reservation = (yield repos.reservation.attend({ id: reservation.id, now }));
101
- // 使用日時がなければ追加
102
- if (((_c = reservation.reservedTicket) === null || _c === void 0 ? void 0 : _c.dateUsed) === undefined) {
103
- reservation = yield repos.reservation.updatePartiallyById({
104
- id: reservation.id,
105
- update: { 'reservedTicket.dateUsed': now }
106
- });
107
- }
111
+ // 使用日時と同時更新(2023-01-30~)
112
+ attendedReservation = (yield repos.reservation.attendIfNotAttended({ id: reservationId, now }));
113
+ // attendedReservation = <IEventReservation>await repos.reservation.attend({ id: reservationId, now });
114
+ // // 使用日時がなければ追加
115
+ // if (attendedReservation.reservedTicket?.dateUsed === undefined) {
116
+ // attendedReservation = await repos.reservation.updatePartiallyById({
117
+ // id: attendedReservation.id,
118
+ // update: { 'reservedTicket.dateUsed': now }
119
+ // });
120
+ // }
108
121
  }
109
122
  catch (error) {
110
123
  // actionにエラー結果を追加
@@ -119,7 +132,7 @@ function useReservation(params) {
119
132
  }
120
133
  // アクション完了
121
134
  action = (yield repos.action.complete({ typeOf: action.typeOf, id: action.id, result: {} }));
122
- yield (0, onReservationUsed_1.onReservationUsed)(action, reservation)({ task: repos.task });
135
+ yield (0, onReservationUsed_1.onReservationUsed)(action, attendedReservation)({ task: repos.task });
123
136
  return action;
124
137
  });
125
138
  }
@@ -14,9 +14,9 @@ const informOrderUrls = (typeof process.env.INFORM_ORDER_URL === 'string')
14
14
  const informReservationUrls = (typeof process.env.INFORM_RESERVATION_URL === 'string')
15
15
  ? process.env.INFORM_RESERVATION_URL.split(',')
16
16
  : [];
17
- const informUseReservationUrls = (typeof process.env.INFORM_USE_RESERVATION_URL === 'string')
18
- ? process.env.INFORM_USE_RESERVATION_URL.split(',')
19
- : [];
17
+ // const informUseReservationUrls = (typeof process.env.INFORM_USE_RESERVATION_URL === 'string')
18
+ // ? process.env.INFORM_USE_RESERVATION_URL.split(',')
19
+ // : [];
20
20
  // tslint:disable-next-line:no-magic-numbers
21
21
  const triggerWebhookTimeout = (process.env.TRIGGER_WEBHOOK_TIMEOUT !== undefined) ? Number(process.env.TRIGGER_WEBHOOK_TIMEOUT) : 15000;
22
22
  const MAXIMUM_RESERVATION_GRACE_PERIOD_IN_DAYS = (typeof process.env.MAXIMUM_RESERVATION_GRACE_PERIOD_IN_DAYS === 'string')
@@ -81,13 +81,16 @@ exports.settings = Object.assign({ transactionWebhookUrls, onOrderStatusChanged:
81
81
  .map((url) => {
82
82
  return { recipient: { url } };
83
83
  })
84
- }, onReservationUsed: {
85
- informAction: informUseReservationUrls
86
- .filter((url) => url.length > 0)
87
- .map((url) => {
88
- return { recipient: { url } };
89
- })
90
- }, webhook: {
84
+ },
85
+ // 廃止(2023-01-30~)
86
+ // onReservationUsed: {
87
+ // informAction: informUseReservationUrls
88
+ // .filter((url) => url.length > 0)
89
+ // .map((url) => {
90
+ // return { recipient: { url } };
91
+ // })
92
+ // },
93
+ webhook: {
91
94
  timeout: triggerWebhookTimeout
92
95
  }, maximumReservationGracePeriodInDays: MAXIMUM_RESERVATION_GRACE_PERIOD_IN_DAYS, userPoolIdOld: String(process.env.USERPOOL_ID_OLD), userPoolIdNew: String(process.env.USERPOOL_ID_NEW) }, (typeof MAX_NUM_CREDIT_CARD_PAYMENT_METHOD === 'number')
93
96
  ? { maxNumCreditCardPaymentMethod: MAX_NUM_CREDIT_CARD_PAYMENT_METHOD }
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  }
10
10
  ],
11
11
  "dependencies": {
12
- "@chevre/factory": "4.284.0-alpha.0",
12
+ "@chevre/factory": "4.284.0-alpha.1",
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.40"
123
+ "version": "20.2.0-alpha.42"
124
124
  }