@@ -152,12 +152,12 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
152152 }
153153 }
154154 }
155- async deleteWithCascade ( resource : AdminForthResource , primaryKey : string , context : { adminUser : any , response : any } ) {
155+ async deleteWithCascade ( resource : AdminForthResource , primaryKey : string , context : { adminUser : any , response : any } ) : Promise < { error : string | null } > {
156156 const { adminUser, response } = context ;
157157
158158 const record = await this . adminforth . connectors [ resource . dataSource ] . getRecordByPrimaryKey ( resource , primaryKey ) ;
159159
160- if ( ! record ) return ;
160+ if ( ! record ) { return { error : null } ; }
161161
162162 const childResources = this . adminforth . config . resources . filter ( r => r . columns . some ( c => c . foreignResource ?. resourceId === resource . resourceId ) ) ;
163163
@@ -175,7 +175,10 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
175175
176176 if ( strategy === 'cascade' ) {
177177 for ( const childRecord of childRecords ) {
178- await this . deleteWithCascade ( childRes , childRecord [ childPk ] , context ) ;
178+ const childResult = await this . deleteWithCascade ( childRes , childRecord [ childPk ] , context ) ;
179+ if ( childResult ?. error ) {
180+ return childResult ;
181+ }
179182 }
180183 }
181184
@@ -185,8 +188,8 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
185188 }
186189 }
187190 }
188-
189- await this . adminforth . deleteResourceRecord ( { resource , record , adminUser , recordId : primaryKey , response } ) ;
191+ const deleteResult = await this . adminforth . deleteResourceRecord ( { resource , record , adminUser , recordId : primaryKey , response } ) ;
192+ return { error : deleteResult . error } ;
190193 }
191194
192195 registerEndpoints ( server : IHttpServer ) {
0 commit comments