create new zone account

master^2
Bhaskar 8 months ago
parent 4eb56f3466
commit e1893e5b91

@ -10,7 +10,7 @@ const fastify = require("fastify")({
});
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 result = await Counter.findOneAndUpdate(
// { _id: 'department_id' },
@ -175,6 +175,46 @@ const generateDepartmentId = async (city, departmentName) => {
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) => {
// try {
// const { departmentId } = req.params;

@ -73,6 +73,31 @@ const citySchema = new mongoose.Schema(
{ versionKey: false }
);
const zoneSchema = new mongoose.Schema(
{
zoneId:{type:String},
officeName: { type: String },
zone: { type: String , default: "ALL"},
city: { type: String },
location: [{ type : String}],
createdAt: {
type: Date,
default: function () {
return Date.now();
},
},
createdBy: ObjectId,
updatedAt: {
type: Date,
default: function () {
return Date.now();
},
},
updatedBy: ObjectId,
},
{ versionKey: false }
);
const departmentsSchema = new mongoose.Schema(
{
departmentId:{type:String},
@ -162,8 +187,9 @@ const citySchema = new mongoose.Schema(
const City = mongoose.model('City', citySchema);
const Deparments = mongoose.model('Deparments', departmentsSchema);
const Branch = mongoose.model('Branch', branchSchema);
const Zone = mongoose.model('Zone', zoneSchema);
const TeamMemberProfilePicture = mongoose.model('TeamMemberProfilePicture', teamMemberProfilePictureSchema);
const CompanyProfilePicture = mongoose.model('CompanyProfilePicture', companyProfilePictureSchema);
module.exports = { City,Deparments,Branch,TeamMemberProfilePicture,CompanyProfilePicture};
module.exports = { City,Deparments,Branch,TeamMemberProfilePicture,CompanyProfilePicture,Zone};

@ -518,6 +518,34 @@ module.exports = function (fastify, opts, next) {
handler: departmentController.addBranch,
});
fastify.route({
method: "POST",
url: "/api/zoneSignup",
schema: {
tags: ["Department"],
description: "This is for creating a new Zone account",
summary: "This is for creating a new Zone account",
body: {
type: "object",
properties: {
city: { type: "string" },
officeName: { type: "string" },
location: {
type: "array",
items: { type: "string" },
},
zone: { type: "string" },
},
},
security: [
{
basicAuth: [],
},
],
},
handler: departmentController.addZone,
});
fastify.delete("/api/deletebranch/:branchId", {
schema: {
description: "Delete a city by branchId",

Loading…
Cancel
Save