Completed
Pull Request — master (#24)
by Kyungmi
02:20
created

src/router/ui-router.js   A

Complexity

Total Complexity 13
Complexity/F 1.3

Size

Lines of Code 65
Function Count 10

Duplication

Duplicated Lines 0
Ratio 0 %

Test Coverage

Coverage 18.18%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 0
wmc 13
c 3
b 0
f 0
nc 1
mnd 2
bc 4
fnc 10
dl 0
loc 65
ccs 4
cts 22
cp 0.1818
crap 0
rs 10
bpm 0.4
cpm 1.3
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 1
const StatusType = require('../repository/StatusType');
8 1
const DeviceType = require('../repository/DeviceType');
9
10 1
const menus = [
11
  { viewName: 'StatusList', title: '공지사항 관리', url: '/' },
12
  { viewName: 'Settings', title: '설정', url: '/settings' },
13
];
14
15
function view(request, reply, childViewName, context) {
16
  const ctx = context || {};
17
  ctx.viewName = childViewName;
18
  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 1
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) => Promise.all([
41
      StatusType.find(),
42
      DeviceType.find(),
43
    ]).then(([statusTypes, deviceTypes]) => view(request, reply, 'Settings', { statusTypes, deviceTypes }))
44
      .catch(error => reply(error)),
45
  },
46
  {
47
    method: 'GET',
48
    path: '/login',
49
    handler: (request, reply) => {
50
      if (request.auth.isAuthenticated) {
51
        return reply.redirect('/');
52
      }
53
      return view(request, reply, 'Login');
54
    },
55
    config: {
56
      auth: {
57
        mode: 'try',
58
      },
59
    },
60
  },
61
  {
62
    method: 'GET',
63
    path: '/logout',
64
    handler: (request, reply) => reply.redirect('/login').unstate('token'),
65
  },
66
  {
67
    method: 'GET',
68
    path: '/change-password',
69
    handler: (request, reply) => view(request, reply, 'ChangePassword'),
70
  },
71
];
72
73