()
| 31 | return function (target: any, propertyKey: string) { |
| 32 | Object.defineProperty(target, propertyKey, { |
| 33 | get() { |
| 34 | const config: ConfigService = this.config; |
| 35 | if (!config) { |
| 36 | throw new Error( |
| 37 | `Config.integer decorator requires 'config: ConfigService' to be injected in ${target.constructor.name}`, |
| 38 | ); |
| 39 | } |
| 40 | const raw = config.get<unknown>(path); |
| 41 | if (raw === undefined || raw === null) return defaultValue; |
| 42 | if (typeof raw === 'number') return Math.floor(raw); |
| 43 | if (typeof raw === 'string') { |
| 44 | const parsed = Number.parseInt(raw, 10); |
| 45 | return Number.isNaN(parsed) ? defaultValue : parsed; |
| 46 | } |
| 47 | return defaultValue; |
| 48 | }, |
| 49 | enumerable: true, |
| 50 | configurable: true, |
| 51 | }); |
no test coverage detected