@chevre/domain 21.4.0-alpha.0 → 21.4.0-alpha.2
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,57 @@
|
|
|
1
|
+
import { Connection } from 'mongoose';
|
|
2
|
+
import * as factory from '../factory';
|
|
3
|
+
/**
|
|
4
|
+
* プロダクトオファーリポジトリ
|
|
5
|
+
*/
|
|
6
|
+
export declare class MongoRepository {
|
|
7
|
+
private readonly productModel;
|
|
8
|
+
constructor(connection: Connection);
|
|
9
|
+
/**
|
|
10
|
+
* プロダクトオファー検索
|
|
11
|
+
*/
|
|
12
|
+
search(params: {
|
|
13
|
+
limit?: number;
|
|
14
|
+
page?: number;
|
|
15
|
+
project?: {
|
|
16
|
+
id?: {
|
|
17
|
+
$eq?: string;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
id?: {
|
|
21
|
+
$eq?: string;
|
|
22
|
+
};
|
|
23
|
+
seller?: {
|
|
24
|
+
id?: {
|
|
25
|
+
$eq?: string;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
}): Promise<(Pick<factory.product.IProduct, 'id' | 'name' | 'typeOf'> & {
|
|
29
|
+
offers: Pick<factory.product.IOffer, 'availabilityEnds' | 'availabilityStarts' | 'seller' | 'validFrom' | 'validThrough'>;
|
|
30
|
+
})[]>;
|
|
31
|
+
create(params: factory.product.IOffer & {
|
|
32
|
+
project: {
|
|
33
|
+
id: string;
|
|
34
|
+
};
|
|
35
|
+
itemOffered: {
|
|
36
|
+
/**
|
|
37
|
+
* プロダクトID
|
|
38
|
+
*/
|
|
39
|
+
id: string;
|
|
40
|
+
};
|
|
41
|
+
}): Promise<{
|
|
42
|
+
id: string;
|
|
43
|
+
}>;
|
|
44
|
+
update(params: factory.product.IOffer & {
|
|
45
|
+
project: {
|
|
46
|
+
id: string;
|
|
47
|
+
};
|
|
48
|
+
itemOffered: {
|
|
49
|
+
/**
|
|
50
|
+
* プロダクトID
|
|
51
|
+
*/
|
|
52
|
+
id: string;
|
|
53
|
+
};
|
|
54
|
+
}): Promise<{
|
|
55
|
+
id: string;
|
|
56
|
+
}>;
|
|
57
|
+
}
|
|
@@ -0,0 +1,162 @@
|
|
|
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
|
+
create(params) {
|
|
86
|
+
var _a;
|
|
87
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
88
|
+
const sellerId = (_a = params.seller) === null || _a === void 0 ? void 0 : _a.id;
|
|
89
|
+
if (typeof sellerId !== 'string' || sellerId.length === 0) {
|
|
90
|
+
throw new factory.errors.ArgumentNull('seller.id');
|
|
91
|
+
}
|
|
92
|
+
// プロダクト存在確認
|
|
93
|
+
let doc = yield this.productModel.findOne({
|
|
94
|
+
'project.id': { $eq: params.project.id },
|
|
95
|
+
_id: { $eq: params.itemOffered.id }
|
|
96
|
+
}, { _id: 1 })
|
|
97
|
+
.exec();
|
|
98
|
+
if (doc === null) {
|
|
99
|
+
throw new factory.errors.NotFound('Product');
|
|
100
|
+
}
|
|
101
|
+
const creatingOffer = {
|
|
102
|
+
priceCurrency: factory.priceCurrency.JPY,
|
|
103
|
+
availabilityEnds: params.availabilityEnds,
|
|
104
|
+
availabilityStarts: params.availabilityStarts,
|
|
105
|
+
validFrom: params.validFrom,
|
|
106
|
+
validThrough: params.validThrough,
|
|
107
|
+
seller: { id: sellerId },
|
|
108
|
+
typeOf: factory.offerType.Offer
|
|
109
|
+
};
|
|
110
|
+
doc = yield this.productModel.findOneAndUpdate({
|
|
111
|
+
'project.id': { $eq: params.project.id },
|
|
112
|
+
_id: { $eq: params.itemOffered.id },
|
|
113
|
+
'offers.seller.id': { $ne: sellerId }
|
|
114
|
+
}, {
|
|
115
|
+
$push: { offers: creatingOffer }
|
|
116
|
+
}, {
|
|
117
|
+
new: true,
|
|
118
|
+
projection: { _id: 1 }
|
|
119
|
+
})
|
|
120
|
+
.exec();
|
|
121
|
+
// 存在しなければプロバイダーID重複
|
|
122
|
+
if (doc === null) {
|
|
123
|
+
throw new factory.errors.AlreadyInUse('offers.seller', ['id']);
|
|
124
|
+
}
|
|
125
|
+
return doc.toObject();
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
update(params) {
|
|
129
|
+
var _a;
|
|
130
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
131
|
+
const sellerId = (_a = params.seller) === null || _a === void 0 ? void 0 : _a.id;
|
|
132
|
+
if (typeof sellerId !== 'string' || sellerId.length === 0) {
|
|
133
|
+
throw new factory.errors.ArgumentNull('seller.id');
|
|
134
|
+
}
|
|
135
|
+
const doc = yield this.productModel.findOneAndUpdate({
|
|
136
|
+
'project.id': { $eq: params.project.id },
|
|
137
|
+
_id: { $eq: params.itemOffered.id },
|
|
138
|
+
'offers.seller.id': { $exists: true, $eq: sellerId }
|
|
139
|
+
}, Object.assign(Object.assign(Object.assign(Object.assign({}, (params.availabilityEnds instanceof Date)
|
|
140
|
+
? { 'offers.$[offerBySeller].availabilityEnds': params.availabilityEnds }
|
|
141
|
+
: undefined), (params.availabilityStarts instanceof Date)
|
|
142
|
+
? { 'offers.$[offerBySeller].availabilityStarts': params.availabilityStarts }
|
|
143
|
+
: undefined), (params.validFrom instanceof Date)
|
|
144
|
+
? { 'offers.$[offerBySeller].validFrom': params.validFrom }
|
|
145
|
+
: undefined), (params.validThrough instanceof Date)
|
|
146
|
+
? { 'offers.$[offerBySeller].validThrough': params.validThrough }
|
|
147
|
+
: undefined), {
|
|
148
|
+
new: true,
|
|
149
|
+
arrayFilters: [
|
|
150
|
+
{ 'offerBySeller.seller.id': { $eq: sellerId } }
|
|
151
|
+
],
|
|
152
|
+
projection: { _id: 1 }
|
|
153
|
+
})
|
|
154
|
+
.exec();
|
|
155
|
+
if (doc === null) {
|
|
156
|
+
throw new factory.errors.NotFound('Product');
|
|
157
|
+
}
|
|
158
|
+
return doc.toObject();
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
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