mirror of https://github.com/ghostfolio/ghostfolio
3 changed files with 35 additions and 5 deletions
@ -0,0 +1,25 @@ |
|||
import * as config from '@ghostfolio/common/config'; |
|||
import type { PropertyKey } from '@ghostfolio/common/types'; |
|||
|
|||
import { BadRequestException, Injectable, PipeTransform } from '@nestjs/common'; |
|||
|
|||
@Injectable() |
|||
export class PropertyKeyPipe implements PipeTransform<string, PropertyKey> { |
|||
private readonly allowedKeys: Set<string>; |
|||
|
|||
public constructor() { |
|||
this.allowedKeys = new Set( |
|||
Object.entries(config) |
|||
.filter(([key]) => key.startsWith('PROPERTY_')) |
|||
.map(([, value]) => value as string) |
|||
); |
|||
} |
|||
|
|||
public transform(value: string): PropertyKey { |
|||
if (!this.allowedKeys.has(value)) { |
|||
throw new BadRequestException(`Invalid property key: ${value}`); |
|||
} |
|||
|
|||
return value as PropertyKey; |
|||
} |
|||
} |
|||
Loading…
Reference in new issue