@chevre/domain 21.18.0-alpha.2 → 21.18.0-alpha.20

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.
Files changed (106) hide show
  1. package/example/src/chevre/aggreateOwnershipInfosByOrder.ts +24 -0
  2. package/example/src/chevre/searchAcceptedOfferIds.ts +57 -0
  3. package/example/src/chevre/searchOrderAcceptedOffers.ts +12 -12
  4. package/example/src/chevre/searchOrders.ts +36 -19
  5. package/example/src/chevre/searchReservationsByOrder.ts +30 -0
  6. package/example/src/chevre/searchTransactions.ts +41 -0
  7. package/example/src/chevre/transaction/processReturnOrder.ts +1 -0
  8. package/example/src/chevre/upsertMoviesByIdentifier.ts +57 -0
  9. package/example/src/chevre/upsertScreeningEventSeriesByVersion.ts +141 -0
  10. package/example/src/duration.ts +22 -0
  11. package/lib/chevre/repo/acceptedOffer.d.ts +60 -0
  12. package/lib/chevre/repo/acceptedOffer.js +158 -0
  13. package/lib/chevre/repo/creativeWork.d.ts +5 -1
  14. package/lib/chevre/repo/creativeWork.js +42 -22
  15. package/lib/chevre/repo/event.d.ts +12 -0
  16. package/lib/chevre/repo/event.js +61 -0
  17. package/lib/chevre/repo/offerCatalog.d.ts +8 -2
  18. package/lib/chevre/repo/offerCatalog.js +8 -8
  19. package/lib/chevre/repo/order.d.ts +14 -54
  20. package/lib/chevre/repo/order.js +46 -180
  21. package/lib/chevre/repo/place.js +14 -10
  22. package/lib/chevre/repo/transaction.d.ts +5 -4
  23. package/lib/chevre/repository.d.ts +5 -7
  24. package/lib/chevre/repository.js +14 -17
  25. package/lib/chevre/service/assetTransaction/pay/potentialActions.d.ts +3 -1
  26. package/lib/chevre/service/assetTransaction/pay/potentialActions.js +3 -3
  27. package/lib/chevre/service/assetTransaction/pay.d.ts +2 -0
  28. package/lib/chevre/service/assetTransaction/pay.js +10 -6
  29. package/lib/chevre/service/delivery/factory.d.ts +3 -1
  30. package/lib/chevre/service/delivery/factory.js +4 -2
  31. package/lib/chevre/service/delivery.d.ts +1 -2
  32. package/lib/chevre/service/delivery.js +1 -3
  33. package/lib/chevre/service/offer/product.d.ts +0 -14
  34. package/lib/chevre/service/offer/product.js +59 -42
  35. package/lib/chevre/service/order/confirmPayTransaction.d.ts +2 -0
  36. package/lib/chevre/service/order/confirmPayTransaction.js +1 -0
  37. package/lib/chevre/service/order/createAccountingReportIfNotExist.d.ts +3 -1
  38. package/lib/chevre/service/order/createAccountingReportIfNotExist.js +4 -1
  39. package/lib/chevre/service/order/deleteOrder.d.ts +2 -0
  40. package/lib/chevre/service/order/deleteOrder.js +15 -4
  41. package/lib/chevre/service/order/findPlaceOrderTransaction.d.ts +3 -1
  42. package/lib/chevre/service/order/findPlaceOrderTransaction.js +1 -2
  43. package/lib/chevre/service/order/onAssetTransactionStatusChanged.d.ts +3 -3
  44. package/lib/chevre/service/order/onAssetTransactionStatusChanged.js +15 -9
  45. package/lib/chevre/service/order/onOrderStatusChanged/onOrderCancelled/factory.d.ts +11 -0
  46. package/lib/chevre/service/order/onOrderStatusChanged/onOrderCancelled/factory.js +54 -0
  47. package/lib/chevre/service/order/onOrderStatusChanged/onOrderCancelled.d.ts +10 -0
  48. package/lib/chevre/service/order/onOrderStatusChanged/onOrderCancelled.js +38 -0
  49. package/lib/chevre/service/order/onOrderStatusChanged/onOrderDelivered/factory.d.ts +12 -0
  50. package/lib/chevre/service/order/onOrderStatusChanged/onOrderDelivered/factory.js +111 -0
  51. package/lib/chevre/service/order/onOrderStatusChanged/onOrderDelivered.d.ts +12 -0
  52. package/lib/chevre/service/order/onOrderStatusChanged/onOrderDelivered.js +64 -0
  53. package/lib/chevre/service/order/onOrderStatusChanged/onOrderPaymentDue.d.ts +10 -0
  54. package/lib/chevre/service/order/onOrderStatusChanged/onOrderPaymentDue.js +103 -0
  55. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/factory.d.ts +30 -0
  56. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/factory.js +227 -0
  57. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing.d.ts +14 -0
  58. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing.js +216 -0
  59. package/lib/chevre/service/order/onOrderStatusChanged/onOrderReturned/factory.d.ts +10 -0
  60. package/lib/chevre/service/order/onOrderStatusChanged/onOrderReturned/factory.js +110 -0
  61. package/lib/chevre/service/order/onOrderStatusChanged/onOrderReturned.d.ts +14 -0
  62. package/lib/chevre/service/order/onOrderStatusChanged/onOrderReturned.js +164 -0
  63. package/lib/chevre/service/order/onOrderStatusChanged.d.ts +9 -15
  64. package/lib/chevre/service/order/onOrderStatusChanged.js +11 -446
  65. package/lib/chevre/service/order/onOrderUpdated/factory.d.ts +6 -0
  66. package/lib/chevre/service/order/onOrderUpdated/factory.js +45 -0
  67. package/lib/chevre/service/order/onOrderUpdated.js +1 -1
  68. package/lib/chevre/service/order/payOrder.d.ts +2 -2
  69. package/lib/chevre/service/order/placeOrder.d.ts +2 -3
  70. package/lib/chevre/service/order/placeOrder.js +65 -22
  71. package/lib/chevre/service/order/returnOrder.d.ts +2 -2
  72. package/lib/chevre/service/order/returnOrder.js +34 -13
  73. package/lib/chevre/service/order/sendOrder.d.ts +2 -2
  74. package/lib/chevre/service/order/sendOrder.js +19 -6
  75. package/lib/chevre/service/order.d.ts +2 -2
  76. package/lib/chevre/service/order.js +2 -2
  77. package/lib/chevre/service/payment/any.js +1 -1
  78. package/lib/chevre/service/reserve/searchByOrder.d.ts +21 -0
  79. package/lib/chevre/service/reserve/searchByOrder.js +113 -0
  80. package/lib/chevre/service/reserve/verifyToken4reservation.js +0 -11
  81. package/lib/chevre/service/reserve.d.ts +2 -1
  82. package/lib/chevre/service/reserve.js +3 -1
  83. package/lib/chevre/service/task/confirmPayTransaction.js +2 -1
  84. package/lib/chevre/service/task/deleteTransaction.js +2 -0
  85. package/lib/chevre/service/task/onAssetTransactionStatusChanged.js +5 -6
  86. package/lib/chevre/service/task/onAuthorizationCreated.js +9 -18
  87. package/lib/chevre/service/task/onOrderPaymentCompleted.js +5 -6
  88. package/lib/chevre/service/task/placeOrder.js +10 -17
  89. package/lib/chevre/service/task/returnOrder.js +10 -17
  90. package/lib/chevre/service/task/sendOrder.js +10 -17
  91. package/lib/chevre/service/task/voidRegisterServiceTransaction.js +3 -7
  92. package/lib/chevre/service/transaction/deleteTransaction.d.ts +2 -0
  93. package/lib/chevre/service/transaction/moneyTransfer.js +3 -4
  94. package/lib/chevre/service/transaction/placeOrderInProgress/result.d.ts +1 -1
  95. package/lib/chevre/service/transaction/placeOrderInProgress/validation.d.ts +1 -1
  96. package/lib/chevre/service/transaction/returnOrder/potentialActions/returnMoneyTransfer.d.ts +1 -0
  97. package/lib/chevre/service/transaction/returnOrder/potentialActions/returnMoneyTransfer.js +3 -3
  98. package/lib/chevre/service/transaction/returnOrder/potentialActions.d.ts +1 -0
  99. package/lib/chevre/service/transaction/returnOrder/potentialActions.js +1 -1
  100. package/lib/chevre/service/transaction/returnOrder.d.ts +3 -0
  101. package/lib/chevre/service/transaction/returnOrder.js +73 -55
  102. package/package.json +2 -2
  103. package/lib/chevre/repo/action/registerServiceInProgress.d.ts +0 -29
  104. package/lib/chevre/repo/action/registerServiceInProgress.js +0 -58
  105. package/lib/chevre/service/order/onOrderStatusChanged/factory.d.ts +0 -42
  106. package/lib/chevre/service/order/onOrderStatusChanged/factory.js +0 -467
