@chevre/domain 22.9.0-alpha.110 → 22.9.0-alpha.112

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.
@@ -14,10 +14,13 @@ const today = moment()
14
14
  .format('YYYYMMDD');
15
15
  const project = { id: String(process.env.PROJECT_ID) };
16
16
  const eventId = `sampleEventId${today}:03`;
17
+ // const eventId = 'bma1pcxs0';
17
18
  const eventStartDate = new Date('2025-05-01T00:00:00Z');
18
- const seatSection = 'SampleSectionNameXXXXXXXXXXXXXXXXXXX';
19
+ // const seatSection = 'SampleSectionNameXXXXXXXXXXXXXXXXXXX';
20
+ const seatSection = 'Default';
19
21
  // tslint:disable-next-line:no-magic-numbers prefer-array-literal
20
22
  const allSeatNumbers = [...Array(10000)].map((__, seatKey) => `SampleSeatNumber-${seatKey}`);
23
+ // const allSeatNumbers = [...Array(10000)].map((__, seatKey) => `A-${seatKey}`);
21
24
 
22
25
  const client = redis.createClient<redis.RedisDefaultModules, Record<string, never>, Record<string, never>>({
23
26
  socket: {
@@ -8,6 +8,7 @@ const today = moment()
8
8
  .tz('Asia/Tokyo')
9
9
  .format('YYYYMMDD');
10
10
  const project = { id: String(process.env.PROJECT_ID) };
11
+ const providerId = 'sampleProviderId';
11
12
  const eventId = `sampleEventId${today}:03`;
12
13
  const eventStartDate = new Date('2025-05-01T00:00:00Z');
13
14
  const expires = moment(eventStartDate)
@@ -140,6 +141,7 @@ async function lockSeatsForcibly(params: {
140
141
  await stockHolderRepo.lockIfNotLimitExceeded(
141
142
  {
142
143
  project: { id: project.id },
144
+ provider: { id: providerId },
143
145
  eventId,
144
146
  startDate: eventStartDate,
145
147
  hasTicketedSeat: true,
@@ -160,6 +162,7 @@ async function lockSeatsForcibly(params: {
160
162
  } else {
161
163
  await stockHolderRepo.lock({
162
164
  project: { id: project.id },
165
+ provider: { id: providerId },
163
166
  eventId,
164
167
  startDate: eventStartDate,
165
168
  hasTicketedSeat: true,
@@ -19,8 +19,9 @@ async function main() {
19
19
  limit: 10,
20
20
  page: 1,
21
21
  project: { id: { $eq: project.id } },
22
- reservationFor: { id: { $eq: 'bma0cfbc6' } }
23
- // reservationNumber: { $eq: '3073981402299' }
22
+ reservationFor: { id: { $eq: 'bma31zpnv' } },
23
+ subReservation: { identifier: { $eq: 'Default:A-1' } },
24
+ reservationNumber: { $eq: '283714519921158' }
24
25
  });
25
26
  diff = process.hrtime(startTime);
26
27
  console.log('result:', result, result.length);
@@ -3,11 +3,19 @@ import * as factory from '../../../factory';
3
3
  interface ISubReservation {
4
4
  identifier: string;
5
5
  }
6
+ interface IProvider {
7
+ /**
8
+ * 販売者ID
9
+ */
10
+ id: string;
11
+ typeOf: factory.organizationType.Corporation;
12
+ }
6
13
  interface IReservationPackage {
7
14
  project: {
8
15
  id: string;
9
16
  typeOf: factory.organizationType.Project;
10
17
  };
18
+ provider: IProvider;
11
19
  typeOf: factory.reservationType.ReservationPackage;
12
20
  bookingTime: Date;
13
21
  dateCreated: Date;
@@ -9,6 +9,7 @@ const modelName = 'PendingReservation';
9
9
  exports.modelName = modelName;
10
10
  const schemaDefinition = {
11
11
  project: { type: mongoose_1.SchemaTypes.Mixed, required: true },
12
+ provider: { type: mongoose_1.SchemaTypes.Mixed, required: true },
12
13
  typeOf: { type: String, required: true },
13
14
  numSeats: { type: Number, required: true },
14
15
  reservationFor: { type: mongoose_1.SchemaTypes.Mixed, required: true },
@@ -52,6 +53,10 @@ const indexes = [
52
53
  { 'project.id': 1, bookingTime: -1 },
53
54
  { name: 'projectId' }
54
55
  ],
56
+ [
57
+ { 'provider.id': 1, bookingTime: -1 },
58
+ { name: 'providerId' }
59
+ ],
55
60
  [
56
61
  { 'reservationFor.id': 1, bookingTime: -1 },
57
62
  { name: 'reservationForId' }
@@ -60,6 +65,10 @@ const indexes = [
60
65
  { reservationNumber: 1, bookingTime: -1 },
61
66
  { name: 'reservationNumber' }
62
67
  ],
68
+ [
69
+ { 'subReservation.identifier': 1, bookingTime: -1 },
70
+ { name: 'subReservationIdentifier' }
71
+ ],
63
72
  [
64
73
  { reservationNumber: 1 },
65
74
  {
@@ -173,33 +173,17 @@ const indexes = [
173
173
  ]
174
174
  // [
175
175
  // {
176
- // 'containsPlace.branchCode': 1,
177
- // 'containsPlace.containsPlace.branchCode': 1
178
- // },
179
- // {
180
- // name: 'searchSeatsSort'
181
- // }
182
- // ],
183
- // [
184
- // {
176
+ // typeOf: 1,
177
+ // 'project.id': 1,
185
178
  // 'containedInPlace.branchCode': 1,
186
- // 'containsPlace.branchCode': 1,
187
- // 'containsPlace.containsPlace.branchCode': 1
188
- // },
189
- // {
190
- // name: 'searchSeatsWithSort2'
191
- // }
192
- // ],
193
- // [
194
- // {
195
179
  // branchCode: 1,
196
180
  // 'containsPlace.branchCode': 1,
197
181
  // 'containsPlace.containsPlace.branchCode': 1
198
182
  // },
199
183
  // {
200
- // name: 'searchSeatsWithSort3'
184
+ // name: 'projectSeatsUsingSort'
201
185
  // }
202
- // ],
186
+ // ]
203
187
  ];
204
188
  exports.indexes = indexes;
205
189
  /**
@@ -1,6 +1,33 @@
1
1
  import type { Connection } from 'mongoose';
2
2
  import { IReservationPackage } from './mongoose/schemas/pendingReservation';
3
3
  import { AbstractStockHolderRepo, IGetHolderResult, ILockKey, IOffer, IUnlockKey } from './stockHolderAbstract';
4
+ interface ISearchConditions {
5
+ limit?: number;
6
+ page?: number;
7
+ project?: {
8
+ id?: {
9
+ $eq?: string;
10
+ };
11
+ };
12
+ provider?: {
13
+ id?: {
14
+ $eq?: string;
15
+ };
16
+ };
17
+ reservationFor?: {
18
+ id?: {
19
+ $eq?: string;
20
+ };
21
+ };
22
+ reservationNumber?: {
23
+ $eq?: string;
24
+ };
25
+ subReservation?: {
26
+ identifier?: {
27
+ $eq?: string;
28
+ };
29
+ };
30
+ }
4
31
  type IProjectFieldResult = Pick<IReservationPackage, 'bookingTime' | 'numSeats' | 'dateCreated' | 'dateModified' | 'expires' | 'reservationFor' | 'reservationNumber' | 'typeOf'>;
5
32
  /**
6
33
  * 保留予約リポジトリ
@@ -44,23 +71,7 @@ export declare class PendingReservationRepo implements AbstractStockHolderRepo {
44
71
  $lte: Date;
45
72
  };
46
73
  }): Promise<import("mongodb").DeleteResult>;
47
- projectFields(params: {
48
- limit?: number;
49
- page?: number;
50
- project?: {
51
- id?: {
52
- $eq?: string;
53
- };
54
- };
55
- reservationFor?: {
56
- id?: {
57
- $eq?: string;
58
- };
59
- };
60
- reservationNumber?: {
61
- $eq?: string;
62
- };
63
- }): Promise<IProjectFieldResult[]>;
74
+ projectFields(params: ISearchConditions): Promise<IProjectFieldResult[]>;
64
75
  private aggregateNumSeats;
65
76
  private createReservationPackageIfPossible;
66
77
  private deleteReservationPackage;
@@ -78,6 +78,7 @@ class PendingReservationRepo {
78
78
  });
79
79
  return {
80
80
  project: { id: lockKey.project.id, typeOf: factory.organizationType.Project },
81
+ provider: { id: lockKey.provider.id, typeOf: factory.organizationType.Corporation },
81
82
  typeOf: factory.reservationType.ReservationPackage,
82
83
  bookingTime,
83
84
  expires,
@@ -232,7 +233,8 @@ class PendingReservationRepo {
232
233
  },
233
234
  {
234
235
  $match: {
235
- 'subReservation.identifier': { $exists: true, $in: reservationIdentifiers }
236
+ // 'subReservation.identifier': { $exists: true, $in: reservationIdentifiers }
237
+ 'subReservation.identifier': { $in: reservationIdentifiers } // $exists不要か?
236
238
  }
237
239
  }, // unwind後にもmatchがないと、reservationIdentifiers以外のsubReservationもprojectされる
238
240
  {
@@ -372,7 +374,7 @@ class PendingReservationRepo {
372
374
  }
373
375
  projectFields(params) {
374
376
  return __awaiter(this, void 0, void 0, function* () {
375
- var _a, _b, _c, _d, _e;
377
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
376
378
  const { limit, page } = params;
377
379
  const filterQueries = [
378
380
  // { numSeats: { $gte: 1 } }
@@ -381,14 +383,22 @@ class PendingReservationRepo {
381
383
  if (typeof projectIdEq === 'string') {
382
384
  filterQueries.push({ 'project.id': { $eq: projectIdEq } });
383
385
  }
384
- const reservationForIdEq = (_d = (_c = params.reservationFor) === null || _c === void 0 ? void 0 : _c.id) === null || _d === void 0 ? void 0 : _d.$eq;
386
+ const providerIdEq = (_d = (_c = params.provider) === null || _c === void 0 ? void 0 : _c.id) === null || _d === void 0 ? void 0 : _d.$eq;
387
+ if (typeof providerIdEq === 'string') {
388
+ filterQueries.push({ 'provider.id': { $eq: providerIdEq } });
389
+ }
390
+ const reservationForIdEq = (_f = (_e = params.reservationFor) === null || _e === void 0 ? void 0 : _e.id) === null || _f === void 0 ? void 0 : _f.$eq;
385
391
  if (typeof reservationForIdEq === 'string') {
386
392
  filterQueries.push({ 'reservationFor.id': { $eq: reservationForIdEq } });
387
393
  }
388
- const reservationNumberEq = (_e = params.reservationNumber) === null || _e === void 0 ? void 0 : _e.$eq;
394
+ const reservationNumberEq = (_g = params.reservationNumber) === null || _g === void 0 ? void 0 : _g.$eq;
389
395
  if (typeof reservationNumberEq === 'string') {
390
396
  filterQueries.push({ reservationNumber: { $eq: reservationNumberEq } });
391
397
  }
398
+ const subReservationIdentifierEq = (_j = (_h = params.subReservation) === null || _h === void 0 ? void 0 : _h.identifier) === null || _j === void 0 ? void 0 : _j.$eq;
399
+ if (typeof subReservationIdentifierEq === 'string') {
400
+ filterQueries.push({ 'subReservation.identifier': { $eq: subReservationIdentifierEq } });
401
+ }
392
402
  const matchStage = (filterQueries.length > 0) ? { $match: { $and: filterQueries } } : undefined;
393
403
  let limitStage;
394
404
  let skipStage;
@@ -14,6 +14,13 @@ export interface ILockKey {
14
14
  project: {
15
15
  id: string;
16
16
  };
17
+ /**
18
+ * required(2025-04-30~)
19
+ * = event.organizer.id
20
+ */
21
+ provider: {
22
+ id: string;
23
+ };
17
24
  eventId: string;
18
25
  startDate: Date;
19
26
  hasTicketedSeat: boolean;
@@ -551,6 +551,7 @@ function processLockSeats(params) {
551
551
  if (typeof maximumAttendeeCapacity4event === 'number') {
552
552
  yield repos.stockHolder.lockIfNotLimitExceeded({
553
553
  project: { id: params.event.project.id },
554
+ provider: { id: params.event.organizer.id },
554
555
  eventId: params.event.id,
555
556
  startDate: moment(params.event.startDate)
556
557
  .toDate(),
@@ -564,6 +565,7 @@ function processLockSeats(params) {
564
565
  else {
565
566
  yield repos.stockHolder.lock({
566
567
  project: { id: params.event.project.id },
568
+ provider: { id: params.event.organizer.id },
567
569
  eventId: params.event.id,
568
570
  startDate: moment(params.event.startDate)
569
571
  .toDate(),
@@ -14,17 +14,22 @@ const factory = require("../../factory");
14
14
  const acceptedOffer_1 = require("../../repo/acceptedOffer");
15
15
  const action_1 = require("../../repo/action");
16
16
  const assetTransaction_1 = require("../../repo/assetTransaction");
17
+ const event_1 = require("../../repo/event");
17
18
  const order_1 = require("../../repo/order");
19
+ const setting_1 = require("../../repo/setting");
20
+ const stockHolder_1 = require("../../repo/stockHolder");
21
+ const task_1 = require("../../repo/task");
22
+ const validateEvent_1 = require("../validation/validateEvent");
18
23
  const validateOrder_1 = require("../validation/validateOrder");
19
24
  /**
20
25
  * タスク実行関数
21
26
  */
22
27
  function call(data) {
23
- return (_a) => __awaiter(this, [_a], void 0, function* ({ connection }) {
24
- const acceptedOfferRepo = new acceptedOffer_1.AcceptedOfferRepo(connection);
28
+ return (_a) => __awaiter(this, [_a], void 0, function* ({ connection, redisClient }) {
29
+ if (redisClient === undefined) {
30
+ throw new factory.errors.Argument('settings', 'redisClient required');
31
+ }
25
32
  const actionRepo = new action_1.ActionRepo(connection);
26
- const assetTransactionRepo = new assetTransaction_1.AssetTransactionRepo(connection);
27
- const orderRepo = new order_1.OrderRepo(connection);
28
33
  const actionAttributes = {
29
34
  agent: { id: data.project.id, typeOf: factory.organizationType.Project },
30
35
  object: data.object,
@@ -32,20 +37,33 @@ function call(data) {
32
37
  typeOf: factory.actionType.CheckAction
33
38
  };
34
39
  const action = yield actionRepo.start(actionAttributes);
40
+ const objectTypeOf = data.object.typeOf;
35
41
  try {
36
- switch (data.object.typeOf) {
42
+ switch (objectTypeOf) {
37
43
  case factory.order.OrderType.Order:
38
44
  yield (0, validateOrder_1.validateOrder)({
39
45
  orderNumber: data.object.orderNumber,
40
46
  project: { id: data.project.id }
41
47
  })({
42
- acceptedOffer: acceptedOfferRepo,
43
- assetTransaction: assetTransactionRepo,
44
- order: orderRepo
48
+ acceptedOffer: new acceptedOffer_1.AcceptedOfferRepo(connection),
49
+ assetTransaction: new assetTransaction_1.AssetTransactionRepo(connection),
50
+ order: new order_1.OrderRepo(connection),
51
+ setting: new setting_1.SettingRepo(connection),
52
+ task: new task_1.TaskRepo(connection)
53
+ });
54
+ break;
55
+ // support ScreeningEvent(2025-05-01~)
56
+ case factory.eventType.ScreeningEvent:
57
+ yield (0, validateEvent_1.validateEvent)({
58
+ id: data.object.id,
59
+ project: { id: data.project.id }
60
+ })({
61
+ event: new event_1.EventRepo(connection),
62
+ stockHolder: new stockHolder_1.StockHolderRepo(redisClient, connection)
45
63
  });
46
64
  break;
47
65
  default:
48
- throw new factory.errors.NotImplemented(`${data.object.typeOf} not implemented`);
66
+ throw new factory.errors.NotImplemented(`${objectTypeOf} not implemented`);
49
67
  }
50
68
  }
51
69
  catch (error) {
@@ -0,0 +1,11 @@
1
+ import type { EventRepo } from '../../repo/event';
2
+ import type { StockHolderRepo } from '../../repo/stockHolder';
3
+ export declare function validateEvent(params: {
4
+ id: string;
5
+ project: {
6
+ id: string;
7
+ };
8
+ }): (repos: {
9
+ event: EventRepo;
10
+ stockHolder: StockHolderRepo;
11
+ }) => Promise<void>;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.validateEvent = validateEvent;
13
+ function validateEvent(params) {
14
+ return (repos) => __awaiter(this, void 0, void 0, function* () {
15
+ const event = yield repos.event.projectEventFieldsById({ id: params.id }, ['startDate']);
16
+ // tslint:disable-next-line:no-console
17
+ console.log('conflicted?', params.project.id, event.id, event.startDate);
18
+ yield repos.stockHolder.checkIfConflicted({
19
+ eventId: event.id,
20
+ startDate: event.startDate
21
+ });
22
+ });
23
+ }
@@ -1,6 +1,8 @@
1
1
  import type { AcceptedOfferRepo } from '../../repo/acceptedOffer';
2
2
  import type { AssetTransactionRepo } from '../../repo/assetTransaction';
3
3
  import type { OrderRepo } from '../../repo/order';
4
+ import type { SettingRepo } from '../../repo/setting';
5
+ import type { TaskRepo } from '../../repo/task';
4
6
  export declare function validateOrder(params: {
5
7
  orderNumber: string;
6
8
  project: {
@@ -10,4 +12,6 @@ export declare function validateOrder(params: {
10
12
  acceptedOffer: AcceptedOfferRepo;
11
13
  assetTransaction: AssetTransactionRepo;
12
14
  order: OrderRepo;
15
+ setting: SettingRepo;
16
+ task: TaskRepo;
13
17
  }) => Promise<void>;
@@ -12,11 +12,35 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.validateOrder = validateOrder;
13
13
  // import * as createDebug from 'debug';
14
14
  const moment = require("moment");
15
+ const util = require("util");
15
16
  const factory = require("../../factory");
16
17
  const factory_1 = require("../offer/event/authorize/factory");
17
18
  const factory_2 = require("../offer/product/factory");
18
19
  const validateMovieTicket_1 = require("../transaction/placeOrder/confirm/validation/validateMovieTicket");
19
- // const debug = createDebug('chevre-domain:service:validation');
20
+ function createCheckEventTasks(params) {
21
+ const { project, reservationForIds } = params;
22
+ const runsAt = new Date();
23
+ return reservationForIds.map((reservationForId) => {
24
+ const object = { id: reservationForId, typeOf: factory.eventType.ScreeningEvent };
25
+ const data = {
26
+ object,
27
+ project: { id: project.id, typeOf: factory.organizationType.Project },
28
+ typeOf: factory.actionType.CheckAction
29
+ };
30
+ const description = util.format('%s:%s:%s:%s', project.id, factory.taskName.CheckResource, factory.eventType.ScreeningEvent, reservationForId);
31
+ return {
32
+ description,
33
+ project: { id: project.id, typeOf: factory.organizationType.Project },
34
+ name: factory.taskName.CheckResource,
35
+ status: factory.taskStatus.Ready,
36
+ runsAt,
37
+ remainingNumberOfTries: 3,
38
+ numberOfTried: 0,
39
+ executionResults: [],
40
+ data
41
+ };
42
+ });
43
+ }
20
44
  function validateOrder(params) {
21
45
  // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
22
46
  return (repos) => __awaiter(this, void 0, void 0, function* () {
@@ -192,5 +216,17 @@ function validateOrder(params) {
192
216
  throw new Error(`invalid ticketIdentifiers.length:${reservationReservedTicketIdentifiers.length} [expected:${acceptedOffers.length}]`);
193
217
  }
194
218
  }
219
+ // add check event task(2025-05-01~)
220
+ const setting = yield repos.setting.findOne({ project: { id: { $eq: '*' } } }, ['useMongoAsStockHolderProjects']);
221
+ const useMongoAsStockHolderProjects = setting === null || setting === void 0 ? void 0 : setting.useMongoAsStockHolderProjects;
222
+ if (Array.isArray(useMongoAsStockHolderProjects) && useMongoAsStockHolderProjects.includes(params.project.id)) {
223
+ const creatingCheckResourceTask = createCheckEventTasks({
224
+ project: { id: params.project.id },
225
+ reservationForIds
226
+ });
227
+ if (creatingCheckResourceTask.length > 0) {
228
+ yield repos.task.saveMany(creatingCheckResourceTask, { emitImmediately: true });
229
+ }
230
+ }
195
231
  });
196
232
  }
package/package.json CHANGED
@@ -11,8 +11,8 @@
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.48",
15
- "@cinerino/sdk": "10.21.0-alpha.30",
14
+ "@chevre/factory": "4.393.0-alpha.49",
15
+ "@cinerino/sdk": "10.21.0-alpha.33",
16
16
  "@motionpicture/coa-service": "9.6.0",
17
17
  "@motionpicture/gmo-service": "5.3.0",
18
18
  "@sendgrid/client": "8.1.4",
@@ -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.110"
116
+ "version": "22.9.0-alpha.112"
117
117
  }