Skip to content

Column names incorrectly lowercased due to missing quotes in SQL aliases when fetching chats #1691

Closed

Description

@foqc

Title: Column names incorrectly lowercased due to missing quotes in SQL aliases when fetching chats. File: channel.service.ts -> fetchChats

Environment:

Evolution API Version: v2.3.0 (built from main branch)
Node.js Version: 20
Database: PostgreSQL with Evolution schema
Cache: Redis
Deployment: Docker-based
Issue Description:
The SQL query used to fetch chat data did not consistently use double quotes ("columnAlias") for column aliases. In PostgreSQL, when aliases are not quoted, their names are automatically converted to lowercase. This caused mismatches during the mapping phase, as the application expected camelCase names (e.g., updatedAt, windowStart), but received lowercase ones (e.g., updatedat, windowstart), breaking or skipping some fields.

The query had a mix of quoted and unquoted aliases, which led to inconsistent mapping behavior, some columns worked, others didn't. Additionally the pagination is not working properly (fetchChat is applying twice the pagination filter).

Solution
Updated the query to consistently use quoted column aliases in camelCase format. This ensures PostgreSQL preserves the exact casing, and the application can reliably map the data fields.

Fix example
... AND AS "lastMessagePushName", "Message"."participant" AS "lastMessageParticipant", "Message"."messageType" AS "lastMessageMessageType", "Message"."message" AS "lastMessageMessage", "Message"."contextInfo" AS "lastMessageContextInfo", "Message"."source" AS "lastMessageSource", "Message"."messageTimestamp" AS "lastMessageMessageTimestamp", "Message"."instanceId" AS "lastMessageInstanceId", "Message"."sessionId" AS "lastMessageSessionId", "Message"."status" AS "lastMessageStatus"

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions