mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-26 02:18:38 -06:00
adds filtering option in findChats to return a single conversation
This commit is contained in:
parent
33cdcd4959
commit
9b68299e20
@ -32,13 +32,18 @@ export class KwikController {
|
||||
skip: number,
|
||||
sort: any,
|
||||
messageTimestamp: number,
|
||||
remoteJid?: string,
|
||||
) {
|
||||
const db = configService.get<Database>('DATABASE');
|
||||
const connection = dbserver.getClient().db(db.CONNECTION.DB_PREFIX_NAME + '-whatsapp-api');
|
||||
const messages = connection.collection('messages');
|
||||
let match: { owner: string; 'key.remoteJid'?: string } = { owner: instanceName };
|
||||
if (remoteJid) {
|
||||
match = { ...match, 'key.remoteJid': remoteJid };
|
||||
}
|
||||
const pipeline: Document[] = [
|
||||
{ $sort: { 'key.remoteJid': -1, messageTimestamp: -1 } },
|
||||
{ $match: { owner: instanceName } },
|
||||
{ $match: match },
|
||||
{
|
||||
$group: {
|
||||
_id: '$key.remoteJid',
|
||||
|
@ -30,6 +30,7 @@ export class KwikRouter extends RouterBroker {
|
||||
Number(req.query.skip),
|
||||
req.query.sort,
|
||||
Number(req.query.messageTimestamp),
|
||||
req.query.remoteJid ? req.query.remoteJid.toString() : null,
|
||||
),
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user