@chevre/domain 20.2.0-alpha.20 → 20.2.0-alpha.21

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.
@@ -6,6 +6,7 @@ import { chevre } from '../../../../lib/index';
6
6
  // const project = { id: <string>process.env.PROJECT_ID };
7
7
  const EXCLUDED_PROJECT_ID = process.env.EXCLUDED_PROJECT_ID;
8
8
  const AGGREGATE_DAYS = Number(process.env.AGGREGATE_DAYS);
9
+ const AGGREGATE_CLIENT_IDS = (typeof process.env.AGGREGATE_CLIENT_IDS === 'string') ? process.env.AGGREGATE_CLIENT_IDS.split(',') : [];
9
10
 
10
11
  async function main() {
11
12
  await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
@@ -16,15 +17,16 @@ async function main() {
16
17
  const orderRepo = new chevre.repository.Order(mongoose.connection);
17
18
  const actionRepo = new chevre.repository.Action(mongoose.connection);
18
19
 
19
- await chevre.service.aggregation.system.aggregateAuthorizeOrderAction({
20
+ await chevre.service.aggregation.system.aggregatePlaceOrder({
20
21
  aggregationDays: AGGREGATE_DAYS,
21
- excludedProjectId: EXCLUDED_PROJECT_ID
22
+ excludedProjectId: EXCLUDED_PROJECT_ID,
23
+ clientIds: AGGREGATE_CLIENT_IDS
22
24
  })({
23
25
  agregation: aggregationRepo,
24
- action: actionRepo
26
+ transaction: transactionRepo
25
27
  });
26
28
 
27
- await chevre.service.aggregation.system.aggregateAuthorizeEventServiceOfferAction({
29
+ await chevre.service.aggregation.system.aggregateAuthorizeOrderAction({
28
30
  aggregationDays: AGGREGATE_DAYS,
29
31
  excludedProjectId: EXCLUDED_PROJECT_ID
30
32
  })({
@@ -32,7 +34,7 @@ async function main() {
32
34
  action: actionRepo
33
35
  });
34
36
 
35
- await chevre.service.aggregation.system.aggregateAuthorizePaymentAction({
37
+ await chevre.service.aggregation.system.aggregateAuthorizeEventServiceOfferAction({
36
38
  aggregationDays: AGGREGATE_DAYS,
37
39
  excludedProjectId: EXCLUDED_PROJECT_ID
38
40
  })({
@@ -40,7 +42,7 @@ async function main() {
40
42
  action: actionRepo
41
43
  });
42
44
 
43
- await chevre.service.aggregation.system.aggregateUseAction({
45
+ await chevre.service.aggregation.system.aggregateAuthorizePaymentAction({
44
46
  aggregationDays: AGGREGATE_DAYS,
45
47
  excludedProjectId: EXCLUDED_PROJECT_ID
46
48
  })({
@@ -48,12 +50,12 @@ async function main() {
48
50
  action: actionRepo
49
51
  });
50
52
 
51
- await chevre.service.aggregation.system.aggregatePlaceOrder({
53
+ await chevre.service.aggregation.system.aggregateUseAction({
52
54
  aggregationDays: AGGREGATE_DAYS,
53
55
  excludedProjectId: EXCLUDED_PROJECT_ID
54
56
  })({
55
57
  agregation: aggregationRepo,
56
- transaction: transactionRepo
58
+ action: actionRepo
57
59
  });
58
60
 
59
61
  await chevre.service.aggregation.system.aggregateOrder({
@@ -9,6 +9,10 @@ export declare enum AggregationType {
9
9
  AggregateReservation = "AggregateReservation",
10
10
  AggregateUseAction = "AggregateUseAction"
11
11
  }
12
+ export interface IAggregationByClient {
13
+ clientId: string;
14
+ aggregation: any;
15
+ }
12
16
  export interface IAggregation {
13
17
  typeOf: AggregationType;
14
18
  project: {
@@ -18,6 +22,7 @@ export interface IAggregation {
18
22
  aggregateDate: Date;
19
23
  aggregateDuration: string;
20
24
  aggregateStart: Date;
25
+ aggregationByClient?: IAggregationByClient[];
21
26
  }
22
27
  /**
23
28
  * 集計リポジトリ
@@ -30,12 +30,6 @@ export declare class MongoRepository {
30
30
  /**
31
31
  * 予約確定
32
32
  */
33
- confirm<T extends factory.reservationType>(params: {
34
- id: string;
35
- previousReservationStatus: factory.reservationStatusType;
36
- underName?: factory.reservation.IUnderName<T>;
37
- reservedTicket?: factory.reservation.ITicket;
38
- }): Promise<factory.reservation.IReservation<T>>;
39
33
  confirmByReservationNumber(params: {
40
34
  reservationNumber: string;
41
35
  previousReservationStatus: factory.reservationStatusType;
@@ -915,49 +915,54 @@ class MongoRepository {
915
915
  /**
916
916
  * 予約確定
917
917
  */
918
- confirm(params) {
919
- return __awaiter(this, void 0, void 0, function* () {
920
- const conditions = {
921
- _id: { $eq: String(params.id) },
922
- reservationStatus: { $eq: params.previousReservationStatus }
923
- };
924
- // 更新属性をwhitelist化(2022-06-13~)
925
- const update = Object.assign(Object.assign({
926
- // ...params,
927
- reservationStatus: factory.reservationStatusType.ReservationConfirmed, modifiedTime: new Date() }, (params.underName !== undefined) ? { underName: params.underName } : undefined), (params.reservedTicket !== undefined) ? { reservedTicket: params.reservedTicket } : undefined);
928
- // 以下値は更新しない(他処理で更新される可能性あり)
929
- // if (typeof update.checkedIn === 'boolean') {
930
- // delete update.checkedIn;
931
- // }
932
- // if (typeof update.attended === 'boolean') {
933
- // delete update.attended;
934
- // }
935
- const doc = yield this.reservationModel.findOneAndUpdate(conditions, update, { new: true })
936
- .select({ __v: 0, createdAt: 0, updatedAt: 0 })
937
- .exec();
938
- // NotFoundであれば状態確認
939
- if (doc === null) {
940
- const reservation = yield this.findById({ id: String(params.id) });
941
- if (reservation.reservationStatus === factory.reservationStatusType.ReservationConfirmed) {
942
- // すでに確定済の場合
943
- return reservation;
944
- }
945
- else {
946
- throw new factory.errors.Argument('id', `Reservation ${reservation.id} already changed -> ${reservation.reservationStatus}`);
947
- }
948
- }
949
- return doc.toObject();
950
- });
951
- }
918
+ // public async confirm<T extends factory.reservationType>(params: {
919
+ // id: string;
920
+ // previousReservationStatus: factory.reservationStatusType;
921
+ // underName?: factory.reservation.IUnderName<T>;
922
+ // }): Promise<factory.reservation.IReservation<T>> {
923
+ // const conditions = {
924
+ // _id: { $eq: String(params.id) },
925
+ // reservationStatus: { $eq: params.previousReservationStatus }
926
+ // };
927
+ // // 更新属性をwhitelist化(2022-06-13~)
928
+ // const update = {
929
+ // // previousReservationStatusを保管(2023-01-19~)
930
+ // previousReservationStatus: params.previousReservationStatus,
931
+ // reservationStatus: factory.reservationStatusType.ReservationConfirmed,
932
+ // modifiedTime: new Date(),
933
+ // ...(params.underName !== undefined) ? { underName: params.underName } : undefined
934
+ // };
935
+ // const doc = await this.reservationModel.findOneAndUpdate(
936
+ // conditions,
937
+ // update,
938
+ // { new: true }
939
+ // )
940
+ // .select({ __v: 0, createdAt: 0, updatedAt: 0 })
941
+ // .exec();
942
+ // // NotFoundであれば状態確認
943
+ // if (doc === null) {
944
+ // const reservation = await this.findById<T>({ id: String(params.id) });
945
+ // if (reservation.reservationStatus === factory.reservationStatusType.ReservationConfirmed) {
946
+ // // すでに確定済の場合
947
+ // return reservation;
948
+ // } else {
949
+ // throw new factory.errors.Argument(
950
+ // 'id',
951
+ // `Reservation ${reservation.id} already changed -> ${reservation.reservationStatus}`
952
+ // );
953
+ // }
954
+ // }
955
+ // return doc.toObject();
956
+ // }
952
957
  confirmByReservationNumber(params) {
953
958
  return __awaiter(this, void 0, void 0, function* () {
954
959
  const conditions = {
955
960
  reservationNumber: { $eq: String(params.reservationNumber) },
956
961
  reservationStatus: { $eq: params.previousReservationStatus }
957
962
  };
958
- const update = Object.assign({ reservationStatus: factory.reservationStatusType.ReservationConfirmed, modifiedTime: new Date() }, (params.underName !== undefined) ? { underName: params.underName } : undefined
959
- // ...(params.reservedTicket !== undefined) ? { reservedTicket: params.reservedTicket } : undefined
960
- );
963
+ const update = Object.assign({
964
+ // previousReservationStatusを保管(2023-01-19~)
965
+ previousReservationStatus: params.previousReservationStatus, reservationStatus: factory.reservationStatusType.ReservationConfirmed, modifiedTime: new Date() }, (params.underName !== undefined) ? { underName: params.underName } : undefined);
961
966
  yield this.reservationModel.updateMany(conditions, update)
962
967
  .exec();
963
968
  });
@@ -16,7 +16,7 @@ interface IStatus {
16
16
  status: factory.transactionStatusType;
17
17
  aggregation: IAggregationByStatus;
18
18
  }
19
- interface IAggregatePlaceOrder {
19
+ export interface IAggregatePlaceOrder {
20
20
  statuses: IStatus[];
21
21
  }
22
22
  /**
@@ -155,6 +155,7 @@ export declare class MongoRepository {
155
155
  startFrom: Date;
156
156
  startThrough: Date;
157
157
  typeOf: factory.transactionType;
158
+ clientId?: string;
158
159
  }): Promise<IAggregatePlaceOrder>;
159
160
  private agggregateByStatus;
160
161
  }
@@ -608,11 +608,19 @@ class MongoRepository {
608
608
  factory.transactionStatusType.Confirmed
609
609
  ].map((transactionStatus) => __awaiter(this, void 0, void 0, function* () {
610
610
  var _a, _b;
611
- const matchConditions = Object.assign({ startDate: {
611
+ const matchConditions = Object.assign(Object.assign({ startDate: {
612
612
  $gte: params.startFrom,
613
613
  $lte: params.startThrough
614
614
  }, typeOf: { $eq: params.typeOf }, status: { $eq: transactionStatus } }, (typeof ((_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$ne) === 'string')
615
615
  ? { 'project.id': { $ne: params.project.id.$ne } }
616
+ : undefined), (typeof params.clientId === 'string')
617
+ // customerIdentifierAll.push();
618
+ ? {
619
+ 'agent.identifier': {
620
+ $exists: true,
621
+ $all: [{ name: 'clientId', value: params.clientId }]
622
+ }
623
+ }
616
624
  : undefined);
617
625
  return this.agggregateByStatus({ matchConditions, status: transactionStatus });
618
626
  })));
@@ -9,6 +9,7 @@ import { MongoRepository as TransactionRepo } from '../../repo/transaction';
9
9
  declare function aggregatePlaceOrder(params: {
10
10
  aggregationDays: number;
11
11
  excludedProjectId?: string;
12
+ clientIds?: string[];
12
13
  }): (repos: {
13
14
  agregation: AggregationRepo;
14
15
  transaction: TransactionRepo;
@@ -44,7 +44,22 @@ function aggregatePlaceOrder(params) {
44
44
  typeOf: factory.transactionType.PlaceOrder
45
45
  });
46
46
  debug('aggregatePlaceOrder:result', aggregateResult, (_a = aggregateResult.statuses[0]) === null || _a === void 0 ? void 0 : _a.aggregation.percentilesDuration, startFrom);
47
- yield repos.agregation.saveAggregation(Object.assign({ typeOf: aggregation_1.AggregationType.AggregatePlaceOrder, project: { id: '*', typeOf: factory.organizationType.Project }, aggregateDuration, aggregateStart: startFrom, aggregateDate }, aggregateResult));
47
+ const aggregateResultsByClientId = [];
48
+ if (Array.isArray(params.clientIds)) {
49
+ for (const clientId of params.clientIds) {
50
+ aggregateResultsByClientId.push({
51
+ clientId,
52
+ aggregation: yield repos.transaction.aggregatePlaceOrder({
53
+ project: { id: { $ne: params.excludedProjectId } },
54
+ startFrom,
55
+ startThrough,
56
+ typeOf: factory.transactionType.PlaceOrder,
57
+ clientId
58
+ })
59
+ });
60
+ }
61
+ }
62
+ yield repos.agregation.saveAggregation(Object.assign({ typeOf: aggregation_1.AggregationType.AggregatePlaceOrder, project: { id: '*', typeOf: factory.organizationType.Project }, aggregateDuration, aggregateStart: startFrom, aggregateDate, aggregationByClient: aggregateResultsByClientId }, aggregateResult));
48
63
  }
49
64
  });
50
65
  }
@@ -468,7 +468,10 @@ function createPotentialActions(params) {
468
468
  underName
469
469
  }));
470
470
  });
471
- const reservationPackage = Object.assign({ reservationFor, reservationNumber: pendingReservations[0].reservationNumber, reservationStatus: pendingReservations[0].reservationStatus, subReservation: pendingReservations, typeOf: factory.reservationType.ReservationPackage }, (typeof (underName === null || underName === void 0 ? void 0 : underName.typeOf) === 'string') ? { underName } : undefined);
471
+ const reservationPackage = Object.assign({ reservationFor, reservationNumber: pendingReservations[0].reservationNumber, reservationStatus: pendingReservations[0].reservationStatus,
472
+ // 不要なので廃止(2023-01-19~)
473
+ // subReservation: pendingReservations,
474
+ typeOf: factory.reservationType.ReservationPackage }, (typeof (underName === null || underName === void 0 ? void 0 : underName.typeOf) === 'string') ? { underName } : undefined);
472
475
  reserveActionAttributes = [{
473
476
  project: transaction.project,
474
477
  typeOf: factory.actionType.ReserveAction,
@@ -37,17 +37,14 @@ function confirmReservation(actionAttributesList) {
37
37
  });
38
38
  }
39
39
  else {
40
+ // 廃止(2023-01-18)
41
+ throw new factory.errors.Forbidden(`${reservation.typeOf} not acceptable`);
40
42
  // 予約を確定状態に変更する
41
- // reservation = await repos.reservation.confirm<factory.reservationType.EventReservation>({
42
- yield repos.reservation.confirm({
43
- // 更新属性をwhitelist化(2022-06-13~)
44
- // ...actionAttributes.object,
45
- id: reservation.id,
46
- previousReservationStatus: reservation.reservationStatus,
47
- underName: reservation.underName
48
- // issuedThroughは予約取引開始時に確定しているので更新不要(2022-12-21~)
49
- // reservedTicket: reservation.reservedTicket
50
- });
43
+ // await repos.reservation.confirm<factory.reservationType.EventReservation>({
44
+ // id: reservation.id,
45
+ // previousReservationStatus: reservation.reservationStatus,
46
+ // underName: reservation.underName
47
+ // });
51
48
  // _idは不要であり、存在すると予期せぬ影響を及ぼす可能性がある
52
49
  // delete (<any>reservation)._id;
53
50
  // confirmedReservations.push(reservation);
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  }
10
10
  ],
11
11
  "dependencies": {
12
- "@chevre/factory": "4.282.0-alpha.0",
12
+ "@chevre/factory": "4.282.0",
13
13
  "@cinerino/sdk": "3.135.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.20"
123
+ "version": "20.2.0-alpha.21"
124
124
  }