@chevre/domain 22.0.0 → 22.1.0-alpha.0

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.
@@ -25,7 +25,7 @@
25
25
  import type { Connection, FilterQuery } from 'mongoose';
26
26
  import * as factory from '../factory';
27
27
  type IOrderWithoutAcceptedOffers = factory.order.IOrder;
28
- type IKeyOfProjection = keyof IOrderWithoutAcceptedOffers | '_id';
28
+ type IKeyOfProjection = Extract<keyof IOrderWithoutAcceptedOffers, 'broker' | 'confirmationNumber' | 'customer' | 'dateReturned' | 'identifier' | 'name' | 'orderDate' | 'orderNumber' | 'orderStatus' | 'orderedItem' | 'paymentMethods' | 'previousOrderStatus' | 'price' | 'priceCurrency' | 'project' | 'returner' | 'seller' | 'typeOf' | 'url'> | 'paymentMethods.accountId' | 'paymentMethods.name' | 'paymentMethods.paymentMethod' | 'paymentMethods.paymentMethodId' | 'paymentMethods.totalPaymentDue' | 'paymentMethods.additionalProperty' | 'paymentMethods.issuedThrough';
29
29
  export type IReturnedOrder = Pick<IOrderWithoutAcceptedOffers, 'project' | 'typeOf' | 'orderNumber' | 'dateReturned' | 'id' | 'customer' | 'returner' | 'seller' | 'price' | 'priceCurrency' | 'orderDate'> & {
30
30
  id: string;
31
31
  };
