I have a form that generates an object like this:
{
"documento": 1,
"origen": 0,
"descripcion": "FUAR y/o sol. ind. con huella(s) ilegible en el área de solicitud",
"resolucion": {
"campo": true,
"gabinete": false,
"resguardo": false
},
"clave": "a1"
}
I send this object to the function that performs the POST to my server, using axios , very simple, a message in the console and an alert, for the moment.
let _createCausa = (_causa) => axios.post(`${BASEURL}/causas`, _causa)
.then(_carga => {
console.log(_carga)
alert(`Se guardaron los siguientes datos: ${_carga.data.clave} - ${_carga.data.descripcion}`)
})
.catch(_error => {
console.log(_error.response.data)
})
The first thing the function does is send the data to the API (_causa) => axios.post(`${BASEURL}/causas`, _causa)
, but I would like that before axios.post()
the fields descripción
and clave
they will be passed to uppercase.
But how can I convert just those two fields or properties, before saving them?
Preferably keep functions as pure as possible, therefore avoid mutating parameters. Instead, you can clone it and override the desired properties on the clone:
You could call
toUpperCase()
on the propertiesdescripcion y clave
inside the function_createCausa
.For example: