importing the data json

This commit is contained in:
Kfir Dayan 2023-04-24 21:34:33 +03:00
parent c7f6066365
commit 64fd4b23c9
7 changed files with 51 additions and 17 deletions

View file

@ -1 +1,7 @@
["2023-05-01","2023-06-12","2023-09-25"] {
"holidays": [
"2023-05-01",
"2023-06-12",
"2023-09-25"
]
}

View file

@ -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"] {
"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"
]
}

View file

@ -1,5 +1,7 @@
import express from 'express'; import express from 'express';
import routes from './routes'; import routes from './routes';
import { getAvailableTimeSlots } from './services/timeslotsService';
import { getHolidays } from './services/holidaysService';
const app = express(); const app = express();

View file

@ -6,7 +6,7 @@ const PORT = process.env.PORT || 3000;
app.listen(PORT, () => { app.listen(PORT, () => {
console.log("STARTING ... ") console.log("STARTING ... ")
if(env === 'development') { if (env === 'development') {
console.log("Generating mock data files") console.log("Generating mock data files")
generateMockDataFiles(); generateMockDataFiles();
} }
@ -21,7 +21,8 @@ const generateMockDataFiles = () => {
} }
if (!fs.existsSync('./data/timeSlots.json')) { if (!fs.existsSync('./data/timeSlots.json')) {
const timeSlots = [ const timeSlots = {
timeSlots: [
"08:00 - 10:00", "08:00 - 10:00",
"10:00 - 12:00", "10:00 - 12:00",
"12:00 - 14:00", "12:00 - 14:00",
@ -29,15 +30,18 @@ const generateMockDataFiles = () => {
"16:00 - 18:00", "16:00 - 18:00",
"18:00 - 20:00" "18:00 - 20:00"
] ]
}
fs.writeFileSync('./data/timeSlots.json', JSON.stringify(timeSlots)); fs.writeFileSync('./data/timeSlots.json', JSON.stringify(timeSlots));
} }
if (!fs.existsSync('./data/holidays.json')) { if (!fs.existsSync('./data/holidays.json')) {
const holidays = [ const holidays = {
holidays: [
"2023-05-01", "2023-05-01",
"2023-06-12", "2023-06-12",
"2023-09-25" "2023-09-25"
] ]
}
fs.writeFileSync('./data/holidays.json', JSON.stringify(holidays)); fs.writeFileSync('./data/holidays.json', JSON.stringify(holidays));
} }
} }

View file

@ -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);
}

View file

@ -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);
}

View file

@ -1,5 +1,6 @@
{ {
"compilerOptions": { "compilerOptions": {
"resolveJsonModule": true,
"target": "es6", "target": "es6",
"module": "commonjs", "module": "commonjs",
"outDir": "dist", "outDir": "dist",