import/parse and generate respects withTransport and requiresTransport properties. parsing rransport initials

This commit is contained in:
Dobromir Popov
2024-03-05 23:49:23 +02:00
parent 1dfd30afa2
commit cf17cc74a2
5 changed files with 41 additions and 13 deletions

View File

@ -11,5 +11,5 @@ TELEGRAM_BOT=true
SSL_KEY=./certificates/localhost-key.pem
SSL_CERT=./certificates/localhost.pem
DATABASE_URL=mysql://root:Zelen0ku4e@192.168.0.10:3306/cart_dev
# DATABASE_URL=mysql://cart:cartpw@localhost:3306/cart
# DATABASE_URL=mysql://root:Zelen0ku4e@192.168.0.10:3306/cart_dev
DATABASE_URL=mysql://cart:cartpw@localhost:3306/cart

View File

@ -194,17 +194,31 @@ function ShiftComponent({ shift, onShiftSelect, isSelected, onPublisherSelect, a
}
}
function toggleTransport(id: any): void {
throw new Error('Function not implemented.');
}
return (
<div key={index}
className={`flow space-x-2 rounded-md px-2 py-1 my-1 ${ass.isConfirmed ? 'bg-yellow-100' : 'bg-gray-100'} ${borderStyles}`}
className={`flow space-x-2 rounded-md px-2 py-1 my-1 ${ass.isConfirmed ? 'bg-green-100' : 'bg-gray-100'} ${borderStyles}`}
>
<div className="flex justify-between items-center" onClick={() => handlePublisherClick(ass.publisher)}>
<span className="text-gray-700">{publisherInfo.firstName} {publisherInfo.lastName}</span>
<button onClick={() => removeAssignment(ass.id)}
className="text-white bg-red-500 hover:bg-red-600 px-3 py-1 ml-2 rounded-md"
>
махни
</button>
<div className="flex items-left" >
{/* //if shift.isWithTransport, add trnsport button toggle, which sets ass.isWithTransportIn */}
{shift.requiresTransport &&
(
<button onClick={() => toggleTransport(ass.id)} className={`text-white hover:bg-orange-600 px-3 py-1 ml-2 rounded-md ${ass.isWithTransport ? 'bg-green-500' : 'bg-orange-500'}`} >
транспорт
</button>
)
}
<button onClick={() => removeAssignment(ass.id)} className="text-white bg-red-500 hover:bg-red-600 px-3 py-1 ml-2 rounded-md" >
махни
</button>
</div>
</div>
</div>
);

View File

@ -178,7 +178,8 @@ async function GenerateSchedule(axios: Axios, date: string, copyFromPreviousMont
shiftNr++;
const __shiftName = String(shiftStart.getHours()).padStart(2, "0") + ":" + String(shiftStart.getMinutes()).padStart(2, "0") + " - " + String(shiftEnd.getHours()).padStart(2, "0") + ":" + String(shiftEnd.getMinutes()).padStart(2, "0");
shiftAssignments = [];
console.log("[shift " + shiftNr + "] " + __shiftName);
let isTransportRequired = shiftNr == 1 || shiftEnd.getTime() == endTime.getTime();
console.log("[shift " + shiftNr + "] " + __shiftName + ", transport: " + (isTransportRequired ? "yes" : "no") + ", " + shiftStart.toLocaleTimeString() + " - " + shiftEnd.toLocaleTimeString() + " (end time: " + endTime.toLocaleTimeString() + ", " + event.shiftDuration + " min)");
if (autoFill || copyFromPreviousMonth) {
// ###########################################
@ -395,6 +396,7 @@ async function GenerateSchedule(axios: Axios, date: string, copyFromPreviousMont
startTime: shiftStart,
endTime: shiftEnd,
name: event.dayofweek + " " + shiftStart.toLocaleTimeString() + " - " + shiftEnd.toLocaleTimeString(),
requiresTransport: isTransportRequired,
cartEvent: {
connect: {
id: event.id,

View File

@ -95,6 +95,9 @@ export const getServerSideProps = async (context) => {
if (availability.startTime) {
availability.startTime = availability.startTime.toISOString();
availability.endTime = availability.endTime.toISOString();
if (availability.dateOfEntry) {
availability.dateOfEntry = availability.dateOfEntry.toISOString();
}
}
});

View File

@ -404,20 +404,21 @@ exports.processEvents = async function (events, year, monthNumber, progressCallb
s.cartEventId === cartEvent.id &&
new Date(s.startTime).getTime() === new Date(start).getTime()
);
// get only hh:mm from the date
let isTransportRequired = event.shiftNr == 1 || end.toLocaleTimeString().substring(0, 5) == cartEvent.endTime.toLocaleTimeString().substring(0, 5);
if (!shift) {
//if shiftnr = 1, notes = "Докарва" + event.transport
//if shiftnr = 8, notes = "Взема" + event.transport
let note = event.shiftNr === 1 ? "Докарва количка от Люлин - " + event.transport :
event.shiftNr === 6 ? "Прибира количка в Люлин - " + event.transport : "";
let note = isTransportRequired ? event.transport : "";
// "Докарва количка от Люлин/Прибира количка в Люлин"
const shiftEntity = await prisma.shift.create({
data: {
name: event.dayOfWeek + " " + event.dayOfMonth + ", " + start.toLocaleTimeString() + " - " + end.toLocaleTimeString(),
startTime: start,
endTime: end,
notes: note,
requiresTransport: isTransportRequired,
cartEvent: {
connect: {
id: cartEvent.id,
@ -506,6 +507,13 @@ exports.processEvents = async function (events, year, monthNumber, progressCallb
}
if (location != null && publisher != null && shift != null) {
let isWithTransport = false;
if (isTransportRequired) {
const pubInitials = publisher.firstName[0] + publisher.lastName[0];
// get cotent after last - or long dash-`-` and remove spaces, trim dots and make lowercase
let transportInitials = event.transport.split("-").pop().replace(/[\s.]/g, "").toUpperCase();
isWithTransport = transportInitials.includes(pubInitials);
}
const assignment = await prisma.assignment.create({
data: {
//publisherId: publisher.id,
@ -520,6 +528,7 @@ exports.processEvents = async function (events, year, monthNumber, progressCallb
id: shift.id,
},
},
isWithTransport: isWithTransport,
},
});
//ToDo: fix findPublisherAvailability and creation of availabilities