I've been trying to use the http requests to update a status of a car, so that it will for example go from 'pending' to 'canceled'. I am using patch because I do not want to update all data but only statusId.
But what is strange, is that it deletes the car, and I do not get any errors. Why, as I know patch updates partial data, and shouldn't delete?
I also have a website, where I have admin panel, and it is working there, no problem with the backend API.
Here's how my button is implemented:
I am not getting any errors, it just deletes my car.
Any ideas?
But what is strange, is that it deletes the car, and I do not get any errors. Why, as I know patch updates partial data, and shouldn't delete?
I also have a website, where I have admin panel, and it is working there, no problem with the backend API.
JavaScript:
useEffect(() => {
const getToken = async () => {
const as = useSecureStorage('AccessToken');
const token = await as.getItem();
setToken(token || '');
setLoadingProcess(false);
};
getToken();
}, []);
const handleCancelCar = async () => {
try {
setSubmitting(true);
const as = await asStorage.getItem();
const app = await client.tokenClient();
const updateDto: UpdateStatus = {
statusId: 989,
};
const response = await app!.patch(
`/car/${id}/status/`,
updateDto,
);
if (response.status === 200) {
console.log('Updated car status');
} else {
console.log('Failed to update car status');
}
} catch (error) {
console.log({ error });
}
};
Here's how my button is implemented:
JavaScript:
<Button
backgroundColor={Colors.red40}
source={{
uri: uri + '',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
Authorization: token ? `Bearer ${token}` : '',
},
}}
onPress={handleCancelCar}
>
<TouchableOpacity style={{ flexDirection: 'row', alignItems: 'center' }}>
<Text text65 white style={{ fontWeight: '700', marginLeft: 10 }}>
{t('Cancel Car')}
</Text>
</TouchableOpacity>
</Button>
I am not getting any errors, it just deletes my car.
Any ideas?