@chevre/domain 22.11.0-alpha.35 → 22.11.0-alpha.37
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/searchProducts.ts +28 -0
- package/example/src/chevre/task/emitRunning.ts +89 -0
- package/lib/chevre/repo/mongoose/schemas/product.js +9 -0
- package/lib/chevre/repo/product.js +12 -17
- package/lib/chevre/service/assetTransaction/registerService.js +4 -0
- package/lib/chevre/service/assetTransaction/reserve/start/createSubReservations.js +19 -16
- package/lib/chevre/service/offer/product.js +4 -0
- package/package.json +3 -3
- package/example/src/chevre/searchProductOffers.ts +0 -29
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
import * as mongoose from 'mongoose';
|
|
3
|
+
|
|
4
|
+
import { chevre } from '../../../lib/index';
|
|
5
|
+
|
|
6
|
+
const PROJECT_ID = String(process.env.PROJECT_ID);
|
|
7
|
+
|
|
8
|
+
async function main() {
|
|
9
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI);
|
|
10
|
+
|
|
11
|
+
const productRepo = await chevre.repository.Product.createInstance(mongoose.connection);
|
|
12
|
+
|
|
13
|
+
const products = await productRepo.projectFields(
|
|
14
|
+
{
|
|
15
|
+
limit: 10,
|
|
16
|
+
project: { id: { $eq: PROJECT_ID } },
|
|
17
|
+
additionalPropertyMatch: { nameEq: 'xxxxx' }
|
|
18
|
+
// seller: { id: { $eq: 'xxx' } }
|
|
19
|
+
},
|
|
20
|
+
['additionalProperty', 'productID']
|
|
21
|
+
);
|
|
22
|
+
console.log(products);
|
|
23
|
+
console.log(products.length, 'products found');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
main()
|
|
27
|
+
.then(console.log)
|
|
28
|
+
.catch(console.error);
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// tslint:disable:no-console no-magic-numbers
|
|
2
|
+
import * as moment from 'moment';
|
|
3
|
+
import * as mongoose from 'mongoose';
|
|
4
|
+
|
|
5
|
+
import { chevre } from '../../../../lib/index';
|
|
6
|
+
|
|
7
|
+
// const project = { id: String(process.env.PROJECT_ID) };
|
|
8
|
+
|
|
9
|
+
const delayInSeconds = 60;
|
|
10
|
+
const numExecuteByRequest = 50;
|
|
11
|
+
const selfName = 'sample';
|
|
12
|
+
|
|
13
|
+
const excludedTaskNames = [
|
|
14
|
+
chevre.factory.taskName.DeleteTransaction,
|
|
15
|
+
chevre.factory.taskName.ImportEventCapacitiesFromCOA,
|
|
16
|
+
chevre.factory.taskName.ImportEventsFromCOA,
|
|
17
|
+
chevre.factory.taskName.AcceptCOAOffer,
|
|
18
|
+
chevre.factory.taskName.CheckMovieTicket,
|
|
19
|
+
chevre.factory.taskName.AuthorizePayment,
|
|
20
|
+
chevre.factory.taskName.PublishPaymentUrl
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
async function main() {
|
|
24
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false, appName: 'sample' });
|
|
25
|
+
|
|
26
|
+
const now = new Date();
|
|
27
|
+
const runsAtLt = moment(now)
|
|
28
|
+
.add(-delayInSeconds, 'seconds')
|
|
29
|
+
.toDate();
|
|
30
|
+
|
|
31
|
+
let allTaskNames = Object.values(chevre.factory.taskName);
|
|
32
|
+
allTaskNames = allTaskNames.filter((name) => !excludedTaskNames.includes(name));
|
|
33
|
+
console.log('allTaskNames:', allTaskNames, allTaskNames.length);
|
|
34
|
+
|
|
35
|
+
const taskRepo = await chevre.repository.Task.createInstance(mongoose.connection);
|
|
36
|
+
|
|
37
|
+
const delayedTask: Pick<chevre.factory.task.ITask<chevre.factory.taskName>, 'id' | 'name'>[] = [];
|
|
38
|
+
|
|
39
|
+
// const { count } = await taskRepo.countPotentiallyRunning({
|
|
40
|
+
// name: { $in: allTaskNames },
|
|
41
|
+
// runsAt: { $lt: runsAtLt },
|
|
42
|
+
// limit: numExecuteByRequest
|
|
43
|
+
// });
|
|
44
|
+
// console.log('countPotentiallyRunning:', count);
|
|
45
|
+
// const executeCount: number = Math.min(count, numExecuteByRequest);
|
|
46
|
+
const executeCount: number = numExecuteByRequest;
|
|
47
|
+
const sort: {
|
|
48
|
+
numberOfTried?: chevre.factory.sortType;
|
|
49
|
+
runsAt?: chevre.factory.sortType;
|
|
50
|
+
} = {
|
|
51
|
+
numberOfTried: chevre.factory.sortType.Ascending, // numberOfTriedソートを加えるとどうなるのか?
|
|
52
|
+
runsAt: chevre.factory.sortType.Ascending
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
for (let i = 0; i < executeCount; i += 1) {
|
|
56
|
+
const runningTask = await taskRepo.emitRunningIfExists(
|
|
57
|
+
{
|
|
58
|
+
name: { $in: allTaskNames },
|
|
59
|
+
runsAt: { $lt: runsAtLt },
|
|
60
|
+
sort,
|
|
61
|
+
executor: {
|
|
62
|
+
name: selfName
|
|
63
|
+
},
|
|
64
|
+
nameFilterBeforeRunsAt: false
|
|
65
|
+
}
|
|
66
|
+
);
|
|
67
|
+
console.log('runningTask found', JSON.stringify(runningTask), i, now);
|
|
68
|
+
if (runningTask !== null) {
|
|
69
|
+
delayedTask.push(runningTask);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const interval = setInterval(
|
|
75
|
+
() => {
|
|
76
|
+
main()
|
|
77
|
+
.then()
|
|
78
|
+
.catch(console.error);
|
|
79
|
+
},
|
|
80
|
+
1000
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
setTimeout(
|
|
84
|
+
() => {
|
|
85
|
+
clearInterval(interval);
|
|
86
|
+
console.log('interval cleared');
|
|
87
|
+
},
|
|
88
|
+
600000
|
|
89
|
+
);
|
|
@@ -120,6 +120,15 @@ const indexes = [
|
|
|
120
120
|
'name.en': { $exists: true }
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
|
+
],
|
|
124
|
+
[
|
|
125
|
+
{ additionalProperty: 1, productID: 1 },
|
|
126
|
+
{
|
|
127
|
+
name: 'additionalProperty',
|
|
128
|
+
partialFilterExpression: {
|
|
129
|
+
additionalProperty: { $exists: true }
|
|
130
|
+
}
|
|
131
|
+
}
|
|
123
132
|
]
|
|
124
133
|
];
|
|
125
134
|
exports.indexes = indexes;
|
|
@@ -48,7 +48,7 @@ class ProductRepo {
|
|
|
48
48
|
}
|
|
49
49
|
// tslint:disable-next-line:max-func-body-length
|
|
50
50
|
static CREATE_MONGO_CONDITIONS(params) {
|
|
51
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
51
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
|
|
52
52
|
// MongoDB検索条件
|
|
53
53
|
const andConditions = [];
|
|
54
54
|
const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
|
|
@@ -151,25 +151,20 @@ class ProductRepo {
|
|
|
151
151
|
const nameRegexExp = new RegExp(nameRegex);
|
|
152
152
|
andConditions.push({
|
|
153
153
|
$or: [
|
|
154
|
-
{
|
|
155
|
-
|
|
156
|
-
$exists: true,
|
|
157
|
-
$regex: nameRegexExp
|
|
158
|
-
}
|
|
159
|
-
},
|
|
160
|
-
{
|
|
161
|
-
'name.en': {
|
|
162
|
-
$exists: true,
|
|
163
|
-
$regex: nameRegexExp
|
|
164
|
-
}
|
|
165
|
-
}
|
|
154
|
+
{ 'name.ja': { $exists: true, $regex: nameRegexExp } },
|
|
155
|
+
{ 'name.en': { $exists: true, $regex: nameRegexExp } }
|
|
166
156
|
]
|
|
167
157
|
});
|
|
168
158
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
159
|
+
const additionalPropertyElemMatchNameEq = (_w = params.additionalPropertyMatch) === null || _w === void 0 ? void 0 : _w.nameEq;
|
|
160
|
+
if (typeof additionalPropertyElemMatchNameEq === 'string') {
|
|
161
|
+
andConditions.push({
|
|
162
|
+
additionalProperty: {
|
|
163
|
+
$exists: true,
|
|
164
|
+
$elemMatch: { name: { $eq: additionalPropertyElemMatchNameEq } }
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
}
|
|
173
168
|
return andConditions;
|
|
174
169
|
}
|
|
175
170
|
/**
|
|
@@ -56,6 +56,10 @@ function start(params) {
|
|
|
56
56
|
if (product === undefined) {
|
|
57
57
|
throw new factory.errors.NotFound('Product');
|
|
58
58
|
}
|
|
59
|
+
if (product.typeOf !== factory.product.ProductType.MembershipService
|
|
60
|
+
&& product.typeOf !== factory.product.ProductType.PaymentCard) {
|
|
61
|
+
throw new factory.errors.Argument('object.itemOffered.id', `invalid product type: ${product.typeOf}`);
|
|
62
|
+
}
|
|
59
63
|
const transactionNumber = params.transactionNumber;
|
|
60
64
|
if (typeof transactionNumber !== 'string' || transactionNumber.length === 0) {
|
|
61
65
|
throw new factory.errors.ArgumentNull('transactionNumber');
|
|
@@ -187,22 +187,25 @@ function searchAvailableAddOns(params) {
|
|
|
187
187
|
const { offers, product } = yield OfferService.product.search(Object.assign({ ids: params.ids, project: { id: params.project.id }, itemOffered: { id: addOnProductId }, onlyValid: true, addSortIndex: false, includedInDataCatalog: { id: '' }, useIncludeInDataCatalog: false }, (typeof ((_a = params.availableAtOrFrom) === null || _a === void 0 ? void 0 : _a.id) === 'string')
|
|
188
188
|
? { availableAt: { id: params.availableAtOrFrom.id } }
|
|
189
189
|
: undefined))(repos);
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
190
|
+
const productType = product.typeOf;
|
|
191
|
+
if (productType === factory.product.ProductType.Product) {
|
|
192
|
+
availableAddOns.push(...offers.map((o) => {
|
|
193
|
+
const itemOffered4addOn = {
|
|
194
|
+
description: product.description,
|
|
195
|
+
id: product.id,
|
|
196
|
+
name: product.name,
|
|
197
|
+
productID: product.productID,
|
|
198
|
+
typeOf: productType
|
|
199
|
+
};
|
|
200
|
+
const unitPriceSpec = o.priceSpecification.priceComponent.find((component) => {
|
|
201
|
+
return component.typeOf === factory.priceSpecificationType.UnitPriceSpecification;
|
|
202
|
+
});
|
|
203
|
+
if ((unitPriceSpec === null || unitPriceSpec === void 0 ? void 0 : unitPriceSpec.typeOf) !== factory.priceSpecificationType.UnitPriceSpecification) {
|
|
204
|
+
throw new factory.errors.NotFound('UnitPriceSpecification of an addOn');
|
|
205
|
+
}
|
|
206
|
+
return Object.assign(Object.assign({ alternateName: o.alternateName, availability: o.availability, description: o.description, id: String(o.id), identifier: o.identifier, itemOffered: itemOffered4addOn, name: o.name, priceCurrency: o.priceCurrency, priceSpecification: unitPriceSpec, typeOf: o.typeOf }, (o.validFrom instanceof Date) ? { validFrom: o.validFrom } : undefined), (o.validThrough instanceof Date) ? { validThrough: o.validThrough } : undefined);
|
|
207
|
+
}));
|
|
208
|
+
}
|
|
206
209
|
}
|
|
207
210
|
}
|
|
208
211
|
return availableAddOns;
|
|
@@ -189,6 +189,10 @@ function fixProductAndOffers(params) {
|
|
|
189
189
|
if (product === undefined) {
|
|
190
190
|
throw new factory.errors.NotFound('Product');
|
|
191
191
|
}
|
|
192
|
+
if (product.typeOf !== factory.product.ProductType.MembershipService
|
|
193
|
+
&& product.typeOf !== factory.product.ProductType.PaymentCard) {
|
|
194
|
+
throw new factory.errors.Argument('object.itemOffered.id', `invalid product type: ${product.typeOf}`);
|
|
195
|
+
}
|
|
192
196
|
const { offers } = yield search(Object.assign({ ids: params.object.map((o) => String(o.id)), project: { id: params.project.id }, itemOffered: { id: String(product.id) }, onlyValid: true, includedInDataCatalog: { id: '' }, addSortIndex: false, useIncludeInDataCatalog: false }, (typeof ((_c = params.location) === null || _c === void 0 ? void 0 : _c.id) === 'string') ? { availableAt: { id: params.location.id } } : undefined))(repos);
|
|
193
197
|
return { product, availableOffers: offers };
|
|
194
198
|
});
|
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.396.0-alpha.
|
|
15
|
-
"@cinerino/sdk": "11.2.0-alpha.
|
|
14
|
+
"@chevre/factory": "4.396.0-alpha.8",
|
|
15
|
+
"@cinerino/sdk": "11.2.0-alpha.2",
|
|
16
16
|
"@motionpicture/coa-service": "9.6.0",
|
|
17
17
|
"@motionpicture/gmo-service": "5.3.0",
|
|
18
18
|
"@sendgrid/client": "8.1.4",
|
|
@@ -115,5 +115,5 @@
|
|
|
115
115
|
"postversion": "git push origin --tags",
|
|
116
116
|
"prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
|
|
117
117
|
},
|
|
118
|
-
"version": "22.11.0-alpha.
|
|
118
|
+
"version": "22.11.0-alpha.37"
|
|
119
119
|
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
// tslint:disable:no-console
|
|
2
|
-
import * as mongoose from 'mongoose';
|
|
3
|
-
|
|
4
|
-
import { chevre } from '../../../lib/index';
|
|
5
|
-
|
|
6
|
-
const PROJECT_ID = String(process.env.PROJECT_ID);
|
|
7
|
-
|
|
8
|
-
async function main() {
|
|
9
|
-
await mongoose.connect(<string>process.env.MONGOLAB_URI);
|
|
10
|
-
|
|
11
|
-
const productOfferRepo = await chevre.repository.ProductOffer.createInstance(mongoose.connection);
|
|
12
|
-
|
|
13
|
-
const offers = await productOfferRepo.search({
|
|
14
|
-
project: { id: { $eq: PROJECT_ID } }
|
|
15
|
-
// seller: { id: { $eq: 'xxx' } }
|
|
16
|
-
});
|
|
17
|
-
console.log(offers);
|
|
18
|
-
console.log(offers.length);
|
|
19
|
-
|
|
20
|
-
// await productOfferRepo.deleteOne({
|
|
21
|
-
// project: { id: PROJECT_ID },
|
|
22
|
-
// seller: { id: 'xxx' },
|
|
23
|
-
// itemOffered: { id: 'xxx' }
|
|
24
|
-
// });
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
main()
|
|
28
|
-
.then(console.log)
|
|
29
|
-
.catch(console.error);
|