Failed Conditions
Push — master ( 492af7...f5e7b3 )
by Yo
01:24
created

server/profile.js (1 issue)

Labels
Severity
1
var express = require('express');
2
var extend  = require('extend');
3
4
// ------------------------------------------
5
//  CONSTRUCTOR
6
// ------------------------------------------
7
8
var init = function(){
9
  info('Starting ProfileManager ...');
10
  
11
  // Expose properties to global
12
  var Profile = {}
13
  global.Profile = Profile;
14
  
15
  return ProfileManager;
16
}
17
18
// ------------------------------------------
19
//  ROUTER
20
// ------------------------------------------
21
22
23
var updateProfile = function(req, res, next) { 
24
  
25
  var name = req.params.name;
26
  var query   = {}; 
27
  var profile = {};
28
29
  var keys = Object.keys(req.query);
30
  for(var i=0 ; i < keys.length ; i++){
31
    var key = keys[i];
32
    var value = req.query[key];
33
    
34
    if (!key.startsWith('profile_')){
35
      query[key] = value;
36
      continue; 
37
    }
38
    
39
    profile[key.substring(8)] = parse(value);
40
  }
41
42
  if (profile.face){
43
    
44
    // Merge previous with new profile
45
    var previous = Profile[profile.face];
0 ignored issues
show
The variable Profile seems to be never declared. If this is a global, consider adding a /** global: Profile */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
46
    if (previous){
47
      extend(true, previous, profile);
48
      profile = previous;
49
    }
50
    
51
    // Save profile for given face
52
    Profile[profile.face] = profile;
53
  }
54
   
55
  // Local profile
56
  req.query = query;
57
  req.query.profile = profile;
58
  Profile.last = profile;
59
  
60
  next();
61
}
62
63
var parse = function(str){
64
  if (str === 'true')  return true;
65
  if (str === 'false') return false;
66
  var num = parseInt(str);
67
  return isNaN(num) ? str : num;
68
}
69
70
var Router = express.Router();
71
72
Router.all('/sarah/:name', updateProfile);
73
Router.all('/standby',     updateProfile);
74
Router.all('/motion',      updateProfile);
75
Router.all('/askme',       updateProfile);
76
77
78
// ------------------------------------------
79
//  PUBLIC
80
// ------------------------------------------
81
82
var ProfileManager = {
83
  'init'   : init,
84
  'Router' : Router
85
}
86
87
// Exports Manager
88
exports.init = ProfileManager.init;