Skip to content

Commit

Permalink
bug fix: delete instance - Closes #149
Browse files Browse the repository at this point in the history
  • Loading branch information
jrCleber committed Sep 4, 2024
1 parent 9a73494 commit 75b0801
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/whatsapp/controllers/instance.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/whatsapp/services/instance.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down

0 comments on commit 75b0801

Please sign in to comment.