Passed
Push — master ( 47dd3c...36b76c )
by Sungyub
03:04 queued 18s
created

src/app.ts   A

Complexity

Total Complexity 4
Complexity/F 0

Size

Lines of Code 68
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 56
mnd 4
bc 4
fnc 0
dl 0
loc 68
rs 10
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
1
// eslint-disable-next-line @typescript-eslint/no-var-requires
2
import getWallets from './handlers/getWallets'
3
4
const level: any = require('level')
5
const print: any = require('print-message')
6
7
import env from 'dotenv'
8
import {
9
  isEnvFile,
10
} from './utils'
11
import { getCount, getWallet } from './handlers'
12
import { Wallet } from './models'
13
14
const loaded = env.config()
15
16
const app = async (query: { command?: string, arg?: string }): Promise<void> => {
17
  let db = null
18
19
  try {
20
    if (!isEnvFile(loaded)) {
21
      return
22
    }
23
    db = level(process.env.DB_LOCATION)
24
25
    switch (query.command) {
26
      case 'f':
27
        const wallet: Wallet| {result: string} = await getWallet(db, query.arg!)
28
29
        if ('member_wallet' in wallet) {
30
          print([
31
            `Wallet Address: ${ wallet.member_wallet.wallet_address }`,
32
            `Wallet Coin Balance: ${ wallet.member_wallet.coin_balance }`,
33
          ])
34
        }
35
        print([
36
          'Result Row:',
37
          JSON.stringify(wallet)
38
        ], {
39
          border: false,
40
          marginTop: 1,
41
          marginBottom: 3,
42
          color: 'green',
43
        })
44
        break
45
      case 'c':
46
        const count: number = await getCount(db)
47
        print([
48
          `Found Number of Wallets`,
49
          `Wallets: ${count} pcs.`
50
        ])
51
        break
52
      case 'l':
53
        const file = await getWallets(db)
54
        print([
55
          `Please open file ${file}`
56
        ])
57
        break
58
      default:
59
        break
60
    }
61
62
  } catch (e) {
63
    console.error(e.message)
64
  }
65
}
66
67
export default app
68