-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
[backend] rename repository services and replace repository modules by dynamicModule #4536
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
068d818
rename database services to repository
Weiko 425176f
refactor more repositories
Weiko 0b1d048
more refactoring
Weiko 12d731c
followup
Weiko f978c6f
remove unused imports
Weiko 5c426f8
fix
Weiko ca5efce
fix
Weiko 931dc6b
Fix calendar listener being called when flag is off
Weiko 0599adc
remove folders
Weiko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Next step should be to improve this job module, we still have to inject everything here, we could at least delegate this to sub modules