Adding Event
$('#add-new-event').click(function (e) {
let add_event_id = add_event(event.text(val), currColor);
})
Store Event to DB using js async/await fetch
async function add_event(event, currColor) {
try {
let response = await fetch('/api/v1/events', {
body: JSON.stringify({
name: event[0].innerHTML,
color: currColor,
_token: token
})
});
const obj = await response.json();
return obj.data.id;
$('#add-new-event').click(function (e) {
let add_event_id = add_event(event.text(val), currColor);
let event_id;
add_event_id.then(function (responseValueID) {
event_id = responseValueID;
event.attr('id', 'event-' + event_id);
event.attr('data-event-id', event_id);
});
})