@chevre/domain 21.8.0-alpha.30 → 21.8.0-alpha.32
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.
- package/example/src/chevre/migrateAggregateOffers.ts +34 -17
- package/example/src/chevre/searchOffersByCatalog.ts +1 -2
- package/example/src/chevre/searchOffersFromAggregateOffer.ts +162 -0
- package/lib/chevre/repo/mongoose/schemas/aggregateOffer.js +134 -0
- package/lib/chevre/repo/offer.d.ts +20 -2
- package/lib/chevre/repo/offer.js +493 -25
- package/lib/chevre/service/aggregation/event/aggregateScreeningEvent.js +2 -2
- package/lib/chevre/service/aggregation/event/aggregateUseActionsOnEvent.js +2 -2
- package/lib/chevre/service/offer/event/searchEventTicketOffers.js +2 -2
- package/lib/chevre/service/offer/product/searchProductOffers.js +1 -1
- package/package.json +1 -1
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
// tslint:disable:no-console
|
|
2
2
|
import * as mongoose from 'mongoose';
|
|
3
|
+
import * as util from 'util';
|
|
3
4
|
|
|
4
5
|
import { chevre } from '../../../lib/index';
|
|
5
6
|
|
|
6
|
-
const project = { id: String(process.env.PROJECT_ID) };
|
|
7
|
+
// const project = { id: String(process.env.PROJECT_ID) };
|
|
7
8
|
|
|
8
9
|
// tslint:disable-next-line:max-func-body-length
|
|
9
10
|
async function main() {
|
|
@@ -13,12 +14,14 @@ async function main() {
|
|
|
13
14
|
|
|
14
15
|
const cursor = offerRepo.getCursor(
|
|
15
16
|
{
|
|
16
|
-
'project.id': { $eq: project.id }
|
|
17
|
+
// 'project.id': { $eq: project.id }
|
|
17
18
|
},
|
|
18
19
|
{
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
__v: 0,
|
|
21
|
+
createdAt: 0,
|
|
22
|
+
updatedAt: 0,
|
|
23
|
+
offers: 0,
|
|
24
|
+
availableAddOn: 0
|
|
22
25
|
}
|
|
23
26
|
);
|
|
24
27
|
console.log('offers found');
|
|
@@ -27,23 +30,37 @@ async function main() {
|
|
|
27
30
|
let updateCount = 0;
|
|
28
31
|
await cursor.eachAsync(async (doc) => {
|
|
29
32
|
i += 1;
|
|
30
|
-
const unitPriceOffer
|
|
31
|
-
chevre.factory.unitPriceOffer.IUnitPriceOffer
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
const { _id, ...unitPriceOffer } =
|
|
34
|
+
<chevre.factory.unitPriceOffer.IUnitPriceOffer & { _id: string }>doc.toObject();
|
|
35
|
+
|
|
36
|
+
let alreadyMigrated = false;
|
|
37
|
+
try {
|
|
38
|
+
const aggregateOffer = await offerRepo.findAggregateOfferById({
|
|
39
|
+
project: { id: unitPriceOffer.project.id },
|
|
40
|
+
id: String(unitPriceOffer.id)
|
|
41
|
+
});
|
|
42
|
+
const offerByAggregateOffer = aggregateOffer.offers.shift();
|
|
43
|
+
// alreadyMigrated = true;
|
|
44
|
+
console.log(unitPriceOffer, offerByAggregateOffer);
|
|
45
|
+
if (util.isDeepStrictEqual(unitPriceOffer, offerByAggregateOffer)) {
|
|
46
|
+
alreadyMigrated = true;
|
|
47
|
+
}
|
|
48
|
+
} catch (error) {
|
|
49
|
+
// no op
|
|
50
|
+
}
|
|
34
51
|
|
|
35
|
-
const alreadyMigrated = false;
|
|
36
52
|
if (alreadyMigrated) {
|
|
37
53
|
console.log('already exist.', unitPriceOffer.project.id, unitPriceOffer.id, unitPriceOffer.identifier, i);
|
|
38
54
|
} else {
|
|
39
55
|
console.log('updating...', unitPriceOffer.project.id, unitPriceOffer.id, unitPriceOffer.identifier, i);
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
56
|
+
await offerRepo.saveSyncTask({
|
|
57
|
+
project: { id: unitPriceOffer.project.id },
|
|
58
|
+
id: { $in: [String(unitPriceOffer.id)] },
|
|
59
|
+
identifier: { $in: [] },
|
|
60
|
+
isDeleted: false,
|
|
61
|
+
typeOf: chevre.factory.offerType.Offer,
|
|
62
|
+
options: { emitImmediately: false }
|
|
63
|
+
});
|
|
47
64
|
updateCount += 1;
|
|
48
65
|
console.log('updated.', unitPriceOffer.project.id, unitPriceOffer.id, unitPriceOffer.identifier, i);
|
|
49
66
|
}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
import * as mongoose from 'mongoose';
|
|
3
|
+
|
|
4
|
+
import { chevre } from '../../../lib/index';
|
|
5
|
+
|
|
6
|
+
// tslint:disable-next-line:max-func-body-length
|
|
7
|
+
async function main() {
|
|
8
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: true });
|
|
9
|
+
|
|
10
|
+
const offerRepo = new chevre.repository.Offer(mongoose.connection);
|
|
11
|
+
|
|
12
|
+
const offers = await offerRepo.searchFromAggregateOffer(
|
|
13
|
+
{
|
|
14
|
+
limit: 5,
|
|
15
|
+
page: 1,
|
|
16
|
+
sort: { 'priceSpecification.price': 1 },
|
|
17
|
+
project: { id: { $eq: String(process.env.PROJECT_ID) } },
|
|
18
|
+
availability: { $eq: chevre.factory.itemAvailability.InStock },
|
|
19
|
+
addOn: {
|
|
20
|
+
itemOffered: {
|
|
21
|
+
/**
|
|
22
|
+
* アドオンプロダクトID
|
|
23
|
+
*/
|
|
24
|
+
id: {
|
|
25
|
+
// $eq: ''
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
availableAtOrFrom: {
|
|
30
|
+
id: {
|
|
31
|
+
// $eq: ''
|
|
32
|
+
// $in: string[]
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
eligibleMembershipType: {
|
|
36
|
+
/**
|
|
37
|
+
* 適用メンバーシップ区分
|
|
38
|
+
*/
|
|
39
|
+
codeValue: {
|
|
40
|
+
// $eq: 'Permit'
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
eligibleMonetaryAmount: {
|
|
44
|
+
/**
|
|
45
|
+
* 適用通貨区分
|
|
46
|
+
*/
|
|
47
|
+
currency: {
|
|
48
|
+
// $eq: 'Point'
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
eligibleSeatingType: {
|
|
52
|
+
/**
|
|
53
|
+
* 適用座席区分
|
|
54
|
+
*/
|
|
55
|
+
codeValue: {
|
|
56
|
+
// $eq: ''
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
hasMerchantReturnPolicy: {
|
|
60
|
+
id: {
|
|
61
|
+
// $eq: ''
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
id: {
|
|
65
|
+
// $eq: '1001'
|
|
66
|
+
// $in: string[];
|
|
67
|
+
},
|
|
68
|
+
identifier: {
|
|
69
|
+
// $eq: '1001'
|
|
70
|
+
// $in: string[];
|
|
71
|
+
// $regex: '003'
|
|
72
|
+
},
|
|
73
|
+
name: {
|
|
74
|
+
// $regex: ''
|
|
75
|
+
},
|
|
76
|
+
priceSpecification: {
|
|
77
|
+
appliesToMovieTicket: {
|
|
78
|
+
/**
|
|
79
|
+
* 適用決済カード区分
|
|
80
|
+
*/
|
|
81
|
+
serviceType: {
|
|
82
|
+
/**
|
|
83
|
+
* 適用決済カード区分が存在するかどうか
|
|
84
|
+
*/
|
|
85
|
+
// $exists: boolean;
|
|
86
|
+
// $eq: '01'
|
|
87
|
+
},
|
|
88
|
+
serviceOutput: {
|
|
89
|
+
/**
|
|
90
|
+
* 適用決済方法タイプ
|
|
91
|
+
*/
|
|
92
|
+
typeOf: {
|
|
93
|
+
// $eq: ''
|
|
94
|
+
// $nin: string[];
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
price: {
|
|
99
|
+
// $gte: 100,
|
|
100
|
+
// $lte: 500
|
|
101
|
+
},
|
|
102
|
+
referenceQuantity: {
|
|
103
|
+
value: {
|
|
104
|
+
// $eq: 2
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
accounting: {
|
|
108
|
+
accountsReceivable: {
|
|
109
|
+
// $gte: 1800,
|
|
110
|
+
// $lte: 100
|
|
111
|
+
},
|
|
112
|
+
operatingRevenue: {
|
|
113
|
+
codeValue: {
|
|
114
|
+
// $eq: ''
|
|
115
|
+
// $in: string[];
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
category: {
|
|
121
|
+
codeValue: {
|
|
122
|
+
// $in: ['1']
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
itemOffered: {
|
|
126
|
+
typeOf: {
|
|
127
|
+
// $eq: chevre.factory.product.ProductType.Product
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
/**
|
|
131
|
+
* 有効期間設定がない、あるいは、有効期間内
|
|
132
|
+
*/
|
|
133
|
+
// onlyValid: true
|
|
134
|
+
additionalProperty: {
|
|
135
|
+
$all: [
|
|
136
|
+
{
|
|
137
|
+
$elemMatch: {
|
|
138
|
+
// name: { $eq: 'nameForPrinting' },
|
|
139
|
+
// value: { $in: ['General'] }
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
]
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
id: 1,
|
|
147
|
+
identifier: 1,
|
|
148
|
+
name: 1,
|
|
149
|
+
alternateName: 1,
|
|
150
|
+
priceSpecification: 1
|
|
151
|
+
}
|
|
152
|
+
);
|
|
153
|
+
console.log(offers);
|
|
154
|
+
console.log(offers.map((offer) => {
|
|
155
|
+
return `${offer.project?.id} ${offer.id} ${offer.identifier} ${offer.name?.ja} ${offer.priceSpecification?.price}`;
|
|
156
|
+
}));
|
|
157
|
+
console.log(offers.length);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
main()
|
|
161
|
+
.then(console.log)
|
|
162
|
+
.catch(console.error);
|
|
@@ -40,3 +40,137 @@ const schema = new mongoose_1.Schema({
|
|
|
40
40
|
exports.schema = schema;
|
|
41
41
|
schema.index({ createdAt: 1 }, { name: 'searchByCreatedAt' });
|
|
42
42
|
schema.index({ updatedAt: 1 }, { name: 'searchByUpdatedAt' });
|
|
43
|
+
schema.index({ 'offers.priceSpecification.price': 1 }, { name: 'searchByOffersPriceSpecificationPrice' });
|
|
44
|
+
schema.index({ 'project.id': 1, 'offers.priceSpecification.price': 1 }, { name: 'searchByProjectId' });
|
|
45
|
+
// オファーIDはグローバルユニーク
|
|
46
|
+
schema.index({ 'offers.id': 1 }, {
|
|
47
|
+
name: 'uniqueOfferId',
|
|
48
|
+
unique: true
|
|
49
|
+
});
|
|
50
|
+
// オファーコードはプロジェクト内ユニーク
|
|
51
|
+
schema.index({ 'offers.identifier': 1, 'project.id': 1 }, {
|
|
52
|
+
name: 'uniqueOfferIdentifier',
|
|
53
|
+
unique: true
|
|
54
|
+
});
|
|
55
|
+
schema.index({ 'offers.availability': 1, 'offers.priceSpecification.price': 1 }, { name: 'searchByOffersAvailability' });
|
|
56
|
+
schema.index({ 'offers.itemOffered.typeOf': 1, 'offers.priceSpecification.price': 1 }, { name: 'searchByOffersItemOfferedTypeOf' });
|
|
57
|
+
schema.index({ 'offers.identifier': 1, 'offers.priceSpecification.price': 1 }, {
|
|
58
|
+
name: 'searchByOffersIdentifier',
|
|
59
|
+
partialFilterExpression: {
|
|
60
|
+
'offers.identifier': { $exists: true }
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
schema.index({ 'offers.priceSpecification.referenceQuantity.value': 1, 'offers.priceSpecification.price': 1 }, {
|
|
64
|
+
name: 'searchByOffersPriceSpecificationReferenceQuantityValue',
|
|
65
|
+
partialFilterExpression: {
|
|
66
|
+
'offers.priceSpecification.referenceQuantity.value': { $exists: true }
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
schema.index({ 'offers.priceSpecification.accounting.accountsReceivable': 1, 'offers.priceSpecification.price': 1 }, {
|
|
70
|
+
name: 'searchByOffersPriceSpecificationAccountingAccountsReceivable',
|
|
71
|
+
partialFilterExpression: {
|
|
72
|
+
'offers.priceSpecification.accounting.accountsReceivable': { $exists: true }
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
schema.index({ 'offers.priceSpecification.accounting.operatingRevenue.codeValue': 1, 'offers.priceSpecification.price': 1 }, {
|
|
76
|
+
name: 'searchByOffersPriceSpecificationAccountingOperatingRevenueCodeValue',
|
|
77
|
+
partialFilterExpression: {
|
|
78
|
+
'offers.priceSpecification.accounting.operatingRevenue.codeValue': { $exists: true }
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
schema.index({ 'offers.priceSpecification.appliesToMovieTicket.serviceType': 1, 'offers.priceSpecification.price': 1 }, {
|
|
82
|
+
name: 'searchByOffersPriceSpecificationAppliesToMovieTicketServiceType',
|
|
83
|
+
partialFilterExpression: {
|
|
84
|
+
'offers.priceSpecification.appliesToMovieTicket.serviceType': { $exists: true }
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
schema.index({ 'offers.priceSpecification.appliesToMovieTicket.serviceOutput.typeOf': 1, 'offers.priceSpecification.price': 1 }, {
|
|
88
|
+
name: 'searchByOffersPriceSpecificationAppliesToMovieTicketServiceOutputTypeOf',
|
|
89
|
+
partialFilterExpression: {
|
|
90
|
+
'offers.priceSpecification.appliesToMovieTicket.serviceOutput.typeOf': { $exists: true }
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
schema.index({ 'offers.name.ja': 1, 'offers.priceSpecification.price': 1 }, {
|
|
94
|
+
name: 'searchByOffersNameJa',
|
|
95
|
+
partialFilterExpression: {
|
|
96
|
+
'offers.name.ja': { $exists: true }
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
schema.index({ 'offers.name.en': 1, 'offers.priceSpecification.price': 1 }, {
|
|
100
|
+
name: 'searchByOffersNameEn',
|
|
101
|
+
partialFilterExpression: {
|
|
102
|
+
'offers.name.en': { $exists: true }
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
schema.index({ 'offers.alternateName': 1, 'offers.priceSpecification.price': 1 }, {
|
|
106
|
+
name: 'searchByOffersAlternateName',
|
|
107
|
+
partialFilterExpression: {
|
|
108
|
+
'offers.alternateName': { $exists: true }
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
schema.index({ 'offers.category.id': 1, 'offers.priceSpecification.price': 1 }, {
|
|
112
|
+
name: 'searchOffersCategoryId',
|
|
113
|
+
partialFilterExpression: {
|
|
114
|
+
'offers.category.id': { $exists: true }
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
schema.index({ 'offers.category.codeValue': 1, 'offers.priceSpecification.price': 1 }, {
|
|
118
|
+
name: 'searchByOffersCategoryCodeValue',
|
|
119
|
+
partialFilterExpression: {
|
|
120
|
+
'offers.category.codeValue': { $exists: true }
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
schema.index({ 'offers.availableAtOrFrom.id': 1, 'offers.priceSpecification.price': 1 }, {
|
|
124
|
+
name: 'searchByOffersAvailableAtOrFromId',
|
|
125
|
+
partialFilterExpression: {
|
|
126
|
+
'offers.availableAtOrFrom.id': { $exists: true }
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
schema.index({ 'offers.eligibleMembershipType.codeValue': 1, 'offers.priceSpecification.price': 1 }, {
|
|
130
|
+
name: 'searchByOffersEligibleMembershipTypeCodeValue',
|
|
131
|
+
partialFilterExpression: {
|
|
132
|
+
'offers.eligibleMembershipType.codeValue': { $exists: true }
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
schema.index({ 'offers.eligibleMonetaryAmount.currency': 1, 'offers.priceSpecification.price': 1 }, {
|
|
136
|
+
name: 'searchByOffersEligibleMonetaryAmountCurrency',
|
|
137
|
+
partialFilterExpression: {
|
|
138
|
+
'offers.eligibleMonetaryAmount.currency': { $exists: true }
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
schema.index({ 'offers.eligibleSeatingType.codeValue': 1, 'offers.priceSpecification.price': 1 }, {
|
|
142
|
+
name: 'searchByOffersEligibleSeatingTypeCodeValue',
|
|
143
|
+
partialFilterExpression: {
|
|
144
|
+
'offers.eligibleSeatingType.codeValue': { $exists: true }
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
schema.index({ 'offers.addOn.itemOffered.id': 1, 'offers.priceSpecification.price': 1 }, {
|
|
148
|
+
name: 'searchByOffersAddOnItemOfferedId',
|
|
149
|
+
partialFilterExpression: {
|
|
150
|
+
'offers.addOn.itemOffered.id': { $exists: true }
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
schema.index({ 'offers.hasMerchantReturnPolicy.id': 1, 'offers.priceSpecification.price': 1 }, {
|
|
154
|
+
name: 'searchByOffersHasMerchantReturnPolicyId',
|
|
155
|
+
partialFilterExpression: {
|
|
156
|
+
'offers.hasMerchantReturnPolicy.id': { $exists: true }
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
schema.index({ 'offers.additionalProperty': 1, 'offers.priceSpecification.price': 1 }, {
|
|
160
|
+
name: 'searchByOffersAdditionalProperty',
|
|
161
|
+
partialFilterExpression: {
|
|
162
|
+
'offers.additionalProperty': { $exists: true }
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
schema.index({ 'offers.validFrom': 1, 'offers.priceSpecification.price': 1 }, {
|
|
166
|
+
name: 'searchByOffersValidFrom',
|
|
167
|
+
partialFilterExpression: {
|
|
168
|
+
'offers.validFrom': { $exists: true }
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
schema.index({ 'offers.validThrough': 1, 'offers.priceSpecification.price': 1 }, {
|
|
172
|
+
name: 'searchByOffersValidThrough',
|
|
173
|
+
partialFilterExpression: {
|
|
174
|
+
'offers.validThrough': { $exists: true }
|
|
175
|
+
}
|
|
176
|
+
});
|
|
@@ -23,8 +23,9 @@
|
|
|
23
23
|
/// <reference types="mongoose/types/virtuals" />
|
|
24
24
|
/// <reference types="mongoose/types/inferschematype" />
|
|
25
25
|
import { BulkWriteResult as BulkWriteOpResultObject } from 'mongodb';
|
|
26
|
-
import { Connection } from 'mongoose';
|
|
26
|
+
import { AnyExpression, Connection, PipelineStage } from 'mongoose';
|
|
27
27
|
import * as factory from '../factory';
|
|
28
|
+
type IMatchStage = PipelineStage.Match;
|
|
28
29
|
interface IProjection {
|
|
29
30
|
[key: string]: 0 | 1;
|
|
30
31
|
}
|
|
@@ -38,6 +39,10 @@ export declare class MongoRepository {
|
|
|
38
39
|
private readonly taskModel;
|
|
39
40
|
constructor(connection: Connection);
|
|
40
41
|
static CREATE_OFFER_MONGO_CONDITIONS(params: factory.unitPriceOffer.ISearchConditions): any[];
|
|
42
|
+
static CREATE_AGGREGATE_OFFERS_MATCH_CONDITIONS(params: factory.unitPriceOffer.ISearchConditions): IMatchStage[];
|
|
43
|
+
static CREATE_AGGREGATE_OFFERS_PROJECTION(params: IProjection): {
|
|
44
|
+
[field: string]: AnyExpression;
|
|
45
|
+
};
|
|
41
46
|
/**
|
|
42
47
|
* カタログに含まれるオファーを検索する
|
|
43
48
|
* カタログに登録されたオファーの順序は保証される
|
|
@@ -58,16 +63,26 @@ export declare class MongoRepository {
|
|
|
58
63
|
onlyValid?: boolean;
|
|
59
64
|
limit?: number;
|
|
60
65
|
page?: number;
|
|
61
|
-
sort: boolean;
|
|
62
66
|
projection?: IProjection;
|
|
63
67
|
}): Promise<{
|
|
64
68
|
offers: factory.unitPriceOffer.IUnitPriceOffer[];
|
|
65
69
|
sortedOfferIds: string[];
|
|
66
70
|
}>;
|
|
67
71
|
findById(params: {
|
|
72
|
+
project: {
|
|
73
|
+
id: string;
|
|
74
|
+
};
|
|
68
75
|
id: string;
|
|
69
76
|
}): Promise<factory.unitPriceOffer.IUnitPriceOffer>;
|
|
77
|
+
findAggregateOfferById(params: {
|
|
78
|
+
project: {
|
|
79
|
+
id: string;
|
|
80
|
+
};
|
|
81
|
+
id: string;
|
|
82
|
+
}): Promise<factory.aggregateOffer.IAggregateOffer>;
|
|
83
|
+
count(params: factory.unitPriceOffer.ISearchConditions): Promise<number>;
|
|
70
84
|
search(params: factory.unitPriceOffer.ISearchConditions, projection?: IProjection): Promise<factory.unitPriceOffer.IUnitPriceOffer[]>;
|
|
85
|
+
searchFromAggregateOffer(params: factory.unitPriceOffer.ISearchConditions, projection?: IProjection): Promise<factory.unitPriceOffer.IUnitPriceOffer[]>;
|
|
71
86
|
save(params: factory.unitPriceOffer.IUnitPriceOffer): Promise<factory.unitPriceOffer.IUnitPriceOffer>;
|
|
72
87
|
/**
|
|
73
88
|
* sskts専用オファー保管
|
|
@@ -126,6 +141,9 @@ export declare class MongoRepository {
|
|
|
126
141
|
id: string;
|
|
127
142
|
};
|
|
128
143
|
typeOf: factory.offerType.AggregateOffer | factory.offerType.Offer;
|
|
144
|
+
options: {
|
|
145
|
+
emitImmediately: boolean;
|
|
146
|
+
};
|
|
129
147
|
}): Promise<{
|
|
130
148
|
id: string;
|
|
131
149
|
}[]>;
|
package/lib/chevre/repo/offer.js
CHANGED
|
@@ -345,6 +345,427 @@ class MongoRepository {
|
|
|
345
345
|
}
|
|
346
346
|
return andConditions;
|
|
347
347
|
}
|
|
348
|
+
// tslint:disable-next-line:cyclomatic-complexity max-func-body-length
|
|
349
|
+
static CREATE_AGGREGATE_OFFERS_MATCH_CONDITIONS(params) {
|
|
350
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33;
|
|
351
|
+
const matchStages = [];
|
|
352
|
+
const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
|
|
353
|
+
if (typeof projectIdEq === 'string') {
|
|
354
|
+
matchStages.push({
|
|
355
|
+
$match: {
|
|
356
|
+
'project.id': { $eq: projectIdEq }
|
|
357
|
+
}
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
const idEq = (_c = params.id) === null || _c === void 0 ? void 0 : _c.$eq;
|
|
361
|
+
if (typeof idEq === 'string') {
|
|
362
|
+
matchStages.push({
|
|
363
|
+
$match: {
|
|
364
|
+
'offers.id': { $eq: idEq }
|
|
365
|
+
}
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
const idIn = (_d = params.id) === null || _d === void 0 ? void 0 : _d.$in;
|
|
369
|
+
if (Array.isArray(idIn)) {
|
|
370
|
+
matchStages.push({
|
|
371
|
+
$match: {
|
|
372
|
+
'offers.id': {
|
|
373
|
+
$in: idIn
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
const identifierEq = (_e = params.identifier) === null || _e === void 0 ? void 0 : _e.$eq;
|
|
379
|
+
if (typeof identifierEq === 'string') {
|
|
380
|
+
matchStages.push({
|
|
381
|
+
$match: {
|
|
382
|
+
'offers.identifier': {
|
|
383
|
+
$exists: true,
|
|
384
|
+
$eq: identifierEq
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
const identifierIn = (_f = params.identifier) === null || _f === void 0 ? void 0 : _f.$in;
|
|
390
|
+
if (Array.isArray(identifierIn)) {
|
|
391
|
+
matchStages.push({
|
|
392
|
+
$match: {
|
|
393
|
+
'offers.identifier': {
|
|
394
|
+
$exists: true,
|
|
395
|
+
$in: identifierIn
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
const identifierRegex = (_g = params.identifier) === null || _g === void 0 ? void 0 : _g.$regex;
|
|
401
|
+
if (typeof identifierRegex === 'string' && identifierRegex.length > 0) {
|
|
402
|
+
matchStages.push({
|
|
403
|
+
$match: {
|
|
404
|
+
'offers.identifier': {
|
|
405
|
+
$exists: true,
|
|
406
|
+
$regex: new RegExp(identifierRegex)
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
const nameRegex = (_h = params.name) === null || _h === void 0 ? void 0 : _h.$regex;
|
|
412
|
+
if (typeof nameRegex === 'string' && nameRegex.length > 0) {
|
|
413
|
+
const nameRegexExp = new RegExp(nameRegex);
|
|
414
|
+
matchStages.push({
|
|
415
|
+
$match: {
|
|
416
|
+
$or: [
|
|
417
|
+
{
|
|
418
|
+
'offers.name.ja': {
|
|
419
|
+
$exists: true,
|
|
420
|
+
$regex: nameRegexExp
|
|
421
|
+
}
|
|
422
|
+
},
|
|
423
|
+
{
|
|
424
|
+
'offers.name.en': {
|
|
425
|
+
$exists: true,
|
|
426
|
+
$regex: nameRegexExp
|
|
427
|
+
}
|
|
428
|
+
},
|
|
429
|
+
{
|
|
430
|
+
'offers.alternateName.ja': {
|
|
431
|
+
$exists: true,
|
|
432
|
+
$regex: nameRegexExp
|
|
433
|
+
}
|
|
434
|
+
},
|
|
435
|
+
{
|
|
436
|
+
'offers.alternateName.en': {
|
|
437
|
+
$exists: true,
|
|
438
|
+
$regex: nameRegexExp
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
]
|
|
442
|
+
}
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
const itemOfferedTypeOfEq = (_k = (_j = params.itemOffered) === null || _j === void 0 ? void 0 : _j.typeOf) === null || _k === void 0 ? void 0 : _k.$eq;
|
|
446
|
+
if (typeof itemOfferedTypeOfEq === 'string') {
|
|
447
|
+
matchStages.push({
|
|
448
|
+
$match: {
|
|
449
|
+
'offers.itemOffered.typeOf': {
|
|
450
|
+
$exists: true,
|
|
451
|
+
$eq: itemOfferedTypeOfEq
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
const categoryCodeValueIn = (_m = (_l = params.category) === null || _l === void 0 ? void 0 : _l.codeValue) === null || _m === void 0 ? void 0 : _m.$in;
|
|
457
|
+
if (Array.isArray(categoryCodeValueIn)) {
|
|
458
|
+
matchStages.push({
|
|
459
|
+
$match: {
|
|
460
|
+
'offers.category.codeValue': {
|
|
461
|
+
$exists: true,
|
|
462
|
+
$in: categoryCodeValueIn
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
const eligibleMembershipTypeCodeValueEq = (_p = (_o = params.eligibleMembershipType) === null || _o === void 0 ? void 0 : _o.codeValue) === null || _p === void 0 ? void 0 : _p.$eq;
|
|
468
|
+
if (typeof eligibleMembershipTypeCodeValueEq === 'string') {
|
|
469
|
+
matchStages.push({
|
|
470
|
+
$match: {
|
|
471
|
+
'offers.eligibleMembershipType.codeValue': {
|
|
472
|
+
$exists: true,
|
|
473
|
+
$eq: eligibleMembershipTypeCodeValueEq
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
});
|
|
477
|
+
}
|
|
478
|
+
const eligibleMonetaryAmountCurrencyEq = (_r = (_q = params.eligibleMonetaryAmount) === null || _q === void 0 ? void 0 : _q.currency) === null || _r === void 0 ? void 0 : _r.$eq;
|
|
479
|
+
if (typeof eligibleMonetaryAmountCurrencyEq === 'string') {
|
|
480
|
+
matchStages.push({
|
|
481
|
+
$match: {
|
|
482
|
+
'offers.eligibleMonetaryAmount.currency': {
|
|
483
|
+
$exists: true,
|
|
484
|
+
$eq: eligibleMonetaryAmountCurrencyEq
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
const eligibleSeatingTypeCodeValueEq = (_t = (_s = params.eligibleSeatingType) === null || _s === void 0 ? void 0 : _s.codeValue) === null || _t === void 0 ? void 0 : _t.$eq;
|
|
490
|
+
if (typeof eligibleSeatingTypeCodeValueEq === 'string') {
|
|
491
|
+
matchStages.push({
|
|
492
|
+
$match: {
|
|
493
|
+
'offers.eligibleSeatingType.codeValue': {
|
|
494
|
+
$exists: true,
|
|
495
|
+
$eq: eligibleSeatingTypeCodeValueEq
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
});
|
|
499
|
+
}
|
|
500
|
+
const appliesToMovieTicketServiceTypeExist = (_w = (_v = (_u = params.priceSpecification) === null || _u === void 0 ? void 0 : _u.appliesToMovieTicket) === null || _v === void 0 ? void 0 : _v.serviceType) === null || _w === void 0 ? void 0 : _w.$exists;
|
|
501
|
+
if (typeof appliesToMovieTicketServiceTypeExist === 'boolean') {
|
|
502
|
+
matchStages.push({
|
|
503
|
+
$match: {
|
|
504
|
+
'offers.priceSpecification.appliesToMovieTicket.serviceType': {
|
|
505
|
+
$exists: appliesToMovieTicketServiceTypeExist
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
const appliesToMovieTicketServiceTypeEq = (_z = (_y = (_x = params.priceSpecification) === null || _x === void 0 ? void 0 : _x.appliesToMovieTicket) === null || _y === void 0 ? void 0 : _y.serviceType) === null || _z === void 0 ? void 0 : _z.$eq;
|
|
511
|
+
if (typeof appliesToMovieTicketServiceTypeEq === 'string') {
|
|
512
|
+
matchStages.push({
|
|
513
|
+
$match: {
|
|
514
|
+
'offers.priceSpecification.appliesToMovieTicket.serviceType': {
|
|
515
|
+
$exists: true,
|
|
516
|
+
$eq: appliesToMovieTicketServiceTypeEq
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
const appliesToMovieTicketServiceOutputTypeOfEq = (_3 = (_2 = (_1 = (_0 = params.priceSpecification) === null || _0 === void 0 ? void 0 : _0.appliesToMovieTicket) === null || _1 === void 0 ? void 0 : _1.serviceOutput) === null || _2 === void 0 ? void 0 : _2.typeOf) === null || _3 === void 0 ? void 0 : _3.$eq;
|
|
522
|
+
if (typeof appliesToMovieTicketServiceOutputTypeOfEq === 'string') {
|
|
523
|
+
matchStages.push({
|
|
524
|
+
$match: {
|
|
525
|
+
'offers.priceSpecification.appliesToMovieTicket.serviceOutput.typeOf': {
|
|
526
|
+
$exists: true,
|
|
527
|
+
$eq: appliesToMovieTicketServiceOutputTypeOfEq
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
const appliesToMovieTicketServiceOutputTypeOfNin = (_7 = (_6 = (_5 = (_4 = params.priceSpecification) === null || _4 === void 0 ? void 0 : _4.appliesToMovieTicket) === null || _5 === void 0 ? void 0 : _5.serviceOutput) === null || _6 === void 0 ? void 0 : _6.typeOf) === null || _7 === void 0 ? void 0 : _7.$nin;
|
|
533
|
+
if (Array.isArray(appliesToMovieTicketServiceOutputTypeOfNin)) {
|
|
534
|
+
matchStages.push({
|
|
535
|
+
$match: {
|
|
536
|
+
'offers.priceSpecification.appliesToMovieTicket.serviceOutput.typeOf': {
|
|
537
|
+
$nin: appliesToMovieTicketServiceOutputTypeOfNin
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
});
|
|
541
|
+
}
|
|
542
|
+
if (params.priceSpecification !== undefined && params.priceSpecification !== null) {
|
|
543
|
+
const priceSpecificationPriceGte = (_8 = params.priceSpecification.price) === null || _8 === void 0 ? void 0 : _8.$gte;
|
|
544
|
+
if (typeof priceSpecificationPriceGte === 'number') {
|
|
545
|
+
matchStages.push({
|
|
546
|
+
$match: {
|
|
547
|
+
'offers.priceSpecification.price': {
|
|
548
|
+
$exists: true,
|
|
549
|
+
$gte: priceSpecificationPriceGte
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
});
|
|
553
|
+
}
|
|
554
|
+
const priceSpecificationPriceLte = (_9 = params.priceSpecification.price) === null || _9 === void 0 ? void 0 : _9.$lte;
|
|
555
|
+
if (typeof priceSpecificationPriceLte === 'number') {
|
|
556
|
+
matchStages.push({
|
|
557
|
+
$match: {
|
|
558
|
+
'offers.priceSpecification.price': {
|
|
559
|
+
$exists: true,
|
|
560
|
+
$lte: priceSpecificationPriceLte
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
});
|
|
564
|
+
}
|
|
565
|
+
const accountsReceivableGte = (_11 = (_10 = params.priceSpecification.accounting) === null || _10 === void 0 ? void 0 : _10.accountsReceivable) === null || _11 === void 0 ? void 0 : _11.$gte;
|
|
566
|
+
if (typeof accountsReceivableGte === 'number') {
|
|
567
|
+
matchStages.push({
|
|
568
|
+
$match: {
|
|
569
|
+
'offers.priceSpecification.accounting.accountsReceivable': {
|
|
570
|
+
$exists: true,
|
|
571
|
+
$gte: accountsReceivableGte
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
});
|
|
575
|
+
}
|
|
576
|
+
const accountsReceivableLte = (_13 = (_12 = params.priceSpecification.accounting) === null || _12 === void 0 ? void 0 : _12.accountsReceivable) === null || _13 === void 0 ? void 0 : _13.$lte;
|
|
577
|
+
if (typeof accountsReceivableLte === 'number') {
|
|
578
|
+
matchStages.push({
|
|
579
|
+
$match: {
|
|
580
|
+
'offers.priceSpecification.accounting.accountsReceivable': {
|
|
581
|
+
$exists: true,
|
|
582
|
+
$lte: accountsReceivableLte
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
});
|
|
586
|
+
}
|
|
587
|
+
const accountingCodeValueEq = (_16 = (_15 = (_14 = params.priceSpecification.accounting) === null || _14 === void 0 ? void 0 : _14.operatingRevenue) === null || _15 === void 0 ? void 0 : _15.codeValue) === null || _16 === void 0 ? void 0 : _16.$eq;
|
|
588
|
+
if (typeof accountingCodeValueEq === 'string') {
|
|
589
|
+
matchStages.push({
|
|
590
|
+
$match: {
|
|
591
|
+
'offers.priceSpecification.accounting.operatingRevenue.codeValue': {
|
|
592
|
+
$exists: true,
|
|
593
|
+
$eq: accountingCodeValueEq
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
});
|
|
597
|
+
}
|
|
598
|
+
const accountingCodeValueIn = (_19 = (_18 = (_17 = params.priceSpecification.accounting) === null || _17 === void 0 ? void 0 : _17.operatingRevenue) === null || _18 === void 0 ? void 0 : _18.codeValue) === null || _19 === void 0 ? void 0 : _19.$in;
|
|
599
|
+
if (Array.isArray(accountingCodeValueIn)) {
|
|
600
|
+
matchStages.push({
|
|
601
|
+
$match: {
|
|
602
|
+
'offers.priceSpecification.accounting.operatingRevenue.codeValue': {
|
|
603
|
+
$exists: true,
|
|
604
|
+
$in: accountingCodeValueIn
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
});
|
|
608
|
+
}
|
|
609
|
+
const referenceQuantityValueEq = (_21 = (_20 = params.priceSpecification.referenceQuantity) === null || _20 === void 0 ? void 0 : _20.value) === null || _21 === void 0 ? void 0 : _21.$eq;
|
|
610
|
+
if (typeof referenceQuantityValueEq === 'number') {
|
|
611
|
+
matchStages.push({
|
|
612
|
+
$match: {
|
|
613
|
+
'offers.priceSpecification.referenceQuantity.value': {
|
|
614
|
+
$exists: true,
|
|
615
|
+
$eq: referenceQuantityValueEq
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
});
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
const availabilityEq = (_22 = params.availability) === null || _22 === void 0 ? void 0 : _22.$eq;
|
|
622
|
+
if (typeof availabilityEq === 'string') {
|
|
623
|
+
matchStages.push({
|
|
624
|
+
$match: {
|
|
625
|
+
'offers.availability': { $eq: availabilityEq }
|
|
626
|
+
}
|
|
627
|
+
});
|
|
628
|
+
}
|
|
629
|
+
const availableAtOrFromIdEq = (_24 = (_23 = params.availableAtOrFrom) === null || _23 === void 0 ? void 0 : _23.id) === null || _24 === void 0 ? void 0 : _24.$eq;
|
|
630
|
+
if (typeof availableAtOrFromIdEq === 'string') {
|
|
631
|
+
matchStages.push({
|
|
632
|
+
$match: {
|
|
633
|
+
'offers.availableAtOrFrom.id': {
|
|
634
|
+
$exists: true,
|
|
635
|
+
$eq: availableAtOrFromIdEq
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
});
|
|
639
|
+
}
|
|
640
|
+
const availableAtOrFromIdIn = (_26 = (_25 = params.availableAtOrFrom) === null || _25 === void 0 ? void 0 : _25.id) === null || _26 === void 0 ? void 0 : _26.$in;
|
|
641
|
+
if (Array.isArray(availableAtOrFromIdIn)) {
|
|
642
|
+
matchStages.push({
|
|
643
|
+
$match: {
|
|
644
|
+
'offers.availableAtOrFrom.id': {
|
|
645
|
+
$exists: true,
|
|
646
|
+
$in: availableAtOrFromIdIn
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
});
|
|
650
|
+
}
|
|
651
|
+
const addOnItemOfferedIdEq = (_29 = (_28 = (_27 = params.addOn) === null || _27 === void 0 ? void 0 : _27.itemOffered) === null || _28 === void 0 ? void 0 : _28.id) === null || _29 === void 0 ? void 0 : _29.$eq;
|
|
652
|
+
if (typeof addOnItemOfferedIdEq === 'string') {
|
|
653
|
+
matchStages.push({
|
|
654
|
+
$match: {
|
|
655
|
+
'offers.addOn.itemOffered.id': {
|
|
656
|
+
$exists: true,
|
|
657
|
+
$eq: addOnItemOfferedIdEq
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
});
|
|
661
|
+
}
|
|
662
|
+
const hasMerchantReturnPolicyIdEq = (_31 = (_30 = params.hasMerchantReturnPolicy) === null || _30 === void 0 ? void 0 : _30.id) === null || _31 === void 0 ? void 0 : _31.$eq;
|
|
663
|
+
if (typeof hasMerchantReturnPolicyIdEq === 'string') {
|
|
664
|
+
matchStages.push({
|
|
665
|
+
$match: {
|
|
666
|
+
'offers.hasMerchantReturnPolicy.id': {
|
|
667
|
+
$exists: true,
|
|
668
|
+
$eq: hasMerchantReturnPolicyIdEq
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
});
|
|
672
|
+
}
|
|
673
|
+
const additionalPropertyAll = (_32 = params.additionalProperty) === null || _32 === void 0 ? void 0 : _32.$all;
|
|
674
|
+
if (Array.isArray(additionalPropertyAll)) {
|
|
675
|
+
matchStages.push({
|
|
676
|
+
$match: {
|
|
677
|
+
'offers.additionalProperty': {
|
|
678
|
+
$exists: true,
|
|
679
|
+
$all: additionalPropertyAll
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
});
|
|
683
|
+
}
|
|
684
|
+
const additionalPropertyElemMatch = (_33 = params.additionalProperty) === null || _33 === void 0 ? void 0 : _33.$elemMatch;
|
|
685
|
+
if (additionalPropertyElemMatch !== undefined && additionalPropertyElemMatch !== null) {
|
|
686
|
+
matchStages.push({
|
|
687
|
+
$match: {
|
|
688
|
+
'offers.additionalProperty': {
|
|
689
|
+
$exists: true,
|
|
690
|
+
$elemMatch: additionalPropertyElemMatch
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
});
|
|
694
|
+
}
|
|
695
|
+
if (params.onlyValid === true) {
|
|
696
|
+
const now = new Date();
|
|
697
|
+
matchStages.push({
|
|
698
|
+
$match: {
|
|
699
|
+
$or: [
|
|
700
|
+
{ 'offers.validFrom': { $exists: false } },
|
|
701
|
+
{ 'offers.validFrom': { $exists: true, $lte: now } }
|
|
702
|
+
]
|
|
703
|
+
}
|
|
704
|
+
}, {
|
|
705
|
+
$match: {
|
|
706
|
+
$or: [
|
|
707
|
+
{ 'offers.validThrough': { $exists: false } },
|
|
708
|
+
{ 'offers.validThrough': { $exists: true, $gte: now } }
|
|
709
|
+
]
|
|
710
|
+
}
|
|
711
|
+
});
|
|
712
|
+
}
|
|
713
|
+
return matchStages;
|
|
714
|
+
}
|
|
715
|
+
static CREATE_AGGREGATE_OFFERS_PROJECTION(params) {
|
|
716
|
+
let projectStage = {
|
|
717
|
+
_id: 0,
|
|
718
|
+
typeOf: '$offers.typeOf',
|
|
719
|
+
project: '$project',
|
|
720
|
+
id: '$offers.id',
|
|
721
|
+
identifier: '$offers.identifier',
|
|
722
|
+
name: '$offers.name',
|
|
723
|
+
description: '$offers.description',
|
|
724
|
+
category: '$offers.category',
|
|
725
|
+
color: '$offers.color',
|
|
726
|
+
additionalProperty: '$offers.additionalProperty',
|
|
727
|
+
advanceBookingRequirement: '$offers.advanceBookingRequirement',
|
|
728
|
+
alternateName: '$offers.alternateName',
|
|
729
|
+
addOn: '$offers.addOn',
|
|
730
|
+
availability: '$offers.availability',
|
|
731
|
+
availableAtOrFrom: '$offers.availableAtOrFrom',
|
|
732
|
+
hasMerchantReturnPolicy: '$offers.hasMerchantReturnPolicy',
|
|
733
|
+
itemOffered: '$offers.itemOffered',
|
|
734
|
+
priceCurrency: '$offers.priceCurrency',
|
|
735
|
+
priceSpecification: '$offers.priceSpecification',
|
|
736
|
+
eligibleCustomerType: '$offers.eligibleCustomerType',
|
|
737
|
+
eligibleDuration: '$offers.eligibleDuration',
|
|
738
|
+
eligibleMembershipType: '$offers.eligibleMembershipType',
|
|
739
|
+
eligibleMonetaryAmount: '$offers.eligibleMonetaryAmount',
|
|
740
|
+
eligibleQuantity: '$offers.eligibleQuantity',
|
|
741
|
+
eligibleRegion: '$offers.eligibleRegion',
|
|
742
|
+
eligibleSeatingType: '$offers.eligibleSeatingType',
|
|
743
|
+
eligibleSubReservation: '$offers.eligibleSubReservation',
|
|
744
|
+
settings: '$offers.settings',
|
|
745
|
+
validFrom: '$offers.validFrom',
|
|
746
|
+
validThrough: '$offers.validThrough',
|
|
747
|
+
validRateLimit: '$offers.validRateLimit'
|
|
748
|
+
};
|
|
749
|
+
const positiveProjectionFields = Object.keys(params)
|
|
750
|
+
.filter((key) => params[key] !== 0);
|
|
751
|
+
const negativeProjectionFields = Object.keys(params)
|
|
752
|
+
.filter((key) => params[key] === 0);
|
|
753
|
+
if (positiveProjectionFields.length > 0) {
|
|
754
|
+
projectStage = { _id: 0 };
|
|
755
|
+
positiveProjectionFields.forEach((field) => {
|
|
756
|
+
projectStage[field] = `$offers.${field}`;
|
|
757
|
+
});
|
|
758
|
+
}
|
|
759
|
+
else if (negativeProjectionFields.length > 0) {
|
|
760
|
+
negativeProjectionFields.forEach((field) => {
|
|
761
|
+
if (typeof projectStage[field] === 'string') {
|
|
762
|
+
// tslint:disable-next-line:no-dynamic-delete
|
|
763
|
+
delete projectStage[field];
|
|
764
|
+
}
|
|
765
|
+
});
|
|
766
|
+
}
|
|
767
|
+
return projectStage;
|
|
768
|
+
}
|
|
348
769
|
/**
|
|
349
770
|
* カタログに含まれるオファーを検索する
|
|
350
771
|
* カタログに登録されたオファーの順序は保証される
|
|
@@ -393,37 +814,55 @@ class MongoRepository {
|
|
|
393
814
|
? { sort: { _id: factory.sortType.Ascending } }
|
|
394
815
|
: undefined), (typeof params.limit === 'number') ? { limit: params.limit } : undefined), (typeof params.page === 'number') ? { page: params.page } : undefined);
|
|
395
816
|
offers = yield this.search(searchOffersConditions, params.projection);
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
817
|
+
// 完全廃止(基本的にsortedOfferIdsと合わせて利用する想定)(2023-09-04~)
|
|
818
|
+
// if (params.sort) {
|
|
819
|
+
// // sorting
|
|
820
|
+
// offers = offers.sort((a, b) => sortedOfferIds.indexOf(String(a.id)) - sortedOfferIds.indexOf(String(b.id)));
|
|
821
|
+
// }
|
|
400
822
|
}
|
|
401
823
|
return { offers, sortedOfferIds };
|
|
402
824
|
});
|
|
403
825
|
}
|
|
404
826
|
findById(params) {
|
|
405
827
|
return __awaiter(this, void 0, void 0, function* () {
|
|
406
|
-
const
|
|
828
|
+
const offers = yield this.search({
|
|
829
|
+
limit: 1,
|
|
830
|
+
page: 1,
|
|
831
|
+
project: { id: { $eq: params.project.id } },
|
|
832
|
+
id: { $eq: params.id }
|
|
833
|
+
});
|
|
834
|
+
const unitPriceOffer = offers.shift();
|
|
835
|
+
if (unitPriceOffer === undefined) {
|
|
836
|
+
throw new factory.errors.NotFound(this.offerModel.modelName);
|
|
837
|
+
}
|
|
838
|
+
return unitPriceOffer;
|
|
839
|
+
});
|
|
840
|
+
}
|
|
841
|
+
findAggregateOfferById(params) {
|
|
842
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
843
|
+
const doc = yield this.aggregateOfferModel.findOne({
|
|
844
|
+
_id: { $eq: params.id },
|
|
845
|
+
'project.id': { $eq: params.project.id }
|
|
846
|
+
}, {
|
|
407
847
|
__v: 0,
|
|
408
848
|
createdAt: 0,
|
|
409
|
-
updatedAt: 0
|
|
410
|
-
availableAddOn: 0 // 廃止属性の残存が確認されたので(2023-09-04~)
|
|
849
|
+
updatedAt: 0
|
|
411
850
|
})
|
|
412
851
|
.exec();
|
|
413
852
|
if (doc === null) {
|
|
414
|
-
throw new factory.errors.NotFound(this.
|
|
853
|
+
throw new factory.errors.NotFound(this.aggregateOfferModel.modelName);
|
|
415
854
|
}
|
|
416
855
|
return doc.toObject();
|
|
417
856
|
});
|
|
418
857
|
}
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
858
|
+
count(params) {
|
|
859
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
860
|
+
const conditions = MongoRepository.CREATE_OFFER_MONGO_CONDITIONS(params);
|
|
861
|
+
return this.offerModel.countDocuments((conditions.length > 0) ? { $and: conditions } : {})
|
|
862
|
+
.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
863
|
+
.exec();
|
|
864
|
+
});
|
|
865
|
+
}
|
|
427
866
|
search(params, projection) {
|
|
428
867
|
var _a;
|
|
429
868
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -451,6 +890,29 @@ class MongoRepository {
|
|
|
451
890
|
.then((docs) => docs.map((doc) => doc.toObject()));
|
|
452
891
|
});
|
|
453
892
|
}
|
|
893
|
+
searchFromAggregateOffer(params, projection) {
|
|
894
|
+
var _a;
|
|
895
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
896
|
+
const matchStages = MongoRepository.CREATE_AGGREGATE_OFFERS_MATCH_CONDITIONS(params);
|
|
897
|
+
const projectStage = MongoRepository.CREATE_AGGREGATE_OFFERS_PROJECTION(Object.assign({}, projection));
|
|
898
|
+
const aggregate = this.aggregateOfferModel.aggregate([
|
|
899
|
+
{ $unwind: '$offers' },
|
|
900
|
+
...matchStages,
|
|
901
|
+
...(typeof ((_a = params.sort) === null || _a === void 0 ? void 0 : _a['priceSpecification.price']) === 'number')
|
|
902
|
+
? [{ $sort: { 'offers.priceSpecification.price': params.sort['priceSpecification.price'] } }]
|
|
903
|
+
: [],
|
|
904
|
+
{ $project: projectStage }
|
|
905
|
+
]);
|
|
906
|
+
// tslint:disable-next-line:no-single-line-block-comment
|
|
907
|
+
/* istanbul ignore else */
|
|
908
|
+
if (typeof params.limit === 'number' && params.limit > 0) {
|
|
909
|
+
const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
|
|
910
|
+
aggregate.limit(params.limit * page)
|
|
911
|
+
.skip(params.limit * (page - 1));
|
|
912
|
+
}
|
|
913
|
+
return aggregate.exec();
|
|
914
|
+
});
|
|
915
|
+
}
|
|
454
916
|
save(params) {
|
|
455
917
|
return __awaiter(this, void 0, void 0, function* () {
|
|
456
918
|
let doc;
|
|
@@ -474,7 +936,8 @@ class MongoRepository {
|
|
|
474
936
|
id: { $in: [doc._id] },
|
|
475
937
|
identifier: { $in: [] },
|
|
476
938
|
isDeleted: false,
|
|
477
|
-
typeOf: factory.offerType.Offer
|
|
939
|
+
typeOf: factory.offerType.Offer,
|
|
940
|
+
options: { emitImmediately: true }
|
|
478
941
|
});
|
|
479
942
|
}
|
|
480
943
|
return doc.toObject();
|
|
@@ -523,7 +986,8 @@ class MongoRepository {
|
|
|
523
986
|
id: { $in: [] },
|
|
524
987
|
identifier: { $in: params.map((savingOffer) => savingOffer.attributes.identifier) },
|
|
525
988
|
isDeleted: false,
|
|
526
|
-
typeOf: factory.offerType.Offer
|
|
989
|
+
typeOf: factory.offerType.Offer,
|
|
990
|
+
options: { emitImmediately: true }
|
|
527
991
|
});
|
|
528
992
|
}
|
|
529
993
|
});
|
|
@@ -558,7 +1022,8 @@ class MongoRepository {
|
|
|
558
1022
|
id: { $in: updatingOffers.map((offer) => offer.id) },
|
|
559
1023
|
identifier: { $in: [] },
|
|
560
1024
|
isDeleted: false,
|
|
561
|
-
typeOf: factory.offerType.Offer
|
|
1025
|
+
typeOf: factory.offerType.Offer,
|
|
1026
|
+
options: { emitImmediately: true }
|
|
562
1027
|
});
|
|
563
1028
|
}
|
|
564
1029
|
return result;
|
|
@@ -574,7 +1039,8 @@ class MongoRepository {
|
|
|
574
1039
|
id: { $in: [params.id] },
|
|
575
1040
|
identifier: { $in: [] },
|
|
576
1041
|
isDeleted: true,
|
|
577
|
-
typeOf: factory.offerType.Offer
|
|
1042
|
+
typeOf: factory.offerType.Offer,
|
|
1043
|
+
options: { emitImmediately: true }
|
|
578
1044
|
});
|
|
579
1045
|
});
|
|
580
1046
|
}
|
|
@@ -718,12 +1184,14 @@ class MongoRepository {
|
|
|
718
1184
|
.map((objectId) => {
|
|
719
1185
|
return { id: objectId.toHexString() };
|
|
720
1186
|
});
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
1187
|
+
if (params.options.emitImmediately === true) {
|
|
1188
|
+
savedTasks.forEach((savedTask) => {
|
|
1189
|
+
task_2.taskEventEmitter.emitTaskStatusChanged({
|
|
1190
|
+
id: savedTask.id,
|
|
1191
|
+
status: factory.taskStatus.Ready
|
|
1192
|
+
});
|
|
725
1193
|
});
|
|
726
|
-
}
|
|
1194
|
+
}
|
|
727
1195
|
return savedTasks;
|
|
728
1196
|
});
|
|
729
1197
|
}
|
|
@@ -179,8 +179,8 @@ function findOffers(params) {
|
|
|
179
179
|
if (typeof ((_b = eventService.hasOfferCatalog) === null || _b === void 0 ? void 0 : _b.id) === 'string') {
|
|
180
180
|
const findOffersByOfferCatalogIdResult = yield repos.offer.findOffersByOfferCatalogId({
|
|
181
181
|
offerCatalog: { id: eventService.hasOfferCatalog.id },
|
|
182
|
-
excludeAppliesToMovieTicket: false
|
|
183
|
-
sort: false // ソート不要(2023-01-27~)
|
|
182
|
+
excludeAppliesToMovieTicket: false
|
|
183
|
+
// sort: false // ソート不要(2023-01-27~) // 完全廃止(2023-09-04~)
|
|
184
184
|
});
|
|
185
185
|
availableOffers = findOffersByOfferCatalogIdResult.offers;
|
|
186
186
|
}
|
|
@@ -104,8 +104,8 @@ function findOffers(params) {
|
|
|
104
104
|
if (typeof ((_b = eventService.hasOfferCatalog) === null || _b === void 0 ? void 0 : _b.id) === 'string') {
|
|
105
105
|
const findOffersByOfferCatalogIdResult = yield repos.offer.findOffersByOfferCatalogId({
|
|
106
106
|
offerCatalog: { id: eventService.hasOfferCatalog.id },
|
|
107
|
-
excludeAppliesToMovieTicket: false
|
|
108
|
-
sort: false // ソート不要(2023-01-27~)
|
|
107
|
+
excludeAppliesToMovieTicket: false
|
|
108
|
+
// sort: false // ソート不要(2023-01-27~) // 完全廃止(2023-09-04~)
|
|
109
109
|
});
|
|
110
110
|
availableOffers = findOffersByOfferCatalogIdResult.offers;
|
|
111
111
|
}
|
|
@@ -35,8 +35,8 @@ function searchTicketOffersByItemOffered(params) {
|
|
|
35
35
|
onlyValid: params.onlyValid === true,
|
|
36
36
|
// Mongoのpagingを利用するオプション(2023-02-21~)
|
|
37
37
|
limit: params.limit,
|
|
38
|
-
page: params.page
|
|
39
|
-
sort: false
|
|
38
|
+
page: params.page
|
|
39
|
+
// sort: false // 完全廃止(2023-09-04~)
|
|
40
40
|
});
|
|
41
41
|
return { availableOffers: offers, sortedOfferIds };
|
|
42
42
|
});
|
|
@@ -29,7 +29,7 @@ function searchProductOffers(params) {
|
|
|
29
29
|
excludeAppliesToMovieTicket: false,
|
|
30
30
|
limit: params.limit,
|
|
31
31
|
page: params.page,
|
|
32
|
-
sort: false,
|
|
32
|
+
// sort: false, // 完全廃止(2023-09-04~)
|
|
33
33
|
onlyValid: params.onlyValid === true,
|
|
34
34
|
availableAtOrFrom: params.availableAt
|
|
35
35
|
});
|
package/package.json
CHANGED