@chevre/domain 28.0.0-alpha.12 → 28.0.0-alpha.14

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,32 +24,24 @@ 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
- createByBranchCode(params: Pick<factory.place.movieTheater.IPOS, 'branchCode' | 'name'> & {
28
+ private countPOS;
29
+ addPOSByBranchCode(params: Pick<factory.place.movieTheater.IPOS, 'branchCode' | 'name'> & {
34
30
  project: {
35
31
  id: string;
36
32
  };
37
- }): Promise<{
38
- id: string;
39
- }>;
40
- updateByBranchCode(params: Pick<factory.place.movieTheater.IPOS, 'branchCode' | 'name'> & {
33
+ }, options: {
34
+ maxNumPOS: number;
35
+ }): Promise<void>;
36
+ updatePOSByBranchCode(params: Pick<factory.place.movieTheater.IPOS, 'branchCode' | 'name'> & {
41
37
  project: {
42
38
  id: string;
43
39
  };
44
- }): Promise<{
45
- id: string;
46
- }>;
47
- deleteByBranchCode(params: Pick<factory.place.movieTheater.IPOS, 'branchCode'> & {
40
+ }): Promise<void>;
41
+ deletePOSByBranchCode(params: Pick<factory.place.movieTheater.IPOS, 'branchCode'> & {
48
42
  project: {
49
43
  id: string;
50
44
  };
51
- }): Promise<{
52
- id: string;
53
- }>;
45
+ }): Promise<void>;
54
46
  }
55
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
  ]);
@@ -58,40 +57,77 @@ class POSRepo {
58
57
  return aggregate.option({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
59
58
  .exec();
60
59
  }
61
- async createByBranchCode(params) {
60
+ async countPOS() {
61
+ const posCount = (await this.civicStructureModel.aggregate([
62
+ {
63
+ $match: {
64
+ _id: { $eq: new mongoose_1.Types.ObjectId(this.operator.id) },
65
+ }
66
+ },
67
+ {
68
+ $project: {
69
+ posCount: {
70
+ $cond: {
71
+ if: { $isArray: '$hasPOS' },
72
+ then: { $size: '$hasPOS' },
73
+ else: 0
74
+ }
75
+ }
76
+ }
77
+ }
78
+ ]).option({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
79
+ .exec()).at(0)?.posCount;
80
+ if (typeof posCount !== 'number') {
81
+ throw new factory_1.factory.errors.NotFound(factory_1.factory.placeType.MovieTheater);
82
+ }
83
+ return { posCount };
84
+ }
85
+ async addPOSByBranchCode(params, options) {
62
86
  // 施設存在確認
63
- let doc = await this.civicStructureModel.findOne({
87
+ const movieTheaterDoc = await this.civicStructureModel.findOne({
64
88
  'project.id': { $eq: params.project.id },
65
89
  _id: { $eq: this.operator.id }
66
- }, { _id: 1, typeOf: 1 })
90
+ }, { _id: 1 })
91
+ .lean()
67
92
  .exec();
68
- if (doc === null) {
93
+ if (movieTheaterDoc === null) {
69
94
  throw new factory_1.factory.errors.NotFound(factory_1.factory.placeType.MovieTheater);
70
95
  }
96
+ // 最大数検証(2026-09-20~)
97
+ const { maxNumPOS } = options;
98
+ const { posCount } = await this.countPOS();
99
+ if (posCount >= maxNumPOS) {
100
+ throw new factory_1.factory.errors.Argument('operator.id', 'maxNumPOS exceeded');
101
+ }
71
102
  const creatingPOS = {
72
- // 互換性維持対応としてidを保管
73
- id: params.branchCode, // eslint-disable-line @typescript-eslint/no-explicit-any
103
+ // // 互換性維持対応としてidを保管
104
+ // id: params.branchCode as any, // discontinue(2026-09-22~)
74
105
  branchCode: params.branchCode,
75
106
  name: params.name
76
107
  };
77
- doc = await this.civicStructureModel.findOneAndUpdate({
108
+ const doc = await this.civicStructureModel.findOneAndUpdate({
78
109
  'project.id': { $eq: params.project.id },
79
110
  _id: { $eq: this.operator.id },
80
111
  'hasPOS.branchCode': { $ne: params.branchCode }
81
112
  }, {
82
- $push: { hasPOS: creatingPOS }
113
+ $push: {
114
+ hasPOS: {
115
+ $each: [creatingPOS],
116
+ $slice: maxNumPOS // 最大数担保(2026-09-20~)
117
+ },
118
+ }
83
119
  }, {
84
120
  new: true,
85
121
  projection: { _id: 1 }
86
122
  })
123
+ .lean()
87
124
  .exec();
88
125
  // 存在しなければID重複
89
126
  if (doc === null) {
90
127
  throw new factory_1.factory.errors.AlreadyInUse('hasPOS', ['id']);
91
128
  }
92
- return doc.toObject({ virtuals: true });
93
129
  }
94
- async updateByBranchCode(params) {
130
+ async updatePOSByBranchCode(params) {
95
131
  const doc = await this.civicStructureModel.findOneAndUpdate({
96
132
  'project.id': { $eq: params.project.id },
97
133
  _id: { $eq: this.operator.id },
@@ -109,13 +145,13 @@ class POSRepo {
109
145
  ],
110
146
  projection: { _id: 1 }
111
147
  })
148
+ .lean()
112
149
  .exec();
113
150
  if (doc === null) {
114
151
  throw new factory_1.factory.errors.NotFound('hasPOS');
115
152
  }
116
- return doc.toObject({ virtuals: true });
117
153
  }
118
- async deleteByBranchCode(params) {
154
+ async deletePOSByBranchCode(params) {
119
155
  const doc = await this.civicStructureModel.findOneAndUpdate({
120
156
  'project.id': { $eq: params.project.id },
121
157
  _id: { $eq: this.operator.id },
@@ -125,11 +161,11 @@ class POSRepo {
125
161
  }, {
126
162
  projection: { _id: 1 }
127
163
  })
164
+ .lean()
128
165
  .exec();
129
166
  if (doc === null) {
130
167
  throw new factory_1.factory.errors.NotFound('hasPOS');
131
168
  }
132
- return doc.toObject({ virtuals: true });
133
169
  }
134
170
  }
135
171
  exports.POSRepo = POSRepo;
@@ -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.12"
91
+ "version": "28.0.0-alpha.14"
92
92
  }