Skip to content

Commit d5f5b83

Browse files
Merge pull request #2120 from FaelN1/develop
fix(chat): apply where filters correctly in findContacts endpoint
2 parents 8c27f11 + 1ad51a4 commit d5f5b83

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)