generate/update and display transport initials correctly in schedule

This commit is contained in:
Dobromir Popov
2024-04-20 13:56:12 +03:00
parent 386deeb71f
commit 9586325bfa

View File

@ -134,12 +134,21 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
groupedShifts[day][time] = [];
}
let { notes, notes_bold } = splitNotes(shift.notes);//.substring(Math.max(shift.notes.lastIndexOf("-"), shift.notes.lastIndexOf("")) + 1).trim() || "";
// let { notes, notes_bold } = splitNotes(shift.notes);//.substring(Math.max(shift.notes.lastIndexOf("-"), shift.notes.lastIndexOf("")) + 1).trim() || "";
let notes = "", notes_bold = "";
if (shift.assignments.some(a => a.isWithTransport)) {
if (shift.requiresTransport) {
notes = "Транспорт: ";
notes_bold = " " + shift.assignments.filter(a => a.isWithTransport).map(a => a.publisher.firstName.charAt(0) + "." + a.publisher.lastName.charAt(0) + ".").join(", ");
}
}
let shiftSchedule = {
date: date,
placeOfEvent: shift.cartEvent.location.name,
time: time,
requiresTransport: shift.requiresTransport,
//bold the text after - in the notes
notes: notes,
notes_bold: notes_bold,
@ -162,6 +171,24 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
console.log(err + " " + JSON.stringify(shifts[i]));
}
for (const day in groupedShifts) {
const times = Object.keys(groupedShifts[day]);
for (const time of times) {
const shift = groupedShifts[day][time][0];
if (shift) {
// Determine the first shift of the day if it requires transport
if (time === times[0] && shift.requiresTransport) { // Check if this is the first time slot of the day
shift.notes = "Докарва количка от Люлин -"; // Update the first shift in the first time slot
}
// Determine the last shift of the day if it requires transport
if (time === times[times.length - 1] && shift.requiresTransport) { // Check if this is the last time slot of the day
shift.notes = "Прибира количка в Люлин -"; // Update the last shift in the last time slot
}
}
}
}
// Create the output object in the format of the second JSON file
const monthlySchedule = {
month: common.getMonthName(shifts[0].startTime.getMonth()),
@ -179,6 +206,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
console.log("shift is null");
continue;
}
let weekday = common.getDayOfWeekName(shift.date);
let monthName = common.getMonthName(shift.date.getMonth());
weekday = weekday.charAt(0).toUpperCase() + weekday.slice(1);