@@ -0,0 +1,158 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.MongoRepository = void 0;
13
+ const order_1 = require("./mongoose/schemas/order");
14
+ const order_2 = require("./order");
15
+ const settings_1 = require("../settings");
16
+ /**
17
+ * 注文オファーリポジトリ
18
+ */
19
+ class MongoRepository {
20
+ constructor(connection) {
21
+ this.orderModel = connection.model(order_1.modelName, (0, order_1.createSchema)());
22
+ }
23
+ /**
24
+ * オファー展開の注文検索
25
+ */
26
+ searchWithUnwoundAcceptedOffers(params, projection) {
27
+ var _a;
28
+ return __awaiter(this, void 0, void 0, function* () {
29
+ const conditions = order_2.MongoRepository.CREATE_MONGO_CONDITIONS(params);
30
+ const aggregate = this.orderModel.aggregate();
31
+ // pipelineの順序に注意
32
+ // @see https://docs.mongodb.com/manual/reference/operator/aggregation/sort/
33
+ // tslint:disable-next-line:no-single-line-block-comment
34
+ /* istanbul ignore else */
35
+ if (typeof ((_a = params.sort) === null || _a === void 0 ? void 0 : _a.orderDate) === 'number') {
36
+ aggregate.sort({ orderDate: params.sort.orderDate });
37
+ }
38
+ aggregate.unwind('$acceptedOffers');
39
+ conditions.forEach((c) => {
40
+ aggregate.match(c);
41
+ });
42
+ aggregate.project(Object.assign(Object.assign({}, projection), { acceptedOffers: ['$acceptedOffers'] }));
43
+ if (typeof params.limit === 'number' && params.limit > 0) {
44
+ const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
45
+ aggregate.limit(params.limit * page)
46
+ .skip(params.limit * (page - 1));
47
+ }
48
+ return aggregate
49
+ // .allowDiskUse(true) // false化(2023-11-30~)
50
+ .option({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
51
+ .exec();
52
+ });
53
+ }
54
+ aggreateOwnershipInfosByOrder(filter) {
55
+ return __awaiter(this, void 0, void 0, function* () {
56
+ const aggregate = this.orderModel.aggregate([
57
+ {
58
+ $unwind: {
59
+ path: '$acceptedOffers',
60
+ includeArrayIndex: 'acceptedOfferIndex'
61
+ }
62
+ },
63
+ { $match: { orderNumber: { $eq: filter.orderNumber.$eq } } },
64
+ {
65
+ $project: {
66
+ _id: 0,
67
+ // acceptedOfferIndex: '$acceptedOfferIndex',
68
+ // itemOfferedTypeOf: '$acceptedOffers.itemOffered.typeOf',
69
+ // customerId: '$customer.id',
70
+ // orderNumber: '$orderNumber',
71
+ identifier: {
72
+ $concat: ['$customer.id', '-', '$acceptedOffers.itemOffered.typeOf', '-', '$orderNumber', '-', { $toString: '$acceptedOfferIndex' }]
73
+ }
74
+ }
75
+ }
76
+ ]);
77
+ return aggregate
78
+ .option({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
79
+ .exec();
80
+ });
81
+ }
82
+ /**
83
+ * 注文オファーを展開して検索する
84
+ */
85
+ searchAcceptedOffersByOrderNumber(filter, inclusion) {
86
+ var _a, _b, _c;
87
+ return __awaiter(this, void 0, void 0, function* () {
88
+ const matchStages = [
89
+ { $match: { 'project.id': { $eq: filter.project.id.$eq } } },
90
+ { $match: { orderNumber: { $eq: filter.orderNumber.$eq } } }
91
+ ];
92
+ const itemOfferedTypeOfIn = (_c = (_b = (_a = filter.acceptedOffers) === null || _a === void 0 ? void 0 : _a.itemOffered) === null || _b === void 0 ? void 0 : _b.typeOf) === null || _c === void 0 ? void 0 : _c.$in;
93
+ if (Array.isArray(itemOfferedTypeOfIn)) {
94
+ matchStages.push({
95
+ $match: { 'acceptedOffers.itemOffered.typeOf': { $exists: true, $in: itemOfferedTypeOfIn } }
96
+ });
97
+ }
98
+ const aggregate = this.orderModel.aggregate([
99
+ // if (typeof params.sort?.orderDate === 'number') {
100
+ // aggregate.sort({ orderDate: params.sort.orderDate });
101
+ // }
102
+ {
103
+ $unwind: {
104
+ path: '$acceptedOffers'
105
+ // includeArrayIndex: 'elementIndex'
106
+ }
107
+ },
108
+ ...matchStages
109
+ ]);
110
+ if (Array.isArray(inclusion) && inclusion.length > 0) {
111
+ const specifiedProjection = {
112
+ _id: 0
113
+ };
114
+ inclusion.forEach((key) => {
115
+ specifiedProjection[key] = `$acceptedOffers.${key}`;
116
+ });
117
+ aggregate.project(specifiedProjection);
118
+ }
119
+ else {
120
+ aggregate.project({
121
+ _id: 0,
122
+ itemOffered: '$acceptedOffers.itemOffered',
123
+ priceSpecification: '$acceptedOffers.priceSpecification',
124
+ typeOf: '$acceptedOffers.typeOf',
125
+ id: '$acceptedOffers.id',
126
+ offeredThrough: '$acceptedOffers.offeredThrough',
127
+ name: '$acceptedOffers.name'
128
+ });
129
+ }
130
+ if (typeof filter.limit === 'number' && filter.limit > 0) {
131
+ const page = (typeof filter.page === 'number' && filter.page > 0) ? filter.page : 1;
132
+ aggregate.limit(filter.limit * page)
133
+ .skip(filter.limit * (page - 1));
134
+ }
135
+ return aggregate
136
+ .option({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
137
+ .exec();
138
+ });
139
+ }
140
+ /**
141
+ * 特定のフィールド値リストを検索する
142
+ */
143
+ distinctValues(filter, field) {
144
+ return __awaiter(this, void 0, void 0, function* () {
145
+ if (!Array.isArray(filter.orderNumber.$in) || filter.orderNumber.$in.length === 0) {
146
+ return [];
147
+ }
148
+ const filterQuery = {
149
+ orderNumber: { $in: filter.orderNumber.$in }
150
+ };
151
+ filterQuery[field] = { $exists: true };
152
+ return this.orderModel.distinct(field, filterQuery)
153
+ .setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
154
+ .exec();
155
+ });
156
+ }
157
+ }
158
+ exports.MongoRepository = MongoRepository;
@@ -42,7 +42,11 @@ export declare class MongoRepository {
42
42
  */
43
43
  upsertMoviesByIdentifier(params: {
44
44
  attributes: factory.creativeWork.movie.ICreativeWork;
45
- }[]): Promise<BulkWriteResult | void>;
45
+ }[], options?: {
46
+ replace?: boolean;
47
+ }): Promise<{
48
+ bulkWriteResult: BulkWriteResult;
49
+ } | void>;
46
50
  /**
47
51
  * コンテンツを検索する
48
52
  */
@@ -138,36 +138,56 @@ class MongoRepository {
138
138
  /**
139
139
  * コードをキーにして冪等作成
140
140
  */
141
- upsertMoviesByIdentifier(params) {
141
+ // tslint:disable-next-line:max-func-body-length
142
+ upsertMoviesByIdentifier(params, options) {
142
143
  return __awaiter(this, void 0, void 0, function* () {
143
144
  const bulkWriteOps = [];
144
145
  if (Array.isArray(params)) {
145
- params.forEach((creatingMovieParams) => {
146
- const _a = creatingMovieParams.attributes, { typeOf, project, identifier, duration, name, additionalProperty, contentRating, headline, distributor, thumbnailUrl, datePublished } = _a, setOnInsertFields = __rest(_a, ["typeOf", "project", "identifier", "duration", "name", "additionalProperty", "contentRating", "headline", "distributor", "thumbnailUrl", "datePublished"]);
147
- if (typeof identifier !== 'string' || identifier.length === 0) {
148
- throw new factory.errors.ArgumentNull('identifier');
146
+ params.forEach(({ attributes }) => {
147
+ // リソースのユニークネスを保証するfilter
148
+ const filter = {
149
+ typeOf: attributes.typeOf,
150
+ 'project.id': { $eq: attributes.project.id },
151
+ identifier: { $eq: attributes.identifier }
152
+ };
153
+ if ((options === null || options === void 0 ? void 0 : options.replace) === true) {
154
+ const { id } = attributes, replaceFields = __rest(attributes, ["id"]);
155
+ if (typeof replaceFields.identifier !== 'string' || replaceFields.identifier.length === 0) {
156
+ throw new factory.errors.ArgumentNull('identifier');
157
+ }
158
+ const replacement = replaceFields;
159
+ const replaceOne = {
160
+ filter,
161
+ replacement,
162
+ upsert: true
163
+ };
164
+ bulkWriteOps.push({ replaceOne });
149
165
  }
150
- const updateFilter = {
151
- $setOnInsert: Object.assign(Object.assign({}, setOnInsertFields), { typeOf,
166
+ else {
167
+ const { typeOf, project, identifier, duration, name, additionalProperty, contentRating, headline, distributor, thumbnailUrl, datePublished } = attributes, setOnInsertFields = __rest(attributes, ["typeOf", "project", "identifier", "duration", "name", "additionalProperty", "contentRating", "headline", "distributor", "thumbnailUrl", "datePublished"]);
168
+ if (typeof identifier !== 'string' || identifier.length === 0) {
169
+ throw new factory.errors.ArgumentNull('identifier');
170
+ }
171
+ const setOnInsert = Object.assign(Object.assign({}, setOnInsertFields), { typeOf,
152
172
  project,
153
- identifier }),
154
- // 変更可能な属性のみ上書き
155
- $set: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (name !== undefined) ? { name } : undefined), (contentRating !== undefined) ? { contentRating } : undefined), (duration !== undefined) ? { duration } : undefined), (headline !== undefined) ? { headline } : undefined), (datePublished !== undefined) ? { datePublished } : undefined), (distributor !== undefined) ? { distributor } : undefined), (typeof thumbnailUrl === 'string') ? { thumbnailUrl } : undefined), (Array.isArray(additionalProperty)) ? { additionalProperty } : [])
156
- };
157
- const updateOne = {
158
- filter: {
159
- typeOf: typeOf,
160
- 'project.id': { $eq: project.id },
161
- identifier: { $eq: identifier }
162
- },
163
- update: updateFilter,
164
- upsert: true
165
- };
166
- bulkWriteOps.push({ updateOne });
173
+ identifier });
174
+ const updateFilter = {
175
+ $setOnInsert: setOnInsert,
176
+ // 変更可能な属性のみ上書き
177
+ $set: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (name !== undefined) ? { name } : undefined), (contentRating !== undefined) ? { contentRating } : undefined), (duration !== undefined) ? { duration } : undefined), (headline !== undefined) ? { headline } : undefined), (datePublished !== undefined) ? { datePublished } : undefined), (distributor !== undefined) ? { distributor } : undefined), (typeof thumbnailUrl === 'string') ? { thumbnailUrl } : undefined), (Array.isArray(additionalProperty)) ? { additionalProperty } : [])
178
+ };
179
+ const updateOne = {
180
+ filter,
181
+ update: updateFilter,
182
+ upsert: true
183
+ };
184
+ bulkWriteOps.push({ updateOne });
185
+ }
167
186
  });
