diff --git a/components/calendar/ShiftComponent.tsx b/components/calendar/ShiftComponent.tsx index 2638fac..f78f498 100644 --- a/components/calendar/ShiftComponent.tsx +++ b/components/calendar/ShiftComponent.tsx @@ -156,37 +156,43 @@ function ShiftComponent({ shift, onShiftSelect, isSelected, onPublisherSelect, a // Determine border styles let borderStyles = ''; - //if there is no publisherInfo - draw red border - publisher is no longer available for the day! - if (!publisherInfo.availabilities || publisherInfo.availabilities.length == 0) { - borderStyles = 'border-2 border-red-500 '; + if (selectedPublisher && selectedPublisher.id === ass.publisher.id) { + borderStyles += 'border-2 border-blue-300'; // Bottom border for selected publishers } else { - //pub is not available for that shift assignment. - if (publisherInfo.availabilities?.length === 0 || - publisherInfo.availabilities?.every(avail => avail.isFromPreviousAssignment)) { - borderStyles += 'border-l-3 border-r-3 border-orange-500 '; // Top border for manual publishers - } - // checkig if the publisher is available for this assignment - if (publisherInfo.availabilities?.some(av => - av.startTime <= ass.startTime && - av.endTime >= ass.endTime)) { - borderStyles += 'border-t-2 border-red-500 '; // Left border for specific availability conditions + if (publisherInfo.availabilityCount == 0) //user has never the form + { + borderStyles = 'border-2 border-orange-300 '; } + else + //if there is no publisherInfo - draw red border - publisher is no longer available for the day! + if (!publisherInfo.availabilities || publisherInfo.availabilities.length == 0) { + borderStyles = 'border-2 border-red-500 '; + } + else { + + // checkig if the publisher is available for this assignment + if (publisherInfo.availabilities?.some(av => + av.startTime <= shift.startTime && + av.endTime >= shift.endTime)) { + borderStyles += 'border-l-2 border-blue-500 '; // Left border for specific availability conditions + } + + if (publisherInfo.hasUpToDateAvailabilities) { + //add green right border + borderStyles += 'border-r-2 border-green-300'; + } + + //the pub is the same time as last month + // if (publisherInfo.availabilities?.some(av => + // (!av.dayOfMonth || av.isFromPreviousMonth) && + // av.startTime <= ass.startTime && + // av.endTime >= ass.endTime)) { + // borderStyles += 'border-t-2 border-yellow-500 '; // Left border for specific availability conditions + // } + + } - //the pub is the same time as last month - // if (publisherInfo.availabilities?.some(av => - // (!av.dayOfMonth || av.isFromPreviousMonth) && - // av.startTime <= ass.startTime && - // av.endTime >= ass.endTime)) { - // borderStyles += 'border-t-2 border-yellow-500 '; // Left border for specific availability conditions - // } - if (selectedPublisher && selectedPublisher.id === ass.publisher.id) { - borderStyles += 'border-2 border-blue-300'; // Bottom border for selected publishers - } - if (publisherInfo.hasUpToDateAvailabilities) { - //add green right border - borderStyles += 'border-r-2 border-green-300'; - } } return (
{ + shift.assignments.forEach(assignment => { + assignment.publisher.availabilityCount = pubAvCount.find(pub => pub.id === assignment.publisher.id)?._count?.availabilities || 0; + }); + } + ); + console.log("shiftsForDate(" + date + ") - " + shiftsForDate.length + " : " + JSON.stringify(shiftsForDate.map(shift => shift.id))); res.status(200).json(shiftsForDate); @@ -587,7 +608,7 @@ export async function filterPublishers(selectFields, searchText, filterDate, fet //if pub has up-to-date availabilities (with dayOfMonth) for the current month pub.hasUpToDateAvailabilities = pub.availabilities?.some(avail => { - return avail.dayOfMonth != null && avail.startTime >= currentMonthStart && avail.startTime <= currentMonthEnd; + return avail.dayOfMonth != null && avail.startTime >= currentMonthStart; // && avail.startTime <= currentMonthEnd; }); }); diff --git a/pages/cart/calendar/index.tsx b/pages/cart/calendar/index.tsx index eafb16e..2468c02 100644 --- a/pages/cart/calendar/index.tsx +++ b/pages/cart/calendar/index.tsx @@ -187,7 +187,7 @@ export default function CalendarPage({ initialEvents, initialShifts }) { // Finally, sort by (currentMonthAssignments - previousMonthAssignments). return (a.currentMonthAssignments - a.previousMonthAssignments) - (b.currentMonthAssignments - b.previousMonthAssignments); }); - setAvailablePubs(sortedPubs); // Assuming availablePubs is a state managed by useState + setAvailablePubs(sortedPubs); }; const handleSelectedPublisher = (publisher) => { diff --git a/prisma/bl/subqueries.js b/prisma/bl/subqueries.js new file mode 100644 index 0000000..ab557e0 --- /dev/null +++ b/prisma/bl/subqueries.js @@ -0,0 +1,46 @@ + +export const publisherSelectWithAvCount = { + select: { + id: true, + firstName: true, + lastName: true, + email: true, + phone: true, + desiredShiftsPerMonth: true, + }, + include: { + _count: { + select: { + availability: { + where: { + isactive: true + } + } + + } + } + } +} + +export const publisherSelect = { + select: { + id: true, + firstName: true, + lastName: true, + email: true, + phone: true, + desiredShiftsPerMonth: true, + }, +} + +// availability: { +// select: { +// id: true, +// startTime: true, +// endTime: true, +// dayOfMonth: true, +// dayofweek: true, +// isactive: true, +// count: 'Availability_count' +// } +// } \ No newline at end of file diff --git a/prisma/migrations/20240302161855_some_new_fields/migration.sql b/prisma/migrations/20240302161855_some_new_fields/migration.sql new file mode 100644 index 0000000..628dc6c --- /dev/null +++ b/prisma/migrations/20240302161855_some_new_fields/migration.sql @@ -0,0 +1,8 @@ +-- AlterTable +--ALTER TABLE `Availability` ADD COLUMN `dateOfEntry` DATETIME(3) NULL; + +-- AlterTable +ALTER TABLE `Publisher` ADD COLUMN `alwaysAsFamily` BOOLEAN NULL DEFAULT false; + +-- AlterTable +ALTER TABLE `Shift` ADD COLUMN `isPublished` BOOLEAN NOT NULL DEFAULT false; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 04f1bc5..a7668d3 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -103,16 +103,14 @@ model Publisher { isMale Boolean @default(true) isNameForeign Boolean @default(false) - familyHeadId String? // Optional familyHeadId for each family member - familyHead Publisher? @relation("FamilyMember", fields: [familyHeadId], references: [id]) - familyMembers Publisher[] @relation("FamilyMember") - //alwaysAsFamily Boolean? @default(false) // New field to indicate if the publisher always wants to be assigned with the family - type PublisherType @default(Publisher) - town String? - comments String? - reports Report[] - - @@map("Publisher") + familyHeadId String? // Optional familyHeadId for each family member + familyHead Publisher? @relation("FamilyMember", fields: [familyHeadId], references: [id]) + familyMembers Publisher[] @relation("FamilyMember") + alwaysAsFamily Boolean? @default(false) //NEW v1.0.1 // New field to indicate if the publisher always wants to be assigned with the family + type PublisherType @default(Publisher) + town String? + comments String? + reports Report[] } model Availability { @@ -131,12 +129,10 @@ model Availability { isWithTransportOut Boolean @default(false) isFromPreviousAssignment Boolean @default(false) isFromPreviousMonth Boolean @default(false) - repeatWeekly Boolean? // New field to indicate weekly repetition + repeatWeekly Boolean? // New field to indicate weekly repetition // until now dayofweek was used for repetition when dayOfMonth is null repeatFrequency Int? // New field to indicate repetition frequency endDate DateTime? // New field for the end date of repetition - //dateOfEntry DateTime - - @@map("Availability") + //dateOfEntry DateTime? //NEW v1.0.1 trade storage for intuintivity } model CartEvent { @@ -169,7 +165,7 @@ model Shift { //date DateTime reportId Int? @unique Report Report? @relation(fields: [reportId], references: [id]) - //isPublished Boolean @default(false) + isPublished Boolean @default(false) //NEW v1.0.1 @@map("Shift") }