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

41 lines
1.2 KiB
TypeScript
Raw Normal View History

2025-01-21 12:00:09 +03:00
import { queryOptions } from '@tanstack/react-query';
2025-01-21 20:33:05 +03:00
import { IUser, IUserInfo, IUserProfile, IUserSignupData } from '@/models/user';
2025-01-21 12:00:09 +03:00
import { axiosInstance } from '../apiConfiguration';
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'],
queryFn: meta =>
2025-01-21 20:33:05 +03:00
axiosInstance
.get<IUserInfo[]>('/users/api/active-users', {
signal: meta.signal
})
.then(response => response.data),
placeholderData: []
}),
getProfileQueryOptions: () =>
queryOptions({
queryKey: [usersApi.baseKey, 'profile'],
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
};
2025-01-21 20:33:05 +03:00
//DataCallback<IUserProfile>