From 57b32a99e79de03b6f720cb7c098389fc50dee66 Mon Sep 17 00:00:00 2001 From: adriano Date: Tue, 11 Apr 2023 17:17:17 -0300 Subject: [PATCH] =?UTF-8?q?Corre=C3=A7=C3=A3o=20na=20api=20de=20gerenciame?= =?UTF-8?q?nto=20de=20whatsapp=20para=20nao=20deletar=20sess=C3=A3o=20de?= =?UTF-8?q?=20outra=20aplica=C3=A7=C3=A3o=20caso=20tenha=20o=20mesmo=20id?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TEST_SERVER1/api/app.js | 32 ++++++++++++------- .../src/controllers/WbotMonitorController.ts | 2 +- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/TEST_SERVER1/api/app.js b/TEST_SERVER1/api/app.js index bc23bce..7d7c048 100644 --- a/TEST_SERVER1/api/app.js +++ b/TEST_SERVER1/api/app.js @@ -25,7 +25,11 @@ app.get('/', function (req, res) { return res.send('Express + TypeScript Server' app.post('/api/session', async function (req, res) { - const { app_name, whatsappId, client_url, number } = req.body + let { app_name, whatsappId, client_url, number } = req.body + + if(app_name){ + app_name = app_name.trim() + } console.log('__dirname: ', path.join(__dirname, '..', app_name)) @@ -39,7 +43,7 @@ app.post('/api/session', async function (req, res) { console.log('directoriesInDIrectory: ', directoriesInDIrectory) - const dirExist = directoriesInDIrectory.filter((e) => e == app_name) + const dirExist = directoriesInDIrectory.filter((e) => e.trim() == app_name) let dirSessionsApp = path.join(sessionsPath, app_name) @@ -75,7 +79,7 @@ app.post('/api/session', async function (req, res) { let whatsId = subDir[x].split('_')[0] - if (whatsId == whatsappId) { + if (whatsId == whatsappId && app_name == directoriesInDIrectory[i]) { let currPath = path.join(sessionsPath, directoriesInDIrectory[i], subDir[x]) @@ -138,6 +142,8 @@ app.post('/api/session', async function (req, res) { appPort.push(+subDir[x].split('_')[3]) + console.log('---------> appPort: '+appPort) + existSubDir = true } @@ -154,11 +160,11 @@ app.post('/api/session', async function (req, res) { let numberSession = 1 - const dirSessionsNumberAppDirectories = fs.readdirSync(dirSessionsApp, { withFileTypes: true }) - .filter((item) => item.isDirectory() && item.name.includes(`${number}`)) - .map((item) => item.name); + // const dirSessionsNumberAppDirectories = fs.readdirSync(dirSessionsApp, { withFileTypes: true }) + // .filter((item) => item.isDirectory() && item.name.includes(`${number}`)) + // .map((item) => item.name); - console.log('dirSessionsNumberAppDirectories', dirSessionsNumberAppDirectories, ' | dirSessionsApp: ', dirSessionsApp) + // console.log('dirSessionsNumberAppDirectories', dirSessionsNumberAppDirectories, ' | dirSessionsApp: ', dirSessionsApp) console.log('client_url: ', client_url) @@ -368,7 +374,11 @@ app.post('/api/session/edit', async function (req, res) { app.post('/api/session/del', async function (req, res) { - const { whatsappId, app_name } = req.body + let { whatsappId, app_name } = req.body + + if(app_name){ + app_name = app_name.trim() + } const sessionsPath = path.join(__dirname, '..', 'sessions') @@ -378,7 +388,7 @@ app.post('/api/session/del', async function (req, res) { console.log('directoriesInDIrectory: ', directoriesInDIrectory) - const dirExist = directoriesInDIrectory.filter((e) => e == app_name) + const dirExist = directoriesInDIrectory.filter((e) => e.trim() == app_name) console.log('dirExist: ', dirExist) @@ -400,7 +410,7 @@ app.post('/api/session/del', async function (req, res) { let whatsId = subDir[x].split('_')[0] - if (whatsId == whatsappId) { + if (whatsId == whatsappId && app_name == directoriesInDIrectory[i]) { let currPath = path.join(sessionsPath, directoriesInDIrectory[i], subDir[x]) @@ -410,7 +420,7 @@ app.post('/api/session/del', async function (req, res) { removeDir(currPath) - break + return res.send('ok') } diff --git a/backend/src/controllers/WbotMonitorController.ts b/backend/src/controllers/WbotMonitorController.ts index 294f2a5..b0e990e 100644 --- a/backend/src/controllers/WbotMonitorController.ts +++ b/backend/src/controllers/WbotMonitorController.ts @@ -43,7 +43,7 @@ export const wbotMonitorQrcodeRemote = async (req: Request, res: Response): Prom const { whatsappId } = req.body - console.log('-----------> whatsappId: ', req.body['whatsappId']) + console.log('-----------> QRCODE MONITOR whatsappId: ', req.body['whatsappId']) const whatsapp: any = await Whatsapp.findByPk(whatsappId, { raw: true }) // let whatsapp = await ShowWhatsAppService(whatsappId)