Refactor backend folder structure (#4505)

* Refactor backend folder structure

Co-authored-by: Charles Bochet <charles@twenty.com>

* fix tests

* fix

* move yoga hooks

---------

Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
Weiko
2024-03-15 18:37:09 +01:00
committed by GitHub
parent afb9b3e375
commit 2c09096edd
523 changed files with 1386 additions and 1856 deletions

View File

@ -0,0 +1,37 @@
import { formatAddressObjectAsParticipants } from 'src/modules/messaging/services/utils/format-address-object-as-participants.util';
describe('formatAddressObjectAsParticipants', () => {
it('should format address object as participants', () => {
const addressObject = {
value: [
{ name: 'John Doe', address: 'john.doe @example.com' },
{ name: 'Jane Smith', address: 'jane.smith@example.com ' },
],
html: '',
text: '',
};
const result = formatAddressObjectAsParticipants(addressObject, 'from');
expect(result).toEqual([
{
role: 'from',
handle: 'john.doe@example.com',
displayName: 'John Doe',
},
{
role: 'from',
handle: 'jane.smith@example.com',
displayName: 'Jane Smith',
},
]);
});
it('should return an empty array if address object is undefined', () => {
const addressObject = undefined;
const result = formatAddressObjectAsParticipants(addressObject, 'to');
expect(result).toEqual([]);
});
});

View File

@ -0,0 +1,37 @@
import { AddressObject } from 'mailparser';
import { Participant } from 'src/modules/messaging/types/gmail-message';
const formatAddressObjectAsArray = (
addressObject: AddressObject | AddressObject[],
): AddressObject[] => {
return Array.isArray(addressObject) ? addressObject : [addressObject];
};
const removeSpacesAndLowerCase = (email: string): string => {
return email.replace(/\s/g, '').toLowerCase();
};
export const formatAddressObjectAsParticipants = (
addressObject: AddressObject | AddressObject[] | undefined,
role: 'from' | 'to' | 'cc' | 'bcc',
): Participant[] => {
if (!addressObject) return [];
const addressObjects = formatAddressObjectAsArray(addressObject);
const participants = addressObjects.map((addressObject) => {
const emailAdresses = addressObject.value;
return emailAdresses.map((emailAddress) => {
const { name, address } = emailAddress;
return {
role,
handle: address ? removeSpacesAndLowerCase(address) : '',
displayName: name || '',
};
});
});
return participants.flat();
};