mirror of
https://github.com/twentyhq/twenty.git
synced 2024-09-11 23:37:21 +03:00
Fix domain name parsing on company creation (#4297)
* add domain parsing library * change package for psl * trying to fix error * fix * update * remove unused function
This commit is contained in:
parent
aa7fa3acfa
commit
735e75b3b1
@ -36,7 +36,8 @@
|
||||
"@ptc-org/nestjs-query-graphql": "patch:@ptc-org/nestjs-query-graphql@4.2.0#./patches/@ptc-org+nestjs-query-graphql+4.2.0.patch",
|
||||
"class-validator": "patch:class-validator@0.14.0#./patches/class-validator+0.14.0.patch",
|
||||
"graphql-middleware": "^6.1.35",
|
||||
"passport": "^0.7.0"
|
||||
"passport": "^0.7.0",
|
||||
"psl": "^1.9.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@nestjs/cli": "10.3.0",
|
||||
|
@ -28,7 +28,7 @@ export class CreateCompaniesAndContactsService {
|
||||
workspaceId: string,
|
||||
transactionManager?: EntityManager,
|
||||
) {
|
||||
if (participants.length === 0) {
|
||||
if (!participants || participants.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -51,6 +51,10 @@ export class CreateCompaniesAndContactsService {
|
||||
const { uniqueParticipants, uniqueHandles } =
|
||||
getUniqueParticipantsAndHandles(participantsFromOtherCompanies);
|
||||
|
||||
if (uniqueHandles.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const alreadyCreatedContacts = await this.personService.getByEmails(
|
||||
uniqueHandles,
|
||||
workspaceId,
|
||||
|
@ -23,6 +23,10 @@ export class CreateCompanyService {
|
||||
): Promise<{
|
||||
[domainName: string]: string;
|
||||
}> {
|
||||
if (domainNames.length === 0) {
|
||||
return {};
|
||||
}
|
||||
|
||||
const uniqueDomainNames = [...new Set(domainNames)];
|
||||
|
||||
const existingCompanies =
|
||||
|
@ -1,5 +1,9 @@
|
||||
import psl from 'psl';
|
||||
|
||||
import { capitalize } from 'src/utils/capitalize';
|
||||
|
||||
export const getCompanyNameFromDomainName = (domainName: string): string => {
|
||||
return capitalize(domainName.split('.').slice(-2, -1)[0]);
|
||||
export const getCompanyNameFromDomainName = (domainName: string) => {
|
||||
const { sld } = psl.parse(domainName);
|
||||
|
||||
return sld ? capitalize(sld) : '';
|
||||
};
|
||||
|
@ -1,3 +1,9 @@
|
||||
export function getDomainNameFromHandle(handle: string): string {
|
||||
return handle.split('@')?.[1].split('.').slice(-2).join('.').toLowerCase();
|
||||
}
|
||||
import psl from 'psl';
|
||||
|
||||
export const getDomainNameFromHandle = (handle: string): string => {
|
||||
const wholeDomain = handle?.split('@')?.[1] || '';
|
||||
|
||||
const { domain } = psl.parse(wholeDomain);
|
||||
|
||||
return domain || '';
|
||||
};
|
||||
|
@ -38834,7 +38834,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"psl@npm:^1.1.28, psl@npm:^1.1.33":
|
||||
"psl@npm:^1.1.28, psl@npm:^1.1.33, psl@npm:^1.9.0":
|
||||
version: 1.9.0
|
||||
resolution: "psl@npm:1.9.0"
|
||||
checksum: 6a3f805fdab9442f44de4ba23880c4eba26b20c8e8e0830eff1cb31007f6825dace61d17203c58bfe36946842140c97a1ba7f67bc63ca2d88a7ee052b65d97ab
|
||||
@ -44289,6 +44289,7 @@ __metadata:
|
||||
class-validator: "patch:class-validator@0.14.0#./patches/class-validator+0.14.0.patch"
|
||||
graphql-middleware: "npm:^6.1.35"
|
||||
passport: "npm:^0.7.0"
|
||||
psl: "npm:^1.9.0"
|
||||
rimraf: "npm:^5.0.5"
|
||||
typescript: "npm:^5.3.3"
|
||||
languageName: unknown
|
||||
|
Loading…
Reference in New Issue
Block a user