Skip to content

Commit 865f405

Browse files
committed
refactored config function to use objects instead of switch
1 parent 940e2a0 commit 865f405

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

config/config.ts

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,24 @@
1-
import { env } from "../src/typeDefinitions/default.types";
1+
import { env, environment } from "../src/typeDefinitions/default.types";
22
import {
33
RDS_BASE_API_URL,
44
RDS_BASE_STAGING_API_URL,
55
RDS_BASE_DEVELOPMENT_API_URL,
66
} from "../src/constants/urls";
77

88
const config = (env: env) => {
9-
const environment = { RDS_BASE_API_URL: "" };
9+
const environment: environment = {
10+
production: {
11+
RDS_BASE_API_URL: RDS_BASE_API_URL,
12+
},
13+
staging: {
14+
RDS_BASE_API_URL: RDS_BASE_STAGING_API_URL,
15+
},
16+
default: {
17+
RDS_BASE_API_URL: RDS_BASE_DEVELOPMENT_API_URL,
18+
},
19+
};
1020

11-
switch (env.CURRENT_ENVIRONMENT) {
12-
case "production":
13-
environment.RDS_BASE_API_URL = RDS_BASE_API_URL;
14-
break;
15-
16-
case "staging":
17-
environment.RDS_BASE_API_URL = RDS_BASE_STAGING_API_URL;
18-
break;
19-
20-
default:
21-
environment.RDS_BASE_API_URL = RDS_BASE_DEVELOPMENT_API_URL;
22-
}
23-
24-
return environment;
21+
return environment[env.CURRENT_ENVIRONMENT] || environment.default;
2522
};
2623

2724
export default config;

src/typeDefinitions/default.types.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@ export interface env {
22
[key: string]: string;
33
}
44

5+
export interface environment {
6+
[key: string]: variables;
7+
}
8+
9+
export interface variables {
10+
RDS_BASE_API_URL: string;
11+
}
12+
513
export interface discordCommand {
614
name: string;
715
description: string;

0 commit comments

Comments
 (0)