Skip to content

Commit 3a0487a

Browse files
Merge pull request #2 from EvolutionAPI/fix-fetch-instances
Fix fetch instances
2 parents fc231c8 + 35787bf commit 3a0487a

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

src/api/controllers/instance.controller.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,8 @@ export class InstanceController {
275275
return this.waMonitor.instanceInfoById(instanceId, number);
276276
}
277277

278-
return this.waMonitor.instanceInfo();
278+
const instanceNames = instanceName ? [instanceName] : null;
279+
return this.waMonitor.instanceInfo(instanceNames);
279280
}
280281

281282
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
@@ -1410,7 +1410,8 @@ export class BaileysStartupService extends ChannelStartupService {
14101410
website: business?.website?.shift(),
14111411
};
14121412
} else {
1413-
const info: Instance = await waMonitor.instanceInfo([instanceName]);
1413+
const instanceNames = instanceName ? [instanceName] : null;
1414+
const info: Instance = await waMonitor.instanceInfo(instanceNames);
14141415
const business = await this.fetchBusinessProfile(jid);
14151416

14161417
return {

src/api/services/monitor.service.ts

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,24 +58,27 @@ export class WAMonitoringService {
5858
}
5959

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

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

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

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

8083
const instances = await this.prismaRepository.instance.findMany({
8184
where,
@@ -121,7 +124,8 @@ export class WAMonitoringService {
121124
throw new NotFoundException(`Instance "${instanceName}" not found`);
122125
}
123126

124-
return this.instanceInfo([instanceName]);
127+
const instanceNames = instanceName ? [instanceName] : null;
128+
return this.instanceInfo(instanceNames);
125129
}
126130

127131
public async cleaningUp(instanceName: string) {

0 commit comments

Comments
 (0)