Skip to content

Commit

Permalink
chore: split Contacts.ts file and its tests into separate files for e…
Browse files Browse the repository at this point in the history
…very function (#33698)
  • Loading branch information
pierre-lehnen-rc authored Oct 22, 2024
1 parent c11a62a commit b4acee8
Show file tree
Hide file tree
Showing 46 changed files with 1,241 additions and 861 deletions.
2 changes: 1 addition & 1 deletion apps/meteor/app/api/server/lib/maybeMigrateLivechatRoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { isOmnichannelRoom, type IRoom } from '@rocket.chat/core-typings';
import { Rooms } from '@rocket.chat/models';
import type { FindOptions } from 'mongodb';

import { migrateVisitorIfMissingContact } from '../../../livechat/server/lib/Contacts';
import { migrateVisitorIfMissingContact } from '../../../livechat/server/lib/contacts/migrateVisitorIfMissingContact';

export async function maybeMigrateLivechatRoom(room: IRoom | null, options: FindOptions<IRoom> = {}): Promise<IRoom | null> {
if (!room || !isOmnichannelRoom(room)) {
Expand Down
3 changes: 2 additions & 1 deletion apps/meteor/app/apps/server/bridges/contact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { ContactBridge } from '@rocket.chat/apps-engine/server/bridges';
import type { IVisitor } from '@rocket.chat/core-typings';
import { LivechatContacts } from '@rocket.chat/models';

import { addContactEmail, verifyContactChannel } from '../../../livechat/server/lib/Contacts';
import { addContactEmail } from '../../../livechat/server/lib/contacts/addContactEmail';
import { verifyContactChannel } from '../../../livechat/server/lib/contacts/verifyContactChannel';

export class AppContactBridge extends ContactBridge {
constructor(private readonly orch: IAppServerOrchestrator) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import type { IImportContact, IImportContactRecord } from '@rocket.chat/core-typings';
import { LivechatVisitors } from '@rocket.chat/models';

import { createContact, getAllowedCustomFields, validateCustomFields } from '../../../../livechat/server/lib/Contacts';
import { createContact } from '../../../../livechat/server/lib/contacts/createContact';
import { getAllowedCustomFields } from '../../../../livechat/server/lib/contacts/getAllowedCustomFields';
import { validateCustomFields } from '../../../../livechat/server/lib/contacts/validateCustomFields';
import { RecordConverter } from './RecordConverter';

export class ContactConverter extends RecordConverter<IImportContactRecord> {
Expand Down
3 changes: 2 additions & 1 deletion apps/meteor/app/livechat/server/api/lib/visitors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import type { FindOptions } from 'mongodb';

import { callbacks } from '../../../../../lib/callbacks';
import { canAccessRoomAsync } from '../../../../authorization/server/functions/canAccessRoom';
import { migrateVisitorToContactId, getContactIdByVisitorId } from '../../lib/Contacts';
import { getContactIdByVisitorId } from '../../lib/contacts/getContactIdByVisitorId';
import { migrateVisitorToContactId } from '../../lib/contacts/migrateVisitorToContactId';

export async function findVisitorInfo({ visitorId }: { visitorId: IVisitor['_id'] }) {
const visitor = await LivechatVisitors.findOneEnabledById(visitorId);
Expand Down
9 changes: 7 additions & 2 deletions apps/meteor/app/livechat/server/api/v1/contact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ import { Meteor } from 'meteor/meteor';

import { API } from '../../../../api/server';
import { getPaginationItems } from '../../../../api/server/helpers/getPaginationItems';
import { getContactHistory, Contacts, createContact, getContact, updateContact, getContacts } from '../../lib/Contacts';
import { createContact } from '../../lib/contacts/createContact';
import { getContact } from '../../lib/contacts/getContact';
import { getContactHistory } from '../../lib/contacts/getContactHistory';
import { getContacts } from '../../lib/contacts/getContacts';
import { registerContact } from '../../lib/contacts/registerContact';
import { updateContact } from '../../lib/contacts/updateContact';

API.v1.addRoute(
'omnichannel/contact',
Expand All @@ -36,7 +41,7 @@ API.v1.addRoute(
}),
});

const contact = await Contacts.registerContact(this.bodyParams);
const contact = await registerContact(this.bodyParams);

return API.v1.success({ contact });
},
Expand Down
Loading

0 comments on commit b4acee8

Please sign in to comment.