Skip to content

Commit

Permalink
Merge pull request #91 from Team-B1ND/refactor/#90
Browse files Browse the repository at this point in the history
refactor :: sortByGradeNum -> Approval #90
  • Loading branch information
wjzlskxk authored Nov 21, 2024
2 parents ac8723d + 2c0231c commit 43a84c9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
18 changes: 12 additions & 6 deletions src/utils/Out/outGoingDataFilter.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
import { changeRoom } from "utils/Member/changeGrade";
import { OutResponse } from "types/Out/out.type";
import { changeRoom } from 'utils/Member/changeGrade';
import { OutResponse } from 'types/Out/out.type';

export const outGoingDataFilter = (
OffBasePass: OutResponse | undefined,
studentName: string,
selectGrade: number,
selectApproval: string | undefined,
selectMealDemand: number,
selectRoom: string,
selectRoom: string
) => {
const sortedData = OffBasePass?.data
.filter((pass) => pass.student.name.includes(studentName))
.filter((data) => data.student.grade === selectGrade || selectGrade === 0)
.filter((data) => data.status === selectApproval || selectApproval === "")
.filter((data) => data.status === selectApproval || selectApproval === '')
.filter((data) => data.student?.room === changeRoom(selectRoom) || changeRoom(selectRoom) === 0)
.filter(
(data) =>
selectMealDemand === 0 ||
(selectMealDemand === 1 && data.dinnerOrNot) ||
(selectMealDemand === 2 && !data.dinnerOrNot) ||
selectMealDemand === -1,
selectMealDemand === -1
)
.sort((a, b) => {
if (a.status === 'PENDING' && b.status !== 'PENDING') {
return -1;
}
if (a.status !== 'PENDING' && b.status === 'PENDING') {
return 1;
}

if (a.student.grade === b.student.grade) {
if (a.student.room === b.student.room) {
return a.student.number - b.student.number;
Expand All @@ -30,6 +37,5 @@ export const outGoingDataFilter = (
}
return a.student.grade - b.student.grade;
});

return sortedData;
};
15 changes: 11 additions & 4 deletions src/utils/Out/outSleepingDataFilter.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
import { OutResponse } from "types/Out/out.type";
import { changeRoom } from "utils/Member/changeGrade";
import { OutResponse } from 'types/Out/out.type';
import { changeRoom } from 'utils/Member/changeGrade';

export const outSleepingDataFilter = (
OffBaseLeave: OutResponse | undefined,
studentName: string,
selectGrade: number,
selectApproval: string | undefined,
selectRoom: string,
selectRoom: string
) => {
return OffBaseLeave?.data
.filter((pass) => pass.student.name.includes(studentName))
.filter((data) => data.student.grade === selectGrade || selectGrade === 0)
.filter((data) => data.status === selectApproval || selectApproval === "")
.filter((data) => data.status === selectApproval || selectApproval === '')
.filter((data) => data.student?.room === changeRoom(selectRoom) || changeRoom(selectRoom) === 0)
.sort((a, b) => {
if (a.status === 'PENDING' && b.status !== 'PENDING') {
return -1;
}
if (a.status !== 'PENDING' && b.status === 'PENDING') {
return 1;
}

if (a.student.grade === b.student.grade) {
if (a.student.room === b.student.room) {
return a.student.number - b.student.number;
Expand Down

0 comments on commit 43a84c9

Please sign in to comment.