@chevre/domain 21.9.0-alpha.2 → 21.9.0-alpha.4
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/{searchOfferCatalogs.ts → searchOfferCatalogItems.ts} +6 -5
- package/example/src/chevre/searchOffersByCatalog.ts +3 -3
- package/lib/chevre/repo/offer.js +9 -4
- package/lib/chevre/repo/offerCatalogItem.d.ts +1 -1
- package/lib/chevre/repo/offerCatalogItem.js +18 -19
- package/package.json +1 -1
|
@@ -9,22 +9,23 @@ mongoose.Model.on('index', (...args) => {
|
|
|
9
9
|
});
|
|
10
10
|
|
|
11
11
|
async function main() {
|
|
12
|
-
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex:
|
|
12
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
13
13
|
|
|
14
|
-
const
|
|
14
|
+
const catalogItemRepo = new chevre.repository.OfferCatalogItem(mongoose.connection);
|
|
15
15
|
|
|
16
16
|
console.log('searching...');
|
|
17
|
-
const catalogs = await
|
|
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(
|
|
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);
|
|
29
30
|
}
|
|
30
31
|
|
|
@@ -14,11 +14,11 @@ async function main() {
|
|
|
14
14
|
page: 1,
|
|
15
15
|
// ids: ['xx', 'xxx', '1001', '901'],
|
|
16
16
|
subOfferCatalog: {
|
|
17
|
-
id: '
|
|
18
|
-
isOfferCatalogItem:
|
|
17
|
+
id: 'xxx',
|
|
18
|
+
isOfferCatalogItem: true
|
|
19
19
|
},
|
|
20
20
|
excludeAppliesToMovieTicket: false,
|
|
21
|
-
useIncludeInDataCatalog:
|
|
21
|
+
useIncludeInDataCatalog: false
|
|
22
22
|
});
|
|
23
23
|
// console.log(offers);
|
|
24
24
|
console.log(offers.map((offer) => {
|
package/lib/chevre/repo/offer.js
CHANGED
|
@@ -21,6 +21,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
21
21
|
};
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
23
|
exports.MongoRepository = void 0;
|
|
24
|
+
const mongoose_1 = require("mongoose");
|
|
24
25
|
const uniqid = require("uniqid");
|
|
25
26
|
const factory = require("../factory");
|
|
26
27
|
const aggregateOffer_1 = require("./mongoose/schemas/aggregateOffer");
|
|
@@ -800,12 +801,12 @@ class MongoRepository {
|
|
|
800
801
|
*/
|
|
801
802
|
searchAggregateOfferIdsBySubOfferCatalog(params) {
|
|
802
803
|
return __awaiter(this, void 0, void 0, function* () {
|
|
803
|
-
const matchStages = [{ $match: { _id: { $eq: params.id } } }];
|
|
804
|
-
if (Array.isArray(params.itemListElementIds)) {
|
|
805
|
-
matchStages.push({ $match: { 'itemListElement.id': { $exists: true, $in: params.itemListElementIds } } });
|
|
806
|
-
}
|
|
807
804
|
let itemListElements;
|
|
808
805
|
if (params.isOfferCatalogItem) {
|
|
806
|
+
const matchStages = [{ $match: { _id: { $eq: new mongoose_1.Types.ObjectId(params.id) } } }]; // ObjectIdなので注意
|
|
807
|
+
if (Array.isArray(params.itemListElementIds)) {
|
|
808
|
+
matchStages.push({ $match: { 'itemListElement.id': { $exists: true, $in: params.itemListElementIds } } });
|
|
809
|
+
}
|
|
809
810
|
itemListElements = yield this.offerCatalogItemModel.aggregate([
|
|
810
811
|
{ $unwind: '$itemListElement' },
|
|
811
812
|
...matchStages,
|
|
@@ -819,6 +820,10 @@ class MongoRepository {
|
|
|
819
820
|
.exec();
|
|
820
821
|
}
|
|
821
822
|
else {
|
|
823
|
+
const matchStages = [{ $match: { _id: { $eq: params.id } } }];
|
|
824
|
+
if (Array.isArray(params.itemListElementIds)) {
|
|
825
|
+
matchStages.push({ $match: { 'itemListElement.id': { $exists: true, $in: params.itemListElementIds } } });
|
|
826
|
+
}
|
|
822
827
|
itemListElements = yield this.offerCatalogModel.aggregate([
|
|
823
828
|
{ $unwind: '$itemListElement' },
|
|
824
829
|
...matchStages,
|
|
@@ -2,7 +2,7 @@ import { Connection } from 'mongoose';
|
|
|
2
2
|
import * as factory from '../factory';
|
|
3
3
|
export type IAggregatedOfferCatalog = Pick<factory.offerCatalog.IOfferCatalog, 'id' | 'name' | 'description' | 'project' | 'typeOf' | 'identifier' | 'itemOffered' | 'additionalProperty'> & {
|
|
4
4
|
numberOfItems?: number;
|
|
5
|
-
itemListElementTypeOf:
|
|
5
|
+
itemListElementTypeOf: factory.offerType.Offer;
|
|
6
6
|
};
|
|
7
7
|
/**
|
|
8
8
|
* オファーカタログアイテムリポジトリ
|
|
@@ -21,6 +21,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
21
21
|
};
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
23
|
exports.MongoRepository = void 0;
|
|
24
|
+
const mongoose_1 = require("mongoose");
|
|
24
25
|
const factory = require("../factory");
|
|
25
26
|
const offerCatalogItem_1 = require("./mongoose/schemas/offerCatalogItem");
|
|
26
27
|
/**
|
|
@@ -32,7 +33,7 @@ class MongoRepository {
|
|
|
32
33
|
}
|
|
33
34
|
// tslint:disable-next-line:max-func-body-length
|
|
34
35
|
static CREATE_MONGO_CONDITIONS(params) {
|
|
35
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u
|
|
36
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
|
|
36
37
|
// MongoDB検索条件
|
|
37
38
|
const andConditions = [];
|
|
38
39
|
const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
|
|
@@ -41,19 +42,17 @@ class MongoRepository {
|
|
|
41
42
|
}
|
|
42
43
|
const idIn = (_c = params.id) === null || _c === void 0 ? void 0 : _c.$in;
|
|
43
44
|
if (Array.isArray(idIn)) {
|
|
44
|
-
andConditions.push({ _id: { $in: idIn } });
|
|
45
|
+
andConditions.push({ _id: { $in: idIn.map((id) => new mongoose_1.Types.ObjectId(id)) } });
|
|
45
46
|
}
|
|
46
|
-
const idRegex =
|
|
47
|
-
if (typeof idRegex === 'string' && idRegex.length > 0) {
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
const identifierEq = (
|
|
47
|
+
// const idRegex = params.id?.$regex;
|
|
48
|
+
// if (typeof idRegex === 'string' && idRegex.length > 0) {
|
|
49
|
+
// andConditions.push({ _id: { $regex: new RegExp(idRegex) } });
|
|
50
|
+
// }
|
|
51
|
+
const identifierEq = (_d = params.identifier) === null || _d === void 0 ? void 0 : _d.$eq;
|
|
51
52
|
if (typeof identifierEq === 'string') {
|
|
52
|
-
andConditions.push({
|
|
53
|
-
identifier: { $eq: identifierEq }
|
|
54
|
-
});
|
|
53
|
+
andConditions.push({ identifier: { $eq: identifierEq } });
|
|
55
54
|
}
|
|
56
|
-
const identifierRegex = (
|
|
55
|
+
const identifierRegex = (_e = params.identifier) === null || _e === void 0 ? void 0 : _e.$regex;
|
|
57
56
|
if (typeof identifierRegex === 'string' && identifierRegex.length > 0) {
|
|
58
57
|
andConditions.push({ identifier: { $regex: new RegExp(identifierRegex) } });
|
|
59
58
|
}
|
|
@@ -65,31 +64,31 @@ class MongoRepository {
|
|
|
65
64
|
]
|
|
66
65
|
});
|
|
67
66
|
}
|
|
68
|
-
const itemListElementTypeOfEq = (
|
|
67
|
+
const itemListElementTypeOfEq = (_g = (_f = params.itemListElement) === null || _f === void 0 ? void 0 : _f.typeOf) === null || _g === void 0 ? void 0 : _g.$eq;
|
|
69
68
|
if (typeof itemListElementTypeOfEq === 'string') {
|
|
70
69
|
andConditions.push({ 'itemListElement.typeOf': { $exists: true, $eq: itemListElementTypeOfEq } });
|
|
71
70
|
}
|
|
72
|
-
const itemListElementIdIn = (
|
|
71
|
+
const itemListElementIdIn = (_j = (_h = params.itemListElement) === null || _h === void 0 ? void 0 : _h.id) === null || _j === void 0 ? void 0 : _j.$in;
|
|
73
72
|
if (Array.isArray(itemListElementIdIn)) {
|
|
74
73
|
andConditions.push({ 'itemListElement.id': { $exists: true, $in: itemListElementIdIn } });
|
|
75
74
|
}
|
|
76
|
-
const itemListElementIdNin = (
|
|
75
|
+
const itemListElementIdNin = (_l = (_k = params.itemListElement) === null || _k === void 0 ? void 0 : _k.id) === null || _l === void 0 ? void 0 : _l.$nin;
|
|
77
76
|
if (Array.isArray(itemListElementIdNin)) {
|
|
78
77
|
andConditions.push({ 'itemListElement.id': { $nin: itemListElementIdNin } });
|
|
79
78
|
}
|
|
80
|
-
const itemListElementIdAll = (
|
|
79
|
+
const itemListElementIdAll = (_o = (_m = params.itemListElement) === null || _m === void 0 ? void 0 : _m.id) === null || _o === void 0 ? void 0 : _o.$all;
|
|
81
80
|
if (Array.isArray(itemListElementIdAll)) {
|
|
82
81
|
andConditions.push({ 'itemListElement.id': { $exists: true, $all: itemListElementIdAll } });
|
|
83
82
|
}
|
|
84
|
-
const itemOfferedTypeOfEq = (
|
|
83
|
+
const itemOfferedTypeOfEq = (_q = (_p = params.itemOffered) === null || _p === void 0 ? void 0 : _p.typeOf) === null || _q === void 0 ? void 0 : _q.$eq;
|
|
85
84
|
if (typeof itemOfferedTypeOfEq === 'string') {
|
|
86
85
|
andConditions.push({ 'itemOffered.typeOf': { $exists: true, $eq: itemOfferedTypeOfEq } });
|
|
87
86
|
}
|
|
88
|
-
const itemOfferedServiceTypeCodeValueEq = (
|
|
87
|
+
const itemOfferedServiceTypeCodeValueEq = (_t = (_s = (_r = params.itemOffered) === null || _r === void 0 ? void 0 : _r.serviceType) === null || _s === void 0 ? void 0 : _s.codeValue) === null || _t === void 0 ? void 0 : _t.$eq;
|
|
89
88
|
if (typeof itemOfferedServiceTypeCodeValueEq === 'string') {
|
|
90
89
|
andConditions.push({ 'itemOffered.serviceType.codeValue': { $exists: true, $eq: itemOfferedServiceTypeCodeValueEq } });
|
|
91
90
|
}
|
|
92
|
-
const additionalPropertyElemMatch = (
|
|
91
|
+
const additionalPropertyElemMatch = (_u = params.additionalProperty) === null || _u === void 0 ? void 0 : _u.$elemMatch;
|
|
93
92
|
if (additionalPropertyElemMatch !== undefined && additionalPropertyElemMatch !== null) {
|
|
94
93
|
andConditions.push({ additionalProperty: { $exists: true, $elemMatch: additionalPropertyElemMatch } });
|
|
95
94
|
}
|
|
@@ -139,7 +138,7 @@ class MongoRepository {
|
|
|
139
138
|
description: '$description',
|
|
140
139
|
project: '$project',
|
|
141
140
|
typeOf: '$typeOf',
|
|
142
|
-
id: '$_id',
|
|
141
|
+
id: { $toString: '$_id' },
|
|
143
142
|
identifier: '$identifier',
|
|
144
143
|
itemOffered: '$itemOffered',
|
|
145
144
|
additionalProperty: '$additionalProperty',
|
package/package.json
CHANGED