From 668f4772185c23fbed540e367d0a2fbe2d441206 Mon Sep 17 00:00:00 2001 From: Judson Cairo Date: Sat, 10 Aug 2024 23:15:02 -0300 Subject: [PATCH] Validate if session exists before deleting it --- .../services/channels/whatsapp.baileys.service.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/api/services/channels/whatsapp.baileys.service.ts b/src/api/services/channels/whatsapp.baileys.service.ts index 392afa17..21b528be 100644 --- a/src/api/services/channels/whatsapp.baileys.service.ts +++ b/src/api/services/channels/whatsapp.baileys.service.ts @@ -227,11 +227,16 @@ export class BaileysStartupService extends ChannelStartupService { this.client?.ws?.close(); - await this.prismaRepository.session.delete({ - where: { - sessionId: this.instanceId, - }, + const sessionExists = await this.prismaRepository.session.findFirst({ + where: { sessionId: this.instanceId }, }); + if (sessionExists) { + await this.prismaRepository.session.delete({ + where: { + sessionId: this.instanceId, + }, + }); + } } public async getProfileName() {