-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
57 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,41 @@ | ||
import type { LoggerService } from '@services/logger.service'; | ||
import { injectable } from 'inversify'; | ||
import { Env } from 'src'; | ||
|
||
@injectable() | ||
export class CosmosConfig {} | ||
export class CosmosConfig { | ||
constructor(private readonly loggerService: LoggerService) {} | ||
|
||
/** | ||
* Get env variables | ||
*/ | ||
public get<T>(value: string): T { | ||
const envValue = process.env[value]; | ||
|
||
if (envValue === 'true') { | ||
return true as T; | ||
} | ||
|
||
if (envValue === 'false') { | ||
return false as T; | ||
} | ||
|
||
if (!Number.isNaN(Number(envValue))) { | ||
return Number(envValue) as T; | ||
} | ||
|
||
return envValue as T; | ||
} | ||
|
||
/** | ||
* Validate if env key exist and then return it | ||
*/ | ||
public getEnvKey(key: string) { | ||
const envKey = Env.EnvKeys[key]; | ||
if (envKey) { | ||
return envKey; | ||
} else { | ||
void this.loggerService.pino.warn(`${key} does not exist in you'r environnement`); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters