mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-12-24 06:07:45 -06:00
fix(chat): apply where filters correctly in findContacts endpoint
Anteriormente, o endpoint findContacts processava apenas o campo remoteJid da cláusula where, ignorando outros campos como id e pushName. Alterações: - Atualiza método fetchContacts para processar todos os campos do where (id, remoteJid, pushName) - Adiciona campo remoteJid ao contactValidateSchema para validação adequada - Garante isolamento multi-tenant mantendo filtro por instanceId Esta correção permite que usuários filtrem contatos por qualquer um dos campos suportados ao invés de sempre retornar todos os contatos da instância.
This commit is contained in:
@@ -490,20 +490,23 @@ export class ChannelStartupService {
|
||||
}
|
||||
|
||||
public async fetchContacts(query: Query<Contact>) {
|
||||
const remoteJid = query?.where?.remoteJid
|
||||
? query?.where?.remoteJid.includes('@')
|
||||
? query.where?.remoteJid
|
||||
: createJid(query.where?.remoteJid)
|
||||
: null;
|
||||
|
||||
const where = {
|
||||
const where: any = {
|
||||
instanceId: this.instanceId,
|
||||
};
|
||||
|
||||
if (remoteJid) {
|
||||
if (query?.where?.remoteJid) {
|
||||
const remoteJid = query.where.remoteJid.includes('@') ? query.where.remoteJid : createJid(query.where.remoteJid);
|
||||
where['remoteJid'] = remoteJid;
|
||||
}
|
||||
|
||||
if (query?.where?.id) {
|
||||
where['id'] = query.where.id;
|
||||
}
|
||||
|
||||
if (query?.where?.pushName) {
|
||||
where['pushName'] = query.where.pushName;
|
||||
}
|
||||
|
||||
const contactFindManyArgs: Prisma.ContactFindManyArgs = {
|
||||
where,
|
||||
};
|
||||
|
||||
@@ -195,8 +195,9 @@ export const contactValidateSchema: JSONSchema7 = {
|
||||
_id: { type: 'string', minLength: 1 },
|
||||
pushName: { type: 'string', minLength: 1 },
|
||||
id: { type: 'string', minLength: 1 },
|
||||
remoteJid: { type: 'string', minLength: 1 },
|
||||
},
|
||||
...isNotEmpty('_id', 'id', 'pushName'),
|
||||
...isNotEmpty('_id', 'id', 'pushName', 'remoteJid'),
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user