From 89bf3ed5d87eb0d01b5576fcf855937c384e56c7 Mon Sep 17 00:00:00 2001 From: dzgierski19 Date: Tue, 18 Jun 2024 09:45:19 +0200 Subject: [PATCH] moved all config --- .../weather/app/AxiosClient/ConfigSchema.ts | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/domains/weather/app/AxiosClient/ConfigSchema.ts b/src/domains/weather/app/AxiosClient/ConfigSchema.ts index 907258a..9e537a5 100644 --- a/src/domains/weather/app/AxiosClient/ConfigSchema.ts +++ b/src/domains/weather/app/AxiosClient/ConfigSchema.ts @@ -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(schema: ZodSchema, data: Record): 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, +});