@chevre/domain 26.0.0-alpha.3 → 26.0.0-alpha.30
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/lib/chevre/eventEmitter/task.d.ts +8 -23
- package/lib/chevre/eventEmitter/task.js +2 -2
- package/lib/chevre/repo/acceptedOffer.d.ts +0 -7
- package/lib/chevre/repo/acceptedOffer.js +27 -27
- package/lib/chevre/repo/action/actionProcess.d.ts +1 -1
- package/lib/chevre/repo/action/inform.d.ts +45 -0
- package/lib/chevre/repo/action/inform.js +159 -0
- package/lib/chevre/repo/action/update.d.ts +56 -0
- package/lib/chevre/repo/action/update.js +173 -0
- package/lib/chevre/repo/action.d.ts +3 -19
- package/lib/chevre/repo/action.js +0 -298
- package/lib/chevre/repo/adminAssetTransaction.d.ts +126 -0
- package/lib/chevre/repo/adminAssetTransaction.js +491 -0
- package/lib/chevre/repo/adminAsyncAction.d.ts +2 -2
- package/lib/chevre/repo/adminScheduledTask.d.ts +1 -1
- package/lib/chevre/repo/adminTask.d.ts +25 -8
- package/lib/chevre/repo/adminTask.js +31 -32
- package/lib/chevre/repo/adminTransaction.d.ts +131 -0
- package/lib/chevre/repo/adminTransaction.js +237 -0
- package/lib/chevre/repo/aggregateAssetTransaction.d.ts +43 -0
- package/lib/chevre/repo/aggregateAssetTransaction.js +166 -0
- package/lib/chevre/repo/aggregateScheduledTask.d.ts +32 -0
- package/lib/chevre/repo/aggregateScheduledTask.js +136 -0
- package/lib/chevre/repo/aggregateTransaction.d.ts +39 -0
- package/lib/chevre/repo/aggregateTransaction.js +166 -0
- package/lib/chevre/repo/aggregation.d.ts +0 -8
- package/lib/chevre/repo/aggregation.js +0 -10
- package/lib/chevre/repo/assetTransaction.d.ts +10 -235
- package/lib/chevre/repo/assetTransaction.js +48 -636
- package/lib/chevre/repo/asyncAction.d.ts +2 -2
- package/lib/chevre/repo/authorization.d.ts +0 -6
- package/lib/chevre/repo/authorization.js +15 -27
- package/lib/chevre/repo/message.d.ts +0 -7
- package/lib/chevre/repo/message.js +0 -38
- package/lib/chevre/repo/mongoose/schemas/{ownershipInfo.d.ts → action/inform.d.ts} +5 -5
- package/lib/chevre/repo/mongoose/schemas/action/inform.js +81 -0
- package/lib/chevre/repo/mongoose/schemas/action/update.d.ts +12 -0
- package/lib/chevre/repo/mongoose/schemas/action/update.js +107 -0
- package/lib/chevre/repo/mongoose/schemas/action.d.ts +1 -1
- package/lib/chevre/repo/mongoose/schemas/action.js +8 -1
- package/lib/chevre/repo/mongoose/schemas/actionRecipe.js +7 -0
- package/lib/chevre/repo/mongoose/schemas/aggregateReservation.js +8 -9
- package/lib/chevre/repo/mongoose/schemas/aggregation.js +8 -1
- package/lib/chevre/repo/mongoose/schemas/assetTransaction.js +95 -76
- package/lib/chevre/repo/mongoose/schemas/authorization.js +25 -18
- package/lib/chevre/repo/mongoose/schemas/event.js +7 -0
- package/lib/chevre/repo/mongoose/schemas/eventOffer.js +7 -0
- package/lib/chevre/repo/mongoose/schemas/message.js +8 -1
- package/lib/chevre/repo/mongoose/schemas/pendingReservation.js +11 -4
- package/lib/chevre/repo/mongoose/schemas/setting.d.ts +1 -0
- package/lib/chevre/repo/mongoose/schemas/task.d.ts +2 -5
- package/lib/chevre/repo/mongoose/schemas/task.js +134 -118
- package/lib/chevre/repo/mongoose/schemas/ticket.js +8 -1
- package/lib/chevre/repo/orderInTransaction.d.ts +0 -3
- package/lib/chevre/repo/orderInTransaction.js +30 -22
- package/lib/chevre/repo/scheduledTask.d.ts +5 -2
- package/lib/chevre/repo/scheduledTask.js +3 -25
- package/lib/chevre/repo/task.d.ts +45 -171
- package/lib/chevre/repo/task.js +20 -475
- package/lib/chevre/repo/taskDelayed.d.ts +74 -0
- package/lib/chevre/repo/taskDelayed.js +195 -0
- package/lib/chevre/repo/taskRunning.d.ts +35 -0
- package/lib/chevre/repo/taskRunning.js +89 -0
- package/lib/chevre/repo/ticket.d.ts +0 -6
- package/lib/chevre/repo/ticket.js +0 -11
- package/lib/chevre/repo/transaction.d.ts +1 -187
- package/lib/chevre/repo/transaction.js +2 -383
- package/lib/chevre/repository.d.ts +35 -5
- package/lib/chevre/repository.js +79 -13
- package/lib/chevre/service/aggregation/system.d.ts +17 -9
- package/lib/chevre/service/aggregation/system.js +46 -4
- package/lib/chevre/service/assetTransaction/cancelReservation/start.js +10 -17
- package/lib/chevre/service/assetTransaction/refund.js +2 -2
- package/lib/chevre/service/asyncAction.d.ts +2 -2
- package/lib/chevre/service/asyncAction.js +1 -4
- package/lib/chevre/service/asyncActionHandler/onOperationFailed.d.ts +2 -2
- package/lib/chevre/service/asyncActionHandler/onOperationFailed.js +0 -2
- package/lib/chevre/service/asyncActionHandler.d.ts +4 -4
- package/lib/chevre/service/asyncActionHandler.js +11 -13
- package/lib/chevre/service/event/processUpdateMovieTheater.d.ts +4 -2
- package/lib/chevre/service/event/processUpdateMovieTheater.js +3 -3
- package/lib/chevre/service/event.d.ts +4 -2
- package/lib/chevre/service/event.js +3 -3
- package/lib/chevre/service/notification/triggerWebhook.d.ts +4 -2
- package/lib/chevre/service/notification/triggerWebhook.js +5 -16
- package/lib/chevre/service/offer/event/voidTransaction/processVoidTransaction4chevre.js +1 -3
- package/lib/chevre/service/offer/eventServiceByCOA/findAcceptAction.d.ts +0 -4
- package/lib/chevre/service/offer/eventServiceByCOA/findAcceptAction.js +19 -19
- package/lib/chevre/service/offer/onEventChanged.js +0 -2
- package/lib/chevre/service/order/confirmPayTransaction.js +4 -1
- package/lib/chevre/service/order/deleteOrder.js +0 -1
- package/lib/chevre/service/order/onAssetTransactionStatusChanged/isDeliverable.js +1 -49
- package/lib/chevre/service/order/onAssetTransactionStatusChanged/onPayTransactionConfirmed.js +2 -2
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderDelivered/factory.js +2 -4
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderDeliveredPartially/factory.js +2 -4
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderInTransit.js +4 -4
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderPaymentDue.js +2 -2
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/createSendEmailMessageTaskIfNotExist.js +2 -2
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/factory.d.ts +2 -2
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/factory.js +3 -5
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/processOrder.js +2 -2
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing.js +1 -1
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderReturned/factory.js +5 -7
- package/lib/chevre/service/order/onOrderUpdated/factory.js +0 -3
- package/lib/chevre/service/order/returnOrder.d.ts +0 -2
- package/lib/chevre/service/order/returnOrder.js +8 -40
- package/lib/chevre/service/order/sendOrder.d.ts +0 -2
- package/lib/chevre/service/order/sendOrder.js +41 -55
- package/lib/chevre/service/payment/any/findAcceptAction.d.ts +0 -4
- package/lib/chevre/service/payment/any/findAcceptAction.js +19 -19
- package/lib/chevre/service/payment/any/findAuthorizeAction.d.ts +0 -4
- package/lib/chevre/service/payment/any/findAuthorizeAction.js +19 -19
- package/lib/chevre/service/payment/any/findCheckAction.d.ts +0 -4
- package/lib/chevre/service/payment/any/findCheckAction.js +19 -19
- package/lib/chevre/service/payment/any/processVoidPayTransaction.js +1 -1
- package/lib/chevre/service/payment/any/publishPaymentUrl.d.ts +0 -2
- package/lib/chevre/service/payment/any/publishPaymentUrl.js +2 -2
- package/lib/chevre/service/project.d.ts +0 -3
- package/lib/chevre/service/project.js +0 -1
- package/lib/chevre/service/reserve/cancelReservation.js +3 -3
- package/lib/chevre/service/reserve/checkInReservation.js +2 -2
- package/lib/chevre/service/reserve/confirmReservation.js +1 -1
- package/lib/chevre/service/reserve/potentialActions/onReservationConfirmed.js +2 -2
- package/lib/chevre/service/reserve/useReservation.js +1 -1
- package/lib/chevre/service/scheduledTask.d.ts +1 -4
- package/lib/chevre/service/scheduledTask.js +3 -10
- package/lib/chevre/service/scheduledTaskHandler/onOperationFailed.js +1 -2
- package/lib/chevre/service/scheduledTaskHandler.js +0 -13
- package/lib/chevre/service/task/acceptCOAOffer.js +1 -14
- package/lib/chevre/service/task/authorizePayment.js +1 -7
- package/lib/chevre/service/task/checkMovieTicket.js +1 -7
- package/lib/chevre/service/task/confirmReserveTransaction.js +3 -1
- package/lib/chevre/service/task/deleteTransaction.js +8 -39
- package/lib/chevre/service/task/importEventsFromCOA.js +4 -2
- package/lib/chevre/service/task/onAuthorizationCreated.js +2 -2
- package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByAggregateOffer.d.ts +4 -2
- package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByAggregateOffer.js +4 -4
- package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByEventSeries.d.ts +4 -2
- package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByEventSeries.js +4 -4
- package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByMovieTheater.d.ts +4 -2
- package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByMovieTheater.js +4 -4
- package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByOfferCatalog.d.ts +4 -2
- package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByOfferCatalog.js +4 -4
- package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByProduct.d.ts +4 -2
- package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByProduct.js +4 -4
- package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByRoom.d.ts +4 -2
- package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByRoom.js +4 -4
- package/lib/chevre/service/task/onResourceDeleted/deleteResourcesBySeller.d.ts +4 -2
- package/lib/chevre/service/task/onResourceDeleted/deleteResourcesBySeller.js +4 -4
- package/lib/chevre/service/task/onResourceDeleted.js +4 -3
- package/lib/chevre/service/task/onResourceUpdated/onAggregateOfferUpdated.js +0 -1
- package/lib/chevre/service/task/onResourceUpdated/onHasPOSUpdated.js +0 -1
- package/lib/chevre/service/task/onResourceUpdated/onOfferCatalogUpdated.js +0 -1
- package/lib/chevre/service/task/onResourceUpdated.js +0 -8
- package/lib/chevre/service/task/publishPaymentUrl.js +2 -13
- package/lib/chevre/service/task/returnOrder.js +2 -5
- package/lib/chevre/service/task/returnPayTransaction.js +2 -2
- package/lib/chevre/service/task/sendOrder.js +2 -2
- package/lib/chevre/service/task/syncResourcesFromCOA.js +31 -23
- package/lib/chevre/service/task/triggerWebhook.js +4 -2
- package/lib/chevre/service/task/voidReserveTransaction.js +5 -8
- package/lib/chevre/service/task.d.ts +3 -22
- package/lib/chevre/service/task.js +8 -40
- package/lib/chevre/service/taskHandler/onOperationFailed/informTaskIfNeeded.js +0 -1
- package/lib/chevre/service/taskHandler/onOperationFailed.d.ts +3 -2
- package/lib/chevre/service/taskHandler/onOperationFailed.js +5 -16
- package/lib/chevre/service/taskHandler.d.ts +1 -2
- package/lib/chevre/service/taskHandler.js +7 -19
- package/lib/chevre/service/transaction/deleteTransaction/deletePayTransactionsByPlaceOrder.js +2 -2
- package/lib/chevre/service/transaction/deleteTransaction/deleteReservationsByPlaceOrder.js +2 -2
- package/lib/chevre/service/transaction/deleteTransaction.d.ts +6 -2
- package/lib/chevre/service/transaction/deleteTransaction.js +5 -5
- package/lib/chevre/service/transaction/placeOrder/confirm.js +1 -1
- package/lib/chevre/service/transaction/placeOrder/exportTasks/factory.d.ts +8 -4
- package/lib/chevre/service/transaction/placeOrder/exportTasks/factory.js +55 -103
- package/lib/chevre/service/transaction/placeOrder/exportTasksById.d.ts +2 -0
- package/lib/chevre/service/transaction/placeOrder/exportTasksById.js +14 -10
- package/lib/chevre/service/transaction/returnOrder/exportTasks/factory.d.ts +13 -3
- package/lib/chevre/service/transaction/returnOrder/exportTasks/factory.js +48 -51
- package/lib/chevre/service/transaction/returnOrder.d.ts +2 -0
- package/lib/chevre/service/transaction/returnOrder.js +15 -13
- package/lib/chevre/service/transaction.d.ts +2 -0
- package/lib/chevre/service/transaction.js +0 -2
- package/lib/chevre/service/validation/validateOrder.js +2 -2
- package/lib/chevre/taskSettings.d.ts +4 -4
- package/package.json +2 -2
- package/lib/chevre/repo/mongoose/schemas/ownershipInfo.js +0 -227
- package/lib/chevre/repo/ownershipInfo.d.ts +0 -122
- package/lib/chevre/repo/ownershipInfo.js +0 -466
|
@@ -1,466 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OwnershipInfoRepo = void 0;
|
|
4
|
-
const uuid_1 = require("uuid");
|
|
5
|
-
const ownershipInfo_1 = require("./mongoose/schemas/ownershipInfo");
|
|
6
|
-
const errorHandler_1 = require("../errorHandler");
|
|
7
|
-
const factory_1 = require("../factory");
|
|
8
|
-
const settings_1 = require("../settings");
|
|
9
|
-
/**
|
|
10
|
-
* 所有権リポジトリ
|
|
11
|
-
*/
|
|
12
|
-
class OwnershipInfoRepo {
|
|
13
|
-
ownershipInfoModel;
|
|
14
|
-
constructor(connection) {
|
|
15
|
-
this.ownershipInfoModel = connection.model(ownershipInfo_1.modelName, (0, ownershipInfo_1.createSchema)());
|
|
16
|
-
}
|
|
17
|
-
static CREATE_MONGO_CONDITIONS(params) {
|
|
18
|
-
const andConditions = []; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
19
|
-
/* istanbul ignore else */
|
|
20
|
-
if (params.project !== undefined) {
|
|
21
|
-
if (params.project.id !== undefined && params.project.id !== null) {
|
|
22
|
-
if (typeof params.project.id.$eq === 'string') {
|
|
23
|
-
andConditions.push({
|
|
24
|
-
'project.id': {
|
|
25
|
-
$eq: params.project.id.$eq
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
const typeOfGoodIdentifierEq = params.typeOfGood?.identifier?.$eq;
|
|
32
|
-
if (typeof typeOfGoodIdentifierEq === 'string') {
|
|
33
|
-
andConditions.push({
|
|
34
|
-
'typeOfGood.identifier': {
|
|
35
|
-
$exists: true,
|
|
36
|
-
$eq: typeOfGoodIdentifierEq
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
const typeOfGoodIssuedThroughIdEq = params.typeOfGood?.issuedThrough?.id?.$eq;
|
|
41
|
-
if (typeof typeOfGoodIssuedThroughIdEq === 'string') {
|
|
42
|
-
andConditions.push({
|
|
43
|
-
'typeOfGood.issuedThrough.id': {
|
|
44
|
-
$exists: true,
|
|
45
|
-
$eq: typeOfGoodIssuedThroughIdEq
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
const typeOfGoodIssuedThroughTypeOfEq = params.typeOfGood?.issuedThrough?.typeOf?.$eq;
|
|
50
|
-
if (typeof typeOfGoodIssuedThroughTypeOfEq === 'string') {
|
|
51
|
-
andConditions.push({
|
|
52
|
-
'typeOfGood.issuedThrough.typeOf': {
|
|
53
|
-
$exists: true,
|
|
54
|
-
$eq: typeOfGoodIssuedThroughTypeOfEq
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
const typeOfGoodTypeOf = params.typeOfGood?.typeOf;
|
|
59
|
-
if (typeof typeOfGoodTypeOf === 'string') {
|
|
60
|
-
andConditions.push({
|
|
61
|
-
'typeOfGood.typeOf': {
|
|
62
|
-
$exists: true,
|
|
63
|
-
$eq: typeOfGoodTypeOf
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
const typeOfGoodTypeOfEq = typeOfGoodTypeOf?.$eq;
|
|
69
|
-
if (typeof typeOfGoodTypeOfEq === 'string') {
|
|
70
|
-
andConditions.push({
|
|
71
|
-
'typeOfGood.typeOf': {
|
|
72
|
-
$exists: true,
|
|
73
|
-
$eq: typeOfGoodTypeOfEq
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
const typeOfGoodTypeOfIn = typeOfGoodTypeOf?.$in;
|
|
78
|
-
if (Array.isArray(typeOfGoodTypeOfIn)) {
|
|
79
|
-
andConditions.push({
|
|
80
|
-
'typeOfGood.typeOf': {
|
|
81
|
-
$exists: true,
|
|
82
|
-
$in: typeOfGoodTypeOfIn
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
// 互換性維持対応
|
|
88
|
-
// if (params.typeOfGood === undefined || params.typeOfGood === null) {
|
|
89
|
-
// params.typeOfGood = {};
|
|
90
|
-
// }
|
|
91
|
-
// if (typeof (<any>params.typeOfGood).id === 'string') {
|
|
92
|
-
// params.typeOfGood.id = { $eq: (<any>params.typeOfGood).id };
|
|
93
|
-
// }
|
|
94
|
-
// if (Array.isArray((<any>params.typeOfGood).ids)) {
|
|
95
|
-
// params.typeOfGood.id = { $in: (<any>params.typeOfGood).ids };
|
|
96
|
-
// }
|
|
97
|
-
const typeOfGoodIdEq = params.typeOfGood?.id?.$eq;
|
|
98
|
-
if (typeof typeOfGoodIdEq === 'string') {
|
|
99
|
-
andConditions.push({
|
|
100
|
-
'typeOfGood.id': {
|
|
101
|
-
$exists: true,
|
|
102
|
-
$eq: typeOfGoodIdEq
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
const typeOfGoodIdIn = params.typeOfGood?.id?.$in;
|
|
107
|
-
if (Array.isArray(typeOfGoodIdIn)) {
|
|
108
|
-
andConditions.push({
|
|
109
|
-
'typeOfGood.id': {
|
|
110
|
-
$exists: true,
|
|
111
|
-
$in: typeOfGoodIdIn
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
/* istanbul ignore else */
|
|
116
|
-
if (Array.isArray(params.ids)) {
|
|
117
|
-
andConditions.push({
|
|
118
|
-
_id: { $in: params.ids }
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
/* istanbul ignore else */
|
|
122
|
-
if (Array.isArray(params.identifiers)) {
|
|
123
|
-
andConditions.push({
|
|
124
|
-
identifier: {
|
|
125
|
-
$exists: true,
|
|
126
|
-
$in: params.identifiers
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
const ownedByTypeOfEq = params.ownedBy?.typeOf?.$eq;
|
|
131
|
-
if (typeof ownedByTypeOfEq === 'string') {
|
|
132
|
-
andConditions.push({
|
|
133
|
-
'ownedBy.typeOf': {
|
|
134
|
-
$exists: true,
|
|
135
|
-
$eq: ownedByTypeOfEq
|
|
136
|
-
}
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
/* istanbul ignore else */
|
|
140
|
-
const ownedById = params.ownedBy?.id;
|
|
141
|
-
if (typeof ownedById === 'string') {
|
|
142
|
-
andConditions.push({
|
|
143
|
-
'ownedBy.id': {
|
|
144
|
-
$exists: true,
|
|
145
|
-
$eq: ownedById
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
else {
|
|
150
|
-
const ownedByIdIn = ownedById?.$in;
|
|
151
|
-
if (Array.isArray(ownedByIdIn)) {
|
|
152
|
-
andConditions.push({
|
|
153
|
-
'ownedBy.id': {
|
|
154
|
-
$exists: true,
|
|
155
|
-
$in: ownedByIdIn
|
|
156
|
-
}
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
// discontinue(2024-12-26~)
|
|
161
|
-
// const ownedByMembershipNumberIn = params.ownedBy?.memberOf?.membershipNumber?.$in;
|
|
162
|
-
// if (Array.isArray(ownedByMembershipNumberIn)) {
|
|
163
|
-
// andConditions.push({
|
|
164
|
-
// 'ownedBy.memberOf.membershipNumber': {
|
|
165
|
-
// $exists: true,
|
|
166
|
-
// $in: ownedByMembershipNumberIn
|
|
167
|
-
// }
|
|
168
|
-
// });
|
|
169
|
-
// }
|
|
170
|
-
/* istanbul ignore else */
|
|
171
|
-
if (params.ownedFrom instanceof Date) {
|
|
172
|
-
andConditions.push({
|
|
173
|
-
ownedThrough: { $gte: params.ownedFrom }
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
/* istanbul ignore else */
|
|
177
|
-
if (params.ownedThrough instanceof Date) {
|
|
178
|
-
andConditions.push({
|
|
179
|
-
ownedFrom: { $lte: params.ownedThrough }
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
const ownedFromGte = params.ownedFromGte;
|
|
183
|
-
if (ownedFromGte instanceof Date) {
|
|
184
|
-
andConditions.push({
|
|
185
|
-
ownedFrom: { $gte: ownedFromGte }
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
const ownedFromLte = params.ownedFromLte;
|
|
189
|
-
if (ownedFromLte instanceof Date) {
|
|
190
|
-
andConditions.push({
|
|
191
|
-
ownedFrom: { $lte: ownedFromLte }
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
const acquiredFromIdIn = params.acquiredFrom?.id?.$in;
|
|
195
|
-
if (Array.isArray(acquiredFromIdIn)) {
|
|
196
|
-
andConditions.push({
|
|
197
|
-
'acquiredFrom.id': {
|
|
198
|
-
$exists: true,
|
|
199
|
-
$in: acquiredFromIdIn
|
|
200
|
-
}
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
return andConditions;
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* なければ作成する
|
|
207
|
-
*/
|
|
208
|
-
async createIfNotExistByIdentifier(ownershipInfo) {
|
|
209
|
-
let doc;
|
|
210
|
-
let duplicate = false;
|
|
211
|
-
try {
|
|
212
|
-
doc = await this.ownershipInfoModel.findOneAndUpdate({ identifier: { $eq: ownershipInfo.identifier } }, {
|
|
213
|
-
// insert時以外は何もしなくてもよい
|
|
214
|
-
$setOnInsert: {
|
|
215
|
-
...ownershipInfo,
|
|
216
|
-
_id: (0, uuid_1.v4)() // 新規作成時は所有権ID発行
|
|
217
|
-
}
|
|
218
|
-
}, {
|
|
219
|
-
new: true,
|
|
220
|
-
upsert: true,
|
|
221
|
-
projection: {
|
|
222
|
-
_id: 0,
|
|
223
|
-
id: { $toString: '$_id' }
|
|
224
|
-
// __v: 0,
|
|
225
|
-
// createdAt: 0,
|
|
226
|
-
// updatedAt: 0
|
|
227
|
-
}
|
|
228
|
-
})
|
|
229
|
-
.lean()
|
|
230
|
-
.exec();
|
|
231
|
-
}
|
|
232
|
-
catch (error) {
|
|
233
|
-
if (await (0, errorHandler_1.isMongoDuplicateError)(error)) {
|
|
234
|
-
// すでに所有権が存在する場合ok
|
|
235
|
-
duplicate = true;
|
|
236
|
-
}
|
|
237
|
-
if (!duplicate) {
|
|
238
|
-
throw error;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
if (duplicate) {
|
|
242
|
-
// 重複の場合、再度取得
|
|
243
|
-
doc = await this.ownershipInfoModel.findOne({ identifier: { $eq: ownershipInfo.identifier } }, {
|
|
244
|
-
_id: 0,
|
|
245
|
-
id: { $toString: '$_id' }
|
|
246
|
-
// __v: 0,
|
|
247
|
-
// createdAt: 0,
|
|
248
|
-
// updatedAt: 0
|
|
249
|
-
})
|
|
250
|
-
.lean()
|
|
251
|
-
.exec();
|
|
252
|
-
}
|
|
253
|
-
if (doc === undefined || doc === null) {
|
|
254
|
-
throw new factory_1.factory.errors.NotFound(this.ownershipInfoModel.modelName);
|
|
255
|
-
}
|
|
256
|
-
return { id: doc.id };
|
|
257
|
-
}
|
|
258
|
-
async projectFieldsById(params, inclusion) {
|
|
259
|
-
let projection = {
|
|
260
|
-
_id: 0,
|
|
261
|
-
id: { $toString: '$_id' },
|
|
262
|
-
project: 1,
|
|
263
|
-
typeOf: 1,
|
|
264
|
-
identifier: 1,
|
|
265
|
-
ownedBy: 1,
|
|
266
|
-
acquiredFrom: 1,
|
|
267
|
-
ownedFrom: 1,
|
|
268
|
-
ownedThrough: 1,
|
|
269
|
-
typeOfGood: 1
|
|
270
|
-
};
|
|
271
|
-
const positiveProjectionFields = (Array.isArray(inclusion))
|
|
272
|
-
? inclusion.filter((key) => key !== 'id' && String(key) !== '_id')
|
|
273
|
-
: undefined;
|
|
274
|
-
if (Array.isArray(positiveProjectionFields)) {
|
|
275
|
-
projection = {
|
|
276
|
-
_id: 0,
|
|
277
|
-
id: { $toString: '$_id' },
|
|
278
|
-
...Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1])))
|
|
279
|
-
};
|
|
280
|
-
}
|
|
281
|
-
const doc = await this.ownershipInfoModel.findOne({ _id: { $eq: params.id } }, projection)
|
|
282
|
-
.lean() // lean(2024-08-15~)
|
|
283
|
-
.exec();
|
|
284
|
-
if (doc === null) {
|
|
285
|
-
throw new factory_1.factory.errors.NotFound(this.ownershipInfoModel.modelName);
|
|
286
|
-
}
|
|
287
|
-
return doc;
|
|
288
|
-
}
|
|
289
|
-
/**
|
|
290
|
-
* 所有権を検索する
|
|
291
|
-
*/
|
|
292
|
-
async projectFields(params, inclusion) {
|
|
293
|
-
const conditions = OwnershipInfoRepo.CREATE_MONGO_CONDITIONS(params);
|
|
294
|
-
let projection = {
|
|
295
|
-
_id: 0,
|
|
296
|
-
id: { $toString: '$_id' },
|
|
297
|
-
project: 1,
|
|
298
|
-
typeOf: 1,
|
|
299
|
-
identifier: 1,
|
|
300
|
-
ownedBy: 1,
|
|
301
|
-
acquiredFrom: 1,
|
|
302
|
-
ownedFrom: 1,
|
|
303
|
-
ownedThrough: 1,
|
|
304
|
-
typeOfGood: 1
|
|
305
|
-
};
|
|
306
|
-
const positiveProjectionFields = (Array.isArray(inclusion))
|
|
307
|
-
? inclusion.filter((key) => key !== 'id' && String(key) !== '_id')
|
|
308
|
-
: undefined;
|
|
309
|
-
if (Array.isArray(positiveProjectionFields)) {
|
|
310
|
-
projection = {
|
|
311
|
-
_id: 0,
|
|
312
|
-
id: { $toString: '$_id' },
|
|
313
|
-
...Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1])))
|
|
314
|
-
};
|
|
315
|
-
}
|
|
316
|
-
const query = this.ownershipInfoModel.find((conditions.length > 0) ? { $and: conditions } : {}, projection);
|
|
317
|
-
if (typeof params.limit === 'number' && params.limit > 0) {
|
|
318
|
-
const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
|
|
319
|
-
query.limit(params.limit)
|
|
320
|
-
.skip(params.limit * (page - 1));
|
|
321
|
-
}
|
|
322
|
-
/* istanbul ignore else */
|
|
323
|
-
if (params.sort?.ownedFrom !== undefined) {
|
|
324
|
-
query.sort({ ownedFrom: params.sort.ownedFrom });
|
|
325
|
-
}
|
|
326
|
-
return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
327
|
-
.lean() // lean(2024-08-19~)
|
|
328
|
-
.exec();
|
|
329
|
-
}
|
|
330
|
-
/**
|
|
331
|
-
* 識別子から所有期限を変更する
|
|
332
|
-
* 存在しない場合undefinedを返す
|
|
333
|
-
*/
|
|
334
|
-
async findByIdentifierAndUpdateOwnedThrough(params) {
|
|
335
|
-
return this.ownershipInfoModel.findOneAndUpdate({
|
|
336
|
-
'project.id': { $eq: params.project.id },
|
|
337
|
-
identifier: { $eq: String(params.identifier) }
|
|
338
|
-
}, { ownedThrough: params.ownedThrough }, {
|
|
339
|
-
new: true,
|
|
340
|
-
projection: {
|
|
341
|
-
_id: 0,
|
|
342
|
-
id: { $toString: '$_id' },
|
|
343
|
-
identifier: 1
|
|
344
|
-
}
|
|
345
|
-
})
|
|
346
|
-
.lean()
|
|
347
|
-
.exec()
|
|
348
|
-
.then((doc) => {
|
|
349
|
-
// 存在しない場合も正常にハンドルする
|
|
350
|
-
if (doc === null) {
|
|
351
|
-
return;
|
|
352
|
-
}
|
|
353
|
-
else {
|
|
354
|
-
return doc;
|
|
355
|
-
}
|
|
356
|
-
});
|
|
357
|
-
}
|
|
358
|
-
/**
|
|
359
|
-
* 所有者の所有権を全て削除する
|
|
360
|
-
*/
|
|
361
|
-
async deleteByOwnedById(params) {
|
|
362
|
-
return this.ownershipInfoModel.deleteMany({
|
|
363
|
-
'project.id': { $eq: params.project.id },
|
|
364
|
-
'ownedBy.id': { $exists: true, $eq: params.ownedBy.id }
|
|
365
|
-
})
|
|
366
|
-
.exec()
|
|
367
|
-
.then((deleteOneResult) => {
|
|
368
|
-
return {
|
|
369
|
-
// n: deleteOneResult?.n,
|
|
370
|
-
// ok: deleteOneResult?.ok,
|
|
371
|
-
deletedCount: deleteOneResult?.deletedCount
|
|
372
|
-
};
|
|
373
|
-
});
|
|
374
|
-
}
|
|
375
|
-
/**
|
|
376
|
-
* 特定所有者の特定所有権を削除する
|
|
377
|
-
*/
|
|
378
|
-
async deleteByIdAndOwnedById(params) {
|
|
379
|
-
return this.ownershipInfoModel.deleteOne({
|
|
380
|
-
_id: { $eq: params.id },
|
|
381
|
-
'project.id': { $eq: params.project.id },
|
|
382
|
-
'ownedBy.id': { $exists: true, $eq: params.ownedBy.id }
|
|
383
|
-
})
|
|
384
|
-
.exec()
|
|
385
|
-
.then((deleteOneResult) => {
|
|
386
|
-
return {
|
|
387
|
-
// n: deleteOneResult?.n,
|
|
388
|
-
// ok: deleteOneResult?.ok,
|
|
389
|
-
deletedCount: deleteOneResult?.deletedCount
|
|
390
|
-
};
|
|
391
|
-
});
|
|
392
|
-
}
|
|
393
|
-
/**
|
|
394
|
-
* 識別子から所有期限切れの所有権を削除する
|
|
395
|
-
*/
|
|
396
|
-
async deleteExpiredByIdentifiers(params) {
|
|
397
|
-
await this.ownershipInfoModel.deleteMany({
|
|
398
|
-
'project.id': { $eq: params.project.id },
|
|
399
|
-
identifier: { $in: params.identifiers },
|
|
400
|
-
// 所有期限切れのもの(ownedThroughは必ず存在する)
|
|
401
|
-
ownedThrough: { $lte: params.ownedThrough.$lte }
|
|
402
|
-
})
|
|
403
|
-
.exec();
|
|
404
|
-
}
|
|
405
|
-
/**
|
|
406
|
-
* 所有期限切れの所有権を削除する
|
|
407
|
-
*/
|
|
408
|
-
async deleteExpiredOwnershipInfos(params) {
|
|
409
|
-
await this.ownershipInfoModel.deleteMany({
|
|
410
|
-
// 所有期限切れのもの(ownedThroughは必ず存在する)
|
|
411
|
-
ownedThrough: { $lte: params.ownedThroughLte }
|
|
412
|
-
})
|
|
413
|
-
.exec();
|
|
414
|
-
}
|
|
415
|
-
getCursor(conditions, projection) {
|
|
416
|
-
return this.ownershipInfoModel.find(conditions, projection)
|
|
417
|
-
.sort({ ownedFrom: factory_1.factory.sortType.Ascending })
|
|
418
|
-
.cursor();
|
|
419
|
-
}
|
|
420
|
-
/**
|
|
421
|
-
* 所有者を追加する
|
|
422
|
-
*/
|
|
423
|
-
async addOwnerIfNotExist(params) {
|
|
424
|
-
if (typeof params.ownedBy.id !== 'string' || params.ownedBy.id.length === 0) {
|
|
425
|
-
throw new factory_1.factory.errors.ArgumentNull('ownedBy.id');
|
|
426
|
-
}
|
|
427
|
-
let newOwner;
|
|
428
|
-
if (params.ownedBy.typeOf === factory_1.factory.personType.Person) {
|
|
429
|
-
newOwner = {
|
|
430
|
-
id: params.ownedBy.id,
|
|
431
|
-
typeOf: params.ownedBy.typeOf
|
|
432
|
-
};
|
|
433
|
-
}
|
|
434
|
-
if (newOwner !== undefined) {
|
|
435
|
-
const doc = await this.ownershipInfoModel.findOneAndUpdate({ _id: { $eq: params.id } }, { $addToSet: { ownedBy: newOwner } }, {
|
|
436
|
-
new: true,
|
|
437
|
-
projection: { _id: 1 }
|
|
438
|
-
})
|
|
439
|
-
.exec();
|
|
440
|
-
if (doc === null) {
|
|
441
|
-
throw new factory_1.factory.errors.NotFound(this.ownershipInfoModel.modelName);
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
/**
|
|
446
|
-
* 所有者を削除する
|
|
447
|
-
*/
|
|
448
|
-
async removeOwnerIfExist(params) {
|
|
449
|
-
if (typeof params.ownedBy.id !== 'string' || params.ownedBy.id.length === 0) {
|
|
450
|
-
throw new factory_1.factory.errors.ArgumentNull('ownedBy.id');
|
|
451
|
-
}
|
|
452
|
-
const doc = await this.ownershipInfoModel.findOneAndUpdate({ _id: { $eq: params.id } }, { $pull: { ownedBy: { id: params.ownedBy.id } } }, {
|
|
453
|
-
new: true,
|
|
454
|
-
projection: { _id: 1 }
|
|
455
|
-
})
|
|
456
|
-
.exec();
|
|
457
|
-
if (doc === null) {
|
|
458
|
-
throw new factory_1.factory.errors.NotFound(this.ownershipInfoModel.modelName);
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
async unsetUnnecessaryFields(params) {
|
|
462
|
-
return this.ownershipInfoModel.updateMany(params.filter, { $unset: params.$unset }, { timestamps: false })
|
|
463
|
-
.exec();
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
exports.OwnershipInfoRepo = OwnershipInfoRepo;
|