Skip to content

Commit 385452b

Browse files
committed
wip
1 parent 0891f82 commit 385452b

File tree

4 files changed

+106
-322
lines changed

4 files changed

+106
-322
lines changed

components/charthop/actions/create-employee/create-employee.mjs

Lines changed: 21 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import charthop from "../../charthop.app.mjs";
2+
import { parseObject } from "../../common/utils.mjs";
23

34
export default {
45
key: "charthop-create-employee",
56
name: "Create Employee",
6-
description: "Adds a new employee to the system. [See the documentation](https://api.charthop.com/swagger#/user/createUser)",
7-
version: "0.0.{{ts}}",
7+
description: "Adds a new employee to the system. [See the documentation](https://api.charthop.com/swagger#/person/createPerson)",
8+
version: "0.0.1",
89
type: "action",
910
props: {
1011
charthop,
@@ -14,70 +15,32 @@ export default {
1415
"orgId",
1516
],
1617
},
17-
firstName: {
18-
propDefinition: [
19-
charthop,
20-
"firstName",
21-
],
22-
},
23-
middleName: {
24-
propDefinition: [
25-
charthop,
26-
"middleName",
27-
],
28-
},
29-
lastName: {
30-
propDefinition: [
31-
charthop,
32-
"lastName",
33-
],
34-
},
35-
preferredFirstName: {
36-
propDefinition: [
37-
charthop,
38-
"preferredFirstName",
39-
],
40-
},
41-
preferredLastName: {
42-
propDefinition: [
43-
charthop,
44-
"preferredLastName",
45-
],
46-
},
47-
email: {
48-
propDefinition: [
49-
charthop,
50-
"email",
51-
],
18+
name: {
19+
type: "string",
20+
label: "Name",
21+
description: "Name of the employee",
5222
},
53-
status: {
54-
propDefinition: [
55-
charthop,
56-
"status",
57-
],
23+
additionalProperties: {
24+
type: "object",
25+
label: "Additional Properties",
26+
description: "Additional properties to add to the employee",
27+
optional: true,
5828
},
5929
},
6030
async run({ $ }) {
61-
const response = await this.charthop.createUser({
31+
const additionalProperties = this.additionalProperties
32+
? parseObject(this.additionalProperties)
33+
: {};
34+
35+
const response = await this.charthop.createPerson({
6236
$,
37+
orgId: this.orgId,
6338
data: {
64-
orgs: [
65-
{
66-
orgId: this.orgId,
67-
access: "MEMBER",
68-
roleId: await this.charthop.getEmployeeRoleId($),
69-
},
70-
],
71-
name: {
72-
first: this.firstName,
73-
middle: this.middleName,
74-
last: this.lastName,
75-
pref: this.preferredFirstName,
76-
prefLast: this.preferredLastName,
77-
},
78-
email: this.email,
39+
name: this.name,
40+
...additionalProperties,
7941
},
8042
});
43+
8144
$.export("$summary", `Successfully created employee with ID: ${response.id}`);
8245
return response;
8346
},

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

Lines changed: 42 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
key: "charthop-update-employee-details",
55
name: "Update Employee Details",
66
description: "Updates an existing employee's details. [See the documentation](https://api.charthop.com/swagger#/user/updateUser)",
7-
version: "0.0.{{ts}}",
7+
version: "0.0.1",
88
type: "action",
99
props: {
1010
charthop,
@@ -22,75 +22,55 @@ export default {
2222
orgId: c.orgId,
2323
}),
2424
],
25-
},
26-
firstName: {
27-
propDefinition: [
28-
charthop,
29-
"firstName",
30-
],
31-
optional: true,
32-
},
33-
middleName: {
34-
propDefinition: [
35-
charthop,
36-
"middleName",
37-
],
38-
},
39-
lastName: {
40-
propDefinition: [
41-
charthop,
42-
"lastName",
43-
],
44-
optional: true,
45-
},
46-
preferredFirstName: {
47-
propDefinition: [
48-
charthop,
49-
"preferredFirstName",
50-
],
51-
},
52-
preferredLastName: {
53-
propDefinition: [
54-
charthop,
55-
"preferredLastName",
56-
],
57-
},
58-
email: {
59-
propDefinition: [
60-
charthop,
61-
"email",
62-
],
63-
optional: true,
64-
},
65-
status: {
66-
propDefinition: [
67-
charthop,
68-
"status",
69-
],
25+
reloadProps: true,
7026
},
7127
},
28+
async additionalProps() {
29+
const props = {};
30+
if (!this.employeeId || !this.orgId) {
31+
return props;
32+
}
33+
34+
const employee = await this.charthop.getPerson({
35+
orgId: this.orgId,
36+
personId: this.employeeId,
37+
});
38+
39+
for (const [
40+
key,
41+
value,
42+
] of Object.entries(employee)) {
43+
if (key === "id") {
44+
continue;
45+
}
46+
props[key] = {
47+
type: "string",
48+
label: `${key}`,
49+
default: key === "name"
50+
? (`${value?.first} ${value?.last}`).trim()
51+
: `${value}`,
52+
};
53+
}
54+
55+
return props;
56+
},
7257
async run({ $ }) {
7358
const {
74-
name, email,
75-
} = await this.charthop.getUser({
76-
$,
77-
userId: this.employeeId,
78-
});
79-
const response = await this.charthop.updateUser({
59+
charthop,
60+
orgId,
61+
employeeId,
62+
...fields
63+
} = this;
64+
65+
const response = await charthop.updatePerson({
8066
$,
81-
userId: this.employeeId,
67+
orgId,
68+
personId: employeeId,
8269
data: {
83-
name: {
84-
first: this.firstName || name.first,
85-
middle: this.middleName || name.middle,
86-
last: this.lastName || name.last,
87-
pref: this.preferredFirstName || name.pref,
88-
prefLast: this.preferredLastName || name.prefLast,
89-
},
90-
email: this.email || email,
70+
...fields,
9171
},
9272
});
93-
$.export("$summary", `Successfully updated employee with ID ${this.employeeId}`);
73+
$.export("$summary", `Successfully updated employee with ID ${employeeId}`);
9474
return response;
9575
},
9676
};

0 commit comments

Comments
 (0)