@chevre/domain 21.9.0-alpha.1 → 21.9.0-alpha.11

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.
Files changed (27) hide show
  1. package/example/src/chevre/searchEventTicketOffers.ts +1 -0
  2. package/example/src/chevre/{searchOfferCatalogs.ts → searchOfferCatalogItems.ts} +15 -5
  3. package/example/src/chevre/searchOffersByCatalog.ts +9 -2
  4. package/lib/chevre/repo/aggregateOffer.d.ts +89 -3
  5. package/lib/chevre/repo/aggregateOffer.js +90 -0
  6. package/lib/chevre/repo/mongoose/schemas/offerCatalogItem.d.ts +92 -0
  7. package/lib/chevre/repo/mongoose/schemas/offerCatalogItem.js +55 -0
  8. package/lib/chevre/repo/offer.d.ts +8 -12
  9. package/lib/chevre/repo/offer.js +96 -56
  10. package/lib/chevre/repo/offerCatalog.d.ts +0 -4
  11. package/lib/chevre/repo/offerCatalog.js +0 -8
  12. package/lib/chevre/repo/offerCatalogItem.d.ts +47 -0
  13. package/lib/chevre/repo/offerCatalogItem.js +231 -0
  14. package/lib/chevre/repository.d.ts +3 -0
  15. package/lib/chevre/repository.js +5 -1
  16. package/lib/chevre/service/aggregation/event/findEventOffers.js +3 -1
  17. package/lib/chevre/service/assetTransaction/reserve.js +1 -0
  18. package/lib/chevre/service/offer/event/authorize.js +1 -0
  19. package/lib/chevre/service/offer/event/searchEventTicketOffers.d.ts +1 -6
  20. package/lib/chevre/service/offer/event/searchEventTicketOffers.js +7 -2
  21. package/lib/chevre/service/offer/product/searchProductOffers.js +5 -2
  22. package/lib/chevre/service/task/onResourceUpdated/onResourceDeleted.d.ts +2 -0
  23. package/lib/chevre/service/task/onResourceUpdated/onResourceDeleted.js +23 -7
  24. package/lib/chevre/service/task/onResourceUpdated/syncOfferCatalog.d.ts +3 -0
  25. package/lib/chevre/service/task/onResourceUpdated/syncOfferCatalog.js +109 -24
  26. package/lib/chevre/service/task/onResourceUpdated.js +4 -1
  27. package/package.json +3 -3
