@chevre/domain 21.4.0-alpha.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.
|
@@ -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;
|
|
@@ -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