@chevre/domain 21.23.0 → 21.24.1
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/findReservationByCode.ts +21 -4
- package/example/src/chevre/migrateProjectMakesOffer.ts +13 -9
- package/lib/chevre/repo/code.d.ts +2 -6
- package/lib/chevre/repo/code.js +25 -52
- package/lib/chevre/repo/mongoose/schemas/authorization.js +9 -8
- package/lib/chevre/repo/order.js +3 -1
- package/lib/chevre/repo/reservation.d.ts +3 -3
- package/lib/chevre/repo/reservation.js +0 -24
- package/lib/chevre/service/code.js +10 -13
- package/lib/chevre/service/reserve/findByCode.d.ts +10 -3
- package/lib/chevre/service/reserve/findByCode.js +31 -60
- package/lib/chevre/service/reserve/useReservation.d.ts +1 -4
- package/lib/chevre/service/reserve/useReservation.js +17 -16
- package/lib/chevre/service/reserve/verifyToken4reservation.d.ts +12 -1
- package/lib/chevre/service/reserve/verifyToken4reservation.js +24 -6
- package/lib/chevre/service/reserve.d.ts +1 -2
- package/lib/chevre/service/reserve.js +2 -3
- package/lib/chevre/service/task/onAuthorizationCreated.js +2 -2
- package/lib/chevre/service/task/useReservation.js +2 -4
- package/package.json +2 -2
|
@@ -9,20 +9,37 @@ mongoose.Model.on('index', (...args) => {
|
|
|
9
9
|
console.error('******** index event emitted. ********\n', args);
|
|
10
10
|
});
|
|
11
11
|
|
|
12
|
+
const CODE = '068cb0ba-8529-4a2b-8cf5-890d5af9c536';
|
|
13
|
+
const RESERVATION_ID = '589701779538948-0';
|
|
14
|
+
// const RESERVATION_ID = '589701779538948-1';
|
|
15
|
+
|
|
12
16
|
async function main() {
|
|
13
17
|
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
14
18
|
|
|
15
|
-
const acceptedOfferRepo = await chevre.repository.AcceptedOffer.createInstance(mongoose.connection);
|
|
16
19
|
const authorizationRepo = await chevre.repository.Code.createInstance(mongoose.connection);
|
|
20
|
+
const orderRepo = await chevre.repository.Order.createInstance(mongoose.connection);
|
|
17
21
|
const reservationRepo = await chevre.repository.Reservation.createInstance(mongoose.connection);
|
|
18
22
|
|
|
23
|
+
await (await chevre.service.reserve.createService()).verifyToken4reservation({
|
|
24
|
+
project: { id: project.id },
|
|
25
|
+
agent: { id: project.id, typeOf: chevre.factory.organizationType.Project },
|
|
26
|
+
reservationId: RESERVATION_ID,
|
|
27
|
+
ticket: {
|
|
28
|
+
ticketToken: CODE
|
|
29
|
+
}
|
|
30
|
+
})({
|
|
31
|
+
authorization: authorizationRepo,
|
|
32
|
+
order: orderRepo
|
|
33
|
+
});
|
|
34
|
+
console.log('verified.');
|
|
35
|
+
|
|
19
36
|
const result = await (await chevre.service.reserve.createService()).findByCode({
|
|
20
37
|
project: { id: project.id },
|
|
21
|
-
code:
|
|
22
|
-
id:
|
|
38
|
+
code: CODE,
|
|
39
|
+
id: RESERVATION_ID
|
|
23
40
|
})({
|
|
24
|
-
acceptedOffer: acceptedOfferRepo,
|
|
25
41
|
authorization: authorizationRepo,
|
|
42
|
+
order: orderRepo,
|
|
26
43
|
reservation: reservationRepo
|
|
27
44
|
});
|
|
28
45
|
// tslint:disable-next-line:no-null-keyword
|
|
@@ -8,8 +8,8 @@ enum ROLE_NAME {
|
|
|
8
8
|
Customer = 'customer',
|
|
9
9
|
POS = 'pos'
|
|
10
10
|
}
|
|
11
|
-
const CLIENT_ID = '
|
|
12
|
-
const CUSTOMER_TYPE = '
|
|
11
|
+
const CLIENT_ID = '5an0cmki8v29vdmk627kdo1r0p';
|
|
12
|
+
const CUSTOMER_TYPE = 'Enduser';
|
|
13
13
|
|
|
14
14
|
// tslint:disable-next-line:max-func-body-length
|
|
15
15
|
async function main() {
|
|
@@ -51,13 +51,17 @@ async function main() {
|
|
|
51
51
|
console.log(
|
|
52
52
|
'updating project...',
|
|
53
53
|
iamMember.project.id, iamMember.member.id, iamMember.member.typeOf, iamMember.member.name, i);
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
54
|
+
try {
|
|
55
|
+
await makesOfferRepo.updateOne({
|
|
56
|
+
availableAtOrFrom: { id: iamMember.member.id },
|
|
57
|
+
eligibleCustomerType: [{
|
|
58
|
+
codeValue: CUSTOMER_TYPE
|
|
59
|
+
}],
|
|
60
|
+
offeredBy: { id: iamMember.project.id }
|
|
61
|
+
});
|
|
62
|
+
} catch (error) {
|
|
63
|
+
console.error(error);
|
|
64
|
+
}
|
|
61
65
|
updateCount += 1;
|
|
62
66
|
console.log(
|
|
63
67
|
'updated.',
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import type { Connection, FilterQuery } from 'mongoose';
|
|
2
2
|
import * as factory from '../factory';
|
|
3
|
-
import { modelName } from './mongoose/schemas/authorization';
|
|
4
3
|
export type IObject = factory.authorization.IObject;
|
|
5
4
|
export type ICode = string;
|
|
6
|
-
export { modelName };
|
|
7
5
|
/**
|
|
8
6
|
* 承認コードリポジトリ
|
|
9
7
|
*/
|
|
@@ -24,16 +22,14 @@ export declare class MongoRepository {
|
|
|
24
22
|
expiresInSeconds: number;
|
|
25
23
|
}[]): Promise<factory.authorization.IAuthorization[]>;
|
|
26
24
|
/**
|
|
27
|
-
*
|
|
25
|
+
* コードで承認対象を検索する
|
|
28
26
|
*/
|
|
29
|
-
|
|
27
|
+
findValidObjectByCode(params: {
|
|
30
28
|
project: {
|
|
31
29
|
id: string;
|
|
32
|
-
typeOf: factory.organizationType.Project;
|
|
33
30
|
};
|
|
34
31
|
code: ICode;
|
|
35
32
|
}): Promise<IObject>;
|
|
36
|
-
count(params: factory.authorization.ISearchConditions): Promise<number>;
|
|
37
33
|
search(params: factory.authorization.ISearchConditions): Promise<factory.authorization.IAuthorization[]>;
|
|
38
34
|
/**
|
|
39
35
|
* 有効期限を一定期間過ぎた承認を削除する
|
package/lib/chevre/repo/code.js
CHANGED
|
@@ -9,12 +9,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.MongoRepository =
|
|
12
|
+
exports.MongoRepository = void 0;
|
|
13
13
|
const moment = require("moment");
|
|
14
14
|
const uuid = require("uuid");
|
|
15
15
|
const factory = require("../factory");
|
|
16
16
|
const authorization_1 = require("./mongoose/schemas/authorization");
|
|
17
|
-
Object.defineProperty(exports, "modelName", { enumerable: true, get: function () { return authorization_1.modelName; } });
|
|
18
17
|
const settings_1 = require("../settings");
|
|
19
18
|
/**
|
|
20
19
|
* 承認コードリポジトリ
|
|
@@ -55,20 +54,14 @@ class MongoRepository {
|
|
|
55
54
|
/* istanbul ignore else */
|
|
56
55
|
if (Array.isArray(object.ids)) {
|
|
57
56
|
andConditions.push({
|
|
58
|
-
'object.id': {
|
|
59
|
-
$exists: true,
|
|
60
|
-
$in: object.ids
|
|
61
|
-
}
|
|
57
|
+
'object.id': { $exists: true, $in: object.ids }
|
|
62
58
|
});
|
|
63
59
|
}
|
|
64
60
|
// tslint:disable-next-line:no-single-line-block-comment
|
|
65
61
|
/* istanbul ignore else */
|
|
66
62
|
if (Array.isArray(object.typeOfs)) {
|
|
67
63
|
andConditions.push({
|
|
68
|
-
'object.typeOf': {
|
|
69
|
-
$exists: true,
|
|
70
|
-
$in: object.typeOfs
|
|
71
|
-
}
|
|
64
|
+
'object.typeOf': { $exists: true, $in: object.typeOfs }
|
|
72
65
|
});
|
|
73
66
|
}
|
|
74
67
|
// tslint:disable-next-line:no-single-line-block-comment
|
|
@@ -78,20 +71,14 @@ class MongoRepository {
|
|
|
78
71
|
/* istanbul ignore else */
|
|
79
72
|
if (Array.isArray(object.typeOfGood.ids)) {
|
|
80
73
|
andConditions.push({
|
|
81
|
-
'object.typeOfGood.id': {
|
|
82
|
-
$exists: true,
|
|
83
|
-
$in: object.typeOfGood.ids
|
|
84
|
-
}
|
|
74
|
+
'object.typeOfGood.id': { $exists: true, $in: object.typeOfGood.ids }
|
|
85
75
|
});
|
|
86
76
|
}
|
|
87
77
|
// tslint:disable-next-line:no-single-line-block-comment
|
|
88
78
|
/* istanbul ignore else */
|
|
89
79
|
if (Array.isArray(object.typeOfGood.typeOfs)) {
|
|
90
80
|
andConditions.push({
|
|
91
|
-
'object.typeOfGood.typeOf': {
|
|
92
|
-
$exists: true,
|
|
93
|
-
$in: object.typeOfGood.typeOfs
|
|
94
|
-
}
|
|
81
|
+
'object.typeOfGood.typeOf': { $exists: true, $in: object.typeOfGood.typeOfs }
|
|
95
82
|
});
|
|
96
83
|
}
|
|
97
84
|
}
|
|
@@ -102,7 +89,7 @@ class MongoRepository {
|
|
|
102
89
|
// });
|
|
103
90
|
// }
|
|
104
91
|
if (params.validFrom instanceof Date) {
|
|
105
|
-
andConditions.push({ validUntil: { $
|
|
92
|
+
andConditions.push({ validUntil: { $gte: params.validFrom } });
|
|
106
93
|
}
|
|
107
94
|
if (params.validThrough instanceof Date) {
|
|
108
95
|
andConditions.push({ validFrom: { $lte: params.validThrough } });
|
|
@@ -114,47 +101,40 @@ class MongoRepository {
|
|
|
114
101
|
*/
|
|
115
102
|
publish(params) {
|
|
116
103
|
return __awaiter(this, void 0, void 0, function* () {
|
|
117
|
-
const saveParams = params.map((
|
|
104
|
+
const saveParams = params.map(({ project, object, validFrom, expiresInSeconds }) => {
|
|
118
105
|
const code = uuid.v4();
|
|
119
|
-
return {
|
|
120
|
-
project: p.project,
|
|
121
|
-
code: code,
|
|
122
|
-
object: p.object,
|
|
123
|
-
validFrom: p.validFrom,
|
|
124
|
-
expiresInSeconds: p.expiresInSeconds
|
|
125
|
-
};
|
|
106
|
+
return { project, code, object, validFrom, expiresInSeconds };
|
|
126
107
|
});
|
|
127
108
|
return this.save(saveParams);
|
|
128
109
|
});
|
|
129
110
|
}
|
|
130
111
|
/**
|
|
131
|
-
*
|
|
112
|
+
* コードで承認対象を検索する
|
|
132
113
|
*/
|
|
133
|
-
|
|
114
|
+
findValidObjectByCode(params) {
|
|
134
115
|
return __awaiter(this, void 0, void 0, function* () {
|
|
135
116
|
const now = new Date();
|
|
136
117
|
const doc = yield this.authorizationModel.findOne({
|
|
137
118
|
'project.id': { $eq: params.project.id },
|
|
138
119
|
code: { $eq: String(params.code) },
|
|
139
120
|
validFrom: { $lte: now },
|
|
140
|
-
validUntil: { $
|
|
141
|
-
})
|
|
121
|
+
validUntil: { $gte: now }
|
|
122
|
+
}, { object: 1, _id: 0 })
|
|
123
|
+
// projection的にleanで十分
|
|
124
|
+
.lean()
|
|
142
125
|
.exec();
|
|
143
126
|
if (doc === null) {
|
|
144
127
|
throw new factory.errors.NotFound(this.authorizationModel.modelName);
|
|
145
128
|
}
|
|
146
|
-
|
|
147
|
-
return authorization.object;
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
count(params) {
|
|
151
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
152
|
-
const conditions = MongoRepository.CREATE_MONGO_CONDITIONS(params);
|
|
153
|
-
return this.authorizationModel.countDocuments((conditions.length > 0) ? { $and: conditions } : {})
|
|
154
|
-
.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
155
|
-
.exec();
|
|
129
|
+
return doc.object;
|
|
156
130
|
});
|
|
157
131
|
}
|
|
132
|
+
// public async count(params: factory.authorization.ISearchConditions): Promise<number> {
|
|
133
|
+
// const conditions = MongoRepository.CREATE_MONGO_CONDITIONS(params);
|
|
134
|
+
// return this.authorizationModel.countDocuments((conditions.length > 0) ? { $and: conditions } : {})
|
|
135
|
+
// .setOptions({ maxTimeMS: MONGO_MAX_TIME_MS })
|
|
136
|
+
// .exec();
|
|
137
|
+
// }
|
|
158
138
|
search(params) {
|
|
159
139
|
var _a;
|
|
160
140
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -199,18 +179,11 @@ class MongoRepository {
|
|
|
199
179
|
save(params) {
|
|
200
180
|
return __awaiter(this, void 0, void 0, function* () {
|
|
201
181
|
if (params.length > 0) {
|
|
202
|
-
const docs = params.map((
|
|
203
|
-
const validUntil = moment(
|
|
204
|
-
.add(
|
|
182
|
+
const docs = params.map(({ project, code, object, validFrom, expiresInSeconds }) => {
|
|
183
|
+
const validUntil = moment(validFrom)
|
|
184
|
+
.add(expiresInSeconds, 'seconds')
|
|
205
185
|
.toDate();
|
|
206
|
-
return {
|
|
207
|
-
project: p.project,
|
|
208
|
-
typeOf: 'Authorization',
|
|
209
|
-
code: p.code,
|
|
210
|
-
object: p.object,
|
|
211
|
-
validFrom: p.validFrom,
|
|
212
|
-
validUntil: validUntil
|
|
213
|
-
};
|
|
186
|
+
return { project, typeOf: 'Authorization', code, object, validFrom, validUntil };
|
|
214
187
|
});
|
|
215
188
|
const result = yield this.authorizationModel.insertMany(docs, { ordered: false, rawResult: true });
|
|
216
189
|
if (result.insertedCount !== docs.length) {
|
|
@@ -7,7 +7,10 @@ const settings_1 = require("../../../settings");
|
|
|
7
7
|
const modelName = 'Authorization';
|
|
8
8
|
exports.modelName = modelName;
|
|
9
9
|
const schemaDefinition = {
|
|
10
|
-
project:
|
|
10
|
+
project: {
|
|
11
|
+
type: mongoose_1.SchemaTypes.Mixed,
|
|
12
|
+
required: true
|
|
13
|
+
},
|
|
11
14
|
typeOf: {
|
|
12
15
|
type: String,
|
|
13
16
|
required: true
|
|
@@ -21,7 +24,10 @@ const schemaDefinition = {
|
|
|
21
24
|
type: Date,
|
|
22
25
|
required: true
|
|
23
26
|
},
|
|
24
|
-
validUntil:
|
|
27
|
+
validUntil: {
|
|
28
|
+
type: Date,
|
|
29
|
+
required: true
|
|
30
|
+
}
|
|
25
31
|
};
|
|
26
32
|
const schemaOptions = {
|
|
27
33
|
autoIndex: settings_1.MONGO_AUTO_INDEX,
|
|
@@ -84,12 +90,7 @@ const indexes = [
|
|
|
84
90
|
],
|
|
85
91
|
[
|
|
86
92
|
{ validUntil: 1, validFrom: 1 },
|
|
87
|
-
{
|
|
88
|
-
name: 'searchByValidUntil',
|
|
89
|
-
partialFilterExpression: {
|
|
90
|
-
validUntil: { $exists: true }
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
+
{ name: 'searchByValidUntil-v2' }
|
|
93
94
|
],
|
|
94
95
|
[
|
|
95
96
|
{ 'object.typeOf': 1, validFrom: 1 },
|
package/lib/chevre/repo/order.js
CHANGED
|
@@ -936,11 +936,13 @@ class MongoRepository {
|
|
|
936
936
|
} }, (typeof ((_a = params.seller) === null || _a === void 0 ? void 0 : _a.id) === 'string')
|
|
937
937
|
? { 'seller.id': { $exists: true, $eq: params.seller.id } }
|
|
938
938
|
: undefined), projection)
|
|
939
|
+
// projection的にleanで十分
|
|
940
|
+
.lean()
|
|
939
941
|
.exec();
|
|
940
942
|
if (doc === null) {
|
|
941
943
|
throw new factory.errors.NotFound(this.orderModel.modelName);
|
|
942
944
|
}
|
|
943
|
-
return doc
|
|
945
|
+
return doc;
|
|
944
946
|
});
|
|
945
947
|
}
|
|
946
948
|
/**
|
|
@@ -54,8 +54,8 @@ export declare class MongoRepository {
|
|
|
54
54
|
}): Promise<factory.reservation.IReservation<factory.reservationType.EventReservation>[]>;
|
|
55
55
|
findById<T extends factory.reservationType>(params: {
|
|
56
56
|
id: string;
|
|
57
|
-
inclusion?:
|
|
58
|
-
exclusion?:
|
|
57
|
+
inclusion?: IKeyOfProjection[];
|
|
58
|
+
exclusion?: IKeyOfProjection[];
|
|
59
59
|
}): Promise<factory.reservation.IReservation<T>>;
|
|
60
60
|
confirmManyIfNotExist(params: {
|
|
61
61
|
provider: factory.reservation.IProvider;
|
|
@@ -115,7 +115,7 @@ export declare class MongoRepository {
|
|
|
115
115
|
updatePartiallyById(params: {
|
|
116
116
|
id: string;
|
|
117
117
|
update: IUpdatePartiallyParams;
|
|
118
|
-
}): Promise<
|
|
118
|
+
}): Promise<void>;
|
|
119
119
|
deleteByIds(params: {
|
|
120
120
|
project: {
|
|
121
121
|
id: string;
|
|
@@ -878,29 +878,6 @@ class MongoRepository {
|
|
|
878
878
|
return doc.toObject();
|
|
879
879
|
});
|
|
880
880
|
}
|
|
881
|
-
// public async confirmByReservationNumber(params: {
|
|
882
|
-
// reservationNumber: string;
|
|
883
|
-
// previousReservationStatus: factory.reservationStatusType;
|
|
884
|
-
// underName?: factory.reservation.IUnderName<factory.reservationType.EventReservation>;
|
|
885
|
-
// broker?: factory.reservation.IBroker<factory.reservationType>;
|
|
886
|
-
// issuedThrough?: factory.assetTransaction.reserve.IIssuedThrough;
|
|
887
|
-
// }): Promise<void> {
|
|
888
|
-
// const conditions = {
|
|
889
|
-
// reservationNumber: { $eq: String(params.reservationNumber) },
|
|
890
|
-
// reservationStatus: { $eq: params.previousReservationStatus }
|
|
891
|
-
// };
|
|
892
|
-
// const update = {
|
|
893
|
-
// // previousReservationStatusを保管(2023-01-19~)
|
|
894
|
-
// previousReservationStatus: params.previousReservationStatus,
|
|
895
|
-
// reservationStatus: factory.reservationStatusType.ReservationConfirmed,
|
|
896
|
-
// modifiedTime: new Date(),
|
|
897
|
-
// ...(params.underName !== undefined) ? { underName: params.underName } : undefined,
|
|
898
|
-
// ...(typeof params.broker?.typeOf === 'string') ? { broker: params.broker } : undefined,
|
|
899
|
-
// ...(typeof params.issuedThrough?.typeOf === 'string') ? { issuedThrough: params.issuedThrough } : undefined
|
|
900
|
-
// };
|
|
901
|
-
// await this.reservationModel.updateMany(conditions, update)
|
|
902
|
-
// .exec();
|
|
903
|
-
// }
|
|
904
881
|
confirmManyIfNotExist(params) {
|
|
905
882
|
return __awaiter(this, void 0, void 0, function* () {
|
|
906
883
|
const modifiedTime = new Date();
|
|
@@ -1101,7 +1078,6 @@ class MongoRepository {
|
|
|
1101
1078
|
if (doc === null) {
|
|
1102
1079
|
throw new factory.errors.ArgumentNull(this.reservationModel.modelName);
|
|
1103
1080
|
}
|
|
1104
|
-
return doc.toObject();
|
|
1105
1081
|
});
|
|
1106
1082
|
});
|
|
1107
1083
|
}
|
|
@@ -21,22 +21,19 @@ const credentials_1 = require("../credentials");
|
|
|
21
21
|
*/
|
|
22
22
|
function getToken(params) {
|
|
23
23
|
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
validFrom: now,
|
|
30
|
-
validThrough: now
|
|
31
|
-
});
|
|
32
|
-
const authorization = authorizations.shift();
|
|
33
|
-
if (authorization === undefined) {
|
|
34
|
-
throw new factory.errors.NotFound('Authorization');
|
|
24
|
+
if (typeof params.project.id !== 'string' || params.project.id.length === 0) {
|
|
25
|
+
throw new factory.errors.ArgumentNull('project.id');
|
|
26
|
+
}
|
|
27
|
+
if (typeof params.code !== 'string' || params.code.length === 0) {
|
|
28
|
+
throw new factory.errors.ArgumentNull('code');
|
|
35
29
|
}
|
|
36
|
-
const
|
|
30
|
+
const authorizationObject = yield repos.authorization.findValidObjectByCode({
|
|
31
|
+
project: { id: params.project.id },
|
|
32
|
+
code: params.code
|
|
33
|
+
});
|
|
37
34
|
return new Promise((resolve, reject) => {
|
|
38
35
|
// 所有権を暗号化する
|
|
39
|
-
jwt.sign(
|
|
36
|
+
jwt.sign(authorizationObject, credentials_1.credentials.jwt.secret,
|
|
40
37
|
// params.secret,
|
|
41
38
|
{
|
|
42
39
|
issuer: credentials_1.credentials.jwt.issuer,
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import * as factory from '../../factory';
|
|
2
|
-
import type { MongoRepository as AcceptedOfferRepo } from '../../repo/acceptedOffer';
|
|
3
2
|
import type { MongoRepository as AuthorizationRepo } from '../../repo/code';
|
|
3
|
+
import type { MongoRepository as OrderRepo } from '../../repo/order';
|
|
4
4
|
import type { MongoRepository as ReservationRepo } from '../../repo/reservation';
|
|
5
5
|
type AvailableReservationType = factory.reservationType.BusReservation | factory.reservationType.EventReservation;
|
|
6
6
|
type IReservationResult = Pick<factory.reservation.IReservation<AvailableReservationType>, 'id' | 'additionalTicketText' | 'reservationStatus'> & {
|
|
7
7
|
reservedTicket: {
|
|
8
|
-
ticketType: Pick<factory.reservation.ITicketType<AvailableReservationType>, 'identifier'
|
|
8
|
+
ticketType: Pick<factory.reservation.ITicketType<AvailableReservationType>, 'identifier'> & {
|
|
9
|
+
name: {
|
|
10
|
+
ja?: string;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
9
13
|
};
|
|
10
14
|
};
|
|
11
15
|
declare function findByCode(params: {
|
|
@@ -20,9 +24,12 @@ declare function findByCode(params: {
|
|
|
20
24
|
* 注文コード
|
|
21
25
|
*/
|
|
22
26
|
code: string;
|
|
27
|
+
seller?: {
|
|
28
|
+
id?: string;
|
|
29
|
+
};
|
|
23
30
|
}): (repos: {
|
|
24
|
-
acceptedOffer: AcceptedOfferRepo;
|
|
25
31
|
authorization: AuthorizationRepo;
|
|
32
|
+
order: OrderRepo;
|
|
26
33
|
reservation: ReservationRepo;
|
|
27
34
|
}) => Promise<{
|
|
28
35
|
reservation: IReservationResult;
|
|
@@ -13,78 +13,49 @@ exports.findByCode = void 0;
|
|
|
13
13
|
const factory = require("../../factory");
|
|
14
14
|
function findByCode(params) {
|
|
15
15
|
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
16
|
-
var _a
|
|
16
|
+
var _a;
|
|
17
17
|
if (typeof params.id !== 'string' || params.id.length === 0) {
|
|
18
18
|
throw new factory.errors.ArgumentNull('id');
|
|
19
19
|
}
|
|
20
20
|
if (typeof params.code !== 'string' || params.code.length === 0) {
|
|
21
21
|
throw new factory.errors.ArgumentNull('code');
|
|
22
22
|
}
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
validThrough: now
|
|
30
|
-
})).shift();
|
|
31
|
-
if (authorization === undefined) {
|
|
32
|
-
throw new factory.errors.NotFound('Authorization');
|
|
33
|
-
}
|
|
34
|
-
let reservationIdInOrder;
|
|
35
|
-
let reservationTypeInOrder;
|
|
36
|
-
let offeredThroughIdentifier = factory.service.webAPI.Identifier.Chevre;
|
|
37
|
-
const data = authorization.object;
|
|
38
|
-
switch (data.typeOf) {
|
|
23
|
+
const reservationId = String(params.id);
|
|
24
|
+
const authorizationObject = yield repos.authorization.findValidObjectByCode({
|
|
25
|
+
project: { id: params.project.id },
|
|
26
|
+
code: params.code
|
|
27
|
+
});
|
|
28
|
+
switch (authorizationObject.typeOf) {
|
|
39
29
|
case factory.order.OrderType.Order:
|
|
40
|
-
const { orderNumber } =
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if (itemOfferedTypeOf === factory.reservationType.BusReservation
|
|
50
|
-
|| itemOfferedTypeOf === factory.reservationType.EventReservation) {
|
|
51
|
-
reservationIdInOrder = acceptedOffer === null || acceptedOffer === void 0 ? void 0 : acceptedOffer.itemOffered.id;
|
|
52
|
-
reservationTypeInOrder = itemOfferedTypeOf;
|
|
53
|
-
offeredThroughIdentifier = (_a = acceptedOffer === null || acceptedOffer === void 0 ? void 0 : acceptedOffer.offeredThrough) === null || _a === void 0 ? void 0 : _a.identifier;
|
|
30
|
+
const { orderNumber } = authorizationObject;
|
|
31
|
+
if (typeof orderNumber === 'string' && orderNumber.length > 0) {
|
|
32
|
+
// reservationIdを含む注文の存在を確認するだけでよい
|
|
33
|
+
yield repos.order.findByOrderNumberAndReservationId({
|
|
34
|
+
project: { id: params.project.id },
|
|
35
|
+
orderNumber,
|
|
36
|
+
reservationId,
|
|
37
|
+
seller: params.seller
|
|
38
|
+
});
|
|
54
39
|
}
|
|
55
40
|
break;
|
|
56
41
|
default:
|
|
57
|
-
throw new factory.errors.NotImplemented(`authorization object typeOf: ${
|
|
42
|
+
throw new factory.errors.NotImplemented(`authorization object typeOf: ${authorizationObject.typeOf} not implemented`);
|
|
58
43
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const { id, additionalTicketText, reservationStatus, reservedTicket } = reservationFromRepo;
|
|
73
|
-
reservation = {
|
|
74
|
-
id, additionalTicketText, reservationStatus,
|
|
75
|
-
reservedTicket: {
|
|
76
|
-
ticketType: {
|
|
77
|
-
identifier: reservedTicket === null || reservedTicket === void 0 ? void 0 : reservedTicket.ticketType.identifier,
|
|
78
|
-
name: { ja: (_b = reservedTicket === null || reservedTicket === void 0 ? void 0 : reservedTicket.ticketType.name) === null || _b === void 0 ? void 0 : _b.ja }
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
}
|
|
44
|
+
const reservationFromRepo = yield repos.reservation.findById({
|
|
45
|
+
id: reservationId,
|
|
46
|
+
inclusion: ['id', 'additionalTicketText', 'reservationStatus', 'reservedTicket'],
|
|
47
|
+
exclusion: []
|
|
48
|
+
});
|
|
49
|
+
const { id, additionalTicketText, reservationStatus, reservedTicket } = reservationFromRepo;
|
|
50
|
+
const reservation = {
|
|
51
|
+
id, additionalTicketText, reservationStatus,
|
|
52
|
+
reservedTicket: {
|
|
53
|
+
ticketType: {
|
|
54
|
+
identifier: reservedTicket.ticketType.identifier,
|
|
55
|
+
name: { ja: (_a = reservedTicket.ticketType.name) === null || _a === void 0 ? void 0 : _a.ja }
|
|
56
|
+
}
|
|
83
57
|
}
|
|
84
|
-
}
|
|
85
|
-
if (reservation === undefined) {
|
|
86
|
-
throw new factory.errors.NotFound('Reservation');
|
|
87
|
-
}
|
|
58
|
+
};
|
|
88
59
|
return { reservation };
|
|
89
60
|
});
|
|
90
61
|
}
|
|
@@ -18,13 +18,10 @@ export declare function useReservation(params: {
|
|
|
18
18
|
*/
|
|
19
19
|
id: string;
|
|
20
20
|
};
|
|
21
|
-
instrument?:
|
|
22
|
-
token?: string;
|
|
23
|
-
};
|
|
21
|
+
instrument?: Pick<factory.action.consume.use.reservation.IInstrument, 'ticketToken' | 'token'>;
|
|
24
22
|
location?: {
|
|
25
23
|
identifier?: string;
|
|
26
24
|
};
|
|
27
|
-
verifyToken: boolean;
|
|
28
25
|
}): (repos: {
|
|
29
26
|
action: ActionRepo;
|
|
30
27
|
assetTransaction: AssetTransactionRepo;
|
|
@@ -14,7 +14,6 @@ const createDebug = require("debug");
|
|
|
14
14
|
const factory = require("../../factory");
|
|
15
15
|
const confirmReservation_1 = require("./confirmReservation");
|
|
16
16
|
const onReservationUsed_1 = require("./potentialActions/onReservationUsed");
|
|
17
|
-
const verifyToken4reservation_1 = require("./verifyToken4reservation");
|
|
18
17
|
const debug = createDebug('chevre-domain:service:reserve:useReservation');
|
|
19
18
|
/**
|
|
20
19
|
* 予約使用
|
|
@@ -22,21 +21,23 @@ const debug = createDebug('chevre-domain:service:reserve:useReservation');
|
|
|
22
21
|
// tslint:disable-next-line:max-func-body-length
|
|
23
22
|
function useReservation(params) {
|
|
24
23
|
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
25
|
-
var _a, _b;
|
|
24
|
+
var _a, _b, _c;
|
|
26
25
|
const now = new Date();
|
|
27
26
|
const reservationId = params.object.id;
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
27
|
+
const ticketToken = (_a = params === null || params === void 0 ? void 0 : params.instrument) === null || _a === void 0 ? void 0 : _a.ticketToken;
|
|
28
|
+
const token = (_b = params === null || params === void 0 ? void 0 : params.instrument) === null || _b === void 0 ? void 0 : _b.token;
|
|
29
|
+
// タスク作成前に検証済なので検証不要
|
|
30
|
+
// if (params.verifyToken === true) {
|
|
31
|
+
// // instrument?.tokenを検証
|
|
32
|
+
// if (typeof token === 'string') {
|
|
33
|
+
// await verifyToken4reservation({
|
|
34
|
+
// project: { id: params.project.id },
|
|
35
|
+
// agent: params.agent,
|
|
36
|
+
// reservationId,
|
|
37
|
+
// token
|
|
38
|
+
// })({ order: repos.order });
|
|
39
|
+
// }
|
|
40
|
+
// }
|
|
40
41
|
// confirmReservationが間に合わない可能性を考慮する(2023-06-01~)
|
|
41
42
|
yield reserveIfNotYet({ object: params.object })(repos);
|
|
42
43
|
// 予約検索
|
|
@@ -54,10 +55,10 @@ function useReservation(params) {
|
|
|
54
55
|
reservedTicket: reservation.reservedTicket,
|
|
55
56
|
typeOf: reservation.typeOf
|
|
56
57
|
};
|
|
57
|
-
const actionAttributes = Object.assign({ project: reservation.project, typeOf: factory.actionType.UseAction, agent: params.agent, instrument: Object.assign(Object.assign({}, (typeof token === 'string') ? { token } : undefined), { typeOf: factory.action.check.token.ObjectType.Ticket }),
|
|
58
|
+
const actionAttributes = Object.assign({ project: reservation.project, typeOf: factory.actionType.UseAction, agent: params.agent, instrument: Object.assign(Object.assign(Object.assign({}, (typeof token === 'string') ? { token } : undefined), (typeof ticketToken === 'string') ? { ticketToken } : undefined), { typeOf: factory.action.check.token.ObjectType.Ticket }),
|
|
58
59
|
// object最適化(2023-01-30~)
|
|
59
60
|
// どの予約を
|
|
60
|
-
object: [reservationAsObject] }, (typeof ((
|
|
61
|
+
object: [reservationAsObject] }, (typeof ((_c = params.location) === null || _c === void 0 ? void 0 : _c.identifier) === 'string')
|
|
61
62
|
? {
|
|
62
63
|
location: {
|
|
63
64
|
typeOf: factory.placeType.Place,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as factory from '../../factory';
|
|
2
|
+
import type { MongoRepository as AuthorizationRepo } from '../../repo/code';
|
|
2
3
|
import type { MongoRepository as OrderRepo } from '../../repo/order';
|
|
3
4
|
/**
|
|
4
5
|
* 予約使用のためのチケットトークンを検証する
|
|
@@ -12,7 +13,17 @@ export declare function verifyToken4reservation(params: {
|
|
|
12
13
|
};
|
|
13
14
|
agent: factory.action.check.token.IAgent;
|
|
14
15
|
reservationId: string;
|
|
15
|
-
|
|
16
|
+
ticket: {
|
|
17
|
+
/**
|
|
18
|
+
* JWT
|
|
19
|
+
*/
|
|
20
|
+
token?: string;
|
|
21
|
+
/**
|
|
22
|
+
* 承認コード
|
|
23
|
+
*/
|
|
24
|
+
ticketToken?: string;
|
|
25
|
+
};
|
|
16
26
|
}): (repos: {
|
|
27
|
+
authorization: AuthorizationRepo;
|
|
17
28
|
order: OrderRepo;
|
|
18
29
|
}) => Promise<void>;
|
|
@@ -17,17 +17,35 @@ const code_1 = require("../code");
|
|
|
17
17
|
*/
|
|
18
18
|
function verifyToken4reservation(params) {
|
|
19
19
|
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
// JWTと承認コードの両方に対応する(2024-02-28~)
|
|
21
|
+
const { token, ticketToken } = params.ticket;
|
|
22
|
+
let payload;
|
|
23
|
+
if (typeof token === 'string' && token.length > 0) {
|
|
24
|
+
payload = yield (0, code_1.verifyToken)({
|
|
25
|
+
project: params.project,
|
|
26
|
+
agent: params.agent,
|
|
27
|
+
token
|
|
28
|
+
})({});
|
|
29
|
+
}
|
|
30
|
+
else if (typeof ticketToken === 'string' && ticketToken.length > 0) {
|
|
31
|
+
payload = yield repos.authorization.findValidObjectByCode({
|
|
32
|
+
project: { id: params.project.id },
|
|
33
|
+
code: ticketToken
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
throw new factory.errors.ArgumentNull('ticket.token or ticket.ticketToken');
|
|
38
|
+
}
|
|
25
39
|
switch (payload.typeOf) {
|
|
26
40
|
case factory.order.OrderType.Order:
|
|
41
|
+
const { orderNumber } = payload;
|
|
42
|
+
if (typeof orderNumber !== 'string' || orderNumber.length === 0) {
|
|
43
|
+
throw new factory.errors.NotFound('payload.orderNumber');
|
|
44
|
+
}
|
|
27
45
|
// reservationIdを含む注文の存在を確認するだけでよい(2023-01-31~)
|
|
28
46
|
const order = yield repos.order.findByOrderNumberAndReservationId({
|
|
29
47
|
project: { id: params.project.id },
|
|
30
|
-
orderNumber
|
|
48
|
+
orderNumber,
|
|
31
49
|
reservationId: params.reservationId,
|
|
32
50
|
seller: params.seller
|
|
33
51
|
});
|
|
@@ -7,6 +7,5 @@ import { checkInReservation } from './reserve/checkInReservation';
|
|
|
7
7
|
import { confirmReservation } from './reserve/confirmReservation';
|
|
8
8
|
import { findByCode } from './reserve/findByCode';
|
|
9
9
|
import { searchByOrder } from './reserve/searchByOrder';
|
|
10
|
-
import { useReservation } from './reserve/useReservation';
|
|
11
10
|
import { verifyToken4reservation } from './reserve/verifyToken4reservation';
|
|
12
|
-
export { maskUnderName, cancelPendingReservation, cancelReservation, checkInReservation, confirmReservation, findByCode, searchByOrder,
|
|
11
|
+
export { maskUnderName, cancelPendingReservation, cancelReservation, checkInReservation, confirmReservation, findByCode, searchByOrder, verifyToken4reservation };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.verifyToken4reservation = exports.
|
|
3
|
+
exports.verifyToken4reservation = exports.searchByOrder = exports.findByCode = exports.confirmReservation = exports.checkInReservation = exports.cancelReservation = exports.cancelPendingReservation = exports.maskUnderName = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* 予約サービス
|
|
6
6
|
*/
|
|
@@ -17,7 +17,6 @@ const findByCode_1 = require("./reserve/findByCode");
|
|
|
17
17
|
Object.defineProperty(exports, "findByCode", { enumerable: true, get: function () { return findByCode_1.findByCode; } });
|
|
18
18
|
const searchByOrder_1 = require("./reserve/searchByOrder");
|
|
19
19
|
Object.defineProperty(exports, "searchByOrder", { enumerable: true, get: function () { return searchByOrder_1.searchByOrder; } });
|
|
20
|
-
|
|
21
|
-
Object.defineProperty(exports, "useReservation", { enumerable: true, get: function () { return useReservation_1.useReservation; } });
|
|
20
|
+
// import { useReservation } from './reserve/useReservation';
|
|
22
21
|
const verifyToken4reservation_1 = require("./reserve/verifyToken4reservation");
|
|
23
22
|
Object.defineProperty(exports, "verifyToken4reservation", { enumerable: true, get: function () { return verifyToken4reservation_1.verifyToken4reservation; } });
|
|
@@ -49,9 +49,9 @@ function onAuthorizationCreated(params) {
|
|
|
49
49
|
let reservationNumbers = [];
|
|
50
50
|
// 発券対象イベントID
|
|
51
51
|
let reservationForIds = [];
|
|
52
|
-
const authorizationObject = yield repos.code.
|
|
52
|
+
const authorizationObject = yield repos.code.findValidObjectByCode({
|
|
53
53
|
code: params.code,
|
|
54
|
-
project: { id: params.project.id
|
|
54
|
+
project: { id: params.project.id }
|
|
55
55
|
});
|
|
56
56
|
switch (authorizationObject.typeOf) {
|
|
57
57
|
case factory.order.OrderType.Order:
|
|
@@ -15,16 +15,14 @@ const assetTransaction_1 = require("../../repo/assetTransaction");
|
|
|
15
15
|
const order_1 = require("../../repo/order");
|
|
16
16
|
const reservation_1 = require("../../repo/reservation");
|
|
17
17
|
const task_1 = require("../../repo/task");
|
|
18
|
-
const
|
|
18
|
+
const useReservation_1 = require("../reserve/useReservation");
|
|
19
19
|
/**
|
|
20
20
|
* タスク実行関数
|
|
21
21
|
*/
|
|
22
22
|
function call(data) {
|
|
23
23
|
return (settings) => __awaiter(this, void 0, void 0, function* () {
|
|
24
24
|
var _a, _b;
|
|
25
|
-
yield (0,
|
|
26
|
-
// タスク作成前に検証済なので検証不要
|
|
27
|
-
verifyToken: false }, (typeof ((_a = data.instrument) === null || _a === void 0 ? void 0 : _a.typeOf) === 'string') ? { instrument: data.instrument } : undefined), (typeof ((_b = data.location) === null || _b === void 0 ? void 0 : _b.typeOf) === 'string') ? { location: data.location } : undefined))({
|
|
25
|
+
yield (0, useReservation_1.useReservation)(Object.assign(Object.assign({ project: data.project, agent: data.agent, object: data.object }, (typeof ((_a = data.instrument) === null || _a === void 0 ? void 0 : _a.typeOf) === 'string') ? { instrument: data.instrument } : undefined), (typeof ((_b = data.location) === null || _b === void 0 ? void 0 : _b.typeOf) === 'string') ? { location: data.location } : undefined))({
|
|
28
26
|
action: new action_1.MongoRepository(settings.connection),
|
|
29
27
|
assetTransaction: new assetTransaction_1.MongoRepository(settings.connection),
|
|
30
28
|
order: new order_1.MongoRepository(settings.connection),
|
package/package.json
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
],
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@aws-sdk/credential-providers": "3.433.0",
|
|
13
|
-
"@chevre/factory": "4.
|
|
13
|
+
"@chevre/factory": "4.358.0",
|
|
14
14
|
"@cinerino/sdk": "5.12.0",
|
|
15
15
|
"@motionpicture/coa-service": "9.3.0-alpha.5",
|
|
16
16
|
"@motionpicture/gmo-service": "5.3.0-alpha.4",
|
|
@@ -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": "21.
|
|
113
|
+
"version": "21.24.1"
|
|
114
114
|
}
|