Skip to content

Commit 139ea91

Browse files
committed
added employee current details crud and services
1 parent e1fb396 commit 139ea91

File tree

2 files changed

+111
-4
lines changed

2 files changed

+111
-4
lines changed
Lines changed: 61 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import connector from "#models/databaseUtil";
22

3-
const employeeCurrentEmployementSchema = {
3+
const employeeCurrentEmploymentSchema = {
44
uid: { type: String, require: true },
55
date_of_joining: { type: Date, required: true },
66
department_name: { type: String, required: true },
@@ -11,7 +11,64 @@ const employeeCurrentEmployementSchema = {
1111
};
1212

1313
// eslint-disable-next-line no-unused-vars
14-
const employeeCurrentEmployement = connector.model(
15-
"Employee current Employement",
16-
employeeCurrentEmployementSchema,
14+
const EmployeeCurrentEmployment = connector.model(
15+
"EmployeeCurrentEmployement",
16+
employeeCurrentEmploymentSchema,
1717
);
18+
19+
async function create(employeeCurrentEmploymentData) {
20+
const {
21+
uid,
22+
dateOfJoining,
23+
departmentName,
24+
designation,
25+
jobStatus,
26+
jobProfile,
27+
currentCtc,
28+
} = employeeCurrentEmploymentData;
29+
30+
const empCurEmp = new EmployeeCurrentEmployment({
31+
uid,
32+
dateOfJoining,
33+
departmentName,
34+
designation,
35+
jobStatus,
36+
jobProfile,
37+
currentCtc,
38+
});
39+
40+
const empCurrentEmploymentDoc = await empCurEmp.save();
41+
return empCurrentEmploymentDoc;
42+
}
43+
44+
async function read(filter, limit = 0, page = 1) {
45+
const empCurrentEmploymentDoc = await EmployeeCurrentEmployment.find(filter)
46+
.limit(limit)
47+
.skip((page - 1) * limit)
48+
.exec();
49+
const count = await EmployeeCurrentEmployment.count();
50+
const totalPages = Math.ceil(count / limit);
51+
return { totalPages, data: empCurrentEmploymentDoc };
52+
}
53+
54+
async function update(filter, updateObject, options = { multi: true }) {
55+
const updateResult = await EmployeeCurrentEmployment.updateMany(
56+
filter,
57+
{ $set: updateObject },
58+
options,
59+
);
60+
return updateResult.acknowledged;
61+
}
62+
63+
async function remove(filter) {
64+
const deleteResult =
65+
await EmployeeCurrentEmployment.deleteMany(filter).exec();
66+
return deleteResult.acknowledged;
67+
}
68+
69+
export default {
70+
create,
71+
read,
72+
update,
73+
remove,
74+
};
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import databaseError from "#error/database";
2+
import EmployeeCurrent from "#models/employee/empPersonal";
3+
4+
export async function addNewEmployeeCurrent(
5+
uid,
6+
dateOfJoining,
7+
departmentName,
8+
designation,
9+
jobStatus,
10+
jobProfile,
11+
currentCtc,
12+
) {
13+
const newEmployeeCurrent = await EmployeeCurrent.create({
14+
uid,
15+
dateOfJoining,
16+
departmentName,
17+
designation,
18+
jobStatus,
19+
jobProfile,
20+
currentCtc,
21+
});
22+
if (newEmployeeCurrent.uid === uid) {
23+
return newEmployeeCurrent;
24+
}
25+
throw new databaseError.DataEntryError("Add EmployeeCurrent");
26+
}
27+
28+
export async function getEmployeeCurrent(filter, limit, page) {
29+
const employeeCurrent = await EmployeeCurrent.read(filter, limit, page);
30+
if (employeeCurrent) {
31+
return employeeCurrent;
32+
}
33+
throw new databaseError.DataNotFoundError("EmployeeCurrent");
34+
}
35+
36+
export async function deleteEmployeeCurrentById(EmployeeCurrentId) {
37+
const deleted = await EmployeeCurrent.remove({ _id: EmployeeCurrentId });
38+
if (deleted) {
39+
return deleted;
40+
}
41+
throw new databaseError.DataDeleteError("EmployeeCurrent");
42+
}
43+
44+
export async function updateEmployeeCurrentById(id, data) {
45+
const updated = await EmployeeCurrent.update({ _id: id }, data);
46+
if (updated) {
47+
return updated;
48+
}
49+
throw new databaseError.DataEntryError("EmployeeCurrent");
50+
}

0 commit comments

Comments
 (0)