{{ message }}
Preserve alias casing in chat fetch query#1696
Merged
DavidsonGomes merged 4 commits intoEvolutionAPI:developfrom Jul 21, 2025
Merged
Preserve alias casing in chat fetch query#1696DavidsonGomes merged 4 commits intoEvolutionAPI:developfrom
DavidsonGomes merged 4 commits intoEvolutionAPI:developfrom
Conversation
…liases (update missing mappings)
Contributor
Comment on lines
773
to
806
| const mappedResults = results.map((contact) => { | ||
| const lastMessage = contact.lastmessageid | ||
| const lastMessage = contact.lastMessageId | ||
| ? { | ||
| id: contact.lastmessageid, | ||
| key: contact.lastmessage_key, | ||
| pushName: contact.lastmessagepushname, | ||
| participant: contact.lastmessageparticipant, | ||
| messageType: contact.lastmessagemessagetype, | ||
| message: contact.lastmessagemessage, | ||
| contextInfo: contact.lastmessagecontextinfo, | ||
| source: contact.lastmessagesource, | ||
| messageTimestamp: contact.lastmessagemessagetimestamp, | ||
| instanceId: contact.lastmessageinstanceid, | ||
| sessionId: contact.lastmessagesessionid, | ||
| status: contact.lastmessagestatus, | ||
| id: contact.lastMessageId, | ||
| key: contact.lastMessage_key, | ||
| pushName: contact.lastMessagePushName, | ||
| participant: contact.lastMessageParticipant, | ||
| messageType: contact.lastMessageMessageType, | ||
| message: contact.lastMessageMessage, | ||
| contextInfo: contact.lastMessageContextInfo, | ||
| source: contact.lastMessageSource, | ||
| messageTimestamp: contact.lastMessageMessageTimestamp, | ||
| instanceId: contact.lastMessageInstanceId, | ||
| sessionId: contact.lastMessageSessionId, | ||
| status: contact.lastMessageStatus, | ||
| } | ||
| : undefined; | ||
|
|
||
| return { | ||
| id: contact.contactid || null, | ||
| remoteJid: contact.remotejid, | ||
| pushName: contact.pushname, | ||
| profilePicUrl: contact.profilepicurl, | ||
| updatedAt: contact.updatedat, | ||
| windowStart: contact.windowstart, | ||
| windowExpires: contact.windowexpires, | ||
| windowActive: contact.windowactive, | ||
| id: contact.contactId || null, | ||
| remoteJid: contact.remoteJid, | ||
| pushName: contact.pushName, | ||
| profilePicUrl: contact.profilePicUrl, | ||
| updatedAt: contact.updatedAt, | ||
| windowStart: contact.windowStart, | ||
| windowExpires: contact.windowExpires, | ||
| windowActive: contact.windowActive, | ||
| lastMessage: lastMessage ? this.cleanMessageData(lastMessage) : undefined, | ||
| unreadCount: 0, | ||
| isSaved: !!contact.contactid, | ||
| unreadCount: contact.unreadMessages, | ||
| isSaved: !!contact.contactId, | ||
| }; | ||
| }); | ||
|
|
||
| if (query?.take && query?.skip) { | ||
| const skip = query.skip || 0; | ||
| const take = query.take || 20; | ||
| return mappedResults.slice(skip, skip + take); | ||
| } | ||
|
|
||
| return mappedResults; |
Contributor
There was a problem hiding this comment.
suggestion (code-quality): Inline variable that is immediately returned (inline-immediately-returned-variable)
Suggested change
| const mappedResults = results.map((contact) => { | |
| const lastMessage = contact.lastmessageid | |
| const lastMessage = contact.lastMessageId | |
| ? { | |
| id: contact.lastmessageid, | |
| key: contact.lastmessage_key, | |
| pushName: contact.lastmessagepushname, | |
| participant: contact.lastmessageparticipant, | |
| messageType: contact.lastmessagemessagetype, | |
| message: contact.lastmessagemessage, | |
| contextInfo: contact.lastmessagecontextinfo, | |
| source: contact.lastmessagesource, | |
| messageTimestamp: contact.lastmessagemessagetimestamp, | |
| instanceId: contact.lastmessageinstanceid, | |
| sessionId: contact.lastmessagesessionid, | |
| status: contact.lastmessagestatus, | |
| id: contact.lastMessageId, | |
| key: contact.lastMessage_key, | |
| pushName: contact.lastMessagePushName, | |
| participant: contact.lastMessageParticipant, | |
| messageType: contact.lastMessageMessageType, | |
| message: contact.lastMessageMessage, | |
| contextInfo: contact.lastMessageContextInfo, | |
| source: contact.lastMessageSource, | |
| messageTimestamp: contact.lastMessageMessageTimestamp, | |
| instanceId: contact.lastMessageInstanceId, | |
| sessionId: contact.lastMessageSessionId, | |
| status: contact.lastMessageStatus, | |
| } | |
| : undefined; | |
| return { | |
| id: contact.contactid || null, | |
| remoteJid: contact.remotejid, | |
| pushName: contact.pushname, | |
| profilePicUrl: contact.profilepicurl, | |
| updatedAt: contact.updatedat, | |
| windowStart: contact.windowstart, | |
| windowExpires: contact.windowexpires, | |
| windowActive: contact.windowactive, | |
| id: contact.contactId || null, | |
| remoteJid: contact.remoteJid, | |
| pushName: contact.pushName, | |
| profilePicUrl: contact.profilePicUrl, | |
| updatedAt: contact.updatedAt, | |
| windowStart: contact.windowStart, | |
| windowExpires: contact.windowExpires, | |
| windowActive: contact.windowActive, | |
| lastMessage: lastMessage ? this.cleanMessageData(lastMessage) : undefined, | |
| unreadCount: 0, | |
| isSaved: !!contact.contactid, | |
| unreadCount: contact.unreadMessages, | |
| isSaved: !!contact.contactId, | |
| }; | |
| }); | |
| if (query?.take && query?.skip) { | |
| const skip = query.skip || 0; | |
| const take = query.take || 20; | |
| return mappedResults.slice(skip, skip + take); | |
| } | |
| return mappedResults; | |
| return results.map((contact) => { | |
| const lastMessage = contact.lastMessageId | |
| ? { | |
| id: contact.lastMessageId, | |
| key: contact.lastMessage_key, | |
| pushName: contact.lastMessagePushName, | |
| participant: contact.lastMessageParticipant, | |
| messageType: contact.lastMessageMessageType, | |
| message: contact.lastMessageMessage, | |
| contextInfo: contact.lastMessageContextInfo, | |
| source: contact.lastMessageSource, | |
| messageTimestamp: contact.lastMessageMessageTimestamp, | |
| instanceId: contact.lastMessageInstanceId, | |
| sessionId: contact.lastMessageSessionId, | |
| status: contact.lastMessageStatus, | |
| } | |
| : undefined; | |
| return { | |
| id: contact.contactId || null, | |
| remoteJid: contact.remoteJid, | |
| pushName: contact.pushName, | |
| profilePicUrl: contact.profilePicUrl, | |
| updatedAt: contact.updatedAt, | |
| windowStart: contact.windowStart, | |
| windowExpires: contact.windowExpires, | |
| windowActive: contact.windowActive, | |
| lastMessage: lastMessage ? this.cleanMessageData(lastMessage) : undefined, | |
| unreadCount: contact.unreadMessages, | |
| isSaved: !!contact.contactId, | |
| }; | |
| }); | |
Explanation
Something that we often see in people's code is assigning to a result variableand then immediately returning it.
Returning the result directly shortens the code and removes an unnecessary
variable, reducing the mental load of reading the function.
Where intermediate variables can be useful is if they then get used as a
parameter or a condition, and the name can act like a comment on what the
variable represents. In the case where you're returning it from a function, the
function name is there to tell you what the result is, so the variable name
is unnecessary.
Collaborator
|
Please, fix the lint with |
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Bug Fix: Inconsistent Column Alias Casing in
fetchChatsBug description: #1691
Context
In PostgreSQL, unquoted column aliases are automatically lowercased. In our
channel.service.ts → fetchChatsquery, there was a mix of quoted and unquoted aliases, causing PostgreSQL to return fields likeupdatedatandwindowstartinstead of the expectedupdatedAtandwindowStart.This inconsistency broke or skipped field mappings in the application layer.
Additionally, the pagination logic was applied twice due to redundant filtering, which led to incorrect result sets when paginating chat data.
Changes Made
OFFSETandLIMITbehavior for chat pagination.Affected Environments
Outcome
Summary by Sourcery
Fix inconsistent column alias casing and eliminate duplicate pagination logic in the chat fetch query to restore proper field mappings and accurate paging.
Bug Fixes: