Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/chore/sci/contact-phone-and-emai…
Browse files Browse the repository at this point in the history
…l-format' into feat/single-contact-id
  • Loading branch information
dougfabris committed Oct 14, 2024
2 parents a39f3c8 + b217165 commit f327f82
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 24 deletions.
4 changes: 1 addition & 3 deletions apps/meteor/app/api/server/lib/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,6 @@ export async function findPaginatedUsersByStatus({
if (sort?.status) {
actualSort.active = sort.status;
}
if (sort?.name) {
actualSort.nameInsensitive = sort.name;
}
const match: Filter<IUser & RootFilterOperators<IUser>> = {};
switch (status) {
case 'active':
Expand Down Expand Up @@ -198,6 +195,7 @@ export async function findPaginatedUsersByStatus({
if (roles?.length && !roles.includes('all')) {
match.roles = { $in: roles };
}

const { cursor, totalCount } = await Users.findPaginated(
{
...match,
Expand Down
12 changes: 6 additions & 6 deletions apps/meteor/app/livechat/server/lib/Contacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ export async function createContactFromVisitor(visitor: ILivechatVisitor): Promi

const contactData: InsertionModel<ILivechatContact> = {
name: visitor.name || visitor.username,
emails: visitor.visitorEmails?.map(({ address }) => address),
phones: visitor.phone?.map(({ phoneNumber }) => phoneNumber),
emails: visitor.visitorEmails,
phones: visitor.phone || undefined,
unknown: true,
channels: [],
customFields: visitor.livechatData,
Expand Down Expand Up @@ -225,8 +225,8 @@ export async function createContact(params: CreateContactParams): Promise<string

const { insertedId } = await LivechatContacts.insertOne({
name,
emails,
phones,
emails: emails?.map((address) => ({ address })),
phones: phones?.map((phoneNumber) => ({ phoneNumber })),
contactManager,
channels,
customFields,
Expand Down Expand Up @@ -254,8 +254,8 @@ export async function updateContact(params: UpdateContactParams): Promise<ILivec

const updatedContact = await LivechatContacts.updateContact(contactId, {
name,
emails,
phones,
emails: emails?.map((address) => ({ address })),
phones: phones?.map((phoneNumber) => ({ phoneNumber })),
contactManager,
channels,
customFields,
Expand Down
8 changes: 4 additions & 4 deletions apps/meteor/server/models/raw/LivechatContacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ export class LivechatContactsRaw extends BaseRaw<ILivechatContact> implements IL
collation: { locale: 'en', strength: 2, caseLevel: false },
},
{
key: { emails: 1 },
key: { 'emails.address': 1 },
unique: false,
name: 'emails_insensitive',
partialFilterExpression: { emails: { $exists: true } },
collation: { locale: 'en', strength: 2, caseLevel: false },
},
{
key: { phones: 1 },
key: { 'phones.phoneNumber': 1 },
partialFilterExpression: { phones: { $exists: true } },
unique: false,
},
Expand All @@ -47,8 +47,8 @@ export class LivechatContactsRaw extends BaseRaw<ILivechatContact> implements IL
const match: Filter<ILivechatContact & RootFilterOperators<ILivechatContact>> = {
$or: [
{ name: { $regex: searchRegex, $options: 'i' } },
{ emails: { $regex: searchRegex, $options: 'i' } },
{ phones: { $regex: searchRegex, $options: 'i' } },
{ 'emails.address': { $regex: searchRegex, $options: 'i' } },
{ 'phones.phoneNumber': { $regex: searchRegex, $options: 'i' } },
],
};

Expand Down
26 changes: 19 additions & 7 deletions apps/meteor/tests/end-to-end/api/livechat/contacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,16 @@ describe('LIVECHAT - contacts', () => {
expect(res.body).to.have.property('success', true);
expect(res.body.contact._id).to.be.equal(contactId);
expect(res.body.contact.name).to.be.equal(name);
expect(res.body.contact.emails).to.be.deep.equal(emails);
expect(res.body.contact.phones).to.be.deep.equal(phones);
expect(res.body.contact.emails).to.be.deep.equal([
{
address: emails[0],
},
]);
expect(res.body.contact.phones).to.be.deep.equal([
{
phoneNumber: phones[0],
},
]);
});

it('should set the unknown field to false when updating a contact', async () => {
Expand Down Expand Up @@ -600,8 +608,12 @@ describe('LIVECHAT - contacts', () => {
expect(res.body.contact).to.have.property('createdAt');
expect(res.body.contact._id).to.be.equal(contactId);
expect(res.body.contact.name).to.be.equal(contact.name);
expect(res.body.contact.emails).to.be.deep.equal(contact.emails);
expect(res.body.contact.phones).to.be.deep.equal(contact.phones);
expect(res.body.contact.emails).to.be.deep.equal([
{
address: contact.emails[0],
},
]);
expect(res.body.contact.phones).to.be.deep.equal([{ phoneNumber: contact.phones[0] }]);
expect(res.body.contact.contactManager).to.be.equal(contact.contactManager);
});

Expand Down Expand Up @@ -708,7 +720,7 @@ describe('LIVECHAT - contacts', () => {
expect(res.body.total).to.be.equal(1);
expect(res.body.contacts[0]._id).to.be.equal(contactId);
expect(res.body.contacts[0].name).to.be.equal(contact.name);
expect(res.body.contacts[0].emails[0]).to.be.equal(contact.emails[0]);
expect(res.body.contacts[0].emails[0].address).to.be.equal(contact.emails[0]);
});

it('should return only contacts that match the searchText using phone number', async () => {
Expand All @@ -720,7 +732,7 @@ describe('LIVECHAT - contacts', () => {
expect(res.body.total).to.be.equal(1);
expect(res.body.contacts[0]._id).to.be.equal(contactId);
expect(res.body.contacts[0].name).to.be.equal(contact.name);
expect(res.body.contacts[0].emails[0]).to.be.equal(contact.emails[0]);
expect(res.body.contacts[0].phones[0].phoneNumber).to.be.equal(contact.phones[0]);
});

it('should return only contacts that match the searchText using name', async () => {
Expand All @@ -732,7 +744,7 @@ describe('LIVECHAT - contacts', () => {
expect(res.body.total).to.be.equal(1);
expect(res.body.contacts[0]._id).to.be.equal(contactId);
expect(res.body.contacts[0].name).to.be.equal(contact.name);
expect(res.body.contacts[0].emails[0]).to.be.equal(contact.emails[0]);
expect(res.body.contacts[0].emails[0].address).to.be.equal(contact.emails[0]);
});

it('should return an empty list if no contacts exist', async () => {
Expand Down
5 changes: 3 additions & 2 deletions packages/core-typings/src/ILivechatContact.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { IVisitorEmail, IVisitorPhone } from './ILivechatVisitor';
import type { IRocketChatRecord } from './IRocketChatRecord';
import type { IOmnichannelSource } from './IRoom';

Expand All @@ -20,8 +21,8 @@ export interface ILivechatContactConflictingField {

export interface ILivechatContact extends IRocketChatRecord {
name: string;
phones?: string[];
emails?: string[];
phones?: IVisitorPhone[];
emails?: IVisitorEmail[];
contactManager?: string;
unknown?: boolean;
hasConflict?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion packages/i18n/src/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ const languages = files.map((file) => path.basename(file, '.i18n.json'));

// write the files
if (fs.existsSync(`./dist`)) {
fs.rmdirSync(`./dist`, { recursive: true });
fs.rmSync(`./dist`, { recursive: true, force: true });
}
fs.mkdirSync(`./dist`, { recursive: true });

Expand Down
2 changes: 1 addition & 1 deletion packages/i18n/src/index.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('i18n', () => {
jest.spyOn(fs, 'writeFileSync').mockImplementation(() => {});
jest.spyOn(fs, 'readFileSync').mockImplementation(() => JSON.stringify({}));
jest.spyOn(fs, 'existsSync').mockReturnValue(true);
jest.spyOn(fs, 'rmdirSync').mockImplementation(() => {});
jest.spyOn(fs, 'rmSync').mockImplementation(() => {});
});

afterEach(() => {
Expand Down

0 comments on commit f327f82

Please sign in to comment.