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:
Rafael Nicolas 2025-10-22 23:52:48 -03:00
parent 8c27f11f5b
commit 1ad51a434b
2 changed files with 13 additions and 9 deletions

View File

@ -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,
};

View File

@ -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'),
},
},
};