Skip to content

Commit

Permalink
Search-TssReportSchedule - adjust logic, add SortBy
Browse files Browse the repository at this point in the history
  • Loading branch information
wsmelton committed Jan 21, 2021
1 parent b64ea8b commit ace866d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
16 changes: 11 additions & 5 deletions src/functions/reports/Search-ReportSchedule.ps1
Expand Up @@ -38,6 +38,10 @@
[int]
$ReportId,

# Sort by specific property, default Name
[string]
$SortBy = 'Name',

# Output the raw response from the REST API endpoint
[switch]
$Raw
Expand All @@ -49,14 +53,13 @@
$reportSchedParams = . $SearchReportSchedParams $PSBoundParameters
$reportSchedParams.Remove('TssSession')
$reportSchedParams.Remove('Raw')

}

process {
Write-Verbose "Provided command parameters: $(. $GetInvocation $PSCmdlet.MyInvocation)"
if ($tssParams.Contains('TssSession') -and $TssSession.IsValidSession()) {
$uri = $TssSession.ApiUrl, 'reports', 'schedules' -join '/'
$uri += "?take=$($TssSession.Take)"
$uri += "?sortBy[0].direction=asc&sortBy[0].name=$SortBy&take=$($TssSession.Take)"

$filters = @()
if ($reportSchedParams.Contains('IncludeDeleted')) {
Expand All @@ -65,9 +68,12 @@
if ($reportSchedParams.Contains('ReportId')) {
$filters += "filter.reportId=$ReportId"
}
$uriFilter = $filters -join '&'
Write-Verbose "Filters: $uriFilter"
$uri = $uri, $uriFilter -join '&'

if ($filters) {
$uriFilter = $filters -join '&'
Write-Verbose "Filters: $uriFilter"
$uri = $uri, $uriFilter -join '&'
}

$invokeParams.Uri = $uri
$invokeParams.PersonalAccessToken = $TssSession.AccessToken
Expand Down
2 changes: 1 addition & 1 deletion tests/reports/Search-TssReportSchedule.Tests.ps1
Expand Up @@ -4,7 +4,7 @@
}
Describe "$commandName verify parameters" {
BeforeDiscovery {
[object[]]$knownParameters = 'TssSession', 'IncludeDeleted', 'ReportId', 'Raw'
[object[]]$knownParameters = 'TssSession', 'SortBy', 'IncludeDeleted', 'ReportId', 'Raw'
[object[]]$currentParams = ([Management.Automation.CommandMetaData]$ExecutionContext.SessionState.InvokeCommand.GetCommand($commandName,'Function')).Parameters.Keys
[object[]]$commandDetails = [System.Management.Automation.CommandInfo]$ExecutionContext.SessionState.InvokeCommand.GetCommand($commandName,'Function')
$unknownParameters = Compare-Object -ReferenceObject $knownParameters -DifferenceObject $currentParams -PassThru
Expand Down

0 comments on commit ace866d

Please sign in to comment.