@@ -11,7 +11,7 @@ const relationSchema = {
11
11
} ;
12
12
13
13
export class ExportRouter extends PromiseRouter {
14
- exportClassPage ( req , name , jsonFileStream , where , skip , limit ) {
14
+ exportClassPage ( req , className , jsonFileStream , where , skip , limit ) {
15
15
const databaseController = req . config . database ;
16
16
17
17
const options = {
@@ -20,13 +20,32 @@ export class ExportRouter extends PromiseRouter {
20
20
} ;
21
21
22
22
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 ) ;
26
31
27
32
return findPromise . then ( data => {
28
33
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
+ } ;
30
49
}
31
50
32
51
if ( skip && data . results . length ) {
@@ -190,9 +209,7 @@ export class ExportRouter extends PromiseRouter {
190
209
} )
191
210
. then ( fileData => {
192
211
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
196
213
Please download from ${ fileData . url } ` ,
197
214
link : fileData . url ,
198
215
to : req . body . feedbackEmail ,
@@ -201,9 +218,7 @@ export class ExportRouter extends PromiseRouter {
201
218
} )
202
219
. catch ( error => {
203
220
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 } ` ,
207
222
to : req . body . feedbackEmail ,
208
223
subject : 'Export failed' ,
209
224
} ) ;
0 commit comments