forked from twentyhq/twenty
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[backend] rename repository services and replace repository modules b…
…y dynamicModule (twentyhq#4536) * rename database services to repository * refactor more repositories * more refactoring * followup * remove unused imports * fix * fix * Fix calendar listener being called when flag is off * remove folders
- Loading branch information
Showing
79 changed files
with
1,080 additions
and
776 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...ges/twenty-server/src/engine/object-metadata-repository/metadata-to-repository.mapping.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { CalendarChannelEventAssociationRepository } from 'src/modules/calendar/repositories/calendar-channel-event-association.repository'; | ||
import { CalendarChannelRepository } from 'src/modules/calendar/repositories/calendar-channel.repository'; | ||
import { CalendarEventAttendeeRepository } from 'src/modules/calendar/repositories/calendar-event-attendee.repository'; | ||
import { CalendarEventRepository } from 'src/modules/calendar/repositories/calendar-event.repository'; | ||
import { CompanyRepository } from 'src/modules/company/repositories/company.repository'; | ||
import { BlocklistRepository } from 'src/modules/connected-account/repositories/blocklist.repository'; | ||
import { ConnectedAccountRepository } from 'src/modules/connected-account/repositories/connected-account.repository'; | ||
import { MessageChannelMessageAssociationRepository } from 'src/modules/messaging/repositories/message-channel-message-association.repository'; | ||
import { MessageChannelRepository } from 'src/modules/messaging/repositories/message-channel.repository'; | ||
import { MessageParticipantRepository } from 'src/modules/messaging/repositories/message-participant.repository'; | ||
import { MessageThreadRepository } from 'src/modules/messaging/repositories/message-thread.repository'; | ||
import { MessageRepository } from 'src/modules/messaging/repositories/message.repository'; | ||
import { PersonRepository } from 'src/modules/person/repositories/person.repository'; | ||
import { WorkspaceMemberRepository } from 'src/modules/workspace-member/repositories/workspace-member.repository'; | ||
|
||
export const metadataToRepositoryMapping = { | ||
BlocklistObjectMetadata: BlocklistRepository, | ||
CalendarChannelEventAssociationObjectMetadata: | ||
CalendarChannelEventAssociationRepository, | ||
CalendarChannelObjectMetadata: CalendarChannelRepository, | ||
CalendarEventAttendeeObjectMetadata: CalendarEventAttendeeRepository, | ||
CalendarEventObjectMetadata: CalendarEventRepository, | ||
CompanyObjectMetadata: CompanyRepository, | ||
ConnectedAccountObjectMetadata: ConnectedAccountRepository, | ||
MessageChannelMessageAssociationObjectMetadata: | ||
MessageChannelMessageAssociationRepository, | ||
MessageChannelObjectMetadata: MessageChannelRepository, | ||
MessageObjectMetadata: MessageRepository, | ||
MessageParticipantObjectMetadata: MessageParticipantRepository, | ||
MessageThreadObjectMetadata: MessageThreadRepository, | ||
PersonObjectMetadata: PersonRepository, | ||
WorkspaceMemberObjectMetadata: WorkspaceMemberRepository, | ||
}; |
12 changes: 12 additions & 0 deletions
12
...enty-server/src/engine/object-metadata-repository/object-metadata-repository.decorator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Inject } from '@nestjs/common'; | ||
|
||
import { convertClassNameToObjectMetadataName } from 'src/engine/workspace-manager/workspace-sync-metadata/utils/convert-class-to-object-metadata-name.util'; | ||
import { capitalize } from 'src/utils/capitalize'; | ||
|
||
export const InjectObjectMetadataRepository = (objectMetadata: any) => { | ||
const token = `${capitalize( | ||
convertClassNameToObjectMetadataName(objectMetadata.name), | ||
)}Repository`; | ||
|
||
return Inject(token); | ||
}; |
40 changes: 40 additions & 0 deletions
40
.../twenty-server/src/engine/object-metadata-repository/object-metadata-repository.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { Global, Module, DynamicModule, Provider } from '@nestjs/common'; | ||
|
||
import { metadataToRepositoryMapping } from 'src/engine/object-metadata-repository/metadata-to-repository.mapping'; | ||
import { WorkspaceDataSourceModule } from 'src/engine/workspace-datasource/workspace-datasource.module'; | ||
import { WorkspaceDataSourceService } from 'src/engine/workspace-datasource/workspace-datasource.service'; | ||
import { convertClassNameToObjectMetadataName } from 'src/engine/workspace-manager/workspace-sync-metadata/utils/convert-class-to-object-metadata-name.util'; | ||
import { capitalize } from 'src/utils/capitalize'; | ||
|
||
@Global() | ||
@Module({}) | ||
export class ObjectMetadataRepositoryModule { | ||
static forFeature(objectMetadatas): DynamicModule { | ||
const providers: Provider[] = objectMetadatas.map((objectMetadata) => { | ||
const repositoryClass = metadataToRepositoryMapping[objectMetadata.name]; | ||
|
||
if (!repositoryClass) { | ||
throw new Error(`No repository found for ${objectMetadata.name}`); | ||
} | ||
|
||
return { | ||
provide: `${capitalize( | ||
convertClassNameToObjectMetadataName(objectMetadata.name), | ||
)}Repository`, | ||
useFactory: ( | ||
workspaceDataSourceService: WorkspaceDataSourceService, | ||
) => { | ||
return new repositoryClass(workspaceDataSourceService); | ||
}, | ||
inject: [WorkspaceDataSourceService], | ||
}; | ||
}); | ||
|
||
return { | ||
module: ObjectMetadataRepositoryModule, | ||
imports: [WorkspaceDataSourceModule], | ||
providers: [...providers], | ||
exports: providers, | ||
}; | ||
} | ||
} |
39 changes: 3 additions & 36 deletions
39
packages/twenty-server/src/modules/calendar/calendar.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,8 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { TypeOrmModule } from '@nestjs/typeorm'; | ||
|
||
import { FeatureFlagEntity } from 'src/engine/modules/feature-flag/feature-flag.entity'; | ||
import { EnvironmentModule } from 'src/engine/integrations/environment/environment.module'; | ||
import { CreateCompaniesAndContactsModule } from 'src/modules/connected-account/auto-companies-and-contacts-creation/create-company-and-contact/create-company-and-contact.module'; | ||
import { BlocklistModule } from 'src/modules/connected-account/repositories/blocklist/blocklist.module'; | ||
import { ConnectedAccountModule } from 'src/modules/connected-account/repositories/connected-account/connected-account.module'; | ||
import { CalendarChannelEventAssociationModule } from 'src/modules/calendar/repositories/calendar-channel-event-association/calendar-channel-event-assocation.module'; | ||
import { CalendarChannelModule } from 'src/modules/calendar/repositories/calendar-channel/calendar-channel.module'; | ||
import { CalendarEventAttendeeModule } from 'src/modules/calendar/repositories/calendar-event-attendee/calendar-event-attendee.module'; | ||
import { CalendarEventModule } from 'src/modules/calendar/repositories/calendar-event/calendar-event.module'; | ||
import { CalendarEventCleanerModule } from 'src/modules/calendar/services/calendar-event-cleaner/calendar-event-cleaner.module'; | ||
import { GoogleCalendarFullSyncService } from 'src/modules/calendar/services/google-calendar-full-sync.service'; | ||
import { GoogleCalendarClientProvider } from 'src/modules/calendar/services/providers/google-calendar/google-calendar.provider'; | ||
import { CompanyModule } from 'src/modules/messaging/repositories/company/company.module'; | ||
import { PersonModule } from 'src/modules/person/repositories/person/person.module'; | ||
import { WorkspaceMemberModule } from 'src/modules/workspace-member/repositories/workspace-member/workspace-member.module'; | ||
import { WorkspaceDataSourceModule } from 'src/engine/workspace-datasource/workspace-datasource.module'; | ||
|
||
@Module({ | ||
imports: [ | ||
EnvironmentModule, | ||
WorkspaceDataSourceModule, | ||
ConnectedAccountModule, | ||
CalendarChannelModule, | ||
CalendarChannelEventAssociationModule, | ||
CalendarEventModule, | ||
CalendarEventAttendeeModule, | ||
CreateCompaniesAndContactsModule, | ||
WorkspaceMemberModule, | ||
TypeOrmModule.forFeature([FeatureFlagEntity], 'core'), | ||
CompanyModule, | ||
PersonModule, | ||
BlocklistModule, | ||
CalendarEventCleanerModule, | ||
], | ||
providers: [GoogleCalendarFullSyncService, GoogleCalendarClientProvider], | ||
exports: [GoogleCalendarFullSyncService], | ||
imports: [], | ||
providers: [], | ||
exports: [], | ||
}) | ||
export class CalendarModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 3 additions & 9 deletions
12
...es/twenty-server/src/modules/calendar/commands/workspace-calendar-sync-commands.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 0 additions & 11 deletions
11
...positories/calendar-channel-event-association/calendar-channel-event-assocation.module.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 0 additions & 11 deletions
11
...enty-server/src/modules/calendar/repositories/calendar-channel/calendar-channel.module.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 0 additions & 11 deletions
11
...c/modules/calendar/repositories/calendar-event-attendee/calendar-event-attendee.module.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.