@@ -28,6 +28,7 @@ async function main() {
28
28
  const { ticketOffers } = await chevre.service.offer.event.searchEventTicketOffers({
29
29
  event: { id: 'ale6qiedq' },
30
30
  onlyValid: true,
31
+ priceSpecification: {},
31
32
  validateOfferRateLimit: true,
32
33
  addSortIndex: true,
33
34
  useIncludeInDataCatalog: true,
@@ -9,23 +9,33 @@ mongoose.Model.on('index', (...args) => {
9
9
  });
10
10
 
11
11
  async function main() {
12
- await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: true });
12
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
13
13
 
14
- const catalogRepo = new chevre.repository.OfferCatalog(mongoose.connection);
14
+ const catalogItemRepo = new chevre.repository.OfferCatalogItem(mongoose.connection);
15
15
 
16
16
  console.log('searching...');
17
- const catalogs = await catalogRepo.search(
17
+ const catalogs = await catalogItemRepo.search(
18
18
  {
19
19
  project: { id: { $eq: PROJECT_ID } },
20
- identifier: { $eq: '0001' },
21
20
  sort: { identifier: chevre.factory.sortType.Descending },
22
21
  limit: 2,
23
22
  page: 1,
24
23
  itemListElement: { typeOf: { $eq: 'Offer' } }
24
+ // id: { $in: ['xxx'] }
25
25
  }
26
26
  );
27
- console.log('catalogs found', catalogs.map((catalog) => `${catalog.identifier} ${catalog.numberOfItems} ${catalog.itemListElementTypeOf}`));
27
+ console.log(catalogs[0]?.id, typeof catalogs[0]?.id);
28
+ console.log('catalogs found', catalogs.map((catalog) => `${catalog.id} ${catalog.identifier} ${catalog.numberOfItems} ${catalog.itemListElementTypeOf}`));
28
29
  console.log(catalogs.length);
30
+
31
+ const numCatalogs = await catalogItemRepo.count(
32
+ {
33
+ project: { id: { $eq: PROJECT_ID } },
34
+ itemListElement: { typeOf: { $eq: 'Offer' } }
35
+ // id: { $in: ['xxx'] }
36
+ }
37
+ );
38
+ console.log('numCatalogs:', numCatalogs);
29
39
  }
30
40
 
31
41
  main()
@@ -14,10 +14,17 @@ async function main() {
14
14
  page: 1,
15
15
  // ids: ['xx', 'xxx', '1001', '901'],
16
16
  subOfferCatalog: {
17
- id: 'xxx'
17
+ id: '0001',
18
+ isOfferCatalogItem: false
18
19
  },
19
20
  excludeAppliesToMovieTicket: false,
20
- useIncludeInDataCatalog: true
21
+ useIncludeInDataCatalog: false,
22
+ priceSpecification: {
23
+ // appliesToMovieTicket: {
24
+ // serviceOutput: { typeOf: { $eq: 'SurfRock' } },
25
+ // serviceType: { $exists: true }
26
+ // }
27
+ }
21
28
  });
22
29
  // console.log(offers);
23
30
  console.log(offers.map((offer) => {
@@ -11,18 +11,19 @@ export type IUnitPriceOfferFromAggregateOffer = factory.unitPriceOffer.IUnitPric
11
11
  id: string;
12
12
  };
13
13
  };
14
+ type ISearchConditions = factory.unitPriceOffer.ISearchConditions;
14
15
  /**
15
16
  * 集計オファーリポジトリ
16
17
  */
17
18
  export declare class MongoRepository {
18
19
  private readonly aggregateOfferModel;
19
20
  constructor(connection: Connection);
20
- static CREATE_AGGREGATE_OFFERS_MATCH_CONDITIONS(params: factory.unitPriceOffer.ISearchConditions): IMatchStage[];
21
+ static CREATE_AGGREGATE_OFFERS_MATCH_CONDITIONS(params: ISearchConditions): IMatchStage[];
21
22
  static CREATE_AGGREGATE_OFFERS_PROJECTION(params: IProjection): {
22
23
  [field: string]: AnyExpression;
23
24
  };
24
- count(params: Omit<factory.unitPriceOffer.ISearchConditions, 'limit' | 'page' | 'sort'>): Promise<number>;
25
- search(params: factory.unitPriceOffer.ISearchConditions, projection?: IProjection): Promise<factory.aggregateOffer.IAggregateOffer[]>;
25
+ count(params: Omit<ISearchConditions, 'limit' | 'page' | 'sort'>): Promise<number>;
26
+ search(params: ISearchConditions, projection?: IProjection): Promise<factory.aggregateOffer.IAggregateOffer[]>;
26
27
  pushIncludedInDataCatalog(params: {
27
28
  project: {
28
29
  id: string;
@@ -58,5 +59,90 @@ export declare class MongoRepository {
58
59
  };
59
60
  };
60
61
  }): Promise<void>;
62
+ pushIncludedInOfferCatalogItem(params: {
63
+ project: {
64
+ id: string;
65
+ };
66
+ id: {
67
+ $in: string[];
68
+ };
69
+ $push: {
70
+ includedInOfferCatalogItem: {
71
+ /**
72
+ * サブカタログID
73
+ */
74
+ id: {
75
+ $eq: string;
76
+ };
77
+ includedInDataCatalog: {
78
+ /**
79
+ * カタログID
80
+ */
81
+ id: {
82
+ $eq: string;
83
+ };
84
+ };
85
+ };
86
+ };
87
+ }): Promise<void>;
88
+ /**
89
+ * サブカタログを含み、かつ、新しいカタログに含まれない集計オファーからサブカタログを除外
90
+ */
91
+ pullIncludedInOfferCatalogItem(params: {
92
+ project: {
93
+ id: string;
94
+ };
95
+ id?: {
96
+ $nin?: string[];
97
+ };
98
+ $pull: {
99
+ includedInOfferCatalogItem: {
100
+ $elemMatch: {
101
+ /**
102
+ * サブカタログID
103
+ */
104
+ id: {
105
+ $eq: string;
106
+ };
107
+ includedInDataCatalog: {
108
+ /**
109
+ * カタログID
110
+ */
111
+ id: {
112
+ $eq: string;
113
+ };
114
+ };
115
+ };
116
+ };
117
+ };
118
+ }): Promise<void>;
119
+ /**
120
+ * カタログに属するサブカタログを全て除外する
121
+ */
122
+ pullIncludedInOfferCatalogItemByCatalogId(params: {
123
+ project: {
124
+ id: string;
125
+ };
126
+ $pull: {
127
+ includedInOfferCatalogItem: {
128
+ $elemMatch: {
129
+ includedInDataCatalog: {
130
+ /**
131
+ * カタログID
132
+ */
133
+ id: {
134
+ $eq: string;
135
+ };
136
+ };
137
+ };
138
+ };
139
+ };
140
+ }): Promise<void>;
141
+ deleteById(params: {
142
+ project: {
143
+ id: string;
144
+ };
145
+ id: string;
146
+ }): Promise<void>;
61
147
  }
62
148
  export {};
@@ -558,5 +558,95 @@ class MongoRepository {
558
558
  .exec();
559
559
  });
560
560
  }
