Skip to content

Commit

Permalink
Merge pull request #2 from EvolutionAPI/fix-fetch-instances
Browse files Browse the repository at this point in the history
Fix fetch instances
  • Loading branch information
DavidsonGomes authored Jan 10, 2025
2 parents fc231c8 + 35787bf commit 3a0487a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
3 changes: 2 additions & 1 deletion src/api/controllers/instance.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,8 @@ export class InstanceController {
return this.waMonitor.instanceInfoById(instanceId, number);
}

return this.waMonitor.instanceInfo();
const instanceNames = instanceName ? [instanceName] : null;
return this.waMonitor.instanceInfo(instanceNames);
}

public async setPresence({ instanceName }: InstanceDto, data: SetPresenceDto) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1410,7 +1410,8 @@ export class BaileysStartupService extends ChannelStartupService {
website: business?.website?.shift(),
};
} else {
const info: Instance = await waMonitor.instanceInfo([instanceName]);
const instanceNames = instanceName ? [instanceName] : null;
const info: Instance = await waMonitor.instanceInfo(instanceNames);
const business = await this.fetchBusinessProfile(jid);

return {
Expand Down
32 changes: 18 additions & 14 deletions src/api/services/monitor.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,24 +58,27 @@ export class WAMonitoringService {
}

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

if (inexistentInstances.length > 0) {
throw new NotFoundException(
`Instance${inexistentInstances.length > 1 ? 's' : ''} "${inexistentInstances.join(', ')}" not found`,
);
if (inexistentInstances.length > 0) {
throw new NotFoundException(
`Instance${inexistentInstances.length > 1 ? 's' : ''} "${inexistentInstances.join(', ')}" not found`,
);
}
}

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

const where = instanceNames
? {
name: {
in: instanceNames,
},
clientName,
}
: { clientName };
const where =
instanceNames && instanceNames.length > 0
? {
name: {
in: instanceNames,
},
clientName,
}
: { clientName };

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

return this.instanceInfo([instanceName]);
const instanceNames = instanceName ? [instanceName] : null;
return this.instanceInfo(instanceNames);
}

public async cleaningUp(instanceName: string) {
Expand Down

0 comments on commit 3a0487a

Please sign in to comment.