feat: drop calendar repository (#5824)
This PR is replacing and removing all the raw queries and repositories with the new `TwentyORM` and injection system using `@InjectWorkspaceRepository`. Some logic that was contained inside repositories has been moved to the services. In this PR we're only replacing repositories for calendar feature. --------- Co-authored-by: Weiko <corentin@twenty.com> Co-authored-by: bosiraphael <raphael.bosi@gmail.com> Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
@ -0,0 +1,39 @@
|
||||
import { Inject, Type } from '@nestjs/common';
|
||||
import { ModuleRef, createContextId } from '@nestjs/core';
|
||||
import { Injector } from '@nestjs/core/injector/injector';
|
||||
|
||||
export class LoadServiceWithWorkspaceContext {
|
||||
private readonly injector = new Injector();
|
||||
|
||||
constructor(
|
||||
@Inject(ModuleRef)
|
||||
private readonly moduleRef: ModuleRef,
|
||||
) {}
|
||||
|
||||
async load<T>(service: T, workspaceId: string): Promise<T> {
|
||||
const modules = this.moduleRef['container'].getModules();
|
||||
const host = [...modules.values()].find((module) =>
|
||||
module.providers.has((service as Type<T>).constructor),
|
||||
);
|
||||
|
||||
if (!host) {
|
||||
throw new Error('Host module not found for the service');
|
||||
}
|
||||
|
||||
const contextId = createContextId();
|
||||
|
||||
if (this.moduleRef.registerRequestByContextId) {
|
||||
this.moduleRef.registerRequestByContextId(
|
||||
{ req: { workspaceId } },
|
||||
contextId,
|
||||
);
|
||||
}
|
||||
|
||||
return this.injector.loadPerContext(
|
||||
service,
|
||||
host,
|
||||
new Map(host.providers),
|
||||
contextId,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user