Format code style

This commit is contained in:
2023-11-29 15:47:56 +07:00
parent a7bd3bf48b
commit 4742ff60ce
4 changed files with 74 additions and 32 deletions
+24 -10
View File
@@ -18,18 +18,22 @@ const useRooms = () => {
const sortByValue = searchParams.get('sortBy') || 'id';
const orderByValue = searchParams.get('orderBy') || 'asc';
const roomSearch = searchParams.get('search') || '';
const page = searchParams.get('page')
? Number(searchParams.get('page'))
: 1;
const searchValue = searchParams.get('search') || '';
const page = searchParams.get('page') ? Number(searchParams.get('page')) : 1;
const {
isLoading,
data: { data: rooms, count } = {},
error,
} = useQuery({
queryKey: ['rooms', sortByValue, orderByValue, roomSearch, page],
queryFn: () => getAllRooms(sortByValue, orderByValue, roomSearch, page),
queryKey: ['rooms', sortByValue, orderByValue, searchValue, page],
queryFn: () =>
getAllRooms({
sortBy: sortByValue,
orderBy: orderByValue,
roomName: searchValue,
page,
}),
});
if (error) {
@@ -43,9 +47,14 @@ const useRooms = () => {
const nextPage = page + 1;
queryClient.prefetchQuery({
queryKey: ['rooms', sortByValue, orderByValue, roomSearch, nextPage],
queryKey: ['rooms', sortByValue, orderByValue, searchValue, nextPage],
queryFn: () =>
getAllRooms(sortByValue, orderByValue, roomSearch, nextPage),
getAllRooms({
sortBy: sortByValue,
orderBy: orderByValue,
roomName: searchValue,
page: nextPage,
}),
});
}
@@ -53,9 +62,14 @@ const useRooms = () => {
const previousPage = page - 1;
queryClient.prefetchQuery({
queryKey: ['rooms', sortByValue, orderByValue, roomSearch, previousPage],
queryKey: ['rooms', sortByValue, orderByValue, searchValue, previousPage],
queryFn: () =>
getAllRooms(sortByValue, orderByValue, roomSearch, previousPage),
getAllRooms({
sortBy: sortByValue,
orderBy: orderByValue,
roomName: searchValue,
page: previousPage,
}),
});
}
+24 -10
View File
@@ -17,18 +17,22 @@ const useUsers = () => {
const queryClient = useQueryClient();
const sortByValue = searchParams.get('sortBy') || 'id';
const orderByValue = searchParams.get('orderBy') || 'asc';
const phoneSearch = searchParams.get('search') || '';
const page = searchParams.get('page')
? Number(searchParams.get('page'))
: 1;
const searchValue = searchParams.get('search') || '';
const page = searchParams.get('page') ? Number(searchParams.get('page')) : 1;
const {
isLoading,
data: { data: users, count } = {},
error,
} = useQuery({
queryKey: ['users', sortByValue, orderByValue, phoneSearch, page],
queryFn: () => getAllUsers(sortByValue, orderByValue, phoneSearch, page),
queryKey: ['users', sortByValue, orderByValue, searchValue, page],
queryFn: () =>
getAllUsers({
sortBy: sortByValue,
orderBy: orderByValue,
phoneSearch: searchValue,
page,
}),
});
if (error) {
@@ -42,9 +46,14 @@ const useUsers = () => {
const nextPage = page + 1;
queryClient.prefetchQuery({
queryKey: ['users', sortByValue, orderByValue, phoneSearch, nextPage],
queryKey: ['users', sortByValue, orderByValue, searchValue, nextPage],
queryFn: () =>
getAllUsers(sortByValue, orderByValue, phoneSearch, nextPage),
getAllUsers({
sortBy: sortByValue,
orderBy: orderByValue,
phoneSearch: searchValue,
page: nextPage,
}),
});
}
@@ -52,9 +61,14 @@ const useUsers = () => {
const previousPage = page - 1;
queryClient.prefetchQuery({
queryKey: ['users', sortByValue, orderByValue, phoneSearch, previousPage],
queryKey: ['users', sortByValue, orderByValue, searchValue, previousPage],
queryFn: () =>
getAllUsers(sortByValue, orderByValue, phoneSearch, previousPage),
getAllUsers({
sortBy: sortByValue,
orderBy: orderByValue,
phoneSearch: searchValue,
page: previousPage,
}),
});
}
+13 -6
View File
@@ -14,16 +14,23 @@ const ERROR_UPDATE_ROOM = "Can't update room!";
const ERROR_CREATE_ROOM = "Can't create room!";
const ERROR_DELETE_ROOM = "Can't delete room!";
interface IGetAllRooms {
sortBy: string;
orderBy: string;
roomName: string;
page: number;
}
/**
* Get all rooms from database
* @returns Return all rooms in database
*/
const getAllRooms = async (
sortBy: string,
orderBy: string,
roomName: string,
page: number
): Promise<{ data: IRoom[]; count: number | null }> => {
const getAllRooms = async ({
sortBy,
orderBy,
roomName,
page,
}: IGetAllRooms): Promise<{ data: IRoom[]; count: number | null }> => {
const from = (page - 1) * DEFAULT_PAGE_SIZE;
const to = from + DEFAULT_PAGE_SIZE - 1;
+13 -6
View File
@@ -52,6 +52,13 @@ const updateUser = async (user: IUser): Promise<IUser> => {
return data;
};
interface IGetAllUsers {
sortBy: string;
orderBy: string;
phoneSearch: string;
page: number;
}
/**
* Return data of users from database
* @param sortBy Sort by column
@@ -59,12 +66,12 @@ const updateUser = async (user: IUser): Promise<IUser> => {
* @param phoneSearch The phone need to be search
* @returns The data of users from database
*/
const getAllUsers = async (
sortBy: string,
orderBy: string,
phoneSearch: string,
page: number
): Promise<{ data: IUser[]; count: number | null }> => {
const getAllUsers = async ({
sortBy,
orderBy,
phoneSearch,
page,
}: IGetAllUsers): Promise<{ data: IUser[]; count: number | null }> => {
const from = (page - 1) * DEFAULT_PAGE_SIZE;
const to = from + DEFAULT_PAGE_SIZE - 1;