1+ import { getCollectionsDto } from '@api/dto/business.dto' ;
12import { OfferCallDto } from '@api/dto/call.dto' ;
23import {
34 ArchiveChatDto ,
45 BlockUserDto ,
56 DeleteMessage ,
67 getBase64FromMediaMessageDto ,
7- getCatalogDto ,
8- getCollectionsDto ,
98 LastMessage ,
109 MarkChatUnreadDto ,
1110 NumberBusiness ,
@@ -2343,8 +2342,8 @@ export class BaileysStartupService extends ChannelStartupService {
23432342 if ( file ) mediaData . sticker = file . buffer . toString ( 'base64' ) ;
23442343
23452344 const convert = data ?. notConvertSticker
2346- ? Buffer . from ( data . sticker , 'base64' )
2347- : await this . convertToWebP ( data . sticker ) ;
2345+ ? Buffer . from ( data . sticker , 'base64' )
2346+ : await this . convertToWebP ( data . sticker ) ;
23482347 const gifPlayback = data . sticker . includes ( '.gif' ) ;
23492348 const result = await this . sendMessageWithTyping (
23502349 data . number ,
@@ -4024,11 +4023,11 @@ export class BaileysStartupService extends ChannelStartupService {
40244023 return response ;
40254024 }
40264025
4027- //Catalogs and collections
4028- public async fetchCatalog ( instanceName : string , data : getCatalogDto ) {
4026+ //Business Controller
4027+ public async fetchCatalog ( instanceName : string , data : getCollectionsDto ) {
40294028 const jid = data . number ? createJid ( data . number ) : this . client ?. user ?. id ;
40304029 const limit = data . limit || 10 ;
4031- const cursor = data . cursor || null ;
4030+ const cursor = null ;
40324031
40334032 const onWhatsapp = ( await this . whatsappNumber ( { numbers : [ jid ] } ) ) ?. shift ( ) ;
40344033
@@ -4039,15 +4038,35 @@ export class BaileysStartupService extends ChannelStartupService {
40394038 try {
40404039 const info = ( await this . whatsappNumber ( { numbers : [ jid ] } ) ) ?. shift ( ) ;
40414040 const business = await this . fetchBusinessProfile ( info ?. jid ) ;
4042- const catalog = await this . getCatalog ( { jid : info ?. jid , limit, cursor } ) ;
4041+
4042+ let catalog = await this . getCatalog ( { jid : info ?. jid , limit, cursor } ) ;
4043+ let nextPageCursor = catalog . nextPageCursor ;
4044+ let nextPageCursorJson = nextPageCursor ? JSON . parse ( atob ( nextPageCursor ) ) : null ;
4045+ let pagination = nextPageCursorJson ?. pagination_cursor
4046+ ? JSON . parse ( atob ( nextPageCursorJson . pagination_cursor ) )
4047+ : null ;
4048+ let fetcherHasMore = pagination ?. fetcher_has_more === true ? true : false ;
4049+
4050+ let productsCatalog = catalog . products || [ ] ;
4051+ let countLoops = 0 ;
4052+ while ( fetcherHasMore && countLoops < 4 ) {
4053+ catalog = await this . getCatalog ( { jid : info ?. jid , limit, cursor : nextPageCursor } ) ;
4054+ nextPageCursor = catalog . nextPageCursor ;
4055+ nextPageCursorJson = nextPageCursor ? JSON . parse ( atob ( nextPageCursor ) ) : null ;
4056+ pagination = nextPageCursorJson ?. pagination_cursor
4057+ ? JSON . parse ( atob ( nextPageCursorJson . pagination_cursor ) )
4058+ : null ;
4059+ fetcherHasMore = pagination ?. fetcher_has_more === true ? true : false ;
4060+ productsCatalog = [ ...productsCatalog , ...catalog . products ] ;
4061+ countLoops ++ ;
4062+ }
40434063
40444064 return {
40454065 wuid : info ?. jid || jid ,
4046- name : info ?. name ,
40474066 numberExists : info ?. exists ,
40484067 isBusiness : business . isBusiness ,
4049- catalogLength : catalog ?. products . length ,
4050- catalog : catalog ?. products ,
4068+ catalogLength : productsCatalog . length ,
4069+ catalog : productsCatalog ,
40514070 } ;
40524071 } catch ( error ) {
40534072 console . log ( error ) ;
@@ -4082,9 +4101,9 @@ export class BaileysStartupService extends ChannelStartupService {
40824101 }
40834102 }
40844103
4085- public async fetchCatalogCollections ( instanceName : string , data : getCollectionsDto ) {
4104+ public async fetchCollections ( instanceName : string , data : getCollectionsDto ) {
40864105 const jid = data . number ? createJid ( data . number ) : this . client ?. user ?. id ;
4087- const limit = data . limit || 10 ;
4106+ const limit = data . limit <= 20 ? data . limit : 20 ; //(tem esse limite, não sei porque)
40884107
40894108 const onWhatsapp = ( await this . whatsappNumber ( { numbers : [ jid ] } ) ) ?. shift ( ) ;
40904109
@@ -4095,18 +4114,17 @@ export class BaileysStartupService extends ChannelStartupService {
40954114 try {
40964115 const info = ( await this . whatsappNumber ( { numbers : [ jid ] } ) ) ?. shift ( ) ;
40974116 const business = await this . fetchBusinessProfile ( info ?. jid ) ;
4098- const catalogCollections = await this . getCollections ( info ?. jid , limit ) ;
4117+ const collections = await this . getCollections ( info ?. jid , limit ) ;
40994118
41004119 return {
41014120 wuid : info ?. jid || jid ,
41024121 name : info ?. name ,
41034122 numberExists : info ?. exists ,
41044123 isBusiness : business . isBusiness ,
4105- catalogLength : catalogCollections ?. length ,
4106- catalogCollections : catalogCollections ,
4124+ collectionsLength : collections ?. length ,
4125+ collections : collections ,
41074126 } ;
41084127 } catch ( error ) {
4109- console . log ( error ) ;
41104128 return {
41114129 wuid : jid ,
41124130 name : null ,
0 commit comments