I'm having problems trying to use a POST request in axios. I need to send an object to my backend, but it receives predefined values inside my function, so I can't send all my data. I tried in different ways and got different messages but I still couldn't find my error.
export function createUsers(user: userApi) {
user.pin = '001'
user.customFields = []
//@ts-ignore
user.admission_at = selectedDate.value
return axios.post('/users',{
...user,
admission_at: dateBr(user.admission_at)
})
}
In this first attempt when I send data, it ends up sending only the pre-defined values:
On the second try I only modified my return, but this time I send my object and it ignored my predefined values, like the "pin" for example. That way I didn't know how to format my date either, using "dateBr". I believe that the best way to send is the first one, but I need all the data
export function createUsers(user: userApi) {
user.pin = '001'
user.customFields = []
//@ts-ignore
user.admission_at = selectedDate.value
return axios.post('/users', user)
}
export interface userApi extends Record<string, unknown>{
customFields?: string[];
company?: number|string;
email: string;
password: string;
name: string;
admission_at: string;
cpf: string;
profession: string;
phone: string;
pin?: string;
enrollment: string;
department_id: string;
}