Skip to content

Commit e563923

Browse files
committed
chore: move setQueryOptions to utils/query
1 parent 7c79d1e commit e563923

File tree

3 files changed

+45
-42
lines changed

3 files changed

+45
-42
lines changed

apps/frontend/src/hooks/useFetchProviderNews.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useGetAllNewsByProviderQuery } from 'src/features/news';
2-
import { setQueryOptions } from './useFetchSortedNews';
2+
import { setQueryOptions } from 'src/utils/query';
33

44
export default function useFetchProviderNews({
55
providerId,

apps/frontend/src/hooks/useFetchSortedNews.ts

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,5 @@
1-
import { useAppSelector } from 'src/app/hooks';
21
import { useGetSortedNewsQuery } from 'src/features/news';
3-
4-
type NewsQueryOptions = {
5-
providerId?: string | undefined;
6-
begin?: string;
7-
end?: string;
8-
filter?: string;
9-
limit?: number;
10-
};
11-
12-
export const setQueryOptions = (
13-
providerId: string | undefined,
14-
): NewsQueryOptions => {
15-
const date = useAppSelector((state) => state.settings.date);
16-
const options: NewsQueryOptions = {};
17-
if (providerId) {
18-
options.providerId = providerId;
19-
}
20-
// utilisation de setHours pour gérer les problèmes de fuseau horaire
21-
if (date === 'today') {
22-
const todayBegin = new Date(new Date().setHours(0, 0, 0, 0));
23-
options.begin = todayBegin.toISOString();
24-
}
25-
if (date === 'yesterday') {
26-
const yesterdayBegin = new Date(
27-
new Date().setDate(new Date().getDate() - 1),
28-
);
29-
yesterdayBegin.setHours(23, 59, 59, 999);
30-
const yesterdayEnd = new Date(new Date().setDate(new Date().getDate() - 1));
31-
yesterdayEnd.setHours(0, 0, 0, 0);
32-
options.begin = yesterdayBegin.toISOString();
33-
options.end = yesterdayEnd.toISOString();
34-
}
35-
if (date === 'last-week') {
36-
const lastWeek = new Date();
37-
lastWeek.setDate(lastWeek.getDate() - 7);
38-
lastWeek.setHours(0, 0, 0, 0);
39-
options.begin = lastWeek.toISOString();
40-
}
41-
return options;
42-
};
2+
import { setQueryOptions } from 'src/utils/query';
433

444
export default function useFetchSortedNews() {
455
// const [searchParams] = useSearchParams();

apps/frontend/src/utils/query.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { useAppSelector } from 'src/app/hooks';
2+
3+
type NewsQueryOptions = {
4+
providerId?: string | undefined;
5+
begin?: string;
6+
end?: string;
7+
filter?: string;
8+
limit?: number;
9+
};
10+
11+
export const setQueryOptions = (
12+
providerId: string | undefined,
13+
): NewsQueryOptions => {
14+
const date = useAppSelector((state) => state.settings.date);
15+
const options: NewsQueryOptions = {};
16+
if (providerId) {
17+
options.providerId = providerId;
18+
}
19+
// utilisation de setHours pour gérer les problèmes de fuseau horaire
20+
if (date === 'today') {
21+
const todayBegin = new Date(new Date().setHours(0, 0, 0, 0));
22+
options.begin = todayBegin.toISOString();
23+
}
24+
if (date === 'yesterday') {
25+
const yesterdayBegin = new Date(
26+
new Date().setDate(new Date().getDate() - 1),
27+
);
28+
yesterdayBegin.setHours(0, 0, 0, 0);
29+
const yesterdayEnd = new Date(new Date().setDate(new Date().getDate() - 1));
30+
yesterdayEnd.setHours(23, 59, 59, 999);
31+
console.log('yesterdayEnd', yesterdayEnd);
32+
options.begin = yesterdayBegin.toISOString();
33+
options.end = yesterdayEnd.toISOString();
34+
}
35+
if (date === 'last-week') {
36+
const lastWeek = new Date();
37+
lastWeek.setDate(lastWeek.getDate() - 7);
38+
lastWeek.setHours(0, 0, 0, 0);
39+
options.begin = lastWeek.toISOString();
40+
}
41+
console.log(options);
42+
return options;
43+
};

0 commit comments

Comments
 (0)