Skip to content

Commit 23640a7

Browse files
committed
fix: fetch instances
1 parent fce3e55 commit 23640a7

File tree

3 files changed

+21
-14
lines changed

3 files changed

+21
-14
lines changed

src/api/controllers/instance.controller.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,9 @@ export class InstanceController {
382382
return this.waMonitor.instanceInfoById(instanceId, number);
383383
}
384384

385-
return this.waMonitor.instanceInfo([instanceName]);
385+
const instanceNames = instanceName ? [instanceName] : null;
386+
387+
return this.waMonitor.instanceInfo(instanceNames);
386388
}
387389

388390
public async setPresence({ instanceName }: InstanceDto, data: SetPresenceDto) {

src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1762,7 +1762,8 @@ export class BaileysStartupService extends ChannelStartupService {
17621762
website: business?.website?.shift(),
17631763
};
17641764
} else {
1765-
const info: Instance = await waMonitor.instanceInfo([instanceName]);
1765+
const instanceNames = instanceName ? [instanceName] : null;
1766+
const info: Instance = await waMonitor.instanceInfo(instanceNames);
17661767
const business = await this.fetchBusinessProfile(jid);
17671768

17681769
return {

src/api/services/monitor.service.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,23 +60,25 @@ export class WAMonitoringService {
6060
}
6161

6262
public async instanceInfo(instanceNames?: string[]): Promise<any> {
63-
const inexistentInstances = instanceNames ? instanceNames.filter((instance) => !this.waInstances[instance]) : [];
63+
if (instanceNames && instanceNames.length > 0) {
64+
const inexistentInstances = instanceNames ? instanceNames.filter((instance) => !this.waInstances[instance]) : [];
6465

65-
if (inexistentInstances.length > 0) {
66-
throw new NotFoundException(
67-
`Instance${inexistentInstances.length > 1 ? 's' : ''} "${inexistentInstances.join(', ')}" not found`,
68-
);
66+
if (inexistentInstances.length > 0) {
67+
throw new NotFoundException(
68+
`Instance${inexistentInstances.length > 1 ? 's' : ''} "${inexistentInstances.join(', ')}" not found`,
69+
);
70+
}
6971
}
7072

7173
const clientName = this.configService.get<Database>('DATABASE').CONNECTION.CLIENT_NAME;
7274

73-
const where = instanceNames
75+
const where = instanceNames && instanceNames.length > 0
7476
? {
75-
name: {
76-
in: instanceNames,
77-
},
78-
clientName,
79-
}
77+
name: {
78+
in: instanceNames,
79+
},
80+
clientName,
81+
}
8082
: { clientName };
8183

8284
const instances = await this.prismaRepository.instance.findMany({
@@ -123,7 +125,9 @@ export class WAMonitoringService {
123125
throw new NotFoundException(`Instance "${instanceName}" not found`);
124126
}
125127

126-
return this.instanceInfo([instanceName]);
128+
const instanceNames = instanceName ? [instanceName] : null;
129+
130+
return this.instanceInfo(instanceNames);
127131
}
128132

129133
public async cleaningUp(instanceName: string) {

0 commit comments

Comments
 (0)