mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-14 01:41:24 -06:00
Merge pull request #991 from rafaelsantana6/fix-fetch-instances
feat: add support for fetching multiple instances by key
This commit is contained in:
commit
c4bcd1fafe
@ -360,27 +360,25 @@ export class InstanceController {
|
||||
public async fetchInstances({ instanceName, instanceId, number }: InstanceDto, key: string) {
|
||||
const env = this.configService.get<Auth>('AUTHENTICATION').API_KEY;
|
||||
|
||||
let name = instanceName;
|
||||
// let arrayReturn = false;
|
||||
|
||||
if (env.KEY !== key) {
|
||||
const instanceByKey = await this.prismaRepository.instance.findMany({
|
||||
const instancesByKey = await this.prismaRepository.instance.findMany({
|
||||
where: {
|
||||
token: key,
|
||||
name: instanceName || undefined,
|
||||
id: instanceId || undefined,
|
||||
},
|
||||
});
|
||||
|
||||
if (instanceByKey) {
|
||||
name = instanceByKey[0].name;
|
||||
// arrayReturn = true;
|
||||
if (instancesByKey.length > 0) {
|
||||
const names = instancesByKey.map((instance) => instance.name);
|
||||
|
||||
return this.waMonitor.instanceInfo(names);
|
||||
} else {
|
||||
throw new UnauthorizedException();
|
||||
}
|
||||
}
|
||||
|
||||
if (name) {
|
||||
return this.waMonitor.instanceInfo(name);
|
||||
} else if (instanceId || number) {
|
||||
if (instanceId || number) {
|
||||
return this.waMonitor.instanceInfoById(instanceId, number);
|
||||
}
|
||||
|
||||
|
@ -1699,7 +1699,7 @@ export class BaileysStartupService extends ChannelStartupService {
|
||||
website: business?.website?.shift(),
|
||||
};
|
||||
} else {
|
||||
const info: Instance = await waMonitor.instanceInfo(instanceName);
|
||||
const info: Instance = await waMonitor.instanceInfo([instanceName]);
|
||||
const business = await this.fetchBusinessProfile(jid);
|
||||
|
||||
return {
|
||||
|
@ -59,14 +59,25 @@ export class WAMonitoringService {
|
||||
}
|
||||
}
|
||||
|
||||
public async instanceInfo(instanceName?: string): Promise<any> {
|
||||
if (instanceName && !this.waInstances[instanceName]) {
|
||||
throw new NotFoundException(`Instance "${instanceName}" not found`);
|
||||
public async instanceInfo(instanceNames?: string[]): Promise<any> {
|
||||
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`,
|
||||
);
|
||||
}
|
||||
|
||||
const clientName = this.configService.get<Database>('DATABASE').CONNECTION.CLIENT_NAME;
|
||||
|
||||
const where = instanceName ? { name: instanceName, clientName } : { clientName };
|
||||
const where = instanceNames
|
||||
? {
|
||||
name: {
|
||||
in: instanceNames,
|
||||
},
|
||||
clientName,
|
||||
}
|
||||
: { clientName };
|
||||
|
||||
const instances = await this.prismaRepository.instance.findMany({
|
||||
where,
|
||||
@ -112,7 +123,7 @@ export class WAMonitoringService {
|
||||
throw new NotFoundException(`Instance "${instanceName}" not found`);
|
||||
}
|
||||
|
||||
return this.instanceInfo(instanceName);
|
||||
return this.instanceInfo([instanceName]);
|
||||
}
|
||||
|
||||
public async cleaningUp(instanceName: string) {
|
||||
|
Loading…
Reference in New Issue
Block a user