Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
onDelete(row) {
if (window.confirm(`Remove ${row.game.name} from your library?`)) {
// Post a delete request to the game purchase endpoint to delete the game.
fetch(row.url, {
method: 'DELETE',
headers: {
'X-CSRF-Token': Rails.csrfToken(),
Accept: 'application/json'
},
credentials: 'same-origin'
}).then(response => {
if (response.ok) {
// Emit a delete event to force the parent library component to
// refresh.
this.$emit('delete');
}
});
}
},
loadGames() {
removeGameFromLibrary() {
let removeGameFromLibraryPath = `/games/${this.gameId}/remove_game_from_library`;
fetch(removeGameFromLibraryPath, {
method: 'DELETE',
headers: {
'X-CSRF-Token': Rails.csrfToken(),
Accept: 'application/json'
},
credentials: 'same-origin'
}).then(response => {
if (response.ok) {
Turbolinks.visit(window.location.href);
}
});
},
onSubmit() {
static async rawAuthenticatedFetch(route: string, method: string, body: string|null = null): Promise {
let requestBody : RequestInit = {
method: method,
headers: {
'Content-Type': 'application/json',
'X-CSRF-Token': Rails.csrfToken(),
Accept: 'application/json'
},
credentials: 'same-origin'
};
if (body !== null) {
requestBody.body = body;
}
return fetch(route, requestBody);
}