Skip to content

Commit

Permalink
feat: external core data (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
ayocodingit authored Mar 10, 2023
1 parent 43e861d commit 4e7b90a
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@ PRAYER_TIMES_LATITUDE=
#Jabarprov
JABARPROV_URL=
JABARPROV_KEYWORD=

#Core Data
CORE_DATA_URL=
3 changes: 3 additions & 0 deletions src/config/config.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,7 @@ export interface Config {
url: string
keyword: string
}
coreData: {
url: string
}
}
1 change: 1 addition & 0 deletions src/config/config.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
})
3 changes: 3 additions & 0 deletions src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ const config: Config = {
url: env.JABARPROV_URL,
keyword: env.JABARPROV_KEYWORD,
},
coreData: {
url: env.CORE_DATA_URL,
},
}

export default config
55 changes: 55 additions & 0 deletions src/external/coreData.ts
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 4e7b90a

Please sign in to comment.