Skip to content

Commit c0537f4

Browse files
committed
fix: error on save contact
1 parent 5097f13 commit c0537f4

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/api/integrations/channel/evolution/evolution.channel.service.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { MediaMessage, Options, SendAudioDto, SendMediaDto, SendTextDto } from '
22
import { PrismaRepository } from '@api/repository/repository.service';
33
import { ChannelStartupService } from '@api/services/channel.service';
44
import { Events, wa } from '@api/types/wa.types';
5-
import { ConfigService } from '@config/env.config';
5+
import { ConfigService, Database } from '@config/env.config';
66
import { BadRequestException, InternalServerErrorException } from '@exceptions';
77
import { isURL } from 'class-validator';
88
import EventEmitter2 from 'eventemitter2';
@@ -150,9 +150,11 @@ export class EvolutionStartupService extends ChannelStartupService {
150150

151151
this.sendDataWebhook(Events.CONTACTS_UPSERT, contactRaw);
152152

153-
await this.prismaRepository.contact.create({
154-
data: contactRaw,
155-
});
153+
if (this.configService.get<Database>('DATABASE').SAVE_DATA.CONTACTS)
154+
await this.prismaRepository.contact.createMany({
155+
data: contactRaw,
156+
skipDuplicates: true,
157+
});
156158

157159
const chat = await this.prismaRepository.chat.findFirst({
158160
where: { instanceId: this.instanceId, remoteJid: data.remoteJid },

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -933,8 +933,10 @@ export class BaileysStartupService extends ChannelStartupService {
933933
this.sendDataWebhook(Events.CONTACTS_UPDATE, contactRaw);
934934

935935
if (this.configService.get<Database>('DATABASE').SAVE_DATA.CONTACTS)
936-
await this.prismaRepository.contact.create({
937-
data: contactRaw,
936+
await this.prismaRepository.contact.upsert({
937+
where: { remoteJid_instanceId: { remoteJid: contactRaw.remoteJid, instanceId: contactRaw.instanceId } },
938+
create: contactRaw,
939+
update: contactRaw,
938940
});
939941

940942
return;

0 commit comments

Comments
 (0)