diff --git a/data/holidays.json b/data/holidays.json index fa71c8d..94832df 100644 --- a/data/holidays.json +++ b/data/holidays.json @@ -1 +1,7 @@ -["2023-05-01","2023-06-12","2023-09-25"] \ No newline at end of file +{ + "holidays": [ + "2023-05-01", + "2023-06-12", + "2023-09-25" + ] +} \ No newline at end of file diff --git a/data/timeSlots.json b/data/timeSlots.json index 5db1855..5bdab5d 100644 --- a/data/timeSlots.json +++ b/data/timeSlots.json @@ -1 +1,10 @@ -["08:00 - 10:00","10:00 - 12:00","12:00 - 14:00","14:00 - 16:00","16:00 - 18:00","18:00 - 20:00"] \ No newline at end of file +{ + "timeSlots": [ + "08:00 - 10:00", + "10:00 - 12:00", + "12:00 - 14:00", + "14:00 - 16:00", + "16:00 - 18:00", + "18:00 - 20:00" + ] +} \ No newline at end of file diff --git a/src/app.ts b/src/app.ts index 7d3f4e2..d68daa5 100644 --- a/src/app.ts +++ b/src/app.ts @@ -1,5 +1,7 @@ import express from 'express'; import routes from './routes'; +import { getAvailableTimeSlots } from './services/timeslotsService'; +import { getHolidays } from './services/holidaysService'; const app = express(); diff --git a/src/index.ts b/src/index.ts index 44d8401..a915a01 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,7 +6,7 @@ const PORT = process.env.PORT || 3000; app.listen(PORT, () => { console.log("STARTING ... ") - if(env === 'development') { + if (env === 'development') { console.log("Generating mock data files") generateMockDataFiles(); } @@ -21,23 +21,27 @@ const generateMockDataFiles = () => { } if (!fs.existsSync('./data/timeSlots.json')) { - const timeSlots = [ - "08:00 - 10:00", - "10:00 - 12:00", - "12:00 - 14:00", - "14:00 - 16:00", - "16:00 - 18:00", - "18:00 - 20:00" - ] + const timeSlots = { + timeSlots: [ + "08:00 - 10:00", + "10:00 - 12:00", + "12:00 - 14:00", + "14:00 - 16:00", + "16:00 - 18:00", + "18:00 - 20:00" + ] + } fs.writeFileSync('./data/timeSlots.json', JSON.stringify(timeSlots)); } - + if (!fs.existsSync('./data/holidays.json')) { - const holidays = [ - "2023-05-01", - "2023-06-12", - "2023-09-25" - ] + const holidays = { + holidays: [ + "2023-05-01", + "2023-06-12", + "2023-09-25" + ] + } fs.writeFileSync('./data/holidays.json', JSON.stringify(holidays)); } } \ No newline at end of file diff --git a/src/services/holidaysService.ts b/src/services/holidaysService.ts new file mode 100644 index 0000000..2c10268 --- /dev/null +++ b/src/services/holidaysService.ts @@ -0,0 +1,6 @@ +import holidays from '../../data/holidays.json'; + +export function getHolidays() { + // for demo resolving the promise immediately with mock data + return Promise.resolve(holidays); +} \ No newline at end of file diff --git a/src/services/timeslotsService.ts b/src/services/timeslotsService.ts new file mode 100644 index 0000000..71987be --- /dev/null +++ b/src/services/timeslotsService.ts @@ -0,0 +1,6 @@ +import timeSlots from '../../data/timeslots.json'; + +export function getAvailableTimeSlots() { + // for demo resolving the promise immediately with mock data + return Promise.resolve(timeSlots); +} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index b5e0b0d..cc9283e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,5 +1,6 @@ { "compilerOptions": { + "resolveJsonModule": true, "target": "es6", "module": "commonjs", "outDir": "dist",