168
187
  }
169
188
  if (bulkWriteOps.length > 0) {
170
- return this.creativeWorkModel.bulkWrite(bulkWriteOps, { ordered: false });
189
+ const bulkWriteResult = yield this.creativeWorkModel.bulkWrite(bulkWriteOps, { ordered: false });
190
+ return { bulkWriteResult };
171
191
  }
172
192
  });
173
193
  }
@@ -119,6 +119,18 @@ export declare class MongoRepository {
119
119
  createScreeningEventSeriesIfNotExistByWorkPerformed(params: {
120
120
  attributes: factory.event.IAttributes<factory.eventType.ScreeningEventSeries>;
121
121
  }[]): Promise<BulkWriteResult | void>;
122
+ /**
123
+ * コンテンツ+バージョンをキーにして冪等置換
124
+ */
125
+ upsertScreeningEventSeriesByVersion(params: {
126
+ attributes: factory.event.IAttributes<factory.eventType.ScreeningEventSeries>;
127
+ }[]): Promise<{
128
+ bulkWriteResult4insert: BulkWriteResult;
129
+ bulkWriteResult: BulkWriteResult;
130
+ modifiedEvents: {
131
+ id: string;
132
+ }[];
133
+ } | void>;
122
134
  /**
123
135
  * イベント部分更新
124
136
  */
@@ -605,6 +605,67 @@ class MongoRepository {
605
605
  }
606
606
  });
