Skip to content

Commit e7c17f9

Browse files
committed
Enhance Buddee component with new actions and sources for employee and leave management
- Added actions for creating employees, leave requests, listing employees, and leave requests. - Introduced new sources for tracking new employee creations, updates, and leave request status changes. - Updated prop definitions in buddee.app.mjs to include companyId, employeeId, costCenterId, and costUnitId. - Implemented utility functions for pagination and filtering in common/utils.mjs. - Bumped component version to 0.1.0 in package.json.
1 parent 212cd8b commit e7c17f9

File tree

15 files changed

+1178
-8
lines changed

15 files changed

+1178
-8
lines changed
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
import buddee from "../../buddee.app.mjs";
2+
3+
export default {
4+
name: "Create Employee",
5+
description: "Create a new employee record. [See the documentation](https://developers.buddee.nl/#d08b1399-6333-4f08-a17b-26b2d8485d7e)",
6+
key: "createEmployee",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
buddee,
11+
companyId: {
12+
propDefinition: [
13+
buddee,
14+
"companyId",
15+
],
16+
},
17+
firstName: {
18+
type: "string",
19+
label: "First Name",
20+
description: "Employee's first name",
21+
},
22+
lastName: {
23+
type: "string",
24+
label: "Last Name",
25+
description: "Employee's last name",
26+
},
27+
employmentDate: {
28+
type: "string",
29+
label: "Employment Date",
30+
description: "Employee's employment date (YYYY-MM-DD)",
31+
},
32+
managerId: {
33+
propDefinition: [
34+
buddee,
35+
"employeeId",
36+
],
37+
label: "Manager ID",
38+
description: "The ID of the manager to create the employee for",
39+
optional: true,
40+
},
41+
indirectManagerId: {
42+
propDefinition: [
43+
buddee,
44+
"employeeId",
45+
],
46+
label: "Indirect Manager ID",
47+
description: "The ID of the indirect manager to create the employee for",
48+
optional: true,
49+
},
50+
costCenterId: {
51+
propDefinition: [
52+
buddee,
53+
"costCenterId",
54+
],
55+
optional: true,
56+
},
57+
costUnitId: {
58+
propDefinition: [
59+
buddee,
60+
"costUnitId",
61+
],
62+
optional: true,
63+
},
64+
gender: {
65+
type: "string",
66+
label: "Gender",
67+
description: "The gender of the employee",
68+
optional: true,
69+
},
70+
birthDate: {
71+
type: "string",
72+
label: "Birth Date",
73+
description: "The birth date of the employee (YYYY-MM-DD)",
74+
optional: true,
75+
},
76+
workEmail: {
77+
type: "string",
78+
label: "Work Email",
79+
description: "The work email of the employee",
80+
optional: true,
81+
},
82+
personalEmail: {
83+
type: "string",
84+
label: "Personal Email",
85+
description: "The personal email of the employee",
86+
optional: true,
87+
},
88+
},
89+
async run({ $ }) {
90+
const response = await this.buddee.createEmployee({
91+
$,
92+
data: {
93+
company_id: this.companyId,
94+
first_name: this.firstName,
95+
last_name: this.lastName,
96+
employment_date: this.employmentDate,
97+
manager_id: this.managerId,
98+
indirect_manager_id: this.indirectManagerId,
99+
cost_center_id: this.costCenterId,
100+
cost_unit_id: this.costUnitId,
101+
gender: this.gender,
102+
birth_date: this.birthDate,
103+
work_email: this.workEmail,
104+
personal_email: this.personalEmail,
105+
},
106+
});
107+
108+
$.export("$summary", `Successfully created employee with ID ${response.data.id}`);
109+
return response.data;
110+
},
111+
};
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import { API_ENDPOINTS } from "../../common/constants.mjs";
2+
3+
export default {
4+
name: "Create Leave Request",
5+
description: "Employee creates a new time-off request",
6+
key: "createLeaveRequest",
7+
version: "0.1.0",
8+
type: "action",
9+
props: {
10+
buddee: {
11+
type: "app",
12+
app: "buddee",
13+
label: "Buddee",
14+
description: "The Buddee app instance to use",
15+
},
16+
employeeId: {
17+
type: "string",
18+
label: "Employee ID",
19+
description: "ID of the employee requesting leave",
20+
required: true,
21+
},
22+
leaveTypeId: {
23+
type: "string",
24+
label: "Leave Type ID",
25+
description: "ID of the leave type (vacation, personal, etc.)",
26+
required: true,
27+
},
28+
startDate: {
29+
type: "string",
30+
label: "Start Date",
31+
description: "Start date of the leave request (YYYY-MM-DD)",
32+
required: true,
33+
},
34+
endDate: {
35+
type: "string",
36+
label: "End Date",
37+
description: "End date of the leave request (YYYY-MM-DD)",
38+
required: true,
39+
},
40+
reason: {
41+
type: "string",
42+
label: "Reason",
43+
description: "Reason for the leave request",
44+
},
45+
halfDay: {
46+
type: "boolean",
47+
label: "Half Day",
48+
description: "Whether this is a half-day leave request",
49+
default: false,
50+
},
51+
morningHalfDay: {
52+
type: "boolean",
53+
label: "Morning Half Day",
54+
description: "If half day, whether it's morning or afternoon",
55+
default: false,
56+
},
57+
},
58+
async run({ $ }) {
59+
const data = {
60+
employee_id: this.employeeId,
61+
leave_type_id: this.leaveTypeId,
62+
start_date: this.startDate,
63+
end_date: this.endDate,
64+
};
65+
66+
if (this.reason) {
67+
data.reason = this.reason;
68+
}
69+
if (this.halfDay) {
70+
data.half_day = this.halfDay;
71+
}
72+
if (this.morningHalfDay) {
73+
data.morning_half_day = this.morningHalfDay;
74+
}
75+
76+
const response = await this.buddee._makeRequest({
77+
$,
78+
method: "POST",
79+
path: API_ENDPOINTS.LEAVE_REQUESTS,
80+
data,
81+
});
82+
83+
return response.data;
84+
},
85+
};
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { API_ENDPOINTS } from "../../common/constants.mjs";
2+
import { buildPaginationParams } from "../../common/utils.mjs";
3+
4+
export default {
5+
name: "List Employees",
6+
description: "Retrieve a complete list of employees",
7+
key: "listEmployees",
8+
version: "0.1.0",
9+
type: "action",
10+
props: {
11+
buddee: {
12+
type: "app",
13+
app: "buddee",
14+
label: "Buddee",
15+
description: "The Buddee app instance to use",
16+
},
17+
limit: {
18+
type: "integer",
19+
label: "Limit",
20+
description: "Maximum number of employees to return",
21+
default: 100,
22+
min: 1,
23+
max: 1000,
24+
},
25+
offset: {
26+
type: "integer",
27+
label: "Offset",
28+
description: "Number of employees to skip",
29+
default: 0,
30+
min: 0,
31+
},
32+
},
33+
async run({ $ }) {
34+
const params = buildPaginationParams(this.limit, this.offset);
35+
36+
const response = await this.buddee._makeRequest({
37+
$,
38+
path: API_ENDPOINTS.EMPLOYEES,
39+
params,
40+
});
41+
42+
return response.data;
43+
},
44+
};
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import {
2+
API_ENDPOINTS, LEAVE_REQUEST_STATUS,
3+
} from "../../common/constants.mjs";
4+
import {
5+
buildEmployeeFilterParams,
6+
buildPaginationParams,
7+
buildStatusFilterParams,
8+
} from "../../common/utils.mjs";
9+
10+
export default {
11+
name: "List Leave Requests",
12+
description: "Get all pending and processed leave requests",
13+
key: "listLeaveRequests",
14+
version: "0.1.0",
15+
type: "action",
16+
props: {
17+
buddee: {
18+
type: "app",
19+
app: "buddee",
20+
label: "Buddee",
21+
description: "The Buddee app instance to use",
22+
},
23+
employeeId: {
24+
type: "string",
25+
label: "Employee ID",
26+
description: "Filter leave requests by specific employee ID",
27+
},
28+
status: {
29+
type: "string",
30+
label: "Status",
31+
description: "Filter by leave request status",
32+
options: [
33+
{
34+
label: "All",
35+
value: "",
36+
},
37+
{
38+
label: "Pending",
39+
value: LEAVE_REQUEST_STATUS.PENDING,
40+
},
41+
{
42+
label: "Approved",
43+
value: LEAVE_REQUEST_STATUS.APPROVED,
44+
},
45+
{
46+
label: "Rejected",
47+
value: LEAVE_REQUEST_STATUS.REJECTED,
48+
},
49+
{
50+
label: "Cancelled",
51+
value: LEAVE_REQUEST_STATUS.CANCELLED,
52+
},
53+
],
54+
default: "",
55+
},
56+
limit: {
57+
type: "integer",
58+
label: "Limit",
59+
description: "Maximum number of leave requests to return",
60+
default: 100,
61+
min: 1,
62+
max: 1000,
63+
},
64+
offset: {
65+
type: "integer",
66+
label: "Offset",
67+
description: "Number of leave requests to skip",
68+
default: 0,
69+
min: 0,
70+
},
71+
},
72+
async run({ $ }) {
73+
const params = {
74+
...buildPaginationParams(this.limit, this.offset),
75+
...buildEmployeeFilterParams(this.employeeId),
76+
...buildStatusFilterParams(this.status),
77+
};
78+
79+
const response = await this.buddee._makeRequest({
80+
$,
81+
path: API_ENDPOINTS.LEAVE_REQUESTS,
82+
params,
83+
});
84+
85+
return response.data;
86+
},
87+
};
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { API_ENDPOINTS } from "../../common/constants.mjs";
2+
import {
3+
buildDateRangeParams,
4+
buildEmployeeFilterParams,
5+
buildPaginationParams,
6+
} from "../../common/utils.mjs";
7+
8+
export default {
9+
name: "List Time Registrations",
10+
description: "Get all time tracking records",
11+
key: "listTimeRegistrations",
12+
version: "0.1.0",
13+
type: "action",
14+
props: {
15+
buddee: {
16+
type: "app",
17+
app: "buddee",
18+
label: "Buddee",
19+
description: "The Buddee app instance to use",
20+
},
21+
employeeId: {
22+
type: "string",
23+
label: "Employee ID",
24+
description: "Filter time registrations by specific employee ID",
25+
},
26+
startDate: {
27+
type: "string",
28+
label: "Start Date",
29+
description: "Filter from this date (YYYY-MM-DD)",
30+
},
31+
endDate: {
32+
type: "string",
33+
label: "End Date",
34+
description: "Filter until this date (YYYY-MM-DD)",
35+
},
36+
limit: {
37+
type: "integer",
38+
label: "Limit",
39+
description: "Maximum number of time registrations to return",
40+
default: 100,
41+
min: 1,
42+
max: 1000,
43+
},
44+
offset: {
45+
type: "integer",
46+
label: "Offset",
47+
description: "Number of time registrations to skip",
48+
default: 0,
49+
min: 0,
50+
},
51+
},
52+
async run({ $ }) {
53+
const params = {
54+
...buildPaginationParams(this.limit, this.offset),
55+
...buildEmployeeFilterParams(this.employeeId),
56+
...buildDateRangeParams(this.startDate, this.endDate),
57+
};
58+
59+
const response = await this.buddee._makeRequest({
60+
$,
61+
path: API_ENDPOINTS.TIME_REGISTRATIONS,
62+
params,
63+
});
64+
65+
return response.data;
66+
},
67+
};

0 commit comments

Comments
 (0)