Skip to content

Commit

Permalink
make channels field required in contacts
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusbsilva137 committed Nov 18, 2024
1 parent 3466a03 commit d504306
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 15 deletions.
2 changes: 1 addition & 1 deletion apps/meteor/app/livechat/server/lib/Helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export const createLivechatRoom = async (
if (!contact) {
throw new Error('error-invalid-contact');
}
const verified = Boolean(contact.channels?.some((channel) => isVerifiedChannelInSource(channel, _id, source)));
const verified = Boolean(contact.channels.some((channel) => isVerifiedChannelInSource(channel, _id, source)));

// TODO: Solve `u` missing issue
const room: InsertionModel<IOmnichannelRoom> = {
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/livechat/server/lib/QueueManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ export class QueueManager {
return false;
}

return Boolean(contact.channels?.some((channel) => isVerifiedChannelInSource(channel, room.v._id, room.source)));
return Boolean(contact.channels.some((channel) => isVerifiedChannelInSource(channel, room.v._id, room.source)));
}

static async requestRoom({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export class ContactMerger {

contact.emails?.forEach(({ address: value }) => fields.add({ type: 'email', value }));
contact.phones?.forEach(({ phoneNumber: value }) => fields.add({ type: 'phone', value }));
contact.channels?.forEach((value) => fields.add({ type: 'channel', value }));
contact.channels.forEach((value) => fields.add({ type: 'channel', value }));

if (name) {
fields.add({ type: 'name', value: name });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export async function createContact({
phones,
customFields: receivedCustomFields = {},
contactManager,
channels,
channels = [],
unknown,
importIds,
}: CreateContactParams): Promise<string> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const runIsAgentAvailableToTakeContactInquiry = async (
return { value: false, error: 'error-unknown-contact' };
}

const isContactVerified = (contact.channels?.filter((channel) => isVerifiedChannelInSource(channel, visitorId, source)) || []).length > 0;
const isContactVerified = (contact.channels.filter((channel) => isVerifiedChannelInSource(channel, visitorId, source)) || []).length > 0;
if (!isContactVerified && settings.get<boolean>('Livechat_Block_Unverified_Contacts')) {
return { value: false, error: 'error-unverified-contact' };
}
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/ee/server/patches/mergeContacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const runMergeContacts = async (
throw new Error('error-invalid-contact');
}

const channel = originalContact.channels?.find((channel: ILivechatContactChannel) => isSameChannel(channel.visitor, visitor));
const channel = originalContact.channels.find((channel: ILivechatContactChannel) => isSameChannel(channel.visitor, visitor));
if (!channel) {
throw new Error('error-invalid-channel');
}
Expand Down
15 changes: 7 additions & 8 deletions apps/meteor/server/models/raw/LivechatContacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ export class LivechatContactsRaw extends BaseRaw<ILivechatContact> implements IL
},
unique: false,
},
{
key: {
channels: 1,
},
unique: false,
},
];
}

Expand Down Expand Up @@ -126,14 +132,7 @@ export class LivechatContactsRaw extends BaseRaw<ILivechatContact> implements IL
],
},
{
$or: [
{
channels: { $exists: false },
},
{
channels: { $size: 0 },
},
],
channels: [],
},
],
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export interface ILivechatContact {
unknown?: boolean;
conflictingFields?: ILivechatContactConflictingField[];
customFields?: Record<string, string | unknown>;
channels?: ILivechatContactChannel[];
channels: ILivechatContactChannel[];
createdAt: Date;
lastChat?: {
_id: string;
Expand Down

0 comments on commit d504306

Please sign in to comment.