Skip to content

Commit d60d6d2

Browse files
Merge pull request #385 from tcet-opensource/#376-crud-and-services-for-employee-personal-details
#376 crud and services for employee personal details
2 parents 1efcc0f + 7033346 commit d60d6d2

File tree

2 files changed

+129
-3
lines changed

2 files changed

+129
-3
lines changed

models/employee/emp_personal.js

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,45 @@ const employeePersonalSchema = {
5555
maidenFirstName: { type: String },
5656
maidenMiddleName: { type: String },
5757
maidenLastName: { type: String },
58-
isNameChangedBefrore: { type: Boolean, required: true },
58+
isNameChangedBefore: { type: Boolean, required: true },
5959
previousFirstName: { type: String },
6060
previousMiddleName: { type: String },
6161
previousLastName: { type: String },
6262
};
63+
const EmployeePersonal = connector.model(
64+
"EmplyeePersonalData",
65+
employeePersonalSchema,
66+
);
67+
/// CRUD operations ///
6368

64-
// eslint-disable-next-line no-unused-vars
65-
const empPersonal = connector.model("Employee personal", employeePersonalSchema);
69+
async function create(employeePersonalData) {
70+
const employeePersonal = new EmployeePersonal(employeePersonalData);
71+
const employeePersonalDoc = await employeePersonal.save();
72+
return employeePersonalDoc;
73+
}
74+
75+
async function read(filter, limit = 1) {
76+
const employeePersonalDoc = await EmployeePersonal.find(filter).limit(limit);
77+
return employeePersonalDoc;
78+
}
79+
80+
async function update(filter, updateObject, options = { multi: true }) {
81+
const updateResult = await EmployeePersonal.updateMany(
82+
filter,
83+
{ $set: updateObject },
84+
options,
85+
);
86+
return updateResult.acknowledged;
87+
}
88+
89+
async function remove(filter) {
90+
const deleteResult = await EmployeePersonal.deleteMany(filter).exec();
91+
return deleteResult.acknowledged;
92+
}
93+
94+
export default {
95+
create,
96+
read,
97+
update,
98+
remove,
99+
};

services/employee/emp_personal.js

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import EmployeePersonal from "#models/employeepersonal";
2+
import databaseError from "#error/database";
3+
4+
export async function addNewEmployeePersonal(uid, title, empFirstName, empLastName, bloodGroup, dob, birthPlace, motherTongue, gender, religion, numOfChildren, originalCastCategory, caste, subCaste, spouseMailAddress, spouseMobileNo, emrgContactNo, emrgContactPersonName, empMobileNo, panNumber, aadharCardNo, creditCardNumber, drivingLicenceNo, drivingLicenceExpiry, passportNumber, licId, identificationMark, addressTypePermanant, permanantPlotNo, permanantStreet, permanantAddress, permanantAddress2, permanantCity, permanantTahshil, permanantDistrict, permanantState, permanantCountry, permanantPincode, addressTypeCorrespondance, correspondancePlotNo, correspondanceStreet, correspondanceAddress, correspondanceAddress2, correspondanceCity, correspondanceTahshil, correspondanceDistrict, correspondanceState, correspondanceCountry, correspondancePincode, maritalStatus, maidenFirstName, maidenMiddleName, maidenLastName, isNameChangedBefore, previousFirstName, previousMiddleName, previousLastName) {
5+
const newEmployeePersonal = await EmployeePersonal.create({
6+
uid,
7+
title,
8+
empFirstName,
9+
empLastName,
10+
bloodGroup,
11+
dob,
12+
birthPlace,
13+
motherTongue,
14+
gender,
15+
religion,
16+
numOfChildren,
17+
originalCastCategory,
18+
caste,
19+
subCaste,
20+
spouseMailAddress,
21+
spouseMobileNo,
22+
emrgContactNo,
23+
emrgContactPersonName,
24+
empMobileNo,
25+
panNumber,
26+
aadharCardNo,
27+
creditCardNumber,
28+
drivingLicenceNo,
29+
drivingLicenceExpiry,
30+
passportNumber,
31+
licId,
32+
identificationMark,
33+
addressTypePermanant,
34+
permanantPlotNo,
35+
permanantStreet,
36+
permanantAddress,
37+
permanantAddress2,
38+
permanantCity,
39+
permanantTahshil,
40+
permanantDistrict,
41+
permanantState,
42+
permanantCountry,
43+
permanantPincode,
44+
addressTypeCorrespondance,
45+
correspondancePlotNo,
46+
correspondanceStreet,
47+
correspondanceAddress,
48+
correspondanceAddress2,
49+
correspondanceCity,
50+
correspondanceTahshil,
51+
correspondanceDistrict,
52+
correspondanceState,
53+
correspondanceCountry,
54+
correspondancePincode,
55+
maritalStatus,
56+
maidenFirstName,
57+
maidenMiddleName,
58+
maidenLastName,
59+
isNameChangedBefore,
60+
previousFirstName,
61+
previousMiddleName,
62+
previousLastName,
63+
});
64+
if (newEmployeePersonal.uid === uid) {
65+
return newEmployeePersonal;
66+
}
67+
throw new databaseError.DataEntryError("Add EmployeePersonal");
68+
}
69+
70+
export async function getEmployeePersonal(filter) {
71+
const employeePersonal = await EmployeePersonal.read(filter);
72+
if (employeePersonal) {
73+
return employeePersonal;
74+
}
75+
throw new databaseError.DataNotFoundError("EmployeePersonal");
76+
}
77+
78+
export async function deleteEmployeePersonalById(employeePersonalId) {
79+
const deleted = await EmployeePersonal.remove({ _id: employeePersonalId });
80+
if (deleted) {
81+
return deleted;
82+
}
83+
throw new databaseError.DataDeleteError("EmployeePersonal");
84+
}
85+
86+
export async function updateEmployeePersonalById(id, data) {
87+
const updated = await EmployeePersonal.update({ _id: id }, data);
88+
if (updated) {
89+
return updated;
90+
}
91+
throw new databaseError.DataEntryError("EmployeePersonal");
92+
}

0 commit comments

Comments
 (0)