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

2
.env
View File

@ -16,7 +16,7 @@ DATABASE_PROVIDER=mysql
DATABASE_URL=mysql://root:Zelen0ku4e@192.168.0.10:3306/cart_dev
# DATABASE_URL=mysql://cart:cartpw@20.101.62.76:3307/cart
#DATABASE_URL=mysql://cart:cartpw@localhost:3306/cart # migrate deploy #dev
# DATABASE_URL=mysql://cart:cartpw@localhost:3306/cart # npx prisma migrate dev
APPLE_ID=
APPLE_TEAM_ID=

1
.gitignore vendored
View File

@ -27,3 +27,4 @@ certificates
content/output/*
baseUrl.txt
public/content/output/*
public/content/output/shifts 2024.1.json

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

View File

@ -20,10 +20,8 @@ const SchedulePage = () => {
const [htmlContent, setHtmlContent] = useState(""); // State to hold fetched HTML content
useEffect(() => {
// Define an async function to fetch the HTML content
const fetchHtmlContent = async () => {
try {
// Replace '/api/schedule' with your actual API endpoint
const response = await axiosInstance.get('/api/schedule?year=2024&month=1', { responseType: 'text' });
setHtmlContent(response.data); // Set the fetched HTML content in state
} catch (error) {

File diff suppressed because one or more lines are too long