@chevre/domain 21.4.0-alpha.1 → 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.
|
@@ -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
|
*/
|
|
@@ -29,4 +28,30 @@ export declare class MongoRepository {
|
|
|
29
28
|
}): Promise<(Pick<factory.product.IProduct, 'id' | 'name' | 'typeOf'> & {
|
|
30
29
|
offers: Pick<factory.product.IOffer, 'availabilityEnds' | 'availabilityStarts' | 'seller' | 'validFrom' | 'validThrough'>;
|
|
31
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
|
+
}>;
|
|
32
57
|
}
|
|
@@ -82,5 +82,81 @@ 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
|
+
}
|
|
85
161
|
}
|
|
86
162
|
exports.MongoRepository = MongoRepository;
|
package/package.json
CHANGED