|
|
|
@ -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,
|
|
|
|
@ -143,7 +143,7 @@ exports.addDepartment = async (request, reply) => {
|
|
|
|
|
const { departmentId } = request.params;
|
|
|
|
|
const {
|
|
|
|
|
|
|
|
|
|
phone,
|
|
|
|
|
// phone,
|
|
|
|
|
city,
|
|
|
|
|
state,
|
|
|
|
|
country,
|
|
|
|
@ -161,13 +161,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 +197,11 @@ exports.addDepartment = async (request, reply) => {
|
|
|
|
|
const {
|
|
|
|
|
phone,
|
|
|
|
|
city,
|
|
|
|
|
firstName,
|
|
|
|
|
lastName,
|
|
|
|
|
departmentName,
|
|
|
|
|
reportingManager,
|
|
|
|
|
email,
|
|
|
|
|
state,
|
|
|
|
|
password,
|
|
|
|
|
country,
|
|
|
|
@ -220,6 +225,11 @@ exports.addDepartment = async (request, reply) => {
|
|
|
|
|
const department = new Desgination({
|
|
|
|
|
desginationId: desginationId,
|
|
|
|
|
city,
|
|
|
|
|
firstName,
|
|
|
|
|
lastName,
|
|
|
|
|
email,
|
|
|
|
|
reportingManager,
|
|
|
|
|
departmentName,
|
|
|
|
|
phone,
|
|
|
|
|
address1,
|
|
|
|
|
address2,
|
|
|
|
@ -306,6 +316,11 @@ exports.addDepartment = async (request, reply) => {
|
|
|
|
|
|
|
|
|
|
phone,
|
|
|
|
|
city,
|
|
|
|
|
firstName,
|
|
|
|
|
lastName,
|
|
|
|
|
email,
|
|
|
|
|
reportingManager,
|
|
|
|
|
departmentName,
|
|
|
|
|
state,
|
|
|
|
|
country,
|
|
|
|
|
zone,
|
|
|
|
@ -339,7 +354,12 @@ 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();
|
|
|
|
|
|
|
|
|
|