Browse Source

Refactoring

pull/5972/head
Thomas Kaul 1 month ago
parent
commit
8ef21a61a9
  1. 34
      apps/api/src/interceptors/transform-data-source-in-response/transform-data-source-in-response.interceptor.ts

34
apps/api/src/interceptors/transform-data-source-in-response/transform-data-source-in-response.interceptor.ts

@ -16,9 +16,28 @@ import { map } from 'rxjs/operators';
export class TransformDataSourceInResponseInterceptor<T> export class TransformDataSourceInResponseInterceptor<T>
implements NestInterceptor<T, any> implements NestInterceptor<T, any>
{ {
private encodedDataSourceMap: {
[dataSource: string]: string;
} = {};
public constructor( public constructor(
private readonly configurationService: ConfigurationService private readonly configurationService: ConfigurationService
) {} ) {
if (this.configurationService.get('ENABLE_FEATURE_SUBSCRIPTION')) {
this.encodedDataSourceMap = Object.keys(DataSource).reduce(
(encodedDataSourceMap, dataSource) => {
if (!['GHOSTFOLIO', 'MANUAL'].includes(dataSource)) {
encodedDataSourceMap[dataSource] = encodeDataSource(
DataSource[dataSource]
);
}
return encodedDataSourceMap;
},
{}
);
}
}
public intercept( public intercept(
_context: ExecutionContext, _context: ExecutionContext,
@ -31,18 +50,7 @@ export class TransformDataSourceInResponseInterceptor<T>
options: [ options: [
{ {
attribute: 'dataSource', attribute: 'dataSource',
valueMap: Object.keys(DataSource).reduce( valueMap: this.encodedDataSourceMap
(valueMap, dataSource) => {
if (!['MANUAL'].includes(dataSource)) {
valueMap[dataSource] = encodeDataSource(
DataSource[dataSource]
);
}
return valueMap;
},
{}
)
} }
], ],
object: data object: data

Loading…
Cancel
Save