Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: created by email calendar #6536

Merged
merged 6 commits into from
Aug 7, 2024
Merged

feat: created by email calendar #6536

merged 6 commits into from
Aug 7, 2024

Conversation

magrinj
Copy link
Member

@magrinj magrinj commented Aug 5, 2024

This PR is a followup of #6324 to add support of EMAIL and CALENDAR source for the created by composite field.

Copy link

github-actions bot commented Aug 5, 2024

TODOs/FIXMEs:

  • // FixMe: TypeORM typing issue... id is always returned when using save: packages/twenty-server/src/modules/contact-creation-manager/services/create-company-and-contact.service.ts

Generated by 🚫 dangerJS against 99c5431

/**
* Pick only the keys that match the Type `U`
*/
-export type PickKeysByType<T, U> = string & keyof {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TypeORM doesn't handle column type that can be nullable...

@@ -111,7 +110,7 @@ export class CompanyWorkspaceEntity extends BaseWorkspaceEntity {
icon: 'IconMap',
})
@WorkspaceIsNullable()
address: Address;
address: AddressMetadata;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing and incorrect metadata types

Comment on lines -165 to -168
const companyDomainNameColumnName =
domainNameFieldMetadata?.type === FieldMetadataType.LINKS
? 'domainNamePrimaryLinkUrl'
: 'domainName';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBC: Dropping support of old column domainName typed as a simple string, as migration should be applied.
cc @ijreilly

@magrinj magrinj marked this pull request as ready for review August 6, 2024 15:26
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

This PR implements support for EMAIL and CALENDAR sources in the createdBy composite field, following up on issue #6324. Key changes include:

  • Updated CreateCompanyAndContactService to handle new ACTOR field type and FieldActorSource
  • Removed specific repository files for companies and persons, shifting to TwentyORMGlobalManager
  • Modified CompanyWorkspaceEntity to include createdBy field of type ActorMetadata
  • Added utility function computeDisplayName for handling full name display
  • Updated various services and jobs to include FieldActorSource.EMAIL and FieldActorSource.CALENDAR
  • Applied a custom patch to typeorm package to handle nullable fields in PickKeysByType

These changes improve record creation source handling and provide more detailed information about record creators across different sources.

17 file(s) reviewed, 2 comment(s)
Edit PR Review Bot Settings

Comment on lines +79 to +83
const alreadyCreatedContacts = await personRepository.find({
where: {
email: Any(uniqueHandles),
},
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Using Any() in TypeORM query may have performance implications for large datasets. Consider using IN operator if possible.

Comment on lines +198 to +199
// FixMe: TypeORM typing issue... id is always returned when using save
recordId: createdPerson.id!,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Using non-null assertion (!) here might hide potential runtime errors. Consider handling the case where id could be undefined.

Copy link
Member

@Weiko Weiko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! I'll try to test everything this morning

{},
// Avoid creating duplicate companies
const uniqueCompanies = uniqBy(companies, 'domainName');
const conditions = uniqueCompanies.map((companyToCreate) => ({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To check performances 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's actually run in a job, but I agree, maybe we can optimize this, I've try to improve it a bit already

@@ -30,6 +31,7 @@ export class CreateCompanyAndContactJob {
displayName: contact.displayName,
})),
workspaceId,
FieldActorSource.EMAIL,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is also emit from CalendarSaveEventsService so it won't always be EMAIL

Comment on lines +52 to +57
const personRepository =
await this.twentyORMGlobalManager.getRepositoryForWorkspace(
workspaceId,
PersonWorkspaceEntity,
);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we use twentyORMManager instead of twentyORMGlobalManager here?

Comment on lines +163 to +184
// In some jobs the accountOwner is not populated
if (!connectedAccount.accountOwner) {
const workspaceMemberRepository =
await this.twentyORMGlobalManager.getRepositoryForWorkspace(
workspaceId,
WorkspaceMemberWorkspaceEntity,
);

const workspaceMember = await workspaceMemberRepository.findOne({
where: {
id: connectedAccount.accountOwnerId,
},
});

if (!workspaceMember) {
throw new Error(
`Workspace member with id ${connectedAccount.accountOwnerId} not found in workspace ${workspaceId}`,
);
}

const companyDomainNameColumnName =
domainNameFieldMetadata?.type === FieldMetadataType.LINKS
? 'domainNamePrimaryLinkUrl'
: 'domainName';
connectedAccount.accountOwner = workspaceMember;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can modify the code to always pass the connected account with the account owner to the job. But it will be easier once all the raw queries are replaced.

transactionManager?: EntityManager,
): Promise<string> {
const companyId = v4();
const companyRepository =
await this.twentyORMGlobalManager.getRepositoryForWorkspace(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

twentyORMManager instead?

Copy link
Member

@Weiko Weiko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@magrinj magrinj merged commit 11a41b3 into main Aug 7, 2024
7 of 15 checks passed
@magrinj magrinj deleted the feat/created-by-messaging branch August 7, 2024 13:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants