@chevre/domain 22.2.0-alpha.4 → 22.2.0-alpha.5
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/{projectReservationFieldsById.ts → projectOwnershipInfoFieldsById.ts} +4 -4
- package/lib/chevre/repo/ownershipInfo.d.ts +5 -3
- package/lib/chevre/repo/ownershipInfo.js +37 -10
- package/lib/chevre/service/order/sendOrder.js +9 -5
- package/lib/chevre/service/task/onAuthorizationCreated.js +1 -1
- package/package.json +2 -2
package/example/src/chevre/{projectReservationFieldsById.ts → projectOwnershipInfoFieldsById.ts}
RENAMED
|
@@ -8,12 +8,12 @@ import { chevre } from '../../../lib/index';
|
|
|
8
8
|
async function main() {
|
|
9
9
|
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
10
10
|
|
|
11
|
-
const
|
|
12
|
-
const result = await
|
|
11
|
+
const ownershipInfoRepo = await chevre.repository.OwnershipInfo.createInstance(mongoose.connection);
|
|
12
|
+
const result = await ownershipInfoRepo.projectFieldsById(
|
|
13
13
|
{
|
|
14
|
-
id: '
|
|
15
|
-
inclusion: ['reservationStatus', 'reservationFor.id']
|
|
14
|
+
id: 'd9080760-1bdb-49cf-86eb-50f98fab0010'
|
|
16
15
|
}
|
|
16
|
+
// ['id', 'typeOfGood']
|
|
17
17
|
);
|
|
18
18
|
// tslint:disable-next-line:no-null-keyword
|
|
19
19
|
console.dir(result, { depth: null });
|
|
@@ -35,10 +35,12 @@ export declare class OwnershipInfoRepo {
|
|
|
35
35
|
/**
|
|
36
36
|
* なければ作成する
|
|
37
37
|
*/
|
|
38
|
-
createIfNotExistByIdentifier(ownershipInfo: IOwnershipInfo): Promise<
|
|
39
|
-
findById(params: {
|
|
38
|
+
createIfNotExistByIdentifier(ownershipInfo: IOwnershipInfo): Promise<{
|
|
40
39
|
id: string;
|
|
41
|
-
}
|
|
40
|
+
}>;
|
|
41
|
+
projectFieldsById(params: {
|
|
42
|
+
id: string;
|
|
43
|
+
}, inclusion?: (keyof IOwnershipInfo)[]): Promise<IOwnershipInfo>;
|
|
42
44
|
/**
|
|
43
45
|
* 所有権を検索する
|
|
44
46
|
*/
|
|
@@ -233,11 +233,14 @@ class OwnershipInfoRepo {
|
|
|
233
233
|
new: true,
|
|
234
234
|
upsert: true,
|
|
235
235
|
projection: {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
236
|
+
_id: 0,
|
|
237
|
+
id: { $toString: '$_id' }
|
|
238
|
+
// __v: 0,
|
|
239
|
+
// createdAt: 0,
|
|
240
|
+
// updatedAt: 0
|
|
239
241
|
}
|
|
240
242
|
})
|
|
243
|
+
.lean()
|
|
241
244
|
.exec();
|
|
242
245
|
}
|
|
243
246
|
catch (error) {
|
|
@@ -254,26 +257,50 @@ class OwnershipInfoRepo {
|
|
|
254
257
|
if (duplicate) {
|
|
255
258
|
// 重複の場合、再度取得
|
|
256
259
|
doc = yield this.ownershipInfoModel.findOne({ identifier: { $eq: ownershipInfo.identifier } }, {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
+
_id: 0,
|
|
261
|
+
id: { $toString: '$_id' }
|
|
262
|
+
// __v: 0,
|
|
263
|
+
// createdAt: 0,
|
|
264
|
+
// updatedAt: 0
|
|
260
265
|
})
|
|
266
|
+
.lean()
|
|
261
267
|
.exec();
|
|
262
268
|
}
|
|
263
269
|
if (doc === undefined || doc === null) {
|
|
264
270
|
throw new factory.errors.NotFound(this.ownershipInfoModel.modelName);
|
|
265
271
|
}
|
|
266
|
-
return doc.
|
|
272
|
+
return { id: doc.id };
|
|
273
|
+
// return <IOwnershipInfo>doc.toObject();
|
|
267
274
|
});
|
|
268
275
|
}
|
|
269
|
-
|
|
276
|
+
projectFieldsById(params, inclusion) {
|
|
270
277
|
return __awaiter(this, void 0, void 0, function* () {
|
|
271
|
-
|
|
278
|
+
let projection = {
|
|
279
|
+
_id: 0,
|
|
280
|
+
id: { $toString: '$_id' },
|
|
281
|
+
project: 1,
|
|
282
|
+
typeOf: 1,
|
|
283
|
+
identifier: 1,
|
|
284
|
+
ownedBy: 1,
|
|
285
|
+
acquiredFrom: 1,
|
|
286
|
+
ownedFrom: 1,
|
|
287
|
+
ownedThrough: 1,
|
|
288
|
+
typeOfGood: 1
|
|
289
|
+
};
|
|
290
|
+
const positiveProjectionFields = (Array.isArray(inclusion))
|
|
291
|
+
? inclusion.filter((key) => key !== 'id' && String(key) !== '_id')
|
|
292
|
+
: undefined;
|
|
293
|
+
if (Array.isArray(positiveProjectionFields)) {
|
|
294
|
+
projection = Object.assign({ _id: 0, id: { $toString: '$_id' } }, Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1]))));
|
|
295
|
+
}
|
|
296
|
+
const doc = yield this.ownershipInfoModel.findOne({ _id: { $eq: params.id } }, projection)
|
|
297
|
+
.lean() // lean(2024-08-15~)
|
|
272
298
|
.exec();
|
|
273
299
|
if (doc === null) {
|
|
274
300
|
throw new factory.errors.NotFound(this.ownershipInfoModel.modelName);
|
|
275
301
|
}
|
|
276
|
-
return doc
|
|
302
|
+
return doc;
|
|
303
|
+
// return doc.toObject();
|
|
277
304
|
});
|
|
278
305
|
}
|
|
279
306
|
/**
|
|
@@ -86,7 +86,8 @@ function sendOrder(params) {
|
|
|
86
86
|
typeOf: factory.actionType.SendAction
|
|
87
87
|
};
|
|
88
88
|
const action = yield repos.action.start(sendOrderActionAttributes);
|
|
89
|
-
let
|
|
89
|
+
let creatingOwnershipInfos = [];
|
|
90
|
+
let createdOwnershipInfos = [];
|
|
90
91
|
let allOffersDelivered = false;
|
|
91
92
|
let acceptedOffers;
|
|
92
93
|
// 所有権生成を最小化(2024-03-01~)
|
|
@@ -111,12 +112,15 @@ function sendOrder(params) {
|
|
|
111
112
|
debug('delivering...', order.orderNumber, acceptedOffers.map((offer) => `${offer.itemOffered.id}`), params.object.acceptedOffers, 'offerIndexBase:', offerIndexBase);
|
|
112
113
|
// 所有権作成
|
|
113
114
|
if (createOwnerships) {
|
|
114
|
-
|
|
115
|
+
creatingOwnershipInfos = (0, factory_1.createOwnershipInfosFromOrder)({
|
|
115
116
|
order: Object.assign(Object.assign({}, order), { acceptedOffers }),
|
|
116
117
|
offerIndexBase
|
|
117
118
|
});
|
|
118
|
-
|
|
119
|
-
|
|
119
|
+
createdOwnershipInfos = yield Promise.all(creatingOwnershipInfos.map((creatingOwnershipInfo) => __awaiter(this, void 0, void 0, function* () {
|
|
120
|
+
const { id } = yield repos.ownershipInfo.createIfNotExistByIdentifier(creatingOwnershipInfo);
|
|
121
|
+
return Object.assign({ id }, (typeof creatingOwnershipInfo.identifier === 'string')
|
|
122
|
+
? { identifier: creatingOwnershipInfo.identifier }
|
|
123
|
+
: undefined);
|
|
120
124
|
})));
|
|
121
125
|
}
|
|
122
126
|
// const deliveredCount = limit * page;
|
|
@@ -140,7 +144,7 @@ function sendOrder(params) {
|
|
|
140
144
|
}
|
|
141
145
|
throw error;
|
|
142
146
|
}
|
|
143
|
-
const result =
|
|
147
|
+
const result = createdOwnershipInfos;
|
|
144
148
|
yield repos.action.completeWithVoid({ typeOf: sendOrderActionAttributes.typeOf, id: action.id, result: result });
|
|
145
149
|
debug('allOffersDelivered?:', allOffersDelivered, order.orderNumber);
|
|
146
150
|
if (params.useOnOrderStatusChanged) {
|
|
@@ -70,7 +70,7 @@ function onAuthorizationCreated(params) {
|
|
|
70
70
|
// 所有権検索
|
|
71
71
|
const ownershipInfoId = authorization.object.id;
|
|
72
72
|
if (typeof ownershipInfoId === 'string' && ownershipInfoId.length > 0) {
|
|
73
|
-
const ownershipInfo = yield repos.ownershipInfo.
|
|
73
|
+
const ownershipInfo = yield repos.ownershipInfo.projectFieldsById({ id: ownershipInfoId }, ['typeOfGood']);
|
|
74
74
|
// 座席予約に対する所有権であれば発券
|
|
75
75
|
if (ownershipInfo.typeOfGood.typeOf === factory.reservationType.EventReservation
|
|
76
76
|
|| ownershipInfo.typeOfGood.typeOf === factory.reservationType.BusReservation) {
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
}
|
|
10
10
|
],
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@chevre/factory": "4.381.0-alpha.
|
|
12
|
+
"@chevre/factory": "4.381.0-alpha.5",
|
|
13
13
|
"@cinerino/sdk": "10.5.0-alpha.1",
|
|
14
14
|
"@motionpicture/coa-service": "9.4.0",
|
|
15
15
|
"@motionpicture/gmo-service": "5.3.0",
|
|
@@ -110,5 +110,5 @@
|
|
|
110
110
|
"postversion": "git push origin --tags",
|
|
111
111
|
"prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
|
|
112
112
|
},
|
|
113
|
-
"version": "22.2.0-alpha.
|
|
113
|
+
"version": "22.2.0-alpha.5"
|
|
114
114
|
}
|