From 75b08011abb9e33ef4b7fcaa33efd508f614fb58 Mon Sep 17 00:00:00 2001 From: Cleber Wilson Date: Wed, 4 Sep 2024 10:34:17 -0300 Subject: [PATCH] bug fix: delete instance - Closes #149 --- src/whatsapp/controllers/instance.controller.ts | 5 +++-- src/whatsapp/services/instance.service.ts | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/whatsapp/controllers/instance.controller.ts b/src/whatsapp/controllers/instance.controller.ts index d9b3f31c..722815fd 100644 --- a/src/whatsapp/controllers/instance.controller.ts +++ b/src/whatsapp/controllers/instance.controller.ts @@ -207,13 +207,14 @@ export class InstanceController { } public async deleteInstance({ instanceName }: InstanceDto, force?: boolean) { - const stateConn = await this.connectionState({ instanceName }); - if (stateConn?.state === 'open') { + const instance = this.waMonitor.waInstances.get(instanceName); + if (instance && instance.getInstance()?.status?.state === 'open') { throw new BadRequestException([ 'Deletion failed', 'The instance needs to be disconnected', ]); } + const del = await this.instanceService.deleteInstance({ instanceName }, force); del['deletedAt'] = new Date(); return del; diff --git a/src/whatsapp/services/instance.service.ts b/src/whatsapp/services/instance.service.ts index 6215ff44..d1c18f2b 100644 --- a/src/whatsapp/services/instance.service.ts +++ b/src/whatsapp/services/instance.service.ts @@ -219,7 +219,7 @@ export class InstanceService { ]; } - delete this.waMonitor.waInstances[instance.instanceName]; + this.waMonitor.waInstances.delete(instance.instanceName); return await this.repository.instance.delete({ where: { name: instance.instanceName },