fix: Do not join field list of the field doesn't exists
This commit is contained in:
@@ -22,8 +22,10 @@ function join_field_list( obj_with_fields , list_of_fields )
|
||||
for(let field_idx=0; field_idx < list_of_fields.length; field_idx++){
|
||||
const field_name = list_of_fields[ field_idx ];
|
||||
const new_field_name = "_" + list_of_fields[ field_idx ];
|
||||
if( obj_with_fields[ field_name ] ){
|
||||
obj_with_fields[ new_field_name ] = obj_with_fields[field_name].join(", ");
|
||||
}
|
||||
}
|
||||
return obj_with_fields;
|
||||
}
|
||||
|
||||
@@ -195,7 +197,7 @@ const getUserLists = async(req, res) => {
|
||||
|
||||
data_list[i].name = name;
|
||||
data_list[i] = join_field_list( data_list[i] , ["categories","user_city","user_state","truck_type"] );
|
||||
let categories = data_list[i].categories.map( ( c ) => c.name);
|
||||
// let categories = data_list[i].categories.map( ( c ) => c.name);
|
||||
|
||||
/** Remove not requried fields */
|
||||
delete data_list[i].categories;
|
||||
@@ -212,7 +214,7 @@ const getUserLists = async(req, res) => {
|
||||
return res.status(200).send( retVal );
|
||||
} catch ( err ){
|
||||
console.error( err );
|
||||
return res.status(500).send({ error : "Public-Companies: Internal error" });
|
||||
return res.status(500).send({ error : "Companies: Internal error" });
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -21,8 +21,10 @@ function join_field_list( obj_with_fields , list_of_fields )
|
||||
for(let field_idx=0; field_idx < list_of_fields.length; field_idx++){
|
||||
const field_name = list_of_fields[ field_idx ];
|
||||
const new_field_name = "_" + list_of_fields[ field_idx ];
|
||||
if( obj_with_fields[ field_name ] ){
|
||||
obj_with_fields[ new_field_name ] = obj_with_fields[field_name].join(", ");
|
||||
}
|
||||
}
|
||||
return obj_with_fields;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user