mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-21 19:47:21 -06:00
Fix and improve fetch chats
This commit is contained in:
parent
96e1802148
commit
10aeeebb53
@ -614,9 +614,7 @@ export class ChannelStartupService {
|
||||
: this.createJid(query.where?.remoteJid)
|
||||
: null;
|
||||
|
||||
let result;
|
||||
if (remoteJid) {
|
||||
result = await this.prismaRepository.$queryRaw`
|
||||
const result = await this.prismaRepository.$queryRaw`
|
||||
SELECT
|
||||
"Chat"."id",
|
||||
"Chat"."remoteJid",
|
||||
@ -625,13 +623,13 @@ export class ChannelStartupService {
|
||||
"Chat"."createdAt",
|
||||
"Chat"."updatedAt",
|
||||
"Contact"."pushName",
|
||||
"Contact"."profilePicUrl"
|
||||
"Contact"."profilePicUrl",
|
||||
"Contact"."unreadMessages"
|
||||
FROM "Chat"
|
||||
INNER JOIN "Message" ON "Chat"."remoteJid" = "Message"."key"->>'remoteJid'
|
||||
LEFT JOIN "Contact" ON "Chat"."remoteJid" = "Contact"."remoteJid"
|
||||
WHERE "Chat"."instanceId" = ${this.instanceId}
|
||||
AND "Chat"."remoteJid" = ${remoteJid}
|
||||
${remoteJid ? 'AND "Chat"."remoteJid" = ${remoteJid}' : ''}
|
||||
GROUP BY
|
||||
"Chat"."id",
|
||||
"Chat"."remoteJid",
|
||||
@ -644,35 +642,6 @@ export class ChannelStartupService {
|
||||
"Contact"."unreadMessages"
|
||||
ORDER BY "Chat"."updatedAt" DESC;
|
||||
`;
|
||||
} else {
|
||||
result = await this.prismaRepository.$queryRaw`
|
||||
SELECT
|
||||
"Chat"."id",
|
||||
"Chat"."remoteJid",
|
||||
"Chat"."name",
|
||||
"Chat"."labels",
|
||||
"Chat"."createdAt",
|
||||
"Chat"."updatedAt",
|
||||
"Contact"."pushName",
|
||||
"Contact"."profilePicUrl"
|
||||
"Contact"."unreadMessages"
|
||||
FROM "Chat"
|
||||
INNER JOIN "Message" ON "Chat"."remoteJid" = "Message"."key"->>'remoteJid'
|
||||
LEFT JOIN "Contact" ON "Chat"."remoteJid" = "Contact"."remoteJid"
|
||||
WHERE "Chat"."instanceId" = ${this.instanceId}
|
||||
GROUP BY
|
||||
"Chat"."id",
|
||||
"Chat"."remoteJid",
|
||||
"Chat"."name",
|
||||
"Chat"."labels",
|
||||
"Chat"."createdAt",
|
||||
"Chat"."updatedAt",
|
||||
"Contact"."pushName",
|
||||
"Contact"."profilePicUrl"
|
||||
"Contact"."unreadMessages"
|
||||
ORDER BY "Chat"."updatedAt" DESC;
|
||||
`;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user