-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathupdate-team.ts
More file actions
60 lines (52 loc) · 2.16 KB
/
Copy pathupdate-team.ts
File metadata and controls
60 lines (52 loc) · 2.16 KB
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
import { z } from 'zod';
import { createAction } from 'nango';
const InputSchema = z.object({
teamId: z.number().describe('The ID of the team to update. Example: 2066772'),
name: z.string().optional().describe('The new name for the team.'),
operationsCoef: z.number().optional().describe('The new operations coefficient for the team.')
});
const ProviderTeamSchema = z
.object({
id: z.number(),
name: z.string().optional().nullable(),
organizationId: z.number().optional().nullable(),
operationsCoef: z.number().optional().nullable(),
transferCoef: z.number().optional().nullable()
})
.passthrough();
const OutputSchema = z.object({
id: z.number().describe('The team ID.'),
name: z.string().optional(),
organizationId: z.number().optional(),
operationsCoef: z.number().optional(),
transferCoef: z.number().optional()
});
const action = createAction({
description: "Update a team's name or operations limit.",
version: '1.0.0',
input: InputSchema,
output: OutputSchema,
scopes: ['teams:write'],
exec: async (nango, input): Promise<z.infer<typeof OutputSchema>> => {
// https://developers.make.com/api-documentation/
const response = await nango.patch({
endpoint: `/teams/${encodeURIComponent(String(input.teamId))}`,
data: {
...(input.name !== undefined && { name: input.name }),
...(input.operationsCoef !== undefined && { operationsCoef: input.operationsCoef })
},
retries: 3
});
const providerData = z.object({ team: ProviderTeamSchema }).parse(response.data);
const team = providerData.team;
return {
id: team.id,
...(team.name != null && { name: team.name }),
...(team.organizationId != null && { organizationId: team.organizationId }),
...(team.operationsCoef != null && { operationsCoef: team.operationsCoef }),
...(team.transferCoef != null && { transferCoef: team.transferCoef })
};
}
});
export type NangoActionLocal = Parameters<(typeof action)['exec']>[0];
export default action;