@uidu/client 3.2.0 → 3.4.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/src/people.ts CHANGED
@@ -8,6 +8,8 @@ import {
8
8
  type ListCirclesQueryVariables,
9
9
  ListEmployeesDocument,
10
10
  type ListEmployeesQueryVariables,
11
+ ListEmploymentHistoryDocument,
12
+ type ListEmploymentHistoryQueryVariables,
11
13
  ListKindsDocument,
12
14
  type ListKindsQuery,
13
15
  type ListKindsQueryVariables,
@@ -134,3 +136,144 @@ export async function listCcnls(
134
136
  ): Promise<Kind[]> {
135
137
  return listKinds(client, { ...variables, models: ['Ccnl'] });
136
138
  }
139
+
140
+ // --- Employment history & contract events ---
141
+
142
+ /** A pay item attached to a contract. */
143
+ export type CompensationRecord = {
144
+ id: string;
145
+ amount: number | null;
146
+ currency: string | null;
147
+ /** e.g. monthly, yearly, hourly. */
148
+ frequency: string | null;
149
+ /** e.g. base, bonus. */
150
+ componentType: string | null;
151
+ effectiveFrom: string | null;
152
+ };
153
+
154
+ /** A single contract (employment) reduced to the fields that describe its span. */
155
+ export type EmploymentRecord = {
156
+ id: string;
157
+ startDate: string | null;
158
+ endDate: string | null;
159
+ endReason: string | null;
160
+ jobTitle: string | null;
161
+ contractType: string | null;
162
+ /** The CCNL (national collective labor contract) that applies, if any. */
163
+ ccnl: { id: string; name: string | null } | null;
164
+ /** Pay items on this contract, most recent effective date first. */
165
+ compensations: CompensationRecord[];
166
+ };
167
+
168
+ /** An employee together with their full list of contracts. */
169
+ export type EmployeeContracts = {
170
+ id: string;
171
+ name: string;
172
+ employments: EmploymentRecord[];
173
+ };
174
+
175
+ /**
176
+ * List every employee with their full employment (contract) history — not just
177
+ * the current one. Use {@link contractEvents} to turn this into a flat, dated
178
+ * list of hires, terminations and contract variations.
179
+ */
180
+ export async function listEmploymentHistory(
181
+ client: UiduClient,
182
+ variables: ListEmploymentHistoryQueryVariables = {},
183
+ ): Promise<EmployeeContracts[]> {
184
+ const result = await client.query(ListEmploymentHistoryDocument, {
185
+ employmentsFirst: 50,
186
+ ...variables,
187
+ });
188
+ return nodes(result.currentWorkspace?.employees).map((employee) => ({
189
+ id: employee.id ?? '',
190
+ name: employee.user?.name || employee.user?.email || 'Senza nome',
191
+ employments: nodes(employee.employments).map((e) => ({
192
+ id: e.id ?? '',
193
+ startDate: e.startDate ?? null,
194
+ endDate: e.endDate ?? null,
195
+ endReason: e.endReason ?? null,
196
+ jobTitle: e.jobTitle ?? null,
197
+ contractType: e.contractType ?? null,
198
+ ccnl: e.ccnl ? { id: e.ccnl.id ?? '', name: e.ccnl.name ?? null } : null,
199
+ compensations: nodes(e.compensations)
200
+ .map((c) => ({
201
+ id: c.id ?? '',
202
+ amount: c.amount ?? null,
203
+ currency: c.currency ?? null,
204
+ frequency: c.frequency ?? null,
205
+ componentType: c.componentType ?? null,
206
+ effectiveFrom: c.effectiveFrom ?? null,
207
+ }))
208
+ .sort((a, b) =>
209
+ (b.effectiveFrom ?? '').localeCompare(a.effectiveFrom ?? ''),
210
+ ),
211
+ })),
212
+ }));
213
+ }
214
+
215
+ export type ContractEventType = 'hire' | 'variation' | 'termination';
216
+
217
+ /** A dated contract event derived from employment history. */
218
+ export type ContractEvent = {
219
+ type: ContractEventType;
220
+ /** ISO8601 date (YYYY-MM-DD) the event happened on. */
221
+ date: string;
222
+ /** Year-month bucket (YYYY-MM), convenient for grouping. */
223
+ month: string;
224
+ employeeId: string;
225
+ employeeName: string;
226
+ employmentId: string;
227
+ jobTitle: string | null;
228
+ contractType: string | null;
229
+ /** Only set on `termination` events. */
230
+ endReason: string | null;
231
+ };
232
+
233
+ /**
234
+ * Flatten employment history into dated contract events, most recent first:
235
+ * - the employee's earliest contract is a `hire` (assunzione) on its start date;
236
+ * - every later contract is a `variation` (variazione) on its start date;
237
+ * - any contract with an end date yields a `termination` (cessazione) on it.
238
+ *
239
+ * Contracts without a start date are ignored.
240
+ */
241
+ export function contractEvents(employees: EmployeeContracts[]): ContractEvent[] {
242
+ const events: ContractEvent[] = [];
243
+
244
+ for (const employee of employees) {
245
+ const dated = employee.employments
246
+ .filter((e) => e.startDate)
247
+ .sort((a, b) => (a.startDate! < b.startDate! ? -1 : 1));
248
+
249
+ dated.forEach((employment, index) => {
250
+ const base = {
251
+ employeeId: employee.id,
252
+ employeeName: employee.name,
253
+ employmentId: employment.id,
254
+ jobTitle: employment.jobTitle,
255
+ contractType: employment.contractType,
256
+ };
257
+
258
+ events.push({
259
+ ...base,
260
+ type: index === 0 ? 'hire' : 'variation',
261
+ date: employment.startDate!,
262
+ month: employment.startDate!.slice(0, 7),
263
+ endReason: null,
264
+ });
265
+
266
+ if (employment.endDate) {
267
+ events.push({
268
+ ...base,
269
+ type: 'termination',
270
+ date: employment.endDate,
271
+ month: employment.endDate.slice(0, 7),
272
+ endReason: employment.endReason,
273
+ });
274
+ }
275
+ });
276
+ }
277
+
278
+ return events.sort((a, b) => (a.date < b.date ? 1 : a.date > b.date ? -1 : 0));
279
+ }
@@ -0,0 +1,32 @@
1
+ mutation CreateApplication($input: CreateApplicationInput!) {
2
+ createApplication(input: $input) {
3
+ errors {
4
+ key
5
+ name
6
+ type
7
+ }
8
+ application {
9
+ id
10
+ aasmState
11
+ summary
12
+ completedAt
13
+ createdAt
14
+ contact {
15
+ id
16
+ humanName
17
+ email
18
+ }
19
+ applicable {
20
+ __typename
21
+ ... on Call {
22
+ id
23
+ name
24
+ kind
25
+ }
26
+ }
27
+ formResponse {
28
+ id
29
+ }
30
+ }
31
+ }
32
+ }
@@ -0,0 +1,40 @@
1
+ query ListApplications($first: Int, $after: String) {
2
+ currentWorkspace {
3
+ applications(first: $first, after: $after) {
4
+ pageInfo {
5
+ hasNextPage
6
+ endCursor
7
+ }
8
+ edges {
9
+ node {
10
+ id
11
+ aasmState
12
+ summary
13
+ completedAt
14
+ createdAt
15
+ status {
16
+ id
17
+ name
18
+ color
19
+ }
20
+ contact {
21
+ id
22
+ humanName
23
+ email
24
+ }
25
+ applicable {
26
+ __typename
27
+ ... on Call {
28
+ id
29
+ name
30
+ kind
31
+ }
32
+ }
33
+ formResponse {
34
+ id
35
+ }
36
+ }
37
+ }
38
+ }
39
+ }
40
+ }
@@ -0,0 +1,50 @@
1
+ mutation CreateCompensation($input: CreateCompensationInput!) {
2
+ createCompensation(input: $input) {
3
+ compensation {
4
+ node {
5
+ id
6
+ amount
7
+ currency
8
+ frequency
9
+ componentType
10
+ effectiveFrom
11
+ }
12
+ }
13
+ errors {
14
+ key
15
+ name
16
+ type
17
+ }
18
+ }
19
+ }
20
+
21
+ mutation UpdateCompensation($input: UpdateCompensationInput!) {
22
+ updateCompensation(input: $input) {
23
+ compensation {
24
+ id
25
+ amount
26
+ currency
27
+ frequency
28
+ componentType
29
+ effectiveFrom
30
+ }
31
+ errors {
32
+ key
33
+ name
34
+ type
35
+ }
36
+ }
37
+ }
38
+
39
+ mutation DeleteCompensation($input: DeleteCompensationInput!) {
40
+ deleteCompensation(input: $input) {
41
+ compensation {
42
+ id
43
+ }
44
+ errors {
45
+ key
46
+ name
47
+ type
48
+ }
49
+ }
50
+ }
@@ -0,0 +1,52 @@
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
+ ccnl {
30
+ id
31
+ name
32
+ }
33
+ compensations(first: 20) {
34
+ edges {
35
+ node {
36
+ id
37
+ amount
38
+ currency
39
+ frequency
40
+ componentType
41
+ effectiveFrom
42
+ }
43
+ }
44
+ }
45
+ }
46
+ }
47
+ }
48
+ }
49
+ }
50
+ }
51
+ }
52
+ }