561
+ pushIncludedInOfferCatalogItem(params) {
562
+ return __awaiter(this, void 0, void 0, function* () {
563
+ if (!Array.isArray(params.id.$in) || params.id.$in.length === 0) {
564
+ return;
565
+ }
566
+ // if (params.$push.includedInOfferCatalogItem.$each.length === 0) {
567
+ // return;
568
+ // }
569
+ const newIncludedInOfferCatalogItem = {
570
+ id: params.$push.includedInOfferCatalogItem.id.$eq,
571
+ typeOf: 'OfferCatalog',
572
+ includedInDataCatalog: { id: params.$push.includedInOfferCatalogItem.includedInDataCatalog.id.$eq, typeOf: 'OfferCatalog' }
573
+ };
574
+ const result = yield this.aggregateOfferModel.updateMany({
575
+ 'project.id': { $eq: params.project.id },
576
+ _id: { $in: params.id.$in }
577
+ }, {
578
+ // newIncludedInOfferCatalogItemsのユニークネスを保証する
579
+ $addToSet: { 'offers.$[].includedInOfferCatalogItem': newIncludedInOfferCatalogItem }
580
+ })
581
+ .exec();
582
+ debug('result', result);
583
+ });
584
+ }
585
+ /**
586
+ * サブカタログを含み、かつ、新しいカタログに含まれない集計オファーからサブカタログを除外
587
+ */
588
+ pullIncludedInOfferCatalogItem(params) {
589
+ var _a;
590
+ return __awaiter(this, void 0, void 0, function* () {
591
+ const idNin = (_a = params.id) === null || _a === void 0 ? void 0 : _a.$nin;
592
+ yield this.aggregateOfferModel.updateMany(Object.assign({ 'project.id': { $eq: params.project.id }, 'offers.includedInOfferCatalogItem': {
593
+ $elemMatch: {
594
+ id: { $exists: true, $eq: params.$pull.includedInOfferCatalogItem.$elemMatch.id.$eq },
595
+ 'includedInDataCatalog.id': {
596
+ $exists: true,
597
+ $eq: params.$pull.includedInOfferCatalogItem.$elemMatch.includedInDataCatalog.id.$eq
598
+ }
599
+ }
600
+ } }, (Array.isArray(idNin)) ? { _id: { $nin: idNin } } : undefined), {
601
+ $pull: {
602
+ 'offers.$[].includedInOfferCatalogItem': {
603
+ id: { $exists: true, $eq: params.$pull.includedInOfferCatalogItem.$elemMatch.id.$eq },
604
+ 'includedInDataCatalog.id': {
605
+ $exists: true,
606
+ $eq: params.$pull.includedInOfferCatalogItem.$elemMatch.includedInDataCatalog.id.$eq
607
+ }
608
+ }
609
+ }
610
+ })
611
+ .exec();
612
+ });
613
+ }
614
+ /**
615
+ * カタログに属するサブカタログを全て除外する
616
+ */
617
+ pullIncludedInOfferCatalogItemByCatalogId(params) {
618
+ return __awaiter(this, void 0, void 0, function* () {
619
+ yield this.aggregateOfferModel.updateMany({
620
+ 'project.id': { $eq: params.project.id },
621
+ 'offers.includedInOfferCatalogItem': {
622
+ $elemMatch: {
623
+ 'includedInDataCatalog.id': {
624
+ $exists: true,
625
+ $eq: params.$pull.includedInOfferCatalogItem.$elemMatch.includedInDataCatalog.id.$eq
626
+ }
627
+ }
628
+ }
629
+ }, {
630
+ $pull: {
631
+ 'offers.$[].includedInOfferCatalogItem': {
632
+ 'includedInDataCatalog.id': {
633
+ $exists: true,
634
+ $eq: params.$pull.includedInOfferCatalogItem.$elemMatch.includedInDataCatalog.id.$eq
635
+ }
636
+ }
637
+ }
638
+ })
639
+ .exec();
640
+ });
641
+ }
642
+ deleteById(params) {
643
+ return __awaiter(this, void 0, void 0, function* () {
644
+ yield this.aggregateOfferModel.findOneAndRemove({
645
+ _id: { $eq: params.id },
646
+ 'project.id': { $eq: params.project.id }
647
+ }, { projection: { _id: 1 } })
648
+ .exec();
649
+ });
650
+ }
561
651
  }
