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

@ -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