some fixs

This commit is contained in:
yousseefs 2024-10-29 18:43:31 +00:00
parent 11d31123ac
commit f6ccd58dee
3 changed files with 18 additions and 6 deletions

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([instanceId, remoteJid])
} }
model Contact { model Contact {

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 {

View File

@ -1085,9 +1085,14 @@ 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({ try {
data: chatToInsert, await this.prismaRepository.chat.create({
}); data: chatToInsert,
});
}
catch(error){
console.log(`Chat insert record ignored: ${chatToInsert.remoteJid} - ${chatToInsert.instanceId}`);
}
} }
} }
@ -1420,9 +1425,14 @@ 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({ try {
data: chatToInsert, await this.prismaRepository.chat.create({
}); data: chatToInsert,
});
}
catch(error){
console.log(`Chat insert record ignored: ${chatToInsert.remoteJid} - ${chatToInsert.instanceId}`);
}
} }
} }
} }