|
|
@ -520,90 +520,103 @@ exports.getallCompanyNames = async (req, reply) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.addDepartment = async (request, reply) => {
|
|
|
|
exports.addDepartment = async (request, reply) => {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const {
|
|
|
|
const {
|
|
|
|
phone,
|
|
|
|
phone,
|
|
|
|
officeName,
|
|
|
|
officeName,
|
|
|
|
alternativeContactNumber,
|
|
|
|
alternativeContactNumber,
|
|
|
|
gender,
|
|
|
|
gender,
|
|
|
|
personalEmail,
|
|
|
|
personalEmail,
|
|
|
|
city,
|
|
|
|
city,
|
|
|
|
personal_city,
|
|
|
|
personal_city,
|
|
|
|
reportingManager_mobile_number,
|
|
|
|
reportingManager_mobile_number,
|
|
|
|
reportingManager_email,
|
|
|
|
reportingManager_email,
|
|
|
|
firstName,
|
|
|
|
firstName,
|
|
|
|
lastName,
|
|
|
|
lastName,
|
|
|
|
departmentName,
|
|
|
|
departmentName,
|
|
|
|
reportingManager,
|
|
|
|
reportingManager,
|
|
|
|
email,
|
|
|
|
email,
|
|
|
|
state,
|
|
|
|
state,
|
|
|
|
password,
|
|
|
|
password,
|
|
|
|
country,
|
|
|
|
country,
|
|
|
|
zone,
|
|
|
|
zone,
|
|
|
|
address1,
|
|
|
|
address1,
|
|
|
|
address2,
|
|
|
|
address2,
|
|
|
|
pincode,
|
|
|
|
pincode,
|
|
|
|
desginationName,
|
|
|
|
desginationName,
|
|
|
|
location,
|
|
|
|
location,
|
|
|
|
picture,
|
|
|
|
picture,
|
|
|
|
dateOfJoin,
|
|
|
|
dateOfJoin,
|
|
|
|
employeeType,
|
|
|
|
employeeType,
|
|
|
|
createdBy,
|
|
|
|
createdBy,
|
|
|
|
updatedBy,
|
|
|
|
updatedBy,
|
|
|
|
} = request.body;
|
|
|
|
} = request.body;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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" });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Generate desginationId
|
|
|
|
// Hash the password
|
|
|
|
const departmentId = await generateDepartmentId(city, departmentName);
|
|
|
|
const hashedPassword = await bcrypt.hash(password, 10);
|
|
|
|
|
|
|
|
|
|
|
|
// Check if the phone is already registered
|
|
|
|
// 🟢 Handle reportingManager "Self"
|
|
|
|
const existingStore = await Deparments.findOne({ phone });
|
|
|
|
let finalReportingManager = reportingManager;
|
|
|
|
if (existingStore) {
|
|
|
|
let finalReportingManagerMobile = reportingManager_mobile_number;
|
|
|
|
return reply.status(400).send({ message: 'Phone is already registered' });
|
|
|
|
let finalReportingManagerEmail = reportingManager_email;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Hash the password
|
|
|
|
if (reportingManager?.toLowerCase() === "self") {
|
|
|
|
const hashedPassword = await bcrypt.hash(password, 10);
|
|
|
|
finalReportingManager = `${firstName || ""} ${lastName || ""} - (${phone}) - ${city}`;
|
|
|
|
|
|
|
|
finalReportingManagerMobile = phone;
|
|
|
|
|
|
|
|
finalReportingManagerEmail = email;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Create a new designation
|
|
|
|
// Create new department
|
|
|
|
const department = new Deparments({
|
|
|
|
const department = new Deparments({
|
|
|
|
departmentId,
|
|
|
|
departmentId,
|
|
|
|
alternativeContactNumber,
|
|
|
|
alternativeContactNumber,
|
|
|
|
officeName,
|
|
|
|
officeName,
|
|
|
|
reportingManager_mobile_number,
|
|
|
|
reportingManager_mobile_number: finalReportingManagerMobile,
|
|
|
|
reportingManager_email,
|
|
|
|
reportingManager_email: finalReportingManagerEmail,
|
|
|
|
personal_city,
|
|
|
|
personal_city,
|
|
|
|
gender,
|
|
|
|
gender,
|
|
|
|
city,
|
|
|
|
city,
|
|
|
|
firstName,
|
|
|
|
firstName,
|
|
|
|
lastName,
|
|
|
|
lastName,
|
|
|
|
email,
|
|
|
|
email,
|
|
|
|
personalEmail,
|
|
|
|
personalEmail,
|
|
|
|
reportingManager,
|
|
|
|
reportingManager: finalReportingManager,
|
|
|
|
departmentName,
|
|
|
|
departmentName,
|
|
|
|
phone,
|
|
|
|
phone,
|
|
|
|
address1,
|
|
|
|
address1,
|
|
|
|
address2,
|
|
|
|
address2,
|
|
|
|
services: { password: { bcrypt: hashedPassword } },
|
|
|
|
services: { password: { bcrypt: hashedPassword } },
|
|
|
|
state,
|
|
|
|
state,
|
|
|
|
zone,
|
|
|
|
zone,
|
|
|
|
country,
|
|
|
|
country,
|
|
|
|
pincode,
|
|
|
|
pincode,
|
|
|
|
desginationName,
|
|
|
|
desginationName,
|
|
|
|
location,
|
|
|
|
location,
|
|
|
|
picture,
|
|
|
|
picture,
|
|
|
|
dateOfJoin,
|
|
|
|
dateOfJoin,
|
|
|
|
employeeType,
|
|
|
|
employeeType,
|
|
|
|
createdBy,
|
|
|
|
createdBy,
|
|
|
|
updatedBy,
|
|
|
|
updatedBy,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
await department.save();
|
|
|
|
await department.save();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
reply.send({ department, message: "Account Created Successfully" });
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
|
|
console.error("❌ Error in addDepartment:", err);
|
|
|
|
|
|
|
|
reply.status(500).send({ message: err.message });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
reply.send({ department, message: 'Account Created Successfully' });
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
|
|
reply.status(500).send({ message: err.message });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.getDetails = async (request, reply) => {
|
|
|
|
exports.getDetails = async (request, reply) => {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|