607
607
  }
608
+ /**
609
+ * コンテンツ+バージョンをキーにして冪等置換
610
+ */
611
+ // tslint:disable-next-line:max-func-body-length
612
+ upsertScreeningEventSeriesByVersion(params
613
+ // options?: {
614
+ // }
615
+ ) {
616
+ return __awaiter(this, void 0, void 0, function* () {
617
+ const uniqid = yield Promise.resolve().then(() => require('uniqid'));
618
+ // replaceOneでは_idを指定できないので、updateOne(setOnInsert)->replaceOneの2段階でbulkWriteを実行する
619
+ const bulkWriteOps4insert = [];
620
+ const bulkWriteOps = [];
621
+ const queryFilters = [];
622
+ if (Array.isArray(params)) {
623
+ params.forEach(({ attributes }) => {
624
+ const version = attributes.workPerformed.version;
625
+ if (typeof version !== 'string' || version.length === 0) {
626
+ throw new factory.errors.ArgumentNull('workPerformed.version');
627
+ }
628
+ // リソースのユニークネスを保証するfilter
629
+ const filter = {
630
+ typeOf: attributes.typeOf,
631
+ 'project.id': { $eq: attributes.project.id },
632
+ 'location.branchCode': { $exists: true, $eq: attributes.location.branchCode },
633
+ 'workPerformed.identifier': { $exists: true, $eq: attributes.workPerformed.identifier },
634
+ 'workPerformed.version': { $exists: true, $eq: version }
635
+ };
636
+ queryFilters.push({
637
+ typeOf: attributes.typeOf,
638
+ 'project.id': { $eq: attributes.project.id },
639
+ 'location.branchCode': { $exists: true, $eq: attributes.location.branchCode },
640
+ 'workPerformed.identifier': { $exists: true, $eq: attributes.workPerformed.identifier },
641
+ 'workPerformed.version': { $exists: true, $eq: version }
642
+ });
643
+ const setOnInsert = Object.assign(Object.assign({}, attributes), { _id: uniqid() });
644
+ const updateOne = {
645
+ filter,
646
+ update: { $setOnInsert: setOnInsert },
647
+ upsert: true
648
+ };
649
+ bulkWriteOps4insert.push({ updateOne });
650
+ const replacement = attributes;
651
+ const replaceOne = {
652
+ filter,
653
+ replacement,
654
+ upsert: true
655
+ };
656
+ bulkWriteOps.push({ replaceOne });
657
+ });
658
+ }
659
+ if (bulkWriteOps.length > 0) {
660
+ const bulkWriteResult4insert = yield this.eventModel.bulkWrite(bulkWriteOps4insert, { ordered: false });
661
+ const bulkWriteResult = yield this.eventModel.bulkWrite(bulkWriteOps, { ordered: false });
662
+ // modifiedの場合upsertedIdsに含まれないので、idを検索する
663
+ const modifiedEvents = yield this.eventModel.find({ $or: queryFilters }, { _id: 1 })
664
+ .exec();
665
+ return { bulkWriteResult4insert, bulkWriteResult, modifiedEvents };
666
+ }
667
+ });
668
+ }
608
669
  /**
609
670
  * イベント部分更新
610
671
  */
