Varun 9 months ago
commit 031754f948

@ -90,6 +90,34 @@ exports.adminSignUp = async (request, reply) => {
// Admin Login Function (With Phone Number) // Admin Login Function (With Phone Number)
// exports.adminLogin = async (request, reply) => {
// try {
// const { phone, password } = request.body;
// // Check if an admin with the phone number exists
// const admin = await Admin.findOne({ phone });
// if (!admin) {
// return reply.status(401).send({ message: 'Invalid phone number or password' });
// }
// // Compare the password entered by the user with the hashed password stored in the database
// const isPasswordValid = await bcrypt.compare(password, admin.password);
// if (!isPasswordValid) {
// return reply.status(401).send({ message: 'Invalid phone number or password' });
// }
// // Generate a JWT token for the authenticated admin
// const token = jwt.sign({ phone: admin.phone, role: 'admin' }, JWT_SECRET, { expiresIn: '1h' });
// return reply.send({ token, admin });
// } catch (err) {
// reply.status(500).send({ message: err.message });
// }
// };
exports.adminLogin = async (request, reply) => { exports.adminLogin = async (request, reply) => {
try { try {
const { phone, password } = request.body; const { phone, password } = request.body;
@ -98,26 +126,59 @@ exports.adminLogin = async (request, reply) => {
const admin = await Admin.findOne({ phone }); const admin = await Admin.findOne({ phone });
if (!admin) { if (!admin) {
return reply.status(401).send({ message: 'Invalid phone number or password' }); return reply.status(401).send({
simplydata: {
error: true,
message: "Invalid phone number or password",
},
});
} }
// Compare the password entered by the user with the hashed password stored in the database // Compare the password entered by the user with the hashed password stored in the database
const isPasswordValid = await bcrypt.compare(password, admin.password); const isPasswordValid = await bcrypt.compare(password, admin.password);
if (!isPasswordValid) { if (!isPasswordValid) {
return reply.status(401).send({ message: 'Invalid phone number or password' }); return reply.status(401).send({
simplydata: {
error: true,
message: "Invalid phone number or password",
},
});
} }
// Generate a JWT token for the authenticated admin // Generate a JWT token for the authenticated admin
const token = jwt.sign({ phone: admin.phone, role: 'admin' }, JWT_SECRET, { expiresIn: '1h' }); const token = jwt.sign(
{ phone: admin.phone, role: admin.role },
JWT_SECRET,
{ expiresIn: "1h" }
);
return reply.send({ token, admin }); // Create the response payload
const responsePayload = {
simplydata: {
error: false,
apiversion: process.env.APIVERSION,
access_token: token,
phone: admin.phone,
type: admin.role,
customerId: admin.customerId || null,
username: admin.username || null,
},
};
// Send the response
return reply.send(responsePayload);
} catch (err) { } catch (err) {
reply.status(500).send({ message: err.message }); reply.status(500).send({
simplydata: {
error: true,
message: err.message,
},
});
} }
}; };
// adminController.js // adminController.js
exports.editUserByCustomerId = async (req, reply) => { exports.editUserByCustomerId = async (req, reply) => {

@ -10,29 +10,51 @@ const fastify = require("fastify")({
}); });
const { Counter} = require('../models/User') const { Counter} = require('../models/User')
const {Department, Desgination} = require('../models/Department') const {Department, Desgination, City, Deparments} = require('../models/Department')
const generateDepartmentId = async (prefix) => { // const generateDepartmentId = async (prefix) => {
const result = await Counter.findOneAndUpdate( // const result = await Counter.findOneAndUpdate(
{ _id: 'department_id' }, // { _id: 'department_id' },
// { $inc: { seq: 1 } },
// { upsert: true, new: true }
// );
// return `AW${prefix}${result.seq}`;
// };
const generateCityId = async () => {
var result = await Counter.findOneAndUpdate(
{ _id: 'customer_id' },
{ $inc: { seq: 1 } }, { $inc: { seq: 1 } },
{ upsert: true, new: true } { upsert: true, new: true }
); );
return `AW${prefix}${result.seq}`;
return result.seq;
}; };
const generateDesginationId = async (prefix) => { // const generateDesginationId = async (prefix) => {
// const result = await Counter.findOneAndUpdate(
// { _id: 'desgination_id' },
// { $inc: { seq: 1 } },
// { upsert: true, new: true }
// );
// return `AW${prefix}${result.seq}`;
// };
const generateDepartmentId = async (city, departmentName) => {
const cityPrefix = city.substring(0, 2).toUpperCase(); // Extract first two letters of city
const departmentPrefix = departmentName.substring(0, 2).toUpperCase(); // Extract first two letters of departmentName
const result = await Counter.findOneAndUpdate( const result = await Counter.findOneAndUpdate(
{ _id: 'desgination_id' }, { _id: 'desgination_id' },
{ $inc: { seq: 1 } }, { $inc: { seq: 1 } },
{ upsert: true, new: true } { upsert: true, new: true }
); );
return `AW${prefix}${result.seq}`;
return `AW${cityPrefix}${departmentPrefix}${result.seq}`; // Generate ID
}; };
exports.addDepartment = async (request, reply) => { exports.addCity = async (request, reply) => {
try { try {
const { const {
departmentName,
phone, phone,
officeName, officeName,
location, location,
@ -48,18 +70,18 @@ const generateDepartmentId = async (prefix) => {
} = request.body; } = request.body;
// Generate departmentId based on departmentName // Generate departmentId based on departmentName
const prefix = departmentName.substring(0, 2).toUpperCase(); // Extract first two letters and convert to uppercase // const prefix = departmentName.substring(0, 2).toUpperCase(); // Extract first two letters and convert to uppercase
const departmentId = await generateDepartmentId(prefix); const cityId = await generateCityId();
// Check for existing department // Check for existing department
const existingStore = await Department.findOne({ departmentId }); const existingStore = await City.findOne({ cityId });
if (existingStore) { if (existingStore) {
return reply.status(400).send({ message: 'Department is already registered' }); return reply.status(400).send({ message: 'City is already registered' });
} }
// Create new department // Create new department
const department = new Department({ const citys = new City({
departmentId, cityId,
phone, phone,
officeName, officeName,
location, location,
@ -70,49 +92,49 @@ const generateDepartmentId = async (prefix) => {
zone, zone,
country, country,
pincode, pincode,
departmentName, // departmentName,
createdBy, createdBy,
updatedBy, updatedBy,
}); });
await department.save(); await citys.save();
reply.send({ department, message: 'Account Created Successfully' }); reply.send({ citys, message: 'Account Created Successfully' });
} catch (err) { } catch (err) {
reply.status(500).send({ message: err.message }); reply.status(500).send({ message: err.message });
} }
}; };
exports.getSinledepartmentData = async (req, reply) => { // exports.getSinledepartmentData = async (req, reply) => {
// try {
// const { departmentId } = req.params;
// const department = await Department.findOne({ departmentId: departmentId });
// if (!department) {
// return reply.code(404).send({
// success: false,
// message: 'Department not found.'
// });
// }
// reply.code(200).send({
// success: true,
// message: 'Department data retrieved successfully.',
// data: department
// });
// } catch (error) {
// console.error('Error fetching department data:', error);
// reply.code(500).send({
// success: false,
// message: 'Failed to retrieve department data.',
// error: error.message,
// });
// }
// };
exports.getallcities = async (req, reply) => {
try { try {
const { departmentId } = req.params; await City.find()
const department = await Department.findOne({ departmentId: departmentId });
if (!department) {
return reply.code(404).send({
success: false,
message: 'Department not found.'
});
}
reply.code(200).send({
success: true,
message: 'Department data retrieved successfully.',
data: department
});
} catch (error) {
console.error('Error fetching department data:', error);
reply.code(500).send({
success: false,
message: 'Failed to retrieve department data.',
error: error.message,
});
}
};
exports.getalldepartmants = async (req, reply) => {
try {
await Department.find()
.exec() .exec()
.then((docs) => { .then((docs) => {
reply.send({ status_code: 200, data: docs, count: docs.length }); reply.send({ status_code: 200, data: docs, count: docs.length });
@ -127,38 +149,38 @@ const generateDepartmentId = async (prefix) => {
}; };
exports.getAllDepartmentsParticularFields = async (req, 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))],
// departments: [...new Set(departments.map((doc) => doc.departmentName))],
// states: [...new Set(departments.map((doc) => doc.state))],
// countries: [...new Set(departments.map((doc) => doc.country))],
// };
// // Sending the response
// reply.send({
// status_code: 200,
// data: result,
// count: departments.length,
// });
// } catch (err) {
// console.error(err);
// reply.send({ error: err.message });
// }
// };
exports.deletecityInfo = async (req, reply) => {
try { try {
const departments = await Department.find().exec(); const cityId = req.params.cityId;
// 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))],
departments: [...new Set(departments.map((doc) => doc.departmentName))],
states: [...new Set(departments.map((doc) => doc.state))],
countries: [...new Set(departments.map((doc) => doc.country))],
};
// 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;
const department = await Department.findOneAndDelete({ departmentId:departmentId }); const department = await City.findOneAndDelete({ cityId:cityId });
reply.send({ status_code: 200, message: 'Delete Sucessfully', department}); reply.send({ status_code: 200, message: 'Delete Sucessfully', department});
} catch (err) { } catch (err) {
@ -167,9 +189,9 @@ exports.getAllDepartmentsParticularFields = async (req, reply) => {
}; };
exports.editdepartment = async (request, reply) => { exports.editcity = async (request, reply) => {
try { try {
const { departmentId } = request.params; const { cityId } = request.params;
const { const {
// phone, // phone,
@ -180,14 +202,14 @@ exports.getAllDepartmentsParticularFields = async (req, reply) => {
address1, address1,
address2, address2,
pincode, pincode,
departmentName // departmentName
} = request.body; } = request.body;
const existing = await Department.findOne({ departmentId }); const existing = await City.findOne({ cityId });
if (!existing) { if (!existing) {
return reply.status(404).send({ message: 'Department not found' }); return reply.status(404).send({ message: 'City not found' });
} }
// const phoneExists = await Department.findOne({ phone, departmentId: { $ne: departmentId } }); // const phoneExists = await Department.findOne({ phone, departmentId: { $ne: departmentId } });
@ -201,7 +223,7 @@ exports.getAllDepartmentsParticularFields = async (req, reply) => {
existing.state = state || existing.state; existing.state = state || existing.state;
existing.country = country || existing.country; existing.country = country || existing.country;
existing.zone = zone || existing.zone; existing.zone = zone || existing.zone;
existing.departmentName = departmentName || existing.departmentName; // existing.departmentName = departmentName || existing.departmentName;
existing.pincode = pincode || existing.pincode; existing.pincode = pincode || existing.pincode;
existing.address1 = address1 || existing.address1; existing.address1 = address1 || existing.address1;
@ -211,17 +233,88 @@ exports.getAllDepartmentsParticularFields = async (req, reply) => {
await existing.save(); await existing.save();
reply.send({ message: 'Department user updated successfully' }); reply.send({ message: 'City user updated successfully' });
} catch (err) { } catch (err) {
reply.status(500).send({ message: err.message }); reply.status(500).send({ message: err.message });
} }
}; };
exports.addDesgination = async (request, reply) => { // exports.addDesgination = async (request, reply) => {
// try {
// const {
// phone,
// city,
// firstName,
// lastName,
// departmentName,
// reportingManager,
// email,
// state,
// password,
// country,
// zone,
// address1,
// address2,
// pincode,
// desginationName,
// location,
// createdBy,
// updatedBy,
// } = request.body;
// // Generate desginationId based on desginationName
// const prefix = departmentName.substring(0, 2).toUpperCase();
// const desginationId = await generateDesginationId(prefix);
// // Check if the phone is already registered
// const existingStore = await Desgination.findOne({ phone });
// if (existingStore) {
// return reply.status(400).send({ message: 'Phone is already registered' });
// }
// // Hash the password
// const hashedPassword = await bcrypt.hash(password, 10);
// // Create a new designation
// const desgination = new Desgination({
// desginationId,
// city,
// firstName,
// lastName,
// email,
// reportingManager,
// departmentName,
// phone,
// address1,
// address2,
// services: { password: { bcrypt: hashedPassword } },
// state,
// zone,
// country,
// pincode,
// desginationName,
// location,
// createdBy,
// updatedBy,
// });
// await desgination.save();
// reply.send({ desgination, message: 'Account Created Successfully' });
// } catch (err) {
// reply.status(500).send({ message: err.message });
// }
// };
exports.addDepartment = async (request, reply) => {
try { try {
const { const {
phone, phone,
alternativeContactNumber,
gender,
personalEmail,
city, city,
firstName, firstName,
lastName, lastName,
@ -241,12 +334,11 @@ exports.getAllDepartmentsParticularFields = async (req, reply) => {
updatedBy, updatedBy,
} = request.body; } = request.body;
// Generate desginationId based on desginationName // Generate desginationId
const prefix = departmentName.substring(0, 2).toUpperCase(); const departmentId = await generateDepartmentId(city, departmentName);
const desginationId = await generateDesginationId(prefix);
// Check if the phone is already registered // Check if the phone is already registered
const existingStore = await Desgination.findOne({ phone }); const existingStore = await Deparments.findOne({ phone });
if (existingStore) { if (existingStore) {
return reply.status(400).send({ message: 'Phone is already registered' }); return reply.status(400).send({ message: 'Phone is already registered' });
} }
@ -255,12 +347,15 @@ exports.getAllDepartmentsParticularFields = async (req, reply) => {
const hashedPassword = await bcrypt.hash(password, 10); const hashedPassword = await bcrypt.hash(password, 10);
// Create a new designation // Create a new designation
const desgination = new Desgination({ const department = new Deparments({
desginationId, departmentId,
alternativeContactNumber,
gender,
city, city,
firstName, firstName,
lastName, lastName,
email, email,
personalEmail,
reportingManager, reportingManager,
departmentName, departmentName,
phone, phone,
@ -277,19 +372,19 @@ exports.getAllDepartmentsParticularFields = async (req, reply) => {
updatedBy, updatedBy,
}); });
await desgination.save(); await department.save();
reply.send({ desgination, message: 'Account Created Successfully' }); reply.send({ department, message: 'Account Created Successfully' });
} catch (err) { } catch (err) {
reply.status(500).send({ message: err.message }); reply.status(500).send({ message: err.message });
} }
}; };
exports.getSinledesginationData = async (req, reply) => { exports.getSinledepartmentData = async (req, reply) => {
try { try {
const { desginationId } = req.params; const { departmentId } = req.params;
const department = await Desgination.findOne({ desginationId: desginationId }); const department = await Deparments.findOne({ departmentId: departmentId });
if (!department) { if (!department) {
return reply.code(404).send({ return reply.code(404).send({
@ -313,9 +408,9 @@ exports.getAllDepartmentsParticularFields = async (req, reply) => {
} }
}; };
exports.getalldesgination = async (req, reply) => { exports.getalldepartments = async (req, reply) => {
try { try {
await Desgination.find() await Deparments.find()
.exec() .exec()
.then((docs) => { .then((docs) => {
reply.send({ status_code: 200, data: docs, count: docs.length }); reply.send({ status_code: 200, data: docs, count: docs.length });
@ -329,11 +424,11 @@ exports.getAllDepartmentsParticularFields = async (req, reply) => {
} }
}; };
exports.deletedesginationInfo = async (req, reply) => { exports.deletedepartmentInfo = async (req, reply) => {
try { try {
const desginationId = req.params.desginationId; const departmentId = req.params.departmentId;
const department = await Desgination.findOneAndDelete({ desginationId:desginationId }); const department = await Deparments.findOneAndDelete({ departmentId:departmentId });
reply.send({ status_code: 200, message: 'Delete Sucessfully', department}); reply.send({ status_code: 200, message: 'Delete Sucessfully', department});
} catch (err) { } catch (err) {
@ -342,12 +437,15 @@ exports.getAllDepartmentsParticularFields = async (req, reply) => {
}; };
exports.editdesgination = async (request, reply) => { exports.editdepartment = async (request, reply) => {
try { try {
const { desginationId } = request.params; const { departmentId } = request.params;
const { const {
phone, phone,
alternativeContactNumber,
gender,
personalEmail,
city, city,
firstName, firstName,
lastName, lastName,
@ -365,18 +463,21 @@ exports.getAllDepartmentsParticularFields = async (req, reply) => {
} = request.body; } = request.body;
const existing = await Desgination.findOne({ desginationId }); const existing = await Deparments.findOne({ departmentId });
if (!existing) { if (!existing) {
return reply.status(404).send({ message: 'Designation not found' }); return reply.status(404).send({ message: 'Department not found' });
} }
const phoneExists = await Desgination.findOne({ phone, desginationId: { $ne: desginationId } }); const phoneExists = await Deparments.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.alternativeContactNumber = alternativeContactNumber || existing.alternativeContactNumber;
existing.personalEmail = personalEmail || existing.personalEmail;
existing.gender = gender || existing.gender;
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;
@ -396,36 +497,86 @@ exports.getAllDepartmentsParticularFields = async (req, reply) => {
await existing.save(); await existing.save();
reply.send({ message: 'Designation user updated successfully' }); reply.send({ message: 'Department user updated successfully' });
} catch (err) { } catch (err) {
reply.status(500).send({ message: err.message }); reply.status(500).send({ message: err.message });
} }
}; };
exports.getAllDesignationsParticularFields = async (req, reply) => { // exports.getAllDesignationsParticularFields = async (req, reply) => {
try { // try {
const departments = await Desgination.find().exec(); // const departments = await Desgination.find().exec();
// Grouping the data // // Grouping the data
const result = { // const result = {
cities: [...new Set(departments.map((doc) => doc.city))], // cities: [...new Set(departments.map((doc) => doc.city))],
zones: [...new Set(departments.map((doc) => doc.zone))], // zones: [...new Set(departments.map((doc) => doc.zone))],
pincodes: [...new Set(departments.map((doc) => doc.pincode))], // pincodes: [...new Set(departments.map((doc) => doc.pincode))],
departments: [...new Set(departments.map((doc) => doc.departmentName))], // departments: [...new Set(departments.map((doc) => doc.departmentName))],
states: [...new Set(departments.map((doc) => doc.state))], // states: [...new Set(departments.map((doc) => doc.state))],
countries: [...new Set(departments.map((doc) => doc.country))], // countries: [...new Set(departments.map((doc) => doc.country))],
designations: [...new Set(departments.map((doc) => doc.desginationName))], // designations: [...new Set(departments.map((doc) => doc.desginationName))],
reportingMangers: [...new Set(departments.map((doc) => doc.reportingManager))], // reportingMangers: [...new Set(departments.map((doc) => doc.reportingManager))],
}; // };
// Sending the response // // Sending the response
reply.send({ // reply.send({
status_code: 200, // status_code: 200,
data: result, // data: result,
count: departments.length, // count: departments.length,
}); // });
// } catch (err) {
// console.error(err);
// reply.send({ error: err.message });
// }
// };
const getLocationsByCityAndZone = async (city, zone) => {
try {
const result = await City.aggregate([
{
$match: {
city: city, // Match documents with the same city
zone: zone, // Match documents with the same zone
},
},
{
$group: {
_id: { city: "$city", zone: "$zone" }, // Group by city and zone
locations: { $push: "$location" }, // Collect all location arrays
},
},
{
$project: {
_id: 0, // Exclude the _id field
city: "$_id.city",
zone: "$_id.zone",
locations: {
$reduce: {
input: "$locations",
initialValue: [],
in: { $concatArrays: ["$$value", "$$this"] }, // Flatten the location arrays
},
},
},
},
]);
return result;
} catch (err) { } catch (err) {
console.error(err); console.error(err);
reply.send({ error: err.message }); throw new Error("Error fetching locations.");
} }
};
exports.getZonebasedLocations = async (req, reply) => {
try {
const { city, zone } = req.query;
const locations = await getLocationsByCityAndZone(city, zone);
reply.send({ status_code: 200, data: locations });
} catch (err) {
reply.status(500).send({ message: err.message });
}
}; };

@ -4,10 +4,10 @@ const ObjectId = Schema.Types.ObjectId;
const departmentSchema = new mongoose.Schema( const citySchema = new mongoose.Schema(
{ {
departmentId:{type:String}, cityId:{type:String},
departmentName: { type: String }, //departmentName: { type: String },
phone: { type: String, unique: true, trim: true }, phone: { type: String, unique: true, trim: true },
office_address1: String, office_address1: String,
officeName: { type: String }, officeName: { type: String },
@ -38,16 +38,19 @@ const departmentSchema = new mongoose.Schema(
); );
const desginationSchema = new mongoose.Schema( const departmentsSchema = new mongoose.Schema(
{ {
desginationId:{type:String}, departmentId:{type:String},
desginationName: { type: String }, desginationName: { type: String },
phone: { type: String, unique: true, trim: true }, phone: { type: String, unique: true, trim: true },
alternativeContactNumber : { type: String },
reportingManager : { type: String }, reportingManager : { type: String },
location: [{ type : String}], location: [{ type : String}],
firstName : { type: String }, firstName : { type: String },
gender: { type: String },
lastName: { type: String }, lastName: { type: String },
email: { type: String }, email: { type: String },
personalEmail : {type: String},
departmentName: { type: String }, departmentName: { type: String },
address1: String, address1: String,
address2: String, address2: String,
@ -76,8 +79,8 @@ const departmentSchema = new mongoose.Schema(
); );
const Department = mongoose.model('Department', departmentSchema); const City = mongoose.model('City', citySchema);
const Desgination = mongoose.model('Desgination', desginationSchema); const Deparments = mongoose.model('Deparments', departmentsSchema);
module.exports = { Department,Desgination}; module.exports = { City,Deparments};

@ -4,11 +4,11 @@ module.exports = function (fastify, opts, next) {
fastify.route({ fastify.route({
method: "POST", method: "POST",
url: "/api/departmentSignup", url: "/api/citySignup",
schema: { schema: {
tags: ["Department"], tags: ["Department"],
description: "This is for creating a new department account", description: "This is for creating a new City account",
summary: "This is for creating a new department account", summary: "This is for creating a new City account",
body: { body: {
type: "object", type: "object",
properties: { properties: {
@ -34,39 +34,39 @@ module.exports = function (fastify, opts, next) {
}, },
], ],
}, },
handler: departmentController.addDepartment, handler: departmentController.addCity,
}); });
fastify.get("/api/getSingledepartmentData/:departmentId", { // fastify.get("/api/getSingledepartmentData/:departmentId", {
schema: { // schema: {
tags: ["Department"], // tags: ["Department"],
description: "This is for Get Single departmentId Data", // description: "This is for Get Single departmentId Data",
summary: "This is to Get Single departmentId Data", // summary: "This is to Get Single departmentId Data",
params: { // params: {
type: "object", // type: "object",
properties: { // properties: {
departmentId: { // departmentId: {
type: "string", // type: "string",
description: "departmentId", // description: "departmentId",
}, // },
}, // },
}, // },
security: [ // security: [
{ // {
basicAuth: [], // basicAuth: [],
}, // },
], // ],
}, // },
handler: departmentController.getSinledepartmentData, // handler: departmentController.getSinledepartmentData,
}); // });
fastify.get("/api/getalldepartments", { fastify.get("/api/getallcities", {
schema: { schema: {
tags: ["Department"], tags: ["Department"],
description: "This is for Get all Department Data", description: "This is for Get all cities Data",
summary: "This is for to Get all Department Data", summary: "This is for to Get all cities Data",
security: [ security: [
{ {
@ -75,37 +75,37 @@ module.exports = function (fastify, opts, next) {
], ],
}, },
//preHandler: fastify.auth([fastify.authenticate]), //preHandler: fastify.auth([fastify.authenticate]),
handler: departmentController.getalldepartmants, handler: departmentController.getallcities,
}); });
fastify.get("/api/getalldepartmentsParticularFileds", { // fastify.get("/api/getalldepartmentsParticularFileds", {
schema: { // schema: {
tags: ["Department"], // tags: ["Department"],
description: "This is for Get all Department particular fileds Data", // description: "This is for Get all Department particular fileds Data",
summary: "This is for to Get all Department particular fields Data", // summary: "This is for to Get all Department particular fields Data",
security: [ // security: [
{ // {
basicAuth: [], // basicAuth: [],
}, // },
], // ],
}, // },
//preHandler: fastify.auth([fastify.authenticate]), // //preHandler: fastify.auth([fastify.authenticate]),
handler: departmentController.getAllDepartmentsParticularFields, // handler: departmentController.getAllDepartmentsParticularFields,
}); // });
fastify.delete("/api/deletedepartment/:departmentId", { fastify.delete("/api/deletecity/:cityId", {
schema: { schema: {
description: "Delete a Department by departmentId", description: "Delete a city by cityId",
tags: ["Department"], tags: ["Department"],
summary: "Delete a user by departmentId", summary: "Delete a user by city",
params: { params: {
type: "object", type: "object",
properties: { properties: {
departmentId: { type: "string" }, // Customer ID cityId: { type: "string" },
}, },
required: ["departmentId"], required: ["cityId"],
}, },
response: { response: {
200: { 200: {
@ -117,20 +117,20 @@ module.exports = function (fastify, opts, next) {
} }
} }
}, },
handler: departmentController.deletedepartmentInfo, handler: departmentController.deletecityInfo,
}); });
fastify.put('/api/editdepartment/:departmentId', { fastify.put('/api/editcity/:cityId', {
schema: { schema: {
description: "Edit Department details by departmentId", description: "Edit City details by cityId",
tags: ["Department"], tags: ["Department"],
summary: "Edit Department details.", summary: "Edit City details.",
params: { params: {
type: "object", type: "object",
properties: { properties: {
departmentId: { type: "string" }, cityId: { type: "string" },
}, },
required: ["departmentId"], required: ["cityId"],
}, },
body: { body: {
type: "object", type: "object",
@ -148,23 +148,26 @@ module.exports = function (fastify, opts, next) {
}, },
} }
}, },
handler: departmentController.editdepartment, handler: departmentController.editcity,
}); });
fastify.route({ fastify.route({
method: "POST", method: "POST",
url: "/api/desginationSignup", url: "/api/departmentSignup",
schema: { schema: {
tags: ["Department"], tags: ["Department"],
description: "This is for creating a new Desgination Account", description: "This is for creating a new Department Account",
summary: "This is for creating a new Desgination Account", summary: "This is for creating a new Department Account",
body: { body: {
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" },
alternativeContactNumber: { type: "string" },
personalEmail: { type: "string" },
gender: { type: "string" },
city: { type: "string" }, city: { type: "string" },
state: { type: "string" }, state: { type: "string" },
country: { type: "string" }, country: { type: "string" },
@ -190,20 +193,20 @@ module.exports = function (fastify, opts, next) {
}, },
], ],
}, },
handler: departmentController.addDesgination, handler: departmentController.addDepartment,
}); });
fastify.get("/api/getSingledesginationData/:desginationId", { fastify.get("/api/getSingledepartmentData/:departmentId", {
schema: { schema: {
tags: ["Department"], tags: ["Department"],
description: "This is for Get Single desginationId Data", description: "This is for Get Single departmentId Data",
summary: "This is to Get Single desginationId Data", summary: "This is to Get Single departmentId Data",
params: { params: {
type: "object", type: "object",
properties: { properties: {
desginationId: { departmentId: {
type: "string", type: "string",
description: "desginationId", description: "departmentId",
}, },
}, },
}, },
@ -214,14 +217,14 @@ module.exports = function (fastify, opts, next) {
}, },
], ],
}, },
handler: departmentController.getSinledesginationData, handler: departmentController.getSinledepartmentData,
}); });
fastify.get("/api/getalldesginations", { fastify.get("/api/getalldepartments", {
schema: { schema: {
tags: ["Department"], tags: ["Department"],
description: "This is for Get all designation Data", description: "This is for Get all departments Data",
summary: "This is for to Get all designation Data", summary: "This is for to Get all departments Data",
security: [ security: [
{ {
@ -230,20 +233,20 @@ module.exports = function (fastify, opts, next) {
], ],
}, },
//preHandler: fastify.auth([fastify.authenticate]), //preHandler: fastify.auth([fastify.authenticate]),
handler: departmentController.getalldesgination, handler: departmentController.getalldepartments,
}); });
fastify.delete("/api/deletedesignation/:desginationId", { fastify.delete("/api/deletedepartment/:departmentId", {
schema: { schema: {
description: "Delete a desgination by desginationId", description: "Delete a Department by departmentId",
tags: ["Department"], tags: ["Department"],
summary: "Delete a user by desginationId", summary: "Delete a user by departmentId",
params: { params: {
type: "object", type: "object",
properties: { properties: {
desginationId: { type: "string" }, departmentId: { type: "string" },
}, },
required: ["desginationId"], required: ["departmentId"],
}, },
response: { response: {
200: { 200: {
@ -255,25 +258,28 @@ module.exports = function (fastify, opts, next) {
} }
} }
}, },
handler: departmentController.deletedesginationInfo, handler: departmentController.deletedepartmentInfo,
}); });
fastify.put('/api/editdesgination/:desginationId', { fastify.put('/api/editdesgination/:departmentId', {
schema: { schema: {
description: "Edit Desgination details by desginationId", description: "Edit Department details by departmentId",
tags: ["Department"], tags: ["Department"],
summary: "Edit Desgination details.", summary: "Edit Department details.",
params: { params: {
type: "object", type: "object",
properties: { properties: {
desginationId: { type: "string" }, departmentId: { type: "string" },
}, },
required: ["desginationId"], required: ["departmentId"],
}, },
body: { body: {
type: "object", type: "object",
properties: { properties: {
phone: { type: "string" }, phone: { type: "string" },
alternativeContactNumber: { type: "string" },
personalEmail: { type: "string" },
gender: { type: "string" },
city: { type: "string" }, city: { type: "string" },
state: { type: "string" }, state: { type: "string" },
country: { type: "string" }, country: { type: "string" },
@ -291,24 +297,44 @@ module.exports = function (fastify, opts, next) {
}, },
} }
}, },
handler: departmentController.editdesgination, handler: departmentController.editdepartment,
}); });
fastify.get("/api/getalldesignationsParticularFileds", { // fastify.get("/api/getalldesignationsParticularFileds", {
// schema: {
// tags: ["Department"],
// description: "This is for Get all Designation particular fileds",
// summary: "This is for to Get all Designation particular fields",
// security: [
// {
// basicAuth: [],
// },
// ],
// },
// //preHandler: fastify.auth([fastify.authenticate]),
// handler: departmentController.getAllDesignationsParticularFields,
// });
fastify.route({
method: "GET",
url: "/api/locations",
schema: { schema: {
tags: ["Department"], tags: ["Department"],
description: "This is for Get all Designation particular fileds", description: "Fetch locations by city and zone",
summary: "This is for to Get all Designation particular fields", summary: "Fetch locations by city and zone",
querystring: {
security: [ type: "object",
{ required: ["city", "zone"],
basicAuth: [], properties: {
city: { type: "string" },
zone: { type: "string" },
}, },
], },
}, },
//preHandler: fastify.auth([fastify.authenticate]), handler:departmentController.getZonebasedLocations
handler: departmentController.getAllDesignationsParticularFields,
}); });
next(); next();
}; };
Loading…
Cancel
Save