I have a doubt about how the code should be arranged professionally, I ask this question because I feel that in the functions I am repeating the try catch a lot and I feel that the base structure is very simple in each function, but I don't know if Is this correct or is there a cleaner/professional way to do such code.
If it is necessary to accommodate it in various files and even folders, it would be very helpful if you could mention it to me.
const axios = require('axios')
const url = 'http://localhost:59692/'
async function getAllAppointments() {
try {
const res = await axios.get(`${url}Appointments`)
return res
} catch (error) {
return error
}
}
async function getOfficeAppintments(idoffice) {
try {
const res = await axios.get(
`${url}Appointments/OfficeLogin?idoffice=${idoffice}`
)
return res
} catch (error) {
return error
}
}
async function postAppointment(object) {
try {
const res = await axios.post(`${url}Appointmets`, object)
return res
} catch (error) {
return error
}
}
async function putAppointment(id) {
try {
const res = await axios.post(`${url}Appointmets/${id}`, object)
return res
} catch (error) {
return error
}
}
async function getInfoQuote(quoteNumber) {
try {
const res = await axios.get(`${url}ITC/Quote/${quoteNumber}`)
return res
} catch (error) {
return error
}
}
module.exports = {
getAllAppointments,
getOfficeAppintments,
postAppointment,
putAppointment,
getInfoQuote,
}
I would do something like this:
and then I would call each function rebuilding variable