Skip to content

Commit

Permalink
some fixs
Browse files Browse the repository at this point in the history
  • Loading branch information
yousseefs committed Oct 29, 2024
1 parent 11d3112 commit f6ccd58
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
1 change: 1 addition & 0 deletions prisma/mysql-schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ model Chat {
unreadMessages Int @default(0)
@@index([instanceId])
@@index([remoteJid])
@@unique([instanceId, remoteJid])
}

model Contact {
Expand Down
1 change: 1 addition & 0 deletions prisma/postgresql-schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ model Chat {
unreadMessages Int @default(0)
@@index([instanceId])
@@index([remoteJid])
@@unique([remoteJid, instanceId])
}

model Contact {
Expand Down
22 changes: 16 additions & 6 deletions src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1085,9 +1085,14 @@ 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({
data: chatToInsert,
});
try {
await this.prismaRepository.chat.create({
data: chatToInsert,
});
}
catch(error){
console.log(`Chat insert record ignored: ${chatToInsert.remoteJid} - ${chatToInsert.instanceId}`);
}
}
}

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

0 comments on commit f6ccd58

Please sign in to comment.