@chevre/domain 22.1.0-alpha.9 → 22.1.0
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/attendIfNotAttended.ts +11 -2
- package/example/src/chevre/projectReservationFields.ts +31 -0
- package/example/src/chevre/projectReservationFieldsById.ts +24 -0
- package/example/src/chevre/unsetUnnecessaryFields.ts +46 -4
- package/lib/chevre/repo/accountingReport.d.ts +4 -0
- package/lib/chevre/repo/accountingReport.js +6 -0
- package/lib/chevre/repo/aggregateReservation.d.ts +4 -0
- package/lib/chevre/repo/aggregateReservation.js +6 -0
- package/lib/chevre/repo/mongoose/schemas/aggregateReservation.js +3 -0
- package/lib/chevre/repo/mongoose/schemas/project.js +3 -0
- package/lib/chevre/repo/mongoose/schemas/reservation.js +3 -0
- package/lib/chevre/repo/project.d.ts +4 -0
- package/lib/chevre/repo/project.js +6 -0
- package/lib/chevre/repo/reservation.d.ts +16 -9
- package/lib/chevre/repo/reservation.js +181 -64
- package/lib/chevre/service/assetTransaction/cancelReservation/factory.d.ts +3 -1
- package/lib/chevre/service/assetTransaction/cancelReservation.js +5 -2
- package/lib/chevre/service/reserve/cancelReservation.js +9 -7
- package/lib/chevre/service/reserve/confirmReservation.js +5 -2
- package/lib/chevre/service/reserve/findByCode.js +3 -3
- package/lib/chevre/service/reserve/potentialActions/onReservationCanceled.d.ts +3 -4
- package/lib/chevre/service/reserve/potentialActions/onReservationUsed.d.ts +2 -3
- package/lib/chevre/service/reserve/searchByOrder.js +1 -1
- package/lib/chevre/service/reserve/useReservation.js +3 -3
- package/lib/chevre/service/task/onAuthorizationCreated.js +5 -2
- package/lib/chevre/service/transaction/returnOrder/preStart.js +2 -2
- package/package.json +3 -3
- package/example/src/chevre/projectOrderFields.ts +0 -55
- package/example/src/chevre/projectOrderFieldsById.ts +0 -41
|
@@ -10,11 +10,20 @@ async function main() {
|
|
|
10
10
|
|
|
11
11
|
const reservation = await reservationRepo.attendIfNotAttended(
|
|
12
12
|
{
|
|
13
|
-
id: '
|
|
13
|
+
id: '948926445022844-0',
|
|
14
14
|
now: new Date()
|
|
15
15
|
}
|
|
16
16
|
);
|
|
17
|
-
console.log('
|
|
17
|
+
console.log('reservation found', reservation);
|
|
18
|
+
|
|
19
|
+
// await reservationRepo.cancel(
|
|
20
|
+
// {
|
|
21
|
+
// id: '948926445022844-0',
|
|
22
|
+
// previousReservationStatus: chevre.factory.reservationStatusType.ReservationConfirmed,
|
|
23
|
+
// modifiedTime: new Date()
|
|
24
|
+
// }
|
|
25
|
+
// );
|
|
26
|
+
// console.log('reservation canceled');
|
|
18
27
|
}
|
|
19
28
|
|
|
20
29
|
main()
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
import * as mongoose from 'mongoose';
|
|
3
|
+
|
|
4
|
+
import { chevre } from '../../../lib/index';
|
|
5
|
+
|
|
6
|
+
const project = { id: String(process.env.PROJECT_ID) };
|
|
7
|
+
|
|
8
|
+
async function main() {
|
|
9
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
10
|
+
|
|
11
|
+
const reservationRepo = await chevre.repository.Reservation.createInstance(mongoose.connection);
|
|
12
|
+
|
|
13
|
+
const reservations = await reservationRepo.projectFields<chevre.factory.reservationType.EventReservation>(
|
|
14
|
+
{
|
|
15
|
+
limit: 1,
|
|
16
|
+
page: 1,
|
|
17
|
+
typeOf: chevre.factory.reservationType.EventReservation,
|
|
18
|
+
project: { id: { $eq: project.id } }
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
id: 1
|
|
22
|
+
}
|
|
23
|
+
);
|
|
24
|
+
// tslint:disable-next-line:no-null-keyword
|
|
25
|
+
console.dir(reservations, { depth: null });
|
|
26
|
+
console.log(reservations.length, 'reservations found');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
main()
|
|
30
|
+
.then()
|
|
31
|
+
.catch(console.error);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
import * as mongoose from 'mongoose';
|
|
3
|
+
|
|
4
|
+
import { chevre } from '../../../lib/index';
|
|
5
|
+
|
|
6
|
+
// const project = { id: String(process.env.PROJECT_ID) };
|
|
7
|
+
|
|
8
|
+
async function main() {
|
|
9
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
10
|
+
|
|
11
|
+
const reservationRepo = await chevre.repository.Reservation.createInstance(mongoose.connection);
|
|
12
|
+
const result = await reservationRepo.projectFieldsById(
|
|
13
|
+
{
|
|
14
|
+
id: '948926445022844-0',
|
|
15
|
+
inclusion: ['reservationStatus', 'reservationFor.id']
|
|
16
|
+
}
|
|
17
|
+
);
|
|
18
|
+
// tslint:disable-next-line:no-null-keyword
|
|
19
|
+
console.dir(result, { depth: null });
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
main()
|
|
23
|
+
.then(console.log)
|
|
24
|
+
.catch(console.error);
|
|
@@ -6,11 +6,51 @@ import { chevre } from '../../../lib/index';
|
|
|
6
6
|
async function main() {
|
|
7
7
|
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
8
8
|
|
|
9
|
-
const
|
|
9
|
+
const accountingReportRepo = await chevre.repository.AccountingReport.createInstance(mongoose.connection);
|
|
10
|
+
const aggregateReservationRepo = await chevre.repository.AggregateReservation.createInstance(mongoose.connection);
|
|
11
|
+
const reservationRepo = await chevre.repository.Reservation.createInstance(mongoose.connection);
|
|
12
|
+
const projectRepo = await chevre.repository.Project.createInstance(mongoose.connection);
|
|
10
13
|
|
|
11
|
-
|
|
14
|
+
let updateResult: any;
|
|
15
|
+
updateResult = await accountingReportRepo.unsetUnnecessaryFields({
|
|
12
16
|
filter: {
|
|
13
|
-
|
|
17
|
+
_id: { $exists: true }
|
|
18
|
+
},
|
|
19
|
+
$unset: {
|
|
20
|
+
createdAt: 1,
|
|
21
|
+
updatedAt: 1,
|
|
22
|
+
__v: 1
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
console.log(updateResult);
|
|
26
|
+
|
|
27
|
+
updateResult = await aggregateReservationRepo.unsetUnnecessaryFields({
|
|
28
|
+
filter: {
|
|
29
|
+
_id: { $exists: true }
|
|
30
|
+
},
|
|
31
|
+
$unset: {
|
|
32
|
+
createdAt: 1,
|
|
33
|
+
updatedAt: 1,
|
|
34
|
+
__v: 1
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
console.log(updateResult);
|
|
38
|
+
|
|
39
|
+
updateResult = await projectRepo.unsetUnnecessaryFields({
|
|
40
|
+
filter: {
|
|
41
|
+
_id: { $exists: true }
|
|
42
|
+
},
|
|
43
|
+
$unset: {
|
|
44
|
+
createdAt: 1,
|
|
45
|
+
updatedAt: 1,
|
|
46
|
+
__v: 1
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
console.log(updateResult);
|
|
50
|
+
|
|
51
|
+
updateResult = await reservationRepo.unsetUnnecessaryFields({
|
|
52
|
+
filter: {
|
|
53
|
+
_id: { $exists: true }
|
|
14
54
|
},
|
|
15
55
|
$unset: {
|
|
16
56
|
createdAt: 1,
|
|
@@ -22,5 +62,7 @@ async function main() {
|
|
|
22
62
|
}
|
|
23
63
|
|
|
24
64
|
main()
|
|
25
|
-
.then()
|
|
65
|
+
.then(() => {
|
|
66
|
+
console.log('success!');
|
|
67
|
+
})
|
|
26
68
|
.catch(console.error);
|
|
@@ -203,5 +203,11 @@ class AccountingReportRepo {
|
|
|
203
203
|
.exec();
|
|
204
204
|
});
|
|
205
205
|
}
|
|
206
|
+
unsetUnnecessaryFields(params) {
|
|
207
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
208
|
+
return this.accountingReportModel.updateMany(params.filter, { $unset: params.$unset }, { timestamps: false })
|
|
209
|
+
.exec();
|
|
210
|
+
});
|
|
211
|
+
}
|
|
206
212
|
}
|
|
207
213
|
exports.AccountingReportRepo = AccountingReportRepo;
|
|
@@ -64,5 +64,9 @@ export declare class AggregateReservationRepo {
|
|
|
64
64
|
* 予約集計を保管する
|
|
65
65
|
*/
|
|
66
66
|
save(filter: Pick<IAggregateReservation, 'project' | 'reservationFor'>, update: IUpdateAggregateReservationParams): Promise<void>;
|
|
67
|
+
unsetUnnecessaryFields(params: {
|
|
68
|
+
filter: any;
|
|
69
|
+
$unset: any;
|
|
70
|
+
}): Promise<import("mongodb").UpdateResult>;
|
|
67
71
|
}
|
|
68
72
|
export {};
|
|
@@ -141,5 +141,11 @@ class AggregateReservationRepo {
|
|
|
141
141
|
}
|
|
142
142
|
});
|
|
143
143
|
}
|
|
144
|
+
unsetUnnecessaryFields(params) {
|
|
145
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
146
|
+
return this.aggregateReservationModel.updateMany(params.filter, { $unset: params.$unset }, { timestamps: false })
|
|
147
|
+
.exec();
|
|
148
|
+
});
|
|
149
|
+
}
|
|
144
150
|
}
|
|
145
151
|
exports.AggregateReservationRepo = AggregateReservationRepo;
|
|
@@ -12,6 +12,9 @@ const schemaDefinition = {
|
|
|
12
12
|
reservationFor: { type: mongoose_1.SchemaTypes.Mixed, required: true },
|
|
13
13
|
aggregateEntranceGate: mongoose_1.SchemaTypes.Mixed,
|
|
14
14
|
aggregateOffer: mongoose_1.SchemaTypes.Mixed
|
|
15
|
+
// createdAt: SchemaTypes.Mixed,
|
|
16
|
+
// updatedAt: SchemaTypes.Mixed,
|
|
17
|
+
// __v: SchemaTypes.Mixed
|
|
15
18
|
};
|
|
16
19
|
const schemaOptions = {
|
|
17
20
|
autoIndex: settings_1.MONGO_AUTO_INDEX,
|
|
@@ -50,6 +50,9 @@ const schemaDefinition = {
|
|
|
50
50
|
attended: { type: Boolean, default: false },
|
|
51
51
|
additionalProperty: mongoose_1.SchemaTypes.Mixed,
|
|
52
52
|
issuedThrough: mongoose_1.SchemaTypes.Mixed
|
|
53
|
+
// createdAt: SchemaTypes.Mixed,
|
|
54
|
+
// updatedAt: SchemaTypes.Mixed,
|
|
55
|
+
// __v: SchemaTypes.Mixed
|
|
53
56
|
};
|
|
54
57
|
const schemaOptions = {
|
|
55
58
|
autoIndex: settings_1.MONGO_AUTO_INDEX,
|
|
@@ -69,5 +69,9 @@ export declare class ProjectRepo {
|
|
|
69
69
|
id: string;
|
|
70
70
|
}): Promise<void>;
|
|
71
71
|
getCursor(conditions: FilterQuery<factory.project.IProject>, projection: any): import("mongoose").Cursor<any, import("mongoose").QueryOptions<any>>;
|
|
72
|
+
unsetUnnecessaryFields(params: {
|
|
73
|
+
filter: any;
|
|
74
|
+
$unset: any;
|
|
75
|
+
}): Promise<import("mongodb").UpdateResult>;
|
|
72
76
|
}
|
|
73
77
|
export {};
|
|
@@ -164,5 +164,11 @@ class ProjectRepo {
|
|
|
164
164
|
.sort({ _id: factory.sortType.Ascending })
|
|
165
165
|
.cursor();
|
|
166
166
|
}
|
|
167
|
+
unsetUnnecessaryFields(params) {
|
|
168
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
169
|
+
return this.projectModel.updateMany(params.filter, { $unset: params.$unset }, { timestamps: false })
|
|
170
|
+
.exec();
|
|
171
|
+
});
|
|
172
|
+
}
|
|
167
173
|
}
|
|
168
174
|
exports.ProjectRepo = ProjectRepo;
|
|
@@ -34,7 +34,11 @@ export type ICreatingReservation<T extends factory.reservationType> = T extends
|
|
|
34
34
|
} : T extends factory.reservationType.EventReservation ? (factory.reservation.eventReservation.IReservation) & {
|
|
35
35
|
_id: string;
|
|
36
36
|
} : never;
|
|
37
|
-
type IKeyOfProjection = keyof factory.reservation.IReservation<factory.reservationType.BusReservation | factory.reservationType.EventReservation> | '
|
|
37
|
+
type IKeyOfProjection = keyof factory.reservation.IReservation<factory.reservationType.BusReservation | factory.reservationType.EventReservation> | 'reservedTicket.dateUsed' | 'reservationFor.id' | 'reservationFor.typeOf';
|
|
38
|
+
export type IAttendedReservation = Pick<factory.reservation.IReservation<factory.reservationType.EventReservation>, 'id' | 'typeOf' | 'project' | 'modifiedTime'> & {
|
|
39
|
+
reservationFor: Pick<factory.reservation.IReservationFor<factory.reservationType.EventReservation>, 'id' | 'typeOf'>;
|
|
40
|
+
reservedTicket: Pick<factory.reservation.ITicket, 'dateUsed'>;
|
|
41
|
+
};
|
|
38
42
|
/**
|
|
39
43
|
* 予約リポジトリ
|
|
40
44
|
*/
|
|
@@ -48,14 +52,14 @@ export declare class ReservationRepo {
|
|
|
48
52
|
count<T extends factory.reservationType>(params: factory.reservation.ISearchConditions<T>): Promise<number>;
|
|
49
53
|
/**
|
|
50
54
|
* 予約検索
|
|
55
|
+
* migrate from search(2024-08-08~)
|
|
51
56
|
*/
|
|
52
|
-
|
|
53
|
-
[key in IKeyOfProjection]?:
|
|
57
|
+
projectFields<T extends factory.reservationType>(params: factory.reservation.ISearchConditions<T>, inclusion?: {
|
|
58
|
+
[key in IKeyOfProjection]?: 1;
|
|
54
59
|
}): Promise<factory.reservation.IReservation<factory.reservationType.EventReservation>[]>;
|
|
55
|
-
|
|
60
|
+
projectFieldsById<T extends factory.reservationType>(params: {
|
|
56
61
|
id: string;
|
|
57
62
|
inclusion?: IKeyOfProjection[];
|
|
58
|
-
exclusion?: IKeyOfProjection[];
|
|
59
63
|
}): Promise<factory.reservation.IReservation<T>>;
|
|
60
64
|
confirmManyIfNotExist(params: {
|
|
61
65
|
bookingTime: Date;
|
|
@@ -73,11 +77,11 @@ export declare class ReservationRepo {
|
|
|
73
77
|
/**
|
|
74
78
|
* 予約取消
|
|
75
79
|
*/
|
|
76
|
-
|
|
80
|
+
cancelById<T extends factory.reservationType>(params: {
|
|
77
81
|
id: string;
|
|
78
82
|
previousReservationStatus?: factory.reservationStatusType;
|
|
79
83
|
modifiedTime: Date;
|
|
80
|
-
}): Promise<
|
|
84
|
+
}): Promise<void>;
|
|
81
85
|
/**
|
|
82
86
|
* 予約取消
|
|
83
87
|
*/
|
|
@@ -113,7 +117,7 @@ export declare class ReservationRepo {
|
|
|
113
117
|
* modifiedTime
|
|
114
118
|
*/
|
|
115
119
|
now: Date;
|
|
116
|
-
}): Promise<
|
|
120
|
+
}): Promise<IAttendedReservation>;
|
|
117
121
|
/**
|
|
118
122
|
* 予約部分更新
|
|
119
123
|
*/
|
|
@@ -147,7 +151,10 @@ export declare class ReservationRepo {
|
|
|
147
151
|
$in: string[];
|
|
148
152
|
};
|
|
149
153
|
}): Promise<string[]>;
|
|
150
|
-
deleteReservedTicketUnderName(): Promise<import("mongodb").UpdateResult>;
|
|
151
154
|
getCursor(conditions: any, projection: any): import("mongoose").Cursor<any, import("mongoose").QueryOptions<any>>;
|
|
155
|
+
unsetUnnecessaryFields(params: {
|
|
156
|
+
filter: any;
|
|
157
|
+
$unset: any;
|
|
158
|
+
}): Promise<import("mongodb").UpdateResult>;
|
|
152
159
|
}
|
|
153
160
|
export {};
|
|
@@ -805,18 +805,54 @@ class ReservationRepo {
|
|
|
805
805
|
}
|
|
806
806
|
/**
|
|
807
807
|
* 予約検索
|
|
808
|
+
* migrate from search(2024-08-08~)
|
|
808
809
|
*/
|
|
809
|
-
|
|
810
|
+
projectFields(params, inclusion) {
|
|
810
811
|
var _a;
|
|
811
812
|
return __awaiter(this, void 0, void 0, function* () {
|
|
812
813
|
const conditions = ReservationRepo.CREATE_MONGO_CONDITIONS(params);
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
814
|
+
let projection = {};
|
|
815
|
+
if (inclusion !== undefined && inclusion !== null) {
|
|
816
|
+
projection = {
|
|
817
|
+
_id: 0,
|
|
818
|
+
id: { $toString: '$_id' }
|
|
819
|
+
};
|
|
820
|
+
for (const [field, value] of Object.entries(inclusion)) {
|
|
821
|
+
// 厳密に1を指定されたフィールドのみprojectionに追加
|
|
822
|
+
if (value === 1 && field !== '_id' && field !== 'id') {
|
|
823
|
+
projection[field] = 1;
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
else {
|
|
828
|
+
projection = {
|
|
829
|
+
_id: 0,
|
|
830
|
+
id: { $toString: '$_id' },
|
|
831
|
+
project: 1,
|
|
832
|
+
provider: 1,
|
|
833
|
+
typeOf: 1,
|
|
834
|
+
additionalTicketText: 1,
|
|
835
|
+
bookingTime: 1,
|
|
836
|
+
broker: 1,
|
|
837
|
+
modifiedTime: 1,
|
|
838
|
+
numSeats: 1,
|
|
839
|
+
previousReservationStatus: 1,
|
|
840
|
+
price: 1,
|
|
841
|
+
priceCurrency: 1,
|
|
842
|
+
programMembershipUsed: 1,
|
|
843
|
+
reservationFor: 1,
|
|
844
|
+
reservationNumber: 1,
|
|
845
|
+
reservationStatus: 1,
|
|
846
|
+
reservedTicket: 1,
|
|
847
|
+
subReservation: 1,
|
|
848
|
+
underName: 1,
|
|
849
|
+
checkedIn: 1,
|
|
850
|
+
attended: 1,
|
|
851
|
+
additionalProperty: 1,
|
|
852
|
+
issuedThrough: 1
|
|
853
|
+
};
|
|
854
|
+
}
|
|
855
|
+
const query = this.reservationModel.find((conditions.length > 0) ? { $and: conditions } : {}, projection);
|
|
820
856
|
if (typeof params.limit === 'number' && params.limit > 0) {
|
|
821
857
|
const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
|
|
822
858
|
query.limit(params.limit)
|
|
@@ -824,40 +860,90 @@ class ReservationRepo {
|
|
|
824
860
|
}
|
|
825
861
|
// tslint:disable-next-line:no-single-line-block-comment
|
|
826
862
|
/* istanbul ignore else */
|
|
827
|
-
if (((_a = params.sort) === null || _a === void 0 ? void 0 : _a.
|
|
828
|
-
query.sort({
|
|
863
|
+
if (((_a = params.sort) === null || _a === void 0 ? void 0 : _a.bookingTime) !== undefined) {
|
|
864
|
+
query.sort({ bookingTime: params.sort.bookingTime });
|
|
829
865
|
}
|
|
830
866
|
return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
831
|
-
.
|
|
832
|
-
.
|
|
867
|
+
.lean()
|
|
868
|
+
.exec();
|
|
833
869
|
});
|
|
834
870
|
}
|
|
835
|
-
|
|
871
|
+
// public async search<T extends factory.reservationType>(
|
|
872
|
+
// params: factory.reservation.ISearchConditions<T>,
|
|
873
|
+
// projection?: { [key in IKeyOfProjection]?: 0 | 1 }
|
|
874
|
+
// ): Promise<factory.reservation.IReservation<factory.reservationType.EventReservation>[]> {
|
|
875
|
+
// const conditions = ReservationRepo.CREATE_MONGO_CONDITIONS(params);
|
|
876
|
+
// const query = this.reservationModel.find(
|
|
877
|
+
// (conditions.length > 0) ? { $and: conditions } : {},
|
|
878
|
+
// (projection !== undefined && projection !== null)
|
|
879
|
+
// ? projection
|
|
880
|
+
// : {
|
|
881
|
+
// __v: 0,
|
|
882
|
+
// createdAt: 0,
|
|
883
|
+
// updatedAt: 0
|
|
884
|
+
// }
|
|
885
|
+
// );
|
|
886
|
+
// if (typeof params.limit === 'number' && params.limit > 0) {
|
|
887
|
+
// const page: number = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
|
|
888
|
+
// query.limit(params.limit)
|
|
889
|
+
// .skip(params.limit * (page - 1));
|
|
890
|
+
// }
|
|
891
|
+
// // tslint:disable-next-line:no-single-line-block-comment
|
|
892
|
+
// /* istanbul ignore else */
|
|
893
|
+
// if (params.sort?.modifiedTime !== undefined) {
|
|
894
|
+
// query.sort({ modifiedTime: params.sort.modifiedTime });
|
|
895
|
+
// }
|
|
896
|
+
// return query.setOptions({ maxTimeMS: MONGO_MAX_TIME_MS })
|
|
897
|
+
// .exec()
|
|
898
|
+
// .then((docs) => docs.map((doc) => doc.toObject()));
|
|
899
|
+
// }
|
|
900
|
+
projectFieldsById(params) {
|
|
836
901
|
return __awaiter(this, void 0, void 0, function* () {
|
|
902
|
+
let useInclusionProjection = false;
|
|
837
903
|
let projection = {};
|
|
838
904
|
if (Array.isArray(params.inclusion) && params.inclusion.length > 0) {
|
|
905
|
+
useInclusionProjection = true;
|
|
906
|
+
projection = {
|
|
907
|
+
_id: 0,
|
|
908
|
+
id: { $toString: '$_id' }
|
|
909
|
+
};
|
|
839
910
|
params.inclusion.forEach((field) => {
|
|
840
|
-
|
|
911
|
+
if (String(field) !== '_id' && field !== 'id') {
|
|
912
|
+
projection[field] = 1;
|
|
913
|
+
}
|
|
841
914
|
});
|
|
842
915
|
}
|
|
843
916
|
else {
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
917
|
+
// discontinue(2024-08-08~)
|
|
918
|
+
throw new factory.errors.ArgumentNull('inclusion', 'inclusion must be specified');
|
|
919
|
+
// projection = {
|
|
920
|
+
// __v: 0,
|
|
921
|
+
// createdAt: 0,
|
|
922
|
+
// updatedAt: 0
|
|
923
|
+
// };
|
|
924
|
+
// if (Array.isArray(params.exclusion) && params.exclusion.length > 0) {
|
|
925
|
+
// params.exclusion.forEach((field) => {
|
|
926
|
+
// projection[field] = 0;
|
|
927
|
+
// });
|
|
928
|
+
// }
|
|
929
|
+
}
|
|
930
|
+
if (useInclusionProjection) {
|
|
931
|
+
const doc = yield this.reservationModel.findById(params.id, projection)
|
|
932
|
+
.lean() // 2024-08-08~
|
|
933
|
+
.exec();
|
|
934
|
+
if (doc === null) {
|
|
935
|
+
throw new factory.errors.NotFound(this.reservationModel.modelName);
|
|
853
936
|
}
|
|
937
|
+
return doc;
|
|
854
938
|
}
|
|
855
|
-
|
|
856
|
-
.
|
|
857
|
-
|
|
858
|
-
|
|
939
|
+
else {
|
|
940
|
+
const doc = yield this.reservationModel.findById(params.id, projection)
|
|
941
|
+
.exec();
|
|
942
|
+
if (doc === null) {
|
|
943
|
+
throw new factory.errors.NotFound(this.reservationModel.modelName);
|
|
944
|
+
}
|
|
945
|
+
return doc.toObject();
|
|
859
946
|
}
|
|
860
|
-
return doc.toObject();
|
|
861
947
|
});
|
|
862
948
|
}
|
|
863
949
|
confirmManyIfNotExist(params) {
|
|
@@ -901,29 +987,33 @@ class ReservationRepo {
|
|
|
901
987
|
/**
|
|
902
988
|
* 予約取消
|
|
903
989
|
*/
|
|
904
|
-
|
|
990
|
+
cancelById(params) {
|
|
905
991
|
return __awaiter(this, void 0, void 0, function* () {
|
|
906
|
-
const conditions = Object.assign({ _id: String(params.id) }, (typeof params.previousReservationStatus === 'string')
|
|
907
|
-
? { reservationStatus: params.previousReservationStatus }
|
|
992
|
+
const conditions = Object.assign({ _id: { $eq: String(params.id) } }, (typeof params.previousReservationStatus === 'string')
|
|
993
|
+
? { reservationStatus: { $eq: params.previousReservationStatus } }
|
|
908
994
|
: undefined);
|
|
909
|
-
const update =
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
995
|
+
const update = {
|
|
996
|
+
$set: Object.assign({ reservationStatus: factory.reservationStatusType.ReservationCancelled, modifiedTime: params.modifiedTime }, (typeof params.previousReservationStatus === 'string')
|
|
997
|
+
? { previousReservationStatus: params.previousReservationStatus }
|
|
998
|
+
: undefined)
|
|
999
|
+
};
|
|
1000
|
+
const doc = yield this.reservationModel.findOneAndUpdate(conditions, update, { new: true, projection: { _id: 1 } })
|
|
1001
|
+
.lean() // 2024-08-07~
|
|
1002
|
+
// .select({ __v: 0, createdAt: 0, updatedAt: 0 })
|
|
914
1003
|
.exec();
|
|
915
1004
|
// NotFoundであれば状態確認
|
|
916
1005
|
if (doc === null) {
|
|
917
|
-
const
|
|
918
|
-
if (
|
|
1006
|
+
const { reservationStatus } = yield this.projectFieldsById({ id: String(params.id), inclusion: ['reservationStatus'] });
|
|
1007
|
+
if (reservationStatus === factory.reservationStatusType.ReservationCancelled) {
|
|
919
1008
|
// すでに取消済の場合
|
|
920
|
-
return
|
|
1009
|
+
return;
|
|
1010
|
+
// return reservation;
|
|
921
1011
|
}
|
|
922
1012
|
else {
|
|
923
|
-
throw new factory.errors.Argument('id', `Reservation ${
|
|
1013
|
+
throw new factory.errors.Argument('id', `Reservation ${params.id} already changed -> ${reservationStatus}`);
|
|
924
1014
|
}
|
|
925
1015
|
}
|
|
926
|
-
return doc.toObject();
|
|
1016
|
+
// return doc.toObject();
|
|
927
1017
|
});
|
|
928
1018
|
}
|
|
929
1019
|
/**
|
|
@@ -932,11 +1022,13 @@ class ReservationRepo {
|
|
|
932
1022
|
cancelByReservationNumber(params) {
|
|
933
1023
|
return __awaiter(this, void 0, void 0, function* () {
|
|
934
1024
|
const conditions = Object.assign({ reservationNumber: { $eq: String(params.reservationNumber) } }, (typeof params.previousReservationStatus === 'string')
|
|
935
|
-
? { reservationStatus: params.previousReservationStatus }
|
|
1025
|
+
? { reservationStatus: { $eq: params.previousReservationStatus } }
|
|
936
1026
|
: undefined);
|
|
937
|
-
const update =
|
|
938
|
-
|
|
939
|
-
|
|
1027
|
+
const update = {
|
|
1028
|
+
$set: Object.assign({ reservationStatus: factory.reservationStatusType.ReservationCancelled, modifiedTime: params.modifiedTime }, (typeof params.previousReservationStatus === 'string')
|
|
1029
|
+
? { previousReservationStatus: params.previousReservationStatus }
|
|
1030
|
+
: undefined)
|
|
1031
|
+
};
|
|
940
1032
|
return this.reservationModel.updateMany(conditions, update)
|
|
941
1033
|
.exec();
|
|
942
1034
|
});
|
|
@@ -1035,17 +1127,38 @@ class ReservationRepo {
|
|
|
1035
1127
|
_id: { $eq: params.id },
|
|
1036
1128
|
attended: { $eq: false }
|
|
1037
1129
|
}, {
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1130
|
+
$set: {
|
|
1131
|
+
attended: true,
|
|
1132
|
+
modifiedTime: params.now,
|
|
1133
|
+
'reservedTicket.dateUsed': params.now
|
|
1134
|
+
}
|
|
1135
|
+
}, {
|
|
1136
|
+
new: true,
|
|
1137
|
+
projection: {
|
|
1138
|
+
_id: 0,
|
|
1139
|
+
id: { $toString: '$_id' },
|
|
1140
|
+
typeOf: 1,
|
|
1141
|
+
project: 1,
|
|
1142
|
+
modifiedTime: 1,
|
|
1143
|
+
'reservedTicket.dateUsed': 1,
|
|
1144
|
+
'reservationFor.id': 1,
|
|
1145
|
+
'reservationFor.typeOf': 1
|
|
1146
|
+
}
|
|
1147
|
+
})
|
|
1148
|
+
.lean() // 2024-08-08~
|
|
1149
|
+
// .select({ __v: 0, createdAt: 0, updatedAt: 0 })
|
|
1043
1150
|
.exec();
|
|
1044
1151
|
if (doc === null) {
|
|
1045
|
-
return this.
|
|
1152
|
+
return this.projectFieldsById({
|
|
1153
|
+
id: params.id,
|
|
1154
|
+
inclusion: [
|
|
1155
|
+
'typeOf', 'project', 'modifiedTime', 'reservedTicket.dateUsed', 'reservationFor.id', 'reservationFor.typeOf'
|
|
1156
|
+
] // inclusion(2024-08-08~)
|
|
1157
|
+
});
|
|
1046
1158
|
// throw new factory.errors.NotFound(this.reservationModel.modelName);
|
|
1047
1159
|
}
|
|
1048
|
-
return doc
|
|
1160
|
+
return doc;
|
|
1161
|
+
// return doc.toObject();
|
|
1049
1162
|
});
|
|
1050
1163
|
}
|
|
1051
1164
|
/**
|
|
@@ -1111,22 +1224,26 @@ class ReservationRepo {
|
|
|
1111
1224
|
.then((docs) => docs.map((doc) => doc._id.toString()));
|
|
1112
1225
|
});
|
|
1113
1226
|
}
|
|
1114
|
-
deleteReservedTicketUnderName() {
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
});
|
|
1125
|
-
}
|
|
1227
|
+
// public async deleteReservedTicketUnderName() {
|
|
1228
|
+
// const conditions = {
|
|
1229
|
+
// 'reservedTicket.underName': { $exists: true }
|
|
1230
|
+
// };
|
|
1231
|
+
// const update = {
|
|
1232
|
+
// $unset: { 'reservedTicket.underName': 1 }
|
|
1233
|
+
// };
|
|
1234
|
+
// return this.reservationModel.updateMany(conditions, update)
|
|
1235
|
+
// .exec();
|
|
1236
|
+
// }
|
|
1126
1237
|
getCursor(conditions, projection) {
|
|
1127
1238
|
return this.reservationModel.find(conditions, projection)
|
|
1128
1239
|
.sort({ bookingTime: factory.sortType.Descending })
|
|
1129
1240
|
.cursor();
|
|
1130
1241
|
}
|
|
1242
|
+
unsetUnnecessaryFields(params) {
|
|
1243
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1244
|
+
return this.reservationModel.updateMany(params.filter, { $unset: params.$unset }, { timestamps: false })
|
|
1245
|
+
.exec();
|
|
1246
|
+
});
|
|
1247
|
+
}
|
|
1131
1248
|
}
|
|
1132
1249
|
exports.ReservationRepo = ReservationRepo;
|
|
@@ -7,7 +7,9 @@ export declare function createStartParams(params: {
|
|
|
7
7
|
project: factory.assetTransaction.IProject;
|
|
8
8
|
transactionNumber: string;
|
|
9
9
|
transaction?: factory.assetTransaction.ITransaction<factory.assetTransactionType.Reserve>;
|
|
10
|
-
reservations?: factory.reservation.IReservation<factory.reservationType.EventReservation>
|
|
10
|
+
reservations?: (Pick<factory.reservation.IReservation<factory.reservationType.EventReservation>, 'id' | 'issuedThrough' | 'typeOf' | 'reservationNumber'> & {
|
|
11
|
+
reservationFor: Pick<factory.reservation.IReservationFor<factory.reservationType.EventReservation>, 'id' | 'typeOf'>;
|
|
12
|
+
})[];
|
|
11
13
|
}): factory.assetTransaction.IStartParams<factory.assetTransactionType.CancelReservation>;
|
|
12
14
|
export declare function createPotentialActions(params: {
|
|
13
15
|
transaction: factory.assetTransaction.ITransaction<factory.assetTransactionType.CancelReservation>;
|
|
@@ -50,8 +50,11 @@ function validateStartParams(params) {
|
|
|
50
50
|
if (reserveTransaction === undefined) {
|
|
51
51
|
// 予約存在確認
|
|
52
52
|
if (typeof ((_c = params.object.reservation) === null || _c === void 0 ? void 0 : _c.id) === 'string') {
|
|
53
|
-
const reservation = yield repos.reservation.
|
|
54
|
-
id: params.object.reservation.id
|
|
53
|
+
const reservation = yield repos.reservation.projectFieldsById({
|
|
54
|
+
id: params.object.reservation.id,
|
|
55
|
+
inclusion: [
|
|
56
|
+
'issuedThrough', 'typeOf', 'reservationNumber', 'reservationFor.id', 'reservationFor.typeOf', 'provider', 'reservationStatus'
|
|
57
|
+
]
|
|
55
58
|
});
|
|
56
59
|
// 販売者検証(2023-08-01~)
|
|
57
60
|
if (typeof sellerId === 'string') {
|
|
@@ -215,8 +215,9 @@ function cancelReservation(actionAttributesList) {
|
|
|
215
215
|
});
|
|
216
216
|
}
|
|
217
217
|
else {
|
|
218
|
-
const reservation = yield repos.reservation.
|
|
219
|
-
id: actionAttributes.object.id
|
|
218
|
+
const reservation = yield repos.reservation.projectFieldsById({
|
|
219
|
+
id: actionAttributes.object.id,
|
|
220
|
+
inclusion: ['reservationNumber', 'reservationStatus', 'project', 'reservedTicket', 'subReservation', 'reservationFor']
|
|
220
221
|
});
|
|
221
222
|
// 予約取引を検索
|
|
222
223
|
const reserveTransactions = yield repos.assetTransaction.search({
|
|
@@ -254,7 +255,7 @@ function cancelReservation(actionAttributesList) {
|
|
|
254
255
|
reservationFor: reservation.reservationFor
|
|
255
256
|
})(repos);
|
|
256
257
|
// 予約をキャンセル状態に変更する
|
|
257
|
-
yield repos.reservation.
|
|
258
|
+
yield repos.reservation.cancelById({
|
|
258
259
|
id: reservation.id,
|
|
259
260
|
previousReservationStatus: actionAttributes.object.reservationStatus,
|
|
260
261
|
modifiedTime: now
|
|
@@ -287,10 +288,10 @@ function cancelReservation(actionAttributesList) {
|
|
|
287
288
|
const reservationNumber = actionAttributes.object.reservationNumber;
|
|
288
289
|
if (typeof reservationNumber === 'string' && reservationNumber.length > 0) {
|
|
289
290
|
// 最新のconfirmedReservationsを検索
|
|
290
|
-
canceledReservations = yield repos.reservation.
|
|
291
|
+
canceledReservations = yield repos.reservation.projectFields({
|
|
291
292
|
reservationNumber: { $eq: reservationNumber },
|
|
292
293
|
typeOf: factory.reservationType.EventReservation
|
|
293
|
-
});
|
|
294
|
+
}, { project: 1, typeOf: 1, modifiedTime: 1, reservationNumber: 1 });
|
|
294
295
|
canceledReservations = canceledReservations.map((r) => {
|
|
295
296
|
// _idは不要であり、存在すると予期せぬ影響を及ぼす可能性がある
|
|
296
297
|
delete r._id;
|
|
@@ -299,8 +300,9 @@ function cancelReservation(actionAttributesList) {
|
|
|
299
300
|
}
|
|
300
301
|
}
|
|
301
302
|
else {
|
|
302
|
-
const canceledReservation = yield repos.reservation.
|
|
303
|
-
id: actionAttributes.object.id
|
|
303
|
+
const canceledReservation = yield repos.reservation.projectFieldsById({
|
|
304
|
+
id: actionAttributes.object.id,
|
|
305
|
+
inclusion: ['project', 'typeOf', 'modifiedTime', 'reservationNumber']
|
|
304
306
|
});
|
|
305
307
|
canceledReservations = [canceledReservation];
|
|
306
308
|
}
|
|
@@ -36,10 +36,13 @@ function confirmReservation(params) {
|
|
|
36
36
|
const reservationNumber = params.potentialReserveAction.object.reservationNumber;
|
|
37
37
|
if (typeof reservationNumber === 'string' && reservationNumber.length > 0) {
|
|
38
38
|
// 最新のconfirmedReservationsを検索
|
|
39
|
-
confirmedReservations = yield repos.reservation.
|
|
39
|
+
confirmedReservations = yield repos.reservation.projectFields({
|
|
40
40
|
reservationNumber: { $eq: reservationNumber },
|
|
41
41
|
typeOf: factory.reservationType.EventReservation
|
|
42
|
-
}
|
|
42
|
+
}
|
|
43
|
+
// project all fields
|
|
44
|
+
// {}
|
|
45
|
+
);
|
|
43
46
|
confirmedReservations = confirmedReservations.map((r) => {
|
|
44
47
|
// _idは不要であり、存在すると予期せぬ影響を及ぼす可能性がある
|
|
45
48
|
delete r._id;
|
|
@@ -41,10 +41,10 @@ function findByCode(params) {
|
|
|
41
41
|
default:
|
|
42
42
|
throw new factory.errors.NotImplemented(`authorization object typeOf: ${authorization.object.typeOf} not implemented`);
|
|
43
43
|
}
|
|
44
|
-
const reservationFromRepo = yield repos.reservation.
|
|
44
|
+
const reservationFromRepo = yield repos.reservation.projectFieldsById({
|
|
45
45
|
id: reservationId,
|
|
46
|
-
inclusion: ['
|
|
47
|
-
exclusion: []
|
|
46
|
+
inclusion: ['additionalTicketText', 'reservationStatus', 'reservedTicket']
|
|
47
|
+
// exclusion: [] // discontinue(2024-08-08~)
|
|
48
48
|
});
|
|
49
49
|
const { id, additionalTicketText, reservationStatus, reservedTicket } = reservationFromRepo;
|
|
50
50
|
const reservation = {
|
|
@@ -4,13 +4,13 @@
|
|
|
4
4
|
import * as factory from '../../../factory';
|
|
5
5
|
import type { TaskRepo } from '../../../repo/task';
|
|
6
6
|
import { Settings } from '../../../settings';
|
|
7
|
-
type
|
|
8
|
-
type
|
|
7
|
+
export type ICanceledEventReservation = Pick<factory.reservation.IReservation<factory.reservationType.EventReservation>, 'project' | 'id' | 'typeOf' | 'modifiedTime' | 'reservationNumber'>;
|
|
8
|
+
export type ICanceledBusReservation = Pick<factory.reservation.IReservation<factory.reservationType.BusReservation>, 'project' | 'id' | 'typeOf' | 'modifiedTime' | 'reservationNumber'>;
|
|
9
9
|
export declare function onReservationCanceled(
|
|
10
10
|
/**
|
|
11
11
|
* ステータス変更された予約リスト
|
|
12
12
|
*/
|
|
13
|
-
canceledReservations:
|
|
13
|
+
canceledReservations: ICanceledEventReservation[] | ICanceledBusReservation[],
|
|
14
14
|
/**
|
|
15
15
|
* 予約通知有無
|
|
16
16
|
*/
|
|
@@ -26,4 +26,3 @@ reservationFor: {
|
|
|
26
26
|
}): (repos: {
|
|
27
27
|
task: TaskRepo;
|
|
28
28
|
}, settings: Settings) => Promise<void>;
|
|
29
|
-
export {};
|
|
@@ -2,14 +2,13 @@
|
|
|
2
2
|
* 予約使用時アクション
|
|
3
3
|
*/
|
|
4
4
|
import * as factory from '../../../factory';
|
|
5
|
+
import type { IAttendedReservation } from '../../../repo/reservation';
|
|
5
6
|
import type { TaskRepo } from '../../../repo/task';
|
|
6
7
|
import { Settings } from '../../../settings';
|
|
7
|
-
type IEventReservation = factory.reservation.IReservation<factory.reservationType.EventReservation>;
|
|
8
8
|
export type IUseReservationAction = factory.action.consume.use.reservation.IAction;
|
|
9
9
|
/**
|
|
10
10
|
* 予約使用
|
|
11
11
|
*/
|
|
12
|
-
export declare function onReservationUsed(attendedReservation:
|
|
12
|
+
export declare function onReservationUsed(attendedReservation: IAttendedReservation): (repos: {
|
|
13
13
|
task: TaskRepo;
|
|
14
14
|
}, settings: Settings) => Promise<void>;
|
|
15
|
-
export {};
|
|
@@ -90,7 +90,7 @@ function searchByOrder(params) {
|
|
|
90
90
|
}
|
|
91
91
|
break;
|
|
92
92
|
default:
|
|
93
|
-
reservations = yield repos.reservation.
|
|
93
|
+
reservations = yield repos.reservation.projectFields({
|
|
94
94
|
project: { id: { $eq: params.project.id } },
|
|
95
95
|
typeOf: reservationType,
|
|
96
96
|
id: { $in: reservationIds }
|
|
@@ -30,9 +30,9 @@ function useReservation(params) {
|
|
|
30
30
|
// confirmReservationが間に合わない可能性を考慮する(2023-06-01~)
|
|
31
31
|
yield reserveIfNotYet({ object: params.object })(repos, settings);
|
|
32
32
|
// 予約検索
|
|
33
|
-
const reservation = yield repos.reservation.
|
|
33
|
+
const reservation = yield repos.reservation.projectFieldsById({
|
|
34
34
|
id: reservationId,
|
|
35
|
-
inclusion: ['
|
|
35
|
+
inclusion: ['issuedThrough', 'project', 'reservationFor', 'reservationNumber', 'reservedTicket', 'typeOf']
|
|
36
36
|
});
|
|
37
37
|
// UseActionを作成する
|
|
38
38
|
// optimize(2024-05-07~)
|
|
@@ -60,7 +60,7 @@ function useReservation(params) {
|
|
|
60
60
|
let attendedReservation;
|
|
61
61
|
try {
|
|
62
62
|
// 使用日時と同時更新(2023-01-30~)
|
|
63
|
-
attendedReservation =
|
|
63
|
+
attendedReservation = yield repos.reservation.attendIfNotAttended({ id: reservationId, now });
|
|
64
64
|
}
|
|
65
65
|
catch (error) {
|
|
66
66
|
try {
|
|
@@ -76,8 +76,11 @@ function onAuthorizationCreated(params) {
|
|
|
76
76
|
|| ownershipInfo.typeOfGood.typeOf === factory.reservationType.BusReservation) {
|
|
77
77
|
const reservationId = String(ownershipInfo.typeOfGood.id);
|
|
78
78
|
reservationIds = [reservationId];
|
|
79
|
-
const
|
|
80
|
-
|
|
79
|
+
const { reservationFor } = yield repos.reservation.projectFieldsById({
|
|
80
|
+
id: reservationId,
|
|
81
|
+
inclusion: ['reservationFor.id']
|
|
82
|
+
});
|
|
83
|
+
reservationForIds = [String(reservationFor.id)];
|
|
81
84
|
}
|
|
82
85
|
}
|
|
83
86
|
break;
|
|
@@ -181,13 +181,13 @@ function checkUsedReservationExists(params) {
|
|
|
181
181
|
}, 'acceptedOffers.itemOffered.reservationNumber');
|
|
182
182
|
if (reservationNumbers.length > 0) {
|
|
183
183
|
// 使用済の予約がひとつでもあれば不可
|
|
184
|
-
const existingUsedReservations = yield repos.reservation.
|
|
184
|
+
const existingUsedReservations = yield repos.reservation.projectFields({
|
|
185
185
|
limit: 1,
|
|
186
186
|
page: 1,
|
|
187
187
|
typeOf: factory.reservationType.EventReservation,
|
|
188
188
|
reservationNumber: { $in: reservationNumbers },
|
|
189
189
|
attended: true
|
|
190
|
-
}, {
|
|
190
|
+
}, { id: 1 });
|
|
191
191
|
if (existingUsedReservations.length > 0) {
|
|
192
192
|
usedReservationExists = true;
|
|
193
193
|
}
|
package/package.json
CHANGED
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
}
|
|
10
10
|
],
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@chevre/factory": "4.
|
|
13
|
-
"@cinerino/sdk": "10.
|
|
12
|
+
"@chevre/factory": "4.380.0",
|
|
13
|
+
"@cinerino/sdk": "10.4.0",
|
|
14
14
|
"@motionpicture/coa-service": "9.4.0",
|
|
15
15
|
"@motionpicture/gmo-service": "5.3.0",
|
|
16
16
|
"@sendgrid/mail": "6.4.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.1.0
|
|
113
|
+
"version": "22.1.0"
|
|
114
114
|
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
// tslint:disable:no-console
|
|
2
|
-
import * as mongoose from 'mongoose';
|
|
3
|
-
|
|
4
|
-
import { chevre } from '../../../lib/index';
|
|
5
|
-
|
|
6
|
-
const project = { id: String(process.env.PROJECT_ID) };
|
|
7
|
-
|
|
8
|
-
mongoose.Model.on('index', (...args) => {
|
|
9
|
-
console.error('******** index event emitted. ********\n', args);
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
async function main() {
|
|
13
|
-
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
14
|
-
|
|
15
|
-
const indexes = await mongoose.connection.db.collection('orders')
|
|
16
|
-
.indexes();
|
|
17
|
-
// console.log(indexes);
|
|
18
|
-
console.log(indexes.length, 'indexes found');
|
|
19
|
-
|
|
20
|
-
const orderRepo = await chevre.repository.Order.createInstance(mongoose.connection);
|
|
21
|
-
|
|
22
|
-
const orders = await orderRepo.projectFields(
|
|
23
|
-
{
|
|
24
|
-
limit: 3,
|
|
25
|
-
page: 1,
|
|
26
|
-
sort: { orderDate: -1 },
|
|
27
|
-
project: { id: { $eq: project.id } },
|
|
28
|
-
acceptedOffers: {
|
|
29
|
-
// itemOffered: {
|
|
30
|
-
// reservedTicket: {
|
|
31
|
-
// identifier: { $eq: 'bls2qevbb:Default:B-9' }
|
|
32
|
-
// }
|
|
33
|
-
// }
|
|
34
|
-
// $size: 1
|
|
35
|
-
// itemOffered: {
|
|
36
|
-
// issuedThrough: { typeOf: { $eq: chevre.factory.product.ProductType.MembershipService } }
|
|
37
|
-
// }
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
inclusion: [
|
|
42
|
-
'orderNumber', 'orderDate'
|
|
43
|
-
, 'paymentMethods.name'
|
|
44
|
-
// , 'confirmationNumber', 'identifier', 'orderDate', 'orderStatus', 'price', 'typeOf'
|
|
45
|
-
]
|
|
46
|
-
}
|
|
47
|
-
);
|
|
48
|
-
// tslint:disable-next-line:no-null-keyword
|
|
49
|
-
console.dir(orders, { depth: null });
|
|
50
|
-
console.log(orders.length, 'orders found');
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
main()
|
|
54
|
-
.then()
|
|
55
|
-
.catch(console.error);
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
// tslint:disable:no-console
|
|
2
|
-
import * as mongoose from 'mongoose';
|
|
3
|
-
|
|
4
|
-
import { chevre } from '../../../lib/index';
|
|
5
|
-
|
|
6
|
-
const project = { id: String(process.env.PROJECT_ID) };
|
|
7
|
-
|
|
8
|
-
mongoose.Model.on('index', (...args) => {
|
|
9
|
-
console.error('******** index event emitted. ********\n', args);
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
async function main() {
|
|
13
|
-
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
14
|
-
|
|
15
|
-
const orderRepo = await chevre.repository.Order.createInstance(mongoose.connection);
|
|
16
|
-
const result = await orderRepo.projectFieldsById(
|
|
17
|
-
{
|
|
18
|
-
id: '66a04d962582d528b3ba6521',
|
|
19
|
-
inclusion: ['orderNumber']
|
|
20
|
-
}
|
|
21
|
-
);
|
|
22
|
-
// tslint:disable-next-line:no-null-keyword
|
|
23
|
-
console.dir(result, { depth: null });
|
|
24
|
-
|
|
25
|
-
const findByOrderNumberResult = await orderRepo.projectFieldsByOrderNumber(
|
|
26
|
-
{
|
|
27
|
-
orderNumber: 'CIN0-2152162-0949752',
|
|
28
|
-
project: { id: project.id },
|
|
29
|
-
inclusion: [
|
|
30
|
-
// 'orderNumber', 'orderStatus', 'typeOf',
|
|
31
|
-
'project'
|
|
32
|
-
]
|
|
33
|
-
}
|
|
34
|
-
);
|
|
35
|
-
// tslint:disable-next-line:no-null-keyword
|
|
36
|
-
console.log(findByOrderNumberResult);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
main()
|
|
40
|
-
.then(console.log)
|
|
41
|
-
.catch(console.error);
|