Public/Get-SignRequest.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<#
.SYNOPSIS
Get signing request
#>

function Get-SignRequest {
    [CmdletBinding()]
    param (
        # Request id
        [Parameter(Mandatory=$false)]
        [string]
        $id,

        # All requests , Received by the current user or Sent by the current user
        [Parameter(Mandatory=$false)]
        [ValidateSet('All requests','Received by the current user','Sent by the current user')]
        [string]
        $mode='All requests',

        #0 = Draft,1 = Waiting for the current user,2 = Waiting for other users,3 = Completed requests, 4 = Aborted requests
        [Parameter(Mandatory=$false)]
        [ValidateSet('Draft','Waiting for the current user','Waiting for other users','Completed requests','Aborted requests')]
        [string]
        $status,

        #Indicates whether requests from all users should be shown
        [Parameter(Mandatory=$false)]

        [switch]
        $showAll
    )

    begin {
        $api = "/request"
        if ($id) { $api = $api +"/$id"}

        $newmode = @{'All requests' = 0; 'Received by the current user' = 1;'Sent by the current user' = 2}[$mode]
        $body = @{ 'mode' = $newmode }

        if ($showAll) { $body.showAll = $true}
        if ( $null -ne $status) {
            $body['status'] = @{'Draft' = 0; 'Waiting for the current user' = 1; 'Waiting for other users' = 2; 'Completed requests' = 3; 'Aborted requests' = 4}[$status]
        }
    }

    process {
        $result = Invoke-SignApi -api $api -Body $body  -method get
        if ($result.requests) {
            $result.requests
        } elseif ($result.request) {
            $result.request
        }
    }

    end {

    }
}