various fixes to imports and filtering;
some API rewrited
This commit is contained in:
@ -147,7 +147,7 @@ export default function ImportPage() {
|
||||
|
||||
let isOld = false;
|
||||
const row = rawData[i];
|
||||
let email, phone, names, dateOfInput, oldAvDeleted = false, isTrained = false, desiredShiftsPerMonth = 4, isActive = false, publisherType = PublisherType.Publisher;
|
||||
let email, phone, names, dateOfInput, oldAvDeleted = false, isTrained = false, desiredShiftsPerMonth = 4, isActive = true, publisherType = PublisherType.Publisher;
|
||||
//const date = new Date(row[0]).toISOS{tring().slice(0, 10);
|
||||
if (mode.mainMode == MODE_PUBLISHERS1) {
|
||||
|
||||
@ -173,19 +173,25 @@ export default function ImportPage() {
|
||||
}
|
||||
else {
|
||||
dateOfInput = common.excelSerialDateToDate(row[0]);
|
||||
//substract 1 day, because excel serial date is 1 day ahead
|
||||
dateOfInput.setDate(dateOfInput.getDate() - 1);
|
||||
email = row[1];
|
||||
names = row[2].normalize('NFC').split(/[, ]+/);
|
||||
}
|
||||
|
||||
//remove special characters from name
|
||||
const day = new Date();
|
||||
let day = new Date();
|
||||
day.setDate(1); // Set to the first day of the month to avoid overflow
|
||||
if (importDate && importDate.value) {
|
||||
let monthOfIportInfo = common.getMonthInfo(importDate.value);
|
||||
day = monthOfIportInfo.firstMonday;
|
||||
}
|
||||
|
||||
dateOfInput = new Date(dateOfInput);
|
||||
// Calculate the total month difference by considering the year difference
|
||||
let totalMonthDifference = (day.getFullYear() - dateOfInput.getFullYear()) * 12 + (day.getMonth() - dateOfInput.getMonth());
|
||||
// If the total month difference is 2 or more, set isOld to true
|
||||
if (totalMonthDifference >= 0) {
|
||||
if (totalMonthDifference >= 2) {
|
||||
isOld = true;
|
||||
}
|
||||
|
||||
@ -195,7 +201,7 @@ export default function ImportPage() {
|
||||
let personNames = names.join(' ');
|
||||
try {
|
||||
try {
|
||||
const select = "&select=id,firstName,lastName,phone,isTrained,desiredShiftsPerMonth,isActive,type,availabilities";
|
||||
const select = "&select=id,firstName,lastName,email,phone,isTrained,desiredShiftsPerMonth,isActive,type,availabilities";
|
||||
const responseByName = await axiosInstance.get(`/api/?action=findPublisher&filter=${names.join(' ')}${select}`);
|
||||
let existingPublisher = responseByName.data[0];
|
||||
if (!existingPublisher) {
|
||||
@ -325,12 +331,13 @@ export default function ImportPage() {
|
||||
const availabilities: Availability[] = [];
|
||||
|
||||
for (let j = 3; j < header.length; j++) {
|
||||
|
||||
|
||||
|
||||
const dayHeader = header[j];
|
||||
|
||||
const shifts = row[j];
|
||||
if (!shifts || shifts === 'Не мога') {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
// specific date: Седмица (17-23 април) [Четвъртък ]
|
||||
// const regex = /^Седмица \((\d{1,2})-(\d{1,2}) (\S+)\) \[(\S+)\]$/;
|
||||
@ -373,8 +380,8 @@ export default function ImportPage() {
|
||||
const dayOfWeek = common.getDayOfWeekIndex(dayOfWeekStr);
|
||||
common.logger.debug("processing availability for week " + weekNr + ": " + weekStart + "." + month + "." + dayOfWeekStr)
|
||||
// Create a new Date object for the start date of the range
|
||||
const day = new Date();
|
||||
day.setDate(1); // Set to the first day of the month to avoid overflow
|
||||
// day = new Date();
|
||||
// day.setDate(1); // Set to the first day of the month to avoid overflow
|
||||
|
||||
//day.setMonth(day.getMonth() + 1); // Add one month to the date, because we assume we are p
|
||||
day.setMonth(common.getMonthIndex(month));
|
||||
@ -385,10 +392,9 @@ export default function ImportPage() {
|
||||
common.logger.debug("parsing availability input: " + shifts); // Output: 0 (Sunday)
|
||||
const dayOfWeekName = common.getDayOfWeekNameEnEnumForDate(day);
|
||||
|
||||
let dayOfMonth = day.getDate();
|
||||
const name = `${names[0]} ${names[1]}`;
|
||||
const intervals = shifts.split(",");
|
||||
|
||||
if (!shifts || shifts === 'Не мога') {
|
||||
continue;
|
||||
}
|
||||
if (!oldAvDeleted && personId) {
|
||||
if (mode.schedule && email) {
|
||||
common.logger.debug(`Deleting existing availabilities for publisher ${personId} for date ${day}`);
|
||||
@ -402,6 +408,11 @@ export default function ImportPage() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let dayOfMonth = day.getDate();
|
||||
const name = `${names[0]} ${names[1]}`;
|
||||
const intervals = shifts.split(",");
|
||||
|
||||
let parsedIntervals: { end: number; }[] = [];
|
||||
intervals.forEach(interval => {
|
||||
// Summer format: (12:00-14:00)
|
||||
@ -451,7 +462,7 @@ export default function ImportPage() {
|
||||
// Iterate over intervals
|
||||
for (let i = 1; i < parsedIntervals.length; i++) {
|
||||
if (parsedIntervals[i].start > maxEndTime) {
|
||||
availabilities.push(createAvailabilityObject(minStartTime, maxEndTime, day, dayOfWeekName, dayOfMonth, weekNr, personId, name, isOld));
|
||||
availabilities.push(createAvailabilityObject(minStartTime, maxEndTime, day, dayOfWeekName, dayOfMonth, weekNr, personId, name, isOld, dateOfInput));
|
||||
minStartTime = parsedIntervals[i].start;
|
||||
maxEndTime = parsedIntervals[i].end;
|
||||
} else {
|
||||
@ -460,7 +471,7 @@ export default function ImportPage() {
|
||||
}
|
||||
|
||||
// Add the last availability
|
||||
availabilities.push(createAvailabilityObject(minStartTime, maxEndTime, day, dayOfWeekName, dayOfMonth, weekNr, personId, name, isOld));
|
||||
availabilities.push(createAvailabilityObject(minStartTime, maxEndTime, day, dayOfWeekName, dayOfMonth, weekNr, personId, name, isOld, dateOfInput));
|
||||
|
||||
}
|
||||
else {
|
||||
@ -477,7 +488,7 @@ export default function ImportPage() {
|
||||
// Experimental: add availabilities to all publishers with the same email
|
||||
//check if more than one publisher has the same email, and add the availabilities to both
|
||||
//check existing publishers with the same email
|
||||
var sameNamePubs = axiosInstance.get(`/api/?action=findPublisher&all=true&email=${email}&select=id,firstName,lastName`);
|
||||
var sameNamePubs = axiosInstance.get(`/api/?action=findPublisher&all=true&email=${email}&select=id,firstName,lastName,email`);
|
||||
sameNamePubs.then(function (response) {
|
||||
common.logger.debug("same name pubs: " + response.data.length);
|
||||
if (response.data.length > 1) {
|
||||
@ -513,7 +524,9 @@ export default function ImportPage() {
|
||||
};
|
||||
|
||||
// Function to create an availability object
|
||||
function createAvailabilityObject(start: any, end: number, day: Date, dayOfWeekName: any, dayOfMonth: number, weekNr: number, personId: string, name: string, isFromPreviousMonth: boolean): Availability {
|
||||
function createAvailabilityObject(start: any, end: number,
|
||||
day: Date, dayOfWeekName: any, dayOfMonth: number, weekNr: number, personId: string, name: string,
|
||||
isFromPreviousMonth: boolean, dateOfInput: Date): Availability {
|
||||
const formatTime = (time) => {
|
||||
const paddedTime = String(time).padStart(4, '0');
|
||||
return new Date(day.getFullYear(), day.getMonth(), day.getDate(), parseInt(paddedTime.substr(0, 2)), parseInt(paddedTime.substr(2, 4)));
|
||||
@ -533,6 +546,7 @@ export default function ImportPage() {
|
||||
endTime,
|
||||
isActive: true,
|
||||
type: AvailabilityType.OneTime,
|
||||
dateOfEntry: dateOfInput,
|
||||
isWithTransportIn: false, // Add the missing 'isWithTransport' property
|
||||
isWithTransportOut: false, // Add the missing 'isWithTransport' property
|
||||
isFromPreviousAssignment: false, // Add the missing 'isFromPreviousAssignment' property
|
||||
|
Reference in New Issue
Block a user