-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSCCDeputy.psm1
161 lines (141 loc) · 3.96 KB
/
SCCDeputy.psm1
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
#region Import Functions
#Get public and private function definition files.
$Public = @( Get-ChildItem -Path $PSScriptRoot\Public\*.ps1 -ErrorAction SilentlyContinue )
$Private = @( Get-ChildItem -Path $PSScriptRoot\Private\*.ps1 -ErrorAction SilentlyContinue )
#Dot source the files
Foreach($import in @($Public + $Private))
{
Try
{
. $import.fullname
}
Catch
{
Write-Error -Message "Failed to import function $($import.fullname): $_"
}
}
#endregion
#Load the config file
$Script:Config = Import-PowerShellDataFile $PSScriptRoot\config.psd1
#If there's no API Key loaded in the profile, prompt the user to set one, unless it's the task scheduling user. In that case, load from config.
if(!$DeputyAPIKey -and $env:USERNAME -ne $Config.ScheduledTask.User){
Set-DeputyAPIKey
}
if($env:USERNAME -eq $Config.ScheduledTask.User){
$Global:DeputyAPIKey = $Config.ScheduledTask.APIKey
}
Export-ModuleMember -Function $Public.Basename
enum DeputyResource {
Address
Category
Comment
Company
CompanyPeriod
Contact
Country
CustomAppData
CustomField
CustomFieldData
Employee
EmployeeAgreement
EmployeeAgreementHistory
EmployeeAppraisal
EmployeeAvailability
EmployeeHistory
EmployeePaycycle
EmployeePaycycleReturn
EmployeeRole
EmployeeSalaryOpunitCosting
EmployeeWorkplace
EmploymentCondition
EmploymentContract
EmploymentContractLeaveRules
Event
Geo
Journal
Kiosk
Leave
LeaveAccrual
LeavePayLine
LeaveRules
Memo
OperationalUnit
PayPeriod
PayRules
PublicHoliday
Roster
RosterOpen
RosterSwap
SalesData
Schedule
SmsLog
State
StressProfile
SystemUsageBalance
SystemUsageTracking
Task
TaskGroup
TaskGroupSetup
TaskOpunitConfig
TaskSetup
Team
Timesheet
TimesheetPayReturn
TrainingModule
TrainingRecord
Webhook
}
class DeputySearchQuery {
[hashtable]$HashTable
DeputySearchQuery(){
$this.HashTable = @{search = @{}}
}
DeputySearchQuery([string]$Field,[string]$Opr,$Data){
$this.HashTable = @{search = @{}}
$this.addfield($Field,$Opr,$Data)
}
DeputySearchQuery([string]$Field,[string]$Opr,$Data,[string]$Join){
$this.HashTable = @{search = @{}}
$this.addfield($Field,$Opr,$Data,$Join)
}
[string]Json(){
return ($this.HashTable | ConvertTo-Json -Depth 100)
}
[void]AddField([string]$Field,[string]$Opr,$Data){
$fCount = $this.HashTable.search.keys.count
$fname = 'f'+($fcount+1)
$this.HashTable.search.add($fname,@{})
$this.HashTable.search.$fname.add('field',$Field)
$this.HashTable.search.$fname.add('type',$Opr)
$this.HashTable.search.$fname.add('data',$Data)
}
[void]AddField([string]$Field,[string]$Opr,$Data,[string]$Join){
$fCount = $this.HashTable.search.keys.count
$fname = 'f'+($fcount+1)
$this.HashTable.search.add($fname,@{})
$this.HashTable.search.$fname.add('field',$Field)
$this.HashTable.search.$fname.add('type',$Opr)
$this.HashTable.search.$fname.add('data',$Data)
$this.HashTable.search.$fname.add('join',$Join)
}
[void]AddSort([string]$Field,[string]$Sort){
if($Sort -inotin @('asc','desc')){
throw 'sort must be asc or desc'
}
if(!$this.HashTable.ContainsKey('sort')){
$this.HashTable.sort = @{$Field = $Sort}
}else{
$this.HashTable.sort.Add($Field,$Sort)
}
}
[void]SetJoin([string[]]$JoinObjects){
$this.HashTable.join = $JoinObjects
}
[void]SetAssoc([string[]]$AssocObjects){
$this.HashTable.assoc = $AssocObjects
}
[void]SetOffset([int]$Offset){
$this.HashTable.start = $Offset
}
}