Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
onDelete() {
if (
window.confirm(
`Remove ${this.gameInLibrary.game.name} from your library?`
)
) {
// Post a delete request to the game purchase endpoint to delete the game.
fetch(this.gameInLibrary.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');
}
});
}
}
},
let platform_id = this.release.platform.id;
let developer_ids = Array.from(this.release.developers, developer => developer.id);
let publisher_ids = Array.from(this.release.publishers, publisher => publisher.id);
fetch(this.submitPath, {
method: this.create ? 'POST' : 'PUT',
body: JSON.stringify({ release: {
name: this.release.name,
description: this.release.description,
game_id: game_id,
platform_id: platform_id,
developer_ids: developer_ids,
publisher_ids: publisher_ids
}}),
headers: {
'Content-Type': 'application/json',
'X-CSRF-Token': Rails.csrfToken()
},
credentials: 'same-origin'
}).then(function(response) {
if (!response.ok) {
throw Error(response.statusText);
}
return response;
}).then(function(data) {
Turbolinks.visit(data.url);
}).catch(function(error) {
console.log(error);
});
}
}