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 routes from './routes';
import { getAvailableTimeSlots } from './services/timeslotsService';
import { getHolidays } from './services/holidaysService';
const app = express();

View file

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

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": {
"resolveJsonModule": true,
"target": "es6",
"module": "commonjs",
"outDir": "dist",