feat: manually implement joinColumn (#6022)

This PR introduce a new decorator named `@WorkspaceJoinColumn`, the goal
of this one is to manually declare the join columns inside the workspace
entities, so we don't have to rely on `ObjectRecord` type.

This decorator can be used that way:

```typescript
  @WorkspaceRelation({
    standardId: ACTIVITY_TARGET_STANDARD_FIELD_IDS.company,
    type: RelationMetadataType.MANY_TO_ONE,
    label: 'Company',
    description: 'ActivityTarget company',
    icon: 'IconBuildingSkyscraper',
    inverseSideTarget: () => CompanyWorkspaceEntity,
    inverseSideFieldKey: 'activityTargets',
  })
  @WorkspaceIsNullable()
  company: Relation<CompanyWorkspaceEntity> | null;

  // The argument is the name of the relation above
  @WorkspaceJoinColumn('company')
  companyId: string | null;
```
This commit is contained in:
Jérémy M
2024-06-27 11:41:22 +02:00
committed by GitHub
parent 7eb69a78ef
commit 95c5602a4e
64 changed files with 427 additions and 243 deletions

View File

@ -11,7 +11,6 @@ import { getFlattenedValuesAndValuesStringForBatchRawQuery } from 'src/modules/c
import { CalendarEventParticipant } from 'src/modules/calendar/types/calendar-event';
import { CalendarEventParticipantWorkspaceEntity } from 'src/modules/calendar/standard-objects/calendar-event-participant.workspace-entity';
import { AddPersonIdAndWorkspaceMemberIdService } from 'src/modules/calendar-messaging-participant/services/add-person-id-and-workspace-member-id/add-person-id-and-workspace-member-id.service';
import { ObjectRecord } from 'src/engine/workspace-manager/workspace-sync-metadata/types/object-record';
import { InjectWorkspaceRepository } from 'src/engine/twenty-orm/decorators/inject-workspace-repository.decorator';
import { WorkspaceRepository } from 'src/engine/twenty-orm/repository/workspace.repository';
@ -28,10 +27,10 @@ export class CalendarEventParticipantService {
) {}
public async updateCalendarEventParticipantsAfterPeopleCreation(
createdPeople: ObjectRecord<PersonWorkspaceEntity>[],
createdPeople: PersonWorkspaceEntity[],
workspaceId: string,
transactionManager?: EntityManager,
): Promise<ObjectRecord<CalendarEventParticipantWorkspaceEntity>[]> {
): Promise<CalendarEventParticipantWorkspaceEntity[]> {
const participants = await this.calendarEventParticipantRepository.find({
where: {
handle: Any(createdPeople.map((person) => person.email)),
@ -88,7 +87,7 @@ export class CalendarEventParticipantService {
calendarEventParticipants: CalendarEventParticipant[],
workspaceId: string,
transactionManager?: EntityManager,
): Promise<ObjectRecord<CalendarEventParticipantWorkspaceEntity>[]> {
): Promise<CalendarEventParticipantWorkspaceEntity[]> {
if (calendarEventParticipants.length === 0) {
return [];
}