Merge pull request #2120 from FaelN1/develop
Some checks failed
Check Code Quality / check-lint-and-build (push) Has been cancelled
Build Docker image / Build and Deploy (push) Has been cancelled
Security Scan / CodeQL Analysis (javascript) (push) Has been cancelled
Security Scan / Dependency Review (push) Has been cancelled

fix(chat): apply where filters correctly in findContacts endpoint
This commit is contained in:
Davidson Gomes 2025-10-23 06:55:28 -03:00 committed by GitHub
commit d5f5b8325e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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'),
},
},
};