Fix settings logic
This commit is contained in:
parent
8d914e38d0
commit
c9c0129eaa
|
@ -150,13 +150,16 @@ const execute = async (message) => {
|
|||
return;
|
||||
}
|
||||
message.channel.send('Deletion Confirmed. Starting deletion process...').then(async msg => {
|
||||
curMsg = msg.content;
|
||||
// Proceed with deletion
|
||||
const hubId = global.hubSettingsHandlers[message.author.id].hub;
|
||||
// Delete fileAuth
|
||||
msg.edit(msg.content + '\nDeleting file authorizations...');
|
||||
curMsg = curMsg + '\nDeleting file authorizations...'
|
||||
await msg.edit(curMsg);
|
||||
await pool.query('DELETE FROM fileAuth WHERE product IN (SELECT id FROM products WHERE hubId = ?)', [hubId]);
|
||||
// Delete files
|
||||
msg.edit(msg.content + '\nDeleting product files...');
|
||||
curMsg = curMsg + '\nDeleting product files...'
|
||||
await msg.edit(curMsg);
|
||||
// const safeFileId = path.basename(product.file);
|
||||
// const filePath = path.join(__dirname, '../productFiles', safeFileId); // Code we use in the CDN route
|
||||
const files = await pool.query('SELECT file FROM products WHERE hubId = ?', [hubId]);
|
||||
|
@ -165,22 +168,28 @@ const execute = async (message) => {
|
|||
const filePath = path.join(__dirname, '../productFiles', safeFileId); // Code we use in the CDN route
|
||||
if (fs.existsSync(filePath)) {
|
||||
fs.unlinkSync(filePath);
|
||||
msg.edit(msg.content + `\nDeleted file: ${safeFileId}`);
|
||||
curMsg = curMsg + `\nDeleted file: ${safeFileId}`;
|
||||
await msg.edit(curMsg);
|
||||
} else {
|
||||
msg.edit(msg.content + `\nFile not found, skipping: ${safeFileId}`);
|
||||
curMsg = curMsg + `\nFile not found (skipping): ${safeFileId}`;
|
||||
await msg.edit(curMsg);
|
||||
}
|
||||
}
|
||||
|
||||
// Delete purchases
|
||||
msg.edit(msg.content + '\nDeleting purchases...');
|
||||
curMsg = curMsg + '\nDeleting purchases...';
|
||||
await msg.edit(curMsg);
|
||||
await pool.query('DELETE FROM purchases WHERE productId IN (SELECT id FROM products WHERE hubId = ?)', [hubId]);
|
||||
// Delete products
|
||||
msg.edit(msg.content + '\nDeleting products...');
|
||||
curMsg = curMsg + '\nDeleting products...';
|
||||
await msg.edit(curMsg);
|
||||
await pool.query('DELETE FROM products WHERE hubId = ?', [hubId]);
|
||||
// Delete hub
|
||||
msg.edit(msg.content + '\nDeleting hub...');
|
||||
curMsg = curMsg + '\nDeleting hub...';
|
||||
await msg.edit(curMsg);
|
||||
await pool.query('DELETE FROM hubs WHERE id = ?', [hubId]);
|
||||
msg.edit(msg.content + '\nDeletion process complete.');
|
||||
curMsg = curMsg + '\nHub and all associated data deleted successfully.';
|
||||
await msg.edit(curMsg);
|
||||
cancel(message.author);
|
||||
});
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue