From 1650b691bd3e3072e0a09a7f7d1474ed1ec44330 Mon Sep 17 00:00:00 2001 From: Swathi Harish Date: Sat, 7 Oct 2023 18:07:15 +0530 Subject: [PATCH] [ADDED] CRUD and Services for Employee Educational History Details --- models/employee/empEduHistory.js | 121 +++++++++++++++++++++++++++++ models/employee/emp_edu_history.js | 33 -------- services/employee/empEduHistory.js | 83 ++++++++++++++++++++ 3 files changed, 204 insertions(+), 33 deletions(-) create mode 100644 models/employee/empEduHistory.js delete mode 100644 models/employee/emp_edu_history.js create mode 100644 services/employee/empEduHistory.js diff --git a/models/employee/empEduHistory.js b/models/employee/empEduHistory.js new file mode 100644 index 00000000..750cd44b --- /dev/null +++ b/models/employee/empEduHistory.js @@ -0,0 +1,121 @@ +import connector from "#models/databaseUtil"; + +const Education = { + educationType: { type: String, required: true }, + educationName: { type: String, required: true }, + specialization: { type: String, required: true }, + period: { type: String, required: true }, + institutionName: { type: String, required: true }, + university: { type: String, required: true }, + passingDivision: { type: String, required: true }, + fromYear: { type: String, required: true }, + uptoYear: { type: String, required: true }, + registrationNumber: { type: String, required: true }, + aggregatePct: { type: String, required: true }, + finalYearPct: { type: String, required: true }, + numberOfAttempts: { type: Number, required: true }, + rank: { type: Number, required: true }, + passingYear: { type: String, required: true }, +}; +const employeeEducationHistorySchema = { + uid: { type: String, require: true }, + ssc: { type: Education, required: true }, + hsc: { type: Education, required: true }, + dip: { type: Education }, + iti: { type: Education }, + deg: { type: Education }, + pgd: { type: Education }, + phd: { type: Education }, + pdoc: { type: Education }, +}; + +// eslint-disable-next-line no-unused-vars +const EmployeeEducationHistory = +connector.model("Employee education history", +employeeEducationHistorySchema); + +//CRUD Operations + +async function create(employeeEducationHistoryData) { + const { + educationType, + educationName, + specialization, + period, + institutionName, + university, + passingDivision, + fromYear, + uptoYear, + registrationNumber, + aggregatePct, + finalYearPct, + numberOfAttempts, + rank, + passingYear, + uid, + ssc, + hsc, + dip, + iti, + deg, + pgd, + phd, + pdoc, + } = employeeEducationHistoryData; + + const empEduHistory = new EmployeeEducationHistory({ + educationType, + educationName, + specialization, + period, + institutionName, + university, + passingDivision, + fromYear, + uptoYear, + registrationNumber, + aggregatePct, + finalYearPct, + numberOfAttempts, + rank, + passingYear, + uid, + ssc, + hsc, + dip, + iti, + deg, + pgd, + phd, + pdoc, + }); + + const empEduHistoryDoc = await empEduHistory.save(); + return empEduHistoryDoc; +} + + +async function read(filter, limit=1) { + const empEduHistoryDoc = employeeEducationHistorySchema.find(filter).limit(limit); + return empEduHistoryDoc; +} + + +async function update(filter, updateObject, options={ multi: true }) { + const updateResult = await employeeEducationHistorySchema.updateMany( + filter, + {$set: updateObject}, + options, + ); + return updateResult.acknowledged; +} + +async function remove(filter) { + const deleteResult= await employeeEducationHistorySchema.deleteMany(filter).exec(); + return deleteResult.acknowledged; +} + +export default{ + create, read, update, remove, +}; \ No newline at end of file diff --git a/models/employee/emp_edu_history.js b/models/employee/emp_edu_history.js deleted file mode 100644 index c242879a..00000000 --- a/models/employee/emp_edu_history.js +++ /dev/null @@ -1,33 +0,0 @@ -import connector from "#models/databaseUtil"; - -const Education = { - education_type: { type: String, required: true }, - education_name: { type: String, required: true }, - specialization: { type: String, required: true }, - period: { type: String, required: true }, - institution_name: { type: String, required: true }, - university: { type: String, required: true }, - passing_division: { type: String, required: true }, - from_year: { type: String, required: true }, - upto_year: { type: String, required: true }, - registration_number: { type: String, required: true }, - aggregate_pct: { type: String, required: true }, - final_year_pct: { type: String, required: true }, - number_of_attempts: { type: Number, required: true }, - rank: { type: Number, required: true }, - passing_year: { type: String, required: true }, -}; -const employeeEducationHistorySchema = { - uid: { type: String, require: true }, - ssc: { type: Education, required: true }, - hsc: { type: Education, required: true }, - dip: { type: Education }, - iti: { type: Education }, - deg: { type: Education }, - pgd: { type: Education }, - phd: { type: Education }, - pdoc: { type: Education }, -}; - -// eslint-disable-next-line no-unused-vars -const employeeEducationHistory = connector.model("Employee education history", employeeEducationHistorySchema); diff --git a/services/employee/empEduHistory.js b/services/employee/empEduHistory.js new file mode 100644 index 00000000..5273ca9a --- /dev/null +++ b/services/employee/empEduHistory.js @@ -0,0 +1,83 @@ +import EmployeeEducationHistory from "#models/employee/empEduHistory"; +import databaseError from "#error/database"; + +export async function createEmployeeEducationHistory( + educationType, + educationName, + specialization, + period, + institutionName, + university, + passingDivision, + fromYear, + uptoYear, + registrationNumber, + aggregatePct, + finalYearPct, + numberOfAttempts, + rank, + passingYear, + uid, + ssc, + hsc, + dip, + iti, + deg, + pgd, + phd, + pdoc, +) { + const newEmployeeEducationHistory = await EmployeeEducationHistory.create({ + educationType, + educationName, + specialization, + period, + institutionName, + university, + passingDivision, + fromYear, + uptoYear, + registrationNumber, + aggregatePct, + finalYearPct, + numberOfAttempts, + rank, + passingYear, + uid, + ssc, + hsc, + dip, + iti, + deg, + pgd, + phd, + pdoc, + }); + if(newEmployeeEducationHistory.uid === uid){ + return newEmployeeEducationHistory; + } + throw new databaseError.DataEntryError("Employee Education History"); +} + + +export async function employeeEducationHistoryList(filter) { + const empEduHistory = await EmployeeEducationHistory.read(filter,0); + return empEduHistory; +} + + +export async function updateEmployeeEducationHistoryById(id, data) { + const updated = await EmployeeEducationHistory.update({_id: id}, data); + if(updated) { + return updated; + } + throw new databaseError.DataEntryError("Employee Education History"); +} + + export async function deleteEmployeeEducationHistoryById(employeeEducationHistoryId) { + const deleted = await EmployeeEducationHistory.remove({_id: employeeEducationHistoryId}); + if (deleted) { + return deleted; + } + throw new databaseError.DataDeleteError("Employee Education History"); + } \ No newline at end of file