Skip to content

Commit 17313d4

Browse files
Merge pull request #886 from judsonjuniorr/fix/instance-validation
Validate if instance exists before deleting it
2 parents 9a1d566 + 6b447c6 commit 17313d4

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/api/services/monitor.service.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export class WAMonitoringService {
6464
throw new NotFoundException(`Instance "${instanceName}" not found`);
6565
}
6666

67-
const clientName = await this.configService.get<Database>('DATABASE').CONNECTION.CLIENT_NAME;
67+
const clientName = this.configService.get<Database>('DATABASE').CONNECTION.CLIENT_NAME;
6868

6969
const where = instanceName ? { name: instanceName, clientName } : { clientName };
7070

@@ -122,17 +122,17 @@ export class WAMonitoringService {
122122
where: { name: instanceName },
123123
});
124124

125-
if (!findInstance) this.logger.error('Instance not found');
126-
127-
const instance = await this.prismaRepository.instance.update({
128-
where: { name: instanceName },
129-
data: { connectionStatus: 'close' },
130-
});
125+
if (findInstance) {
126+
const instance = await this.prismaRepository.instance.update({
127+
where: { name: instanceName },
128+
data: { connectionStatus: 'close' },
129+
});
131130

132-
rmSync(join(INSTANCE_DIR, instance.id), { recursive: true, force: true });
131+
rmSync(join(INSTANCE_DIR, instance.id), { recursive: true, force: true });
133132

134-
instanceDbId = instance.id;
135-
await this.prismaRepository.session.deleteMany({ where: { sessionId: instance.id } });
133+
instanceDbId = instance.id;
134+
await this.prismaRepository.session.deleteMany({ where: { sessionId: instance.id } });
135+
}
136136
}
137137

138138
if (this.redis.REDIS.ENABLED && this.redis.REDIS.SAVE_INSTANCES) {

0 commit comments

Comments
 (0)