Portal/rsconcept/frontend/src/backend/users/api.ts

40 lines
1.3 KiB
TypeScript
Raw Normal View History

2025-01-21 12:00:09 +03:00
import { queryOptions } from '@tanstack/react-query';
2025-01-23 19:41:31 +03:00
import { axiosInstance } from '@/backend/axiosInstance';
import { DELAYS } from '@/backend/configuration';
2025-01-21 20:33:05 +03:00
import { IUser, IUserInfo, IUserProfile, IUserSignupData } from '@/models/user';
2025-01-21 12:00:09 +03:00
2025-01-21 20:33:05 +03:00
/**
* Represents user data, intended to update user profile in persistent storage.
*/
export interface IUpdateProfileDTO extends Omit<IUser, 'is_staff' | 'id'> {}
2025-01-21 12:00:09 +03:00
export const usersApi = {
baseKey: 'users',
2025-01-21 20:33:05 +03:00
getUsersQueryOptions: () =>
queryOptions({
2025-01-21 12:00:09 +03:00
queryKey: [usersApi.baseKey, 'list'],
2025-01-23 19:41:31 +03:00
staleTime: DELAYS.staleMedium,
2025-01-21 12:00:09 +03:00
queryFn: meta =>
2025-01-21 20:33:05 +03:00
axiosInstance
.get<IUserInfo[]>('/users/api/active-users', {
signal: meta.signal
})
2025-01-23 19:41:31 +03:00
.then(response => response.data)
2025-01-21 20:33:05 +03:00
}),
getProfileQueryOptions: () =>
queryOptions({
queryKey: [usersApi.baseKey, 'profile'],
2025-01-23 19:41:31 +03:00
staleTime: DELAYS.staleShort,
2025-01-21 20:33:05 +03:00
queryFn: meta =>
axiosInstance
.get<IUserProfile>('/users/api/profile', {
signal: meta.signal
})
.then(response => response.data)
}),
signup: (data: IUserSignupData) => axiosInstance.post('/users/api/signup', data),
updateProfile: (data: IUpdateProfileDTO) => axiosInstance.patch('/users/api/profile', data)
2025-01-21 12:00:09 +03:00
};