@@ -155,6 +155,9 @@ export declare class OrderRepo {
155
155
  inclusion: {
156
156
  [key in IKeyOfProjection]?: 1;
157
157
  };
158
+ /**
159
+ * @deprecated use inclusion
160
+ */
158
161
  exclusion: {
159
162
  [key in IKeyOfProjection]?: 0;
160
163
  };
@@ -14,6 +14,15 @@ const factory = require("../factory");
14
14
  const order_1 = require("./mongoose/schemas/order");
15
15
  const errorHandler_1 = require("../errorHandler");
16
16
  const settings_1 = require("../settings");
17
+ /**
18
+ * ドキュメント検索時に指定可能なprojectionフィールドを厳密に定義する
19
+ */
20
+ const AVAILABLE_PROJECT_FIELDS = [
21
+ 'broker', 'confirmationNumber', 'customer', 'dateReturned', 'identifier', 'name', 'orderDate', 'orderNumber', 'orderStatus', 'orderedItem',
22
+ 'paymentMethods', 'previousOrderStatus', 'price', 'priceCurrency', 'project', 'returner', 'seller', 'typeOf', 'url',
23
+ 'paymentMethods.accountId', 'paymentMethods.additionalProperty', 'paymentMethods.issuedThrough', 'paymentMethods.name', 'paymentMethods.paymentMethod',
24
+ 'paymentMethods.paymentMethodId', 'paymentMethods.totalPaymentDue'
25
+ ];
17
26
  /**
18
27
  * 注文リポジトリ
19
28
  */
@@ -31,22 +40,6 @@ class OrderRepo {
31
40
  if (typeof projectIdEq === 'string') {
32
41
  andConditions.push({ 'project.id': { $eq: projectIdEq } });
33
42
  }
34
- // const additionalPropertyAll = params.additionalProperty?.$all; // 廃止(2024-04-12~)
35
- // if (Array.isArray(additionalPropertyAll)) {
36
- // andConditions.push({ additionalProperty: { $exists: true, $all: additionalPropertyAll } });
37
- // }
38
- // const additionalPropertyIn = params.additionalProperty?.$in; // 廃止(2024-04-12~)
39
- // if (Array.isArray(additionalPropertyIn)) {
40
- // andConditions.push({ additionalProperty: { $exists: true, $in: additionalPropertyIn } });
41
- // }
42
- // const additionalPropertyNin = params.additionalProperty?.$nin; // 廃止(2024-04-12~)
43
- // if (Array.isArray(additionalPropertyNin)) {
44
- // andConditions.push({ additionalProperty: { $nin: additionalPropertyNin } });
45
- // }
46
- // const additionalPropertyElemMatch = params.additionalProperty?.$elemMatch; // 廃止(2024-04-12~)
47
- // if (additionalPropertyElemMatch !== undefined && additionalPropertyElemMatch !== null) {
48
- // andConditions.push({ additionalProperty: { $exists: true, $elemMatch: additionalPropertyElemMatch } });
49
- // }
50
43
  // tslint:disable-next-line:no-single-line-block-comment
51
44
  /* istanbul ignore else */
52
45
  if (params.identifier !== undefined) {
@@ -83,10 +76,6 @@ class OrderRepo {
83
76
  if (Array.isArray(sellerIds)) {
84
77
  andConditions.push({ 'seller.id': { $exists: true, $in: sellerIds } });
85
78
  }
86
- // 不要なので廃止(2023-09-11~)
87
- // if (typeof params.seller?.typeOf === 'string') {
88
- // andConditions.push({ 'seller.typeOf': { $exists: true, $eq: params.seller.typeOf } });
89
- // }
90
79
  const brokerIdEq = (_j = (_h = params.broker) === null || _h === void 0 ? void 0 : _h.id) === null || _j === void 0 ? void 0 : _j.$eq;
91
80
  if (typeof brokerIdEq === 'string') {
92
81
  andConditions.push({
@@ -768,26 +757,33 @@ class OrderRepo {
768
757
  */
769
758
  returnOrder(params) {
770
759
  return __awaiter(this, void 0, void 0, function* () {
760
+ const { dateReturned, returner, orderNumber, project } = params;
771
761
  const doc = yield this.orderModel.findOneAndUpdate({
772
- orderNumber: { $eq: params.orderNumber },
762
+ orderNumber: { $eq: orderNumber },
773
763
  orderStatus: { $eq: factory.orderStatus.OrderDelivered },
774
- 'project.id': { $eq: params.project.id },
764
+ 'project.id': { $eq: project.id },
775
765
  typeOf: { $eq: factory.order.OrderType.Order }
776
766
  }, {
777
- previousOrderStatus: factory.orderStatus.OrderDelivered,
778
- orderStatus: factory.orderStatus.OrderReturned,
779
- dateReturned: params.dateReturned,
780
- returner: params.returner
767
+ $set: {
768
+ previousOrderStatus: factory.orderStatus.OrderDelivered,
769
+ orderStatus: factory.orderStatus.OrderReturned,
770
+ dateReturned,
771
+ returner
772
+ }
781
773
  }, {
782
774
  new: true,
783
775
  projection: {
784
- _id: 1, project: 1, typeOf: 1, orderNumber: 1, dateReturned: 1,
776
+ _id: 0,
777
+ id: { $toString: '$_id' },
778
+ // _id: 1,
779
+ project: 1, typeOf: 1, orderNumber: 1, dateReturned: 1,
785
780
  customer: 1, returner: 1, seller: 1, price: 1, priceCurrency: 1, orderDate: 1 // optimize(2023-12-07~)
786
781
  // __v: 0,
787
782
  // createdAt: 0,
788
783
  // updatedAt: 0
789
784
  }
790
785
  })
786
+ .lean() // lean(2024-07-30~)
791
787
  .exec();
792
788
  // NotFoundであれば状態確認
793
789
  if (doc === null) {
@@ -795,7 +791,7 @@ class OrderRepo {
795
791
  orderNumber: params.orderNumber,
796
792
  project: { id: params.project.id },
797
793
  inclusion: [
798
- 'project', 'typeOf', 'orderNumber', 'dateReturned', 'id',
794
+ 'project', 'typeOf', 'orderNumber', 'dateReturned',
799
795
  'customer', 'returner', 'seller', 'price', 'priceCurrency', 'orderDate'
800
796
  ]
801
797
  });
@@ -811,7 +807,8 @@ class OrderRepo {
811
807
  throw new factory.errors.Argument('orderNumber', `Order ${order.orderNumber} already changed -> ${order.orderStatus}`);
812
808
  }
813
809
  }
814
- return doc.toObject();
810
+ return doc;
811
+ // return doc.toObject();
815
812
  });
816
813
  }
817
814
  /**
@@ -820,19 +817,21 @@ class OrderRepo {
820
817
  updateChangeableAttributes(params) {
821
818
  return __awaiter(this, void 0, void 0, function* () {
822
819
  const updatedAt = new Date();
820
+ const { orderNumber, project, name } = params;
823
821
  const doc = yield this.orderModel.findOneAndUpdate({
824
- orderNumber: { $eq: params.orderNumber },
825
- 'project.id': { $eq: params.project.id },
822
+ orderNumber: { $eq: orderNumber },
823
+ 'project.id': { $eq: project.id },
826
824
  typeOf: { $eq: factory.order.OrderType.Order }
827
825
  }, {
828
- $set: Object.assign({}, (typeof params.name === 'string') ? { name: params.name } : undefined)
826
+ $set: Object.assign({}, (typeof name === 'string') ? { name } : undefined)
829
827
  }, {
830
- new: true,
828
+ new: false,
831
829
  projection: {
832
830
  _id: 1
833
831
  // updatedAt: 1 // discontinue(2024-06-17~)
834
832
  }
835
833
  })
834
+ .lean() // lean(2024-07-30~)
836
835
  .exec();
837
836
  if (doc === null) {
838
837
  throw new factory.errors.NotFound(this.orderModel.modelName);
@@ -864,6 +863,7 @@ class OrderRepo {
864
863
  _id: 1
865
864
  }
866
865
  })
866
+ .lean() // lean(2024-07-30~)
867
867
  .exec();
868
868
  if (doc === null) {
869
869
  throw new factory.errors.NotFound(this.orderModel.modelName);
@@ -879,7 +879,10 @@ class OrderRepo {
879
879
  };
880
880
  if (Array.isArray(params.inclusion) && params.inclusion.length > 0) {
881
881
  params.inclusion.forEach((field) => {
882
- if (String(field) !== 'acceptedOffers' && field !== '_id' && field !== 'id') {
882
+ // if (String(field) !== 'acceptedOffers' && field !== '_id' && field !== 'id') {
883
+ // projection[field] = 1;
884
+ // }
885
+ if (AVAILABLE_PROJECT_FIELDS.includes(field)) {
883
886
  projection[field] = 1;
884
887
  }
885
888
  });
@@ -887,12 +890,6 @@ class OrderRepo {
887
890
  else {
888
891
  // discontinue(2024-07-25~)
889
892
  throw new factory.errors.ArgumentNull('inclusion', 'inclusion must be specified');
890
- // projection = {
891
- // __v: 0,
892
- // createdAt: 0,
893
- // updatedAt: 0,
894
- // acceptedOffers: 0
895
- // };
896
893
  }
897
894
  const doc = yield this.orderModel.findOne({
898
895
  _id: { $eq: params.id },
@@ -920,7 +917,10 @@ class OrderRepo {
920
917
  };
921
918
  if (Array.isArray(params.inclusion) && params.inclusion.length > 0) {
922
919
  params.inclusion.forEach((field) => {
923
- if (String(field) !== 'acceptedOffers' && field !== '_id' && field !== 'id') {
920
+ // if (String(field) !== 'acceptedOffers' && field !== '_id' && field !== 'id') {
921
+ // projection[field] = 1;
922
+ // }
923
+ if (AVAILABLE_PROJECT_FIELDS.includes(field)) {
924
924
  projection[field] = 1;
925
925
  }
926
926
  });
@@ -928,12 +928,6 @@ class OrderRepo {
928
928
  else {
929
929
  // discontinue(2024-07-25~)
930
930
  throw new factory.errors.ArgumentNull('inclusion', 'inclusion must be specified');
931
- // projection = {
932
- // __v: 0,
933
- // createdAt: 0,
934
- // updatedAt: 0,
935
- // acceptedOffers: 0 // defaultで除外(2023-12-08~)
936
- // };
937
931
  }
938
932
  const doc = yield this.orderModel.findOne({
939
933
  orderNumber: { $eq: params.orderNumber },
@@ -1008,10 +1002,14 @@ class OrderRepo {
1008
1002
  let projectStage = {};
1009
1003
  const positiveProjectionFields = (inclusion !== undefined && inclusion !== null)
1010
1004
  ? Object.keys(inclusion)
1011
- .filter((key) => inclusion[key] === 1
1012
- && key !== 'acceptedOffers' // defaultで隠蔽(2023-12-06~)
1013
- && key !== '_id'
1014
- && key !== 'id')
1005
+ .filter((key) => {
1006
+ // return inclusion[<IKeyOfProjection>key] === 1
1007
+ // && key !== 'acceptedOffers' // defaultで隠蔽(2023-12-06~)
1008
+ // && key !== '_id'
1009
+ // && key !== 'id';
1010
+ return inclusion[key] === 1
1011
+ && AVAILABLE_PROJECT_FIELDS.includes(key);
1012
+ })
1015
1013
  : [];
1016
1014
  if (Array.isArray(positiveProjectionFields) && positiveProjectionFields.length > 0) {
1017
1015
  useInclusionProjection = true;
@@ -30,7 +30,7 @@ function returnOrder(params) {
30
30
  orderNumber,
31
31
  project: { id: params.project.id },
32
32
  inclusion: [
33
- 'project', 'typeOf', 'orderNumber', 'dateReturned', 'id',
33
+ 'project', 'typeOf', 'orderNumber', 'dateReturned',
34
34
  'customer', 'returner', 'seller', 'price', 'priceCurrency', 'orderDate', 'orderStatus'
35
35
  ]
36
36
  });
@@ -51,7 +51,7 @@ function sendOrder(params) {
51
51
  let order = yield repos.order.projectFieldsByOrderNumber({
52
52
  orderNumber,
53
53
  project: { id: params.project.id },
54
- inclusion: ['confirmationNumber', 'project', 'typeOf', 'seller', 'orderNumber', 'price', 'priceCurrency', 'orderDate', 'customer', '_id']
54
+ inclusion: ['confirmationNumber', 'project', 'typeOf', 'seller', 'orderNumber', 'price', 'priceCurrency', 'orderDate', 'customer']
55
55
  });
56
56
  // プロジェクト条件検証
57
57
  if (order.project.id !== params.project.id) {
package/package.json CHANGED
@@ -110,5 +110,5 @@
110
110
  "postversion": "git push origin --tags",
111
111
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
112
112
  },
113
- "version": "22.0.0"
113
+ "version": "22.1.0-alpha.0"
114
114
  }