562
652
  exports.MongoRepository = MongoRepository;
@@ -0,0 +1,92 @@
1
+ /// <reference types="mongoose/types/aggregate" />
2
+ /// <reference types="mongoose/types/callback" />
3
+ /// <reference types="mongoose/types/collection" />
4
+ /// <reference types="mongoose/types/connection" />
5
+ /// <reference types="mongoose/types/cursor" />
6
+ /// <reference types="mongoose/types/document" />
7
+ /// <reference types="mongoose/types/error" />
8
+ /// <reference types="mongoose/types/expressions" />
9
+ /// <reference types="mongoose/types/helpers" />
10
+ /// <reference types="mongoose/types/middlewares" />
11
+ /// <reference types="mongoose/types/indexes" />
12
+ /// <reference types="mongoose/types/models" />
13
+ /// <reference types="mongoose/types/mongooseoptions" />
14
+ /// <reference types="mongoose/types/pipelinestage" />
15
+ /// <reference types="mongoose/types/populate" />
16
+ /// <reference types="mongoose/types/query" />
17
+ /// <reference types="mongoose/types/schemaoptions" />
18
+ /// <reference types="mongoose/types/schematypes" />
19
+ /// <reference types="mongoose/types/session" />
20
+ /// <reference types="mongoose/types/types" />
21
+ /// <reference types="mongoose/types/utility" />
22
+ /// <reference types="mongoose/types/validation" />
23
+ /// <reference types="mongoose/types/virtuals" />
24
+ /// <reference types="mongoose/types/inferschematype" />
25
+ import { Schema } from 'mongoose';
26
+ declare const modelName = "OfferCatalogItem";
27
+ /**
28
+ * オファーカタログアイテムスキーマ
29
+ */
30
+ declare const schema: Schema<any, import("mongoose").Model<any, any, any, any, any, any>, {}, {}, {}, {}, {
31
+ collection: string;
32
+ id: true;
33
+ read: string;
34
+ writeConcern: import("mongodb").WriteConcern;
35
+ strict: true;
36
+ strictQuery: false;
37
+ timestamps: {
38
+ createdAt: string;
39
+ updatedAt: string;
40
+ };
41
+ toJSON: {
42
+ getters: false;
43
+ virtuals: false;
44
+ minimize: false;
45
+ versionKey: false;
46
+ };
47
+ toObject: {
48
+ getters: false;
49
+ virtuals: true;
50
+ minimize: false;
51
+ versionKey: false;
52
+ };
53
+ }, {
54
+ typeOf: string;
55
+ additionalProperty: any[];
56
+ identifier: string;
57
+ itemListElement: any[];
58
+ name?: any;
59
+ project?: any;
60
+ alternateName?: any;
61
+ description?: any;
62
+ itemOffered?: any;
63
+ dateSynced?: Date | undefined;
64
+ relatedOffer?: any;
65
+ }, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
66
+ typeOf: string;
67
+ additionalProperty: any[];
68
+ identifier: string;
69
+ itemListElement: any[];
70
+ name?: any;
71
+ project?: any;
72
+ alternateName?: any;
73
+ description?: any;
74
+ itemOffered?: any;
75
+ dateSynced?: Date | undefined;
76
+ relatedOffer?: any;
77
+ }>> & Omit<import("mongoose").FlatRecord<{
78
+ typeOf: string;
79
+ additionalProperty: any[];
80
+ identifier: string;
81
+ itemListElement: any[];
82
+ name?: any;
83
+ project?: any;
84
+ alternateName?: any;
85
+ description?: any;
86
+ itemOffered?: any;
87
+ dateSynced?: Date | undefined;
88
+ relatedOffer?: any;
89
+ }> & {
90
+ _id: import("mongoose").Types.ObjectId;
91
+ }, never>>;
92
+ export { modelName, schema };
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.schema = exports.modelName = void 0;
4
+ const mongoose_1 = require("mongoose");
5
+ const writeConcern_1 = require("../writeConcern");
6
+ const modelName = 'OfferCatalogItem';
7
+ exports.modelName = modelName;
8
+ /**
9
+ * オファーカタログアイテムスキーマ
10
+ */
11
+ const schema = new mongoose_1.Schema({
12
+ project: mongoose_1.SchemaTypes.Mixed,
13
+ identifier: {
14
+ type: String,
15
+ required: true
16
+ },
17
+ name: mongoose_1.SchemaTypes.Mixed,
18
+ description: mongoose_1.SchemaTypes.Mixed,
19
+ alternateName: mongoose_1.SchemaTypes.Mixed,
20
+ typeOf: {
21
+ type: String,
22
+ required: true
23
+ },
24
+ itemListElement: [mongoose_1.SchemaTypes.Mixed],
25
+ itemOffered: mongoose_1.SchemaTypes.Mixed,
26
+ additionalProperty: [mongoose_1.SchemaTypes.Mixed],
27
+ dateSynced: Date,
28
+ relatedOffer: mongoose_1.SchemaTypes.Mixed
29
+ }, {
30
+ collection: 'offerCatalogItems',
31
+ id: true,
32
+ read: 'primaryPreferred',
33
+ writeConcern: writeConcern_1.writeConcern,
34
+ strict: true,
35
+ strictQuery: false,
36
+ timestamps: {
37
+ createdAt: 'createdAt',
38
+ updatedAt: 'updatedAt'
39
+ },
40
+ toJSON: {
41
+ getters: false,
42
+ virtuals: false,
43
+ minimize: false,
44
+ versionKey: false
45
+ },
46
+ toObject: {
47
+ getters: false,
48
+ virtuals: true,
49
+ minimize: false,
50
+ versionKey: false
51
+ }
52
+ });
53
+ exports.schema = schema;
54
+ schema.index({ createdAt: 1 }, { name: 'searchByCreatedAt' });
55
+ schema.index({ updatedAt: 1 }, { name: 'searchByUpdatedAt' });
@@ -17,6 +17,7 @@ export type IUnitPriceOfferFromAggregateOffer = factory.unitPriceOffer.IUnitPric
17
17
  export declare class MongoRepository {
18
18
  private readonly aggregateOfferModel;
19
19
  private readonly offerCatalogModel;
20
+ private readonly offerCatalogItemModel;
20
21
  constructor(connection: Connection);
21
22
  static CREATE_AGGREGATE_OFFERS_MATCH_CONDITIONS(params: Omit<factory.unitPriceOffer.ISearchConditions, 'limit' | 'page' | 'sort'>): IMatchStage[];
22
23
  static CREATE_AGGREGATE_OFFERS_PROJECTION(params: IProjection): {
@@ -32,6 +33,7 @@ export declare class MongoRepository {
32
33
  * サブカタログID
33
34
  */
34
35
  id: string;
36
+ isOfferCatalogItem: boolean;
35
37
  };
36
38
  projection?: IProjection;
37
39
  }): Promise<{
@@ -51,6 +53,7 @@ export declare class MongoRepository {
51
53
  * サブカタログID
52
54
  */
53
55
  id: string;
56
+ isOfferCatalogItem: boolean;
54
57
  };
55
58
  availableAtOrFrom?: {
56
59
  id?: string;
@@ -74,12 +77,17 @@ export declare class MongoRepository {
74
77
  * サブカタログID
75
78
  */
76
79
  id: string;
80
+ isOfferCatalogItem: boolean;
77
81
  };
78
82
  availableAtOrFrom?: {
79
83
  id?: string;
80
84
  };
81
85
  unacceptedPaymentMethod?: string[];
82
86
  excludeAppliesToMovieTicket: boolean;
87
+ /**
88
+ * 適用決済カード条件
89
+ */
90
+ priceSpecification: Pick<factory.unitPriceOffer.IPriceSpecificationSearchConditions, 'appliesToMovieTicket'>;
83
91
  onlyValid?: boolean;
84
92
  useIncludeInDataCatalog: boolean;
85
93
  limit?: number;
@@ -111,12 +119,6 @@ export declare class MongoRepository {
111
119
  limit?: number;
112
120
  page?: number;
113
121
  }): Promise<Pick<factory.priceSpecification.unitPrice.IAppliesToMovieTicket, 'serviceOutput'>[]>;
114
- findAggregateOfferById(params: {
115
- project: {
116
- id: string;
117
- };
118
- id: string;
119
- }): Promise<factory.aggregateOffer.IAggregateOffer>;
120
122
  count(params: Omit<factory.unitPriceOffer.ISearchConditions, 'limit' | 'page' | 'sort'>): Promise<number>;
121
123
  search(params: factory.unitPriceOffer.ISearchConditions, projection?: IProjection): Promise<IUnitPriceOfferFromAggregateOffer[]>;
122
124
  save(params: factory.unitPriceOffer.IUnitPriceOffer & {
@@ -144,12 +146,6 @@ export declare class MongoRepository {
144
146
  };
145
147
  };
146
148
  }): Promise<import("mongodb").UpdateResult | undefined>;
147
- deleteById(params: {
148
- project: {
149
- id: string;
150
- };
151
- id: string;
152
- }): Promise<void>;
153
149
  /**
154
150
  * サブカタログから集計オファーIDリストを検索する
155
151
  */