Skip to content

Commit 1ad51a4

Browse files
committed
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.
1 parent 8c27f11 commit 1ad51a4

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

src/api/services/channel.service.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -490,20 +490,23 @@ export class ChannelStartupService {
490490
}
491491

492492
public async fetchContacts(query: Query<Contact>) {
493-
const remoteJid = query?.where?.remoteJid
494-
? query?.where?.remoteJid.includes('@')
495-
? query.where?.remoteJid
496-
: createJid(query.where?.remoteJid)
497-
: null;
498-
499-
const where = {
493+
const where: any = {
500494
instanceId: this.instanceId,
501495
};
502496

503-
if (remoteJid) {
497+
if (query?.where?.remoteJid) {
498+
const remoteJid = query.where.remoteJid.includes('@') ? query.where.remoteJid : createJid(query.where.remoteJid);
504499
where['remoteJid'] = remoteJid;
505500
}
506501

502+
if (query?.where?.id) {
503+
where['id'] = query.where.id;
504+
}
505+
506+
if (query?.where?.pushName) {
507+
where['pushName'] = query.where.pushName;
508+
}
509+
507510
const contactFindManyArgs: Prisma.ContactFindManyArgs = {
508511
where,
509512
};

src/validate/chat.schema.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,9 @@ export const contactValidateSchema: JSONSchema7 = {
195195
_id: { type: 'string', minLength: 1 },
196196
pushName: { type: 'string', minLength: 1 },
197197
id: { type: 'string', minLength: 1 },
198+
remoteJid: { type: 'string', minLength: 1 },
198199
},
199-
...isNotEmpty('_id', 'id', 'pushName'),
200+
...isNotEmpty('_id', 'id', 'pushName', 'remoteJid'),
200201
},
201202
},
202203
};

0 commit comments

Comments
 (0)