@chevre/domain 22.9.0-alpha.76 → 22.9.0-alpha.78

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.
@@ -11,7 +11,7 @@ mongoose.Model.on('index', (...args) => {
11
11
  async function main() {
12
12
  await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
13
13
 
14
- await chevre.repository.AggregateOrder.createInstance(mongoose.connection);
14
+ await chevre.repository.Authorization.createInstance(mongoose.connection);
15
15
  console.log('success!');
16
16
  }
17
17
 
@@ -104,6 +104,15 @@ const indexes = [
104
104
  }
105
105
  }
106
106
  ],
107
+ [
108
+ { 'object.orderNumber': 1, validFrom: 1 },
109
+ {
110
+ name: 'objectOrderNumber',
111
+ partialFilterExpression: {
112
+ 'object.orderNumber': { $exists: true }
113
+ }
114
+ }
115
+ ],
107
116
  [
108
117
  { 'object.typeOfGood.typeOf': 1, validFrom: 1 },
109
118
  {
@@ -90,7 +90,6 @@ function createOnAuthorizationCreatedTask(order) {
90
90
  if (typeof codeFromTransaction === 'string') {
91
91
  const taskRunsAt = new Date();
92
92
  const taskIdentifier = `${order.project.id}:${factory.taskName.OnAuthorizationCreated}:${factory.transactionType.PlaceOrder}:${placeOrderTransaction === null || placeOrderTransaction === void 0 ? void 0 : placeOrderTransaction.id}`;
93
- debug('codeFromTransaction exists. so creating OnAuthorizationCreated task...taskIdentifier:', taskIdentifier);
94
93
  const task = {
95
94
  identifier: taskIdentifier,
96
95
  name: factory.taskName.OnAuthorizationCreated,
@@ -101,7 +100,8 @@ function createOnAuthorizationCreatedTask(order) {
101
100
  executionResults: [],
102
101
  data: {
103
102
  project: { id: order.project.id },
104
- code: codeFromTransaction
103
+ code: codeFromTransaction,
104
+ retryOnReservationNotFound: true
105
105
  },
106
106
  project: { id: order.project.id, typeOf: factory.organizationType.Project }
107
107
  };
@@ -28,7 +28,7 @@ interface ICheckInReservationParams {
28
28
  orderNumber?: string;
29
29
  };
30
30
  options: {
31
- retry: boolean;
31
+ retryOnReservationNotFound: boolean;
32
32
  };
33
33
  }
34
34
  export declare function checkInReservation(params: ICheckInReservationParams): (repos: {
@@ -29,49 +29,60 @@ function checkInReservation(params) {
29
29
  typeOf: factory.reservationType.EventReservation
30
30
  });
31
31
  if (existingReservationCount !== params.object.ids.length) {
32
- if (params.options.retry === true) {
32
+ if (params.options.retryOnReservationNotFound === true) {
33
33
  throw new factory.errors.NotFound(factory.reservationType.EventReservation, `Some reservations dot not exist. ${params.object.ids.join(',')}`);
34
34
  }
35
35
  }
36
- checkedInResult = yield repos.reservation.checkInIfNot({ id: { $in: params.object.ids }, now });
37
- checkedInReservationIds = params.object.ids;
36
+ if (existingReservationCount > 0) {
37
+ checkedInResult = yield repos.reservation.checkInIfNot({ id: { $in: params.object.ids }, now });
38
+ checkedInReservationIds = params.object.ids;
39
+ }
38
40
  }
39
41
  if (Array.isArray(params.object.reservationNumbers) && params.object.reservationNumbers.length > 0) {
42
+ let reservationExists = false;
40
43
  for (const reservationNumber of params.object.reservationNumbers) {
41
44
  const existingReservationCount = yield repos.reservation.count({
42
45
  reservationNumber: { $eq: reservationNumber },
43
46
  typeOf: factory.reservationType.EventReservation
44
47
  });
45
48
  if (existingReservationCount === 0) {
46
- if (params.options.retry === true) {
49
+ if (params.options.retryOnReservationNotFound === true) {
47
50
  throw new factory.errors.NotFound(factory.reservationType.EventReservation, `Some reservations dot not exist. ${params.object.reservationNumbers.join(',')}`);
48
51
  }
49
52
  }
53
+ if (existingReservationCount > 0) {
54
+ reservationExists = true;
55
+ }
56
+ }
57
+ if (reservationExists) {
58
+ checkedInResult =
59
+ yield repos.reservation.checkInIfNot({ reservationNumber: { $in: params.object.reservationNumbers }, now });
50
60
  }
51
- checkedInResult = yield repos.reservation.checkInIfNot({ reservationNumber: { $in: params.object.reservationNumbers }, now });
52
61
  }
53
62
  const checkedInForTheFirstTime = typeof (checkedInResult === null || checkedInResult === void 0 ? void 0 : checkedInResult.modifiedCount) === 'number' && checkedInResult.modifiedCount > 0;
54
- if (Array.isArray(checkedInReservationIds)) {
55
- yield (0, onReservationCheckedIn_1.onReservationCheckedIn)({
56
- project: params.project,
57
- object: {
58
- ids: checkedInReservationIds,
59
- reservedTicket: Object.assign({}, (checkedInForTheFirstTime) ? { dateIssued: now } : undefined)
60
- },
61
- purpose: params.purpose,
62
- instrument: params.instrument
63
- })(repos);
64
- }
65
- else if (Array.isArray(params.object.reservationNumbers) && params.object.reservationNumbers.length > 0) {
66
- yield (0, onReservationCheckedIn_1.onReservationCheckedIn)({
67
- project: params.project,
68
- object: {
69
- reservationNumbers: params.object.reservationNumbers,
70
- reservedTicket: Object.assign({}, (checkedInForTheFirstTime) ? { dateIssued: now } : undefined)
71
- },
72
- purpose: params.purpose,
73
- instrument: params.instrument
74
- })(repos);
63
+ if (checkedInResult !== undefined) {
64
+ if (Array.isArray(checkedInReservationIds)) {
65
+ yield (0, onReservationCheckedIn_1.onReservationCheckedIn)({
66
+ project: params.project,
67
+ object: {
68
+ ids: checkedInReservationIds,
69
+ reservedTicket: Object.assign({}, (checkedInForTheFirstTime) ? { dateIssued: now } : undefined)
70
+ },
71
+ purpose: params.purpose,
72
+ instrument: params.instrument
73
+ })(repos);
74
+ }
75
+ else if (Array.isArray(params.object.reservationNumbers) && params.object.reservationNumbers.length > 0) {
76
+ yield (0, onReservationCheckedIn_1.onReservationCheckedIn)({
77
+ project: params.project,
78
+ object: {
79
+ reservationNumbers: params.object.reservationNumbers,
80
+ reservedTicket: Object.assign({}, (checkedInForTheFirstTime) ? { dateIssued: now } : undefined)
81
+ },
82
+ purpose: params.purpose,
83
+ instrument: params.instrument
84
+ })(repos);
85
+ }
75
86
  }
76
87
  });
77
88
  }
@@ -73,6 +73,7 @@ function onReservationConfirmed(confirmedReservations, reserveAction) {
73
73
  // create AggregateScreeningEvent task -> migrate to agg(2024-10-29~)
74
74
  const now = new Date();
75
75
  const taskAttributes = [];
76
+ let onAuthorizationCreatedTask;
76
77
  // support OnAuthorizationCreated(2025-03-15~)
77
78
  if (typeof (orderAsAbout === null || orderAsAbout === void 0 ? void 0 : orderAsAbout.orderNumber) === 'string') {
78
79
  const existingAuthorization = (yield repos.code.projectFields({
@@ -84,9 +85,13 @@ function onReservationConfirmed(confirmedReservations, reserveAction) {
84
85
  }
85
86
  }, ['code'])).shift();
86
87
  if (existingAuthorization !== undefined) {
87
- // tslint:disable-next-line:no-console
88
- console.log('onReservationConfirmed: existingAuthorization found.', orderAsAbout.orderNumber, reservationNumber, JSON.stringify(existingAuthorization));
89
- const onAuthorizationCreatedTask = {
88
+ // console.log(
89
+ // 'onReservationConfirmed: existingAuthorization found.',
90
+ // orderAsAbout.orderNumber, reservationNumber, JSON.stringify(existingAuthorization)
91
+ // );
92
+ const taskIdentifier = `${project.id}:${factory.taskName.OnAuthorizationCreated}:${factory.assetTransactionType.Reserve}:${reservationNumber}:onReservationConfirmed`;
93
+ onAuthorizationCreatedTask = {
94
+ identifier: taskIdentifier,
90
95
  name: factory.taskName.OnAuthorizationCreated,
91
96
  status: factory.taskStatus.Ready,
92
97
  runsAt: now,
@@ -95,11 +100,11 @@ function onReservationConfirmed(confirmedReservations, reserveAction) {
95
100
  executionResults: [],
96
101
  data: {
97
102
  project: { id: project.id },
98
- code: existingAuthorization.code
103
+ code: existingAuthorization.code,
104
+ retryOnReservationNotFound: true
99
105
  },
100
106
  project
101
107
  };
102
- taskAttributes.push(onAuthorizationCreatedTask);
103
108
  }
104
109
  }
105
110
  const subReservations4inform = confirmedReservations.map((r) => {
@@ -161,6 +166,9 @@ function onReservationConfirmed(confirmedReservations, reserveAction) {
161
166
  if (taskAttributes.length > 0) {
162
167
  yield repos.task.saveMany(taskAttributes, { emitImmediately: true });
163
168
  }
169
+ if (onAuthorizationCreatedTask !== undefined) {
170
+ yield repos.task.createIfNotExistByIdentifier(onAuthorizationCreatedTask, { emitImmediately: true });
171
+ }
164
172
  }
165
173
  });
166
174
  }
@@ -83,7 +83,7 @@ function onAuthorizationCreated(params) {
83
83
  },
84
84
  purpose: { code: params.data.code },
85
85
  instrument: Object.assign({}, (typeof orderNumber === 'string') ? { orderNumber } : undefined),
86
- options: { retry: false } // add(2025-03-15~)
86
+ options: { retryOnReservationNotFound: params.data.retryOnReservationNotFound === true } // add(2025-03-15~)
87
87
  })(repos);
88
88
  });
89
89
  }
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "dependencies": {
12
12
  "@aws-sdk/client-cognito-identity-provider": "3.600.0",
13
13
  "@aws-sdk/credential-providers": "3.600.0",
14
- "@chevre/factory": "4.393.0-alpha.39",
14
+ "@chevre/factory": "4.393.0-alpha.40",
15
15
  "@cinerino/sdk": "10.21.0-alpha.24",
16
16
  "@motionpicture/coa-service": "9.6.0",
17
17
  "@motionpicture/gmo-service": "5.3.0",
@@ -113,5 +113,5 @@
113
113
  "postversion": "git push origin --tags",
114
114
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
115
115
  },
116
- "version": "22.9.0-alpha.76"
116
+ "version": "22.9.0-alpha.78"
117
117
  }