diff --git a/.env.example b/.env.example index 119088b..3200f45 100644 --- a/.env.example +++ b/.env.example @@ -28,3 +28,6 @@ PRAYER_TIMES_LATITUDE= #Jabarprov JABARPROV_URL= JABARPROV_KEYWORD= + +#Core Data +CORE_DATA_URL= diff --git a/src/config/config.interface.ts b/src/config/config.interface.ts index 891ab15..84efad6 100644 --- a/src/config/config.interface.ts +++ b/src/config/config.interface.ts @@ -33,4 +33,7 @@ export interface Config { url: string keyword: string } + coreData: { + url: string + } } diff --git a/src/config/config.schema.ts b/src/config/config.schema.ts index c06ee33..050df9b 100644 --- a/src/config/config.schema.ts +++ b/src/config/config.schema.ts @@ -22,4 +22,5 @@ export default Joi.object({ PRAYER_TIMES_LATITUDE: Joi.number().required(), JABARPROV_URL: Joi.string().uri().required(), JABARPROV_KEYWORD: Joi.string().required(), + CORE_DATA_URL: Joi.string().uri().required(), }) diff --git a/src/config/config.ts b/src/config/config.ts index ca0145d..b857e30 100644 --- a/src/config/config.ts +++ b/src/config/config.ts @@ -41,6 +41,9 @@ const config: Config = { url: env.JABARPROV_URL, keyword: env.JABARPROV_KEYWORD, }, + coreData: { + url: env.CORE_DATA_URL, + }, } export default config diff --git a/src/external/coreData.ts b/src/external/coreData.ts new file mode 100644 index 0000000..ae235bb --- /dev/null +++ b/src/external/coreData.ts @@ -0,0 +1,55 @@ +import axios from 'axios' +import winston from 'winston' +import { Config } from '../config/config.interface' + +class CoreData { + constructor(private config: Config, private logger: winston.Logger) {} + + async Banner() { + try { + const response = await axios.get( + this.config.coreData.url + `/banner` + ) + const { data } = response + return data + } catch (error) { + this.logger.error(error) + throw error + } + } + + async Activity(startDate: string, endDate: string) { + try { + const response = await axios.get( + this.config.coreData.url + `/kegiatan`, + { + params: { + start_date: startDate, + end_date: endDate, + }, + } + ) + const { data } = response + return data + } catch (error) { + this.logger.error(error) + throw error + } + } + + async ActivityById(id: string) { + try { + const response = await axios.get( + this.config.coreData.url + `/kegiatan/${id}` + ) + + const { data } = response + return data + } catch (error) { + this.logger.error(error) + throw error + } + } +} + +export default CoreData