Company profile bug fixed
This commit is contained in:
parent
41bbc2ca6f
commit
4c65cece11
@ -104,16 +104,38 @@ exports.createEstablishment = async (req, res) => {
|
||||
establishment_products
|
||||
} = req.body;
|
||||
|
||||
|
||||
// Basic Validation
|
||||
if (!establishment_code || !factory_name || !establishment_user) {
|
||||
if (!establishment_code) {
|
||||
return res.status(400).send({
|
||||
status: "failed",
|
||||
message: "Missing required fields: establishment_code, factory_name, email, establishment_user",
|
||||
message: "Missing required field: Unique License Number",
|
||||
});
|
||||
}
|
||||
|
||||
if (!establishment_city_town_id || !corporate_city_town_id) {
|
||||
if (!establishment_user.name) {
|
||||
return res.status(400).send({
|
||||
status: "failed",
|
||||
message: "User Profile: Name is required",
|
||||
});
|
||||
}
|
||||
if (!establishment_user.email) {
|
||||
return res.status(400).send({
|
||||
status: "failed",
|
||||
message: "User Profile: Email is required",
|
||||
});
|
||||
}
|
||||
if (!factory_name) {
|
||||
return res.status(400).send({
|
||||
status: "failed",
|
||||
message: "Establishment Contact Details: Name is required",
|
||||
});
|
||||
}
|
||||
if (!establishment_emirate_id) {
|
||||
return res.status(400).send({
|
||||
status: "failed",
|
||||
message: "Missing required field: Emirate",
|
||||
});
|
||||
}
|
||||
if (!establishment_city_town_id) {
|
||||
return res.status(400).send({
|
||||
status: "failed",
|
||||
message: "Missing required field: city/town",
|
||||
@ -125,6 +147,12 @@ exports.createEstablishment = async (req, res) => {
|
||||
message: "Missing required field: Industry Code (Current Production)",
|
||||
});
|
||||
}
|
||||
if (!corporate_email) {
|
||||
return res.status(400).send({
|
||||
status: "failed",
|
||||
message: "Establishment Contact Details: Email is required",
|
||||
});
|
||||
}
|
||||
if (!Array.isArray(establishment_products) || establishment_products.length === 0) {
|
||||
return res.status(400).send({
|
||||
status: "failed",
|
||||
@ -559,7 +587,17 @@ exports.updateEstablishment = async (req, res) => {
|
||||
});
|
||||
|
||||
const { id } = req.params;
|
||||
const { establishment_products, establishment_user, ...estData } = req.body;
|
||||
const {
|
||||
establishment_products,
|
||||
establishment_user,
|
||||
establishment_code,
|
||||
factory_name,
|
||||
establishment_emirate_id,
|
||||
establishment_city_town_id,
|
||||
industry_code_production,
|
||||
corporate_email,
|
||||
...estData
|
||||
} = req.body;
|
||||
const user = await EstablishmentUser.findOne({where:{establishment_id:id}});
|
||||
|
||||
const resolveActionDoneBy = (item) => {
|
||||
@ -574,6 +612,69 @@ exports.updateEstablishment = async (req, res) => {
|
||||
return res.status(404).json({ status: "failed", message: "Record not found" });
|
||||
}
|
||||
|
||||
if (establishment_code !== undefined && !establishment_code) {
|
||||
return res.status(400).json({
|
||||
status: "failed",
|
||||
message: "Missing required field: Unique License Number",
|
||||
});
|
||||
}
|
||||
|
||||
// establishment_user validation
|
||||
if (establishment_user) {
|
||||
if (!establishment_user.name) {
|
||||
return res.status(400).json({
|
||||
status: "failed",
|
||||
message: "User Profile: Name is required",
|
||||
});
|
||||
}
|
||||
|
||||
if (!establishment_user.email) {
|
||||
return res.status(400).json({
|
||||
status: "failed",
|
||||
message: "User Profile: Email is required",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// factory name
|
||||
if (factory_name !== undefined && !factory_name) {
|
||||
return res.status(400).json({
|
||||
status: "failed",
|
||||
message: "Establishment Contact Details: Name is required",
|
||||
});
|
||||
}
|
||||
|
||||
// emirate
|
||||
if (establishment_emirate_id !== undefined && !establishment_emirate_id) {
|
||||
return res.status(400).json({
|
||||
status: "failed",
|
||||
message: "Missing required field: Emirate",
|
||||
});
|
||||
}
|
||||
|
||||
// city / town
|
||||
if (establishment_city_town_id !== undefined && !establishment_city_town_id) {
|
||||
return res.status(400).json({
|
||||
status: "failed",
|
||||
message: "Missing required field: City/Town",
|
||||
});
|
||||
}
|
||||
|
||||
// industry code production
|
||||
if (industry_code_production !== undefined && !industry_code_production) {
|
||||
return res.status(400).json({
|
||||
status: "failed",
|
||||
message: "Missing required field: Industry Code (Current Production)",
|
||||
});
|
||||
}
|
||||
|
||||
// corporate email
|
||||
if (corporate_email !== undefined && !corporate_email) {
|
||||
return res.status(400).json({
|
||||
status: "failed",
|
||||
message: "Establishment Contact Details: Email is required",
|
||||
});
|
||||
}
|
||||
// check duplicate establishment_code
|
||||
if (estData.establishment_code) {
|
||||
const exists = await Establishment.findOne({
|
||||
@ -583,7 +684,7 @@ exports.updateEstablishment = async (req, res) => {
|
||||
return res.status(400).json({ status:"failed", message:"establishment_code already exists" });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
estData.updated_by = estData.updated_by || req.user.id;
|
||||
estData.updated_at = estData.updated_at || new Date();
|
||||
// update establishment
|
||||
|
||||
Loading…
Reference in New Issue
Block a user