Public/Documents/Get-UKGDocumentType.ps1
|
function Get-UKGEmployeeDocumentType { <# .SYNOPSIS Gets employee document types from the UKG HR Service Delivery API. .DESCRIPTION Retrieves employee document type definitions by ID or lists all. .PARAMETER Id The unique identifier of the document type to retrieve. .PARAMETER All Retrieves all employee document types. .PARAMETER PerPage Number of results per page (1-100, default 25). .PARAMETER Cursor Pagination cursor for retrieving a specific page. .EXAMPLE Get-UKGEmployeeDocumentType -Id "dt123" .EXAMPLE Get-UKGEmployeeDocumentType -All .OUTPUTS UKG.DocumentType or array of UKG.DocumentType objects. #> [CmdletBinding(DefaultParameterSetName = 'ById')] [OutputType([PSCustomObject])] param( [Parameter(Mandatory, ParameterSetName = 'ById', ValueFromPipelineByPropertyName)] [ValidateNotNullOrEmpty()] [Alias('DocumentTypeId')] [string]$Id, [Parameter(ParameterSetName = 'List')] [switch]$All, [Parameter(ParameterSetName = 'List')] [ValidateRange(1, 100)] [int]$PerPage = 25, [Parameter(ParameterSetName = 'List')] [string]$Cursor ) process { $queryParams = @{} switch ($PSCmdlet.ParameterSetName) { 'ById' { $response = Invoke-UKGRequest -Endpoint "/employee_document_types/$Id" -Method GET if ($response) { $response.PSObject.TypeNames.Insert(0, 'UKG.DocumentType') } return $response } 'List' { $queryParams['per_page'] = $PerPage if ($Cursor) { $queryParams['cursor'] = $Cursor } if ($All -and -not $Cursor) { $allTypes = Get-UKGAllPages -Endpoint '/employee_document_types' -Method GET -QueryParameters $queryParams foreach ($type in $allTypes) { $type.PSObject.TypeNames.Insert(0, 'UKG.DocumentType') } return $allTypes } else { $response = Invoke-UKGRequest -Endpoint '/employee_document_types' -Method GET -QueryParameters $queryParams -ReturnHeaders if ($response.Data) { foreach ($type in $response.Data) { $type.PSObject.TypeNames.Insert(0, 'UKG.DocumentType') } return $response.Data } } } } } } function Set-UKGEmployeeDocumentType { <# .SYNOPSIS Updates an employee document type in the UKG HR Service Delivery system. .DESCRIPTION Updates document type properties using either PUT or PATCH. .PARAMETER Id The unique identifier of the document type to update. .PARAMETER Name The document type name. .PARAMETER Description The document type description. .PARAMETER Properties Hashtable of properties to update. .PARAMETER Replace Use PUT method for full replacement instead of PATCH. .EXAMPLE Set-UKGEmployeeDocumentType -Id "dt123" -Name "Employment Contract" .OUTPUTS UKG.DocumentType object representing the updated document type. #> [CmdletBinding(SupportsShouldProcess)] [OutputType([PSCustomObject])] param( [Parameter(Mandatory, ValueFromPipelineByPropertyName)] [ValidateNotNullOrEmpty()] [Alias('DocumentTypeId')] [string]$Id, [Parameter()] [string]$Name, [Parameter()] [string]$Description, [Parameter()] [hashtable]$Properties, [Parameter()] [switch]$Replace ) process { $body = @{} if ($Name) { $body['name'] = $Name } if ($Description) { $body['description'] = $Description } if ($Properties) { foreach ($key in $Properties.Keys) { $body[$key] = $Properties[$key] } } if ($body.Count -eq 0) { Write-Warning "No properties specified to update." return } $method = if ($Replace) { 'PUT' } else { 'PATCH' } if ($PSCmdlet.ShouldProcess($Id, "Update Employee Document Type ($method)")) { $response = Invoke-UKGRequest -Endpoint "/employee_document_types/$Id" -Method $method -Body $body if ($response) { $response.PSObject.TypeNames.Insert(0, 'UKG.DocumentType') } return $response } } } function Get-UKGCompanyDocumentType { <# .SYNOPSIS Gets company document types from the UKG HR Service Delivery API. .DESCRIPTION Retrieves company document type definitions by ID or lists all. .PARAMETER Id The unique identifier of the document type to retrieve. .PARAMETER All Retrieves all company document types. .PARAMETER PerPage Number of results per page (1-100, default 25). .PARAMETER Cursor Pagination cursor for retrieving a specific page. .EXAMPLE Get-UKGCompanyDocumentType -Id "dt123" .EXAMPLE Get-UKGCompanyDocumentType -All .OUTPUTS UKG.DocumentType or array of UKG.DocumentType objects. #> [CmdletBinding(DefaultParameterSetName = 'ById')] [OutputType([PSCustomObject])] param( [Parameter(Mandatory, ParameterSetName = 'ById', ValueFromPipelineByPropertyName)] [ValidateNotNullOrEmpty()] [Alias('DocumentTypeId')] [string]$Id, [Parameter(ParameterSetName = 'List')] [switch]$All, [Parameter(ParameterSetName = 'List')] [ValidateRange(1, 100)] [int]$PerPage = 25, [Parameter(ParameterSetName = 'List')] [string]$Cursor ) process { $queryParams = @{} switch ($PSCmdlet.ParameterSetName) { 'ById' { $response = Invoke-UKGRequest -Endpoint "/company_document_types/$Id" -Method GET if ($response) { $response.PSObject.TypeNames.Insert(0, 'UKG.DocumentType') } return $response } 'List' { $queryParams['per_page'] = $PerPage if ($Cursor) { $queryParams['cursor'] = $Cursor } if ($All -and -not $Cursor) { $allTypes = Get-UKGAllPages -Endpoint '/company_document_types' -Method GET -QueryParameters $queryParams foreach ($type in $allTypes) { $type.PSObject.TypeNames.Insert(0, 'UKG.DocumentType') } return $allTypes } else { $response = Invoke-UKGRequest -Endpoint '/company_document_types' -Method GET -QueryParameters $queryParams -ReturnHeaders if ($response.Data) { foreach ($type in $response.Data) { $type.PSObject.TypeNames.Insert(0, 'UKG.DocumentType') } return $response.Data } } } } } } function Set-UKGCompanyDocumentType { <# .SYNOPSIS Updates a company document type in the UKG HR Service Delivery system. .DESCRIPTION Updates document type properties using either PUT or PATCH. .PARAMETER Id The unique identifier of the document type to update. .PARAMETER Name The document type name. .PARAMETER Description The document type description. .PARAMETER Properties Hashtable of properties to update. .PARAMETER Replace Use PUT method for full replacement instead of PATCH. .EXAMPLE Set-UKGCompanyDocumentType -Id "dt123" -Name "Company Policy" .OUTPUTS UKG.DocumentType object representing the updated document type. #> [CmdletBinding(SupportsShouldProcess)] [OutputType([PSCustomObject])] param( [Parameter(Mandatory, ValueFromPipelineByPropertyName)] [ValidateNotNullOrEmpty()] [Alias('DocumentTypeId')] [string]$Id, [Parameter()] [string]$Name, [Parameter()] [string]$Description, [Parameter()] [hashtable]$Properties, [Parameter()] [switch]$Replace ) process { $body = @{} if ($Name) { $body['name'] = $Name } if ($Description) { $body['description'] = $Description } if ($Properties) { foreach ($key in $Properties.Keys) { $body[$key] = $Properties[$key] } } if ($body.Count -eq 0) { Write-Warning "No properties specified to update." return } $method = if ($Replace) { 'PUT' } else { 'PATCH' } if ($PSCmdlet.ShouldProcess($Id, "Update Company Document Type ($method)")) { $response = Invoke-UKGRequest -Endpoint "/company_document_types/$Id" -Method $method -Body $body if ($response) { $response.PSObject.TypeNames.Insert(0, 'UKG.DocumentType') } return $response } } } |