Skip to content

Commit

Permalink
Merge pull request #92 from Together42/rotation-hotfix
Browse files Browse the repository at this point in the history
hotfix: change default attendees
  • Loading branch information
seo-wo authored Apr 30, 2024
2 parents 76dd518 + 79e40bc commit 4db34bc
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 69 deletions.
3 changes: 2 additions & 1 deletion src/rotation/rotations.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,8 @@ export class RotationsService {
const day = new Date(year, month - 1, i).getDate();

if (!holidayArrayOfMonth.includes(day)) {
const tmpDayObject: DayObject = { day, arr: [0, 0] };
// const tmpDayObject: DayObject = { day, arr: [0, 0] };
const tmpDayObject: DayObject = { day, arr: [0] };

tmpWeekArray.push(tmpDayObject);

Expand Down
136 changes: 68 additions & 68 deletions src/rotation/utils/rotation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,74 +113,74 @@ export function createRotation(
monthArrayInfo[i][j].arr[arrIndex++] = participant1.userId;
}

shuffle(rotationAttendeeInfo);
sortByArray(rotationAttendeeInfo);

let participant2 = undefined;
for (let k = 0; k < rotationAttendeeInfo.length; k++) {
if (
rotationAttendeeInfo[k].attended < participation &&
!rotationAttendeeInfo[k].attendLimit.includes(
monthArrayInfo[i][j].day,
) &&
!monthArrayInfo[i][j].arr.includes(rotationAttendeeInfo[k].userId)
) {
participant2 = rotationAttendeeInfo[k];
participant2.attended += 1;
break;
}
}
if (canDuplicate && participant2 === undefined) {
for (let k = 0; k < rotationAttendeeInfo.length; k++) {
if (
rotationAttendeeInfo[k].attended < participation + 1 &&
!rotationAttendeeInfo[k].attendLimit.includes(
monthArrayInfo[i][j].day,
) &&
!monthArrayInfo[i][j].arr.includes(rotationAttendeeInfo[k].userId)
) {
participant2 = rotationAttendeeInfo[k];
participant2.attended += 1;
break;
}
}
}
if (participant2 === undefined) {
participation += 1;
if (j > 0) {
j -= 1;
} else {
j = -1;
}
if (participant1 && isLooped === false) {
if (isLoopedAgain === true) {
participation -= 1;
isLoopedAgain = false;
continue;
}
const index = rotationAttendeeInfo.findIndex(
(obj) => obj.userId === participant1.userId,
);
continueIndex = index;
checkContinue = true;
isLooped = true;
isLoopedAgain = true;
participant1.attended -= 1;
monthArrayInfo[i][j + 1].arr[0] = 0;
} else if (isLooped) {
participation -= 1;
isLooped = false;
isLoopedAgain = false;
j += 1;
}
continue;
} else {
continueIndex = 0;
checkContinue = false;
isLooped = false;
isLoopedAgain = false;
monthArrayInfo[i][j].arr[arrIndex--] = participant2.userId;
}
// shuffle(rotationAttendeeInfo);
// sortByArray(rotationAttendeeInfo);
//
// let participant2 = undefined;
// for (let k = 0; k < rotationAttendeeInfo.length; k++) {
// if (
// rotationAttendeeInfo[k].attended < participation &&
// !rotationAttendeeInfo[k].attendLimit.includes(
// monthArrayInfo[i][j].day,
// ) &&
// !monthArrayInfo[i][j].arr.includes(rotationAttendeeInfo[k].userId)
// ) {
// participant2 = rotationAttendeeInfo[k];
// participant2.attended += 1;
// break;
// }
// }
// if (canDuplicate && participant2 === undefined) {
// for (let k = 0; k < rotationAttendeeInfo.length; k++) {
// if (
// rotationAttendeeInfo[k].attended < participation + 1 &&
// !rotationAttendeeInfo[k].attendLimit.includes(
// monthArrayInfo[i][j].day,
// ) &&
// !monthArrayInfo[i][j].arr.includes(rotationAttendeeInfo[k].userId)
// ) {
// participant2 = rotationAttendeeInfo[k];
// participant2.attended += 1;
// break;
// }
// }
// }
// if (participant2 === undefined) {
// participation += 1;
// if (j > 0) {
// j -= 1;
// } else {
// j = -1;
// }
// if (participant1 && isLooped === false) {
// if (isLoopedAgain === true) {
// participation -= 1;
// isLoopedAgain = false;
// continue;
// }
// const index = rotationAttendeeInfo.findIndex(
// (obj) => obj.userId === participant1.userId,
// );
// continueIndex = index;
// checkContinue = true;
// isLooped = true;
// isLoopedAgain = true;
// participant1.attended -= 1;
// monthArrayInfo[i][j + 1].arr[0] = 0;
// } else if (isLooped) {
// participation -= 1;
// isLooped = false;
// isLoopedAgain = false;
// j += 1;
// }
// continue;
// } else {
// continueIndex = 0;
// checkContinue = false;
// isLooped = false;
// isLoopedAgain = false;
// monthArrayInfo[i][j].arr[arrIndex--] = participant2.userId;
// }
}
}

Expand Down

0 comments on commit 4db34bc

Please sign in to comment.