Skip to content

Commit

Permalink
moved all config
Browse files Browse the repository at this point in the history
  • Loading branch information
dzgierski19 committed Jun 18, 2024
1 parent fe44bc0 commit 89bf3ed
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/domains/weather/app/AxiosClient/ConfigSchema.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import z, { ZodSchema } from "zod";
import { configDataType } from "./ConfigTypes";
import z from "zod";
import { Validator } from "../Validator";

export class Validator {
static run<T>(schema: ZodSchema<T>, data: Record<string, unknown>): T {
return schema.parse(data);
}
}
export type configDataType = { baseUrl?: string; apiKey?: string };

export const weatherApiConfig = (config: configDataType) => {
Validator.run(z.object({ baseUrl: z.string().url(), apiKey: z.string() }), {
baseUrl: config.baseUrl,
apiKey: config.apiKey,
});
export const getWeatherApiConfig = (config: configDataType) => {
return Validator.run(
z.object({ baseUrl: z.string().url(), apiKey: z.string() }),
{
baseUrl: config.baseUrl,
apiKey: config.apiKey,
}
);
};

export const weatherApiConfig = getWeatherApiConfig({
apiKey: process.env.API_KEY,
baseUrl: process.env.EXTERNAL_API,
});

0 comments on commit 89bf3ed

Please sign in to comment.