fix: chats must be unique

This commit is contained in:
Pedro Ivo
2024-11-15 17:38:26 -03:00
parent 1665654676
commit cefe3ef6c3
3 changed files with 10 additions and 2 deletions
+1
View File
@@ -127,6 +127,7 @@ model Chat {
unreadMessages Int @default(0) unreadMessages Int @default(0)
@@index([instanceId]) @@index([instanceId])
@@index([remoteJid]) @@index([remoteJid])
@@unique([remoteJid, instanceId])
} }
model Contact { model Contact {
+1
View File
@@ -127,6 +127,7 @@ model Chat {
unreadMessages Int @default(0) unreadMessages Int @default(0)
@@index([instanceId]) @@index([instanceId])
@@index([remoteJid]) @@index([remoteJid])
@@unique([remoteJid, instanceId])
} }
model Contact { model Contact {
@@ -1147,7 +1147,10 @@ export class BaileysStartupService extends ChannelStartupService {
this.sendDataWebhook(Events.CHATS_UPSERT, [chatToInsert]); this.sendDataWebhook(Events.CHATS_UPSERT, [chatToInsert]);
if (this.configService.get<Database>('DATABASE').SAVE_DATA.CHATS) { if (this.configService.get<Database>('DATABASE').SAVE_DATA.CHATS) {
await this.prismaRepository.chat.create({ await this.prismaRepository.chat.update({
where: {
id: existingChat.id,
},
data: chatToInsert, data: chatToInsert,
}); });
} }
@@ -1483,7 +1486,10 @@ export class BaileysStartupService extends ChannelStartupService {
this.sendDataWebhook(Events.CHATS_UPSERT, [chatToInsert]); this.sendDataWebhook(Events.CHATS_UPSERT, [chatToInsert]);
if (this.configService.get<Database>('DATABASE').SAVE_DATA.CHATS) { if (this.configService.get<Database>('DATABASE').SAVE_DATA.CHATS) {
await this.prismaRepository.chat.create({ await this.prismaRepository.chat.update({
where: {
id: existingChat.id,
},
data: chatToInsert, data: chatToInsert,
}); });
} }