From f4e5eadea70228e24c6b8f656aa88784f86d49d5 Mon Sep 17 00:00:00 2001 From: James Nuanez Date: Fri, 24 Apr 2020 12:56:05 -0700 Subject: [PATCH] Delete applications: check if it is used by an account for device calls --- .../pages/internal/ApplicationsList.js | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/components/pages/internal/ApplicationsList.js b/src/components/pages/internal/ApplicationsList.js index 01ac666..faf2513 100644 --- a/src/components/pages/internal/ApplicationsList.js +++ b/src/components/pages/internal/ApplicationsList.js @@ -105,6 +105,31 @@ const ApplicationsList = () => { }); return; } + + // check if any account requires this application for SIP device calls + const accounts = await axios({ + method: 'get', + baseURL: process.env.REACT_APP_API_BASE_URL, + url: '/Accounts', + headers: { + Authorization: `Bearer ${localStorage.getItem('token')}`, + }, + }); + + const accountsRequiringThisApp = accounts.data.filter(acc => { + return acc.device_calling_application_sid === applicationToDelete.sid; + }); + + if (accountsRequiringThisApp.length) { + const accountName = accountsRequiringThisApp[0].name; + dispatch({ + type: 'ADD', + level: 'error', + message: `This application cannot be deleted because it is set to receive SIP Device Calls on account: ${accountName}`, + }); + return false; + } + await axios({ method: 'delete', baseURL: process.env.REACT_APP_API_BASE_URL,