Skip to content

Commit

Permalink
feat(volunteer): period 로 startDate 와 endDate 가공하는 기능 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
kutta97 committed Nov 20, 2023
1 parent cd67962 commit a98a760
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
33 changes: 33 additions & 0 deletions apps/shelter/src/pages/volunteers/search/_utils/period.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { createFormattedTime } from 'shared/utils/date';

import { Period } from '@/pages/volunteers/search/_types/filter';

export const getDatesFromPeriod = (period?: Period) => {
if (!period) {
return {
startDate: undefined,
endDate: undefined,
};
}

const startDate = new Date();
const endDate = new Date();

if (period === 'WITHIN_ONE_DAY') {
endDate.setDate(startDate.getDate() + 1);
}
if (period === 'WITHIN_ONE_WEEK') {
endDate.setDate(startDate.getDate() + 7);
}
if (period === 'WITHIN_ONE_MONTH') {
endDate.setMonth(startDate.getMonth() + 1);
}
if (period === 'WITHIN_THREE_MONTH') {
endDate.setMonth(startDate.getMonth() + 3);
}

return {
startDate: createFormattedTime(startDate, 'YYYY-MM-DD'),
endDate: createFormattedTime(startDate, 'YYYY-MM-DD'),
};
};
7 changes: 5 additions & 2 deletions apps/shelter/src/pages/volunteers/search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@ import useFetchVolunteers from '@/pages/volunteers/_hooks/useFetchVolunteers';
import RecruitmentsSearchFilter from '@/pages/volunteers/search/_components/RecruitmentsSearchFilter';
import { useVolunteerSearch } from '@/pages/volunteers/search/_hooks/useVolunteerSearch';
import { VolunteerSearchFilter } from '@/pages/volunteers/search/_types/filter';
import { getDatesFromPeriod } from '@/pages/volunteers/search/_utils/period';
import { RecruitmentSearchFilter } from '@/types/apis/recruitment';

const getVolunteerSearchRequestFilter = (
searchFilter: Partial<VolunteerSearchFilter>,
): Partial<RecruitmentSearchFilter> => {
const { keyword, period, recruitmentStatus, searchType } = searchFilter;
const { startDate, endDate } = getDatesFromPeriod(period);

return {
keyword,
startDate: period,
endDate: period,
startDate,
endDate,
closedFilter: recruitmentStatus,
keywordFilter: searchType,
};
Expand Down

0 comments on commit a98a760

Please sign in to comment.