|
|
|
|
@ -35,10 +35,10 @@ exports.addDepartment = async (request, reply) => {
|
|
|
|
|
const departmentId = `AWDP${d_id}`;
|
|
|
|
|
|
|
|
|
|
const {
|
|
|
|
|
phone,
|
|
|
|
|
//phone,
|
|
|
|
|
city,
|
|
|
|
|
state,
|
|
|
|
|
password,
|
|
|
|
|
// password,
|
|
|
|
|
country,
|
|
|
|
|
zone,
|
|
|
|
|
address1,
|
|
|
|
|
@ -50,12 +50,12 @@ exports.addDepartment = async (request, reply) => {
|
|
|
|
|
} = request.body;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const existingStore = await Department.findOne({ phone });
|
|
|
|
|
const existingStore = await Department.findOne({ departmentId });
|
|
|
|
|
if (existingStore) {
|
|
|
|
|
return reply.status(400).send({ message: 'Phone is already registered' });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const hashedPassword = await bcrypt.hash(password, 10);
|
|
|
|
|
// const hashedPassword = await bcrypt.hash(password, 10);
|
|
|
|
|
|
|
|
|
|
const department = new Department({
|
|
|
|
|
departmentId: departmentId,
|
|
|
|
|
@ -63,7 +63,7 @@ exports.addDepartment = async (request, reply) => {
|
|
|
|
|
phone,
|
|
|
|
|
address1,
|
|
|
|
|
address2,
|
|
|
|
|
services: { password: { bcrypt: hashedPassword } },
|
|
|
|
|
// services: { password: { bcrypt: hashedPassword } },
|
|
|
|
|
state,
|
|
|
|
|
zone,
|
|
|
|
|
country,
|
|
|
|
|
@ -125,6 +125,31 @@ exports.addDepartment = async (request, reply) => {
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.getAllDepartmentsParticularFields = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const departments = await Department.find().exec();
|
|
|
|
|
|
|
|
|
|
// Grouping the data
|
|
|
|
|
const result = {
|
|
|
|
|
cities: [...new Set(departments.map((doc) => doc.city))],
|
|
|
|
|
zones: [...new Set(departments.map((doc) => doc.zone))],
|
|
|
|
|
pincodes: [...new Set(departments.map((doc) => doc.pincode))],
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Sending the response
|
|
|
|
|
reply.send({
|
|
|
|
|
status_code: 200,
|
|
|
|
|
data: result,
|
|
|
|
|
count: departments.length,
|
|
|
|
|
});
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error(err);
|
|
|
|
|
reply.send({ error: err.message });
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.deletedepartmentInfo = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const departmentId = req.params.departmentId;
|
|
|
|
|
@ -143,7 +168,7 @@ exports.addDepartment = async (request, reply) => {
|
|
|
|
|
const { departmentId } = request.params;
|
|
|
|
|
const {
|
|
|
|
|
|
|
|
|
|
phone,
|
|
|
|
|
// phone,
|
|
|
|
|
city,
|
|
|
|
|
state,
|
|
|
|
|
country,
|
|
|
|
|
@ -161,13 +186,13 @@ exports.addDepartment = async (request, reply) => {
|
|
|
|
|
return reply.status(404).send({ message: 'Department not found' });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const phoneExists = await Department.findOne({ phone, departmentId: { $ne: departmentId } });
|
|
|
|
|
if (phoneExists) {
|
|
|
|
|
return reply.status(400).send({ message: 'Phone is already registered to another user' });
|
|
|
|
|
}
|
|
|
|
|
// const phoneExists = await Department.findOne({ phone, departmentId: { $ne: departmentId } });
|
|
|
|
|
// if (phoneExists) {
|
|
|
|
|
// return reply.status(400).send({ message: 'Phone is already registered to another user' });
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
existing.phone = phone || existing.phone;
|
|
|
|
|
// existing.phone = phone || existing.phone;
|
|
|
|
|
existing.city = city || existing.city;
|
|
|
|
|
existing.state = state || existing.state;
|
|
|
|
|
existing.country = country || existing.country;
|
|
|
|
|
@ -197,6 +222,11 @@ exports.addDepartment = async (request, reply) => {
|
|
|
|
|
const {
|
|
|
|
|
phone,
|
|
|
|
|
city,
|
|
|
|
|
firstName,
|
|
|
|
|
lastName,
|
|
|
|
|
departmentName,
|
|
|
|
|
reportingManager,
|
|
|
|
|
email,
|
|
|
|
|
state,
|
|
|
|
|
password,
|
|
|
|
|
country,
|
|
|
|
|
@ -220,6 +250,11 @@ exports.addDepartment = async (request, reply) => {
|
|
|
|
|
const department = new Desgination({
|
|
|
|
|
desginationId: desginationId,
|
|
|
|
|
city,
|
|
|
|
|
firstName,
|
|
|
|
|
lastName,
|
|
|
|
|
email,
|
|
|
|
|
reportingManager,
|
|
|
|
|
departmentName,
|
|
|
|
|
phone,
|
|
|
|
|
address1,
|
|
|
|
|
address2,
|
|
|
|
|
@ -306,6 +341,11 @@ exports.addDepartment = async (request, reply) => {
|
|
|
|
|
|
|
|
|
|
phone,
|
|
|
|
|
city,
|
|
|
|
|
firstName,
|
|
|
|
|
lastName,
|
|
|
|
|
email,
|
|
|
|
|
reportingManager,
|
|
|
|
|
departmentName,
|
|
|
|
|
state,
|
|
|
|
|
country,
|
|
|
|
|
zone,
|
|
|
|
|
@ -339,6 +379,11 @@ exports.addDepartment = async (request, reply) => {
|
|
|
|
|
existing.address1 = address1 || existing.address1;
|
|
|
|
|
existing.address2 = address2 || existing.address2;
|
|
|
|
|
|
|
|
|
|
existing.email = email || existing.email;
|
|
|
|
|
existing.firstName = firstName || existing.firstName;
|
|
|
|
|
existing.lastName = lastName || existing.lastName;
|
|
|
|
|
existing.departmentName = departmentName || existing.departmentName;
|
|
|
|
|
existing.reportingManager = reportingManager || existing.reportingManager
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await existing.save();
|
|
|
|
|
|