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 },