Skip to content

Commit

Permalink
refactor: simplify ID path handling in parseWriteResponse and improve…
Browse files Browse the repository at this point in the history
… default behavior
  • Loading branch information
immdipu committed Feb 28, 2025
1 parent e0637b8 commit 4503e9c
Showing 1 changed file with 11 additions and 40 deletions.
51 changes: 11 additions & 40 deletions providers/brevo/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (c *Connector) buildWriteRequest(ctx context.Context, params common.WritePa
return http.NewRequestWithContext(ctx, method, url.String(), bytes.NewReader(jsonData))
}

func (c *Connector) parseWriteResponse( //nolint:funlen
func (c *Connector) parseWriteResponse(
ctx context.Context,
params common.WriteParams,
response *common.JSONHTTPResponse,
Expand All @@ -58,68 +58,39 @@ func (c *Connector) parseWriteResponse( //nolint:funlen
"smtp/email": "messageId",
"transactionalSMS/sms": "messageId",
"whatsapp/sendMessage": "messageId",
"smtp/templates": "id",
"emailCampaigns": "id",
"emailCampaigns/images": "url",
"smsCampaigns": "id",
"whatsappCampaigns": "id",
"whatsappCampaigns/template": "id",
"contacts": "id",
"contacts/folders": "id",
"contacts/export": "processId",
"contacts/import": "processId",
"senders": "id",
"senders/domains": "id",
"webhooks": "id",
"webhooks/export": "processId",
"corporate/subAccount": "id",
"corporate/ssoToken": "token",
"corporate/subAccount/ssoToken": "token",
"corporate/subAccount/key": "key",
"corporate/group": "id",
"corporate/user/invitation/send": "id",
"organization/user/invitation/send": "invoice_id",
"organization/user/update/permissions": "invoice_id",
"feeds": "id",
"companies": "id",
"events": "id",
"crm/attributes": "id",
"companies/import": "processId",
"crm/deals": "id",
"crm/deals/import": "processId",
"crm/tasks": "id",
"crm/notes": "id",
"conversations/messages": "id",
"conversations/pushedMessages": "id",
"orders/status/batch": "batchId",
"categories": "id",
"products": "id",
"couponCollections": "id",
"payments/requests": "id",
"loyalty/config/programs": "id",
"ecommerce/activate": "id",
}

idPath, valid := recordIDPaths[params.ObjectName]
if !valid {
return &common.WriteResult{
Success: true,
Errors: nil,
Data: nil,
}, nil
// Get ID path, defaulting to "id" if not specifically mapped
idPath := "id"
mappedPath, exists := recordIDPaths[params.ObjectName]

if exists {
idPath = mappedPath
}

// Try string first
rawID, err := jsonquery.New(node).StrWithDefault(idPath, "id")
rawID, err := jsonquery.New(node).StrWithDefault(idPath, "")
if err != nil {
// Try integer
IntID, err := jsonquery.New(node).IntegerOptional(idPath)
if err != nil {
return nil, err
}

str := strconv.FormatInt(*IntID, 10)
rawID = str
if IntID != nil {
rawID = strconv.FormatInt(*IntID, 10)
}
}

return &common.WriteResult{
Expand Down

0 comments on commit 4503e9c

Please sign in to comment.