Skip to content

Commit

Permalink
chore: improve readability on unverifyContactChannel
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustrb committed Oct 14, 2024
1 parent c77655e commit 81020db
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions apps/meteor/app/livechat/server/lib/Contacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,13 +350,17 @@ export async function unverifyContactChannel(
channelName: string,
visitorId: string,
): Promise<ILivechatContact> {
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,
});
Expand Down

0 comments on commit 81020db

Please sign in to comment.