Skip to content

Commit b29cf1b

Browse files
matheusmartinsInspermatheusmartinsInsper
authored andcommitted
Refactor logical message deletion in BaileysStartupService
1 parent 15eccc9 commit b29cf1b

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2983,25 +2983,31 @@ export class BaileysStartupService extends ChannelStartupService {
29832983
const messageId = response.message?.protocolMessage?.key?.id;
29842984
if (messageId) {
29852985
const isLogicalDeleted = configService.get<Database>('DATABASE').DELETE_DATA.LOGICAL_MESSAGE_DELETE;
2986-
let message = await this.prismaRepository.message.findUnique({
2987-
where: { id: messageId },
2986+
let message = await this.prismaRepository.message.findFirst({
2987+
where: {
2988+
key: {
2989+
path: ['id'],
2990+
equals: messageId,
2991+
},
2992+
},
29882993
});
29892994
if (isLogicalDeleted) {
29902995
if (!message) return response;
29912996
const existingKey = typeof message?.key === 'object' && message.key !== null ? message.key : {};
29922997
message = await this.prismaRepository.message.update({
2993-
where: { id: messageId },
2998+
where: { id: message.id },
29942999
data: {
29953000
key: {
29963001
...existingKey,
29973002
deleted: true,
29983003
},
3004+
status: 'DELETED',
29993005
},
30003006
});
30013007
} else {
30023008
await this.prismaRepository.message.deleteMany({
30033009
where: {
3004-
id: messageId,
3010+
id: message.id,
30053011
},
30063012
});
30073013
}
@@ -3010,7 +3016,7 @@ export class BaileysStartupService extends ChannelStartupService {
30103016
instanceId: message.instanceId,
30113017
key: message.key,
30123018
messageType: message.messageType,
3013-
status: message.status,
3019+
status: 'DELETED',
30143020
source: message.source,
30153021
messageTimestamp: message.messageTimestamp,
30163022
pushName: message.pushName,

0 commit comments

Comments
 (0)