@@ -35,11 +35,17 @@ export declare class MongoRepository {
35
35
  private readonly offerCatalogModel;
36
36
  constructor(connection: Connection);
37
37
  static CREATE_MONGO_CONDITIONS(params: factory.offerCatalog.ISearchConditions): any[];
38
- save(params: factory.offerCatalog.IOfferCatalog): Promise<factory.offerCatalog.IOfferCatalog>;
38
+ save(params: factory.offerCatalog.IOfferCatalog & {
39
+ $unset?: any;
40
+ }): Promise<{
41
+ id: string;
42
+ }>;
39
43
  /**
40
44
  * プロジェクトとコードから冪等保管
41
45
  */
42
- saveByIdentifier(params: factory.offerCatalog.IOfferCatalog): Promise<factory.offerCatalog.IOfferCatalog>;
46
+ saveByIdentifier(params: factory.offerCatalog.IOfferCatalog): Promise<{
47
+ id: string;
48
+ }>;
43
49
  /**
44
50
  * 同期日時を更新する
45
51
  */
@@ -133,13 +133,13 @@ class MongoRepository {
133
133
  let doc;
134
134
  if (params.id === '') {
135
135
  const uniqid = yield Promise.resolve().then(() => require('uniqid'));
136
- const id = uniqid();
137
- doc = yield this.offerCatalogModel.create(Object.assign(Object.assign({}, params), { _id: id }));
136
+ const newId = uniqid();
137
+ const { id, $unset } = params, creatingDoc = __rest(params, ["id", "$unset"]);
138
+ doc = yield this.offerCatalogModel.create(Object.assign(Object.assign({}, creatingDoc), { _id: newId }));
138
139
  }
139
140
  else {
140
- // 上書き禁止属性を除外(2022-08-24~)
141
- const { id, identifier, project, typeOf } = params, updateFields = __rest(params, ["id", "identifier", "project", "typeOf"]);
142
- doc = yield this.offerCatalogModel.findOneAndUpdate({ _id: params.id }, updateFields, { upsert: false, new: true })
141
+ const { id, identifier, itemOffered, project, typeOf, $unset } = params, updateFields = __rest(params, ["id", "identifier", "itemOffered", "project", "typeOf", "$unset"]); // 上書き禁止属性を除外
142
+ doc = yield this.offerCatalogModel.findOneAndUpdate({ _id: { $eq: params.id } }, Object.assign({ $set: updateFields }, (params.$unset !== undefined) ? { $unset: params.$unset } : undefined), { upsert: false, new: true, projection: { _id: 1 } })
143
143
  .exec();
144
144
  }
145
145
  if (doc === null) {
@@ -155,14 +155,14 @@ class MongoRepository {
155
155
  return __awaiter(this, void 0, void 0, function* () {
156
156
  const uniqid = yield Promise.resolve().then(() => require('uniqid'));
157
157
  const newId = uniqid();
158
- const { id, identifier, project, typeOf } = params, updateFields = __rest(params, ["id", "identifier", "project", "typeOf"]);
158
+ const { id, identifier, itemOffered, project, typeOf } = params, updateFields = __rest(params, ["id", "identifier", "itemOffered", "project", "typeOf"]);
159
159
  const doc = yield this.offerCatalogModel.findOneAndUpdate({
160
160
  identifier: { $eq: params.identifier },
161
161
  'project.id': { $eq: params.project.id }
162
162
  }, {
163
163
  $set: updateFields,
164
- $setOnInsert: { _id: newId, identifier, project, typeOf }
165
- }, { upsert: true, new: true })
164
+ $setOnInsert: { _id: newId, identifier, itemOffered, project, typeOf }
165
+ }, { upsert: true, new: true, projection: { _id: 1 } })
166
166
  .exec();
167
167
  return doc.toObject();
168
168
  });
@@ -24,12 +24,9 @@
24
24
  /// <reference types="mongoose/types/inferschematype" />
25
25
  import type { Connection, FilterQuery } from 'mongoose';
26
26
  import * as factory from '../factory';
27
- type IKeyOfProjection = keyof factory.order.IOrder | '_id';
28
- type IProjection4searchWithUnwoundAcceptedOffers = {
29
- [key in keyof Omit<factory.order.IOrder, 'acceptedOffers'>]?: 1;
30
- } & {
31
- _id?: 0 | 1;
32
- };
27
+ type IOrderWithoutAcceptedOffers = factory.order.IOrder;
28
+ type IKeyOfProjection = keyof IOrderWithoutAcceptedOffers | '_id';
29
+ export type IReturnedOrder = Pick<IOrderWithoutAcceptedOffers, 'project' | 'typeOf' | 'orderNumber' | 'dateReturned' | 'id' | 'customer' | 'returner' | 'seller' | 'price' | 'priceCurrency' | 'orderDate'>;
33
30
  /**
34
31
  * 注文リポジトリ
35
32
  */
@@ -40,7 +37,9 @@ export declare class MongoRepository {
40
37
  /**
41
38
  * なければ作成する
42
39
  */
43
- createIfNotExist(order: factory.order.IOrder): Promise<void>;
40
+ createIfNotExist(order: IOrderWithoutAcceptedOffers & {
41
+ acceptedOffers: factory.order.IAcceptedOffer<factory.order.IItemOffered>[];
42
+ }): Promise<void>;
44
43
  /**
45
44
  * 注文ステータスを変更する
46
45
  */
@@ -51,7 +50,7 @@ export declare class MongoRepository {
51
50
  orderNumber: string;
52
51
  orderStatus: factory.orderStatus;
53
52
  previousOrderStatus: factory.orderStatus;
54
- }): Promise<factory.order.IOrder>;
53
+ }): Promise<IOrderWithoutAcceptedOffers>;
55
54
  /**
56
55
  * 注文を返品する
57
56
  */
