@@ -111,14 +111,14 @@ func (a *App) CreateCatalog(r *fastglue.Request) error {
111111 }
112112
113113 // Get WhatsApp account
114- var account models. WhatsAppAccount
115- if err := a . DB . Where ( "organization_id = ? AND name = ?" , orgID , req . WhatsAppAccount ). First ( & account ). Error ; err != nil {
114+ account , err := a . resolveWhatsAppAccount ( orgID , req . WhatsAppAccount )
115+ if err != nil {
116116 return r .SendErrorEnvelope (fasthttp .StatusNotFound , "WhatsApp account not found" , nil , "" )
117117 }
118118
119119 // Create catalog in Meta
120120 ctx := context .Background ()
121- waAccount := a .toWhatsAppAccount (& account )
121+ waAccount := a .toWhatsAppAccount (account )
122122
123123 metaCatalogID , err := a .WhatsApp .CreateCatalog (ctx , waAccount , req .Name )
124124 if err != nil {
@@ -188,14 +188,14 @@ func (a *App) DeleteCatalog(r *fastglue.Request) error {
188188 }
189189
190190 // Get WhatsApp account
191- var account models. WhatsAppAccount
192- if err := a . DB . Where ( "organization_id = ? AND name = ?" , orgID , catalog . WhatsAppAccount ). First ( & account ). Error ; err != nil {
191+ account , err := a . resolveWhatsAppAccount ( orgID , catalog . WhatsAppAccount )
192+ if err != nil {
193193 return r .SendErrorEnvelope (fasthttp .StatusNotFound , "WhatsApp account not found" , nil , "" )
194194 }
195195
196196 // Delete from Meta
197197 ctx := context .Background ()
198- waAccount := a .toWhatsAppAccount (& account )
198+ waAccount := a .toWhatsAppAccount (account )
199199
200200 if err := a .WhatsApp .DeleteCatalog (ctx , waAccount , catalog .MetaCatalogID ); err != nil {
201201 a .Log .Error ("Failed to delete catalog from Meta" , "error" , err )
@@ -231,14 +231,14 @@ func (a *App) SyncCatalogs(r *fastglue.Request) error {
231231 }
232232
233233 // Get WhatsApp account
234- var account models. WhatsAppAccount
235- if err := a . DB . Where ( "organization_id = ? AND name = ?" , orgID , req . WhatsAppAccount ). First ( & account ). Error ; err != nil {
234+ account , err := a . resolveWhatsAppAccount ( orgID , req . WhatsAppAccount )
235+ if err != nil {
236236 return r .SendErrorEnvelope (fasthttp .StatusNotFound , "WhatsApp account not found" , nil , "" )
237237 }
238238
239239 // Fetch catalogs from Meta
240240 ctx := context .Background ()
241- waAccount := a .toWhatsAppAccount (& account )
241+ waAccount := a .toWhatsAppAccount (account )
242242
243243 metaCatalogs , err := a .WhatsApp .ListCatalogs (ctx , waAccount )
244244 if err != nil {
@@ -343,8 +343,8 @@ func (a *App) CreateCatalogProduct(r *fastglue.Request) error {
343343 }
344344
345345 // Get WhatsApp account
346- var account models. WhatsAppAccount
347- if err := a . DB . Where ( "organization_id = ? AND name = ?" , orgID , catalog . WhatsAppAccount ). First ( & account ). Error ; err != nil {
346+ account , err := a . resolveWhatsAppAccount ( orgID , catalog . WhatsAppAccount )
347+ if err != nil {
348348 return r .SendErrorEnvelope (fasthttp .StatusNotFound , "WhatsApp account not found" , nil , "" )
349349 }
350350
@@ -355,7 +355,7 @@ func (a *App) CreateCatalogProduct(r *fastglue.Request) error {
355355
356356 // Create product in Meta
357357 ctx := context .Background ()
358- waAccount := a .toWhatsAppAccount (& account )
358+ waAccount := a .toWhatsAppAccount (account )
359359
360360 productInput := & whatsapp.ProductInput {
361361 Name : req .Name ,
@@ -445,14 +445,14 @@ func (a *App) UpdateCatalogProduct(r *fastglue.Request) error {
445445 }
446446
447447 // Get WhatsApp account
448- var account models. WhatsAppAccount
449- if err := a . DB . Where ( "organization_id = ? AND name = ?" , orgID , catalog . WhatsAppAccount ). First ( & account ). Error ; err != nil {
448+ account , err := a . resolveWhatsAppAccount ( orgID , catalog . WhatsAppAccount )
449+ if err != nil {
450450 return r .SendErrorEnvelope (fasthttp .StatusNotFound , "WhatsApp account not found" , nil , "" )
451451 }
452452
453453 // Update product in Meta
454454 ctx := context .Background ()
455- waAccount := a .toWhatsAppAccount (& account )
455+ waAccount := a .toWhatsAppAccount (account )
456456
457457 productInput := & whatsapp.ProductInput {
458458 Name : req .Name ,
@@ -523,14 +523,14 @@ func (a *App) DeleteCatalogProduct(r *fastglue.Request) error {
523523 }
524524
525525 // Get WhatsApp account
526- var account models. WhatsAppAccount
527- if err := a . DB . Where ( "organization_id = ? AND name = ?" , orgID , catalog . WhatsAppAccount ). First ( & account ). Error ; err != nil {
526+ account , err := a . resolveWhatsAppAccount ( orgID , catalog . WhatsAppAccount )
527+ if err != nil {
528528 return r .SendErrorEnvelope (fasthttp .StatusNotFound , "WhatsApp account not found" , nil , "" )
529529 }
530530
531531 // Delete from Meta
532532 ctx := context .Background ()
533- waAccount := a .toWhatsAppAccount (& account )
533+ waAccount := a .toWhatsAppAccount (account )
534534
535535 if err := a .WhatsApp .DeleteProduct (ctx , waAccount , product .MetaProductID ); err != nil {
536536 a .Log .Error ("Failed to delete product from Meta" , "error" , err )
0 commit comments