Skip to content

Commit 40cdcae

Browse files
authored
Merge pull request #34 from back4app/fix_User_import
fix: _User import not working
2 parents 3a229c0 + f669548 commit 40cdcae

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

src/Routers/ExportRouter.js

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const relationSchema = {
1111
};
1212

1313
export class ExportRouter extends PromiseRouter {
14-
exportClassPage(req, name, jsonFileStream, where, skip, limit) {
14+
exportClassPage(req, className, jsonFileStream, where, skip, limit) {
1515
const databaseController = req.config.database;
1616

1717
const options = {
@@ -20,13 +20,32 @@ export class ExportRouter extends PromiseRouter {
2020
};
2121

2222
const findPromise =
23-
name.indexOf('_Join') === 0
24-
? databaseController.adapter.find(name, relationSchema, where, options)
25-
: rest.find(req.config, req.auth, name, where, options);
23+
className.indexOf('_Join') === 0
24+
? databaseController.adapter.find(
25+
className,
26+
relationSchema,
27+
where,
28+
options
29+
)
30+
: rest.find(req.config, req.auth, className, where, options);
2631

2732
return findPromise.then(data => {
2833
if (Array.isArray(data)) {
29-
data = { results: data };
34+
data = {
35+
results: data.map(obj => {
36+
// Needed to avoid errors during import.
37+
// See more: https://docs.parseplatform.org/js/guide/#error-codes
38+
39+
// Deletes invalid keys in order to avoid "ParseError: 105 Invalid field name"
40+
// when importing
41+
Object.keys(obj).forEach(key => {
42+
if (key.startsWith('_')) {
43+
delete obj[key];
44+
}
45+
});
46+
return obj;
47+
}),
48+
};
3049
}
3150

3251
if (skip && data.results.length) {
@@ -190,9 +209,7 @@ export class ExportRouter extends PromiseRouter {
190209
})
191210
.then(fileData => {
192211
return emailControllerAdapter.sendMail({
193-
text: `We have successfully exported your data from the class ${
194-
req.body.name
195-
}.\n
212+
text: `We have successfully exported your data from the class ${req.body.name}.\n
196213
Please download from ${fileData.url}`,
197214
link: fileData.url,
198215
to: req.body.feedbackEmail,
@@ -201,9 +218,7 @@ export class ExportRouter extends PromiseRouter {
201218
})
202219
.catch(error => {
203220
return emailControllerAdapter.sendMail({
204-
text: `We could not export your data to the class ${
205-
req.body.name
206-
}. Error: ${error}`,
221+
text: `We could not export your data to the class ${req.body.name}. Error: ${error}`,
207222
to: req.body.feedbackEmail,
208223
subject: 'Export failed',
209224
});

0 commit comments

Comments
 (0)