Simplify ORM (#6373)
This PR refactors the ORM-Manager to simplify and unify the datasource creation. I'm deprecating all usages if InjectWorkspaceDatasource and InjectWorkspaceRepository as we can't be sure they are up-to-date
This commit is contained in:
@ -44,9 +44,10 @@ export class BlocklistReimportCalendarEventsJob {
|
||||
return;
|
||||
}
|
||||
|
||||
const calendarChannelRepository = await this.twentyORMManager.getRepository(
|
||||
CalendarChannelWorkspaceEntity,
|
||||
);
|
||||
const calendarChannelRepository =
|
||||
await this.twentyORMManager.getRepository<CalendarChannelWorkspaceEntity>(
|
||||
'calendarChannel',
|
||||
);
|
||||
|
||||
await calendarChannelRepository.update(
|
||||
{
|
||||
|
||||
@ -9,15 +9,12 @@ import { Processor } from 'src/engine/integrations/message-queue/decorators/proc
|
||||
import { MessageQueue } from 'src/engine/integrations/message-queue/message-queue.constants';
|
||||
import { MessageQueueService } from 'src/engine/integrations/message-queue/services/message-queue.service';
|
||||
import { DataSourceEntity } from 'src/engine/metadata-modules/data-source/data-source.entity';
|
||||
import { TwentyORMManager } from 'src/engine/twenty-orm/twenty-orm.manager';
|
||||
import { TwentyORMGlobalManager } from 'src/engine/twenty-orm/twenty-orm-global.manager';
|
||||
import {
|
||||
CalendarEventListFetchJob,
|
||||
CalendarEventsImportJobData,
|
||||
} from 'src/modules/calendar/calendar-event-import-manager/jobs/calendar-event-list-fetch.job';
|
||||
import {
|
||||
CalendarChannelSyncStage,
|
||||
CalendarChannelWorkspaceEntity,
|
||||
} from 'src/modules/calendar/common/standard-objects/calendar-channel.workspace-entity';
|
||||
import { CalendarChannelSyncStage } from 'src/modules/calendar/common/standard-objects/calendar-channel.workspace-entity';
|
||||
|
||||
@Processor({
|
||||
queueName: MessageQueue.cronQueue,
|
||||
@ -29,7 +26,7 @@ export class CalendarEventListFetchCronJob {
|
||||
@InjectMessageQueue(MessageQueue.calendarQueue)
|
||||
private readonly messageQueueService: MessageQueueService,
|
||||
private readonly billingService: BillingService,
|
||||
private readonly twentyORMManager: TwentyORMManager,
|
||||
private readonly twentyORMGlobalManager: TwentyORMGlobalManager,
|
||||
) {}
|
||||
|
||||
@Process(CalendarEventListFetchCronJob.name)
|
||||
@ -49,9 +46,9 @@ export class CalendarEventListFetchCronJob {
|
||||
|
||||
for (const workspaceId of workspaceIdsWithDataSources) {
|
||||
const calendarChannelRepository =
|
||||
await this.twentyORMManager.getRepositoryForWorkspace(
|
||||
await this.twentyORMGlobalManager.getRepositoryForWorkspace(
|
||||
workspaceId,
|
||||
CalendarChannelWorkspaceEntity,
|
||||
'calendarChannel',
|
||||
);
|
||||
|
||||
const calendarChannels = await calendarChannelRepository.find({
|
||||
|
||||
@ -6,8 +6,6 @@ import { Any } from 'typeorm';
|
||||
import { InjectMessageQueue } from 'src/engine/integrations/message-queue/decorators/message-queue.decorator';
|
||||
import { MessageQueue } from 'src/engine/integrations/message-queue/message-queue.constants';
|
||||
import { MessageQueueService } from 'src/engine/integrations/message-queue/services/message-queue.service';
|
||||
import { WorkspaceDataSource } from 'src/engine/twenty-orm/datasource/workspace.datasource';
|
||||
import { InjectWorkspaceDatasource } from 'src/engine/twenty-orm/decorators/inject-workspace-datasource.decorator';
|
||||
import { TwentyORMManager } from 'src/engine/twenty-orm/twenty-orm.manager';
|
||||
import { injectIdsInCalendarEvents } from 'src/modules/calendar/calendar-event-import-manager/utils/inject-ids-in-calendar-events.util';
|
||||
import { CalendarEventParticipantService } from 'src/modules/calendar/calendar-event-participant-manager/services/calendar-event-participant.service';
|
||||
@ -26,8 +24,6 @@ import {
|
||||
export class CalendarSaveEventsService {
|
||||
constructor(
|
||||
private readonly twentyORMManager: TwentyORMManager,
|
||||
@InjectWorkspaceDatasource()
|
||||
private readonly workspaceDataSource: WorkspaceDataSource,
|
||||
private readonly calendarEventParticipantService: CalendarEventParticipantService,
|
||||
@InjectMessageQueue(MessageQueue.contactCreationQueue)
|
||||
private readonly messageQueueService: MessageQueueService,
|
||||
@ -119,8 +115,7 @@ export class CalendarSaveEventsService {
|
||||
const savedCalendarEventParticipantsToEmit: CalendarEventParticipantWorkspaceEntity[] =
|
||||
[];
|
||||
|
||||
const workspaceDataSource =
|
||||
await this.twentyORMManager.getWorkspaceDatasource();
|
||||
const workspaceDataSource = await this.twentyORMManager.getDatasource();
|
||||
|
||||
await workspaceDataSource?.transaction(async (transactionManager) => {
|
||||
await calendarEventRepository.save(eventsToSave, {}, transactionManager);
|
||||
|
||||
@ -4,7 +4,6 @@ import { isDefined } from 'class-validator';
|
||||
import isEmpty from 'lodash.isempty';
|
||||
|
||||
import { TwentyORMGlobalManager } from 'src/engine/twenty-orm/twenty-orm-global.manager';
|
||||
import { ViewFieldWorkspaceEntity } from 'src/modules/view/standard-objects/view-field.workspace-entity';
|
||||
|
||||
@Injectable()
|
||||
export class ViewService {
|
||||
@ -29,7 +28,7 @@ export class ViewService {
|
||||
const viewFieldRepository =
|
||||
await this.twentyORMGlobalManager.getRepositoryForWorkspace(
|
||||
workspaceId,
|
||||
ViewFieldWorkspaceEntity,
|
||||
'viewField',
|
||||
);
|
||||
|
||||
for (const viewId of viewsIds) {
|
||||
@ -71,7 +70,7 @@ export class ViewService {
|
||||
const viewFieldRepository =
|
||||
await this.twentyORMGlobalManager.getRepositoryForWorkspace(
|
||||
workspaceId,
|
||||
ViewFieldWorkspaceEntity,
|
||||
'viewField',
|
||||
);
|
||||
const viewsWithField = await viewFieldRepository.find({
|
||||
where: {
|
||||
|
||||
Reference in New Issue
Block a user