Skip to content

Commit f6ccd58

Browse files
committed
some fixs
1 parent 11d3112 commit f6ccd58

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

prisma/mysql-schema.prisma

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ model Chat {
127127
unreadMessages Int @default(0)
128128
@@index([instanceId])
129129
@@index([remoteJid])
130+
@@unique([instanceId, remoteJid])
130131
}
131132

132133
model Contact {

prisma/postgresql-schema.prisma

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ model Chat {
127127
unreadMessages Int @default(0)
128128
@@index([instanceId])
129129
@@index([remoteJid])
130+
@@unique([remoteJid, instanceId])
130131
}
131132

132133
model Contact {

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,9 +1085,14 @@ export class BaileysStartupService extends ChannelStartupService {
10851085

10861086
this.sendDataWebhook(Events.CHATS_UPSERT, [chatToInsert]);
10871087
if (this.configService.get<Database>('DATABASE').SAVE_DATA.CHATS) {
1088-
await this.prismaRepository.chat.create({
1089-
data: chatToInsert,
1090-
});
1088+
try {
1089+
await this.prismaRepository.chat.create({
1090+
data: chatToInsert,
1091+
});
1092+
}
1093+
catch(error){
1094+
console.log(`Chat insert record ignored: ${chatToInsert.remoteJid} - ${chatToInsert.instanceId}`);
1095+
}
10911096
}
10921097
}
10931098

@@ -1420,9 +1425,14 @@ export class BaileysStartupService extends ChannelStartupService {
14201425

14211426
this.sendDataWebhook(Events.CHATS_UPSERT, [chatToInsert]);
14221427
if (this.configService.get<Database>('DATABASE').SAVE_DATA.CHATS) {
1423-
await this.prismaRepository.chat.create({
1424-
data: chatToInsert,
1425-
});
1428+
try {
1429+
await this.prismaRepository.chat.create({
1430+
data: chatToInsert,
1431+
});
1432+
}
1433+
catch(error){
1434+
console.log(`Chat insert record ignored: ${chatToInsert.remoteJid} - ${chatToInsert.instanceId}`);
1435+
}
14261436
}
14271437
}
14281438
}

0 commit comments

Comments
 (0)