0

This is the scenario where I am storing several attributes into the database. Now, while I fetch the response I don't want the exact attribute name what's already stored in Db. For eg, below is my code. Here, I have stored fields as 'ca_xyz'.Now while fetching the response I want only only 'xyz' as fieldname. Can anyone help me?

// --------adding customer group--------

const addCustomerGroup = async(req,res,next) => {
    try{
        console.log(req.body)
        
         let data = await Group.create({
             cg_name:req.body.name,
             cg_description:req.body.description,
             cg_is_active: req.body.is_ctive,
             cg_created_by: req.body.created_by,
             cg_modified_by: req.body.modified_by
                  })

        var newData = {};

        for (const [key, value] of Object.entries(data)) {
        newData[key.substr("cg_".length)] = value;
            }  
        console.log(newData)
         res.send({
             status:"success",
             message:"Added customer group"
         })
    }
    catch(error){
        console.log(error)
        res.send({
            status:"failed",
            message:"An error occurred"
        })
    }
}

0 Answers0