@chevre/domain 21.4.0-alpha.1 → 21.4.0-alpha.3
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.
|
@@ -16,6 +16,12 @@ async function main() {
|
|
|
16
16
|
});
|
|
17
17
|
console.log(offers);
|
|
18
18
|
console.log(offers.length);
|
|
19
|
+
|
|
20
|
+
// await productOfferRepo.deleteOne({
|
|
21
|
+
// project: { id: PROJECT_ID },
|
|
22
|
+
// seller: { id: 'xxx' },
|
|
23
|
+
// itemOffered: { id: 'xxx' }
|
|
24
|
+
// });
|
|
19
25
|
}
|
|
20
26
|
|
|
21
27
|
main()
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Connection } from 'mongoose';
|
|
2
2
|
import * as factory from '../factory';
|
|
3
|
-
export type IAvailablePaymentServiceType = factory.service.paymentService.PaymentServiceType.CreditCard | factory.service.paymentService.PaymentServiceType.MovieTicket;
|
|
4
3
|
/**
|
|
5
4
|
* プロダクトオファーリポジトリ
|
|
6
5
|
*/
|
|
@@ -18,15 +17,56 @@ export declare class MongoRepository {
|
|
|
18
17
|
$eq?: string;
|
|
19
18
|
};
|
|
20
19
|
};
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
itemOffered?: {
|
|
21
|
+
id?: {
|
|
22
|
+
$eq?: string;
|
|
23
|
+
};
|
|
23
24
|
};
|
|
24
25
|
seller?: {
|
|
25
26
|
id?: {
|
|
26
27
|
$eq?: string;
|
|
27
28
|
};
|
|
28
29
|
};
|
|
29
|
-
}): Promise<(Pick<factory.product.
|
|
30
|
-
|
|
30
|
+
}): Promise<(Pick<factory.product.IOffer, 'availabilityEnds' | 'availabilityStarts' | 'seller' | 'validFrom' | 'validThrough'> & {
|
|
31
|
+
itemOffered: Pick<factory.product.IProduct, 'id' | 'name' | 'typeOf'>;
|
|
31
32
|
})[]>;
|
|
33
|
+
create(params: factory.product.IOffer & {
|
|
34
|
+
project: {
|
|
35
|
+
id: string;
|
|
36
|
+
};
|
|
37
|
+
itemOffered: {
|
|
38
|
+
/**
|
|
39
|
+
* プロダクトID
|
|
40
|
+
*/
|
|
41
|
+
id: string;
|
|
42
|
+
};
|
|
43
|
+
}): Promise<{
|
|
44
|
+
id: string;
|
|
45
|
+
}>;
|
|
46
|
+
update(params: factory.product.IOffer & {
|
|
47
|
+
project: {
|
|
48
|
+
id: string;
|
|
49
|
+
};
|
|
50
|
+
itemOffered: {
|
|
51
|
+
/**
|
|
52
|
+
* プロダクトID
|
|
53
|
+
*/
|
|
54
|
+
id: string;
|
|
55
|
+
};
|
|
56
|
+
}): Promise<{
|
|
57
|
+
id: string;
|
|
58
|
+
}>;
|
|
59
|
+
deleteOne(params: Pick<factory.product.IOffer, 'seller'> & {
|
|
60
|
+
project: {
|
|
61
|
+
id: string;
|
|
62
|
+
};
|
|
63
|
+
itemOffered: {
|
|
64
|
+
/**
|
|
65
|
+
* プロダクトID
|
|
66
|
+
*/
|
|
67
|
+
id: string;
|
|
68
|
+
};
|
|
69
|
+
}): Promise<{
|
|
70
|
+
id: string;
|
|
71
|
+
}>;
|
|
32
72
|
}
|
|
@@ -25,7 +25,7 @@ class MongoRepository {
|
|
|
25
25
|
* プロダクトオファー検索
|
|
26
26
|
*/
|
|
27
27
|
search(params) {
|
|
28
|
-
var _a, _b, _c, _d, _e;
|
|
28
|
+
var _a, _b, _c, _d, _e, _f;
|
|
29
29
|
return __awaiter(this, void 0, void 0, function* () {
|
|
30
30
|
const matchStages = [{
|
|
31
31
|
$match: {
|
|
@@ -41,11 +41,11 @@ class MongoRepository {
|
|
|
41
41
|
if (typeof projectIdEq === 'string') {
|
|
42
42
|
matchStages.push({ $match: { 'project.id': { $eq: projectIdEq } } });
|
|
43
43
|
}
|
|
44
|
-
const
|
|
45
|
-
if (typeof
|
|
46
|
-
matchStages.push({ $match: { _id: { $eq: new mongoose_1.Types.ObjectId(
|
|
44
|
+
const itemOfferedIdEq = (_d = (_c = params.itemOffered) === null || _c === void 0 ? void 0 : _c.id) === null || _d === void 0 ? void 0 : _d.$eq;
|
|
45
|
+
if (typeof itemOfferedIdEq === 'string') {
|
|
46
|
+
matchStages.push({ $match: { _id: { $eq: new mongoose_1.Types.ObjectId(itemOfferedIdEq) } } });
|
|
47
47
|
}
|
|
48
|
-
const sellerIdEq = (
|
|
48
|
+
const sellerIdEq = (_f = (_e = params.seller) === null || _e === void 0 ? void 0 : _e.id) === null || _f === void 0 ? void 0 : _f.$eq;
|
|
49
49
|
if (typeof sellerIdEq === 'string') {
|
|
50
50
|
matchStages.push({ $match: { 'offers.seller.id': { $exists: true, $eq: sellerIdEq } } });
|
|
51
51
|
}
|
|
@@ -60,16 +60,16 @@ class MongoRepository {
|
|
|
60
60
|
{
|
|
61
61
|
$project: {
|
|
62
62
|
_id: 0,
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
validThrough: '$offers.validThrough',
|
|
68
|
-
seller: '$offers.seller'
|
|
63
|
+
itemOffered: {
|
|
64
|
+
id: { $toString: '$_id' },
|
|
65
|
+
name: '$name',
|
|
66
|
+
typeOf: '$typeOf'
|
|
69
67
|
},
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
68
|
+
availabilityEnds: '$offers.availabilityEnds',
|
|
69
|
+
availabilityStarts: '$offers.availabilityStarts',
|
|
70
|
+
validFrom: '$offers.validFrom',
|
|
71
|
+
validThrough: '$offers.validThrough',
|
|
72
|
+
seller: '$offers.seller'
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
]);
|
|
@@ -82,5 +82,104 @@ class MongoRepository {
|
|
|
82
82
|
.exec();
|
|
83
83
|
});
|
|
84
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
|
+
deleteOne(params) {
|
|
162
|
+
var _a;
|
|
163
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
164
|
+
const sellerId = (_a = params.seller) === null || _a === void 0 ? void 0 : _a.id;
|
|
165
|
+
if (typeof sellerId !== 'string' || sellerId.length === 0) {
|
|
166
|
+
throw new factory.errors.ArgumentNull('seller.id');
|
|
167
|
+
}
|
|
168
|
+
const doc = yield this.productModel.findOneAndUpdate({
|
|
169
|
+
'project.id': { $eq: params.project.id },
|
|
170
|
+
_id: { $eq: params.itemOffered.id },
|
|
171
|
+
'offers.seller.id': { $exists: true, $eq: sellerId }
|
|
172
|
+
}, {
|
|
173
|
+
$pull: { offers: { 'seller.id': { $exists: true, $eq: sellerId } } }
|
|
174
|
+
}, {
|
|
175
|
+
projection: { _id: 1 }
|
|
176
|
+
})
|
|
177
|
+
.exec();
|
|
178
|
+
if (doc === null) {
|
|
179
|
+
throw new factory.errors.NotFound('Product');
|
|
180
|
+
}
|
|
181
|
+
return doc.toObject();
|
|
182
|
+
});
|
|
183
|
+
}
|
|
85
184
|
}
|
|
86
185
|
exports.MongoRepository = MongoRepository;
|
package/package.json
CHANGED