{"action":"created","comment":{"url":"https://api.github.com/repos/ParsePlatform/parse-server/pulls/comments/92298363","pull_request_review_id":12811261,"id":92298363,"diff_hunk":"@@ -0,0 +1,111 @@\n+import express          from 'express';\n+import * as middlewares from '../middlewares';\n+import multer           from 'multer';\n+import rest             from '../rest';\n+import bluebird         from 'bluebird';\n+\n+function handleImport(req, res) {\n+  let restObjects = [];\n+  let importFile;\n+  try {\n+    importFile = JSON.parse(req.file.buffer.toString());\n+  } catch (e) {\n+    res.status(400);\n+    res.json({ response: 'Failed to parse JSON based on the file sent' });\n+    return;\n+  }\n+  \n+  if (Array.isArray(importFile)) {\n+    restObjects = importFile;\n+  } else if (Array.isArray(importFile.results)) {\n+    restObjects = importFile.results;\n+  } else if (Array.isArray(importFile.rows)) {\n+    restObjects = importFile.rows;\n+  }\n+\n+  if (!restObjects) {\n+    res.status(400);\n+    res.json({ response: 'No data to import' });\n+    return;\n+  }\n+\n+  if (req.body.feedbackEmail) {\n+    let emailControllerAdapter = req.config.emailControllerAdapter;\n+    if (!emailControllerAdapter) {\n+      res.status(400);\n+      res.json({ response: 'You have to setup a Mail Adapter.' });\n+      return;\n+    } else {\n+      res.status(200);\n+      res.json({response: 'We are importing your data. You will be notified by e-mail once it is completed.'});\n+    }\n+    bluebird.map(restObjects, importRestObject, { concurrency: 100 })\n+      .then(() => {\n+        emailControllerAdapter.sendMail({\n+          text: `We have successfully imported your data to the class ${req.params.className}.`,\n+          to: req.body.feedbackEmail,\n+          subject: 'Import completed'\n+        });\n+      })\n+      .catch((error) => {\n+        emailControllerAdapter.sendMail({\n+          text: `We could not import your data to the class ${req.params.className}. Error: ${error}`,\n+          to: req.body.feedbackEmail,\n+          subject: 'Import failed'\n+        });\n+      });\n+  } else {\n+    bluebird.map(restObjects, importRestObject, { concurrency: 100 })\n+      .then((results) => {\n+        res.status(200);\n+        res.json({response: results});\n+      })\n+      .catch((error) => {\n+        res.status(500);\n+        res.json({response: 'Internal server error: ' + error});\n+      });\n+  }\n+\n+  function importRestObject(restObject) {\n+    if (restObject.createdAt) {\n+      delete restObject.createdAt;\n+    }\n+    if (restObject.updatedAt) {\n+      delete restObject.updatedAt;\n+    }\n+    if (restObject.objectId) {\n+      return rest\n+        .update(req.config, req.auth, req.params.className, restObject.objectId, restObject)","path":"src/Routers/ImportRouter.js","position":null,"original_position":78,"commit_id":"ae6f46fad71eb777d440fec483295a224477d12f","original_commit_id":"d8d240518710859978a2325ff7ee2fe41a4508f0","user":{"login":"Jcarlosjunior","id":994377,"avatar_url":"https://avatars.githubusercontent.com/u/994377?v=3","gravatar_id":"","url":"https://api.github.com/users/Jcarlosjunior","html_url":"https://github.com/Jcarlosjunior","followers_url":"https://api.github.com/users/Jcarlosjunior/followers","following_url":"https://api.github.com/users/Jcarlosjunior/following{/other_user}","gists_url":"https://api.github.com/users/Jcarlosjunior/gists{/gist_id}","starred_url":"https://api.github.com/users/Jcarlosjunior/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Jcarlosjunior/subscriptions","organizations_url":"https://api.github.com/users/Jcarlosjunior/orgs","repos_url":"https://api.github.com/users/Jcarlosjunior/repos","events_url":"https://api.github.com/users/Jcarlosjunior/events{/privacy}","received_events_url":"https://api.github.com/users/Jcarlosjunior/received_events","type":"User","site_admin":false},"body":"hey @flovilmart I've checked the `rest` and `RestWrite` classes and they don't implement the upsert, we only have access to it directly from the `DatabaseController`, but on the import we need things that are only implemented on the `RestWrite` class such as the call to the `expandFilesForExistingObjects()` method.","created_at":"2016-12-14T00:24:50Z","updated_at":"2016-12-14T00:24:50Z","html_url":"https://github.com/ParsePlatform/parse-server/pull/3046#discussion_r92298363","pull_request_url":"https://api.github.com/repos/ParsePlatform/parse-server/pulls/3046","_links":{"self":{"href":"https://api.github.com/repos/ParsePlatform/parse-server/pulls/comments/92298363"},"html":{"href":"https://github.com/ParsePlatform/parse-server/pull/3046#discussion_r92298363"},"pull_request":{"href":"https://api.github.com/repos/ParsePlatform/parse-server/pulls/3046"}}},"pull_request":{"url":"https://api.github.com/repos/ParsePlatform/parse-server/pulls/3046","id":93478559,"html_url":"https://github.com/ParsePlatform/parse-server/pull/3046","diff_url":"https://github.com/ParsePlatform/parse-server/pull/3046.diff","patch_url":"https://github.com/ParsePlatform/parse-server/pull/3046.patch","issue_url":"https://api.github.com/repos/ParsePlatform/parse-server/issues/3046","number":3046,"state":"open","locked":false,"title":"Endpoints for importing and exporting data","user":{"login":"davimacedo","id":4430059,"avatar_url":"https://avatars.githubusercontent.com/u/4430059?v=3","gravatar_id":"","url":"https://api.github.com/users/davimacedo","html_url":"https://github.com/davimacedo","followers_url":"https://api.github.com/users/davimacedo/followers","following_url":"https://api.github.com/users/davimacedo/following{/other_user}","gists_url":"https://api.github.com/users/davimacedo/gists{/gist_id}","starred_url":"https://api.github.com/users/davimacedo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davimacedo/subscriptions","organizations_url":"https://api.github.com/users/davimacedo/orgs","repos_url":"https://api.github.com/users/davimacedo/repos","events_url":"https://api.github.com/users/davimacedo/events{/privacy}","received_events_url":"https://api.github.com/users/davimacedo/received_events","type":"User","site_admin":false},"body":"Endpoints for:\r\na) Import Data into a class - it receives a file in the same format of parse.com and backwards the data that is exported;\r\nb) Import Relation Data into a class relation - it receives a file in the same format of parse.com and backwards the data that is exported;\r\nc) Export Data from a class - It returns a zipped .json file just like parse.com","created_at":"2016-11-13T16:50:10Z","updated_at":"2016-12-14T00:24:50Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3feab7597f715ef9d973dd962875235410630c92","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/ParsePlatform/parse-server/pulls/3046/commits","review_comments_url":"https://api.github.com/repos/ParsePlatform/parse-server/pulls/3046/comments","review_comment_url":"https://api.github.com/repos/ParsePlatform/parse-server/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ParsePlatform/parse-server/issues/3046/comments","statuses_url":"https://api.github.com/repos/ParsePlatform/parse-server/statuses/ae6f46fad71eb777d440fec483295a224477d12f","head":{"label":"back4app:importAndExport","ref":"importAndExport","sha":"ae6f46fad71eb777d440fec483295a224477d12f","user":{"login":"back4app","id":13628833,"avatar_url":"https://avatars.githubusercontent.com/u/13628833?v=3","gravatar_id":"","url":"https://api.github.com/users/back4app","html_url":"https://github.com/back4app","followers_url":"https://api.github.com/users/back4app/followers","following_url":"https://api.github.com/users/back4app/following{/other_user}","gists_url":"https://api.github.com/users/back4app/gists{/gist_id}","starred_url":"https://api.github.com/users/back4app/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/back4app/subscriptions","organizations_url":"https://api.github.com/users/back4app/orgs","repos_url":"https://api.github.com/users/back4app/repos","events_url":"https://api.github.com/users/back4app/events{/privacy}","received_events_url":"https://api.github.com/users/back4app/received_events","type":"Organization","site_admin":false},"repo":{"id":55724577,"name":"parse-server","full_name":"back4app/parse-server","owner":{"login":"back4app","id":13628833,"avatar_url":"https://avatars.githubusercontent.com/u/13628833?v=3","gravatar_id":"","url":"https://api.github.com/users/back4app","html_url":"https://github.com/back4app","followers_url":"https://api.github.com/users/back4app/followers","following_url":"https://api.github.com/users/back4app/following{/other_user}","gists_url":"https://api.github.com/users/back4app/gists{/gist_id}","starred_url":"https://api.github.com/users/back4app/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/back4app/subscriptions","organizations_url":"https://api.github.com/users/back4app/orgs","repos_url":"https://api.github.com/users/back4app/repos","events_url":"https://api.github.com/users/back4app/events{/privacy}","received_events_url":"https://api.github.com/users/back4app/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/back4app/parse-server","description":"Parse-compatible API server module for Node/Express","fork":true,"url":"https://api.github.com/repos/back4app/parse-server","forks_url":"https://api.github.com/repos/back4app/parse-server/forks","keys_url":"https://api.github.com/repos/back4app/parse-server/keys{/key_id}","collaborators_url":"https://api.github.com/repos/back4app/parse-server/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/back4app/parse-server/teams","hooks_url":"https://api.github.com/repos/back4app/parse-server/hooks","issue_events_url":"https://api.github.com/repos/back4app/parse-server/issues/events{/number}","events_url":"https://api.github.com/repos/back4app/parse-server/events","assignees_url":"https://api.github.com/repos/back4app/parse-server/assignees{/user}","branches_url":"https://api.github.com/repos/back4app/parse-server/branches{/branch}","tags_url":"https://api.github.com/repos/back4app/parse-server/tags","blobs_url":"https://api.github.com/repos/back4app/parse-server/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/back4app/parse-server/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/back4app/parse-server/git/refs{/sha}","trees_url":"https://api.github.com/repos/back4app/parse-server/git/trees{/sha}","statuses_url":"https://api.github.com/repos/back4app/parse-server/statuses/{sha}","languages_url":"https://api.github.com/repos/back4app/parse-server/languages","stargazers_url":"https://api.github.com/repos/back4app/parse-server/stargazers","contributors_url":"https://api.github.com/repos/back4app/parse-server/contributors","subscribers_url":"https://api.github.com/repos/back4app/parse-server/subscribers","subscription_url":"https://api.github.com/repos/back4app/parse-server/subscription","commits_url":"https://api.github.com/repos/back4app/parse-server/commits{/sha}","git_commits_url":"https://api.github.com/repos/back4app/parse-server/git/commits{/sha}","comments_url":"https://api.github.com/repos/back4app/parse-server/comments{/number}","issue_comment_url":"https://api.github.com/repos/back4app/parse-server/issues/comments{/number}","contents_url":"https://api.github.com/repos/back4app/parse-server/contents/{+path}","compare_url":"https://api.github.com/repos/back4app/parse-server/compare/{base}...{head}","merges_url":"https://api.github.com/repos/back4app/parse-server/merges","archive_url":"https://api.github.com/repos/back4app/parse-server/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/back4app/parse-server/downloads","issues_url":"https://api.github.com/repos/back4app/parse-server/issues{/number}","pulls_url":"https://api.github.com/repos/back4app/parse-server/pulls{/number}","milestones_url":"https://api.github.com/repos/back4app/parse-server/milestones{/number}","notifications_url":"https://api.github.com/repos/back4app/parse-server/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/back4app/parse-server/labels{/name}","releases_url":"https://api.github.com/repos/back4app/parse-server/releases{/id}","deployments_url":"https://api.github.com/repos/back4app/parse-server/deployments","created_at":"2016-04-07T20:08:04Z","updated_at":"2016-11-29T11:19:09Z","pushed_at":"2016-12-13T22:46:44Z","git_url":"git://github.com/back4app/parse-server.git","ssh_url":"git@github.com:back4app/parse-server.git","clone_url":"https://github.com/back4app/parse-server.git","svn_url":"https://github.com/back4app/parse-server","homepage":null,"size":3618,"stargazers_count":4,"watchers_count":4,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":0,"forks":1,"open_issues":0,"watchers":4,"default_branch":"master"}},"base":{"label":"ParsePlatform:master","ref":"master","sha":"aa071e034eb925c031fd77510097e986f5ee1775","user":{"login":"ParsePlatform","id":1294580,"avatar_url":"https://avatars.githubusercontent.com/u/1294580?v=3","gravatar_id":"","url":"https://api.github.com/users/ParsePlatform","html_url":"https://github.com/ParsePlatform","followers_url":"https://api.github.com/users/ParsePlatform/followers","following_url":"https://api.github.com/users/ParsePlatform/following{/other_user}","gists_url":"https://api.github.com/users/ParsePlatform/gists{/gist_id}","starred_url":"https://api.github.com/users/ParsePlatform/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ParsePlatform/subscriptions","organizations_url":"https://api.github.com/users/ParsePlatform/orgs","repos_url":"https://api.github.com/users/ParsePlatform/repos","events_url":"https://api.github.com/users/ParsePlatform/events{/privacy}","received_events_url":"https://api.github.com/users/ParsePlatform/received_events","type":"Organization","site_admin":false},"repo":{"id":50603846,"name":"parse-server","full_name":"ParsePlatform/parse-server","owner":{"login":"ParsePlatform","id":1294580,"avatar_url":"https://avatars.githubusercontent.com/u/1294580?v=3","gravatar_id":"","url":"https://api.github.com/users/ParsePlatform","html_url":"https://github.com/ParsePlatform","followers_url":"https://api.github.com/users/ParsePlatform/followers","following_url":"https://api.github.com/users/ParsePlatform/following{/other_user}","gists_url":"https://api.github.com/users/ParsePlatform/gists{/gist_id}","starred_url":"https://api.github.com/users/ParsePlatform/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ParsePlatform/subscriptions","organizations_url":"https://api.github.com/users/ParsePlatform/orgs","repos_url":"https://api.github.com/users/ParsePlatform/repos","events_url":"https://api.github.com/users/ParsePlatform/events{/privacy}","received_events_url":"https://api.github.com/users/ParsePlatform/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ParsePlatform/parse-server","description":"Parse-compatible API server module for Node/Express","fork":false,"url":"https://api.github.com/repos/ParsePlatform/parse-server","forks_url":"https://api.github.com/repos/ParsePlatform/parse-server/forks","keys_url":"https://api.github.com/repos/ParsePlatform/parse-server/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ParsePlatform/parse-server/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ParsePlatform/parse-server/teams","hooks_url":"https://api.github.com/repos/ParsePlatform/parse-server/hooks","issue_events_url":"https://api.github.com/repos/ParsePlatform/parse-server/issues/events{/number}","events_url":"https://api.github.com/repos/ParsePlatform/parse-server/events","assignees_url":"https://api.github.com/repos/ParsePlatform/parse-server/assignees{/user}","branches_url":"https://api.github.com/repos/ParsePlatform/parse-server/branches{/branch}","tags_url":"https://api.github.com/repos/ParsePlatform/parse-server/tags","blobs_url":"https://api.github.com/repos/ParsePlatform/parse-server/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ParsePlatform/parse-server/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ParsePlatform/parse-server/git/refs{/sha}","trees_url":"https://api.github.com/repos/ParsePlatform/parse-server/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ParsePlatform/parse-server/statuses/{sha}","languages_url":"https://api.github.com/repos/ParsePlatform/parse-server/languages","stargazers_url":"https://api.github.com/repos/ParsePlatform/parse-server/stargazers","contributors_url":"https://api.github.com/repos/ParsePlatform/parse-server/contributors","subscribers_url":"https://api.github.com/repos/ParsePlatform/parse-server/subscribers","subscription_url":"https://api.github.com/repos/ParsePlatform/parse-server/subscription","commits_url":"https://api.github.com/repos/ParsePlatform/parse-server/commits{/sha}","git_commits_url":"https://api.github.com/repos/ParsePlatform/parse-server/git/commits{/sha}","comments_url":"https://api.github.com/repos/ParsePlatform/parse-server/comments{/number}","issue_comment_url":"https://api.github.com/repos/ParsePlatform/parse-server/issues/comments{/number}","contents_url":"https://api.github.com/repos/ParsePlatform/parse-server/contents/{+path}","compare_url":"https://api.github.com/repos/ParsePlatform/parse-server/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ParsePlatform/parse-server/merges","archive_url":"https://api.github.com/repos/ParsePlatform/parse-server/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ParsePlatform/parse-server/downloads","issues_url":"https://api.github.com/repos/ParsePlatform/parse-server/issues{/number}","pulls_url":"https://api.github.com/repos/ParsePlatform/parse-server/pulls{/number}","milestones_url":"https://api.github.com/repos/ParsePlatform/parse-server/milestones{/number}","notifications_url":"https://api.github.com/repos/ParsePlatform/parse-server/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ParsePlatform/parse-server/labels{/name}","releases_url":"https://api.github.com/repos/ParsePlatform/parse-server/releases{/id}","deployments_url":"https://api.github.com/repos/ParsePlatform/parse-server/deployments","created_at":"2016-01-28T18:29:14Z","updated_at":"2016-12-13T20:16:46Z","pushed_at":"2016-12-13T22:46:45Z","git_url":"git://github.com/ParsePlatform/parse-server.git","ssh_url":"git@github.com:ParsePlatform/parse-server.git","clone_url":"https://github.com/ParsePlatform/parse-server.git","svn_url":"https://github.com/ParsePlatform/parse-server","homepage":"https://parse.com","size":3473,"stargazers_count":12000,"watchers_count":12000,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3261,"mirror_url":null,"open_issues_count":121,"forks":3261,"open_issues":121,"watchers":12000,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ParsePlatform/parse-server/pulls/3046"},"html":{"href":"https://github.com/ParsePlatform/parse-server/pull/3046"},"issue":{"href":"https://api.github.com/repos/ParsePlatform/parse-server/issues/3046"},"comments":{"href":"https://api.github.com/repos/ParsePlatform/parse-server/issues/3046/comments"},"review_comments":{"href":"https://api.github.com/repos/ParsePlatform/parse-server/pulls/3046/comments"},"review_comment":{"href":"https://api.github.com/repos/ParsePlatform/parse-server/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ParsePlatform/parse-server/pulls/3046/commits"},"statuses":{"href":"https://api.github.com/repos/ParsePlatform/parse-server/statuses/ae6f46fad71eb777d440fec483295a224477d12f"}}}}
{"actor":{"display_login":"Jcarlosjunior"}}