My http request is working but not doing it correctly

Joined
Oct 13, 2023
Messages
1
Reaction score
0
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.

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,708
Messages
2,569,347
Members
44,654
Latest member
7Jhamal74

Latest Threads

Top