@chevre/domain 21.1.0-alpha.2 → 21.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/publishConfirmationNumber.ts +27 -0
- package/lib/chevre/repo/action/registerServiceInProgress.js +2 -5
- package/lib/chevre/repo/confirmationNumber.js +7 -7
- package/lib/chevre/repo/itemAvailability/screeningEvent.js +2 -3
- package/lib/chevre/repo/orderNumber.js +7 -8
- package/lib/chevre/repo/serviceOutputIdentifier.js +3 -8
- package/lib/chevre/repo/transactionNumber.js +4 -18
- package/package.json +1 -1
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
import * as redis from 'redis';
|
|
3
|
+
|
|
4
|
+
import { chevre } from '../../../lib/index';
|
|
5
|
+
|
|
6
|
+
// const project = { id: String(process.env.PROJECT_ID) };
|
|
7
|
+
|
|
8
|
+
// tslint:disable-next-line:max-func-body-length
|
|
9
|
+
async function main() {
|
|
10
|
+
const client = redis.createClient<redis.RedisDefaultModules, Record<string, never>, Record<string, never>>({
|
|
11
|
+
socket: {
|
|
12
|
+
host: process.env.REDIS_HOST,
|
|
13
|
+
port: Number(process.env.REDIS_PORT)
|
|
14
|
+
},
|
|
15
|
+
password: process.env.REDIS_KEY
|
|
16
|
+
});
|
|
17
|
+
await client.connect();
|
|
18
|
+
|
|
19
|
+
const confirmationNumberRepo = new chevre.repository.ConfirmationNumber(client);
|
|
20
|
+
await confirmationNumberRepo.publish({ orderDate: new Date() });
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
main()
|
|
24
|
+
.then(() => {
|
|
25
|
+
console.log('success!');
|
|
26
|
+
})
|
|
27
|
+
.catch(console.error);
|
|
@@ -10,8 +10,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.RedisRepository = void 0;
|
|
13
|
-
const createDebug = require("debug");
|
|
14
|
-
const debug = createDebug('chevre:repository');
|
|
15
13
|
/**
|
|
16
14
|
* 進行中サービス登録アクションリポジトリ
|
|
17
15
|
*/
|
|
@@ -26,14 +24,13 @@ class RedisRepository {
|
|
|
26
24
|
return __awaiter(this, void 0, void 0, function* () {
|
|
27
25
|
const key = `${RedisRepository.KEY_PREFIX}:${progressKey.agent.id}:${progressKey.product.id}`;
|
|
28
26
|
const ttl = 7200;
|
|
29
|
-
|
|
30
|
-
const results = yield this.redisClient.multi()
|
|
27
|
+
const [setNXReply] = yield this.redisClient.multi()
|
|
31
28
|
.setNX(key, holder)
|
|
32
29
|
.expire(key, ttl)
|
|
33
30
|
.exec();
|
|
34
31
|
// tslint:disable-next-line:no-single-line-block-comment
|
|
35
32
|
/* istanbul ignore else: please write tests */
|
|
36
|
-
if (
|
|
33
|
+
if (setNXReply === 1 || setNXReply === true) {
|
|
37
34
|
return true;
|
|
38
35
|
}
|
|
39
36
|
else {
|
|
@@ -44,18 +44,18 @@ class RedisRepository {
|
|
|
44
44
|
const key = util.format('%s:%s', RedisRepository.REDIS_KEY_PREFIX, moment(params.orderDate)
|
|
45
45
|
.tz('Asia/Tokyo')
|
|
46
46
|
.format('YYMM'));
|
|
47
|
-
const
|
|
47
|
+
const [incrReply] = yield this.redisClient.multi()
|
|
48
48
|
.incr(key)
|
|
49
49
|
.expire(key, TTL)
|
|
50
50
|
.exec();
|
|
51
|
-
if (!Array.isArray(results)) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
51
|
+
// if (!Array.isArray(results)) {
|
|
52
|
+
// // なぜかresults: nullのことがあるのでハンドリング
|
|
53
|
+
// throw new factory.errors.ServiceUnavailable('incr confirmationNumber result not array');
|
|
54
|
+
// }
|
|
55
55
|
// tslint:disable-next-line:no-single-line-block-comment
|
|
56
56
|
/* istanbul ignore else: please write tests */
|
|
57
|
-
if (typeof
|
|
58
|
-
const no =
|
|
57
|
+
if (typeof incrReply === 'number') {
|
|
58
|
+
const no = incrReply;
|
|
59
59
|
// debug('no incremented.', no);
|
|
60
60
|
// 桁数調整
|
|
61
61
|
let confirmationNumber = RedisRepository.ALIGN_DIGITS(String(no));
|
|
@@ -83,7 +83,7 @@ class RedisRepository {
|
|
|
83
83
|
.hDel(key, lockedFields)
|
|
84
84
|
.exec();
|
|
85
85
|
}
|
|
86
|
-
throw new factory.errors.AlreadyInUse(
|
|
86
|
+
throw new factory.errors.AlreadyInUse(factory.reservationType.EventReservation, ['ticketedSeat'], 'Already hold');
|
|
87
87
|
}
|
|
88
88
|
});
|
|
89
89
|
}
|
|
@@ -94,10 +94,9 @@ class RedisRepository {
|
|
|
94
94
|
return __awaiter(this, void 0, void 0, function* () {
|
|
95
95
|
const key = `${RedisRepository.KEY_PREFIX}:${params.eventId}`;
|
|
96
96
|
const field = RedisRepository.OFFER2FIELD(params.offer);
|
|
97
|
-
|
|
97
|
+
yield this.redisClient.multi()
|
|
98
98
|
.hDel(key, field)
|
|
99
99
|
.exec();
|
|
100
|
-
debug('reply:', reply);
|
|
101
100
|
});
|
|
102
101
|
}
|
|
103
102
|
/**
|
|
@@ -38,20 +38,19 @@ class RedisRepository {
|
|
|
38
38
|
.add(1, 'minute') // ミリ秒でカウントしていくので、注文日時後1分で十分
|
|
39
39
|
.diff(now, 'seconds');
|
|
40
40
|
const key = util.format('%s:%s:%s', RedisRepository.REDIS_KEY_PREFIX, projectPrefix, timestamp);
|
|
41
|
-
const
|
|
41
|
+
const [incrReply] = yield this.redisClient.multi()
|
|
42
42
|
.incr(key)
|
|
43
43
|
.expire(key, TTL)
|
|
44
44
|
.exec();
|
|
45
|
-
if (!Array.isArray(results)) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
45
|
+
// if (!Array.isArray(results)) {
|
|
46
|
+
// // なぜかresults: nullのことがあるのでハンドリング
|
|
47
|
+
// throw new factory.errors.ServiceUnavailable('incr orderNumber result not array');
|
|
48
|
+
// }
|
|
49
49
|
// tslint:disable-next-line:no-single-line-block-comment
|
|
50
50
|
/* istanbul ignore else: please write tests */
|
|
51
|
-
if (typeof
|
|
51
|
+
if (typeof incrReply === 'number') {
|
|
52
52
|
let orderNumber = timestamp;
|
|
53
|
-
const no =
|
|
54
|
-
// orderNumber = `${orderNumber}${(`${no}`).slice(-1)}`; // ミリ秒あたり10件以内の注文想定
|
|
53
|
+
const no = incrReply;
|
|
55
54
|
orderNumber = `${orderNumber}${no}`;
|
|
56
55
|
// checkdigit
|
|
57
56
|
const cd = cdigit.luhn.compute(orderNumber);
|
|
@@ -11,13 +11,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.RedisRepository = void 0;
|
|
13
13
|
const cdigit = require("cdigit");
|
|
14
|
-
const createDebug = require("debug");
|
|
15
14
|
const moment = require("moment-timezone");
|
|
16
15
|
const util = require("util");
|
|
17
16
|
// tslint:disable-next-line:no-require-imports no-var-requires
|
|
18
17
|
const fpe = require('node-fpe');
|
|
19
18
|
const factory = require("../factory");
|
|
20
|
-
const debug = createDebug('chevre-domain:repo');
|
|
21
19
|
/**
|
|
22
20
|
* サービスアウトプット識別子リポジトリ
|
|
23
21
|
*/
|
|
@@ -37,24 +35,21 @@ class RedisRepository {
|
|
|
37
35
|
const TTL = moment(params.startDate)
|
|
38
36
|
.add(1, 'minute') // ミリ秒でカウントしていくので、予約日時後1分で十分
|
|
39
37
|
.diff(now, 'seconds');
|
|
40
|
-
debug(`TTL:${TTL} seconds`);
|
|
41
38
|
const key = util.format('%s:%s', RedisRepository.REDIS_KEY_PREFIX, timestamp);
|
|
42
|
-
const
|
|
39
|
+
const [incrReply] = yield this.redisClient.multi()
|
|
43
40
|
.incr(key)
|
|
44
41
|
.expire(key, TTL)
|
|
45
42
|
.exec();
|
|
46
43
|
// tslint:disable-next-line:no-single-line-block-comment
|
|
47
44
|
/* istanbul ignore else: please write tests */
|
|
48
|
-
if (
|
|
45
|
+
if (typeof incrReply === 'number') {
|
|
49
46
|
let identifier = timestamp;
|
|
50
|
-
const no =
|
|
51
|
-
debug('no incremented.', no);
|
|
47
|
+
const no = incrReply;
|
|
52
48
|
identifier = `${identifier}${no}`;
|
|
53
49
|
// checkdigit
|
|
54
50
|
const cd = cdigit.luhn.compute(identifier);
|
|
55
51
|
const cipher = fpe({ password: cd });
|
|
56
52
|
identifier = cipher.encrypt(identifier);
|
|
57
|
-
debug('publishing serviceOutputIdentifier from', timestamp, no, cd);
|
|
58
53
|
identifier = `${cd}${identifier}`;
|
|
59
54
|
return identifier;
|
|
60
55
|
}
|
|
@@ -11,13 +11,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.RedisRepository = void 0;
|
|
13
13
|
const cdigit = require("cdigit");
|
|
14
|
-
const createDebug = require("debug");
|
|
15
14
|
const moment = require("moment-timezone");
|
|
16
15
|
const util = require("util");
|
|
17
16
|
// tslint:disable-next-line:no-require-imports no-var-requires
|
|
18
17
|
const fpe = require('node-fpe');
|
|
19
18
|
const factory = require("../factory");
|
|
20
|
-
const debug = createDebug('chevre-domain:repo');
|
|
21
19
|
/**
|
|
22
20
|
* 取引番号リポジトリ
|
|
23
21
|
*/
|
|
@@ -30,9 +28,6 @@ class RedisRepository {
|
|
|
30
28
|
*/
|
|
31
29
|
publishByTimestamp(params) {
|
|
32
30
|
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
-
// tslint:disable-next-line:no-magic-numbers
|
|
34
|
-
// const projectPrefix = params.project.id.slice(0, 3)
|
|
35
|
-
// .toUpperCase();
|
|
36
31
|
const timestamp = moment(params.startDate)
|
|
37
32
|
.valueOf()
|
|
38
33
|
.toString();
|
|
@@ -40,30 +35,21 @@ class RedisRepository {
|
|
|
40
35
|
const TTL = moment(params.startDate)
|
|
41
36
|
.add(1, 'minute') // ミリ秒でカウントしていくので、予約日時後1分で十分
|
|
42
37
|
.diff(now, 'seconds');
|
|
43
|
-
|
|
44
|
-
const
|
|
45
|
-
// '%s:%s:%s',
|
|
46
|
-
'%s:%s', RedisRepository.REDIS_KEY_PREFIX,
|
|
47
|
-
// projectPrefix,
|
|
48
|
-
timestamp);
|
|
49
|
-
const results = yield this.redisClient.multi()
|
|
38
|
+
const key = util.format('%s:%s', RedisRepository.REDIS_KEY_PREFIX, timestamp);
|
|
39
|
+
const [incrReply] = yield this.redisClient.multi()
|
|
50
40
|
.incr(key)
|
|
51
41
|
.expire(key, TTL)
|
|
52
42
|
.exec();
|
|
53
43
|
// tslint:disable-next-line:no-single-line-block-comment
|
|
54
44
|
/* istanbul ignore else: please write tests */
|
|
55
|
-
if (
|
|
45
|
+
if (typeof incrReply === 'number') {
|
|
56
46
|
let transactionNumber = timestamp;
|
|
57
|
-
const no =
|
|
58
|
-
debug('no incremented.', no);
|
|
47
|
+
const no = incrReply;
|
|
59
48
|
transactionNumber = `${transactionNumber}${no}`;
|
|
60
49
|
// checkdigit
|
|
61
50
|
const cd = cdigit.luhn.compute(transactionNumber);
|
|
62
51
|
const cipher = fpe({ password: cd });
|
|
63
52
|
transactionNumber = cipher.encrypt(transactionNumber);
|
|
64
|
-
// debug('publishing transactionNumber from', projectPrefix, timestamp, no, cd);
|
|
65
|
-
// transactionNumber = `${projectPrefix}${cd}${transactionNumber}`;
|
|
66
|
-
debug('publishing transactionNumber from', timestamp, no, cd);
|
|
67
53
|
transactionNumber = `${cd}${transactionNumber}`;
|
|
68
54
|
return { transactionNumber };
|
|
69
55
|
}
|
package/package.json
CHANGED