From 81020db1780ffe3acad4a2bfad79065972ae6024 Mon Sep 17 00:00:00 2001 From: gustrb Date: Mon, 14 Oct 2024 13:24:55 -0300 Subject: [PATCH] chore: improve readability on unverifyContactChannel --- apps/meteor/app/livechat/server/lib/Contacts.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/apps/meteor/app/livechat/server/lib/Contacts.ts b/apps/meteor/app/livechat/server/lib/Contacts.ts index a87309bb767a..28de523c28a2 100644 --- a/apps/meteor/app/livechat/server/lib/Contacts.ts +++ b/apps/meteor/app/livechat/server/lib/Contacts.ts @@ -350,13 +350,17 @@ export async function unverifyContactChannel( channelName: string, visitorId: string, ): Promise { - const channelToUnverify = contact.channels?.find((channel) => channel.name === channelName && channel.visitorId === visitorId); + if (!contact.channels) { + throw new Error('error-invalid-channel'); + } - if (!channelToUnverify) { + const channelToUnverify = contact.channels.findIndex((channel) => channel.name === channelName && channel.visitorId === visitorId); + if (channelToUnverify < 0) { throw new Error('error-invalid-channel'); } - channelToUnverify.verified = false; + contact.channels[channelToUnverify].verified = false; + return LivechatContacts.updateContact(contact._id, { channels: contact.channels, });