Instantly share code, notes, and snippets.

Embed
What would you like to do?
saveRealty = async () => {
try {
const {
realtyData: {
name,
address,
price,
location: {
latitude,
longitude
},
images
}
} = this.state;
const newRealtyResponse = await api.post('/properties', {
title: name,
address,
price,
latitude: Number(latitude.toFixed(6)),
longitude: Number(longitude.toFixed(6)),
});
const imagesData = new FormData();
images.forEach((image, index) => {
imagesData.append('image', {
uri: image.uri,
type: 'image/jpeg',
name: `${newRealtyResponse.data.title}_${index}.jpg`
});
});
await api.post(
`/properties/${newRealtyResponse.data.id}/images`,
imagesData,
);
this.getLocation()
this.handleDataModalClose()
this.setState({ newRealty: false });
} catch (err) {
console.tron.log(err);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment