Files
twenty_crm/server/src/integrations/integrations.module.ts
Jérémy M 1144bd13ed feat: onboarding & profile edition (#507)
* feat: wip onboarding

* fix: generate graphql front

* wip: onboarding

* feat: login/register and edit profile

* fix: unused import

* fix: test

* Use DEBUG_MODE instead of STAGE and mute typescript depth exceed errors

* Fix seeds

* Fix onboarding when coming from google

* Fix

* Fix lint

* Fix ci

* Fix tests

---------

Co-authored-by: Charles Bochet <charles@twenty.com>
2023-07-06 17:05:15 -07:00

64 lines
1.8 KiB
TypeScript

import { Global, Module } from '@nestjs/common';
import { fromNodeProviderChain } from '@aws-sdk/credential-providers';
import { EnvironmentModule } from './environment/environment.module';
import { EnvironmentService } from './environment/environment.service';
import { FileStorageModule } from './file-storage/file-storage.module';
import { FileStorageModuleOptions } from './file-storage/interfaces';
import { StorageType } from './environment/interfaces/storage.interface';
/**
* FileStorage Module factory
* @param environment
* @returns FileStorageModuleOptions
*/
const fileStorageModuleFactory = async (
environmentService: EnvironmentService,
): Promise<FileStorageModuleOptions> => {
const type = environmentService.getStorageType();
switch (type) {
case undefined:
case StorageType.Local: {
const storagePath = environmentService.getStorageLocalPath();
return {
type: StorageType.Local,
options: {
storagePath: process.cwd() + '/' + storagePath,
},
};
}
case StorageType.S3: {
const bucketName = environmentService.getStorageS3Name();
const region = environmentService.getStorageS3Region();
return {
type: StorageType.S3,
options: {
bucketName: bucketName ?? '',
credentials: fromNodeProviderChain({
clientConfig: { region },
}),
forcePathStyle: true,
region: region ?? '',
},
};
}
default:
throw new Error(`Invalid storage type (${type}), check your .env file`);
}
};
@Module({
imports: [
EnvironmentModule.forRoot({}),
FileStorageModule.forRootAsync({
useFactory: fileStorageModuleFactory,
inject: [EnvironmentService],
}),
],
exports: [],
providers: [],
})
export class IntegrationsModule {}