Merge pull request #886 from judsonjuniorr/fix/instance-validation

Validate if instance exists before deleting it
This commit is contained in:
Davidson Gomes 2024-09-17 07:28:27 -03:00 committed by GitHub
commit 17313d45f9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -64,7 +64,7 @@ export class WAMonitoringService {
throw new NotFoundException(`Instance "${instanceName}" not found`); throw new NotFoundException(`Instance "${instanceName}" not found`);
} }
const clientName = await this.configService.get<Database>('DATABASE').CONNECTION.CLIENT_NAME; const clientName = this.configService.get<Database>('DATABASE').CONNECTION.CLIENT_NAME;
const where = instanceName ? { name: instanceName, clientName } : { clientName }; const where = instanceName ? { name: instanceName, clientName } : { clientName };
@ -122,8 +122,7 @@ export class WAMonitoringService {
where: { name: instanceName }, where: { name: instanceName },
}); });
if (!findInstance) this.logger.error('Instance not found'); if (findInstance) {
const instance = await this.prismaRepository.instance.update({ const instance = await this.prismaRepository.instance.update({
where: { name: instanceName }, where: { name: instanceName },
data: { connectionStatus: 'close' }, data: { connectionStatus: 'close' },
@ -134,6 +133,7 @@ export class WAMonitoringService {
instanceDbId = instance.id; instanceDbId = instance.id;
await this.prismaRepository.session.deleteMany({ where: { sessionId: instance.id } }); await this.prismaRepository.session.deleteMany({ where: { sessionId: instance.id } });
} }
}
if (this.redis.REDIS.ENABLED && this.redis.REDIS.SAVE_INSTANCES) { if (this.redis.REDIS.ENABLED && this.redis.REDIS.SAVE_INSTANCES) {
await this.cache.delete(instanceName); await this.cache.delete(instanceName);