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,17 +122,17 @@ 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({
where: { name: instanceName },
data: { connectionStatus: 'close' },
});
const instance = await this.prismaRepository.instance.update({ rmSync(join(INSTANCE_DIR, instance.id), { recursive: true, force: true });
where: { name: instanceName },
data: { connectionStatus: 'close' },
});
rmSync(join(INSTANCE_DIR, instance.id), { recursive: true, force: true }); instanceDbId = instance.id;
await this.prismaRepository.session.deleteMany({ where: { sessionId: instance.id } });
instanceDbId = 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) {