mirror of https://github.com/ghostfolio/ghostfolio
Thomas Kaul
3 years ago
committed by
GitHub
4 changed files with 55 additions and 0 deletions
@ -0,0 +1,50 @@ |
|||
import { Activity } from '@ghostfolio/api/app/order/interfaces/activities.interface'; |
|||
import { |
|||
CallHandler, |
|||
ExecutionContext, |
|||
Injectable, |
|||
NestInterceptor |
|||
} from '@nestjs/common'; |
|||
import { Observable } from 'rxjs'; |
|||
import { map } from 'rxjs/operators'; |
|||
|
|||
@Injectable() |
|||
export class RedactValuesInResponseInterceptor<T> |
|||
implements NestInterceptor<T, any> |
|||
{ |
|||
public constructor() {} |
|||
|
|||
public intercept( |
|||
context: ExecutionContext, |
|||
next: CallHandler<T> |
|||
): Observable<any> { |
|||
return next.handle().pipe( |
|||
map((data: any) => { |
|||
const request = context.switchToHttp().getRequest(); |
|||
const hasImpersonationId = !!request.headers?.['impersonation-id']; |
|||
|
|||
if (hasImpersonationId) { |
|||
if (data.accounts) { |
|||
for (const accountId of Object.keys(data.accounts)) { |
|||
if (data.accounts[accountId]?.balance !== undefined) { |
|||
data.accounts[accountId].balance = null; |
|||
} |
|||
} |
|||
} |
|||
|
|||
if (data.activities) { |
|||
data.activities = data.activities.map((activity: Activity) => { |
|||
if (activity.Account?.balance !== undefined) { |
|||
activity.Account.balance = null; |
|||
} |
|||
|
|||
return activity; |
|||
}); |
|||
} |
|||
} |
|||
|
|||
return data; |
|||
}) |
|||
); |
|||
} |
|||
} |
Loading…
Reference in new issue