Add delete logic

This commit is contained in:
Christopher Cookman 2025-10-25 10:21:46 -06:00
parent 1a430e1b4a
commit daceb05d52

View file

@ -33,7 +33,20 @@ const main = async () => {
}
}
}
console.log("Call forwards:", forwards);
// Search all forwards for any target that is between 700 and 800. If it exists, log to console and run `asterisk -x "database del CF[U/B] <ext>"` to delete it
for (const [key, target] of Object.entries(forwards)) {
const targetExt = parseInt(target, 10);
if (targetExt >= 700 && targetExt < 800) {
console.log(`Deleting forward ${key} to target ${target}`);
const delCommand = `asterisk -x "database del ${key.replace('/', ' ')}"`;
const { error, stdout, stderr } = await runAsterisk(delCommand);
if (error) {
console.error(`Error executing command "${delCommand}": ${error}`);
} else {
console.log(`Successfully deleted forward ${key}`);
}
}
} catch (err) {
console.error(`Unexpected error: ${err}`);
}