@chevre/domain 28.0.0-alpha.14 → 28.0.0-alpha.15
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.
|
@@ -5,29 +5,19 @@ import { Connection } from 'mongoose';
|
|
|
5
5
|
export declare class SellerPaymentAcceptedRepo {
|
|
6
6
|
private readonly sellerModel;
|
|
7
7
|
constructor(connection: Connection);
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
$eq?: string;
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
project?: {
|
|
17
|
-
id?: {
|
|
18
|
-
$eq?: string;
|
|
19
|
-
};
|
|
20
|
-
};
|
|
8
|
+
findSellerPaymentAccepted(params: {
|
|
9
|
+
sellerId: string;
|
|
10
|
+
projectId: string;
|
|
11
|
+
limit: number;
|
|
12
|
+
page: number;
|
|
21
13
|
codeValue?: {
|
|
22
14
|
$eq?: string;
|
|
23
15
|
};
|
|
24
16
|
}): Promise<{
|
|
25
17
|
codeValue: string;
|
|
26
|
-
seller: {
|
|
27
|
-
id: string;
|
|
28
|
-
};
|
|
29
18
|
}[]>;
|
|
30
|
-
|
|
19
|
+
private countSellerPaymentAccepted;
|
|
20
|
+
addSellerPaymentAccepted(params: {
|
|
31
21
|
codeValue: string;
|
|
32
22
|
project: {
|
|
33
23
|
id: string;
|
|
@@ -35,8 +25,10 @@ export declare class SellerPaymentAcceptedRepo {
|
|
|
35
25
|
seller: {
|
|
36
26
|
id: string;
|
|
37
27
|
};
|
|
28
|
+
}, options: {
|
|
29
|
+
maxNumSellerPaymentAccepted: number;
|
|
38
30
|
}): Promise<void>;
|
|
39
|
-
|
|
31
|
+
deleteSellerPaymentAccepted(params: {
|
|
40
32
|
codeValue: string;
|
|
41
33
|
project: {
|
|
42
34
|
id: string;
|
|
@@ -13,21 +13,21 @@ class SellerPaymentAcceptedRepo {
|
|
|
13
13
|
constructor(connection) {
|
|
14
14
|
this.sellerModel = connection.model(seller_1.modelName, (0, seller_1.createSchema)());
|
|
15
15
|
}
|
|
16
|
-
async
|
|
16
|
+
async findSellerPaymentAccepted(params) {
|
|
17
|
+
const { sellerId, projectId } = params;
|
|
17
18
|
const matchStages = [];
|
|
18
|
-
const projectIdEq = params.project?.id?.$eq;
|
|
19
|
-
if (typeof projectIdEq === 'string') {
|
|
20
|
-
matchStages.push({ $match: { 'project.id': { $eq: projectIdEq } } });
|
|
21
|
-
}
|
|
22
|
-
const sellerIdEq = params.seller?.id?.$eq;
|
|
23
|
-
if (typeof sellerIdEq === 'string') {
|
|
24
|
-
matchStages.push({ $match: { _id: { $eq: new mongoose_1.Types.ObjectId(sellerIdEq) } } });
|
|
25
|
-
}
|
|
26
19
|
const codeValueEq = params.codeValue?.$eq;
|
|
27
20
|
if (typeof codeValueEq === 'string') {
|
|
28
21
|
matchStages.push({ $match: { 'paymentAccepted.paymentMethodType': { $exists: true, $eq: codeValueEq } } });
|
|
29
22
|
}
|
|
30
23
|
const aggregate = this.sellerModel.aggregate([
|
|
24
|
+
// まず販売者ドキュメントで絞る
|
|
25
|
+
{
|
|
26
|
+
$match: {
|
|
27
|
+
_id: { $eq: new mongoose_1.Types.ObjectId(sellerId) },
|
|
28
|
+
'project.id': { $eq: projectId }
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
31
|
{
|
|
32
32
|
$unwind: {
|
|
33
33
|
path: '$paymentAccepted'
|
|
@@ -39,45 +39,82 @@ class SellerPaymentAcceptedRepo {
|
|
|
39
39
|
$project: {
|
|
40
40
|
_id: 0,
|
|
41
41
|
codeValue: '$paymentAccepted.paymentMethodType',
|
|
42
|
-
seller: { id: { $toString: '$_id' } }
|
|
43
42
|
}
|
|
44
43
|
}
|
|
45
44
|
]);
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
45
|
+
const { limit, page } = params;
|
|
46
|
+
const pageMustBePositive = (typeof page === 'number' && page > 0) ? page : 1;
|
|
47
|
+
aggregate.skip(limit * (pageMustBePositive - 1))
|
|
48
|
+
.limit(limit);
|
|
51
49
|
return aggregate.option({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
52
50
|
.exec();
|
|
53
51
|
}
|
|
54
|
-
async
|
|
55
|
-
|
|
52
|
+
async countSellerPaymentAccepted(params) {
|
|
53
|
+
const paymentAcceptedCount = (await this.sellerModel.aggregate([
|
|
54
|
+
{
|
|
55
|
+
$match: {
|
|
56
|
+
_id: { $eq: new mongoose_1.Types.ObjectId(params.seller.id) },
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
$project: {
|
|
61
|
+
paymentAcceptedCount: {
|
|
62
|
+
$cond: {
|
|
63
|
+
if: { $isArray: '$paymentAccepted' },
|
|
64
|
+
then: { $size: '$paymentAccepted' },
|
|
65
|
+
else: 0
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
]).option({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
71
|
+
.exec()).at(0)?.paymentAcceptedCount;
|
|
72
|
+
if (typeof paymentAcceptedCount !== 'number') {
|
|
73
|
+
throw new factory_1.factory.errors.NotFound(factory_1.factory.organizationType.Corporation);
|
|
74
|
+
}
|
|
75
|
+
return { paymentAcceptedCount };
|
|
76
|
+
}
|
|
77
|
+
async addSellerPaymentAccepted(params, options) {
|
|
78
|
+
const sellerDoc = await this.sellerModel.findOne({
|
|
56
79
|
'project.id': { $eq: params.project.id },
|
|
57
80
|
_id: { $eq: params.seller.id }
|
|
58
81
|
}, { _id: 1 })
|
|
82
|
+
.lean()
|
|
59
83
|
.exec();
|
|
60
|
-
if (
|
|
84
|
+
if (sellerDoc === null) {
|
|
61
85
|
throw new factory_1.factory.errors.NotFound(factory_1.factory.organizationType.Corporation);
|
|
62
86
|
}
|
|
87
|
+
// 最大数検証(2026-09-20~)
|
|
88
|
+
const { maxNumSellerPaymentAccepted } = options;
|
|
89
|
+
const { paymentAcceptedCount } = await this.countSellerPaymentAccepted({ seller: params.seller });
|
|
90
|
+
if (paymentAcceptedCount >= maxNumSellerPaymentAccepted) {
|
|
91
|
+
throw new factory_1.factory.errors.Argument('seller.id', 'maxNumSellerPaymentAccepted exceeded');
|
|
92
|
+
}
|
|
63
93
|
const creatingPaymentAccepted = {
|
|
64
94
|
paymentMethodType: params.codeValue
|
|
65
95
|
};
|
|
66
|
-
doc = await this.sellerModel.findOneAndUpdate({
|
|
96
|
+
const doc = await this.sellerModel.findOneAndUpdate({
|
|
67
97
|
'project.id': { $eq: params.project.id },
|
|
68
98
|
_id: { $eq: params.seller.id },
|
|
69
99
|
'paymentAccepted.paymentMethodType': { $ne: params.codeValue }
|
|
70
100
|
}, {
|
|
71
|
-
$push: { paymentAccepted: creatingPaymentAccepted }
|
|
101
|
+
// $push: { paymentAccepted: creatingPaymentAccepted }
|
|
102
|
+
$push: {
|
|
103
|
+
paymentAccepted: {
|
|
104
|
+
$each: [creatingPaymentAccepted],
|
|
105
|
+
$slice: maxNumSellerPaymentAccepted // 最大数担保(2026-09-22~)
|
|
106
|
+
},
|
|
107
|
+
}
|
|
72
108
|
}, {
|
|
73
109
|
projection: { _id: 1 }
|
|
74
110
|
})
|
|
111
|
+
.lean()
|
|
75
112
|
.exec();
|
|
76
113
|
if (doc === null) {
|
|
77
114
|
throw new factory_1.factory.errors.AlreadyInUse('paymentAccepted', ['paymentMethodType']);
|
|
78
115
|
}
|
|
79
116
|
}
|
|
80
|
-
async
|
|
117
|
+
async deleteSellerPaymentAccepted(params) {
|
|
81
118
|
const doc = await this.sellerModel.findOneAndUpdate({
|
|
82
119
|
'project.id': { $eq: params.project.id },
|
|
83
120
|
_id: { $eq: params.seller.id },
|
|
@@ -87,6 +124,7 @@ class SellerPaymentAcceptedRepo {
|
|
|
87
124
|
}, {
|
|
88
125
|
projection: { _id: 1 }
|
|
89
126
|
})
|
|
127
|
+
.lean()
|
|
90
128
|
.exec();
|
|
91
129
|
if (doc === null) {
|
|
92
130
|
throw new factory_1.factory.errors.NotFound(factory_1.factory.organizationType.Corporation);
|
|
@@ -94,10 +132,11 @@ class SellerPaymentAcceptedRepo {
|
|
|
94
132
|
}
|
|
95
133
|
async isAcceptedBySeller(params) {
|
|
96
134
|
const aggregate = this.sellerModel.aggregate([
|
|
135
|
+
// まず販売者ドキュメントで絞る
|
|
136
|
+
{ $match: { _id: { $eq: new mongoose_1.Types.ObjectId(params.seller.id) } } },
|
|
97
137
|
{
|
|
98
138
|
$unwind: { path: '$paymentAccepted' }
|
|
99
139
|
},
|
|
100
|
-
{ $match: { _id: { $eq: new mongoose_1.Types.ObjectId(params.seller.id) } } },
|
|
101
140
|
{ $match: { 'paymentAccepted.paymentMethodType': { $exists: true, $eq: params.codeValue } } },
|
|
102
141
|
{
|
|
103
142
|
$project: {
|
|
@@ -106,8 +145,8 @@ class SellerPaymentAcceptedRepo {
|
|
|
106
145
|
}
|
|
107
146
|
}
|
|
108
147
|
])
|
|
109
|
-
.
|
|
110
|
-
.
|
|
148
|
+
.skip(0)
|
|
149
|
+
.limit(1);
|
|
111
150
|
return (await aggregate.option({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
112
151
|
.exec()).length > 0;
|
|
113
152
|
}
|
package/package.json
CHANGED