@chevre/domain 21.4.0-alpha.13 → 21.4.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.
@@ -64,7 +64,7 @@ export declare class MongoRepository {
64
64
  * idを指定すれば更新
65
65
  */
66
66
  id?: string;
67
- attributes: factory.product.IProduct;
67
+ attributes: factory.product.IProduct | factory.service.paymentService.IService;
68
68
  /**
69
69
  * 指定プロジェクトの指定プロダクトタイプが存在しなければ作成する
70
70
  */
@@ -303,10 +303,34 @@ class MongoRepository {
303
303
  delete params.attributes.id;
304
304
  }
305
305
  if (typeof params.id === 'string') {
306
- // 上書き禁止属性を除外(2022-08-24~)
307
- const _a = params.attributes, { id, productID, project, typeOf } = _a, updateFields = __rest(_a, ["id", "productID", "project", "typeOf"]);
308
- doc = yield this.productModel.findOneAndUpdate({ _id: params.id }, updateFields, { upsert: false, new: true })
309
- .exec();
306
+ const _a = params.attributes, { id, productID, project } = _a, updateFields = __rest(_a, ["id", "productID", "project"]);
307
+ switch (updateFields.typeOf) {
308
+ case factory.product.ProductType.EventService:
309
+ case factory.product.ProductType.MembershipService:
310
+ case factory.product.ProductType.PaymentCard:
311
+ case factory.product.ProductType.Product:
312
+ case factory.product.ProductType.Transportation:
313
+ // 上書き禁止属性を除外(2022-08-24~)
314
+ const { offers } = updateFields, updateProductFields = __rest(updateFields, ["offers"]);
315
+ doc = yield this.productModel.findOneAndUpdate({
316
+ _id: { $eq: params.id },
317
+ typeOf: { $eq: updateProductFields.typeOf }
318
+ }, updateProductFields, { upsert: false, new: true })
319
+ .exec();
320
+ break;
321
+ case factory.service.paymentService.PaymentServiceType.CreditCard:
322
+ case factory.service.paymentService.PaymentServiceType.MovieTicket:
323
+ // 上書き禁止属性を除外(2022-08-24~)
324
+ const { provider } = updateFields, updatePaymentServiceFields = __rest(updateFields, ["provider"]);
325
+ doc = yield this.productModel.findOneAndUpdate({
326
+ _id: { $eq: params.id },
327
+ typeOf: { $eq: updatePaymentServiceFields.typeOf }
328
+ }, updatePaymentServiceFields, { upsert: false, new: true })
329
+ .exec();
330
+ break;
331
+ default:
332
+ throw new factory.errors.NotImplemented(`${updateFields.typeOf} not implemented`);
333
+ }
310
334
  if (doc === null) {
311
335
  throw new factory.errors.NotFound(this.productModel.modelName);
312
336
  }
@@ -315,7 +339,7 @@ class MongoRepository {
315
339
  if (params.createIfNotExist === true) {
316
340
  doc = yield this.productModel.findOneAndUpdate({
317
341
  'project.id': { $eq: params.attributes.project.id },
318
- typeOf: params.attributes.typeOf
342
+ typeOf: { $eq: params.attributes.typeOf }
319
343
  }, { $setOnInsert: params.attributes }, { new: true, upsert: true })
320
344
  .exec();
321
345
  }
package/package.json CHANGED
@@ -117,5 +117,5 @@
117
117
  "postversion": "git push origin --tags",
118
118
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
119
119
  },
120
- "version": "21.4.0-alpha.13"
120
+ "version": "21.4.0-alpha.14"
121
121
  }