@uidu/client 3.1.1 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +32 -0
- package/dist/declarations/src/generated/index.d.ts +260 -0
- package/dist/declarations/src/index.d.ts +3 -3
- package/dist/declarations/src/mutations.d.ts +122 -1
- package/dist/declarations/src/people.d.ts +69 -1
- package/dist/uidu-client.cjs.dev.js +170 -1
- package/dist/uidu-client.cjs.prod.js +170 -1
- package/dist/uidu-client.esm.js +158 -2
- package/package.json +1 -1
- package/src/generated/index.ts +78 -0
- package/src/index.ts +28 -2
- package/src/mutations.test.ts +43 -0
- package/src/mutations.ts +49 -0
- package/src/people.test.ts +114 -2
- package/src/people.ts +207 -0
- package/src/queries/people/ListCircles.graphql +17 -0
- package/src/queries/people/ListEmploymentHistory.graphql +36 -0
- package/src/queries/people/ListKinds.graphql +18 -0
- package/src/queries/people/ListOffices.graphql +16 -0
- package/src/queries/people/PeopleMutations.graphql +88 -0
package/src/people.ts
CHANGED
|
@@ -3,15 +3,56 @@ import {
|
|
|
3
3
|
GetEmployeeDocument,
|
|
4
4
|
type GetEmployeeQuery,
|
|
5
5
|
type GetEmployeeQueryVariables,
|
|
6
|
+
ListCirclesDocument,
|
|
7
|
+
type ListCirclesQuery,
|
|
8
|
+
type ListCirclesQueryVariables,
|
|
6
9
|
ListEmployeesDocument,
|
|
7
10
|
type ListEmployeesQueryVariables,
|
|
11
|
+
ListEmploymentHistoryDocument,
|
|
12
|
+
type ListEmploymentHistoryQueryVariables,
|
|
13
|
+
ListKindsDocument,
|
|
14
|
+
type ListKindsQuery,
|
|
15
|
+
type ListKindsQueryVariables,
|
|
16
|
+
ListOfficesDocument,
|
|
17
|
+
type ListOfficesQuery,
|
|
18
|
+
type ListOfficesQueryVariables,
|
|
8
19
|
} from './generated';
|
|
20
|
+
|
|
9
21
|
import { nodes } from './utils/relay';
|
|
10
22
|
|
|
11
23
|
export type Employee = NonNullable<
|
|
12
24
|
NonNullable<GetEmployeeQuery['currentWorkspace']>['employee']
|
|
13
25
|
>;
|
|
14
26
|
|
|
27
|
+
export type Circle = NonNullable<
|
|
28
|
+
NonNullable<
|
|
29
|
+
NonNullable<
|
|
30
|
+
NonNullable<
|
|
31
|
+
NonNullable<ListCirclesQuery['currentWorkspace']>['circles']
|
|
32
|
+
>['edges']
|
|
33
|
+
>[number]
|
|
34
|
+
>['node']
|
|
35
|
+
>;
|
|
36
|
+
export type Office = NonNullable<
|
|
37
|
+
NonNullable<
|
|
38
|
+
NonNullable<
|
|
39
|
+
NonNullable<
|
|
40
|
+
NonNullable<ListOfficesQuery['currentWorkspace']>['offices']
|
|
41
|
+
>['edges']
|
|
42
|
+
>[number]
|
|
43
|
+
>['node']
|
|
44
|
+
>;
|
|
45
|
+
/** A `Kind` record — CCNLs (national collective labor contracts) are Kinds. */
|
|
46
|
+
export type Kind = NonNullable<
|
|
47
|
+
NonNullable<
|
|
48
|
+
NonNullable<
|
|
49
|
+
NonNullable<
|
|
50
|
+
NonNullable<ListKindsQuery['currentWorkspace']>['kinds']
|
|
51
|
+
>['edges']
|
|
52
|
+
>[number]
|
|
53
|
+
>['node']
|
|
54
|
+
>;
|
|
55
|
+
|
|
15
56
|
export async function listEmployees(
|
|
16
57
|
client: UiduClient,
|
|
17
58
|
variables: ListEmployeesQueryVariables = {},
|
|
@@ -41,3 +82,169 @@ export function weekStartFor(date: Date = new Date()): string {
|
|
|
41
82
|
d.setUTCDate(d.getUTCDate() - diff);
|
|
42
83
|
return d.toISOString().slice(0, 10);
|
|
43
84
|
}
|
|
85
|
+
|
|
86
|
+
// --- Reference data (for populating employment forms) ---
|
|
87
|
+
|
|
88
|
+
/** List the workspace offices — used for an employment's `employmentOfficesAttributes`. */
|
|
89
|
+
export async function listOffices(
|
|
90
|
+
client: UiduClient,
|
|
91
|
+
variables: ListOfficesQueryVariables = {},
|
|
92
|
+
): Promise<Office[]> {
|
|
93
|
+
const result = await client.query(ListOfficesDocument, variables);
|
|
94
|
+
return nodes(result.currentWorkspace?.offices);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* List the workspace circles. Circles come in two flavours distinguished by
|
|
99
|
+
* `kind`: org units (e.g. departments — used as an employment's `circleId`) and
|
|
100
|
+
* roles (`kind === 'role'` — used as an employment's `roleId`). Use
|
|
101
|
+
* {@link listRoles} when you only want the role-Circles.
|
|
102
|
+
*/
|
|
103
|
+
export async function listCircles(
|
|
104
|
+
client: UiduClient,
|
|
105
|
+
variables: ListCirclesQueryVariables = {},
|
|
106
|
+
): Promise<Circle[]> {
|
|
107
|
+
const result = await client.query(ListCirclesDocument, variables);
|
|
108
|
+
return nodes(result.currentWorkspace?.circles);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** List only the role-Circles (structured job titles) — an employment's `roleId`. */
|
|
112
|
+
export async function listRoles(
|
|
113
|
+
client: UiduClient,
|
|
114
|
+
variables: ListCirclesQueryVariables = {},
|
|
115
|
+
): Promise<Circle[]> {
|
|
116
|
+
const circles = await listCircles(client, variables);
|
|
117
|
+
return circles.filter((c) => c.kind === 'role');
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** List `Kind` records for the given polymorphic models. */
|
|
121
|
+
export async function listKinds(
|
|
122
|
+
client: UiduClient,
|
|
123
|
+
variables: ListKindsQueryVariables,
|
|
124
|
+
): Promise<Kind[]> {
|
|
125
|
+
const result = await client.query(ListKindsDocument, variables);
|
|
126
|
+
return nodes(result.currentWorkspace?.kinds);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* List the CCNLs (national collective labor contracts) configured for the
|
|
131
|
+
* workspace — used for an employment's `ccnlId`.
|
|
132
|
+
*/
|
|
133
|
+
export async function listCcnls(
|
|
134
|
+
client: UiduClient,
|
|
135
|
+
variables: Omit<ListKindsQueryVariables, 'models'> = {},
|
|
136
|
+
): Promise<Kind[]> {
|
|
137
|
+
return listKinds(client, { ...variables, models: ['Ccnl'] });
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// --- Employment history & contract events ---
|
|
141
|
+
|
|
142
|
+
/** A single contract (employment) reduced to the fields that describe its span. */
|
|
143
|
+
export type EmploymentRecord = {
|
|
144
|
+
id: string;
|
|
145
|
+
startDate: string | null;
|
|
146
|
+
endDate: string | null;
|
|
147
|
+
endReason: string | null;
|
|
148
|
+
jobTitle: string | null;
|
|
149
|
+
contractType: string | null;
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
/** An employee together with their full list of contracts. */
|
|
153
|
+
export type EmployeeContracts = {
|
|
154
|
+
id: string;
|
|
155
|
+
name: string;
|
|
156
|
+
employments: EmploymentRecord[];
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* List every employee with their full employment (contract) history — not just
|
|
161
|
+
* the current one. Use {@link contractEvents} to turn this into a flat, dated
|
|
162
|
+
* list of hires, terminations and contract variations.
|
|
163
|
+
*/
|
|
164
|
+
export async function listEmploymentHistory(
|
|
165
|
+
client: UiduClient,
|
|
166
|
+
variables: ListEmploymentHistoryQueryVariables = {},
|
|
167
|
+
): Promise<EmployeeContracts[]> {
|
|
168
|
+
const result = await client.query(ListEmploymentHistoryDocument, {
|
|
169
|
+
employmentsFirst: 50,
|
|
170
|
+
...variables,
|
|
171
|
+
});
|
|
172
|
+
return nodes(result.currentWorkspace?.employees).map((employee) => ({
|
|
173
|
+
id: employee.id ?? '',
|
|
174
|
+
name: employee.user?.name || employee.user?.email || 'Senza nome',
|
|
175
|
+
employments: nodes(employee.employments).map((e) => ({
|
|
176
|
+
id: e.id ?? '',
|
|
177
|
+
startDate: e.startDate ?? null,
|
|
178
|
+
endDate: e.endDate ?? null,
|
|
179
|
+
endReason: e.endReason ?? null,
|
|
180
|
+
jobTitle: e.jobTitle ?? null,
|
|
181
|
+
contractType: e.contractType ?? null,
|
|
182
|
+
})),
|
|
183
|
+
}));
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export type ContractEventType = 'hire' | 'variation' | 'termination';
|
|
187
|
+
|
|
188
|
+
/** A dated contract event derived from employment history. */
|
|
189
|
+
export type ContractEvent = {
|
|
190
|
+
type: ContractEventType;
|
|
191
|
+
/** ISO8601 date (YYYY-MM-DD) the event happened on. */
|
|
192
|
+
date: string;
|
|
193
|
+
/** Year-month bucket (YYYY-MM), convenient for grouping. */
|
|
194
|
+
month: string;
|
|
195
|
+
employeeId: string;
|
|
196
|
+
employeeName: string;
|
|
197
|
+
employmentId: string;
|
|
198
|
+
jobTitle: string | null;
|
|
199
|
+
contractType: string | null;
|
|
200
|
+
/** Only set on `termination` events. */
|
|
201
|
+
endReason: string | null;
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Flatten employment history into dated contract events, most recent first:
|
|
206
|
+
* - the employee's earliest contract is a `hire` (assunzione) on its start date;
|
|
207
|
+
* - every later contract is a `variation` (variazione) on its start date;
|
|
208
|
+
* - any contract with an end date yields a `termination` (cessazione) on it.
|
|
209
|
+
*
|
|
210
|
+
* Contracts without a start date are ignored.
|
|
211
|
+
*/
|
|
212
|
+
export function contractEvents(employees: EmployeeContracts[]): ContractEvent[] {
|
|
213
|
+
const events: ContractEvent[] = [];
|
|
214
|
+
|
|
215
|
+
for (const employee of employees) {
|
|
216
|
+
const dated = employee.employments
|
|
217
|
+
.filter((e) => e.startDate)
|
|
218
|
+
.sort((a, b) => (a.startDate! < b.startDate! ? -1 : 1));
|
|
219
|
+
|
|
220
|
+
dated.forEach((employment, index) => {
|
|
221
|
+
const base = {
|
|
222
|
+
employeeId: employee.id,
|
|
223
|
+
employeeName: employee.name,
|
|
224
|
+
employmentId: employment.id,
|
|
225
|
+
jobTitle: employment.jobTitle,
|
|
226
|
+
contractType: employment.contractType,
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
events.push({
|
|
230
|
+
...base,
|
|
231
|
+
type: index === 0 ? 'hire' : 'variation',
|
|
232
|
+
date: employment.startDate!,
|
|
233
|
+
month: employment.startDate!.slice(0, 7),
|
|
234
|
+
endReason: null,
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
if (employment.endDate) {
|
|
238
|
+
events.push({
|
|
239
|
+
...base,
|
|
240
|
+
type: 'termination',
|
|
241
|
+
date: employment.endDate,
|
|
242
|
+
month: employment.endDate.slice(0, 7),
|
|
243
|
+
endReason: employment.endReason,
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
return events.sort((a, b) => (a.date < b.date ? 1 : a.date > b.date ? -1 : 0));
|
|
250
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
query ListEmploymentHistory(
|
|
2
|
+
$first: Int
|
|
3
|
+
$after: String
|
|
4
|
+
$employmentsFirst: Int
|
|
5
|
+
) {
|
|
6
|
+
currentWorkspace {
|
|
7
|
+
employees(first: $first, after: $after) {
|
|
8
|
+
pageInfo {
|
|
9
|
+
hasNextPage
|
|
10
|
+
endCursor
|
|
11
|
+
}
|
|
12
|
+
edges {
|
|
13
|
+
node {
|
|
14
|
+
id
|
|
15
|
+
user {
|
|
16
|
+
id
|
|
17
|
+
name
|
|
18
|
+
email
|
|
19
|
+
}
|
|
20
|
+
employments(first: $employmentsFirst) {
|
|
21
|
+
edges {
|
|
22
|
+
node {
|
|
23
|
+
id
|
|
24
|
+
startDate
|
|
25
|
+
endDate
|
|
26
|
+
endReason
|
|
27
|
+
jobTitle
|
|
28
|
+
contractType
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
query ListKinds($models: [String!]!, $first: Int, $after: String) {
|
|
2
|
+
currentWorkspace {
|
|
3
|
+
kinds(models: $models, first: $first, after: $after) {
|
|
4
|
+
pageInfo {
|
|
5
|
+
hasNextPage
|
|
6
|
+
endCursor
|
|
7
|
+
}
|
|
8
|
+
edges {
|
|
9
|
+
node {
|
|
10
|
+
id
|
|
11
|
+
name
|
|
12
|
+
code
|
|
13
|
+
model
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
mutation CreateEmployee($input: CreateEmployeeInput!) {
|
|
2
|
+
createEmployee(input: $input) {
|
|
3
|
+
employee {
|
|
4
|
+
node {
|
|
5
|
+
id
|
|
6
|
+
employeeCode
|
|
7
|
+
user {
|
|
8
|
+
id
|
|
9
|
+
name
|
|
10
|
+
email
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
errors {
|
|
15
|
+
key
|
|
16
|
+
name
|
|
17
|
+
type
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
mutation UpdateEmployee($input: UpdateEmployeeInput!) {
|
|
23
|
+
updateEmployee(input: $input) {
|
|
24
|
+
employee {
|
|
25
|
+
id
|
|
26
|
+
employeeCode
|
|
27
|
+
}
|
|
28
|
+
errors {
|
|
29
|
+
key
|
|
30
|
+
name
|
|
31
|
+
type
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
mutation CreateEmployment($input: CreateEmploymentInput!) {
|
|
37
|
+
createEmployment(input: $input) {
|
|
38
|
+
employment {
|
|
39
|
+
node {
|
|
40
|
+
id
|
|
41
|
+
jobTitle
|
|
42
|
+
contractType
|
|
43
|
+
classification
|
|
44
|
+
startDate
|
|
45
|
+
endDate
|
|
46
|
+
isActive
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
errors {
|
|
50
|
+
key
|
|
51
|
+
name
|
|
52
|
+
type
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
mutation UpdateEmployment($input: UpdateEmploymentInput!) {
|
|
58
|
+
updateEmployment(input: $input) {
|
|
59
|
+
employment {
|
|
60
|
+
id
|
|
61
|
+
jobTitle
|
|
62
|
+
contractType
|
|
63
|
+
classification
|
|
64
|
+
startDate
|
|
65
|
+
endDate
|
|
66
|
+
endReason
|
|
67
|
+
isActive
|
|
68
|
+
}
|
|
69
|
+
errors {
|
|
70
|
+
key
|
|
71
|
+
name
|
|
72
|
+
type
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
mutation DeleteEmployment($input: DeleteEmploymentInput!) {
|
|
78
|
+
deleteEmployment(input: $input) {
|
|
79
|
+
employment {
|
|
80
|
+
id
|
|
81
|
+
}
|
|
82
|
+
errors {
|
|
83
|
+
key
|
|
84
|
+
name
|
|
85
|
+
type
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|