Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions components/charthop/actions/create-employee/create-employee.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import charthop from "../../charthop.app.mjs";
import { parseObject } from "../../common/utils.mjs";

export default {
key: "charthop-create-employee",
name: "Create Employee",
description: "Adds a new employee to the system. [See the documentation](https://api.charthop.com/swagger#/person/createPerson)",
version: "0.0.1",
type: "action",
props: {
charthop,
orgId: {
propDefinition: [
charthop,
"orgId",
],
},
name: {
type: "string",
label: "Name",
description: "Name of the employee",
},
additionalProperties: {
type: "object",
label: "Additional Properties",
description: "Additional properties to add to the employee",
optional: true,
},
},
async run({ $ }) {
const additionalProperties = this.additionalProperties
? parseObject(this.additionalProperties)
: {};

const response = await this.charthop.createPerson({
$,
orgId: this.orgId,
data: {
name: this.name,
...additionalProperties,
},
});

$.export("$summary", `Successfully created employee with ID: ${response.id}`);
return response;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import charthop from "../../charthop.app.mjs";

export default {
key: "charthop-search-organization",
name: "Search Organization",
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)",
version: "0.0.1",
type: "action",
props: {
charthop,
orgId: {
propDefinition: [
charthop,
"orgId",
],
},
q: {
type: "string",
label: "Query",
description: "The search query",
},
},
async run({ $ }) {
const response = await this.charthop.searchOrganization({
$,
orgId: this.orgId,
params: {
q: this.q,
includeFormer: true,
},
});

$.export("$summary", "Successfully completed search query");
return response;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import charthop from "../../charthop.app.mjs";

export default {
key: "charthop-update-employee-details",
name: "Update Employee Details",
description: "Updates an existing employee's details. [See the documentation](https://api.charthop.com/swagger#/user/updateUser)",
version: "0.0.1",
type: "action",
props: {
charthop,
orgId: {
propDefinition: [
charthop,
"orgId",
],
},
employeeId: {
propDefinition: [
charthop,
"employeeId",
(c) => ({
orgId: c.orgId,
}),
],
reloadProps: true,
},
},
async additionalProps() {
const props = {};
if (!this.employeeId || !this.orgId) {
return props;
}

const employee = await this.charthop.getPerson({
orgId: this.orgId,
personId: this.employeeId,
});

for (const [
key,
value,
] of Object.entries(employee)) {
if (key === "id") {
continue;
}
props[key] = {
type: "string",
label: `${key}`,
default: key === "name"
? (`${value?.first} ${value?.last}`).trim()
: `${value}`,
};
}

return props;
},
async run({ $ }) {
const {
charthop,
orgId,
employeeId,
...fields
} = this;

await charthop.updatePerson({
$,
orgId,
personId: employeeId,
data: {
...fields,
},
});

const response = await charthop.getPerson({
$,
orgId,
personId: employeeId,
});

$.export("$summary", `Successfully updated employee with ID ${employeeId}`);
return response;
},
};
211 changes: 207 additions & 4 deletions components/charthop/charthop.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,214 @@
import { axios } from "@pipedream/platform";

export default {
type: "app",
app: "charthop",
propDefinitions: {},
propDefinitions: {
orgId: {
type: "string",
label: "Organization ID",
description: "The identifier of an organization",
async options({ prevContext }) {
const params = prevContext?.from
? {
from: prevContext.from,
}
: {};
const { data } = await this.listOrgs({
params,
});
const options = data?.map(({
id: value, name: label,
}) => ({
value,
label,
})) || [];
return {
options,
context: {
from: options[options.length - 1].id,
},
};
},
},
employeeId: {
type: "string",
label: "Employee ID",
description: "The identifier of an employee",
async options({
orgId, prevContext,
}) {
const params = {
includeAll: true,
};
if (prevContext?.from) {
params.from = prevContext.from;
}
const { data } = await this.listPersons({
orgId,
params: {
...params,
},
});
const options = data?.map(({
id: value, name,
}) => ({
value,
label: (`${name?.first} ${name?.last}`).trim(),
})) || [];
return {
options,
context: {
from: data[data.length - 1].id,
},
};
},
},
groupTypeId: {
type: "string",
label: "Group Type ID",
description: "The identifier of a group type",
async options({
orgId, prevContext,
}) {
const params = {
includeAll: true,
};
if (prevContext?.from) {
params.from = prevContext.from;
}
const { data } = await this.listGroupTypes({
orgId,
params: {
...params,
},
});
const options = data?.map(({
id: value, name: label,
}) => ({
value,
label,
})) || [];
return {
options,
context: {
from: data[data.length - 1].id,
},
};
},
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl() {
return "https://api.charthop.com";
},
_makeRequest({
$ = this,
path,
...otherOpts
}) {
return axios($, {
...otherOpts,
url: `${this._baseUrl()}${path}`,
headers: {
"Authorization": `Bearer ${this.$auth.api_token}`,
"Content-Type": "application/json",
},
});
},
listOrgs(opts = {}) {
return this._makeRequest({
path: "/v1/org",
...opts,
});
},
listPersons({
orgId, ...opts
}) {
return this._makeRequest({
path: `/v2/org/${orgId}/person`,
...opts,
});
},
listJobs({
orgId, ...opts
}) {
return this._makeRequest({
path: `/v2/org/${orgId}/job`,
...opts,
});
},
listGroupTypes({
orgId, ...opts
}) {
return this._makeRequest({
path: `/v1/org/${orgId}/group-type`,
...opts,
});
},
listGroups({
orgId, type, ...opts
}) {
return this._makeRequest({
path: `/v2/org/${orgId}/group/${type}`,
...opts,
});
},
getPerson({
orgId, personId, ...opts
}) {
return this._makeRequest({
path: `/v2/org/${orgId}/person/${personId}`,
...opts,
});
},
createPerson({
orgId, ...opts
}) {
return this._makeRequest({
method: "POST",
path: `/v2/org/${orgId}/person`,
...opts,
});
},
updatePerson({
orgId, personId, ...opts
}) {
return this._makeRequest({
method: "PATCH",
path: `/v2/org/${orgId}/person/${personId}`,
...opts,
});
},
searchOrganization({
orgId, ...opts
}) {
return this._makeRequest({
path: `/v1/org/${orgId}/search`,
...opts,
});
},
async *paginate({
resourceFn,
args,
max,
}) {
let count = 0;
do {
const {
data, next,
} = await resourceFn(args);
for (const item of data) {
yield item;
if (max && ++count >= max) {
return;
}
args.params = {
...args.params,
from: next,
};
}
} while (args.params?.from);
},
},
};
Loading
Loading