@@ -360,10 +360,16 @@ function Invoke-ExecCustomData {
360360 try {
361361 $Mappings = Get-CIPPAzDataTableEntity @CustomDataMappingsTable | ForEach-Object {
362362 $Mapping = $_.JSON | ConvertFrom-Json - AsHashtable
363+
364+ Write-Information ($Mapping | ConvertTo-Json - Depth 5 )
363365 [PSCustomObject ]@ {
364- id = $_.RowKey
365- tenant = $Mapping.tenantFilter.label
366- sourceDataset = $Mapping.sourceDataset.label
366+ id = $_.RowKey
367+ tenant = $Mapping.tenantFilter.label
368+ dataset = $Mapping.extensionSyncDataset.label
369+ sourceType = $Mapping.sourceType.label
370+ directoryType = $Mapping.directoryObjectType.label
371+ syncProperty = $Mapping.extensionSyncProperty.label
372+ customDataAttribute = $Mapping.customDataAttribute.label
367373 }
368374 }
369375 $Body = @ {
@@ -380,16 +386,16 @@ function Invoke-ExecCustomData {
380386 }
381387 }
382388 }
383- ' AddMapping ' {
389+ ' AddEditMapping ' {
384390 try {
385391 $Mapping = $Request.Body.Mapping
386392 if (! $Mapping ) {
387393 throw ' Mapping data is missing in the request body.'
388394 }
389- $id = [Guid ]::NewGuid().ToString()
395+ $MappingId = $Request .Body.id ?? [Guid ]::NewGuid().ToString()
390396 $Entity = @ {
391397 PartitionKey = ' Mapping'
392- RowKey = $id
398+ RowKey = [ string ] $MappingId
393399 JSON = [string ]($Mapping | ConvertTo-Json - Depth 5 - Compress)
394400 }
395401
@@ -399,7 +405,7 @@ function Invoke-ExecCustomData {
399405 $Body = @ {
400406 Results = @ {
401407 state = ' success'
402- resultText = " Mapping with ID ' $ ( $id ) ' added successfully."
408+ resultText = ' Mapping saved successfully.'
403409 }
404410 }
405411 } catch {
@@ -413,6 +419,67 @@ function Invoke-ExecCustomData {
413419 }
414420 }
415421 }
422+ ' DeleteMapping' {
423+ try {
424+ $MappingId = $Request.Body.id
425+ if (! $MappingId ) {
426+ throw ' Mapping ID is missing in the request body.'
427+ }
428+
429+ # Retrieve the mapping entity
430+ $MappingEntity = Get-CIPPAzDataTableEntity @CustomDataMappingsTable - Filter " PartitionKey eq 'Mapping' and RowKey eq '$MappingId '"
431+ if (! $MappingEntity ) {
432+ throw " Mapping with ID '$MappingId ' not found."
433+ }
434+
435+ # Delete the mapping entity
436+ Remove-AzDataTableEntity @CustomDataMappingsTable - Entity $MappingEntity
437+ Register-CIPPExtensionScheduledTasks
438+ $Body = @ {
439+ Results = @ {
440+ state = ' success'
441+ resultText = " Mapping deleted successfully."
442+ }
443+ }
444+ } catch {
445+ $Body = @ {
446+ Results = @ (
447+ @ {
448+ state = ' error'
449+ resultText = " Failed to delete mapping: $ ( $_.Exception.Message ) "
450+ }
451+ )
452+ }
453+ }
454+ }
455+ ' GetMapping' {
456+ try {
457+ $MappingId = $Request.Query.id
458+ if (! $MappingId ) {
459+ throw ' Mapping ID is missing in the request query.'
460+ }
461+
462+ # Retrieve the mapping entity
463+ $MappingEntity = Get-CIPPAzDataTableEntity @CustomDataMappingsTable - Filter " PartitionKey eq 'Mapping' and RowKey eq '$MappingId '"
464+ if (! $MappingEntity ) {
465+ throw " Mapping with ID '$MappingId ' not found."
466+ }
467+
468+ $Mapping = $MappingEntity.JSON | ConvertFrom-Json
469+ $Body = @ {
470+ Results = $Mapping
471+ }
472+ } catch {
473+ $Body = @ {
474+ Results = @ (
475+ @ {
476+ state = ' error'
477+ resultText = " Failed to retrieve mapping: $ ( $_.Exception.Message ) "
478+ }
479+ )
480+ }
481+ }
482+ }
416483
417484 default {
418485 $Body = @ {
0 commit comments