fix schedule

This commit is contained in:
Dobromir Popov
2024-03-02 19:11:23 +02:00
parent 6c6f8f41d0
commit c984490980
5 changed files with 14 additions and 20 deletions

View File

@ -43,21 +43,17 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
if (req.method === 'GET') {
const { year, month } = req.query;
let monthIndex = parseInt(month as string) - 1;
const monthInfo = common.getMonthDatesInfo(new Date(year, month, 1));
let fromDate = monthInfo.firstMonday;
const toDate = monthInfo.lastSunday;
// Ensure fromDate is not in the past
const today = new Date();
today.setHours(0, 0, 0, 0); // Set time to midnight for accurate comparison
if (fromDate < today) {
fromDate = today;
}
// const { year, month } = req.query;
// let monthIndex = parseInt(month as string) - 1;
// const monthInfo = common.getMonthDatesInfo(new Date(year, month, 1));
// let fromDate = monthInfo.firstMonday;
// const toDate = monthInfo.lastSunday;
let fromDate = new Date();
fromDate.setDate(fromDate.getDate() - 1);
fromDate.setHours(0, 0, 0, 0);
let toDate = new Date(fromDate);
toDate.setDate(toDate.getDate() + 30);
try {
@ -167,11 +163,11 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
fs.mkdirSync(outputPath, { recursive: true });
}
fs.writeFileSync(path.join(outputPath, `shifts ${year}.${month}.json`), JSON.stringify(monthlySchedule), 'utf8');
//fs.writeFileSync(path.join(outputPath, `shifts ${year}.${month}.json`), JSON.stringify(monthlySchedule), 'utf8');
// Load the Handlebars template from a file
const template = fs.readFileSync("./src/templates/schedule.hbs", "utf8");
generateTemplateFile(monthlySchedule, template).then((result) => {
const filename = path.join(outputPath, `schedule ${year}.${month}.html`)
const filename = path.join(outputPath, `schedule.html`)
//fs.writeFileSync(filename, result, "utf8");
res.end(result);
}