chnages in desigination

master
Bhaskar 10 months ago
parent 0f978d027f
commit 1141602d70

@ -35,10 +35,10 @@ exports.addDepartment = async (request, reply) => {
const departmentId = `AWDP${d_id}`; const departmentId = `AWDP${d_id}`;
const { const {
phone, //phone,
city, city,
state, state,
password, // password,
country, country,
zone, zone,
address1, address1,
@ -50,12 +50,12 @@ exports.addDepartment = async (request, reply) => {
} = request.body; } = request.body;
const existingStore = await Department.findOne({ phone }); const existingStore = await Department.findOne({ departmentId });
if (existingStore) { if (existingStore) {
return reply.status(400).send({ message: 'Phone is already registered' }); 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({ const department = new Department({
departmentId: departmentId, departmentId: departmentId,
@ -63,7 +63,7 @@ exports.addDepartment = async (request, reply) => {
phone, phone,
address1, address1,
address2, address2,
services: { password: { bcrypt: hashedPassword } }, // services: { password: { bcrypt: hashedPassword } },
state, state,
zone, zone,
country, country,
@ -143,7 +143,7 @@ exports.addDepartment = async (request, reply) => {
const { departmentId } = request.params; const { departmentId } = request.params;
const { const {
phone, // phone,
city, city,
state, state,
country, country,
@ -161,13 +161,13 @@ exports.addDepartment = async (request, reply) => {
return reply.status(404).send({ message: 'Department not found' }); return reply.status(404).send({ message: 'Department not found' });
} }
const phoneExists = await Department.findOne({ phone, departmentId: { $ne: departmentId } }); // const phoneExists = await Department.findOne({ phone, departmentId: { $ne: departmentId } });
if (phoneExists) { // if (phoneExists) {
return reply.status(400).send({ message: 'Phone is already registered to another user' }); // 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.city = city || existing.city;
existing.state = state || existing.state; existing.state = state || existing.state;
existing.country = country || existing.country; existing.country = country || existing.country;
@ -197,6 +197,11 @@ exports.addDepartment = async (request, reply) => {
const { const {
phone, phone,
city, city,
firstName,
lastName,
departmentName,
reportingManager,
email,
state, state,
password, password,
country, country,
@ -220,6 +225,11 @@ exports.addDepartment = async (request, reply) => {
const department = new Desgination({ const department = new Desgination({
desginationId: desginationId, desginationId: desginationId,
city, city,
firstName,
lastName,
email,
reportingManager,
departmentName,
phone, phone,
address1, address1,
address2, address2,
@ -306,6 +316,11 @@ exports.addDepartment = async (request, reply) => {
phone, phone,
city, city,
firstName,
lastName,
email,
reportingManager,
departmentName,
state, state,
country, country,
zone, zone,
@ -339,6 +354,11 @@ exports.addDepartment = async (request, reply) => {
existing.address1 = address1 || existing.address1; existing.address1 = address1 || existing.address1;
existing.address2 = address2 || existing.address2; 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(); await existing.save();

@ -8,7 +8,7 @@ const departmentSchema = new mongoose.Schema(
{ {
departmentId:{type:String}, departmentId:{type:String},
departmentName: { type: String }, departmentName: { type: String },
phone: { type: String, unique: true, trim: true }, //phone: { type: String, unique: true, trim: true },
address1: String, address1: String,
address2: String, address2: String,
pincode: { type: String }, pincode: { type: String },
@ -16,7 +16,7 @@ const departmentSchema = new mongoose.Schema(
city: { type: String }, city: { type: String },
state: String, state: String,
country: String, country: String,
services: { password: { bcrypt: String } }, //services: { password: { bcrypt: String } },
createdAt: { createdAt: {
type: Date, type: Date,
default: function () { default: function () {
@ -41,6 +41,11 @@ const departmentSchema = new mongoose.Schema(
desginationId:{type:String}, desginationId:{type:String},
desginationName: { type: String }, desginationName: { type: String },
phone: { type: String, unique: true, trim: true }, phone: { type: String, unique: true, trim: true },
reportingManager : { type: String },
firstName : { type: String },
lastName: { type: String },
email: { type: String },
departmentName: { type: String },
address1: String, address1: String,
address2: String, address2: String,
pincode: { type: String }, pincode: { type: String },

@ -14,8 +14,8 @@ module.exports = function (fastify, opts, next) {
type: "object", type: "object",
//required: ["phone", "username", "password", "role"], // Add role to required fields //required: ["phone", "username", "password", "role"], // Add role to required fields
properties: { properties: {
phone: { type: "string" }, // phone: { type: "string" },
password: { type: "string" }, // password: { type: "string" },
city: { type: "string" }, city: { type: "string" },
state: { type: "string" }, state: { type: "string" },
country: { type: "string" }, country: { type: "string" },
@ -116,7 +116,7 @@ module.exports = function (fastify, opts, next) {
body: { body: {
type: "object", type: "object",
properties: { properties: {
phone: { type: "string" }, // phone: { type: "string" },
city: { type: "string" }, city: { type: "string" },
state: { type: "string" }, state: { type: "string" },
country: { type: "string" }, country: { type: "string" },
@ -154,7 +154,11 @@ module.exports = function (fastify, opts, next) {
zone: { type: "string" }, zone: { type: "string" },
pincode: { type: "string" }, pincode: { type: "string" },
desginationName: { type: "string" }, desginationName: { type: "string" },
departmentName: { type: "string" },
firstName: { type: "string" },
lastName: { type: "string" },
reportingManager: { type: "string" },
email: { type: "string" },
}, },
}, },
security: [ security: [
@ -255,6 +259,11 @@ module.exports = function (fastify, opts, next) {
zone: { type: "string" }, zone: { type: "string" },
pincode: { type: "string" }, pincode: { type: "string" },
desginationName: { type: "string" }, desginationName: { type: "string" },
email: { type: "string" },
reportingManager: { type: "string" },
departmentName: { type: "string" },
firstName: { type: "string" },
lastName: { type: "string" },
}, },
} }

Loading…
Cancel
Save