@@ -131,6 +131,14 @@ export default class ImportExport extends AdminForthPlugin {
131131 return { ok : false , errors } ;
132132 }
133133
134+ const primaryKeyColumn = this . resourceConfig . columns . find ( col => col . primaryKey ) ;
135+ if ( ! primaryKeyColumn ) {
136+ return {
137+ ok : false ,
138+ errors : [ 'Resource has no primary key column' ]
139+ } ;
140+ }
141+
134142 const columnValues : any [ ] = Object . values ( data ) ;
135143 for ( let i = 0 ; i < columnValues [ 0 ] . length ; i ++ ) {
136144 const row = { } ;
@@ -142,7 +150,6 @@ export default class ImportExport extends AdminForthPlugin {
142150
143151 let importedCount = 0 ;
144152 let updatedCount = 0 ;
145- const primaryKeyColumn = this . resourceConfig . columns . find ( col => col . primaryKey ) ;
146153
147154 await Promise . all ( rows . map ( async ( row ) => {
148155 try {
@@ -191,6 +198,14 @@ export default class ImportExport extends AdminForthPlugin {
191198 return { ok : false , errors } ;
192199 }
193200
201+ const primaryKeyColumn = this . resourceConfig . columns . find ( col => col . primaryKey ) ;
202+ if ( ! primaryKeyColumn ) {
203+ return {
204+ ok : false ,
205+ errors : [ 'Resource has no primary key column' ]
206+ } ;
207+ }
208+
194209 const columnValues : any [ ] = Object . values ( data ) ;
195210 for ( let i = 0 ; i < columnValues [ 0 ] . length ; i ++ ) {
196211 const row = { } ;
@@ -201,7 +216,6 @@ export default class ImportExport extends AdminForthPlugin {
201216 }
202217
203218 let importedCount = 0 ;
204- const primaryKeyColumn = this . resourceConfig . columns . find ( col => col . primaryKey ) ;
205219
206220 await Promise . all ( rows . map ( async ( row ) => {
207221 try {
@@ -233,6 +247,13 @@ export default class ImportExport extends AdminForthPlugin {
233247
234248 const primaryKeyColumn = this . resourceConfig . columns . find ( col => col . primaryKey ) ;
235249
250+ if ( ! primaryKeyColumn ) {
251+ return {
252+ ok : false ,
253+ error : { message : 'Resource has no primary key column' } ,
254+ } ;
255+ }
256+
236257 const rows = [ ] ;
237258 const columns = Object . keys ( data ) ;
238259 const columnValues = Object . values ( data ) ;
0 commit comments