Skip to content

Commit 88fe66a

Browse files
fix(common): add unique id to multer (nested options issue)
1 parent e62942a commit 88fe66a

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const MULTER_MODULE_ID = 'MULTER_MODULE_ID';

packages/platform-express/multer/multer.module.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
import { DynamicModule, Module, Provider } from '@nestjs/common';
2+
import { randomStringGenerator } from '../utils/random-string-generator.util';
23
import { MULTER_MODULE_OPTIONS } from './files.constants';
34
import {
45
MulterModuleAsyncOptions,
56
MulterModuleOptions,
67
MulterOptionsFactory,
78
} from './interfaces/files-upload-module.interface';
9+
import { MULTER_MODULE_ID } from './multer.constants';
810

911
@Module({})
1012
export class MulterModule {
1113
static register(options: MulterModuleOptions = {}): DynamicModule {
1214
return {
1315
module: MulterModule,
14-
providers: [{ provide: MULTER_MODULE_OPTIONS, useValue: options }],
16+
providers: [
17+
{ provide: MULTER_MODULE_OPTIONS, useValue: options },
18+
{
19+
provide: MULTER_MODULE_ID,
20+
useValue: randomStringGenerator(),
21+
},
22+
],
1523
exports: [MULTER_MODULE_OPTIONS],
1624
};
1725
}
@@ -20,7 +28,13 @@ export class MulterModule {
2028
return {
2129
module: MulterModule,
2230
imports: options.imports,
23-
providers: this.createAsyncProviders(options),
31+
providers: [
32+
...this.createAsyncProviders(options),
33+
{
34+
provide: MULTER_MODULE_ID,
35+
useValue: randomStringGenerator(),
36+
},
37+
],
2438
exports: [MULTER_MODULE_OPTIONS],
2539
};
2640
}

0 commit comments

Comments
 (0)