@chevre/domain 28.0.0-alpha.15 → 28.0.0-alpha.17

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,7 +1,9 @@
1
1
  import { IndexDefinition, IndexOptions, Model, Schema, SchemaDefinition } from 'mongoose';
2
2
  import { IVirtuals } from '../virtuals';
3
3
  import { factory } from '../../../factory';
4
- type IDocType = Omit<factory.seller.ISeller, 'id'>;
4
+ type IDocType = Pick<factory.seller.ISeller, 'additionalProperty' | 'branchCode' | 'hasMerchantReturnPolicy' | 'makesOffer' | 'name' | 'project' | 'telephone' | 'typeOf' | 'url'> & {
5
+ paymentAccepted?: factory.seller.IPaymentAccepted[];
6
+ };
5
7
  type IModel = Model<IDocType, Record<string, never>, Record<string, never>, IVirtuals>;
6
8
  type ISchemaDefinition = SchemaDefinition<IDocType>;
7
9
  type ISchema = Schema<IDocType, IModel, Record<string, never>, Record<string, never>, IVirtuals, Record<string, never>, ISchemaDefinition, IDocType>;
@@ -9,12 +9,10 @@ const modelName = 'Seller';
9
9
  exports.modelName = modelName;
10
10
  const schemaDefinition = {
11
11
  additionalProperty: [mongoose_1.SchemaTypes.Mixed],
12
- // areaServed: [SchemaTypes.Mixed],
13
12
  branchCode: String,
14
13
  hasMerchantReturnPolicy: [mongoose_1.SchemaTypes.Mixed],
15
14
  makesOffer: [mongoose_1.SchemaTypes.Mixed],
16
15
  name: mongoose_1.SchemaTypes.Mixed,
17
- // parentOrganization: SchemaTypes.Mixed,
18
16
  paymentAccepted: [mongoose_1.SchemaTypes.Mixed],
19
17
  project: mongoose_1.SchemaTypes.Mixed,
20
18
  typeOf: {
@@ -95,10 +95,6 @@ class POSRepo {
95
95
  }
96
96
  // 最大数検証(2026-09-20~)
97
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
- }
102
98
  const creatingPOS = {
103
99
  // // 互換性維持対応としてidを保管
104
100
  // id: params.branchCode as any, // discontinue(2026-09-22~)
@@ -108,22 +104,25 @@ class POSRepo {
108
104
  const doc = await this.civicStructureModel.findOneAndUpdate({
109
105
  'project.id': { $eq: params.project.id },
110
106
  _id: { $eq: this.operator.id },
111
- 'hasPOS.branchCode': { $ne: params.branchCode }
112
- }, {
113
- $push: {
114
- hasPOS: {
115
- $each: [creatingPOS],
116
- $slice: maxNumPOS // 最大数担保(2026-09-20~)
117
- },
107
+ 'hasPOS.branchCode': { $ne: params.branchCode },
108
+ // 配列の長さが上限未満であることをアトミックに確認
109
+ $expr: {
110
+ $lt: [{ $size: { $ifNull: ['$hasPOS', []] } }, maxNumPOS] // 最大数担保(2026-09-20~)
118
111
  }
119
112
  }, {
120
- new: true,
113
+ $push: { hasPOS: creatingPOS }
114
+ }, {
121
115
  projection: { _id: 1 }
122
116
  })
123
117
  .lean()
124
118
  .exec();
125
119
  // 存在しなければID重複
126
120
  if (doc === null) {
121
+ const { posCount } = await this.countPOS();
122
+ if (posCount >= maxNumPOS) {
123
+ throw new factory_1.factory.errors.Argument('operator.id', 'maxNumPOS exceeded');
124
+ }
125
+ // 上限以下で追加できない場合は「すでに登録済み」
127
126
  throw new factory_1.factory.errors.AlreadyInUse('hasPOS', ['id']);
128
127
  }
129
128
  }
@@ -33,7 +33,7 @@ export declare class SellerRepo {
33
33
  private readonly sellerModel;
34
34
  constructor(connection: Connection);
35
35
  static CREATE_MONGO_CONDITIONS(params: factory.seller.ISearchConditions & IMemberSearchConditions): FilterQuery<factory.seller.ISeller>[];
36
- static CREATE_AGGREGATE_SELLERS_PROJECTION(exclusion: (keyof ISellerByAggregate)[]): Record<string, AnyExpression>;
36
+ static CREATE_AGGREGATE_SELLERS_PROJECTION(inclusions: (Exclude<keyof ISellerByAggregate, 'id'>)[]): Record<string, AnyExpression>;
37
37
  /**
38
38
  * 販売者を保管する
39
39
  */
@@ -46,7 +46,10 @@ export declare class SellerRepo {
46
46
  /**
47
47
  * 集計検索(publicな属性検索が目的)
48
48
  */
49
- searchByAggregate(conditions: factory.seller.ISearchConditions & IMemberSearchConditions, exclusion: (keyof ISellerByAggregate)[]): Promise<ISellerByAggregate[]>;
49
+ findSellersPublicFields(conditions: factory.seller.ISearchConditions & IMemberSearchConditions & {
50
+ limit: number;
51
+ page: number;
52
+ }, inclusions: (Exclude<keyof ISellerByAggregate, 'id'>)[]): Promise<ISellerByAggregate[]>;
50
53
  /**
51
54
  * 販売者検索
52
55
  */
@@ -72,11 +75,15 @@ export declare class SellerRepo {
72
75
  id: string;
73
76
  makesOffer: factory.seller.IMakesOffer;
74
77
  }): Promise<void>;
75
- getCursor(conditions: FilterQuery<factory.seller.ISeller>, projection: any): import("mongoose").Cursor<import("mongoose").Document<unknown, Record<string, never>, IDocType, import("./mongoose/virtuals").IVirtuals, {}> & IDocType & {
78
+ getCursor(conditions: FilterQuery<factory.seller.ISeller>, projection: any): import("mongoose").Cursor<import("mongoose").Document<unknown, Record<string, never>, IDocType, import("./mongoose/virtuals").IVirtuals, {}> & Pick<factory.seller.ISeller, "project" | "name" | "typeOf" | "url" | "additionalProperty" | "telephone" | "branchCode" | "makesOffer" | "hasMerchantReturnPolicy"> & {
79
+ paymentAccepted?: factory.seller.IPaymentAccepted[];
80
+ } & {
76
81
  _id: Types.ObjectId;
77
82
  } & {
78
83
  __v: number;
79
- }, QueryOptions<IDocType>, (import("mongoose").Document<unknown, Record<string, never>, IDocType, import("./mongoose/virtuals").IVirtuals, {}> & IDocType & {
84
+ }, QueryOptions<IDocType>, (import("mongoose").Document<unknown, Record<string, never>, IDocType, import("./mongoose/virtuals").IVirtuals, {}> & Pick<factory.seller.ISeller, "project" | "name" | "typeOf" | "url" | "additionalProperty" | "telephone" | "branchCode" | "makesOffer" | "hasMerchantReturnPolicy"> & {
85
+ paymentAccepted?: factory.seller.IPaymentAccepted[];
86
+ } & {
80
87
  _id: Types.ObjectId;
81
88
  } & {
82
89
  __v: number;
@@ -125,63 +125,38 @@ class SellerRepo {
125
125
  'hasMerchantReturnPolicy.identifier': { $exists: true, $eq: hasMerchantReturnPolicyIdentifierEq }
126
126
  });
127
127
  }
128
- // discontinue(2025-01-22~)
129
- // const hasMerchantReturnApplicablePaymentMethodEq = params.hasMerchantReturnPolicy?.applicablePaymentMethod?.$eq;
130
- // if (typeof hasMerchantReturnApplicablePaymentMethodEq === 'string') {
131
- // andConditions.push({
132
- // 'hasMerchantReturnPolicy.applicablePaymentMethod': { $exists: true, $eq: hasMerchantReturnApplicablePaymentMethodEq }
133
- // });
134
- // }
135
- // discontinue(2025-01-22~)
136
- // const hasMerchantReturnPolicyItemConditionIdEq = params.hasMerchantReturnPolicy?.itemCondition?.id?.$eq;
137
- // if (typeof hasMerchantReturnPolicyItemConditionIdEq === 'string') {
138
- // andConditions.push({
139
- // 'hasMerchantReturnPolicy.itemCondition.id': {
140
- // $exists: true,
141
- // $eq: hasMerchantReturnPolicyItemConditionIdEq
142
- // }
143
- // });
144
- // }
145
128
  return andConditions;
146
129
  }
147
- static CREATE_AGGREGATE_SELLERS_PROJECTION(exclusion) {
130
+ static CREATE_AGGREGATE_SELLERS_PROJECTION(inclusions) {
131
+ const inclusionMap = new Map(inclusions.map(inclusion => [inclusion, 1]));
148
132
  const projectStage = {
149
133
  _id: 0,
150
134
  id: { $toString: '$_id' },
151
- additionalProperty: '$additionalProperty',
152
- branchCode: '$branchCode',
153
- hasMerchantReturnPolicy: {
154
- $cond: {
155
- if: { $isArray: '$hasMerchantReturnPolicy' },
156
- then: {
157
- $cond: {
158
- if: { $eq: [{ $size: '$hasMerchantReturnPolicy' }, 0] },
159
- then: [],
160
- else: [{
161
- url: { $first: '$hasMerchantReturnPolicy.url' }
162
- // typeOf: { $first: '$hasMerchantReturnPolicy.typeOf' }
163
- }]
164
- }
165
- },
166
- else: []
135
+ ...((inclusionMap.get('additionalProperty') === 1) && { additionalProperty: '$additionalProperty' }),
136
+ ...((inclusionMap.get('branchCode') === 1) && { branchCode: '$branchCode' }),
137
+ ...((inclusionMap.get('name') === 1) && { name: '$name' }),
138
+ ...((inclusionMap.get('project') === 1) && { project: '$project' }),
139
+ ...((inclusionMap.get('typeOf') === 1) && { typeOf: '$typeOf' }),
140
+ ...((inclusionMap.get('url') === 1) && { url: '$url' }),
141
+ ...((inclusionMap.get('telephone') === 1) && { telephone: '$telephone' }),
142
+ ...((inclusionMap.get('hasMerchantReturnPolicy') === 1) && {
143
+ hasMerchantReturnPolicy: {
144
+ $cond: {
145
+ if: { $isArray: '$hasMerchantReturnPolicy' },
146
+ then: {
147
+ $cond: {
148
+ if: { $eq: [{ $size: '$hasMerchantReturnPolicy' }, 0] },
149
+ then: [],
150
+ else: [{
151
+ url: { $first: '$hasMerchantReturnPolicy.url' }
152
+ }]
153
+ }
154
+ },
155
+ else: []
156
+ }
167
157
  }
168
- },
169
- name: '$name',
170
- project: '$project',
171
- typeOf: '$typeOf',
172
- url: '$url',
173
- telephone: '$telephone'
158
+ }),
174
159
  };
175
- // if (inclusion.length > 0) {
176
- // // no op
177
- // } else
178
- if (exclusion.length > 0) {
179
- exclusion.forEach((field) => {
180
- if (typeof projectStage[field] === 'string' || typeof projectStage[field] === 'object') {
181
- delete projectStage[field]; // eslint-disable-line @typescript-eslint/no-dynamic-delete
182
- }
183
- });
184
- }
185
160
  return projectStage;
186
161
  }
187
162
  /**
@@ -233,10 +208,10 @@ class SellerRepo {
233
208
  /**
234
209
  * 集計検索(publicな属性検索が目的)
235
210
  */
236
- async searchByAggregate(conditions, exclusion) {
211
+ async findSellersPublicFields(conditions, inclusions) {
237
212
  const matchStages = SellerRepo.CREATE_MONGO_CONDITIONS(conditions)
238
213
  .map((c) => ({ $match: c }));
239
- const projectStage = SellerRepo.CREATE_AGGREGATE_SELLERS_PROJECTION(exclusion);
214
+ const projectStage = SellerRepo.CREATE_AGGREGATE_SELLERS_PROJECTION(inclusions);
240
215
  const sortByBranchCode = conditions.sort?.branchCode;
241
216
  const aggregate = this.sellerModel.aggregate([
242
217
  ...matchStages,
@@ -245,12 +220,10 @@ class SellerRepo {
245
220
  : [],
246
221
  { $project: projectStage }
247
222
  ]);
248
- /* istanbul ignore else */
249
- if (typeof conditions.limit === 'number' && conditions.limit > 0) {
250
- const page = (typeof conditions.page === 'number' && conditions.page > 0) ? conditions.page : 1;
251
- aggregate.limit(conditions.limit * page)
252
- .skip(conditions.limit * (page - 1));
253
- }
223
+ const { limit, page } = conditions;
224
+ const pageMustBePositive = (typeof page === 'number' && page > 0) ? page : 1;
225
+ aggregate.skip(limit * (pageMustBePositive - 1))
226
+ .limit(limit);
254
227
  return aggregate.exec();
255
228
  }
256
229
  /**
@@ -38,9 +38,10 @@ export declare class SellerPaymentAcceptedRepo {
38
38
  };
39
39
  }): Promise<void>;
40
40
  isAcceptedBySeller(params: {
41
- seller: {
42
- id: string;
43
- };
41
+ sellerId: string;
42
+ /**
43
+ * 決済方法区分
44
+ */
44
45
  codeValue: string;
45
46
  }): Promise<boolean>;
46
47
  }
@@ -86,31 +86,30 @@ class SellerPaymentAcceptedRepo {
86
86
  }
87
87
  // 最大数検証(2026-09-20~)
88
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
- }
93
89
  const creatingPaymentAccepted = {
94
90
  paymentMethodType: params.codeValue
95
91
  };
96
92
  const doc = await this.sellerModel.findOneAndUpdate({
97
93
  'project.id': { $eq: params.project.id },
98
94
  _id: { $eq: params.seller.id },
99
- 'paymentAccepted.paymentMethodType': { $ne: params.codeValue }
100
- }, {
101
- // $push: { paymentAccepted: creatingPaymentAccepted }
102
- $push: {
103
- paymentAccepted: {
104
- $each: [creatingPaymentAccepted],
105
- $slice: maxNumSellerPaymentAccepted // 最大数担保(2026-09-22~)
106
- },
95
+ 'paymentAccepted.paymentMethodType': { $ne: params.codeValue },
96
+ // 配列の長さが上限未満であることをアトミックに確認
97
+ $expr: {
98
+ $lt: [{ $size: { $ifNull: ['$paymentAccepted', []] } }, maxNumSellerPaymentAccepted] // 最大数担保(2026-09-22~)
107
99
  }
100
+ }, {
101
+ $push: { paymentAccepted: creatingPaymentAccepted }
108
102
  }, {
109
103
  projection: { _id: 1 }
110
104
  })
111
105
  .lean()
112
106
  .exec();
113
107
  if (doc === null) {
108
+ const { paymentAcceptedCount } = await this.countSellerPaymentAccepted({ seller: params.seller });
109
+ if (paymentAcceptedCount >= maxNumSellerPaymentAccepted) {
110
+ throw new factory_1.factory.errors.Argument('seller.id', 'maxNumSellerPaymentAccepted exceeded');
111
+ }
112
+ // 上限以下で追加できない場合は「すでに登録済み」
114
113
  throw new factory_1.factory.errors.AlreadyInUse('paymentAccepted', ['paymentMethodType']);
115
114
  }
116
115
  }
@@ -131,24 +130,13 @@ class SellerPaymentAcceptedRepo {
131
130
  }
132
131
  }
133
132
  async isAcceptedBySeller(params) {
134
- const aggregate = this.sellerModel.aggregate([
135
- // まず販売者ドキュメントで絞る
136
- { $match: { _id: { $eq: new mongoose_1.Types.ObjectId(params.seller.id) } } },
137
- {
138
- $unwind: { path: '$paymentAccepted' }
139
- },
140
- { $match: { 'paymentAccepted.paymentMethodType': { $exists: true, $eq: params.codeValue } } },
141
- {
142
- $project: {
143
- _id: 0,
144
- codeValue: '$paymentAccepted.paymentMethodType'
145
- }
146
- }
147
- ])
148
- .skip(0)
149
- .limit(1);
150
- return (await aggregate.option({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
151
- .exec()).length > 0;
133
+ const { sellerId, codeValue } = params;
134
+ const doc = await this.sellerModel.exists({
135
+ _id: { $eq: new mongoose_1.Types.ObjectId(sellerId) },
136
+ 'paymentAccepted.paymentMethodType': { $exists: true, $eq: codeValue }
137
+ })
138
+ .setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS });
139
+ return doc !== null;
152
140
  }
153
141
  }
154
142
  exports.SellerPaymentAcceptedRepo = SellerPaymentAcceptedRepo;
@@ -21,7 +21,7 @@ function validateSeller(params) {
21
21
  // 販売者の対応決済方法かどうか確認
22
22
  // const paymentAccepted = seller.paymentAccepted?.some((a) => a.paymentMethodType === paymentMethodType);
23
23
  const paymentAccepted = await repos.paymentAccepted.isAcceptedBySeller({
24
- seller: { id: sellerId },
24
+ sellerId,
25
25
  codeValue: paymentMethodType
26
26
  });
27
27
  if (paymentAccepted !== true) {
@@ -33,7 +33,7 @@ function validateSeller(params) {
33
33
  // 販売者の対応決済方法かどうか確認
34
34
  // const paymentAccepted = seller.paymentAccepted?.some((a) => a.paymentMethodType === paymentMethodType);
35
35
  const paymentAccepted = await repos.paymentAccepted.isAcceptedBySeller({
36
- seller: { id: sellerId },
36
+ sellerId,
37
37
  codeValue: paymentMethodType
38
38
  });
39
39
  if (paymentAccepted !== true) {
@@ -6,7 +6,7 @@ function getGMOInfoFromSeller(params) {
6
6
  return async (repos) => {
7
7
  if (params.requirePaymentAccepted) {
8
8
  const paymentAccepted = await repos.paymentAccepted.isAcceptedBySeller({
9
- seller: { id: params.seller.id },
9
+ sellerId: params.seller.id,
10
10
  codeValue: params.paymentMethodType
11
11
  });
12
12
  if (paymentAccepted !== true) {
@@ -56,7 +56,7 @@ function checkMovieTicket(params) {
56
56
  const screeningEvent = await repos.event.projectEventFieldsById({ id: eventIds[0] }, ['typeOf', 'project', 'coaInfo', 'startDate', 'offers.offeredThrough', 'superEvent.workPerformed.identifier']);
57
57
  const sellerId = optimizedCheckObject[0]?.seller.id;
58
58
  const paymentAccepted = await repos.paymentAccepted.isAcceptedBySeller({
59
- seller: { id: sellerId },
59
+ sellerId,
60
60
  codeValue: paymentMethodType
61
61
  });
62
62
  if (paymentAccepted !== true) {
@@ -31,7 +31,7 @@ function payActionParams2seatInfoSyncIn(params) {
31
31
  paymentServiceId
32
32
  })(repos);
33
33
  const paymentAccepted = await repos.paymentAccepted.isAcceptedBySeller({
34
- seller: { id: sellerId },
34
+ sellerId,
35
35
  codeValue: paymentMethodType
36
36
  });
37
37
  if (paymentAccepted !== true) {
@@ -61,7 +61,7 @@ checkedAction, purpose) {
61
61
  // }
62
62
  // const paymentAccepted = seller.paymentAccepted?.some((a) => a.paymentMethodType === paymentMethodType);
63
63
  const paymentAccepted = await repos.paymentAccepted.isAcceptedBySeller({
64
- seller: { id: sellerId },
64
+ sellerId,
65
65
  codeValue: paymentMethodType
66
66
  });
67
67
  if (paymentAccepted !== true) {
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "dependencies": {
12
12
  "@aws-sdk/client-cognito-identity-provider": "3.1090.0",
13
13
  "@aws-sdk/credential-providers": "3.1090.0",
14
- "@chevre/factory": "11.0.0-alpha.4",
14
+ "@chevre/factory": "11.0.0",
15
15
  "@motionpicture/coa-service": "10.0.0",
16
16
  "@motionpicture/gmo-service": "6.1.0-alpha.0",
17
17
  "@sendgrid/client": "8.1.4",
@@ -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.15"
91
+ "version": "28.0.0-alpha.17"
92
92
  }