Skip to content

Commit 1650b69

Browse files
[ADDED] CRUD and Services for Employee Educational History Details
1 parent 2b96c47 commit 1650b69

File tree

3 files changed

+204
-33
lines changed

3 files changed

+204
-33
lines changed

models/employee/empEduHistory.js

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
import connector from "#models/databaseUtil";
2+
3+
const Education = {
4+
educationType: { type: String, required: true },
5+
educationName: { type: String, required: true },
6+
specialization: { type: String, required: true },
7+
period: { type: String, required: true },
8+
institutionName: { type: String, required: true },
9+
university: { type: String, required: true },
10+
passingDivision: { type: String, required: true },
11+
fromYear: { type: String, required: true },
12+
uptoYear: { type: String, required: true },
13+
registrationNumber: { type: String, required: true },
14+
aggregatePct: { type: String, required: true },
15+
finalYearPct: { type: String, required: true },
16+
numberOfAttempts: { type: Number, required: true },
17+
rank: { type: Number, required: true },
18+
passingYear: { type: String, required: true },
19+
};
20+
const employeeEducationHistorySchema = {
21+
uid: { type: String, require: true },
22+
ssc: { type: Education, required: true },
23+
hsc: { type: Education, required: true },
24+
dip: { type: Education },
25+
iti: { type: Education },
26+
deg: { type: Education },
27+
pgd: { type: Education },
28+
phd: { type: Education },
29+
pdoc: { type: Education },
30+
};
31+
32+
// eslint-disable-next-line no-unused-vars
33+
const EmployeeEducationHistory =
34+
connector.model("Employee education history",
35+
employeeEducationHistorySchema);
36+
37+
//CRUD Operations
38+
39+
async function create(employeeEducationHistoryData) {
40+
const {
41+
educationType,
42+
educationName,
43+
specialization,
44+
period,
45+
institutionName,
46+
university,
47+
passingDivision,
48+
fromYear,
49+
uptoYear,
50+
registrationNumber,
51+
aggregatePct,
52+
finalYearPct,
53+
numberOfAttempts,
54+
rank,
55+
passingYear,
56+
uid,
57+
ssc,
58+
hsc,
59+
dip,
60+
iti,
61+
deg,
62+
pgd,
63+
phd,
64+
pdoc,
65+
} = employeeEducationHistoryData;
66+
67+
const empEduHistory = new EmployeeEducationHistory({
68+
educationType,
69+
educationName,
70+
specialization,
71+
period,
72+
institutionName,
73+
university,
74+
passingDivision,
75+
fromYear,
76+
uptoYear,
77+
registrationNumber,
78+
aggregatePct,
79+
finalYearPct,
80+
numberOfAttempts,
81+
rank,
82+
passingYear,
83+
uid,
84+
ssc,
85+
hsc,
86+
dip,
87+
iti,
88+
deg,
89+
pgd,
90+
phd,
91+
pdoc,
92+
});
93+
94+
const empEduHistoryDoc = await empEduHistory.save();
95+
return empEduHistoryDoc;
96+
}
97+
98+
99+
async function read(filter, limit=1) {
100+
const empEduHistoryDoc = employeeEducationHistorySchema.find(filter).limit(limit);
101+
return empEduHistoryDoc;
102+
}
103+
104+
105+
async function update(filter, updateObject, options={ multi: true }) {
106+
const updateResult = await employeeEducationHistorySchema.updateMany(
107+
filter,
108+
{$set: updateObject},
109+
options,
110+
);
111+
return updateResult.acknowledged;
112+
}
113+
114+
async function remove(filter) {
115+
const deleteResult= await employeeEducationHistorySchema.deleteMany(filter).exec();
116+
return deleteResult.acknowledged;
117+
}
118+
119+
export default{
120+
create, read, update, remove,
121+
};

models/employee/emp_edu_history.js

Lines changed: 0 additions & 33 deletions
This file was deleted.

services/employee/empEduHistory.js

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import EmployeeEducationHistory from "#models/employee/empEduHistory";
2+
import databaseError from "#error/database";
3+
4+
export async function createEmployeeEducationHistory(
5+
educationType,
6+
educationName,
7+
specialization,
8+
period,
9+
institutionName,
10+
university,
11+
passingDivision,
12+
fromYear,
13+
uptoYear,
14+
registrationNumber,
15+
aggregatePct,
16+
finalYearPct,
17+
numberOfAttempts,
18+
rank,
19+
passingYear,
20+
uid,
21+
ssc,
22+
hsc,
23+
dip,
24+
iti,
25+
deg,
26+
pgd,
27+
phd,
28+
pdoc,
29+
) {
30+
const newEmployeeEducationHistory = await EmployeeEducationHistory.create({
31+
educationType,
32+
educationName,
33+
specialization,
34+
period,
35+
institutionName,
36+
university,
37+
passingDivision,
38+
fromYear,
39+
uptoYear,
40+
registrationNumber,
41+
aggregatePct,
42+
finalYearPct,
43+
numberOfAttempts,
44+
rank,
45+
passingYear,
46+
uid,
47+
ssc,
48+
hsc,
49+
dip,
50+
iti,
51+
deg,
52+
pgd,
53+
phd,
54+
pdoc,
55+
});
56+
if(newEmployeeEducationHistory.uid === uid){
57+
return newEmployeeEducationHistory;
58+
}
59+
throw new databaseError.DataEntryError("Employee Education History");
60+
}
61+
62+
63+
export async function employeeEducationHistoryList(filter) {
64+
const empEduHistory = await EmployeeEducationHistory.read(filter,0);
65+
return empEduHistory;
66+
}
67+
68+
69+
export async function updateEmployeeEducationHistoryById(id, data) {
70+
const updated = await EmployeeEducationHistory.update({_id: id}, data);
71+
if(updated) {
72+
return updated;
73+
}
74+
throw new databaseError.DataEntryError("Employee Education History");
75+
}
76+
77+
export async function deleteEmployeeEducationHistoryById(employeeEducationHistoryId) {
78+
const deleted = await EmployeeEducationHistory.remove({_id: employeeEducationHistoryId});
79+
if (deleted) {
80+
return deleted;
81+
}
82+
throw new databaseError.DataDeleteError("Employee Education History");
83+
}

0 commit comments

Comments
 (0)