@chevre/domain 21.1.0-alpha.3 → 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.
@@ -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);
@@ -24,13 +24,13 @@ class RedisRepository {
24
24
  return __awaiter(this, void 0, void 0, function* () {
25
25
  const key = `${RedisRepository.KEY_PREFIX}:${progressKey.agent.id}:${progressKey.product.id}`;
26
26
  const ttl = 7200;
27
- const results = yield this.redisClient.multi()
27
+ const [setNXReply] = yield this.redisClient.multi()
28
28
  .setNX(key, holder)
29
29
  .expire(key, ttl)
30
30
  .exec();
31
31
  // tslint:disable-next-line:no-single-line-block-comment
32
32
  /* istanbul ignore else: please write tests */
33
- if (Array.isArray(results) && (results[0] === 1 || results[0] === true)) {
33
+ if (setNXReply === 1 || setNXReply === true) {
34
34
  return true;
35
35
  }
36
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 results = yield this.redisClient.multi()
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
- // なぜかresults: nullのことがあるのでハンドリング
53
- throw new factory.errors.ServiceUnavailable('incr confirmationNumber result not array');
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 results[0] === 'number') {
58
- const no = results[0];
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));
@@ -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
- const reply = yield this.redisClient.multi()
97
+ yield this.redisClient.multi()
98
98
  .hDel(key, field)
99
99
  .exec();
100
- debug('reply:', reply);
101
100
  });
102
101
  }
103
102
  /**
@@ -38,19 +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 results = yield this.redisClient.multi()
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
- // なぜかresults: nullのことがあるのでハンドリング
47
- throw new factory.errors.ServiceUnavailable('incr orderNumber result not array');
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 results[0] === 'number') {
51
+ if (typeof incrReply === 'number') {
52
52
  let orderNumber = timestamp;
53
- const no = results[0];
53
+ const no = incrReply;
54
54
  orderNumber = `${orderNumber}${no}`;
55
55
  // checkdigit
56
56
  const cd = cdigit.luhn.compute(orderNumber);
@@ -36,15 +36,15 @@ class RedisRepository {
36
36
  .add(1, 'minute') // ミリ秒でカウントしていくので、予約日時後1分で十分
37
37
  .diff(now, 'seconds');
38
38
  const key = util.format('%s:%s', RedisRepository.REDIS_KEY_PREFIX, timestamp);
39
- const results = yield this.redisClient.multi()
39
+ const [incrReply] = yield this.redisClient.multi()
40
40
  .incr(key)
41
41
  .expire(key, TTL)
42
42
  .exec();
43
43
  // tslint:disable-next-line:no-single-line-block-comment
44
44
  /* istanbul ignore else: please write tests */
45
- if (Array.isArray(results) && typeof results[0] === 'number') {
45
+ if (typeof incrReply === 'number') {
46
46
  let identifier = timestamp;
47
- const no = results[0];
47
+ const no = incrReply;
48
48
  identifier = `${identifier}${no}`;
49
49
  // checkdigit
50
50
  const cd = cdigit.luhn.compute(identifier);
@@ -36,15 +36,15 @@ class RedisRepository {
36
36
  .add(1, 'minute') // ミリ秒でカウントしていくので、予約日時後1分で十分
37
37
  .diff(now, 'seconds');
38
38
  const key = util.format('%s:%s', RedisRepository.REDIS_KEY_PREFIX, timestamp);
39
- const results = yield this.redisClient.multi()
39
+ const [incrReply] = yield this.redisClient.multi()
40
40
  .incr(key)
41
41
  .expire(key, TTL)
42
42
  .exec();
43
43
  // tslint:disable-next-line:no-single-line-block-comment
44
44
  /* istanbul ignore else: please write tests */
45
- if (Array.isArray(results) && typeof results[0] === 'number') {
45
+ if (typeof incrReply === 'number') {
46
46
  let transactionNumber = timestamp;
47
- const no = results[0];
47
+ const no = incrReply;
48
48
  transactionNumber = `${transactionNumber}${no}`;
49
49
  // checkdigit
50
50
  const cd = cdigit.luhn.compute(transactionNumber);
package/package.json CHANGED
@@ -117,5 +117,5 @@
117
117
  "postversion": "git push origin --tags",
118
118
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
119
119
  },
120
- "version": "21.1.0-alpha.3"
120
+ "version": "21.1.0"
121
121
  }