Passed
Push — master ( a485dd...9339af )
by Kyungmi
01:25
created

src/router/ui-router.js   A

Complexity

Total Complexity 11
Complexity/F 1.38

Size

Lines of Code 61
Function Count 8

Duplication

Duplicated Lines 0
Ratio 0 %

Test Coverage

Coverage 35%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 0
c 3
b 0
f 0
nc 1
dl 0
loc 61
rs 10
ccs 7
cts 20
cp 0.35
crap 0
wmc 11
mnd 2
bc 4
fnc 8
bpm 0.5
cpm 1.375
noi 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A ui-router.js ➔ ??? 0 3 1
A ui-router.js ➔ view 0 13 3
1
/**
2
 * Service authenticator
3
 *
4
 * @since 1.0.0
5
 */
6
7 4
const StatusType = require('../repository/StatusType');
8 4
const DeviceType = require('../repository/DeviceType');
9
10 4
const menus = [
11
  { viewName: 'StatusList', title: '공지사항 관리', url: '/' },
12
  { viewName: 'SettingList', title: '설정', url: '/settings' },
13
];
14
15
function view(request, reply, childViewName, context) {
16 2
  const ctx = context || {};
17
  ctx.viewName = childViewName;
18 2
  if (request.auth) {
19
    ctx.auth = {
20
      isAuthenticated: request.auth.isAuthenticated,
21
      username: request.auth.credentials ? request.auth.credentials.username : undefined,
22
    };
23
  }
24
  ctx.menus = menus;
25
  ctx.state = `window.state = ${JSON.stringify(ctx)}`;
26
  return reply.view('Layout', ctx);
27
}
28
29 4
module.exports = [
30
  {
31
    method: 'GET',
32
    path: '/',
33
    handler: (request, reply) => Promise.all([StatusType.find(), DeviceType.find()])
34
      .then(([statusTypes, deviceTypes]) => view(request, reply, 'StatusList', { statusTypes, deviceTypes }))
35
      .catch(error => reply(error)),
36
  },
37
  {
38
    method: 'GET',
39
    path: '/settings',
40
    handler: (request, reply) => view(request, reply, 'SettingList', {}),
41
  },
42
  {
43
    method: 'GET',
44
    path: '/login',
45
    handler: (request, reply) => {
46 2
      if (request.auth.isAuthenticated) {
47
        return reply.redirect('/');
48
      }
49
      return view(request, reply, 'Login');
50
    },
51
    config: {
52
      auth: {
53
        mode: 'try',
54
      },
55
    },
56
  },
57
  {
58
    method: 'GET',
59
    path: '/logout',
60
    handler: (request, reply) => reply.redirect('/login').unstate('token'),
61
  },
62
  {
63
    method: 'GET',
64
    path: '/change-password',
65
    handler: (request, reply) => view(request, reply, 'ChangePassword'),
66
  },
67
];
68
69