@@ -503,9 +503,17 @@ export class ChannelStartupService {
503
503
where [ 'remoteJid' ] = remoteJid ;
504
504
}
505
505
506
- return await this . prismaRepository . contact . findMany ( {
506
+ const contactFindManyArgs : Prisma . ContactFindManyArgs = {
507
507
where,
508
- } ) ;
508
+ } ;
509
+
510
+ if ( query . offset ) contactFindManyArgs . take = query . offset ;
511
+ if ( query . page ) {
512
+ const validPage = Math . max ( query . page as number , 1 ) ;
513
+ contactFindManyArgs . skip = query . offset * ( validPage - 1 ) ;
514
+ }
515
+
516
+ return await this . prismaRepository . contact . findMany ( contactFindManyArgs ) ;
509
517
}
510
518
511
519
public cleanMessageData ( message : any ) {
@@ -674,6 +682,13 @@ export class ChannelStartupService {
674
682
: createJid ( query . where ?. remoteJid )
675
683
: null ;
676
684
685
+ const limit =
686
+ query . offset && ! query . page
687
+ ? Prisma . sql ` LIMIT ${ query . offset } `
688
+ : query . offset && query . page
689
+ ? Prisma . sql ` LIMIT ${ query . offset } OFFSET ${ ( ( query . page as number ) - 1 ) * query . offset } `
690
+ : Prisma . sql `` ;
691
+
677
692
const where = {
678
693
instanceId : this . instanceId ,
679
694
} ;
@@ -700,6 +715,7 @@ export class ChannelStartupService {
700
715
to_timestamp("Message"."messageTimestamp"::double precision),
701
716
"Contact"."updatedAt"
702
717
) as "updatedAt",
718
+ "Chat"."name" as "chatName",
703
719
"Chat"."createdAt" as "windowStart",
704
720
"Chat"."createdAt" + INTERVAL '24 hours' as "windowExpires",
705
721
CASE
@@ -730,6 +746,7 @@ export class ChannelStartupService {
730
746
ORDER BY
731
747
"Contact"."remoteJid",
732
748
"Message"."messageTimestamp" DESC
749
+ ${ limit }
733
750
)
734
751
SELECT * FROM rankedMessages
735
752
ORDER BY "updatedAt" DESC NULLS LAST;
@@ -758,6 +775,7 @@ export class ChannelStartupService {
758
775
id : contact . id ,
759
776
remoteJid : contact . remoteJid ,
760
777
pushName : contact . pushName ,
778
+ chatName : contact . chatName ,
761
779
profilePicUrl : contact . profilePicUrl ,
762
780
updatedAt : contact . updatedAt ,
763
781
windowStart : contact . windowStart ,
0 commit comments