@chevre/domain 21.18.0-alpha.4 → 21.18.0-alpha.41
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.
- package/example/src/chevre/aggreateOwnershipInfosByOrder.ts +24 -0
- package/example/src/chevre/offerCatalog2offerCatalogItem.ts +4 -0
- package/example/src/chevre/searchAcceptedOfferIds.ts +57 -0
- package/example/src/chevre/searchOffers.ts +41 -37
- package/example/src/chevre/searchOrderAcceptedOffers.ts +12 -12
- package/example/src/chevre/searchOrders.ts +36 -19
- package/example/src/chevre/searchReservationsByOrder.ts +30 -0
- package/example/src/chevre/searchTransactions.ts +41 -0
- package/example/src/chevre/transaction/processReturnOrder.ts +1 -0
- package/example/src/chevre/upsertMoviesByIdentifier.ts +5 -4
- package/example/src/chevre/upsertOfferCatalogsByIdentifier.ts +46 -0
- package/example/src/chevre/upsertOffersByIdentifier.ts +94 -0
- package/example/src/chevre/upsertScreeningEventSeriesByVersion.ts +104 -0
- package/lib/chevre/credentials.d.ts +0 -3
- package/lib/chevre/credentials.js +4 -3
- package/lib/chevre/repo/acceptedOffer.d.ts +60 -0
- package/lib/chevre/repo/acceptedOffer.js +158 -0
- package/lib/chevre/repo/creativeWork.d.ts +12 -2
- package/lib/chevre/repo/creativeWork.js +39 -25
- package/lib/chevre/repo/event.d.ts +15 -0
- package/lib/chevre/repo/event.js +66 -0
- package/lib/chevre/repo/offer.d.ts +14 -5
- package/lib/chevre/repo/offer.js +94 -19
- package/lib/chevre/repo/offerCatalog.d.ts +18 -1
- package/lib/chevre/repo/offerCatalog.js +51 -39
- package/lib/chevre/repo/order.d.ts +14 -54
- package/lib/chevre/repo/order.js +46 -180
- package/lib/chevre/repo/paymentService.d.ts +30 -0
- package/lib/chevre/repo/paymentService.js +75 -0
- package/lib/chevre/repo/place.js +14 -10
- package/lib/chevre/repo/product.d.ts +41 -10
- package/lib/chevre/repo/product.js +94 -47
- package/lib/chevre/repo/transaction.d.ts +5 -4
- package/lib/chevre/repository.d.ts +10 -7
- package/lib/chevre/repository.js +28 -17
- package/lib/chevre/service/aggregation/event/aggregateScreeningEvent.js +10 -1
- package/lib/chevre/service/aggregation/event/findEventOffers.js +10 -1
- package/lib/chevre/service/assetTransaction/moneyTransfer.js +1 -1
- package/lib/chevre/service/assetTransaction/pay/potentialActions.d.ts +3 -1
- package/lib/chevre/service/assetTransaction/pay/potentialActions.js +3 -3
- package/lib/chevre/service/assetTransaction/pay.d.ts +2 -0
- package/lib/chevre/service/assetTransaction/pay.js +47 -34
- package/lib/chevre/service/assetTransaction/refund/factory.d.ts +1 -1
- package/lib/chevre/service/assetTransaction/refund/factory.js +0 -5
- package/lib/chevre/service/assetTransaction/refund.js +15 -3
- package/lib/chevre/service/assetTransaction/registerService.js +18 -2
- package/lib/chevre/service/assetTransaction/reserve/factory/price.js +1 -1
- package/lib/chevre/service/assetTransaction/reserve.js +32 -2
- package/lib/chevre/service/delivery/factory.d.ts +3 -1
- package/lib/chevre/service/delivery/factory.js +4 -2
- package/lib/chevre/service/delivery.d.ts +1 -2
- package/lib/chevre/service/delivery.js +1 -3
- package/lib/chevre/service/event.js +1 -1
- package/lib/chevre/service/moneyTransfer.js +11 -1
- package/lib/chevre/service/offer/event/factory.d.ts +1 -1
- package/lib/chevre/service/offer/event/factory.js +4 -2
- package/lib/chevre/service/offer/event/searchEventTicketOffers.js +40 -5
- package/lib/chevre/service/offer/product/factory.js +1 -1
- package/lib/chevre/service/offer/product/searchProductOffers.js +10 -1
- package/lib/chevre/service/offer/product.d.ts +0 -14
- package/lib/chevre/service/offer/product.js +61 -44
- package/lib/chevre/service/order/confirmPayTransaction.d.ts +2 -0
- package/lib/chevre/service/order/confirmPayTransaction.js +1 -0
- package/lib/chevre/service/order/createAccountingReportIfNotExist.d.ts +3 -1
- package/lib/chevre/service/order/createAccountingReportIfNotExist.js +4 -1
- package/lib/chevre/service/order/deleteOrder.d.ts +2 -0
- package/lib/chevre/service/order/deleteOrder.js +15 -4
- package/lib/chevre/service/order/findPlaceOrderTransaction.d.ts +3 -1
- package/lib/chevre/service/order/findPlaceOrderTransaction.js +1 -2
- package/lib/chevre/service/order/onAssetTransactionStatusChanged.d.ts +3 -3
- package/lib/chevre/service/order/onAssetTransactionStatusChanged.js +15 -9
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderCancelled/factory.d.ts +11 -0
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderCancelled/factory.js +54 -0
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderCancelled.d.ts +10 -0
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderCancelled.js +38 -0
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderDelivered/factory.d.ts +12 -0
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderDelivered/factory.js +111 -0
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderDelivered.d.ts +12 -0
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderDelivered.js +64 -0
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderPaymentDue.d.ts +10 -0
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderPaymentDue.js +103 -0
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/factory.d.ts +23 -0
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/factory.js +180 -0
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing.d.ts +14 -0
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing.js +214 -0
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderReturned/factory.d.ts +10 -0
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderReturned/factory.js +110 -0
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderReturned.d.ts +14 -0
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderReturned.js +164 -0
- package/lib/chevre/service/order/onOrderStatusChanged.d.ts +9 -15
- package/lib/chevre/service/order/onOrderStatusChanged.js +11 -446
- package/lib/chevre/service/order/onOrderUpdated/factory.d.ts +6 -0
- package/lib/chevre/service/order/onOrderUpdated/factory.js +45 -0
- package/lib/chevre/service/order/onOrderUpdated.js +1 -1
- package/lib/chevre/service/order/payOrder.d.ts +2 -2
- package/lib/chevre/service/order/placeOrder.d.ts +2 -3
- package/lib/chevre/service/order/placeOrder.js +65 -22
- package/lib/chevre/service/order/returnOrder.d.ts +2 -2
- package/lib/chevre/service/order/returnOrder.js +34 -13
- package/lib/chevre/service/order/sendOrder.d.ts +2 -2
- package/lib/chevre/service/order/sendOrder.js +19 -6
- package/lib/chevre/service/order.d.ts +2 -2
- package/lib/chevre/service/order.js +2 -2
- package/lib/chevre/service/payment/any.js +1 -1
- package/lib/chevre/service/payment/movieTicket/getCredentials.js +1 -2
- package/lib/chevre/service/payment/paymentCard.js +9 -2
- package/lib/chevre/service/reserve/searchByOrder.d.ts +21 -0
- package/lib/chevre/service/reserve/searchByOrder.js +113 -0
- package/lib/chevre/service/reserve/verifyToken4reservation.js +0 -11
- package/lib/chevre/service/reserve.d.ts +2 -1
- package/lib/chevre/service/reserve.js +3 -1
- package/lib/chevre/service/task/confirmPayTransaction.js +2 -1
- package/lib/chevre/service/task/deleteTransaction.js +2 -0
- package/lib/chevre/service/task/onAssetTransactionStatusChanged.js +5 -6
- package/lib/chevre/service/task/onAuthorizationCreated.js +9 -18
- package/lib/chevre/service/task/onOrderPaymentCompleted.js +5 -6
- package/lib/chevre/service/task/onResourceUpdated/onResourceDeleted.js +1 -1
- package/lib/chevre/service/task/onResourceUpdated.js +1 -1
- package/lib/chevre/service/task/placeOrder.js +10 -17
- package/lib/chevre/service/task/returnOrder.js +10 -17
- package/lib/chevre/service/task/sendOrder.js +10 -17
- package/lib/chevre/service/task/voidRegisterServiceTransaction.js +3 -7
- package/lib/chevre/service/transaction/deleteTransaction.d.ts +2 -0
- package/lib/chevre/service/transaction/moneyTransfer.js +3 -4
- package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions/registerService.d.ts +0 -4
- package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions/registerService.js +0 -86
- package/lib/chevre/service/transaction/placeOrderInProgress/result.d.ts +1 -1
- package/lib/chevre/service/transaction/placeOrderInProgress/validation.d.ts +1 -1
- package/lib/chevre/service/transaction/returnOrder/potentialActions/returnMoneyTransfer.d.ts +1 -0
- package/lib/chevre/service/transaction/returnOrder/potentialActions/returnMoneyTransfer.js +3 -3
- package/lib/chevre/service/transaction/returnOrder/potentialActions.d.ts +1 -0
- package/lib/chevre/service/transaction/returnOrder/potentialActions.js +1 -1
- package/lib/chevre/service/transaction/returnOrder.d.ts +3 -0
- package/lib/chevre/service/transaction/returnOrder.js +73 -55
- package/package.json +3 -3
- package/example/src/chevre/transaction/findPaymentCardPermit.ts +0 -29
- package/lib/chevre/repo/action/registerServiceInProgress.d.ts +0 -29
- package/lib/chevre/repo/action/registerServiceInProgress.js +0 -58
- package/lib/chevre/service/order/onOrderStatusChanged/factory.d.ts +0 -42
- package/lib/chevre/service/order/onOrderStatusChanged/factory.js +0 -467
- package/lib/chevre/service/transaction/orderProgramMembership/findPaymentCardPermit.d.ts +0 -26
- package/lib/chevre/service/transaction/orderProgramMembership/findPaymentCardPermit.js +0 -65
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
/// <reference types="mongoose/types/validation" />
|
|
23
23
|
/// <reference types="mongoose/types/virtuals" />
|
|
24
24
|
/// <reference types="mongoose/types/inferschematype" />
|
|
25
|
+
import type { BulkWriteResult } from 'mongodb';
|
|
25
26
|
import type { Connection } from 'mongoose';
|
|
26
27
|
import * as factory from '../factory';
|
|
27
28
|
export type IAggregatedOfferCatalog = Pick<factory.offerCatalog.IOfferCatalog, 'id' | 'name' | 'description' | 'project' | 'typeOf' | 'identifier' | 'itemOffered' | 'additionalProperty'> & {
|
|
@@ -36,7 +37,9 @@ export declare class MongoRepository {
|
|
|
36
37
|
constructor(connection: Connection);
|
|
37
38
|
static CREATE_MONGO_CONDITIONS(params: factory.offerCatalog.ISearchConditions): any[];
|
|
38
39
|
save(params: factory.offerCatalog.IOfferCatalog & {
|
|
39
|
-
$unset?:
|
|
40
|
+
$unset?: {
|
|
41
|
+
[key in keyof factory.offerCatalog.IOfferCatalog]?: 1;
|
|
42
|
+
};
|
|
40
43
|
}): Promise<{
|
|
41
44
|
id: string;
|
|
42
45
|
}>;
|
|
@@ -46,6 +49,20 @@ export declare class MongoRepository {
|
|
|
46
49
|
saveByIdentifier(params: factory.offerCatalog.IOfferCatalog): Promise<{
|
|
47
50
|
id: string;
|
|
48
51
|
}>;
|
|
52
|
+
/**
|
|
53
|
+
* コードをキーにして冪等置換(2023-12-14~)
|
|
54
|
+
*/
|
|
55
|
+
upsertManyByIdentifier(params: {
|
|
56
|
+
$set: factory.offerCatalog.IOfferCatalog;
|
|
57
|
+
$unset?: {
|
|
58
|
+
[key in keyof factory.offerCatalog.IOfferCatalog]?: 1;
|
|
59
|
+
};
|
|
60
|
+
}[]): Promise<{
|
|
61
|
+
bulkWriteResult: BulkWriteResult;
|
|
62
|
+
modifiedCatalogs: {
|
|
63
|
+
id: string;
|
|
64
|
+
}[];
|
|
65
|
+
} | void>;
|
|
49
66
|
/**
|
|
50
67
|
* 同期日時を更新する
|
|
51
68
|
*/
|
|
@@ -167,6 +167,57 @@ class MongoRepository {
|
|
|
167
167
|
return doc.toObject();
|
|
168
168
|
});
|
|
169
169
|
}
|
|
170
|
+
/**
|
|
171
|
+
* コードをキーにして冪等置換(2023-12-14~)
|
|
172
|
+
*/
|
|
173
|
+
upsertManyByIdentifier(params
|
|
174
|
+
// options?: {
|
|
175
|
+
// }
|
|
176
|
+
) {
|
|
177
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
178
|
+
const uniqid = yield Promise.resolve().then(() => require('uniqid'));
|
|
179
|
+
const bulkWriteOps = [];
|
|
180
|
+
const queryFilters = [];
|
|
181
|
+
if (Array.isArray(params)) {
|
|
182
|
+
params.forEach(({ $set, $unset }) => {
|
|
183
|
+
const { id, identifier, project, typeOf } = $set, setFields = __rest($set, ["id", "identifier", "project", "typeOf"]);
|
|
184
|
+
if (typeof identifier !== 'string' || identifier.length === 0) {
|
|
185
|
+
throw new factory.errors.ArgumentNull('identifier');
|
|
186
|
+
}
|
|
187
|
+
// リソースのユニークネスを保証するfilter
|
|
188
|
+
const filter = {
|
|
189
|
+
'project.id': { $eq: project.id },
|
|
190
|
+
identifier: { $eq: identifier }
|
|
191
|
+
};
|
|
192
|
+
queryFilters.push({
|
|
193
|
+
'project.id': { $eq: project.id },
|
|
194
|
+
identifier: { $eq: identifier }
|
|
195
|
+
});
|
|
196
|
+
const newId = uniqid();
|
|
197
|
+
const setOnInsert = {
|
|
198
|
+
identifier,
|
|
199
|
+
project,
|
|
200
|
+
typeOf,
|
|
201
|
+
_id: newId
|
|
202
|
+
};
|
|
203
|
+
const updateOne = {
|
|
204
|
+
filter,
|
|
205
|
+
update: Object.assign({ $setOnInsert: setOnInsert, $set: setFields }, ($unset !== undefined) ? { $unset } : undefined),
|
|
206
|
+
upsert: true
|
|
207
|
+
};
|
|
208
|
+
bulkWriteOps.push({ updateOne });
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
if (bulkWriteOps.length > 0) {
|
|
212
|
+
const bulkWriteResult = yield this.offerCatalogModel.bulkWrite(bulkWriteOps, { ordered: false });
|
|
213
|
+
// const bulkWriteResult = await this.offerCatalogModel.bulkWrite(bulkWriteOps, { ordered: false });
|
|
214
|
+
// modifiedの場合upsertedIdsに含まれないので、idを検索する
|
|
215
|
+
const modifiedCatalogs = yield this.offerCatalogModel.find({ $or: queryFilters }, { _id: 1 })
|
|
216
|
+
.exec();
|
|
217
|
+
return { bulkWriteResult, modifiedCatalogs };
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
}
|
|
170
221
|
/**
|
|
171
222
|
* 同期日時を更新する
|
|
172
223
|
*/
|
|
@@ -176,45 +227,6 @@ class MongoRepository {
|
|
|
176
227
|
.exec();
|
|
177
228
|
});
|
|
178
229
|
}
|
|
179
|
-
// /**
|
|
180
|
-
// * 型を統一する
|
|
181
|
-
// */
|
|
182
|
-
// public async optimizeAll(): Promise<void> {
|
|
183
|
-
// let result = await this.offerCatalogModel.updateMany(
|
|
184
|
-
// { typeOf: { $ne: 'OfferCatalog' } },
|
|
185
|
-
// { $set: { typeOf: 'OfferCatalog' } }
|
|
186
|
-
// )
|
|
187
|
-
// .exec();
|
|
188
|
-
// // tslint:disable-next-line:no-console
|
|
189
|
-
// console.log(result);
|
|
190
|
-
// result = await this.offerCatalogModel.updateMany(
|
|
191
|
-
// { ticketTypes: { $exists: true } },
|
|
192
|
-
// {
|
|
193
|
-
// $unset: { ticketTypes: 1 }
|
|
194
|
-
// }
|
|
195
|
-
// )
|
|
196
|
-
// .exec();
|
|
197
|
-
// // tslint:disable-next-line:no-console
|
|
198
|
-
// console.log(result);
|
|
199
|
-
// result = await this.offerCatalogModel.updateMany(
|
|
200
|
-
// { id: { $exists: true } },
|
|
201
|
-
// {
|
|
202
|
-
// $unset: { id: 1 }
|
|
203
|
-
// }
|
|
204
|
-
// )
|
|
205
|
-
// .exec();
|
|
206
|
-
// // tslint:disable-next-line:no-console
|
|
207
|
-
// console.log(result);
|
|
208
|
-
// result = await this.offerCatalogModel.updateMany(
|
|
209
|
-
// { 'itemOffered.serviceType': { $exists: true } },
|
|
210
|
-
// {
|
|
211
|
-
// $unset: { 'itemOffered.serviceType': 1 }
|
|
212
|
-
// }
|
|
213
|
-
// )
|
|
214
|
-
// .exec();
|
|
215
|
-
// // tslint:disable-next-line:no-console
|
|
216
|
-
// console.log(result);
|
|
217
|
-
// }
|
|
218
230
|
updateManyById(params) {
|
|
219
231
|
return __awaiter(this, void 0, void 0, function* () {
|
|
220
232
|
if (!Array.isArray(params.id.$in) || params.id.$in.length === 0) {
|
|
@@ -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
|
|
28
|
-
type
|
|
29
|
-
|
|
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:
|
|
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<
|
|
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<
|
|
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<
|
|
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<
|
|
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<
|
|
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<
|
|
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>;
|
package/lib/chevre/repo/order.js
CHANGED
|
@@ -697,7 +697,8 @@ class MongoRepository {
|
|
|
697
697
|
projection: {
|
|
698
698
|
__v: 0,
|
|
699
699
|
createdAt: 0,
|
|
700
|
-
updatedAt: 0
|
|
700
|
+
updatedAt: 0,
|
|
701
|
+
acceptedOffers: 0 // 除外(2023-12-08~)
|
|
701
702
|
}
|
|
702
703
|
})
|
|
703
704
|
.exec();
|
|
@@ -707,7 +708,9 @@ class MongoRepository {
|
|
|
707
708
|
orderNumber: params.orderNumber,
|
|
708
709
|
project: { id: params.project.id },
|
|
709
710
|
inclusion: [],
|
|
710
|
-
exclusion: [
|
|
711
|
+
exclusion: [
|
|
712
|
+
'acceptedOffers' // 除外(2023-12-08~)
|
|
713
|
+
]
|
|
711
714
|
});
|
|
712
715
|
// tslint:disable-next-line:no-single-line-block-comment
|
|
713
716
|
/* istanbul ignore next */
|
|
@@ -741,9 +744,11 @@ class MongoRepository {
|
|
|
741
744
|
}, {
|
|
742
745
|
new: true,
|
|
743
746
|
projection: {
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
+
_id: 1, project: 1, typeOf: 1, orderNumber: 1, dateReturned: 1,
|
|
748
|
+
customer: 1, returner: 1, seller: 1, price: 1, priceCurrency: 1, orderDate: 1 // optimize(2023-12-07~)
|
|
749
|
+
// __v: 0,
|
|
750
|
+
// createdAt: 0,
|
|
751
|
+
// updatedAt: 0
|
|
747
752
|
}
|
|
748
753
|
})
|
|
749
754
|
.exec();
|
|
@@ -752,8 +757,11 @@ class MongoRepository {
|
|
|
752
757
|
const order = yield this.findByOrderNumber({
|
|
753
758
|
orderNumber: params.orderNumber,
|
|
754
759
|
project: { id: params.project.id },
|
|
755
|
-
inclusion: [
|
|
756
|
-
|
|
760
|
+
inclusion: [
|
|
761
|
+
'project', 'typeOf', 'orderNumber', 'dateReturned', 'id',
|
|
762
|
+
'customer', 'returner', 'seller', 'price', 'priceCurrency', 'orderDate'
|
|
763
|
+
],
|
|
764
|
+
exclusion: [] // 除外(2023-12-07~)
|
|
757
765
|
});
|
|
758
766
|
// tslint:disable-next-line:no-single-line-block-comment
|
|
759
767
|
/* istanbul ignore next */
|
|
@@ -825,17 +833,20 @@ class MongoRepository {
|
|
|
825
833
|
}
|
|
826
834
|
findById(params) {
|
|
827
835
|
return __awaiter(this, void 0, void 0, function* () {
|
|
828
|
-
let projection = {};
|
|
836
|
+
let projection = { _id: 1 };
|
|
829
837
|
if (Array.isArray(params.inclusion) && params.inclusion.length > 0) {
|
|
830
838
|
params.inclusion.forEach((field) => {
|
|
831
|
-
|
|
839
|
+
if (String(field) !== 'acceptedOffers') {
|
|
840
|
+
projection[field] = 1;
|
|
841
|
+
}
|
|
832
842
|
});
|
|
833
843
|
}
|
|
834
844
|
else {
|
|
835
845
|
projection = {
|
|
836
846
|
__v: 0,
|
|
837
847
|
createdAt: 0,
|
|
838
|
-
updatedAt: 0
|
|
848
|
+
updatedAt: 0,
|
|
849
|
+
acceptedOffers: 0
|
|
839
850
|
};
|
|
840
851
|
if (Array.isArray(params.exclusion) && params.exclusion.length > 0) {
|
|
841
852
|
params.exclusion.forEach((field) => {
|
|
@@ -859,14 +870,17 @@ class MongoRepository {
|
|
|
859
870
|
let projection = {};
|
|
860
871
|
if (Array.isArray(params.inclusion) && params.inclusion.length > 0) {
|
|
861
872
|
params.inclusion.forEach((field) => {
|
|
862
|
-
|
|
873
|
+
if (String(field) !== 'acceptedOffers') {
|
|
874
|
+
projection[field] = 1;
|
|
875
|
+
}
|
|
863
876
|
});
|
|
864
877
|
}
|
|
865
878
|
else {
|
|
866
879
|
projection = {
|
|
867
880
|
__v: 0,
|
|
868
881
|
createdAt: 0,
|
|
869
|
-
updatedAt: 0
|
|
882
|
+
updatedAt: 0,
|
|
883
|
+
acceptedOffers: 0 // defaultで除外(2023-12-08~)
|
|
870
884
|
};
|
|
871
885
|
if (Array.isArray(params.exclusion) && params.exclusion.length > 0) {
|
|
872
886
|
params.exclusion.forEach((field) => {
|
|
@@ -929,19 +943,30 @@ class MongoRepository {
|
|
|
929
943
|
/**
|
|
930
944
|
* 注文を検索する
|
|
931
945
|
*/
|
|
932
|
-
search(params,
|
|
946
|
+
search(params,
|
|
947
|
+
// 必須化(2023-12-08~)
|
|
948
|
+
projection) {
|
|
933
949
|
var _a;
|
|
934
950
|
return __awaiter(this, void 0, void 0, function* () {
|
|
935
951
|
const conditions = MongoRepository.CREATE_MONGO_CONDITIONS(params);
|
|
936
|
-
|
|
937
|
-
const
|
|
938
|
-
? Object.
|
|
939
|
-
.
|
|
940
|
-
|
|
952
|
+
let projectStage = {};
|
|
953
|
+
const positiveProjectionFields = (projection !== undefined && projection !== null)
|
|
954
|
+
? Object.keys(projection)
|
|
955
|
+
.filter((key) => projection[key] !== 0
|
|
956
|
+
&& key !== 'acceptedOffers' // defaultで隠蔽(2023-12-06~)
|
|
957
|
+
)
|
|
958
|
+
: [];
|
|
959
|
+
if (Array.isArray(positiveProjectionFields) && positiveProjectionFields.length > 0) {
|
|
960
|
+
projectStage = {};
|
|
961
|
+
positiveProjectionFields.forEach((field) => {
|
|
962
|
+
projectStage[field] = 1;
|
|
963
|
+
});
|
|
964
|
+
}
|
|
965
|
+
else {
|
|
966
|
+
projectStage = Object.assign({ __v: 0, createdAt: 0, updatedAt: 0, acceptedOffers: 0 }, projection);
|
|
967
|
+
}
|
|
941
968
|
const query = this.orderModel.find((conditions.length > 0) ? { $and: conditions } : {})
|
|
942
|
-
.select(
|
|
943
|
-
? projection
|
|
944
|
-
: Object.assign({ __v: 0, createdAt: 0, updatedAt: 0 }, projection));
|
|
969
|
+
.select(projectStage);
|
|
945
970
|
if (typeof params.limit === 'number' && params.limit > 0) {
|
|
946
971
|
const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
|
|
947
972
|
query.limit(params.limit)
|
|
@@ -959,165 +984,6 @@ class MongoRepository {
|
|
|
959
984
|
.then((docs) => docs.map((doc) => doc.toObject()));
|
|
960
985
|
});
|
|
961
986
|
}
|
|
962
|
-
/**
|
|
963
|
-
* 注文の受入オファーIDリストを検索する
|
|
964
|
-
*/
|
|
965
|
-
searchAcceptedOfferIds(params) {
|
|
966
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
967
|
-
const conditions = MongoRepository.CREATE_MONGO_CONDITIONS(params);
|
|
968
|
-
const query = this.orderModel.find((conditions.length > 0) ? { $and: conditions } : {})
|
|
969
|
-
.select({
|
|
970
|
-
'acceptedOffers.id': 1
|
|
971
|
-
});
|
|
972
|
-
const orders = yield query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
973
|
-
.exec()
|
|
974
|
-
.then((docs) => docs.map((doc) => {
|
|
975
|
-
return doc.toObject();
|
|
976
|
-
}));
|
|
977
|
-
const offerIds = orders.reduce((a, b) => {
|
|
978
|
-
const offerIdsByOrder = (Array.isArray(b.acceptedOffers))
|
|
979
|
-
? b.acceptedOffers.filter((offer) => typeof offer.id === 'string')
|
|
980
|
-
.map((offer) => {
|
|
981
|
-
return String(offer.id);
|
|
982
|
-
})
|
|
983
|
-
: [];
|
|
984
|
-
return [...a, ...offerIdsByOrder];
|
|
985
|
-
}, []);
|
|
986
|
-
return [...new Set(offerIds)];
|
|
987
|
-
});
|
|
988
|
-
}
|
|
989
|
-
/**
|
|
990
|
-
* オファー展開の注文検索
|
|
991
|
-
*/
|
|
992
|
-
searchWithUnwoundAcceptedOffers(params, projection) {
|
|
993
|
-
var _a;
|
|
994
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
995
|
-
const conditions = MongoRepository.CREATE_MONGO_CONDITIONS(params);
|
|
996
|
-
const aggregate = this.orderModel.aggregate();
|
|
997
|
-
// pipelineの順序に注意
|
|
998
|
-
// @see https://docs.mongodb.com/manual/reference/operator/aggregation/sort/
|
|
999
|
-
// tslint:disable-next-line:no-single-line-block-comment
|
|
1000
|
-
/* istanbul ignore else */
|
|
1001
|
-
if (typeof ((_a = params.sort) === null || _a === void 0 ? void 0 : _a.orderDate) === 'number') {
|
|
1002
|
-
aggregate.sort({ orderDate: params.sort.orderDate });
|
|
1003
|
-
}
|
|
1004
|
-
aggregate.unwind('$acceptedOffers');
|
|
1005
|
-
conditions.forEach((c) => {
|
|
1006
|
-
aggregate.match(c);
|
|
1007
|
-
});
|
|
1008
|
-
aggregate.project(Object.assign(Object.assign({}, projection), { acceptedOffers: ['$acceptedOffers'] }));
|
|
1009
|
-
if (typeof params.limit === 'number' && params.limit > 0) {
|
|
1010
|
-
const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
|
|
1011
|
-
aggregate.limit(params.limit * page)
|
|
1012
|
-
.skip(params.limit * (page - 1));
|
|
1013
|
-
}
|
|
1014
|
-
return aggregate
|
|
1015
|
-
// .allowDiskUse(true) // false化(2023-11-30~)
|
|
1016
|
-
.option({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
1017
|
-
.exec();
|
|
1018
|
-
});
|
|
1019
|
-
}
|
|
1020
|
-
/**
|
|
1021
|
-
* オファーのみ展開して検索する
|
|
1022
|
-
*/
|
|
1023
|
-
searchAcceptedOffers(params, inclusion) {
|
|
1024
|
-
var _a;
|
|
1025
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1026
|
-
const conditions = MongoRepository.CREATE_MONGO_CONDITIONS(params);
|
|
1027
|
-
const aggregate = this.orderModel.aggregate();
|
|
1028
|
-
// pipelineの順序に注意
|
|
1029
|
-
// @see https://docs.mongodb.com/manual/reference/operator/aggregation/sort/
|
|
1030
|
-
// tslint:disable-next-line:no-single-line-block-comment
|
|
1031
|
-
/* istanbul ignore else */
|
|
1032
|
-
if (typeof ((_a = params.sort) === null || _a === void 0 ? void 0 : _a.orderDate) === 'number') {
|
|
1033
|
-
aggregate.sort({ orderDate: params.sort.orderDate });
|
|
1034
|
-
}
|
|
1035
|
-
aggregate.unwind('$acceptedOffers');
|
|
1036
|
-
conditions.forEach((c) => {
|
|
1037
|
-
aggregate.match(c);
|
|
1038
|
-
});
|
|
1039
|
-
if (Array.isArray(inclusion) && inclusion.length > 0) {
|
|
1040
|
-
const specifiedProjection = {
|
|
1041
|
-
_id: 0
|
|
1042
|
-
};
|
|
1043
|
-
inclusion.forEach((key) => {
|
|
1044
|
-
specifiedProjection[key] = `$acceptedOffers.${key}`;
|
|
1045
|
-
});
|
|
1046
|
-
aggregate.project(specifiedProjection);
|
|
1047
|
-
}
|
|
1048
|
-
else {
|
|
1049
|
-
aggregate.project({
|
|
1050
|
-
_id: 0,
|
|
1051
|
-
itemOffered: '$acceptedOffers.itemOffered',
|
|
1052
|
-
priceSpecification: '$acceptedOffers.priceSpecification',
|
|
1053
|
-
typeOf: '$acceptedOffers.typeOf',
|
|
1054
|
-
id: '$acceptedOffers.id',
|
|
1055
|
-
offeredThrough: '$acceptedOffers.offeredThrough',
|
|
1056
|
-
name: '$acceptedOffers.name'
|
|
1057
|
-
});
|
|
1058
|
-
}
|
|
1059
|
-
if (typeof params.limit === 'number' && params.limit > 0) {
|
|
1060
|
-
const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
|
|
1061
|
-
aggregate.limit(params.limit * page)
|
|
1062
|
-
.skip(params.limit * (page - 1));
|
|
1063
|
-
}
|
|
1064
|
-
return aggregate
|
|
1065
|
-
.option({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
1066
|
-
.exec();
|
|
1067
|
-
});
|
|
1068
|
-
}
|
|
1069
|
-
/**
|
|
1070
|
-
* 注文に含まれる予約番号を検索する
|
|
1071
|
-
*/
|
|
1072
|
-
searchReservationNumbersByOrderNumbers(params) {
|
|
1073
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1074
|
-
if (!Array.isArray(params.orderNumber.$in) || params.orderNumber.$in.length === 0) {
|
|
1075
|
-
return [];
|
|
1076
|
-
}
|
|
1077
|
-
return this.orderModel.distinct('acceptedOffers.itemOffered.reservationNumber', {
|
|
1078
|
-
'acceptedOffers.itemOffered.reservationNumber': { $exists: true },
|
|
1079
|
-
orderNumber: { $in: params.orderNumber.$in }
|
|
1080
|
-
})
|
|
1081
|
-
.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
1082
|
-
.exec();
|
|
1083
|
-
});
|
|
1084
|
-
}
|
|
1085
|
-
/**
|
|
1086
|
-
* 注文に含まれるイベントIDを検索する
|
|
1087
|
-
*/
|
|
1088
|
-
searchReservationForIdsByOrderNumbers(params) {
|
|
1089
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1090
|
-
if (!Array.isArray(params.orderNumber.$in) || params.orderNumber.$in.length === 0) {
|
|
1091
|
-
return [];
|
|
1092
|
-
}
|
|
1093
|
-
return this.orderModel.distinct('acceptedOffers.itemOffered.reservationFor.id', {
|
|
1094
|
-
'acceptedOffers.itemOffered.reservationFor.id': { $exists: true },
|
|
1095
|
-
orderNumber: { $in: params.orderNumber.$in }
|
|
1096
|
-
})
|
|
1097
|
-
.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
1098
|
-
.exec();
|
|
1099
|
-
});
|
|
1100
|
-
}
|
|
1101
|
-
/**
|
|
1102
|
-
* 注文に含まれるacceptedOffersを検索する
|
|
1103
|
-
*/
|
|
1104
|
-
searchAcceptedOffersByOrderNumbers(params) {
|
|
1105
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1106
|
-
if (!Array.isArray(params.orderNumber.$in) || params.orderNumber.$in.length === 0) {
|
|
1107
|
-
return [];
|
|
1108
|
-
}
|
|
1109
|
-
const aggregate = this.orderModel.aggregate();
|
|
1110
|
-
aggregate.unwind('$acceptedOffers');
|
|
1111
|
-
aggregate.match({ orderNumber: { $in: params.orderNumber.$in } });
|
|
1112
|
-
aggregate.project({
|
|
1113
|
-
_id: 0,
|
|
1114
|
-
id: '$acceptedOffers.id',
|
|
1115
|
-
priceSpecification: '$acceptedOffers.priceSpecification'
|
|
1116
|
-
});
|
|
1117
|
-
return aggregate.option({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
1118
|
-
.exec();
|
|
1119
|
-
});
|
|
1120
|
-
}
|
|
1121
987
|
getCursor(conditions, projection) {
|
|
1122
988
|
return this.orderModel.find(conditions, projection)
|
|
1123
989
|
.sort({ orderDate: factory.sortType.Descending })
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Connection } from 'mongoose';
|
|
2
|
+
import * as factory from '../factory';
|
|
3
|
+
type IUnsetKey = keyof Pick<factory.service.paymentService.IService, 'additionalProperty' | 'availableChannel' | 'serviceOutput' | 'serviceType'>;
|
|
4
|
+
/**
|
|
5
|
+
* 決済サービスリポジトリ
|
|
6
|
+
*/
|
|
7
|
+
export declare class MongoRepository {
|
|
8
|
+
private readonly productModel;
|
|
9
|
+
constructor(connection: Connection);
|
|
10
|
+
/**
|
|
11
|
+
* 決済サービスを保管する
|
|
12
|
+
*/
|
|
13
|
+
savePaymentService(params: {
|
|
14
|
+
/**
|
|
15
|
+
* idを指定すれば更新
|
|
16
|
+
*/
|
|
17
|
+
id?: string;
|
|
18
|
+
$set: factory.service.paymentService.IService;
|
|
19
|
+
$unset: {
|
|
20
|
+
[key in IUnsetKey]?: 1;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* 指定プロジェクトの指定プロダクトタイプが存在しなければ作成する
|
|
24
|
+
*/
|
|
25
|
+
createIfNotExist?: boolean;
|
|
26
|
+
}): Promise<{
|
|
27
|
+
id: string;
|
|
28
|
+
}>;
|
|
29
|
+
}
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,75 @@
|
|
|
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
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
exports.MongoRepository = void 0;
|
|
24
|
+
const product_1 = require("./mongoose/schemas/product");
|
|
25
|
+
const factory = require("../factory");
|
|
26
|
+
/**
|
|
27
|
+
* 決済サービスリポジトリ
|
|
28
|
+
*/
|
|
29
|
+
class MongoRepository {
|
|
30
|
+
constructor(connection) {
|
|
31
|
+
this.productModel = connection.model(product_1.modelName, (0, product_1.createSchema)());
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* 決済サービスを保管する
|
|
35
|
+
*/
|
|
36
|
+
savePaymentService(params) {
|
|
37
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
let doc;
|
|
39
|
+
if (typeof params.id === 'string') {
|
|
40
|
+
// 上書き禁止属性を除外
|
|
41
|
+
const _a = params.$set, { id, productID, project, typeOf, provider } = _a, setFields = __rest(_a, ["id", "productID", "project", "typeOf", "provider"]);
|
|
42
|
+
switch (typeOf) {
|
|
43
|
+
case factory.service.paymentService.PaymentServiceType.CreditCard:
|
|
44
|
+
case factory.service.paymentService.PaymentServiceType.MovieTicket:
|
|
45
|
+
doc = yield this.productModel.findOneAndUpdate({
|
|
46
|
+
_id: { $eq: params.id },
|
|
47
|
+
typeOf: { $eq: typeOf }
|
|
48
|
+
}, { $set: setFields }, { upsert: false, new: true, projection: { _id: 1 } })
|
|
49
|
+
.exec();
|
|
50
|
+
break;
|
|
51
|
+
default:
|
|
52
|
+
throw new factory.errors.NotImplemented(`${typeOf} not implemented`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
const _b = params.$set, { id } = _b, createParams = __rest(_b, ["id"]);
|
|
57
|
+
if (params.createIfNotExist === true) {
|
|
58
|
+
doc = yield this.productModel.findOneAndUpdate({
|
|
59
|
+
'project.id': { $eq: createParams.project.id },
|
|
60
|
+
typeOf: { $eq: createParams.typeOf }
|
|
61
|
+
}, { $setOnInsert: createParams }, { new: true, upsert: true, projection: { _id: 1 } })
|
|
62
|
+
.exec();
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
doc = yield this.productModel.create(createParams);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (doc === null) {
|
|
69
|
+
throw new factory.errors.NotFound(this.productModel.modelName);
|
|
70
|
+
}
|
|
71
|
+
return doc.toObject();
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
exports.MongoRepository = MongoRepository;
|