@chevre/domain 20.2.0-alpha.39 → 20.2.0-alpha.40
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/findScreeningRoomsByBranchCode.ts +27 -0
- package/example/src/chevre/processReserve.ts +2 -0
- package/lib/chevre/repo/order.d.ts +3 -1
- package/lib/chevre/repo/order.js +30 -4
- package/lib/chevre/repo/place.d.ts +11 -0
- package/lib/chevre/repo/place.js +47 -8
- package/lib/chevre/service/aggregation/event/aggregateScreeningEvent.js +52 -36
- package/lib/chevre/service/delivery/factory.d.ts +1 -1
- package/lib/chevre/service/order/returnOrder.js +1 -1
- package/lib/chevre/service/order/sendOrder.js +4 -2
- package/lib/chevre/service/reserve/useReservation.js +5 -1
- package/lib/chevre/service/task/returnPayTransaction.js +5 -1
- package/package.json +1 -1
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
import * as mongoose from 'mongoose';
|
|
3
|
+
|
|
4
|
+
import { chevre } from '../../../lib/index';
|
|
5
|
+
|
|
6
|
+
async function main() {
|
|
7
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI);
|
|
8
|
+
|
|
9
|
+
const placeRepo = new chevre.repository.Place(mongoose.connection);
|
|
10
|
+
|
|
11
|
+
const event = await placeRepo.findScreeningRoomsByBranchCode({
|
|
12
|
+
branchCode: {
|
|
13
|
+
$eq: '20'
|
|
14
|
+
},
|
|
15
|
+
containedInPlace: {
|
|
16
|
+
id: {
|
|
17
|
+
$eq: '5bfb841d5a78d7948369979a'
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
console.log('room found', event);
|
|
22
|
+
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
main()
|
|
26
|
+
.then(console.log)
|
|
27
|
+
.catch(console.error);
|
|
@@ -41,7 +41,9 @@ export declare class MongoRepository {
|
|
|
41
41
|
*/
|
|
42
42
|
findByOrderNumber(params: {
|
|
43
43
|
orderNumber: string;
|
|
44
|
-
|
|
44
|
+
inclusion: string[];
|
|
45
|
+
exclusion: string[];
|
|
46
|
+
}): Promise<factory.order.IOrder>;
|
|
45
47
|
/**
|
|
46
48
|
* 注文番号で削除する
|
|
47
49
|
*/
|
package/lib/chevre/repo/order.js
CHANGED
|
@@ -693,7 +693,11 @@ class MongoRepository {
|
|
|
693
693
|
.exec();
|
|
694
694
|
// NotFoundであれば状態確認
|
|
695
695
|
if (doc === null) {
|
|
696
|
-
const order = yield this.findByOrderNumber(
|
|
696
|
+
const order = yield this.findByOrderNumber({
|
|
697
|
+
orderNumber: params.orderNumber,
|
|
698
|
+
inclusion: [],
|
|
699
|
+
exclusion: []
|
|
700
|
+
});
|
|
697
701
|
// tslint:disable-next-line:no-single-line-block-comment
|
|
698
702
|
/* istanbul ignore next */
|
|
699
703
|
if (order.orderStatus === params.orderStatus) {
|
|
@@ -732,7 +736,11 @@ class MongoRepository {
|
|
|
732
736
|
.exec();
|
|
733
737
|
// NotFoundであれば状態確認
|
|
734
738
|
if (doc === null) {
|
|
735
|
-
const order = yield this.findByOrderNumber(
|
|
739
|
+
const order = yield this.findByOrderNumber({
|
|
740
|
+
orderNumber: params.orderNumber,
|
|
741
|
+
inclusion: [],
|
|
742
|
+
exclusion: []
|
|
743
|
+
});
|
|
736
744
|
// tslint:disable-next-line:no-single-line-block-comment
|
|
737
745
|
/* istanbul ignore next */
|
|
738
746
|
if (order.orderStatus === factory.orderStatus.OrderReturned) {
|
|
@@ -769,9 +777,27 @@ class MongoRepository {
|
|
|
769
777
|
/**
|
|
770
778
|
* 注文番号から注文を取得する
|
|
771
779
|
*/
|
|
772
|
-
findByOrderNumber(params
|
|
780
|
+
findByOrderNumber(params) {
|
|
773
781
|
return __awaiter(this, void 0, void 0, function* () {
|
|
774
|
-
|
|
782
|
+
let projection = {};
|
|
783
|
+
if (Array.isArray(params.inclusion) && params.inclusion.length > 0) {
|
|
784
|
+
params.inclusion.forEach((field) => {
|
|
785
|
+
projection[field] = 1;
|
|
786
|
+
});
|
|
787
|
+
}
|
|
788
|
+
else {
|
|
789
|
+
projection = {
|
|
790
|
+
__v: 0,
|
|
791
|
+
createdAt: 0,
|
|
792
|
+
updatedAt: 0
|
|
793
|
+
};
|
|
794
|
+
if (Array.isArray(params.exclusion) && params.exclusion.length > 0) {
|
|
795
|
+
params.exclusion.forEach((field) => {
|
|
796
|
+
projection[field] = 0;
|
|
797
|
+
});
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
const doc = yield this.orderModel.findOne({ orderNumber: params.orderNumber }, projection)
|
|
775
801
|
.exec();
|
|
776
802
|
if (doc === null) {
|
|
777
803
|
throw new factory.errors.NotFound(this.orderModel.modelName);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Connection } from 'mongoose';
|
|
2
2
|
import * as factory from '../factory';
|
|
3
3
|
declare type IScreeningRoomSectionWithoutContainsPlace = Omit<factory.place.screeningRoomSection.IPlace, 'containsPlace'>;
|
|
4
|
+
export declare type IScreeningRoomFoundByBranchCode = Pick<factory.place.screeningRoom.IPlace, 'typeOf' | 'branchCode' | 'name' | 'containsPlace'>;
|
|
4
5
|
/**
|
|
5
6
|
* 施設リポジトリ
|
|
6
7
|
*/
|
|
@@ -79,6 +80,16 @@ export declare class MongoRepository {
|
|
|
79
80
|
};
|
|
80
81
|
}): Promise<void>;
|
|
81
82
|
searchScreeningRooms(searchConditions: factory.place.screeningRoom.ISearchConditions): Promise<Omit<factory.place.screeningRoom.IPlace, 'containsPlace'>[]>;
|
|
83
|
+
findScreeningRoomsByBranchCode(params: {
|
|
84
|
+
branchCode: {
|
|
85
|
+
$eq: string;
|
|
86
|
+
};
|
|
87
|
+
containedInPlace: {
|
|
88
|
+
id: {
|
|
89
|
+
$eq: string;
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
}): Promise<IScreeningRoomFoundByBranchCode>;
|
|
82
93
|
createSeat(seat: factory.place.seat.IPlace): Promise<void>;
|
|
83
94
|
updateSeat(seat: factory.place.seat.IPlace, $unset: any): Promise<void>;
|
|
84
95
|
searchSeats(params: factory.place.seat.ISearchConditions): Promise<factory.place.seat.IPlace[]>;
|
package/lib/chevre/repo/place.js
CHANGED
|
@@ -250,6 +250,10 @@ class MongoRepository {
|
|
|
250
250
|
typeOf: { $eq: factory.placeType.MovieTheater },
|
|
251
251
|
'project.id': { $eq: params.project.id },
|
|
252
252
|
branchCode: { $eq: params.branchCode }
|
|
253
|
+
}, {
|
|
254
|
+
__v: 0,
|
|
255
|
+
createdAt: 0,
|
|
256
|
+
updatedAt: 0
|
|
253
257
|
})
|
|
254
258
|
.exec()
|
|
255
259
|
.then((doc) => {
|
|
@@ -260,12 +264,6 @@ class MongoRepository {
|
|
|
260
264
|
});
|
|
261
265
|
});
|
|
262
266
|
}
|
|
263
|
-
// public async countMovieTheaters(params: factory.place.movieTheater.ISearchConditions): Promise<number> {
|
|
264
|
-
// const conditions = MongoRepository.CREATE_MOVIE_THEATER_MONGO_CONDITIONS(params);
|
|
265
|
-
// return this.placeModel.countDocuments((conditions.length > 0) ? { $and: conditions } : {})
|
|
266
|
-
// .setOptions({ maxTimeMS: 10000 })
|
|
267
|
-
// .exec();
|
|
268
|
-
// }
|
|
269
267
|
/**
|
|
270
268
|
* 施設検索
|
|
271
269
|
*/
|
|
@@ -533,7 +531,7 @@ class MongoRepository {
|
|
|
533
531
|
}
|
|
534
532
|
});
|
|
535
533
|
}
|
|
536
|
-
//
|
|
534
|
+
// ルームコード
|
|
537
535
|
const containedInPlaceBranchCodeEq = (_g = (_f = searchConditions.containedInPlace) === null || _f === void 0 ? void 0 : _f.branchCode) === null || _g === void 0 ? void 0 : _g.$eq;
|
|
538
536
|
if (typeof containedInPlaceBranchCodeEq === 'string') {
|
|
539
537
|
matchStages.push({
|
|
@@ -698,7 +696,7 @@ class MongoRepository {
|
|
|
698
696
|
}
|
|
699
697
|
}
|
|
700
698
|
}
|
|
701
|
-
//
|
|
699
|
+
// ルームコード
|
|
702
700
|
if (searchConditions.branchCode !== undefined) {
|
|
703
701
|
if (typeof searchConditions.branchCode.$eq === 'string') {
|
|
704
702
|
matchStages.push({
|
|
@@ -814,6 +812,47 @@ class MongoRepository {
|
|
|
814
812
|
return aggregate.exec();
|
|
815
813
|
});
|
|
816
814
|
}
|
|
815
|
+
findScreeningRoomsByBranchCode(params) {
|
|
816
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
817
|
+
const matchStages = [
|
|
818
|
+
{ $match: { typeOf: { $eq: factory.placeType.MovieTheater } } },
|
|
819
|
+
{
|
|
820
|
+
$match: { _id: { $eq: mongoose_1.Types.ObjectId(params.containedInPlace.id.$eq) } }
|
|
821
|
+
},
|
|
822
|
+
{
|
|
823
|
+
$match: { 'containsPlace.branchCode': { $exists: true, $eq: params.branchCode.$eq } }
|
|
824
|
+
}
|
|
825
|
+
];
|
|
826
|
+
const aggregate = this.placeModel.aggregate([
|
|
827
|
+
{ $unwind: '$containsPlace' },
|
|
828
|
+
...matchStages,
|
|
829
|
+
{
|
|
830
|
+
$project: {
|
|
831
|
+
_id: 0,
|
|
832
|
+
typeOf: '$containsPlace.typeOf',
|
|
833
|
+
branchCode: '$containsPlace.branchCode',
|
|
834
|
+
name: '$containsPlace.name',
|
|
835
|
+
// address: '$containsPlace.address',
|
|
836
|
+
// containedInPlace: {
|
|
837
|
+
// id: '$_id',
|
|
838
|
+
// typeOf: '$typeOf',
|
|
839
|
+
// branchCode: '$branchCode',
|
|
840
|
+
// name: '$name'
|
|
841
|
+
// },
|
|
842
|
+
// openSeatingAllowed: '$containsPlace.openSeatingAllowed',
|
|
843
|
+
// additionalProperty: '$containsPlace.additionalProperty',
|
|
844
|
+
containsPlace: '$containsPlace.containsPlace'
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
]);
|
|
848
|
+
const docs = yield aggregate.limit(1)
|
|
849
|
+
.exec();
|
|
850
|
+
if (docs.length < 1) {
|
|
851
|
+
throw new factory.errors.NotFound(factory.placeType.ScreeningRoom);
|
|
852
|
+
}
|
|
853
|
+
return docs[0];
|
|
854
|
+
});
|
|
855
|
+
}
|
|
817
856
|
createSeat(seat) {
|
|
818
857
|
var _a, _b;
|
|
819
858
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -63,22 +63,36 @@ function aggregateScreeningEvent(params) {
|
|
|
63
63
|
exports.aggregateScreeningEvent = aggregateScreeningEvent;
|
|
64
64
|
function aggregateByEvent(params) {
|
|
65
65
|
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
66
|
+
var _a;
|
|
66
67
|
const now = new Date();
|
|
67
68
|
// 集計対象イベント検索
|
|
68
69
|
let event = params.event;
|
|
69
|
-
//
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
return;
|
|
70
|
+
// 施設取得は冗長なので、ルーム検索に変更(2023-01-30~)
|
|
71
|
+
let movieTheaterId;
|
|
72
|
+
if (params.event.typeOf === factory.eventType.ScreeningEvent) {
|
|
73
|
+
movieTheaterId = params.event.superEvent.location.id;
|
|
74
74
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
// 基本的にありえないはずだが、万が一スクリーンが見つからなければcapacityは0のまま
|
|
78
|
-
// tslint:disable-next-line:no-console
|
|
79
|
-
console.error(new Error(`Screening room not found. branchCode: ${event.location.branchCode}`));
|
|
80
|
-
return;
|
|
75
|
+
else {
|
|
76
|
+
movieTheaterId = String((_a = params.event.offers) === null || _a === void 0 ? void 0 : _a.itemOffered.availableChannel.serviceLocation.containedInPlace.id);
|
|
81
77
|
}
|
|
78
|
+
const screeningRoom = yield repos.place.findScreeningRoomsByBranchCode({
|
|
79
|
+
branchCode: { $eq: event.location.branchCode },
|
|
80
|
+
containedInPlace: { id: { $eq: movieTheaterId } }
|
|
81
|
+
});
|
|
82
|
+
// 施設取得
|
|
83
|
+
// const movieTheater = await findLocation(params)(repos);
|
|
84
|
+
// // 万が一施設が存在しなければ処理終了
|
|
85
|
+
// if (movieTheater === undefined) {
|
|
86
|
+
// return;
|
|
87
|
+
// }
|
|
88
|
+
// const screeningRoom = <factory.place.screeningRoom.IPlace | undefined>
|
|
89
|
+
// movieTheater.containsPlace.find((p) => p.branchCode === event.location.branchCode);
|
|
90
|
+
// if (screeningRoom === undefined) {
|
|
91
|
+
// // 基本的にありえないはずだが、万が一スクリーンが見つからなければcapacityは0のまま
|
|
92
|
+
// // tslint:disable-next-line:no-console
|
|
93
|
+
// console.error(new Error(`Screening room not found. branchCode: ${event.location.branchCode}`));
|
|
94
|
+
// return;
|
|
95
|
+
// }
|
|
82
96
|
// 予約集計
|
|
83
97
|
const { maximumAttendeeCapacity, remainingAttendeeCapacity, aggregateReservation } = yield aggregateReservationByEvent({
|
|
84
98
|
aggregateDate: now,
|
|
@@ -115,31 +129,33 @@ exports.aggregateByEvent = aggregateByEvent;
|
|
|
115
129
|
* イベントロケーション取得
|
|
116
130
|
* NotFoundエラーをハンドリングする
|
|
117
131
|
*/
|
|
118
|
-
function findLocation(params
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
132
|
+
// function findLocation(params: {
|
|
133
|
+
// event: factory.event.screeningEvent.IEvent | factory.event.event.IEvent;
|
|
134
|
+
// }) {
|
|
135
|
+
// return async (repos: {
|
|
136
|
+
// place: PlaceRepo;
|
|
137
|
+
// }): Promise<factory.place.movieTheater.IPlace | undefined> => {
|
|
138
|
+
// let movieTheater: factory.place.movieTheater.IPlace | undefined;
|
|
139
|
+
// try {
|
|
140
|
+
// if (params.event.typeOf === factory.eventType.ScreeningEvent) {
|
|
141
|
+
// movieTheater = await repos.place.findById({ id: params.event.superEvent.location.id });
|
|
142
|
+
// } else {
|
|
143
|
+
// const movieTheaterId: string =
|
|
144
|
+
// String(params.event.offers?.itemOffered.availableChannel.serviceLocation.containedInPlace.id);
|
|
145
|
+
// movieTheater = await repos.place.findById({ id: movieTheaterId });
|
|
146
|
+
// }
|
|
147
|
+
// } catch (error) {
|
|
148
|
+
// let throwsError = true;
|
|
149
|
+
// if (error instanceof factory.errors.NotFound) {
|
|
150
|
+
// throwsError = false;
|
|
151
|
+
// }
|
|
152
|
+
// if (throwsError) {
|
|
153
|
+
// throw error;
|
|
154
|
+
// }
|
|
155
|
+
// }
|
|
156
|
+
// return movieTheater;
|
|
157
|
+
// };
|
|
158
|
+
// }
|
|
143
159
|
/**
|
|
144
160
|
* 集計後アクション
|
|
145
161
|
*/
|
|
@@ -4,5 +4,5 @@ export declare type IOwnershipInfo = factory.ownershipInfo.IOwnershipInfo<factor
|
|
|
4
4
|
* 注文から所有権を作成する
|
|
5
5
|
*/
|
|
6
6
|
export declare function createOwnershipInfosFromOrder(params: {
|
|
7
|
-
order: factory.order.IOrder
|
|
7
|
+
order: Pick<factory.order.IOrder, 'acceptedOffers' | 'orderDate' | 'project' | 'customer' | 'orderNumber' | 'seller'>;
|
|
8
8
|
}): IOwnershipInfo[];
|
|
@@ -21,7 +21,7 @@ function returnOrder(params) {
|
|
|
21
21
|
? params.object.dateReturned
|
|
22
22
|
: new Date();
|
|
23
23
|
const returner = params.agent;
|
|
24
|
-
let order = yield repos.order.findByOrderNumber({ orderNumber });
|
|
24
|
+
let order = yield repos.order.findByOrderNumber({ orderNumber, inclusion: [], exclusion: [] });
|
|
25
25
|
// プロジェクト条件検証
|
|
26
26
|
if (order.project.id !== params.project.id) {
|
|
27
27
|
throw new factory.errors.NotFound('Order');
|
|
@@ -31,7 +31,7 @@ function sendOrder(params) {
|
|
|
31
31
|
orderNumber
|
|
32
32
|
})({ transaction: repos.transaction });
|
|
33
33
|
// 注文取得
|
|
34
|
-
let order = yield repos.order.findByOrderNumber({ orderNumber });
|
|
34
|
+
let order = yield repos.order.findByOrderNumber({ orderNumber, inclusion: [], exclusion: [] });
|
|
35
35
|
// プロジェクト条件検証
|
|
36
36
|
if (order.project.id !== params.project.id) {
|
|
37
37
|
throw new factory.errors.NotFound('Order');
|
|
@@ -100,7 +100,9 @@ function sendOrder(params) {
|
|
|
100
100
|
let throwsError = true;
|
|
101
101
|
// すでにOrderReturnedだった場合、OrderDelivered->OrderReturnedの処理自体は成功しているので、後処理を続行する
|
|
102
102
|
const currentOrder = yield repos.order.findByOrderNumber({
|
|
103
|
-
orderNumber: params.object.orderNumber
|
|
103
|
+
orderNumber: params.object.orderNumber,
|
|
104
|
+
inclusion: ['orderStatus'],
|
|
105
|
+
exclusion: []
|
|
104
106
|
});
|
|
105
107
|
if ((currentOrder === null || currentOrder === void 0 ? void 0 : currentOrder.orderStatus) === factory.orderStatus.OrderReturned) {
|
|
106
108
|
throwsError = false;
|
|
@@ -27,7 +27,11 @@ function verifyToken4reservation(params) {
|
|
|
27
27
|
switch (payload.typeOf) {
|
|
28
28
|
case factory.order.OrderType.Order:
|
|
29
29
|
// 注文検索
|
|
30
|
-
const order = yield repos.order.findByOrderNumber({
|
|
30
|
+
const order = yield repos.order.findByOrderNumber({
|
|
31
|
+
orderNumber: payload.orderNumber,
|
|
32
|
+
inclusion: ['orderStatus', 'acceptedOffers'],
|
|
33
|
+
exclusion: []
|
|
34
|
+
});
|
|
31
35
|
// ステータス検証
|
|
32
36
|
switch (order.orderStatus) {
|
|
33
37
|
case factory.orderStatus.OrderDelivered:
|
|
@@ -64,7 +64,11 @@ function returnPayTransaction(params) {
|
|
|
64
64
|
if (typeof paymentServiceType !== 'string' || paymentServiceType.length === 0) {
|
|
65
65
|
throw new factory.errors.ArgumentNull('object.issuedThrough.typeOf');
|
|
66
66
|
}
|
|
67
|
-
const order = yield repos.order.findByOrderNumber({
|
|
67
|
+
const order = yield repos.order.findByOrderNumber({
|
|
68
|
+
orderNumber,
|
|
69
|
+
inclusion: ['seller', 'project', 'dateReturned'],
|
|
70
|
+
exclusion: []
|
|
71
|
+
});
|
|
68
72
|
const action = yield repos.action.start(refundActionAttributes);
|
|
69
73
|
let refundTransaction;
|
|
70
74
|
try {
|
package/package.json
CHANGED