Skip to content

Commit f010ed1

Browse files
committed
new components
1 parent 385452b commit f010ed1

File tree

11 files changed

+308
-409
lines changed

11 files changed

+308
-409
lines changed

components/charthop/actions/record-compensation-change/record-compensation-change.mjs

Lines changed: 0 additions & 49 deletions
This file was deleted.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import charthop from "../../charthop.app.mjs";
2+
3+
export default {
4+
key: "charthop-search-organization",
5+
name: "Search Organization",
6+
description: "Return people, job, group, and field data for a particular org that match a provided search string. [See the documentation](https://api.charthop.com/swagger#/search/searchOrgData)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
charthop,
11+
orgId: {
12+
propDefinition: [
13+
charthop,
14+
"orgId",
15+
],
16+
},
17+
q: {
18+
type: "string",
19+
label: "Query",
20+
description: "The search query",
21+
},
22+
},
23+
async run({ $ }) {
24+
const response = await this.charthop.searchOrganization({
25+
$,
26+
orgId: this.orgId,
27+
params: {
28+
q: this.q,
29+
includeFormer: true,
30+
},
31+
});
32+
33+
$.export("$summary", "Successfully completed search query");
34+
return response;
35+
},
36+
};

components/charthop/actions/update-employee-details/update-employee-details.mjs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,21 @@ export default {
6262
...fields
6363
} = this;
6464

65-
const response = await charthop.updatePerson({
65+
await charthop.updatePerson({
6666
$,
6767
orgId,
6868
personId: employeeId,
6969
data: {
7070
...fields,
7171
},
7272
});
73+
74+
const response = await charthop.getPerson({
75+
$,
76+
orgId,
77+
personId: employeeId,
78+
});
79+
7380
$.export("$summary", `Successfully updated employee with ID ${employeeId}`);
7481
return response;
7582
},

components/charthop/charthop.app.mjs

Lines changed: 85 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -64,29 +64,38 @@ export default {
6464
};
6565
},
6666
},
67-
68-
// Action: Modify Compensation Records
69-
modifyCompensationEmployeeId: {
70-
type: "string",
71-
label: "Employee ID",
72-
description: "ID of the employee for compensation update.",
73-
},
74-
modifyCompensationDetails: {
75-
type: "string",
76-
label: "Compensation Details",
77-
description: "Details of the compensation update. Provide as a JSON string.",
78-
},
79-
modifyCompensationEffectiveDate: {
80-
type: "string",
81-
label: "Effective Date",
82-
description: "Optional effective date for the compensation update.",
83-
optional: true,
84-
},
85-
modifyCompensationReason: {
67+
groupTypeId: {
8668
type: "string",
87-
label: "Reason for Change",
88-
description: "Optional reason for the compensation update.",
89-
optional: true,
69+
label: "Group Type ID",
70+
description: "The identifier of a group type",
71+
async options({
72+
orgId, prevContext,
73+
}) {
74+
const params = {
75+
includeAll: true,
76+
};
77+
if (prevContext?.from) {
78+
params.from = prevContext.from;
79+
}
80+
const { data } = await this.listGroupTypes({
81+
orgId,
82+
params: {
83+
...params,
84+
},
85+
});
86+
const options = data?.map(({
87+
id: value, name: label,
88+
}) => ({
89+
value,
90+
label,
91+
})) || [];
92+
return {
93+
options,
94+
context: {
95+
from: data[data.length - 1].id,
96+
},
97+
};
98+
},
9099
},
91100
},
92101
methods: {
@@ -121,6 +130,30 @@ export default {
121130
...opts,
122131
});
123132
},
133+
listJobs({
134+
orgId, ...opts
135+
}) {
136+
return this._makeRequest({
137+
path: `/v2/org/${orgId}/job`,
138+
...opts,
139+
});
140+
},
141+
listGroupTypes({
142+
orgId, ...opts
143+
}) {
144+
return this._makeRequest({
145+
path: `/v1/org/${orgId}/group-type`,
146+
...opts,
147+
});
148+
},
149+
listGroups({
150+
orgId, type, ...opts
151+
}) {
152+
return this._makeRequest({
153+
path: `/v2/org/${orgId}/group/${type}`,
154+
...opts,
155+
});
156+
},
124157
getPerson({
125158
orgId, personId, ...opts
126159
}) {
@@ -147,5 +180,35 @@ export default {
147180
...opts,
148181
});
149182
},
183+
searchOrganization({
184+
orgId, ...opts
185+
}) {
186+
return this._makeRequest({
187+
path: `/v1/org/${orgId}/search`,
188+
...opts,
189+
});
190+
},
191+
async *paginate({
192+
resourceFn,
193+
args,
194+
max,
195+
}) {
196+
let count = 0;
197+
do {
198+
const {
199+
data, next,
200+
} = await resourceFn(args);
201+
for (const item of data) {
202+
yield item;
203+
if (max && ++count >= max) {
204+
return;
205+
}
206+
args.params = {
207+
...args.params,
208+
from: next,
209+
};
210+
}
211+
} while (args.params?.next);
212+
},
150213
},
151214
};
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import charthop from "../../charthop.app.mjs";
2+
import {
3+
ConfigurationError, DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
4+
} from "@pipedream/platform";
5+
6+
export default {
7+
props: {
8+
charthop,
9+
db: "$.service.db",
10+
timer: {
11+
type: "$.interface.timer",
12+
default: {
13+
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
14+
},
15+
},
16+
orgId: {
17+
propDefinition: [
18+
charthop,
19+
"orgId",
20+
],
21+
},
22+
},
23+
methods: {
24+
_getLastId() {
25+
return this.db.get("lastId");
26+
},
27+
_setLastId(lastId) {
28+
this.db.set("lastId", lastId);
29+
},
30+
generateMeta(item) {
31+
return {
32+
id: item.id,
33+
summary: this.getSummary(item),
34+
ts: Date.now(),
35+
};
36+
},
37+
emitEvents(items) {
38+
items.forEach((item) => {
39+
const meta = this.generateMeta(item);
40+
this.$emit(item, meta);
41+
});
42+
},
43+
getArgs() {
44+
return {
45+
orgId: this.orgId,
46+
};
47+
},
48+
async getResults() {
49+
const lastId = this._getLastId();
50+
const resourceFn = this.getResourceFn();
51+
const args = this.getArgs();
52+
53+
if (lastId) {
54+
args.params = {
55+
...args.params,
56+
from: lastId,
57+
};
58+
}
59+
60+
const items = this.charthop.paginate({
61+
resourceFn,
62+
args,
63+
});
64+
65+
const results = [];
66+
for await (const item of items) {
67+
results.push(item);
68+
}
69+
70+
if (results.length) {
71+
this._setLastId(results[results.length - 1].id);
72+
}
73+
74+
return results;
75+
},
76+
getResourceFn() {
77+
throw new ConfigurationError("getResourceFn is not implemented");
78+
},
79+
getSummary() {
80+
throw new ConfigurationError("getSummary is not implemented");
81+
},
82+
},
83+
hooks: {
84+
async deploy() {
85+
const results = await this.getResults();
86+
this.emitEvents(results.slice(-25));
87+
},
88+
},
89+
async run() {
90+
const results = await this.getResults();
91+
this.emitEvents(results);
92+
},
93+
};

0 commit comments

Comments
 (0)