fix: chats must be unique

This commit is contained in:
Pedro Ivo 2024-11-15 17:38:26 -03:00
parent 1665654676
commit cefe3ef6c3
No known key found for this signature in database
GPG Key ID: BC120FACE48D28A0
3 changed files with 10 additions and 2 deletions

View File

@ -127,6 +127,7 @@ model Chat {
unreadMessages Int @default(0)
@@index([instanceId])
@@index([remoteJid])
@@unique([remoteJid, instanceId])
}
model Contact {

View File

@ -127,6 +127,7 @@ model Chat {
unreadMessages Int @default(0)
@@index([instanceId])
@@index([remoteJid])
@@unique([remoteJid, instanceId])
}
model Contact {

View File

@ -1147,7 +1147,10 @@ export class BaileysStartupService extends ChannelStartupService {
this.sendDataWebhook(Events.CHATS_UPSERT, [chatToInsert]);
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,
});
}
@ -1483,7 +1486,10 @@ export class BaileysStartupService extends ChannelStartupService {
this.sendDataWebhook(Events.CHATS_UPSERT, [chatToInsert]);
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,
});
}