Skip to content

Commit

Permalink
Merge branch 'feature-DATAAPI-2_delete_by_filters_without_id_not_queu…
Browse files Browse the repository at this point in the history
…ed' of https://github.com/jtcy0123/preside-ext-data-api into feature-DATAAPI-2_delete-by-filters-without-id
  • Loading branch information
DominicWatson committed Jun 24, 2021
2 parents 2409ff4 + c0e80e6 commit b12c0bd
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
8 changes: 8 additions & 0 deletions interceptors/DataApiInterceptors.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ component extends="coldbox.system.Interceptor" {
}
}

public void function preDeleteObjectData( event, interceptData ) {
if ( !_applicationLoaded ) return;

if( isEmptyString( interceptData.id ?: "" ) ){
interceptData.deletedIds = dataApiQueueService.getDeletedRecordIds( argumentCollection = interceptData );
}
}

public void function postDeleteObjectData( event, interceptData ) {
if ( !_applicationLoaded ) return;

Expand Down
26 changes: 26 additions & 0 deletions services/DataApiQueueService.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,11 @@ component {
string objectName = ""
, string id = ""
, any filter = {}
, array deletedIds = []
) {
if( $helpers.isEmptyString( filter.id ?: "" ) && arrayLen( deletedIds ) ) {
filter = { id = deletedIds };
}
if ( IsStruct( filter ) && filter.count() == 1 ) {
var value = filter.id ?: ( filter[ "#objectName#.id" ] ?: "" );
if ( !IsArray( value ) ) {
Expand Down Expand Up @@ -349,6 +353,28 @@ component {
return subscribers;
}

public array function getDeletedRecordIds (
required string objectName
, any filter = {}
, struct filterParams = {}
, array extraFilters = []
, array savedFilters = []
){
var values = [];

arguments.selectFields = [ "id" ];

try{
var queuedObj = $getPresideObject( objectName ).selectData( argumentCollection=arguments );
if( queuedObj.recordcount ) {
values = valueArray( queuedObj, "id" );
}
} catch( any e ) {
values = [];
}

return values;
}

// PRIVATE HELPERS
private struct function _getQueueFilter( required string queueName ) {
Expand Down

0 comments on commit b12c0bd

Please sign in to comment.