Skip to content

fix: _User import not working #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 20, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 26 additions & 11 deletions src/Routers/ExportRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const relationSchema = {
};

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

const options = {
Expand All @@ -20,13 +20,32 @@ export class ExportRouter extends PromiseRouter {
};

const findPromise =
name.indexOf('_Join') === 0
? databaseController.adapter.find(name, relationSchema, where, options)
: rest.find(req.config, req.auth, name, where, options);
className.indexOf('_Join') === 0
? databaseController.adapter.find(
className,
relationSchema,
where,
options
)
: rest.find(req.config, req.auth, className, where, options);

return findPromise.then(data => {
if (Array.isArray(data)) {
data = { results: data };
data = {
results: data.map(obj => {
// Needed to avoid errors during import.
// See more: https://docs.parseplatform.org/js/guide/#error-codes

// Deletes invalid keys in order to avoid "ParseError: 105 Invalid field name"
// when importing
Object.keys(obj).forEach(key => {
if (key.startsWith('_')) {
delete obj[key];
}
});
return obj;
}),
};
}

if (skip && data.results.length) {
Expand Down Expand Up @@ -190,9 +209,7 @@ export class ExportRouter extends PromiseRouter {
})
.then(fileData => {
return emailControllerAdapter.sendMail({
text: `We have successfully exported your data from the class ${
req.body.name
}.\n
text: `We have successfully exported your data from the class ${req.body.name}.\n
Please download from ${fileData.url}`,
link: fileData.url,
to: req.body.feedbackEmail,
Expand All @@ -201,9 +218,7 @@ export class ExportRouter extends PromiseRouter {
})
.catch(error => {
return emailControllerAdapter.sendMail({
text: `We could not export your data to the class ${
req.body.name
}. Error: ${error}`,
text: `We could not export your data to the class ${req.body.name}. Error: ${error}`,
to: req.body.feedbackEmail,
subject: 'Export failed',
});
Expand Down