|
|
@ -10,7 +10,7 @@ const fastify = require("fastify")({
|
|
|
|
});
|
|
|
|
});
|
|
|
|
const { Counter} = require('../models/User')
|
|
|
|
const { Counter} = require('../models/User')
|
|
|
|
|
|
|
|
|
|
|
|
const {Department, Desgination, City, Deparments, Branch} = require('../models/Department')
|
|
|
|
const {Department, Desgination, City, Deparments, Branch, Zone} = 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' },
|
|
|
@ -175,6 +175,46 @@ const generateDepartmentId = async (city, departmentName) => {
|
|
|
|
reply.status(500).send({ message: err.message });
|
|
|
|
reply.status(500).send({ message: err.message });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.addZone = async (request, reply) => {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
const {
|
|
|
|
|
|
|
|
officeName,
|
|
|
|
|
|
|
|
location,
|
|
|
|
|
|
|
|
city,
|
|
|
|
|
|
|
|
zone,
|
|
|
|
|
|
|
|
createdBy,
|
|
|
|
|
|
|
|
updatedBy,
|
|
|
|
|
|
|
|
} = request.body;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Generate departmentId based on departmentName
|
|
|
|
|
|
|
|
// const prefix = departmentName.substring(0, 2).toUpperCase(); // Extract first two letters and convert to uppercase
|
|
|
|
|
|
|
|
const b_id = await generateBranchId();
|
|
|
|
|
|
|
|
const zoneId = `AWZN${b_id}`;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check for existing department
|
|
|
|
|
|
|
|
const existingStore = await Zone.findOne({ zoneId });
|
|
|
|
|
|
|
|
if (existingStore) {
|
|
|
|
|
|
|
|
return reply.status(400).send({ message: 'Branch is already registered' });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const zones = new Zone({
|
|
|
|
|
|
|
|
zoneId,
|
|
|
|
|
|
|
|
officeName,
|
|
|
|
|
|
|
|
location,
|
|
|
|
|
|
|
|
city,
|
|
|
|
|
|
|
|
zone,
|
|
|
|
|
|
|
|
createdBy,
|
|
|
|
|
|
|
|
updatedBy,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await zones.save();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
reply.send({ zones, message: 'Account Created Successfully' });
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
|
|
reply.status(500).send({ message: err.message });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
// exports.getSinledepartmentData = async (req, reply) => {
|
|
|
|
// exports.getSinledepartmentData = async (req, reply) => {
|
|
|
|
// try {
|
|
|
|
// try {
|
|
|
|
// const { departmentId } = req.params;
|
|
|
|
// const { departmentId } = req.params;
|
|
|
|