@@ -62,7 +61,7 @@ export declare class MongoRepository {
62
61
  orderNumber: string;
63
62
  dateReturned: Date;
64
63
  returner: factory.order.IReturner;
65
- }): Promise<factory.order.IOrder>;
64
+ }): Promise<IReturnedOrder>;
66
65
  /**
67
66
  * 変更可能な属性を更新する
68
67
  */
@@ -95,7 +94,7 @@ export declare class MongoRepository {
95
94
  id: string;
96
95
  inclusion: IKeyOfProjection[];
97
96
  exclusion: IKeyOfProjection[];
98
- }): Promise<factory.order.IOrder>;
97
+ }): Promise<IOrderWithoutAcceptedOffers>;
99
98
  /**
100
99
  * 注文番号から注文を取得する
101
100
  */
@@ -108,8 +107,8 @@ export declare class MongoRepository {
108
107
  id?: string;
109
108
  };
110
109
  inclusion: IKeyOfProjection[];
111
- exclusion: IKeyOfProjection[];
112
- }): Promise<factory.order.IOrder>;
110
+ exclusion: (IKeyOfProjection | 'acceptedOffers')[];
111
+ }): Promise<IOrderWithoutAcceptedOffers>;
113
112
  findByOrderNumberAndReservationId(params: {
114
113
  project: {
115
114
  id: string;
@@ -119,7 +118,7 @@ export declare class MongoRepository {
119
118
  };
120
119
  orderNumber: string;
121
120
  reservationId: string;
122
- }): Promise<Pick<factory.order.IOrder, 'orderNumber' | 'orderStatus' | 'typeOf'>>;
121
+ }): Promise<Pick<IOrderWithoutAcceptedOffers, 'orderNumber' | 'orderStatus' | 'typeOf'>>;
123
122
  /**
124
123
  * 注文番号で削除する
125
124
  */
