async function ajaxRequest(url, method, data) {
    const options = {
        url: url,
        method: method,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("X-CSRFToken", CSRF_MiddlewareToken);
        }
    }
    
    if (data) {
        options.data = data;
        options.processData = false;
        options.contentType = false;
    }

    try {
        const response = await $.ajax(options);
        return response
    }
    catch (error) {
        return error
    }
}

// Venues

async function getVenues() {
    const url = `/api/venue/`;
    return await ajaxRequest(url, "GET");
}

async function getVenue(id) {
    return await ajaxRequest(`/api/venue/${id}/`, "GET");
}

async function newVenue(formData) {
    return await ajaxRequest("/api/venue/", "POST", formData);
}

async function deleteVenue(id) {
    return await ajaxRequest(`/api/venue/${id}/`, "DELETE");
}

async function editVenue(id, formData) {
    return await ajaxRequest(`/api/venue/${id}/`, "PUT", formData);
}