@chevre/domain 28.0.0-alpha.13 → 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.
@@ -24,11 +24,6 @@ export declare class POSRepo {
24
24
  $eq?: string;
25
25
  $regex?: string;
26
26
  };
27
- }, options: {
28
- /**
29
- * 2026-09-18~
30
- */
31
- excludePOSId: boolean;
32
27
  }): Promise<Pick<factory.place.movieTheater.IPOS, 'branchCode' | 'name'>[]>;
33
28
  private countPOS;
34
29
  addPOSByBranchCode(params: Pick<factory.place.movieTheater.IPOS, 'branchCode' | 'name'> & {
@@ -37,22 +32,16 @@ export declare class POSRepo {
37
32
  };
38
33
  }, options: {
39
34
  maxNumPOS: number;
40
- }): Promise<{
41
- id: string;
42
- }>;
43
- updateByBranchCode(params: Pick<factory.place.movieTheater.IPOS, 'branchCode' | 'name'> & {
35
+ }): Promise<void>;
36
+ updatePOSByBranchCode(params: Pick<factory.place.movieTheater.IPOS, 'branchCode' | 'name'> & {
44
37
  project: {
45
38
  id: string;
46
39
  };
47
- }): Promise<{
48
- id: string;
49
- }>;
50
- deleteByBranchCode(params: Pick<factory.place.movieTheater.IPOS, 'branchCode'> & {
40
+ }): Promise<void>;
41
+ deletePOSByBranchCode(params: Pick<factory.place.movieTheater.IPOS, 'branchCode'> & {
51
42
  project: {
52
43
  id: string;
53
44
  };
54
- }): Promise<{
55
- id: string;
56
- }>;
45
+ }): Promise<void>;
57
46
  }
58
47
  export {};
@@ -15,7 +15,7 @@ class POSRepo {
15
15
  this.civicStructureModel = connection.model(civicStructure_1.modelName, (0, civicStructure_1.createSchema)());
16
16
  this.operator = operater;
17
17
  }