@@ -130,48 +129,9 @@ export declare class MongoRepository {
130
129
  /**
131
130
  * 注文を検索する
132
131
  */
133
- search(params: factory.order.ISearchConditions, projection?: {
132
+ search(params: factory.order.ISearchConditions, projection: {
134
133
  [key in IKeyOfProjection]?: 0 | 1;
135
- }): Promise<factory.order.IOrder[]>;
136
- /**
137
- * 注文の受入オファーIDリストを検索する
138
- */
139
- searchAcceptedOfferIds(params: factory.order.ISearchConditions): Promise<(string)[]>;
140
- /**
141
- * オファー展開の注文検索
142
- */
143
- searchWithUnwoundAcceptedOffers(params: factory.order.ISearchConditions, projection?: IProjection4searchWithUnwoundAcceptedOffers): Promise<factory.order.IOrder[]>;
144
- /**
145
- * オファーのみ展開して検索する
146
- */
147
- searchAcceptedOffers(params: factory.order.ISearchConditions, inclusion?: (keyof factory.order.IAcceptedOffer<factory.order.IItemOffered>)[]): Promise<factory.order.IAcceptedOffer<factory.order.IItemOffered>[]>;
148
- /**
149
- * 注文に含まれる予約番号を検索する
150
- */
151
- searchReservationNumbersByOrderNumbers(params: {
152
- orderNumber: {
153
- $in: string[];
154
- };
155
- }): Promise<(string)[]>;
156
- /**
157
- * 注文に含まれるイベントIDを検索する
158
- */
159
- searchReservationForIdsByOrderNumbers(params: {
160
- orderNumber: {
161
- $in: string[];
162
- };
163
- }): Promise<string[]>;
164
- /**
165
- * 注文に含まれるacceptedOffersを検索する
166
- */
167
- searchAcceptedOffersByOrderNumbers(params: {
168
- orderNumber: {
169
- $in: string[];
170
- };
171
- }): Promise<{
172
- id: string;
173
- priceSpecification: factory.order.ITicketPriceSpecification;
174
- }[]>;
134
+ }): Promise<IOrderWithoutAcceptedOffers[]>;
175
135
  getCursor(conditions: any, projection: any): import("mongoose").Cursor<any, import("mongoose").QueryOptions<any>>;
176
136
  unsetUnnecessaryFields(params: {
177
137
  filter: FilterQuery<any>;