@chevre/domain 21.3.0 → 21.4.0-alpha.1
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/searchProductOffers.ts +6 -21
- package/lib/chevre/repo/productOffer.d.ts +32 -0
- package/lib/chevre/repo/productOffer.js +86 -0
- package/lib/chevre/repo/seller.d.ts +0 -1
- package/lib/chevre/repo/seller.js +18 -16
- package/lib/chevre/repository.d.ts +3 -0
- package/lib/chevre/repository.js +5 -1
- package/package.json +2 -2
|
@@ -3,33 +3,18 @@ import * as mongoose from 'mongoose';
|
|
|
3
3
|
|
|
4
4
|
import { chevre } from '../../../lib/index';
|
|
5
5
|
|
|
6
|
-
const PROJECT_ID = process.env.PROJECT_ID;
|
|
6
|
+
const PROJECT_ID = String(process.env.PROJECT_ID);
|
|
7
7
|
|
|
8
8
|
async function main() {
|
|
9
9
|
await mongoose.connect(<string>process.env.MONGOLAB_URI);
|
|
10
10
|
|
|
11
|
-
const
|
|
12
|
-
const productRepo = new chevre.repository.Product(mongoose.connection);
|
|
11
|
+
const productOfferRepo = new chevre.repository.ProductOffer(mongoose.connection);
|
|
13
12
|
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
itemOffered: { id: '62b90fef5b3eb4000b75150f' },
|
|
18
|
-
// seller?: {
|
|
19
|
-
// id: string;
|
|
20
|
-
// },
|
|
21
|
-
// availableAt?: {
|
|
22
|
-
// id: string;
|
|
23
|
-
// },
|
|
24
|
-
onlyValid: true,
|
|
25
|
-
// limit?: number,
|
|
26
|
-
// page?: number,
|
|
27
|
-
addSortIndex: false
|
|
28
|
-
})({
|
|
29
|
-
offer: offerRepo,
|
|
30
|
-
product: productRepo
|
|
13
|
+
const offers = await productOfferRepo.search({
|
|
14
|
+
project: { id: { $eq: PROJECT_ID } }
|
|
15
|
+
// seller: { id: { $eq: 'xxx' } }
|
|
31
16
|
});
|
|
32
|
-
console.log(offers
|
|
17
|
+
console.log(offers);
|
|
33
18
|
console.log(offers.length);
|
|
34
19
|
}
|
|
35
20
|
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Connection } from 'mongoose';
|
|
2
|
+
import * as factory from '../factory';
|
|
3
|
+
export type IAvailablePaymentServiceType = factory.service.paymentService.PaymentServiceType.CreditCard | factory.service.paymentService.PaymentServiceType.MovieTicket;
|
|
4
|
+
/**
|
|
5
|
+
* プロダクトオファーリポジトリ
|
|
6
|
+
*/
|
|
7
|
+
export declare class MongoRepository {
|
|
8
|
+
private readonly productModel;
|
|
9
|
+
constructor(connection: Connection);
|
|
10
|
+
/**
|
|
11
|
+
* プロダクトオファー検索
|
|
12
|
+
*/
|
|
13
|
+
search(params: {
|
|
14
|
+
limit?: number;
|
|
15
|
+
page?: number;
|
|
16
|
+
project?: {
|
|
17
|
+
id?: {
|
|
18
|
+
$eq?: string;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
id?: {
|
|
22
|
+
$eq?: string;
|
|
23
|
+
};
|
|
24
|
+
seller?: {
|
|
25
|
+
id?: {
|
|
26
|
+
$eq?: string;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
}): Promise<(Pick<factory.product.IProduct, 'id' | 'name' | 'typeOf'> & {
|
|
30
|
+
offers: Pick<factory.product.IOffer, 'availabilityEnds' | 'availabilityStarts' | 'seller' | 'validFrom' | 'validThrough'>;
|
|
31
|
+
})[]>;
|
|
32
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.MongoRepository = void 0;
|
|
13
|
+
const mongoose_1 = require("mongoose");
|
|
14
|
+
const product_1 = require("./mongoose/schemas/product");
|
|
15
|
+
const factory = require("../factory");
|
|
16
|
+
const settings_1 = require("../settings");
|
|
17
|
+
/**
|
|
18
|
+
* プロダクトオファーリポジトリ
|
|
19
|
+
*/
|
|
20
|
+
class MongoRepository {
|
|
21
|
+
constructor(connection) {
|
|
22
|
+
this.productModel = connection.model(product_1.modelName, product_1.schema);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* プロダクトオファー検索
|
|
26
|
+
*/
|
|
27
|
+
search(params) {
|
|
28
|
+
var _a, _b, _c, _d, _e;
|
|
29
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
const matchStages = [{
|
|
31
|
+
$match: {
|
|
32
|
+
typeOf: {
|
|
33
|
+
$in: [
|
|
34
|
+
factory.product.ProductType.MembershipService,
|
|
35
|
+
factory.product.ProductType.PaymentCard
|
|
36
|
+
]
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}];
|
|
40
|
+
const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
|
|
41
|
+
if (typeof projectIdEq === 'string') {
|
|
42
|
+
matchStages.push({ $match: { 'project.id': { $eq: projectIdEq } } });
|
|
43
|
+
}
|
|
44
|
+
const idEq = (_c = params.id) === null || _c === void 0 ? void 0 : _c.$eq;
|
|
45
|
+
if (typeof idEq === 'string') {
|
|
46
|
+
matchStages.push({ $match: { _id: { $eq: new mongoose_1.Types.ObjectId(idEq) } } });
|
|
47
|
+
}
|
|
48
|
+
const sellerIdEq = (_e = (_d = params.seller) === null || _d === void 0 ? void 0 : _d.id) === null || _e === void 0 ? void 0 : _e.$eq;
|
|
49
|
+
if (typeof sellerIdEq === 'string') {
|
|
50
|
+
matchStages.push({ $match: { 'offers.seller.id': { $exists: true, $eq: sellerIdEq } } });
|
|
51
|
+
}
|
|
52
|
+
const aggregate = this.productModel.aggregate([
|
|
53
|
+
{ $sort: { productID: factory.sortType.Ascending } },
|
|
54
|
+
{
|
|
55
|
+
$unwind: {
|
|
56
|
+
path: '$offers'
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
...matchStages,
|
|
60
|
+
{
|
|
61
|
+
$project: {
|
|
62
|
+
_id: 0,
|
|
63
|
+
offers: {
|
|
64
|
+
availabilityEnds: '$offers.availabilityEnds',
|
|
65
|
+
availabilityStarts: '$offers.availabilityStarts',
|
|
66
|
+
validFrom: '$offers.validFrom',
|
|
67
|
+
validThrough: '$offers.validThrough',
|
|
68
|
+
seller: '$offers.seller'
|
|
69
|
+
},
|
|
70
|
+
id: { $toString: '$_id' },
|
|
71
|
+
name: '$name',
|
|
72
|
+
typeOf: '$typeOf'
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
]);
|
|
76
|
+
if (typeof params.limit === 'number' && params.limit > 0) {
|
|
77
|
+
const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
|
|
78
|
+
aggregate.limit(params.limit * page)
|
|
79
|
+
.skip(params.limit * (page - 1));
|
|
80
|
+
}
|
|
81
|
+
return aggregate.option({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
82
|
+
.exec();
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.MongoRepository = MongoRepository;
|
|
@@ -34,13 +34,17 @@ class MongoRepository {
|
|
|
34
34
|
}
|
|
35
35
|
// tslint:disable-next-line:max-func-body-length
|
|
36
36
|
static CREATE_MONGO_CONDITIONS(params) {
|
|
37
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
37
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
38
38
|
// MongoDB検索条件
|
|
39
39
|
const andConditions = [];
|
|
40
40
|
const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
|
|
41
41
|
if (typeof projectIdEq === 'string') {
|
|
42
42
|
andConditions.push({ 'project.id': { $eq: projectIdEq } });
|
|
43
43
|
}
|
|
44
|
+
const idEq = (_c = params.id) === null || _c === void 0 ? void 0 : _c.$eq;
|
|
45
|
+
if (typeof idEq === 'string') {
|
|
46
|
+
andConditions.push({ _id: { $eq: idEq } });
|
|
47
|
+
}
|
|
44
48
|
const nameRegex = params.name;
|
|
45
49
|
if (typeof nameRegex === 'string' && nameRegex.length > 0) {
|
|
46
50
|
andConditions.push({
|
|
@@ -60,7 +64,7 @@ class MongoRepository {
|
|
|
60
64
|
]
|
|
61
65
|
});
|
|
62
66
|
}
|
|
63
|
-
const branchCodeEq = (
|
|
67
|
+
const branchCodeEq = (_d = params.branchCode) === null || _d === void 0 ? void 0 : _d.$eq;
|
|
64
68
|
if (typeof branchCodeEq === 'string') {
|
|
65
69
|
andConditions.push({
|
|
66
70
|
branchCode: {
|
|
@@ -68,7 +72,7 @@ class MongoRepository {
|
|
|
68
72
|
}
|
|
69
73
|
});
|
|
70
74
|
}
|
|
71
|
-
const branchCodeRegex = (
|
|
75
|
+
const branchCodeRegex = (_e = params.branchCode) === null || _e === void 0 ? void 0 : _e.$regex;
|
|
72
76
|
if (typeof branchCodeRegex === 'string' && branchCodeRegex.length > 0) {
|
|
73
77
|
andConditions.push({
|
|
74
78
|
branchCode: {
|
|
@@ -76,7 +80,7 @@ class MongoRepository {
|
|
|
76
80
|
}
|
|
77
81
|
});
|
|
78
82
|
}
|
|
79
|
-
const additionalPropertyAll = (
|
|
83
|
+
const additionalPropertyAll = (_f = params.additionalProperty) === null || _f === void 0 ? void 0 : _f.$all;
|
|
80
84
|
if (Array.isArray(additionalPropertyAll)) {
|
|
81
85
|
andConditions.push({
|
|
82
86
|
additionalProperty: {
|
|
@@ -85,7 +89,7 @@ class MongoRepository {
|
|
|
85
89
|
}
|
|
86
90
|
});
|
|
87
91
|
}
|
|
88
|
-
const additionalPropertyIn = (
|
|
92
|
+
const additionalPropertyIn = (_g = params.additionalProperty) === null || _g === void 0 ? void 0 : _g.$in;
|
|
89
93
|
if (Array.isArray(additionalPropertyIn)) {
|
|
90
94
|
andConditions.push({
|
|
91
95
|
additionalProperty: {
|
|
@@ -94,7 +98,7 @@ class MongoRepository {
|
|
|
94
98
|
}
|
|
95
99
|
});
|
|
96
100
|
}
|
|
97
|
-
const additionalPropertyNin = (
|
|
101
|
+
const additionalPropertyNin = (_h = params.additionalProperty) === null || _h === void 0 ? void 0 : _h.$nin;
|
|
98
102
|
if (Array.isArray(additionalPropertyNin)) {
|
|
99
103
|
andConditions.push({
|
|
100
104
|
additionalProperty: {
|
|
@@ -102,7 +106,7 @@ class MongoRepository {
|
|
|
102
106
|
}
|
|
103
107
|
});
|
|
104
108
|
}
|
|
105
|
-
const additionalPropertyElemMatch = (
|
|
109
|
+
const additionalPropertyElemMatch = (_j = params.additionalProperty) === null || _j === void 0 ? void 0 : _j.$elemMatch;
|
|
106
110
|
if (additionalPropertyElemMatch !== undefined && additionalPropertyElemMatch !== null) {
|
|
107
111
|
andConditions.push({
|
|
108
112
|
additionalProperty: {
|
|
@@ -111,7 +115,7 @@ class MongoRepository {
|
|
|
111
115
|
}
|
|
112
116
|
});
|
|
113
117
|
}
|
|
114
|
-
const hasMerchantReturnPolicyItemConditionIdEq = (
|
|
118
|
+
const hasMerchantReturnPolicyItemConditionIdEq = (_m = (_l = (_k = params.hasMerchantReturnPolicy) === null || _k === void 0 ? void 0 : _k.itemCondition) === null || _l === void 0 ? void 0 : _l.id) === null || _m === void 0 ? void 0 : _m.$eq;
|
|
115
119
|
if (typeof hasMerchantReturnPolicyItemConditionIdEq === 'string') {
|
|
116
120
|
andConditions.push({
|
|
117
121
|
'hasMerchantReturnPolicy.itemCondition.id': {
|
|
@@ -178,14 +182,12 @@ class MongoRepository {
|
|
|
178
182
|
return organization;
|
|
179
183
|
});
|
|
180
184
|
}
|
|
181
|
-
count(params) {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
});
|
|
188
|
-
}
|
|
185
|
+
// public async count(params: factory.seller.ISearchConditions): Promise<number> {
|
|
186
|
+
// const conditions = MongoRepository.CREATE_MONGO_CONDITIONS(params);
|
|
187
|
+
// return this.organizationModel.countDocuments((conditions.length > 0) ? { $and: conditions } : {})
|
|
188
|
+
// .setOptions({ maxTimeMS: MONGO_MAX_TIME_MS })
|
|
189
|
+
// .exec();
|
|
190
|
+
// }
|
|
189
191
|
/**
|
|
190
192
|
* 販売者検索
|
|
191
193
|
*/
|
|
@@ -28,6 +28,7 @@ import { MongoRepository as PermitRepo } from './repo/permit';
|
|
|
28
28
|
import { MongoRepository as PlaceRepo } from './repo/place';
|
|
29
29
|
import { MongoRepository as PriceSpecificationRepo } from './repo/priceSpecification';
|
|
30
30
|
import { MongoRepository as ProductRepo } from './repo/product';
|
|
31
|
+
import { MongoRepository as ProductOfferRepo } from './repo/productOffer';
|
|
31
32
|
import { MongoRepository as ProjectRepo } from './repo/project';
|
|
32
33
|
import { RedisRepository as OfferRateLimitRepo } from './repo/rateLimit/offer';
|
|
33
34
|
import { MongoRepository as ReservationRepo } from './repo/reservation';
|
|
@@ -174,6 +175,8 @@ export declare class PriceSpecification extends PriceSpecificationRepo {
|
|
|
174
175
|
}
|
|
175
176
|
export declare class Product extends ProductRepo {
|
|
176
177
|
}
|
|
178
|
+
export declare class ProductOffer extends ProductOfferRepo {
|
|
179
|
+
}
|
|
177
180
|
export declare class Project extends ProjectRepo {
|
|
178
181
|
}
|
|
179
182
|
export declare class Reservation extends ReservationRepo {
|
package/lib/chevre/repository.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.rateLimit = exports.Trip = exports.TransactionNumber = exports.Transaction = exports.Telemetry = exports.Task = exports.StockHolder = exports.ServiceOutputIdentifier = exports.ServiceOutput = exports.Seller = exports.Role = exports.Reservation = exports.Project = exports.Product = exports.PriceSpecification = exports.Place = exports.Permit = exports.Person = exports.paymentMethod = exports.PaymentServiceProvider = exports.OwnershipInfo = exports.OrderNumber = exports.Order = exports.Offer = exports.OfferItemCondition = exports.OfferCatalog = exports.MerchantReturnPolicy = exports.Member = exports.Event = exports.EmailMessage = exports.Customer = exports.CreativeWork = exports.ConfirmationNumber = exports.Comment = exports.Code = exports.CategoryCode = exports.AssetTransaction = exports.action = exports.Aggregation = exports.AdditionalProperty = exports.Action = exports.AccountTransaction = exports.AccountTitle = exports.AccountingReport = exports.Account = void 0;
|
|
3
|
+
exports.rateLimit = exports.Trip = exports.TransactionNumber = exports.Transaction = exports.Telemetry = exports.Task = exports.StockHolder = exports.ServiceOutputIdentifier = exports.ServiceOutput = exports.Seller = exports.Role = exports.Reservation = exports.Project = exports.ProductOffer = exports.Product = exports.PriceSpecification = exports.Place = exports.Permit = exports.Person = exports.paymentMethod = exports.PaymentServiceProvider = exports.OwnershipInfo = exports.OrderNumber = exports.Order = exports.Offer = exports.OfferItemCondition = exports.OfferCatalog = exports.MerchantReturnPolicy = exports.Member = exports.Event = exports.EmailMessage = exports.Customer = exports.CreativeWork = exports.ConfirmationNumber = exports.Comment = exports.Code = exports.CategoryCode = exports.AssetTransaction = exports.action = exports.Aggregation = exports.AdditionalProperty = exports.Action = exports.AccountTransaction = exports.AccountTitle = exports.AccountingReport = exports.Account = void 0;
|
|
4
4
|
// tslint:disable:max-classes-per-file completed-docs
|
|
5
5
|
/**
|
|
6
6
|
* リポジトリ
|
|
@@ -32,6 +32,7 @@ const permit_1 = require("./repo/permit");
|
|
|
32
32
|
const place_1 = require("./repo/place");
|
|
33
33
|
const priceSpecification_1 = require("./repo/priceSpecification");
|
|
34
34
|
const product_1 = require("./repo/product");
|
|
35
|
+
const productOffer_1 = require("./repo/productOffer");
|
|
35
36
|
const project_1 = require("./repo/project");
|
|
36
37
|
const offer_2 = require("./repo/rateLimit/offer");
|
|
37
38
|
const reservation_1 = require("./repo/reservation");
|
|
@@ -212,6 +213,9 @@ exports.PriceSpecification = PriceSpecification;
|
|
|
212
213
|
class Product extends product_1.MongoRepository {
|
|
213
214
|
}
|
|
214
215
|
exports.Product = Product;
|
|
216
|
+
class ProductOffer extends productOffer_1.MongoRepository {
|
|
217
|
+
}
|
|
218
|
+
exports.ProductOffer = ProductOffer;
|
|
215
219
|
class Project extends project_1.MongoRepository {
|
|
216
220
|
}
|
|
217
221
|
exports.Project = Project;
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
}
|
|
10
10
|
],
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@chevre/factory": "4.
|
|
12
|
+
"@chevre/factory": "4.314.0",
|
|
13
13
|
"@cinerino/sdk": "3.157.1",
|
|
14
14
|
"@motionpicture/coa-service": "9.2.0",
|
|
15
15
|
"@motionpicture/gmo-service": "5.2.0",
|
|
@@ -117,5 +117,5 @@
|
|
|
117
117
|
"postversion": "git push origin --tags",
|
|
118
118
|
"prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
|
|
119
119
|
},
|
|
120
|
-
"version": "21.
|
|
120
|
+
"version": "21.4.0-alpha.1"
|
|
121
121
|
}
|