@chevre/domain 21.26.0-alpha.3 → 21.26.0-alpha.4
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/migrateOrderSeller.ts +65 -0
- package/example/src/mvtkMessage.ts +11 -0
- package/lib/chevre/errorHandler.d.ts +1 -0
- package/lib/chevre/errorHandler.js +3 -2
- package/lib/chevre/service/notification/factory.js +29 -18
- package/lib/chevre/service/payment/movieTicket.js +18 -8
- package/package.json +1 -1
|
@@ -0,0 +1,65 @@
|
|
|
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
|
+
|
|
9
|
+
// tslint:disable-next-line:max-func-body-length
|
|
10
|
+
async function main() {
|
|
11
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
12
|
+
|
|
13
|
+
const orderRepo = await chevre.repository.Order.createInstance(mongoose.connection);
|
|
14
|
+
|
|
15
|
+
const cursor = orderRepo.getCursor(
|
|
16
|
+
{
|
|
17
|
+
orderDate: {
|
|
18
|
+
$gte: moment()
|
|
19
|
+
// tslint:disable-next-line:no-magic-numbers
|
|
20
|
+
.add(-12, 'months')
|
|
21
|
+
.toDate()
|
|
22
|
+
// $lte: moment()
|
|
23
|
+
// // tslint:disable-next-line:no-magic-numbers
|
|
24
|
+
// .add(-6, 'months')
|
|
25
|
+
// .toDate()
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
orderDate: 1,
|
|
30
|
+
orderNumber: 1,
|
|
31
|
+
project: 1,
|
|
32
|
+
seller: 1
|
|
33
|
+
}
|
|
34
|
+
);
|
|
35
|
+
console.log('orders found');
|
|
36
|
+
|
|
37
|
+
let i = 0;
|
|
38
|
+
let updateCount = 0;
|
|
39
|
+
await cursor.eachAsync(async (doc) => {
|
|
40
|
+
i += 1;
|
|
41
|
+
const order: Pick<
|
|
42
|
+
chevre.factory.order.IOrder,
|
|
43
|
+
'orderDate' | 'orderNumber' | 'project' | 'seller'
|
|
44
|
+
> = doc.toObject();
|
|
45
|
+
console.log(order);
|
|
46
|
+
|
|
47
|
+
const alreadyMigrated = (<any>order.seller).telephone === undefined
|
|
48
|
+
&& (<any>order.seller).url === undefined;
|
|
49
|
+
|
|
50
|
+
if (alreadyMigrated) {
|
|
51
|
+
console.log('already exist.', order.project.id, order.orderNumber, order.orderDate, i, updateCount);
|
|
52
|
+
} else {
|
|
53
|
+
console.log('updating...', order.project.id, order.orderNumber, order.orderDate, i, updateCount);
|
|
54
|
+
updateCount += 1;
|
|
55
|
+
console.log('updated.', order.project.id, order.orderNumber, order.orderDate, i, updateCount);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
console.log(i, 'orders checked');
|
|
60
|
+
console.log(updateCount, 'orders updated');
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
main()
|
|
64
|
+
.then()
|
|
65
|
+
.catch(console.error);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
|
|
3
|
+
const paymentMethodId = '792943638208219';
|
|
4
|
+
const message = `{\"message\":\"bookingNo:\\\"${paymentMethodId}\\\" が見つかりません。\"}`;
|
|
5
|
+
console.log(JSON.parse(message));
|
|
6
|
+
|
|
7
|
+
const error = { message: `bookingNo:"${paymentMethodId}" が見つかりません。` };
|
|
8
|
+
const expectedMessage4surfrockNotFound = JSON.stringify(error);
|
|
9
|
+
console.log(expectedMessage4surfrockNotFound);
|
|
10
|
+
|
|
11
|
+
console.log(expectedMessage4surfrockNotFound === message);
|
|
@@ -14,6 +14,7 @@ export declare function handleCOAError(error: any): Error;
|
|
|
14
14
|
* 可能であればChevreエラーへ変換します
|
|
15
15
|
*/
|
|
16
16
|
export declare function handlePecorinoError(error: any): Error;
|
|
17
|
+
export declare const MOVIE_TICKET_RESERVE_REQUEST_ERROR_NAME = "MovieticketReserveRequestError";
|
|
17
18
|
/**
|
|
18
19
|
* ムビチケ着券サービスエラーをハンドリングする
|
|
19
20
|
* 可能であればChevreエラーへ変換します
|
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.handleAWSError = exports.handleMvtkReserveError = exports.handlePecorinoError = exports.handleCOAError = exports.handleMongoError = exports.isMongoError = exports.MongoErrorCode = void 0;
|
|
12
|
+
exports.handleAWSError = exports.handleMvtkReserveError = exports.MOVIE_TICKET_RESERVE_REQUEST_ERROR_NAME = exports.handlePecorinoError = exports.handleCOAError = exports.handleMongoError = exports.isMongoError = exports.MongoErrorCode = void 0;
|
|
13
13
|
/**
|
|
14
14
|
* エラーハンドラー
|
|
15
15
|
* 外部サービスと連携している場合に、サービス(API)のエラーを本ドメインのエラーに変換する責任を担います。
|
|
@@ -115,6 +115,7 @@ function handlePecorinoError(error) {
|
|
|
115
115
|
return handledError;
|
|
116
116
|
}
|
|
117
117
|
exports.handlePecorinoError = handlePecorinoError;
|
|
118
|
+
exports.MOVIE_TICKET_RESERVE_REQUEST_ERROR_NAME = 'MovieticketReserveRequestError';
|
|
118
119
|
/**
|
|
119
120
|
* ムビチケ着券サービスエラーをハンドリングする
|
|
120
121
|
* 可能であればChevreエラーへ変換します
|
|
@@ -122,7 +123,7 @@ exports.handlePecorinoError = handlePecorinoError;
|
|
|
122
123
|
// tslint:disable-next-line:no-any
|
|
123
124
|
function handleMvtkReserveError(error) {
|
|
124
125
|
let handledError = error;
|
|
125
|
-
if (error.name ===
|
|
126
|
+
if (error.name === exports.MOVIE_TICKET_RESERVE_REQUEST_ERROR_NAME) {
|
|
126
127
|
// ムビチケAPIのステータスコード4xxをハンドリング
|
|
127
128
|
// ムビチケAPIのレスポンスステータスコードが4xxであればクライアントエラー
|
|
128
129
|
const message = `${error.name}:${error.message}`;
|
|
@@ -32,26 +32,37 @@ lastMessage:${lastMessage}`;
|
|
|
32
32
|
exports.task2lineNotify = task2lineNotify;
|
|
33
33
|
const MAX_LAST_MESSAGE_LENGTH = 20;
|
|
34
34
|
function tasks2lineNotify(params) {
|
|
35
|
-
|
|
36
|
-
content =
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
35
|
+
const subject = `${params.tasks.length} ${exports.ABORT_REPORT_SUBJECT}`;
|
|
36
|
+
let content = subject;
|
|
37
|
+
// あまりに通知タスク数が多いケースに対応
|
|
38
|
+
// tslint:disable-next-line:no-magic-numbers
|
|
39
|
+
if (params.tasks.length > 10) {
|
|
40
|
+
content = params.tasks.map((task) => {
|
|
41
|
+
return `project:${task.project.id}
|
|
42
|
+
id:${task.id}
|
|
43
|
+
name:${task.name}`;
|
|
44
|
+
})
|
|
45
|
+
.join('\n');
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
// tslint:disable-next-line:no-magic-numbers
|
|
49
|
+
const maxLastMessageLength = (params.tasks.length <= 5) ? 80 : MAX_LAST_MESSAGE_LENGTH; // 通知タスク数に応じてメッセージ長を調整
|
|
50
|
+
content = params.tasks.map((task) => {
|
|
51
|
+
const lastExecutionResult = (task.executionResults.length > 0) ? task.executionResults.slice(-1)[0] : undefined;
|
|
52
|
+
let lastError = lastExecutionResult === null || lastExecutionResult === void 0 ? void 0 : lastExecutionResult.error;
|
|
53
|
+
if (typeof lastError === 'string') {
|
|
54
|
+
lastError = { message: lastError, name: 'Error' };
|
|
55
|
+
}
|
|
56
|
+
const lastMessage = `${String(lastError === null || lastError === void 0 ? void 0 : lastError.name)} ${String(lastError === null || lastError === void 0 ? void 0 : lastError.message)}`;
|
|
57
|
+
return `project:${task.project.id}
|
|
45
58
|
id:${task.id}
|
|
46
59
|
name:${task.name}
|
|
47
60
|
runsAt:${moment(task.runsAt)
|
|
48
|
-
|
|
49
|
-
lastMessage:${lastMessage.slice(0,
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
content: content
|
|
55
|
-
};
|
|
61
|
+
.toISOString()}
|
|
62
|
+
lastMessage:${lastMessage.slice(0, maxLastMessageLength)}...`;
|
|
63
|
+
})
|
|
64
|
+
.join('\n');
|
|
65
|
+
}
|
|
66
|
+
return { subject, content };
|
|
56
67
|
}
|
|
57
68
|
exports.tasks2lineNotify = tasks2lineNotify;
|
|
@@ -14,6 +14,7 @@ exports.voidTransaction = exports.refundMovieTicket = exports.payMovieTicket = e
|
|
|
14
14
|
* 決済サービス
|
|
15
15
|
*/
|
|
16
16
|
const surfrock = require("@surfrock/sdk");
|
|
17
|
+
const http_status_1 = require("http-status");
|
|
17
18
|
const credentials_1 = require("../../credentials");
|
|
18
19
|
const factory = require("../../factory");
|
|
19
20
|
const checkByIdentifier_1 = require("./movieTicket/checkByIdentifier");
|
|
@@ -23,6 +24,12 @@ const validation_1 = require("./movieTicket/validation");
|
|
|
23
24
|
const errorHandler_1 = require("../../errorHandler");
|
|
24
25
|
const onPaid_1 = require("./any/onPaid");
|
|
25
26
|
const onRefund_1 = require("./any/onRefund");
|
|
27
|
+
var MovieticketReserveRequestErrorMessage;
|
|
28
|
+
(function (MovieticketReserveRequestErrorMessage) {
|
|
29
|
+
MovieticketReserveRequestErrorMessage["AlreadyPaid"] = "\u65E2\u306B\u5B58\u5728\u3059\u308B\u8208\u884C\u30B7\u30B9\u30C6\u30E0\u5EA7\u5E2D\u4E88\u7D04\u756A\u53F7\u304C\u5165\u529B\u3055\u308C\u307E\u3057\u305F\u3002";
|
|
30
|
+
MovieticketReserveRequestErrorMessage["NotFound"] = "\u5B58\u5728\u3057\u306A\u3044\u8208\u884C\u4F1A\u793E\u30B7\u30B9\u30C6\u30E0\u5EA7\u5E2D\u4E88\u7D04\u756A\u53F7\u304C\u5165\u529B\u3055\u308C\u307E\u3057\u305F\u3002";
|
|
31
|
+
MovieticketReserveRequestErrorMessage["ReservationResult19"] = "ReservationResult 19";
|
|
32
|
+
})(MovieticketReserveRequestErrorMessage || (MovieticketReserveRequestErrorMessage = {}));
|
|
26
33
|
/**
|
|
27
34
|
* MovieTicket認証
|
|
28
35
|
*/
|
|
@@ -250,9 +257,8 @@ function payMovieTicket(params) {
|
|
|
250
257
|
catch (error) {
|
|
251
258
|
let throwsError = true;
|
|
252
259
|
// 「既に存在する興行システム座席予約番号が入力されました」の場合、着券済なのでok
|
|
253
|
-
if (error.name ===
|
|
254
|
-
|
|
255
|
-
if (error.code === 400 && error.message === '既に存在する興行システム座席予約番号が入力されました。') {
|
|
260
|
+
if (error.name === errorHandler_1.MOVIE_TICKET_RESERVE_REQUEST_ERROR_NAME) {
|
|
261
|
+
if (error.code === http_status_1.BAD_REQUEST && error.message === MovieticketReserveRequestErrorMessage.AlreadyPaid) {
|
|
256
262
|
seatInfoSyncResult = error;
|
|
257
263
|
throwsError = false;
|
|
258
264
|
}
|
|
@@ -366,15 +372,19 @@ function refundMovieTicket(params) {
|
|
|
366
372
|
catch (error) {
|
|
367
373
|
let throwsError = true;
|
|
368
374
|
// 「存在しない興行会社システム座席予約番号が入力されました」の場合、取消済なのでok
|
|
369
|
-
if (error.name ===
|
|
370
|
-
|
|
371
|
-
if (error.code === 400 && error.message === '存在しない興行会社システム座席予約番号が入力されました。') {
|
|
375
|
+
if (error.name === errorHandler_1.MOVIE_TICKET_RESERVE_REQUEST_ERROR_NAME) {
|
|
376
|
+
if (error.code === http_status_1.BAD_REQUEST && error.message === MovieticketReserveRequestErrorMessage.NotFound) {
|
|
372
377
|
seatInfoSyncResult = error;
|
|
373
378
|
throwsError = false;
|
|
374
379
|
}
|
|
375
380
|
// ReservationResult 19の内容が不明だがリトライする意味はおそらくないパターン
|
|
376
|
-
|
|
377
|
-
|
|
381
|
+
if (error.code === http_status_1.BAD_REQUEST && error.message === MovieticketReserveRequestErrorMessage.ReservationResult19) {
|
|
382
|
+
seatInfoSyncResult = error;
|
|
383
|
+
throwsError = false;
|
|
384
|
+
}
|
|
385
|
+
// surfrock: bookingNoが存在しないケースをハンドル(2024-03-13~)
|
|
386
|
+
const expectedMessage4surfrockNotFound = JSON.stringify({ message: `bookingNo:"${paymentMethodId}" が見つかりません。` });
|
|
387
|
+
if (error.code === http_status_1.BAD_REQUEST && error.message === expectedMessage4surfrockNotFound) {
|
|
378
388
|
seatInfoSyncResult = error;
|
|
379
389
|
throwsError = false;
|
|
380
390
|
}
|
package/package.json
CHANGED