@chevre/domain 21.4.0-alpha.15 → 21.4.0-alpha.16
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/migrateReservationProvider.ts +107 -0
- package/lib/chevre/repo/order.d.ts +3 -0
- package/lib/chevre/repo/order.js +5 -5
- package/lib/chevre/repo/reservation.d.ts +26 -1
- package/lib/chevre/repo/reservation.js +6 -1
- package/lib/chevre/service/reserve/verifyToken4reservation.d.ts +3 -0
- package/lib/chevre/service/reserve/verifyToken4reservation.js +2 -1
- package/package.json +1 -1
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
// import * as moment from 'moment';
|
|
3
|
+
import * as mongoose from 'mongoose';
|
|
4
|
+
|
|
5
|
+
import { chevre } from '../../../lib/index';
|
|
6
|
+
|
|
7
|
+
// const project = { id: String(process.env.PROJECT_ID) };
|
|
8
|
+
// const EXCLUDED_PROJECT_ID = process.env.EXCLUDED_PROJECT_ID;
|
|
9
|
+
|
|
10
|
+
// tslint:disable-next-line:max-func-body-length
|
|
11
|
+
async function main() {
|
|
12
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: true });
|
|
13
|
+
|
|
14
|
+
const reservationRepo = new chevre.repository.Reservation(mongoose.connection);
|
|
15
|
+
const placeRepo = new chevre.repository.Place(mongoose.connection);
|
|
16
|
+
|
|
17
|
+
const cursor = reservationRepo.getCursor(
|
|
18
|
+
{
|
|
19
|
+
typeOf: {
|
|
20
|
+
$in: [
|
|
21
|
+
chevre.factory.reservationType.EventReservation
|
|
22
|
+
]
|
|
23
|
+
}
|
|
24
|
+
// bookingTime: {
|
|
25
|
+
// $gte: moment('2023-06-09T00:00:00Z')
|
|
26
|
+
// .toDate()
|
|
27
|
+
// }
|
|
28
|
+
// organizer: { $exists: false }
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
_id: 1,
|
|
32
|
+
project: 1,
|
|
33
|
+
provider: 1,
|
|
34
|
+
bookingTime: 1,
|
|
35
|
+
reservationFor: 1
|
|
36
|
+
}
|
|
37
|
+
);
|
|
38
|
+
console.log('reservations found');
|
|
39
|
+
|
|
40
|
+
let i = 0;
|
|
41
|
+
let updateCount = 0;
|
|
42
|
+
await cursor.eachAsync(async (doc) => {
|
|
43
|
+
i += 1;
|
|
44
|
+
const reservation: Pick<
|
|
45
|
+
chevre.factory.reservation.IReservation<chevre.factory.reservationType.EventReservation>,
|
|
46
|
+
'id' | 'project' | 'provider' | 'bookingTime' | 'reservationFor'
|
|
47
|
+
> = doc.toObject();
|
|
48
|
+
|
|
49
|
+
const providerId = reservation.provider?.id;
|
|
50
|
+
const alreadyMigrated = typeof providerId === 'string';
|
|
51
|
+
|
|
52
|
+
if (alreadyMigrated) {
|
|
53
|
+
console.log('already exist...', reservation.project.id, reservation.id, reservation.bookingTime, providerId, i);
|
|
54
|
+
} else {
|
|
55
|
+
const movieTheaterId: string = reservation.reservationFor.superEvent.location.id;
|
|
56
|
+
const movieTheaterBranchCode: string = reservation.reservationFor.superEvent.location.branchCode;
|
|
57
|
+
const movieTheaters = <Pick<
|
|
58
|
+
chevre.factory.place.movieTheater.IPlaceWithoutScreeningRoom,
|
|
59
|
+
'parentOrganization' | 'branchCode'
|
|
60
|
+
>[]>
|
|
61
|
+
await placeRepo.searchMovieTheaters(
|
|
62
|
+
{
|
|
63
|
+
limit: 1,
|
|
64
|
+
page: 1,
|
|
65
|
+
project: { id: { $eq: reservation.project.id } },
|
|
66
|
+
id: { $eq: movieTheaterId }
|
|
67
|
+
},
|
|
68
|
+
['parentOrganization', 'branchCode'],
|
|
69
|
+
[]
|
|
70
|
+
);
|
|
71
|
+
const movieTheater = movieTheaters.shift();
|
|
72
|
+
const sellerId = movieTheater?.parentOrganization?.id;
|
|
73
|
+
console.log(
|
|
74
|
+
'movieTheater found',
|
|
75
|
+
reservation.project.id, reservation.id, reservation.bookingTime, providerId, 'sellerId:', sellerId,
|
|
76
|
+
'movieTheaterId:', movieTheaterId,
|
|
77
|
+
'movieTheaterBranchCode:', movieTheaterBranchCode,
|
|
78
|
+
i
|
|
79
|
+
);
|
|
80
|
+
if (typeof sellerId !== 'string') {
|
|
81
|
+
throw new Error('movieTheater not found');
|
|
82
|
+
}
|
|
83
|
+
if (typeof sellerId === 'string') {
|
|
84
|
+
const newProvider: chevre.factory.reservation.IProvider = {
|
|
85
|
+
id: sellerId,
|
|
86
|
+
typeOf: chevre.factory.organizationType.Corporation
|
|
87
|
+
};
|
|
88
|
+
console.log('updating reservation...', reservation.project.id, reservation.id, reservation.bookingTime, providerId, i);
|
|
89
|
+
await reservationRepo.updatePartiallyById({
|
|
90
|
+
id: reservation.id,
|
|
91
|
+
update: <any>{
|
|
92
|
+
provider: newProvider
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
updateCount += 1;
|
|
96
|
+
console.log('updated.', reservation.project.id, reservation.id, reservation.bookingTime, providerId, i);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
console.log(i, 'reservations checked');
|
|
102
|
+
console.log(updateCount, 'reservations updated');
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
main()
|
|
106
|
+
.then()
|
|
107
|
+
.catch(console.error);
|
|
@@ -77,6 +77,9 @@ export declare class MongoRepository {
|
|
|
77
77
|
findByOrderNumberAndReservationId(params: {
|
|
78
78
|
orderNumber: string;
|
|
79
79
|
reservationId: string;
|
|
80
|
+
seller?: {
|
|
81
|
+
id?: string;
|
|
82
|
+
};
|
|
80
83
|
}): Promise<Pick<factory.order.IOrder, 'orderNumber' | 'orderStatus' | 'typeOf'>>;
|
|
81
84
|
/**
|
|
82
85
|
* 注文番号で削除する
|
package/lib/chevre/repo/order.js
CHANGED
|
@@ -853,6 +853,7 @@ class MongoRepository {
|
|
|
853
853
|
});
|
|
854
854
|
}
|
|
855
855
|
findByOrderNumberAndReservationId(params) {
|
|
856
|
+
var _a;
|
|
856
857
|
return __awaiter(this, void 0, void 0, function* () {
|
|
857
858
|
const projection = {
|
|
858
859
|
orderStatus: 1,
|
|
@@ -860,15 +861,14 @@ class MongoRepository {
|
|
|
860
861
|
orderNumber: 1,
|
|
861
862
|
_id: 0
|
|
862
863
|
};
|
|
863
|
-
const doc = yield this.orderModel.findOne({
|
|
864
|
-
orderNumber: { $eq: params.orderNumber },
|
|
865
|
-
acceptedOffers: {
|
|
864
|
+
const doc = yield this.orderModel.findOne(Object.assign({ orderNumber: { $eq: params.orderNumber }, acceptedOffers: {
|
|
866
865
|
$elemMatch: {
|
|
867
866
|
'itemOffered.typeOf': { $in: [factory.reservationType.BusReservation, factory.reservationType.EventReservation] },
|
|
868
867
|
'itemOffered.id': { $eq: params.reservationId }
|
|
869
868
|
}
|
|
870
|
-
}
|
|
871
|
-
|
|
869
|
+
} }, (typeof ((_a = params.seller) === null || _a === void 0 ? void 0 : _a.id) === 'string')
|
|
870
|
+
? { 'seller.id': { $exists: true, $eq: params.seller.id } }
|
|
871
|
+
: undefined), projection)
|
|
872
872
|
.exec();
|
|
873
873
|
if (doc === null) {
|
|
874
874
|
throw new factory.errors.NotFound(this.orderModel.modelName);
|
|
@@ -1,3 +1,27 @@
|
|
|
1
|
+
/// <reference types="mongoose/types/aggregate" />
|
|
2
|
+
/// <reference types="mongoose/types/callback" />
|
|
3
|
+
/// <reference types="mongoose/types/collection" />
|
|
4
|
+
/// <reference types="mongoose/types/connection" />
|
|
5
|
+
/// <reference types="mongoose/types/cursor" />
|
|
6
|
+
/// <reference types="mongoose/types/document" />
|
|
7
|
+
/// <reference types="mongoose/types/error" />
|
|
8
|
+
/// <reference types="mongoose/types/expressions" />
|
|
9
|
+
/// <reference types="mongoose/types/helpers" />
|
|
10
|
+
/// <reference types="mongoose/types/middlewares" />
|
|
11
|
+
/// <reference types="mongoose/types/indexes" />
|
|
12
|
+
/// <reference types="mongoose/types/models" />
|
|
13
|
+
/// <reference types="mongoose/types/mongooseoptions" />
|
|
14
|
+
/// <reference types="mongoose/types/pipelinestage" />
|
|
15
|
+
/// <reference types="mongoose/types/populate" />
|
|
16
|
+
/// <reference types="mongoose/types/query" />
|
|
17
|
+
/// <reference types="mongoose/types/schemaoptions" />
|
|
18
|
+
/// <reference types="mongoose/types/schematypes" />
|
|
19
|
+
/// <reference types="mongoose/types/session" />
|
|
20
|
+
/// <reference types="mongoose/types/types" />
|
|
21
|
+
/// <reference types="mongoose/types/utility" />
|
|
22
|
+
/// <reference types="mongoose/types/validation" />
|
|
23
|
+
/// <reference types="mongoose/types/virtuals" />
|
|
24
|
+
/// <reference types="mongoose/types/inferschematype" />
|
|
1
25
|
import { BulkWriteResult as BulkWriteOpResultObject } from 'mongodb';
|
|
2
26
|
import { Connection, UpdateWriteOpResult } from 'mongoose';
|
|
3
27
|
import * as factory from '../factory';
|
|
@@ -91,7 +115,7 @@ export declare class MongoRepository {
|
|
|
91
115
|
updatePartiallyById(params: {
|
|
92
116
|
id: string;
|
|
93
117
|
update: IUpdatePartiallyParams;
|
|
94
|
-
}): Promise<factory.reservation.eventReservation.IReservation
|
|
118
|
+
}): Promise<Pick<factory.reservation.eventReservation.IReservation, 'id'>>;
|
|
95
119
|
deleteByIds(params: {
|
|
96
120
|
project: {
|
|
97
121
|
id: string;
|
|
@@ -119,4 +143,5 @@ export declare class MongoRepository {
|
|
|
119
143
|
};
|
|
120
144
|
}): Promise<string[]>;
|
|
121
145
|
deleteReservedTicketUnderName(): Promise<import("mongodb").UpdateResult>;
|
|
146
|
+
getCursor(conditions: any, projection: any): import("mongoose").Cursor<any, import("mongoose").QueryOptions<any>>;
|
|
122
147
|
}
|
|
@@ -1112,10 +1112,10 @@ class MongoRepository {
|
|
|
1112
1112
|
/**
|
|
1113
1113
|
* 予約部分更新
|
|
1114
1114
|
*/
|
|
1115
|
-
// public async findByIdAndUpdate(params: {
|
|
1116
1115
|
updatePartiallyById(params) {
|
|
1117
1116
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1118
1117
|
return this.reservationModel.findOneAndUpdate({ _id: { $eq: params.id } }, params.update, { new: true })
|
|
1118
|
+
.select({ _id: 1 })
|
|
1119
1119
|
.exec()
|
|
1120
1120
|
.then((doc) => {
|
|
1121
1121
|
if (doc === null) {
|
|
@@ -1185,5 +1185,10 @@ class MongoRepository {
|
|
|
1185
1185
|
.exec();
|
|
1186
1186
|
});
|
|
1187
1187
|
}
|
|
1188
|
+
getCursor(conditions, projection) {
|
|
1189
|
+
return this.reservationModel.find(conditions, projection)
|
|
1190
|
+
.sort({ bookingTime: factory.sortType.Descending })
|
|
1191
|
+
.cursor();
|
|
1192
|
+
}
|
|
1188
1193
|
}
|
|
1189
1194
|
exports.MongoRepository = MongoRepository;
|
|
@@ -27,7 +27,8 @@ function verifyToken4reservation(params) {
|
|
|
27
27
|
// reservationIdを含む注文の存在を確認するだけでよい(2023-01-31~)
|
|
28
28
|
const order = yield repos.order.findByOrderNumberAndReservationId({
|
|
29
29
|
orderNumber: payload.orderNumber,
|
|
30
|
-
reservationId: params.reservationId
|
|
30
|
+
reservationId: params.reservationId,
|
|
31
|
+
seller: params.seller
|
|
31
32
|
});
|
|
32
33
|
// ステータス検証
|
|
33
34
|
switch (order.orderStatus) {
|
package/package.json
CHANGED