Add ability to delete product
This commit is contained in:
parent
eb53bd1056
commit
6ff920c322
|
@ -42,6 +42,9 @@ const execute = async (interaction) => {
|
||||||
case "category":
|
case "category":
|
||||||
await interaction.user.send({ content: "Please provide a new category for the product. Say `cancel` to exit. Set to `~none` to remove." });
|
await interaction.user.send({ content: "Please provide a new category for the product. Say `cancel` to exit. Set to `~none` to remove." });
|
||||||
break;
|
break;
|
||||||
|
case "delete":
|
||||||
|
await interaction.user.send({ content: "Are you sure you want to delete this product? This action is irreversible, and all buyees will lose access to the file forever! Type `confirm` to delete, or `cancel` to exit." });
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return interaction.editReply({ content: "Invalid field provided.", ephemeral: true });
|
return interaction.editReply({ content: "Invalid field provided.", ephemeral: true });
|
||||||
}
|
}
|
||||||
|
|
|
@ -132,6 +132,50 @@ const execute = async (message) => {
|
||||||
await pool.query('UPDATE products SET category = ? WHERE id = ?', [newCategory, global.productUpdateData[message.author.id].id]);
|
await pool.query('UPDATE products SET category = ? WHERE id = ?', [newCategory, global.productUpdateData[message.author.id].id]);
|
||||||
message.channel.send('Category updated!');
|
message.channel.send('Category updated!');
|
||||||
break;
|
break;
|
||||||
|
case "delete": // Delete
|
||||||
|
if (message.content.toLowerCase() === 'cancel') {
|
||||||
|
cancel(message.author);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (message.content.toLowerCase() !== 'confirm') {
|
||||||
|
message.channel.send('You must type `confirm` to delete the product, or `cancel` to exit.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Proceed with deletion
|
||||||
|
message.channel.send('Deletion Confirmed. Starting deletion process...').then(async msg => {
|
||||||
|
let curMsg = msg.content;
|
||||||
|
// Delete fileAuth
|
||||||
|
curMsg = curMsg + '\nDeleting file authorizations...'
|
||||||
|
await msg.edit(curMsg);
|
||||||
|
await pool.query('DELETE FROM fileAuth WHERE product = ?', [global.productUpdateData[message.author.id].id]);
|
||||||
|
// Delete file
|
||||||
|
curMsg = curMsg + '\nDeleting product file...'
|
||||||
|
await msg.edit(curMsg);
|
||||||
|
const [product] = await pool.query('SELECT file FROM products WHERE id = ?', [global.productUpdateData[message.author.id].id]);
|
||||||
|
if (product) {
|
||||||
|
const safeFileId = path.basename(product.file);
|
||||||
|
const filePath = path.join(__dirname, '../productFiles', safeFileId); // Code we use in the CDN route
|
||||||
|
if (fs.existsSync(filePath)) {
|
||||||
|
fs.unlinkSync(filePath);
|
||||||
|
curMsg = curMsg + `\nDeleted file: ${safeFileId}`;
|
||||||
|
await msg.edit(curMsg);
|
||||||
|
} else {
|
||||||
|
curMsg = curMsg + `\nFile not found (skipping): ${safeFileId}`;
|
||||||
|
await msg.edit(curMsg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Delete purchases
|
||||||
|
curMsg = curMsg + '\nDeleting purchases...';
|
||||||
|
await msg.edit(curMsg);
|
||||||
|
await pool.query('DELETE FROM purchases WHERE productId = ?', [global.productUpdateData[message.author.id].id]);
|
||||||
|
// Delete product
|
||||||
|
curMsg = curMsg + '\nDeleting product...';
|
||||||
|
await msg.edit(curMsg);
|
||||||
|
await pool.query('DELETE FROM products WHERE id = ?', [global.productUpdateData[message.author.id].id]);
|
||||||
|
curMsg = curMsg + '\nProduct deletion complete.';
|
||||||
|
await msg.edit(curMsg);
|
||||||
|
});
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
message.channel.send('Invalid type. Somehow?');
|
message.channel.send('Invalid type. Somehow?');
|
||||||
cancel(message.author);
|
cancel(message.author);
|
||||||
|
|
Loading…
Reference in a new issue