18
- async findPOS(params, options) {
18
+ async findPOS(params) {
19
19
  const matchStages = [];
20
20
  const branchCodeEq = params.branchCode?.$eq;
21
21
  if (typeof branchCodeEq === 'string') {
@@ -25,7 +25,6 @@ class POSRepo {
25
25
  if (typeof branchCodeRegex === 'string' && branchCodeRegex.length > 0) {
26
26
  matchStages.push({ $match: { 'hasPOS.branchCode': { $regex: new RegExp(branchCodeRegex) } } });
27
27
  }
28
- const { excludePOSId } = options;
29
28
  const aggregate = this.civicStructureModel.aggregate([
30
29
  // まず施設ドキュメントで絞る
31
30
  {
@@ -46,7 +45,7 @@ class POSRepo {
46
45
  _id: 0,
47
46
  branchCode: '$hasPOS.branchCode',
48
47
  name: '$hasPOS.name',
49
- ...((!excludePOSId) && { id: '$hasPOS.branchCode' })
48
+ // ...((!excludePOSId) && { id: '$hasPOS.branchCode' }) // discontinue(2026-09-22~)
50
49
  }
51
50
  }
52
51
  ]);
@@ -85,12 +84,13 @@ class POSRepo {
85
84
  }
86
85
  async addPOSByBranchCode(params, options) {
87
86
  // 施設存在確認
88
- let doc = await this.civicStructureModel.findOne({
87
+ const movieTheaterDoc = await this.civicStructureModel.findOne({
89
88
  'project.id': { $eq: params.project.id },
90
89
  _id: { $eq: this.operator.id }
91
- }, { _id: 1, typeOf: 1 })
90
+ }, { _id: 1 })
91
+ .lean()
92
92
  .exec();
93
- if (doc === null) {
93
+ if (movieTheaterDoc === null) {
94
94
  throw new factory_1.factory.errors.NotFound(factory_1.factory.placeType.MovieTheater);
95
95
  }
96
96
  // 最大数検証(2026-09-20~)
@@ -100,12 +100,12 @@ class POSRepo {
100
100
  throw new factory_1.factory.errors.Argument('operator.id', 'maxNumPOS exceeded');
101
101
  }
102
102
  const creatingPOS = {
103
- // 互換性維持対応としてidを保管
104
- id: params.branchCode, // eslint-disable-line @typescript-eslint/no-explicit-any
103
+ // // 互換性維持対応としてidを保管
104
+ // id: params.branchCode as any, // discontinue(2026-09-22~)
105
105
  branchCode: params.branchCode,
106
106
  name: params.name
107
107
  };
108
- doc = await this.civicStructureModel.findOneAndUpdate({
108
+ const doc = await this.civicStructureModel.findOneAndUpdate({
109
109
  'project.id': { $eq: params.project.id },
110
110
  _id: { $eq: this.operator.id },
111
111
  'hasPOS.branchCode': { $ne: params.branchCode }
@@ -120,14 +120,14 @@ class POSRepo {
120
120
  new: true,
121
121
  projection: { _id: 1 }
122
122
  })
123
+ .lean()
123
124
  .exec();
124
125
  // 存在しなければID重複
125
126
  if (doc === null) {
126
127
  throw new factory_1.factory.errors.AlreadyInUse('hasPOS', ['id']);
127
128
  }
128
- return doc.toObject({ virtuals: true });
129
129
  }
130
- async updateByBranchCode(params) {
130
+ async updatePOSByBranchCode(params) {
131
131
  const doc = await this.civicStructureModel.findOneAndUpdate({
132
132
  'project.id': { $eq: params.project.id },
133
133
  _id: { $eq: this.operator.id },
@@ -145,13 +145,13 @@ class POSRepo {
145
145
  ],
146
146
  projection: { _id: 1 }
147
147
  })
148
+ .lean()
148
149
  .exec();
149
150
  if (doc === null) {
150
151
  throw new factory_1.factory.errors.NotFound('hasPOS');
151
152
  }
152
- return doc.toObject({ virtuals: true });
153
153
  }
154
- async deleteByBranchCode(params) {
154
+ async deletePOSByBranchCode(params) {
155
155
  const doc = await this.civicStructureModel.findOneAndUpdate({
156
156
  'project.id': { $eq: params.project.id },
157
157
  _id: { $eq: this.operator.id },
@@ -161,11 +161,11 @@ class POSRepo {
161
161
  }, {
162
162
  projection: { _id: 1 }
163
163
  })
164
+ .lean()
164
165
  .exec();
165
166
  if (doc === null) {
166
167
  throw new factory_1.factory.errors.NotFound('hasPOS');
167
168
  }
168
- return doc.toObject({ virtuals: true });
169
169
  }
170
170
  }
171
171
  exports.POSRepo = POSRepo;
@@ -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
- search(params: {
9
- limit?: number;
10
- page?: number;
11
- seller?: {
12
- id?: {
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
- create(params: {
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
- deleteOne(params: {
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 search(params) {
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
- if (typeof params.limit === 'number' && params.limit > 0) {
47
- const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
48
- aggregate.limit(params.limit * page)
49
- .skip(params.limit * (page - 1));
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 create(params) {
55
- let doc = await this.sellerModel.findOne({
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 (doc === null) {
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 deleteOne(params) {
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
- .limit(1)
110
- .skip(0);
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
  }
@@ -28,7 +28,7 @@ function createInformHasPOSTasks(params) {
28
28
  repos.pos.operator.id = movieTheater.id;
29
29
  const hasPOS = await repos.pos.findPOS({
30
30
  projectId: params.project.id
31
- }, { excludePOSId: true }); // pos.idを除外(2026-09-18~)
31
+ }); // pos.idを除外(2026-09-18~)
32
32
  const movieTheaters4inform = [{
33
33
  hasPOS: (Array.isArray(hasPOS)) ? hasPOS : [],
34
34
  id: movieTheater.id,
package/package.json CHANGED
@@ -88,5 +88,5 @@
88
88
  "postversion": "git push origin --tags",
89
89
  "prepublishOnly": "npm run clean && npm run build"
90
90
  },
91
- "version": "28.0.0-alpha.13"
91
+ "version": "28.0.0-alpha.15"
92
92
  }