{"action":"created","comment":{"url":"https://api.github.com/repos/RandoApp/Rando/pulls/comments/75339770","id":75339770,"diff_hunk":"@@ -8,13 +8,75 @@ var backwardCompatibility = require(\"../util/backwardCompatibility\");\n var passwordUtil = require(\"../util/password\");\n \n module.exports = {\n-  destroyAuthToken: function (user, callback) {\n+  addOrUpdateFirebaseInstanceId (user, firebaseInstanceId, callback) {\n+  if (!user || !firebaseInstanceId) {\n+    return callback(\"user and firebaseInstanceId should be present\", user);\n+  }\n+  if (!user.firebaseInstanceIds){\n+    user.firebaseInstanceIds = [];\n+  }\n+    async.detect(user.firebaseInstanceIds, (instanceIdTest, done) => {\n+    done(null, instanceIdTest.instanceId === firebaseInstanceId);\n+  }, (err, instanceIdFound) => {\n+    if (err){\n+      logger.log(err);\n+      return callback(\"err finding instanceId\");\n+    }\n+    if(instanceIdFound){\n+      logger.debug(\"[userService.addOrUpdateFirebaseInstanceId] \",\"Activating firebaseInstanceId: \", firebaseInstanceId, \" for user: \", user.email);\n+      instanceIdFound.lastUsedDate = Date.now();\n+      instanceIdFound.active = true;\n+    } else {\n+      user.firebaseInstanceIds.push( { instanceId: firebaseInstanceId, active: true, createdDate: Date.now(), lastUsedDate: Date.now() } );\n+      logger.debug(\"[userService.addOrUpdateFirebaseInstanceId] \",\"Adding new firebaseInstanceId: \", firebaseInstanceId, \" for user: \", user.email);\n+    }\n+      callback(null, user);\n+  });\n+  return;\n+},\n+\n+deactivateFirebaseInstanceId (user, firebaseInstanceId, callback) {\n+  if (!user || !firebaseInstanceId) {\n+    return callback(\"user and firebaseInstanceId should be present\", user);\n+  }\n+  if (!user.firebaseInstanceIds){\n+    user.firebaseInstanceIds = [];\n+  }\n+  async.detect(user.firebaseInstanceIds, (instanceIdTest,done) => {\n+    done(null, instanceIdTest.instanceId === firebaseInstanceId);\n+  }, (err, instanceIdFound) => {\n+    if (err){\n+      logger.log(err);\n+      return callback(\"err finding instanceId\");\n+    }\n+    if(instanceIdFound){\n+      logger.debug(\"[userService.deactivateFirebaseInstanceId] \", \"Deactivating firebaseInstanceId: \", firebaseInstanceId, \" for user: \", user.email);\n+      instanceIdFound.lastUsedDate = Date.now();\n+      instanceIdFound.active = false;\n+    } else {\n+      user.firebaseInstanceIds.push( { instanceId: firebaseInstanceId, active: false, createdDate: Date.now(), lastUsedDate: Date.now() } );\n+      logger.debug(\"[userService.deactivateFirebaseInstanceId] \", \"Deactivating never used firebaseInstanceId: \", firebaseInstanceId, \" for user: \", user.email);\n+    }\n+    callback(null, user);\n+  });\n+  return;\n+},\n+\n+  destroyAuthToken (user, firebaseInstanceId, callback) {\n     user.authToken = \"\";\n-    db.user.update(user);\n-    callback(null, {command: \"logout\", result: \"done\"});\n+    this.deactivateFirebaseInstanceId(user, firebaseInstanceId, function (err, user) {\n+      if (err && firebaseInstanceId) {\n+            logger.info(\"[userService.findOrCreateByLoginAndPassword, \", email, \"] error setting firebaseInstanceId\");\n+            return callback(Errors.System(err));","path":"src/service/userService.js","position":66,"original_position":66,"commit_id":"001134ffd02a36a01a89b0e02c479ba89cb84b63","original_commit_id":"001134ffd02a36a01a89b0e02c479ba89cb84b63","user":{"login":"codacy-bot","id":19940114,"avatar_url":"https://avatars.githubusercontent.com/u/19940114?v=3","gravatar_id":"","url":"https://api.github.com/users/codacy-bot","html_url":"https://github.com/codacy-bot","followers_url":"https://api.github.com/users/codacy-bot/followers","following_url":"https://api.github.com/users/codacy-bot/following{/other_user}","gists_url":"https://api.github.com/users/codacy-bot/gists{/gist_id}","starred_url":"https://api.github.com/users/codacy-bot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/codacy-bot/subscriptions","organizations_url":"https://api.github.com/users/codacy-bot/orgs","repos_url":"https://api.github.com/users/codacy-bot/repos","events_url":"https://api.github.com/users/codacy-bot/events{/privacy}","received_events_url":"https://api.github.com/users/codacy-bot/received_events","type":"User","site_admin":false},"body":"![Codacy](https://www.codacy.com/assets/images/favicon.png) Issue found: [A function with a name starting with an uppercase letter should only be used as a constructor. (new-cap)](https://www.codacy.com/app/RandoApp/Rando/file/3397234294/issues/source?bid=3392764&fileBranchId=3459529#l70)","created_at":"2016-08-18T16:17:41Z","updated_at":"2016-08-18T16:17:41Z","html_url":"https://github.com/RandoApp/Rando/pull/41#discussion_r75339770","pull_request_url":"https://api.github.com/repos/RandoApp/Rando/pulls/41","_links":{"self":{"href":"https://api.github.com/repos/RandoApp/Rando/pulls/comments/75339770"},"html":{"href":"https://github.com/RandoApp/Rando/pull/41#discussion_r75339770"},"pull_request":{"href":"https://api.github.com/repos/RandoApp/Rando/pulls/41"}}},"pull_request":{"url":"https://api.github.com/repos/RandoApp/Rando/pulls/41","id":78341539,"html_url":"https://github.com/RandoApp/Rando/pull/41","diff_url":"https://github.com/RandoApp/Rando/pull/41.diff","patch_url":"https://github.com/RandoApp/Rando/pull/41.patch","issue_url":"https://api.github.com/repos/RandoApp/Rando/issues/41","number":41,"state":"open","locked":false,"title":"Update access to use token and store firebaseInstanceId","user":{"login":"xp-vit","id":2340581,"avatar_url":"https://avatars.githubusercontent.com/u/2340581?v=3","gravatar_id":"","url":"https://api.github.com/users/xp-vit","html_url":"https://github.com/xp-vit","followers_url":"https://api.github.com/users/xp-vit/followers","following_url":"https://api.github.com/users/xp-vit/following{/other_user}","gists_url":"https://api.github.com/users/xp-vit/gists{/gist_id}","starred_url":"https://api.github.com/users/xp-vit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xp-vit/subscriptions","organizations_url":"https://api.github.com/users/xp-vit/orgs","repos_url":"https://api.github.com/users/xp-vit/repos","events_url":"https://api.github.com/users/xp-vit/events{/privacy}","received_events_url":"https://api.github.com/users/xp-vit/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-07-21T15:54:03Z","updated_at":"2016-08-18T16:17:41Z","closed_at":null,"merged_at":null,"merge_commit_sha":"85c5f5796d99fe0b81068cd419a0e9220e42d20e","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/RandoApp/Rando/pulls/41/commits","review_comments_url":"https://api.github.com/repos/RandoApp/Rando/pulls/41/comments","review_comment_url":"https://api.github.com/repos/RandoApp/Rando/pulls/comments{/number}","comments_url":"https://api.github.com/repos/RandoApp/Rando/issues/41/comments","statuses_url":"https://api.github.com/repos/RandoApp/Rando/statuses/001134ffd02a36a01a89b0e02c479ba89cb84b63","head":{"label":"RandoApp:add-firebase-instance-id","ref":"add-firebase-instance-id","sha":"001134ffd02a36a01a89b0e02c479ba89cb84b63","user":{"login":"RandoApp","id":7382647,"avatar_url":"https://avatars.githubusercontent.com/u/7382647?v=3","gravatar_id":"","url":"https://api.github.com/users/RandoApp","html_url":"https://github.com/RandoApp","followers_url":"https://api.github.com/users/RandoApp/followers","following_url":"https://api.github.com/users/RandoApp/following{/other_user}","gists_url":"https://api.github.com/users/RandoApp/gists{/gist_id}","starred_url":"https://api.github.com/users/RandoApp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RandoApp/subscriptions","organizations_url":"https://api.github.com/users/RandoApp/orgs","repos_url":"https://api.github.com/users/RandoApp/repos","events_url":"https://api.github.com/users/RandoApp/events{/privacy}","received_events_url":"https://api.github.com/users/RandoApp/received_events","type":"Organization","site_admin":false},"repo":{"id":12946779,"name":"Rando","full_name":"RandoApp/Rando","owner":{"login":"RandoApp","id":7382647,"avatar_url":"https://avatars.githubusercontent.com/u/7382647?v=3","gravatar_id":"","url":"https://api.github.com/users/RandoApp","html_url":"https://github.com/RandoApp","followers_url":"https://api.github.com/users/RandoApp/followers","following_url":"https://api.github.com/users/RandoApp/following{/other_user}","gists_url":"https://api.github.com/users/RandoApp/gists{/gist_id}","starred_url":"https://api.github.com/users/RandoApp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RandoApp/subscriptions","organizations_url":"https://api.github.com/users/RandoApp/orgs","repos_url":"https://api.github.com/users/RandoApp/repos","events_url":"https://api.github.com/users/RandoApp/events{/privacy}","received_events_url":"https://api.github.com/users/RandoApp/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/RandoApp/Rando","description":"Rando server. Give, receive and collect unique photos from random people from all over the world","fork":false,"url":"https://api.github.com/repos/RandoApp/Rando","forks_url":"https://api.github.com/repos/RandoApp/Rando/forks","keys_url":"https://api.github.com/repos/RandoApp/Rando/keys{/key_id}","collaborators_url":"https://api.github.com/repos/RandoApp/Rando/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/RandoApp/Rando/teams","hooks_url":"https://api.github.com/repos/RandoApp/Rando/hooks","issue_events_url":"https://api.github.com/repos/RandoApp/Rando/issues/events{/number}","events_url":"https://api.github.com/repos/RandoApp/Rando/events","assignees_url":"https://api.github.com/repos/RandoApp/Rando/assignees{/user}","branches_url":"https://api.github.com/repos/RandoApp/Rando/branches{/branch}","tags_url":"https://api.github.com/repos/RandoApp/Rando/tags","blobs_url":"https://api.github.com/repos/RandoApp/Rando/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/RandoApp/Rando/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/RandoApp/Rando/git/refs{/sha}","trees_url":"https://api.github.com/repos/RandoApp/Rando/git/trees{/sha}","statuses_url":"https://api.github.com/repos/RandoApp/Rando/statuses/{sha}","languages_url":"https://api.github.com/repos/RandoApp/Rando/languages","stargazers_url":"https://api.github.com/repos/RandoApp/Rando/stargazers","contributors_url":"https://api.github.com/repos/RandoApp/Rando/contributors","subscribers_url":"https://api.github.com/repos/RandoApp/Rando/subscribers","subscription_url":"https://api.github.com/repos/RandoApp/Rando/subscription","commits_url":"https://api.github.com/repos/RandoApp/Rando/commits{/sha}","git_commits_url":"https://api.github.com/repos/RandoApp/Rando/git/commits{/sha}","comments_url":"https://api.github.com/repos/RandoApp/Rando/comments{/number}","issue_comment_url":"https://api.github.com/repos/RandoApp/Rando/issues/comments{/number}","contents_url":"https://api.github.com/repos/RandoApp/Rando/contents/{+path}","compare_url":"https://api.github.com/repos/RandoApp/Rando/compare/{base}...{head}","merges_url":"https://api.github.com/repos/RandoApp/Rando/merges","archive_url":"https://api.github.com/repos/RandoApp/Rando/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/RandoApp/Rando/downloads","issues_url":"https://api.github.com/repos/RandoApp/Rando/issues{/number}","pulls_url":"https://api.github.com/repos/RandoApp/Rando/pulls{/number}","milestones_url":"https://api.github.com/repos/RandoApp/Rando/milestones{/number}","notifications_url":"https://api.github.com/repos/RandoApp/Rando/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/RandoApp/Rando/labels{/name}","releases_url":"https://api.github.com/repos/RandoApp/Rando/releases{/id}","deployments_url":"https://api.github.com/repos/RandoApp/Rando/deployments","created_at":"2013-09-19T11:18:46Z","updated_at":"2016-07-06T15:04:35Z","pushed_at":"2016-08-18T16:16:00Z","git_url":"git://github.com/RandoApp/Rando.git","ssh_url":"git@github.com:RandoApp/Rando.git","clone_url":"https://github.com/RandoApp/Rando.git","svn_url":"https://github.com/RandoApp/Rando","homepage":"https://rando4.me","size":2734,"stargazers_count":3,"watchers_count":3,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":7,"forks":2,"open_issues":7,"watchers":3,"default_branch":"master"}},"base":{"label":"RandoApp:master","ref":"master","sha":"9b4246c7d981df37a14ae9feef9c8b5b285a075f","user":{"login":"RandoApp","id":7382647,"avatar_url":"https://avatars.githubusercontent.com/u/7382647?v=3","gravatar_id":"","url":"https://api.github.com/users/RandoApp","html_url":"https://github.com/RandoApp","followers_url":"https://api.github.com/users/RandoApp/followers","following_url":"https://api.github.com/users/RandoApp/following{/other_user}","gists_url":"https://api.github.com/users/RandoApp/gists{/gist_id}","starred_url":"https://api.github.com/users/RandoApp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RandoApp/subscriptions","organizations_url":"https://api.github.com/users/RandoApp/orgs","repos_url":"https://api.github.com/users/RandoApp/repos","events_url":"https://api.github.com/users/RandoApp/events{/privacy}","received_events_url":"https://api.github.com/users/RandoApp/received_events","type":"Organization","site_admin":false},"repo":{"id":12946779,"name":"Rando","full_name":"RandoApp/Rando","owner":{"login":"RandoApp","id":7382647,"avatar_url":"https://avatars.githubusercontent.com/u/7382647?v=3","gravatar_id":"","url":"https://api.github.com/users/RandoApp","html_url":"https://github.com/RandoApp","followers_url":"https://api.github.com/users/RandoApp/followers","following_url":"https://api.github.com/users/RandoApp/following{/other_user}","gists_url":"https://api.github.com/users/RandoApp/gists{/gist_id}","starred_url":"https://api.github.com/users/RandoApp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RandoApp/subscriptions","organizations_url":"https://api.github.com/users/RandoApp/orgs","repos_url":"https://api.github.com/users/RandoApp/repos","events_url":"https://api.github.com/users/RandoApp/events{/privacy}","received_events_url":"https://api.github.com/users/RandoApp/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/RandoApp/Rando","description":"Rando server. Give, receive and collect unique photos from random people from all over the world","fork":false,"url":"https://api.github.com/repos/RandoApp/Rando","forks_url":"https://api.github.com/repos/RandoApp/Rando/forks","keys_url":"https://api.github.com/repos/RandoApp/Rando/keys{/key_id}","collaborators_url":"https://api.github.com/repos/RandoApp/Rando/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/RandoApp/Rando/teams","hooks_url":"https://api.github.com/repos/RandoApp/Rando/hooks","issue_events_url":"https://api.github.com/repos/RandoApp/Rando/issues/events{/number}","events_url":"https://api.github.com/repos/RandoApp/Rando/events","assignees_url":"https://api.github.com/repos/RandoApp/Rando/assignees{/user}","branches_url":"https://api.github.com/repos/RandoApp/Rando/branches{/branch}","tags_url":"https://api.github.com/repos/RandoApp/Rando/tags","blobs_url":"https://api.github.com/repos/RandoApp/Rando/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/RandoApp/Rando/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/RandoApp/Rando/git/refs{/sha}","trees_url":"https://api.github.com/repos/RandoApp/Rando/git/trees{/sha}","statuses_url":"https://api.github.com/repos/RandoApp/Rando/statuses/{sha}","languages_url":"https://api.github.com/repos/RandoApp/Rando/languages","stargazers_url":"https://api.github.com/repos/RandoApp/Rando/stargazers","contributors_url":"https://api.github.com/repos/RandoApp/Rando/contributors","subscribers_url":"https://api.github.com/repos/RandoApp/Rando/subscribers","subscription_url":"https://api.github.com/repos/RandoApp/Rando/subscription","commits_url":"https://api.github.com/repos/RandoApp/Rando/commits{/sha}","git_commits_url":"https://api.github.com/repos/RandoApp/Rando/git/commits{/sha}","comments_url":"https://api.github.com/repos/RandoApp/Rando/comments{/number}","issue_comment_url":"https://api.github.com/repos/RandoApp/Rando/issues/comments{/number}","contents_url":"https://api.github.com/repos/RandoApp/Rando/contents/{+path}","compare_url":"https://api.github.com/repos/RandoApp/Rando/compare/{base}...{head}","merges_url":"https://api.github.com/repos/RandoApp/Rando/merges","archive_url":"https://api.github.com/repos/RandoApp/Rando/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/RandoApp/Rando/downloads","issues_url":"https://api.github.com/repos/RandoApp/Rando/issues{/number}","pulls_url":"https://api.github.com/repos/RandoApp/Rando/pulls{/number}","milestones_url":"https://api.github.com/repos/RandoApp/Rando/milestones{/number}","notifications_url":"https://api.github.com/repos/RandoApp/Rando/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/RandoApp/Rando/labels{/name}","releases_url":"https://api.github.com/repos/RandoApp/Rando/releases{/id}","deployments_url":"https://api.github.com/repos/RandoApp/Rando/deployments","created_at":"2013-09-19T11:18:46Z","updated_at":"2016-07-06T15:04:35Z","pushed_at":"2016-08-18T16:16:00Z","git_url":"git://github.com/RandoApp/Rando.git","ssh_url":"git@github.com:RandoApp/Rando.git","clone_url":"https://github.com/RandoApp/Rando.git","svn_url":"https://github.com/RandoApp/Rando","homepage":"https://rando4.me","size":2734,"stargazers_count":3,"watchers_count":3,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":7,"forks":2,"open_issues":7,"watchers":3,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/RandoApp/Rando/pulls/41"},"html":{"href":"https://github.com/RandoApp/Rando/pull/41"},"issue":{"href":"https://api.github.com/repos/RandoApp/Rando/issues/41"},"comments":{"href":"https://api.github.com/repos/RandoApp/Rando/issues/41/comments"},"review_comments":{"href":"https://api.github.com/repos/RandoApp/Rando/pulls/41/comments"},"review_comment":{"href":"https://api.github.com/repos/RandoApp/Rando/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/RandoApp/Rando/pulls/41/commits"},"statuses":{"href":"https://api.github.com/repos/RandoApp/Rando/statuses/001134ffd02a36a01a89b0e02c479ba89cb84b63"}}}}
{"actor":{"display_login":"codacy-bot"}}