|
|
|
@ -552,25 +552,36 @@ exports.addDepartment = async (request, reply) => {
|
|
|
|
|
updatedBy,
|
|
|
|
|
} = request.body;
|
|
|
|
|
|
|
|
|
|
// Generate desginationId
|
|
|
|
|
// Generate departmentId
|
|
|
|
|
const departmentId = await generateDepartmentId(city, departmentName);
|
|
|
|
|
|
|
|
|
|
// Check if the phone is already registered
|
|
|
|
|
const existingStore = await Deparments.findOne({ phone });
|
|
|
|
|
if (existingStore) {
|
|
|
|
|
return reply.status(400).send({ message: 'Phone is already registered' });
|
|
|
|
|
return reply.status(400).send({ message: "Phone is already registered" });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Hash the password
|
|
|
|
|
const hashedPassword = await bcrypt.hash(password, 10);
|
|
|
|
|
|
|
|
|
|
// Create a new designation
|
|
|
|
|
// 🟢 Handle reportingManager "Self"
|
|
|
|
|
let finalReportingManager = reportingManager;
|
|
|
|
|
let finalReportingManagerMobile = reportingManager_mobile_number;
|
|
|
|
|
let finalReportingManagerEmail = reportingManager_email;
|
|
|
|
|
|
|
|
|
|
if (reportingManager?.toLowerCase() === "self") {
|
|
|
|
|
finalReportingManager = `${firstName || ""} ${lastName || ""} - (${phone}) - ${city}`;
|
|
|
|
|
finalReportingManagerMobile = phone;
|
|
|
|
|
finalReportingManagerEmail = email;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create new department
|
|
|
|
|
const department = new Deparments({
|
|
|
|
|
departmentId,
|
|
|
|
|
alternativeContactNumber,
|
|
|
|
|
officeName,
|
|
|
|
|
reportingManager_mobile_number,
|
|
|
|
|
reportingManager_email,
|
|
|
|
|
reportingManager_mobile_number: finalReportingManagerMobile,
|
|
|
|
|
reportingManager_email: finalReportingManagerEmail,
|
|
|
|
|
personal_city,
|
|
|
|
|
gender,
|
|
|
|
|
city,
|
|
|
|
@ -578,7 +589,7 @@ exports.addDepartment = async (request, reply) => {
|
|
|
|
|
lastName,
|
|
|
|
|
email,
|
|
|
|
|
personalEmail,
|
|
|
|
|
reportingManager,
|
|
|
|
|
reportingManager: finalReportingManager,
|
|
|
|
|
departmentName,
|
|
|
|
|
phone,
|
|
|
|
|
address1,
|
|
|
|
@ -599,11 +610,13 @@ exports.addDepartment = async (request, reply) => {
|
|
|
|
|
|
|
|
|
|
await department.save();
|
|
|
|
|
|
|
|
|
|
reply.send({ department, message: 'Account Created Successfully' });
|
|
|
|
|
reply.send({ department, message: "Account Created Successfully" });
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error("❌ Error in addDepartment:", err);
|
|
|
|
|
reply.status(500).send({ message: err.message });
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.getDetails = async (request, reply) => {
|
|
|
|
|
try {
|
|
|
|
|