|
|
|
@ -60,7 +60,6 @@ const generateDepartmentId = async (city, departmentName) => {
|
|
|
|
|
return `AW${cityPrefix}${departmentPrefix}${result.seq}`; // Generate ID
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.addCity = async (request, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const {
|
|
|
|
@ -79,19 +78,27 @@ const generateDepartmentId = async (city, departmentName) => {
|
|
|
|
|
email
|
|
|
|
|
} = request.body;
|
|
|
|
|
|
|
|
|
|
// Generate departmentId based on departmentName
|
|
|
|
|
// const prefix = departmentName.substring(0, 2).toUpperCase(); // Extract first two letters and convert to uppercase
|
|
|
|
|
// Generate unique cityId
|
|
|
|
|
const c_id = await generateCityId();
|
|
|
|
|
const cityId = `AWCI${c_id}`;
|
|
|
|
|
|
|
|
|
|
// Check for existing records with specific fields
|
|
|
|
|
const existingPhone = await City.findOne({ phone });
|
|
|
|
|
if (existingPhone) {
|
|
|
|
|
return reply.status(400).send({ message: 'Phone number already exists' });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check for existing department
|
|
|
|
|
const existingStore = await City.findOne({ cityId });
|
|
|
|
|
if (existingStore) {
|
|
|
|
|
return reply.status(400).send({ message: 'City is already registered' });
|
|
|
|
|
const existingOfficeName = await City.findOne({ officeName });
|
|
|
|
|
if (existingOfficeName) {
|
|
|
|
|
return reply.status(400).send({ message: 'Office name already exists' });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create new department
|
|
|
|
|
const existingCityId = await City.findOne({ cityId });
|
|
|
|
|
if (existingCityId) {
|
|
|
|
|
return reply.status(400).send({ message: 'City ID already exists' });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create new city record
|
|
|
|
|
const citys = new City({
|
|
|
|
|
cityId,
|
|
|
|
|
phone,
|
|
|
|
@ -105,19 +112,19 @@ const generateDepartmentId = async (city, departmentName) => {
|
|
|
|
|
country,
|
|
|
|
|
pincode,
|
|
|
|
|
email,
|
|
|
|
|
// departmentName,
|
|
|
|
|
createdBy,
|
|
|
|
|
updatedBy,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await citys.save();
|
|
|
|
|
|
|
|
|
|
reply.send({ citys, message: 'Account Created Successfully' });
|
|
|
|
|
reply.send({ citys, message: 'City Created Successfully' });
|
|
|
|
|
} catch (err) {
|
|
|
|
|
reply.status(500).send({ message: err.message });
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.addBranch = async (request, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const {
|
|
|
|
|