feat: integrate all backend APIs into frontend apps
- Fix API service paths to use /v1/iam/, /v1/dimentorin/, /v1/gacha/, /v1/hackathon/ prefixes - Add roles, permissions, events, testimonials, sessions API services and hooks - Rewrite gacha service with full CRUD + roll/claim endpoints - Replace all mock data in backoffice pages with real API calls (accounts, roles, permissions, gacha-roll, dashboard, sessions, users-dimentorin, feedback-review, settings) - Wire dimentorin mentoring list to useMentorList with search + pagination - Wire dimentorin mentor detail page to useMentorById, pass real data to all sections - Wire appointment modal to useBookSession with controlled schedule inputs - Wire gacha app Spin Now to useExecuteGachaRoll, show credits and real items Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
8d2aaf5188
commit
53ad40f3fd
@@ -5,23 +5,28 @@ import type {
|
||||
TAdminSubmissionsResponse,
|
||||
} from '../../types/admin';
|
||||
|
||||
const ADMIN_BASE_URL = '/admin';
|
||||
|
||||
export const getAdminUsers = async (params?: {
|
||||
page?: number;
|
||||
per_page?: number;
|
||||
search?: string;
|
||||
is_admin?: boolean;
|
||||
}) => {
|
||||
const response = await api.get<TAdminUsersResponse>(
|
||||
`${ADMIN_BASE_URL}/users`,
|
||||
{
|
||||
params: {
|
||||
...params,
|
||||
is_admin: params?.is_admin ?? false,
|
||||
},
|
||||
}
|
||||
);
|
||||
const response = await api.get<TAdminUsersResponse>('/v1/hackathon/admin/users', { params });
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export const getAdminUserById = async (userId: string) => {
|
||||
const response = await api.get(`/v1/hackathon/admin/users/${userId}`);
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export const deleteAdminUser = async (userId: string) => {
|
||||
const response = await api.delete(`/v1/hackathon/admin/users/${userId}`);
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export const setAdminUser = async (userId: string, is_admin: boolean) => {
|
||||
const response = await api.post(`/v1/hackathon/admin/users/${userId}/set-admin`, { is_admin });
|
||||
return response.data;
|
||||
};
|
||||
|
||||
@@ -30,10 +35,12 @@ export const getAdminTeams = async (params?: {
|
||||
per_page?: number;
|
||||
search?: string;
|
||||
}) => {
|
||||
const response = await api.get<TAdminTeamsResponse>(
|
||||
`${ADMIN_BASE_URL}/teams`,
|
||||
{ params }
|
||||
);
|
||||
const response = await api.get<TAdminTeamsResponse>('/v1/hackathon/admin/teams', { params });
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export const deleteAdminTeam = async (teamId: string) => {
|
||||
const response = await api.delete(`/v1/hackathon/admin/teams/${teamId}`);
|
||||
return response.data;
|
||||
};
|
||||
|
||||
@@ -43,9 +50,21 @@ export const getAdminSubmissions = async (params?: {
|
||||
search?: string;
|
||||
status?: string;
|
||||
}) => {
|
||||
const response = await api.get<TAdminSubmissionsResponse>(
|
||||
`${ADMIN_BASE_URL}/submissions`,
|
||||
{ params }
|
||||
);
|
||||
const response = await api.get<TAdminSubmissionsResponse>('/v1/hackathon/admin/submissions', { params });
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export const getAdminWinners = async () => {
|
||||
const response = await api.get('/v1/hackathon/admin/winners');
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export const setWinner = async (data: { team_id: string; rank: number; prize?: string }) => {
|
||||
const response = await api.post('/v1/hackathon/admin/winners', data);
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export const removeWinner = async (teamId: string) => {
|
||||
const response = await api.delete(`/v1/hackathon/admin/winners/${teamId}`);
|
||||
return response.data;
|
||||
};
|
||||
|
||||
@@ -1,80 +1,65 @@
|
||||
import { api, getBaseURL } from '../';
|
||||
import {
|
||||
TLoginRequest,
|
||||
TLoginResponse,
|
||||
TRegisterRequest,
|
||||
TSendOTPRequest,
|
||||
TVerifyEmailRequest,
|
||||
TGoogleCallbackResponse,
|
||||
} from '../../types/auth';
|
||||
import { TResponseMessage } from '../../types/common';
|
||||
import { api } from '../index';
|
||||
import type { TLoginResponse, TRegisterRequest, TSendOTPRequest, TVerifyEmailRequest } from '../../types/auth';
|
||||
import type { TResponseMessage } from '../../types/common';
|
||||
|
||||
export const postLogin = async (
|
||||
payload: TLoginRequest
|
||||
): Promise<TLoginResponse> => {
|
||||
export type TLoginRequest = {
|
||||
email: string;
|
||||
password: string;
|
||||
};
|
||||
|
||||
export type TForgotPasswordRequest = {
|
||||
email: string;
|
||||
};
|
||||
|
||||
export type TNewPasswordRequest = {
|
||||
token: string;
|
||||
password: string;
|
||||
};
|
||||
|
||||
export type TRefreshTokenRequest = {
|
||||
refresh_token: string;
|
||||
};
|
||||
|
||||
export const postLogin = async (payload: TLoginRequest): Promise<TLoginResponse> => {
|
||||
const { data } = await api({ method: 'POST', url: '/v1/iam/auth/login', data: payload });
|
||||
return data;
|
||||
};
|
||||
|
||||
export const postLoginMentor = async (payload: TLoginRequest): Promise<TLoginResponse> => {
|
||||
const { data } = await api({ method: 'POST', url: '/v1/iam/auth/login-mentor', data: payload });
|
||||
return data;
|
||||
};
|
||||
|
||||
export const postRegister = async (payload: TRegisterRequest): Promise<TResponseMessage> => {
|
||||
const { data } = await api({ method: 'POST', url: '/v1/iam/auth/register', data: payload });
|
||||
return data;
|
||||
};
|
||||
|
||||
export const postVerifyEmail = async (payload: TVerifyEmailRequest): Promise<TResponseMessage> => {
|
||||
const { data } = await api({
|
||||
method: 'POST',
|
||||
url: '/auth/login',
|
||||
data: payload,
|
||||
url: '/v1/iam/auth/verify-email',
|
||||
data: { otp: parseInt(payload.otp), email: payload.email },
|
||||
});
|
||||
return data;
|
||||
};
|
||||
|
||||
export const postRegister = async (
|
||||
payload: TRegisterRequest
|
||||
): Promise<TResponseMessage> => {
|
||||
const { data } = await api({
|
||||
method: 'POST',
|
||||
url: '/auth/register',
|
||||
data: payload,
|
||||
});
|
||||
export const postSendOtp = async (payload: TSendOTPRequest): Promise<TResponseMessage> => {
|
||||
const { data } = await api({ method: 'POST', url: '/v1/iam/auth/send-otp', data: payload });
|
||||
return data;
|
||||
};
|
||||
|
||||
export const postVerifyEmail = async (
|
||||
payload: TVerifyEmailRequest
|
||||
): Promise<TResponseMessage> => {
|
||||
const { data } = await api({
|
||||
method: 'POST',
|
||||
url: '/auth/verify-email',
|
||||
data: {otp: parseInt(payload.otp), email: payload.email},
|
||||
});
|
||||
export const postForgotPassword = async (payload: TForgotPasswordRequest): Promise<TResponseMessage> => {
|
||||
const { data } = await api({ method: 'POST', url: '/v1/iam/auth/forgot', data: payload });
|
||||
return data;
|
||||
};
|
||||
|
||||
export const postSendOtp = async (
|
||||
payload: TSendOTPRequest
|
||||
): Promise<TResponseMessage> => {
|
||||
const { data } = await api({
|
||||
method: 'POST',
|
||||
url: '/auth/send-otp',
|
||||
data: payload,
|
||||
});
|
||||
export const postNewPassword = async (payload: TNewPasswordRequest): Promise<TResponseMessage> => {
|
||||
const { data } = await api({ method: 'POST', url: '/v1/iam/auth/new-password', data: payload });
|
||||
return data;
|
||||
};
|
||||
|
||||
export const getGoogleAuthUrl = async (): Promise<string> => {
|
||||
const baseUrl = getBaseURL() || 'http://localhost:8080';
|
||||
return `${baseUrl}/auth/google/login`;
|
||||
};
|
||||
|
||||
export const postGoogleCallback = async (code: string, state: string): Promise<TGoogleCallbackResponse> => {
|
||||
const { data } = await api({
|
||||
method: 'GET',
|
||||
url: `/auth/google/callback?code=${code}&state=${state}`,
|
||||
});
|
||||
return data;
|
||||
};
|
||||
|
||||
export const getGitHubAuthUrl = async (): Promise<string> => {
|
||||
const baseUrl = getBaseURL() || 'http://localhost:8080';
|
||||
return `${baseUrl}/auth/github/login`;
|
||||
};
|
||||
|
||||
export const postGitHubCallback = async (code: string, state: string): Promise<TGoogleCallbackResponse> => {
|
||||
const { data } = await api({
|
||||
method: 'GET',
|
||||
url: `/auth/github/callback?code=${code}&state=${state}`,
|
||||
});
|
||||
export const postRefreshToken = async (payload: TRefreshTokenRequest): Promise<{ access_token: string; refresh_token: string }> => {
|
||||
const { data } = await api({ method: 'POST', url: '/v1/iam/auth/refresh', data: payload });
|
||||
return data;
|
||||
};
|
||||
|
||||
@@ -1,52 +1,6 @@
|
||||
import axios from 'axios';
|
||||
import { useAuthStore } from '../hooks/auth';
|
||||
|
||||
const BACKOFFICE_API_URL = 'https://api.hackathon.imphnen.dev/api/v1';
|
||||
|
||||
export const backofficeApi = axios.create({
|
||||
baseURL: BACKOFFICE_API_URL,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
|
||||
backofficeApi.interceptors.request.use(
|
||||
(config) => {
|
||||
const { session } = useAuthStore.getState();
|
||||
if (session?.token?.access_token) {
|
||||
config.headers.Authorization = `Bearer ${session.token.access_token}`;
|
||||
}
|
||||
return config;
|
||||
},
|
||||
(error) => {
|
||||
return Promise.reject(new Error(error.message || 'Request failed'));
|
||||
}
|
||||
);
|
||||
|
||||
backofficeApi.interceptors.response.use(
|
||||
(response) => response,
|
||||
(error) => {
|
||||
if (error.response?.status === 401) {
|
||||
const isAuthPage =
|
||||
globalThis.window !== undefined &&
|
||||
globalThis.location.pathname.startsWith('/auth');
|
||||
|
||||
if (!isAuthPage) {
|
||||
useAuthStore.getState().clearSession();
|
||||
if (globalThis.window !== undefined) {
|
||||
globalThis.location.href = '/auth/login';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const backendMsg = error?.response?.data?.message;
|
||||
if (backendMsg && typeof backendMsg === 'string') {
|
||||
return Promise.reject(new Error(backendMsg));
|
||||
}
|
||||
|
||||
return Promise.reject(new Error(error.message || 'An error occurred'));
|
||||
}
|
||||
);
|
||||
// All API calls now go through the main `api` instance (api.imphnen.dev).
|
||||
// This file re-exports `api` as `backofficeApi` for backward compatibility.
|
||||
export { api as backofficeApi } from './index';
|
||||
|
||||
export interface BackofficeApiResponse<T> {
|
||||
data: T;
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
import { api, ApiResponse } from '../index';
|
||||
import type { TEventsListItem, TEventsDetailItem, TEventCreateRequest, TEventUpdateRequest } from '../../types/events';
|
||||
import type { TApiPaginated, TPaginationParams } from '../../types/common';
|
||||
|
||||
export const getEventList = async (params?: TPaginationParams): Promise<TApiPaginated<TEventsListItem>> => {
|
||||
const response = await api.get<TApiPaginated<TEventsListItem>>('/v1/landing/cms/events', { params });
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export const getEventById = async (id: string): Promise<TEventsDetailItem> => {
|
||||
const response = await api.get<ApiResponse<TEventsDetailItem>>(`/v1/landing/cms/events/detail/${id}`);
|
||||
return response.data.data;
|
||||
};
|
||||
|
||||
export const createEvent = async (data: TEventCreateRequest): Promise<TEventsDetailItem> => {
|
||||
const response = await api.post<ApiResponse<TEventsDetailItem>>('/v1/landing/cms/events/create', data);
|
||||
return response.data.data;
|
||||
};
|
||||
|
||||
export const updateEvent = async (id: string, data: TEventUpdateRequest): Promise<TEventsDetailItem> => {
|
||||
const response = await api.patch<ApiResponse<TEventsDetailItem>>(`/v1/landing/cms/events/update/${id}`, data);
|
||||
return response.data.data;
|
||||
};
|
||||
|
||||
export const deleteEvent = async (id: string): Promise<{ message: string }> => {
|
||||
const response = await api.delete<{ message: string }>(`/v1/landing/cms/events/delete/${id}`);
|
||||
return response.data;
|
||||
};
|
||||
@@ -1 +1,87 @@
|
||||
export {};
|
||||
import { api, ApiResponse } from '../index';
|
||||
import type {
|
||||
TGachaItemDto,
|
||||
TGachaItemCreateRequest,
|
||||
TGachaItemUpdateRequest,
|
||||
TGachaRollItemDto,
|
||||
TGachaRollCreateRequest,
|
||||
TGachaCreditDto,
|
||||
TGachaCreditAddRequest,
|
||||
TGachaClaimDetailDto,
|
||||
TGachaClaimCreateRequest,
|
||||
} from '../../types/gacha';
|
||||
import type { TApiPaginated, TPaginationParams } from '../../types/common';
|
||||
|
||||
// ----- Credits -----
|
||||
export const getUserCredits = async (): Promise<TGachaCreditDto> => {
|
||||
const response = await api.get<ApiResponse<TGachaCreditDto>>('/v1/gacha/credits/');
|
||||
return response.data.data;
|
||||
};
|
||||
|
||||
export const addCredits = async (data: TGachaCreditAddRequest): Promise<TGachaCreditDto> => {
|
||||
const response = await api.post<ApiResponse<TGachaCreditDto>>('/v1/gacha/credits/add', data);
|
||||
return response.data.data;
|
||||
};
|
||||
|
||||
export const consumeCredit = async (): Promise<{ message: string }> => {
|
||||
const response = await api.post<{ message: string }>('/v1/gacha/credits/consume');
|
||||
return response.data;
|
||||
};
|
||||
|
||||
// ----- Items -----
|
||||
export const getGachaItemList = async (params?: TPaginationParams): Promise<TApiPaginated<TGachaItemDto>> => {
|
||||
const response = await api.get<TApiPaginated<TGachaItemDto>>('/v1/gacha/items/', { params });
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export const getGachaItemById = async (id: string): Promise<TGachaItemDto> => {
|
||||
const response = await api.get<ApiResponse<TGachaItemDto>>(`/v1/gacha/items/detail/${id}`);
|
||||
return response.data.data;
|
||||
};
|
||||
|
||||
export const createGachaItem = async (data: TGachaItemCreateRequest): Promise<TGachaItemDto> => {
|
||||
const response = await api.post<ApiResponse<TGachaItemDto>>('/v1/gacha/items/create', data);
|
||||
return response.data.data;
|
||||
};
|
||||
|
||||
export const updateGachaItem = async (id: string, data: TGachaItemUpdateRequest): Promise<TGachaItemDto> => {
|
||||
const response = await api.put<ApiResponse<TGachaItemDto>>(`/v1/gacha/items/update/${id}`, data);
|
||||
return response.data.data;
|
||||
};
|
||||
|
||||
export const deleteGachaItem = async (id: string): Promise<{ message: string }> => {
|
||||
const response = await api.delete<{ message: string }>(`/v1/gacha/items/delete/${id}`);
|
||||
return response.data;
|
||||
};
|
||||
|
||||
// ----- Rolls -----
|
||||
export const getGachaRollById = async (id: string): Promise<TGachaRollItemDto> => {
|
||||
const response = await api.get<ApiResponse<TGachaRollItemDto>>(`/v1/gacha/rolls/detail/${id}`);
|
||||
return response.data.data;
|
||||
};
|
||||
|
||||
export const createGachaRoll = async (data: TGachaRollCreateRequest): Promise<TGachaRollItemDto> => {
|
||||
const response = await api.post<ApiResponse<TGachaRollItemDto>>('/v1/gacha/rolls/create', data);
|
||||
return response.data.data;
|
||||
};
|
||||
|
||||
export const executeGachaRoll = async (): Promise<TGachaRollItemDto> => {
|
||||
const response = await api.post<ApiResponse<TGachaRollItemDto>>('/v1/gacha/rolls/execute');
|
||||
return response.data.data;
|
||||
};
|
||||
|
||||
export const deleteGachaRoll = async (id: string): Promise<{ message: string }> => {
|
||||
const response = await api.delete<{ message: string }>(`/v1/gacha/rolls/delete/${id}`);
|
||||
return response.data;
|
||||
};
|
||||
|
||||
// ----- Claims -----
|
||||
export const getGachaClaimById = async (id: string): Promise<TGachaClaimDetailDto> => {
|
||||
const response = await api.get<ApiResponse<TGachaClaimDetailDto>>(`/v1/gacha/claims/detail/${id}`);
|
||||
return response.data.data;
|
||||
};
|
||||
|
||||
export const createGachaClaim = async (data: TGachaClaimCreateRequest): Promise<TGachaClaimDetailDto> => {
|
||||
const response = await api.post<ApiResponse<TGachaClaimDetailDto>>('/v1/gacha/claims/create', data);
|
||||
return response.data.data;
|
||||
};
|
||||
|
||||
@@ -1,51 +1,6 @@
|
||||
import axios from 'axios';
|
||||
import { useAuthStore } from '../hooks/auth';
|
||||
|
||||
const HACKATHON_API_URL = 'https://api.hackathon.imphnen.dev/api/v1';
|
||||
|
||||
export const hackathonApi = axios.create({
|
||||
baseURL: HACKATHON_API_URL,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
|
||||
hackathonApi.interceptors.request.use(
|
||||
(config) => {
|
||||
const { session } = useAuthStore.getState();
|
||||
if (session?.token?.access_token) {
|
||||
config.headers.Authorization = `Bearer ${session.token.access_token}`;
|
||||
}
|
||||
return config;
|
||||
},
|
||||
(error) => {
|
||||
return Promise.reject(new Error(error.message || 'Request failed'));
|
||||
}
|
||||
);
|
||||
|
||||
hackathonApi.interceptors.response.use(
|
||||
(response) => response,
|
||||
(error) => {
|
||||
if (error.response?.status === 401) {
|
||||
const isAuthPage = globalThis.window !== undefined && globalThis.location.pathname.startsWith('/auth');
|
||||
const isCertificatePage = globalThis.window !== undefined && globalThis.location.pathname.startsWith('/certificate/');
|
||||
|
||||
if (!isAuthPage && !isCertificatePage) {
|
||||
useAuthStore.getState().clearSession();
|
||||
if (globalThis.window !== undefined) {
|
||||
globalThis.location.href = '/auth/login';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const backendMsg = error?.response?.data?.message;
|
||||
if (backendMsg && typeof backendMsg === 'string') {
|
||||
return Promise.reject(new Error(backendMsg));
|
||||
}
|
||||
|
||||
return Promise.reject(new Error(error.message || 'Request failed'));
|
||||
}
|
||||
);
|
||||
// All API calls now go through the main `api` instance (api.imphnen.dev).
|
||||
// This file re-exports `api` as `hackathonApi` for backward compatibility.
|
||||
export { api as hackathonApi } from './index';
|
||||
|
||||
export interface HackathonApiResponse<T> {
|
||||
data: T;
|
||||
|
||||
@@ -7,6 +7,11 @@ export * from './mentors';
|
||||
export * from './upload';
|
||||
export * from './hackathon';
|
||||
export * from './admin';
|
||||
export * from './roles';
|
||||
export * from './permissions';
|
||||
export * from './events';
|
||||
export * from './testimonials';
|
||||
export * from './sessions';
|
||||
|
||||
export interface ApiResponse<T> {
|
||||
data: T;
|
||||
@@ -140,7 +145,7 @@ async function handleTokenRefresh(originalRequest: AxiosRequestConfig) {
|
||||
}
|
||||
|
||||
async function refreshAccessToken(refreshToken: string) {
|
||||
return axios.post(`${getBaseURL()}/auth/refresh`, {
|
||||
return axios.post(`${getBaseURL()}/v1/iam/auth/refresh`, {
|
||||
refresh_token: refreshToken,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,34 +1,61 @@
|
||||
import { api, ApiResponse } from '../index';
|
||||
import type {
|
||||
MentorDetailResponseDto,
|
||||
MentorUpdateRequestDto
|
||||
} from '../../types/mentors';
|
||||
import type { MentorDetailResponseDto, MentorUpdateRequestDto } from '../../types/mentors';
|
||||
import type { TApiPaginated, TPaginationParams } from '../../types/common';
|
||||
|
||||
export interface MentorService {
|
||||
getMentorMe(): Promise<MentorDetailResponseDto>;
|
||||
getMentorById(id: string): Promise<MentorDetailResponseDto>;
|
||||
updateMentorMe(data: MentorUpdateRequestDto): Promise<MentorDetailResponseDto>;
|
||||
updateMentorById(id: string, data: MentorUpdateRequestDto): Promise<MentorDetailResponseDto>;
|
||||
}
|
||||
|
||||
export const mentorService: MentorService = {
|
||||
async getMentorMe() {
|
||||
const response = await api.get<ApiResponse<MentorDetailResponseDto>>('/mentors/me');
|
||||
return response.data.data;
|
||||
},
|
||||
|
||||
async getMentorById(id: string) {
|
||||
const response = await api.get<ApiResponse<MentorDetailResponseDto>>(`/mentors/detail/${id}`);
|
||||
return response.data.data;
|
||||
},
|
||||
|
||||
async updateMentorMe(data: MentorUpdateRequestDto) {
|
||||
const response = await api.put<ApiResponse<MentorDetailResponseDto>>('/mentors/update/me', data);
|
||||
return response.data.data;
|
||||
},
|
||||
|
||||
async updateMentorById(id: string, data: MentorUpdateRequestDto) {
|
||||
const response = await api.put<ApiResponse<MentorDetailResponseDto>>(`/mentors/update/${id}`, data);
|
||||
return response.data.data;
|
||||
},
|
||||
export type MentorRegisterRequest = MentorUpdateRequestDto & {
|
||||
email: string;
|
||||
password: string;
|
||||
};
|
||||
|
||||
export const registerMentor = async (data: MentorRegisterRequest): Promise<MentorDetailResponseDto> => {
|
||||
const response = await api.post<ApiResponse<MentorDetailResponseDto>>('/v1/dimentorin/mentors/create', data);
|
||||
return response.data.data;
|
||||
};
|
||||
|
||||
export const getMentorList = async (params?: TPaginationParams): Promise<TApiPaginated<MentorDetailResponseDto>> => {
|
||||
const response = await api.get<TApiPaginated<MentorDetailResponseDto>>('/v1/dimentorin/mentors', { params });
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export const getMentorMe = async (): Promise<MentorDetailResponseDto> => {
|
||||
const response = await api.get<ApiResponse<MentorDetailResponseDto>>('/v1/dimentorin/mentors/me');
|
||||
return response.data.data;
|
||||
};
|
||||
|
||||
export const getMentorStatus = async (): Promise<{ status: string }> => {
|
||||
const response = await api.get<ApiResponse<{ status: string }>>('/v1/dimentorin/mentors/me/status');
|
||||
return response.data.data;
|
||||
};
|
||||
|
||||
export const getMentorById = async (id: string): Promise<MentorDetailResponseDto> => {
|
||||
const response = await api.get<ApiResponse<MentorDetailResponseDto>>(`/v1/dimentorin/mentors/detail/${id}`);
|
||||
return response.data.data;
|
||||
};
|
||||
|
||||
export const updateMentorMe = async (data: MentorUpdateRequestDto): Promise<MentorDetailResponseDto> => {
|
||||
const response = await api.put<ApiResponse<MentorDetailResponseDto>>('/v1/dimentorin/mentors/me/update', data);
|
||||
return response.data.data;
|
||||
};
|
||||
|
||||
export const updateMentorById = async (id: string, data: MentorUpdateRequestDto): Promise<MentorDetailResponseDto> => {
|
||||
const response = await api.put<ApiResponse<MentorDetailResponseDto>>(`/v1/dimentorin/mentors/update/${id}`, data);
|
||||
return response.data.data;
|
||||
};
|
||||
|
||||
export const deleteMentor = async (id: string): Promise<{ message: string }> => {
|
||||
const response = await api.delete<{ message: string }>(`/v1/dimentorin/mentors/delete/${id}`);
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export const verifyMentor = async (id: string): Promise<{ message: string }> => {
|
||||
const response = await api.put<{ message: string }>(`/v1/dimentorin/mentors/verify/${id}`);
|
||||
return response.data;
|
||||
};
|
||||
|
||||
// Legacy service object for backward compatibility
|
||||
export const mentorService = {
|
||||
getMentorMe,
|
||||
getMentorById,
|
||||
updateMentorMe,
|
||||
updateMentorById: (id: string, data: MentorUpdateRequestDto) => updateMentorById(id, data),
|
||||
};
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
import { api, ApiResponse } from '../index';
|
||||
import type { TPermissionItem, TPermissionCreateRequest, TPermissionUpdateRequest } from '../../types/permissions';
|
||||
import type { TApiPaginated, TPaginationParams } from '../../types/common';
|
||||
|
||||
export const getPermissionList = async (params?: TPaginationParams): Promise<TApiPaginated<TPermissionItem>> => {
|
||||
const response = await api.get<TApiPaginated<TPermissionItem>>('/v1/iam/permissions', { params });
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export const getPermissionById = async (id: string): Promise<TPermissionItem> => {
|
||||
const response = await api.get<ApiResponse<TPermissionItem>>(`/v1/iam/permissions/detail/${id}`);
|
||||
return response.data.data;
|
||||
};
|
||||
|
||||
export const createPermission = async (data: TPermissionCreateRequest): Promise<TPermissionItem> => {
|
||||
const response = await api.post<ApiResponse<TPermissionItem>>('/v1/iam/permissions/create', data);
|
||||
return response.data.data;
|
||||
};
|
||||
|
||||
export const updatePermission = async (id: string, data: TPermissionUpdateRequest): Promise<TPermissionItem> => {
|
||||
const response = await api.put<ApiResponse<TPermissionItem>>(`/v1/iam/permissions/update/${id}`, data);
|
||||
return response.data.data;
|
||||
};
|
||||
|
||||
export const deletePermission = async (id: string): Promise<{ message: string }> => {
|
||||
const response = await api.delete<{ message: string }>(`/v1/iam/permissions/delete/${id}`);
|
||||
return response.data;
|
||||
};
|
||||
@@ -0,0 +1,28 @@
|
||||
import { api, ApiResponse } from '../index';
|
||||
import type { TRolesListItem, TRoleDetailItem, TRoleCreateRequest, TRoleUpdateRequest } from '../../types/roles';
|
||||
import type { TApiPaginated, TPaginationParams } from '../../types/common';
|
||||
|
||||
export const getRoleList = async (params?: TPaginationParams): Promise<TApiPaginated<TRolesListItem>> => {
|
||||
const response = await api.get<TApiPaginated<TRolesListItem>>('/v1/iam/roles', { params });
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export const getRoleById = async (id: string): Promise<TRoleDetailItem> => {
|
||||
const response = await api.get<ApiResponse<TRoleDetailItem>>(`/v1/iam/roles/detail/${id}`);
|
||||
return response.data.data;
|
||||
};
|
||||
|
||||
export const createRole = async (data: TRoleCreateRequest): Promise<TRoleDetailItem> => {
|
||||
const response = await api.post<ApiResponse<TRoleDetailItem>>('/v1/iam/roles/create', data);
|
||||
return response.data.data;
|
||||
};
|
||||
|
||||
export const updateRole = async (id: string, data: TRoleUpdateRequest): Promise<TRoleDetailItem> => {
|
||||
const response = await api.put<ApiResponse<TRoleDetailItem>>(`/v1/iam/roles/update/${id}`, data);
|
||||
return response.data.data;
|
||||
};
|
||||
|
||||
export const deleteRole = async (id: string): Promise<{ message: string }> => {
|
||||
const response = await api.delete<{ message: string }>(`/v1/iam/roles/delete/${id}`);
|
||||
return response.data;
|
||||
};
|
||||
@@ -0,0 +1,64 @@
|
||||
import { api, ApiResponse } from '../index';
|
||||
import type {
|
||||
TBookSessionRequest,
|
||||
TBookSessionResponse,
|
||||
TUpdateSessionStatusRequest,
|
||||
TUpdateSessionStatusResponse,
|
||||
TSessionFeedbackRequest,
|
||||
TSessionFeedbackResponse,
|
||||
TSessionListResponse,
|
||||
TMentorAvailability,
|
||||
} from '../../types/sessions';
|
||||
|
||||
export const getMentorAvailability = async (mentorId: string): Promise<TMentorAvailability> => {
|
||||
const response = await api.get<ApiResponse<TMentorAvailability>>(
|
||||
`/v1/dimentorin/mentors/${mentorId}/availability`
|
||||
);
|
||||
return response.data.data;
|
||||
};
|
||||
|
||||
export const bookSession = async (mentorId: string, data: TBookSessionRequest): Promise<TBookSessionResponse> => {
|
||||
const response = await api.post<ApiResponse<TBookSessionResponse>>(
|
||||
`/v1/dimentorin/mentors/${mentorId}/sessions/create`,
|
||||
data
|
||||
);
|
||||
return response.data.data;
|
||||
};
|
||||
|
||||
export const getMentorSessions = async (mentorId: string, params?: { status?: string }): Promise<TSessionListResponse> => {
|
||||
const response = await api.get<ApiResponse<TSessionListResponse>>(
|
||||
`/v1/dimentorin/mentors/${mentorId}/sessions`,
|
||||
{ params }
|
||||
);
|
||||
return response.data.data;
|
||||
};
|
||||
|
||||
export const getMySessions = async (params?: { status?: string }): Promise<TSessionListResponse> => {
|
||||
const response = await api.get<ApiResponse<TSessionListResponse>>(
|
||||
'/v1/dimentorin/sessions/me',
|
||||
{ params }
|
||||
);
|
||||
return response.data.data;
|
||||
};
|
||||
|
||||
export const updateSessionStatus = async (
|
||||
id: string,
|
||||
data: TUpdateSessionStatusRequest
|
||||
): Promise<TUpdateSessionStatusResponse> => {
|
||||
const response = await api.put<ApiResponse<TUpdateSessionStatusResponse>>(
|
||||
`/v1/dimentorin/sessions/update/${id}/status`,
|
||||
data
|
||||
);
|
||||
return response.data.data;
|
||||
};
|
||||
|
||||
export const submitFeedback = async (
|
||||
id: string,
|
||||
data: TSessionFeedbackRequest
|
||||
): Promise<TSessionFeedbackResponse> => {
|
||||
const response = await api.post<ApiResponse<TSessionFeedbackResponse>>(
|
||||
`/v1/dimentorin/sessions/${id}/feedback/create`,
|
||||
data
|
||||
);
|
||||
return response.data.data;
|
||||
};
|
||||
@@ -4,7 +4,6 @@ import type {
|
||||
TUpdateTeamRequest,
|
||||
TInviteMemberRequest,
|
||||
TJoinTeamRequest,
|
||||
TManageMemberRequest,
|
||||
TSubmitProjectRequest,
|
||||
TTeamListResponse,
|
||||
TTeamDetailResponse,
|
||||
@@ -14,8 +13,6 @@ import type {
|
||||
TProjectSubmissionResponse,
|
||||
} from '../../types/teams';
|
||||
|
||||
const TEAMS_BASE_URL = '/teams';
|
||||
|
||||
export const getTeams = async (params?: {
|
||||
page?: number;
|
||||
limit?: number;
|
||||
@@ -23,86 +20,93 @@ export const getTeams = async (params?: {
|
||||
visibility?: string;
|
||||
search?: string;
|
||||
}) => {
|
||||
const response = await api.get<TTeamListResponse>(TEAMS_BASE_URL, { params });
|
||||
const response = await api.get<TTeamListResponse>('/v1/hackathon/teams/browse', { params });
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export const getTeamById = async (teamId: string) => {
|
||||
const response = await api.get<TTeamDetailResponse>(`${TEAMS_BASE_URL}/${teamId}`);
|
||||
const response = await api.get<TTeamDetailResponse>(`/v1/hackathon/teams/${teamId}`);
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export const createTeam = async (data: TCreateTeamRequest) => {
|
||||
const response = await api.post<TTeamDetailResponse>(TEAMS_BASE_URL, data);
|
||||
const response = await api.post<TTeamDetailResponse>('/v1/hackathon/teams', data);
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export const updateTeam = async (teamId: string, data: TUpdateTeamRequest) => {
|
||||
const response = await api.put<TTeamDetailResponse>(`${TEAMS_BASE_URL}/${teamId}`, data);
|
||||
const response = await api.put<TTeamDetailResponse>(`/v1/hackathon/teams/${teamId}`, data);
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export const deleteTeam = async (teamId: string) => {
|
||||
const response = await api.delete(`/v1/hackathon/teams/${teamId}`);
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export const getTeamMembers = async (teamId: string) => {
|
||||
const response = await api.get<TTeamMembersResponse>(`${TEAMS_BASE_URL}/${teamId}/members`);
|
||||
const response = await api.get<TTeamMembersResponse>(`/v1/hackathon/teams/${teamId}`);
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export const inviteMember = async (teamId: string, data: TInviteMemberRequest) => {
|
||||
const response = await api.post(`${TEAMS_BASE_URL}/${teamId}/invite`, data);
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export const manageMember = async (teamId: string, userId: string, data: TManageMemberRequest) => {
|
||||
const response = await api.put(`${TEAMS_BASE_URL}/${teamId}/members/${userId}`, data);
|
||||
const response = await api.post(`/v1/hackathon/invitations/teams/${teamId}/invite`, data);
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export const removeMember = async (teamId: string, userId: string) => {
|
||||
const response = await api.delete(`${TEAMS_BASE_URL}/${teamId}/members/${userId}`);
|
||||
const response = await api.delete(`/v1/hackathon/teams/${teamId}/members/${userId}`);
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export const joinTeam = async (teamId: string, data: TJoinTeamRequest) => {
|
||||
const response = await api.post(`${TEAMS_BASE_URL}/${teamId}/join-request`, data);
|
||||
const response = await api.post(`/v1/hackathon/join-requests/teams/${teamId}`, data);
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export const getTeamJoinRequests = async (teamId: string) => {
|
||||
const response = await api.get<TTeamJoinRequestsResponse>(`${TEAMS_BASE_URL}/${teamId}/join-requests`);
|
||||
const response = await api.get<TTeamJoinRequestsResponse>(
|
||||
`/v1/hackathon/join-requests/teams/${teamId}/pending`
|
||||
);
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export const respondToJoinRequest = async (teamId: string, requestId: string, action: 'approve' | 'reject') => {
|
||||
const response = await api.put(`${TEAMS_BASE_URL}/${teamId}/join-requests/${requestId}`, { action });
|
||||
export const respondToJoinRequest = async (requestId: string, action: 'accept' | 'reject') => {
|
||||
const response = await api.post(`/v1/hackathon/join-requests/${requestId}/respond`, { action });
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export const getMyInvitations = async () => {
|
||||
const response = await api.get<TTeamInvitationsResponse>(`${TEAMS_BASE_URL}/invitations/me`);
|
||||
const response = await api.get<TTeamInvitationsResponse>('/v1/hackathon/invitations/my');
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export const respondToInvitation = async (invitationId: string, action: 'accept' | 'reject') => {
|
||||
const response = await api.put(`${TEAMS_BASE_URL}/invitations/${invitationId}`, { action });
|
||||
const response = await api.post(`/v1/hackathon/invitations/${invitationId}/respond`, { action });
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export const getMyTeams = async () => {
|
||||
const response = await api.get<TTeamListResponse>(`${TEAMS_BASE_URL}/me`);
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export const submitProject = async (teamId: string, data: TSubmitProjectRequest) => {
|
||||
const response = await api.post<TProjectSubmissionResponse>(`${TEAMS_BASE_URL}/${teamId}/submission`, data);
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export const getTeamSubmission = async (teamId: string) => {
|
||||
const response = await api.get<TProjectSubmissionResponse>(`${TEAMS_BASE_URL}/${teamId}/submission`);
|
||||
const response = await api.get('/v1/hackathon/teams/my');
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export const leaveTeam = async (teamId: string) => {
|
||||
const response = await api.post(`${TEAMS_BASE_URL}/${teamId}/leave`);
|
||||
const response = await api.post(`/v1/hackathon/teams/${teamId}/leave`);
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export const submitProject = async (teamId: string, data: TSubmitProjectRequest) => {
|
||||
const response = await api.post<TProjectSubmissionResponse>(
|
||||
`/v1/hackathon/submissions/teams/${teamId}`,
|
||||
data
|
||||
);
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export const getTeamSubmission = async (teamId: string) => {
|
||||
const response = await api.get<TProjectSubmissionResponse>(
|
||||
`/v1/hackathon/submissions/teams/${teamId}`
|
||||
);
|
||||
return response.data;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import { api, ApiResponse } from '../index';
|
||||
import type {
|
||||
TTestimonialsListItem,
|
||||
TTestimonialsDetailItem,
|
||||
TTestimonialCreateRequest,
|
||||
TTestimonialUpdateRequest,
|
||||
} from '../../types/testimonials';
|
||||
import type { TApiPaginated, TPaginationParams } from '../../types/common';
|
||||
|
||||
export const getTestimonialList = async (params?: TPaginationParams): Promise<TApiPaginated<TTestimonialsListItem>> => {
|
||||
const response = await api.get<TApiPaginated<TTestimonialsListItem>>('/v1/landing/cms/testimonials', { params });
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export const getTestimonialById = async (id: string): Promise<TTestimonialsDetailItem> => {
|
||||
const response = await api.get<ApiResponse<TTestimonialsDetailItem>>(`/v1/landing/cms/testimonials/detail/${id}`);
|
||||
return response.data.data;
|
||||
};
|
||||
|
||||
export const createTestimonial = async (data: TTestimonialCreateRequest): Promise<TTestimonialsDetailItem> => {
|
||||
const response = await api.post<ApiResponse<TTestimonialsDetailItem>>('/v1/landing/cms/testimonials/create', data);
|
||||
return response.data.data;
|
||||
};
|
||||
|
||||
export const updateTestimonial = async (id: string, data: TTestimonialUpdateRequest): Promise<TTestimonialsDetailItem> => {
|
||||
const response = await api.patch<ApiResponse<TTestimonialsDetailItem>>(`/v1/landing/cms/testimonials/update/${id}`, data);
|
||||
return response.data.data;
|
||||
};
|
||||
|
||||
export const deleteTestimonial = async (id: string): Promise<{ message: string }> => {
|
||||
const response = await api.delete<{ message: string }>(`/v1/landing/cms/testimonials/delete/${id}`);
|
||||
return response.data;
|
||||
};
|
||||
@@ -1,59 +1,39 @@
|
||||
import { api, ApiResponse } from '../index';
|
||||
|
||||
export interface UploadResponse {
|
||||
filename: string;
|
||||
original_filename: string;
|
||||
uploaded_path: string;
|
||||
filename?: string;
|
||||
original_filename?: string;
|
||||
uploaded_path?: string;
|
||||
url: string;
|
||||
size: number;
|
||||
content_type: string;
|
||||
file_type: string;
|
||||
user_id: string;
|
||||
email: string;
|
||||
size?: number;
|
||||
content_type?: string;
|
||||
file_type?: string;
|
||||
user_id?: string;
|
||||
email?: string;
|
||||
}
|
||||
|
||||
export interface UploadService {
|
||||
uploadFile(file: File): Promise<UploadResponse>;
|
||||
uploadAvatar(file: File): Promise<UploadResponse>;
|
||||
uploadCV(file: File): Promise<UploadResponse>;
|
||||
}
|
||||
const multipartPost = async (url: string, file: File, fieldName = 'file'): Promise<UploadResponse> => {
|
||||
const formData = new FormData();
|
||||
formData.append(fieldName, file);
|
||||
const response = await api.post<ApiResponse<UploadResponse>>(url, formData, {
|
||||
headers: { 'Content-Type': 'multipart/form-data' },
|
||||
});
|
||||
return response.data.data;
|
||||
};
|
||||
|
||||
export const uploadService: UploadService = {
|
||||
async uploadFile(file: File) {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
export const uploadUserFile = (file: File) => multipartPost('/v1/iam/users/upload', file);
|
||||
|
||||
const response = await api.post<ApiResponse<UploadResponse>>('/users/upload', formData, {
|
||||
headers: {
|
||||
'Content-Type': 'multipart/form-data',
|
||||
},
|
||||
});
|
||||
return response.data.data;
|
||||
},
|
||||
export const uploadHackathonFile = (file: File) => multipartPost('/v1/hackathon/upload', file);
|
||||
|
||||
async uploadAvatar(file: File) {
|
||||
if (!file.type.startsWith('image/')) {
|
||||
throw new Error('File harus berupa gambar');
|
||||
}
|
||||
export const uploadHackathonAvatar = (file: File) => multipartPost('/v1/hackathon/upload/avatar', file);
|
||||
|
||||
const maxSize = 5 * 1024 * 1024;
|
||||
if (file.size > maxSize) {
|
||||
throw new Error('Ukuran file maksimal 5MB');
|
||||
}
|
||||
export const uploadHackathonTeamFile = (file: File) => multipartPost('/v1/hackathon/upload/team', file);
|
||||
|
||||
return this.uploadFile(file);
|
||||
},
|
||||
export const uploadHackathonSubmission = (file: File) => multipartPost('/v1/hackathon/upload/submission', file);
|
||||
|
||||
async uploadCV(file: File) {
|
||||
if (file.type !== 'application/pdf') {
|
||||
throw new Error('CV harus berupa file PDF');
|
||||
}
|
||||
|
||||
const maxSize = 10 * 1024 * 1024;
|
||||
if (file.size > maxSize) {
|
||||
throw new Error('Ukuran file maksimal 10MB');
|
||||
}
|
||||
|
||||
return this.uploadFile(file);
|
||||
},
|
||||
// Legacy service object for backward compatibility
|
||||
export const uploadService = {
|
||||
uploadFile: uploadUserFile,
|
||||
uploadAvatar: uploadUserFile,
|
||||
uploadCV: uploadUserFile,
|
||||
};
|
||||
|
||||
@@ -1,89 +1,69 @@
|
||||
import { api, ApiResponse } from '../index';
|
||||
import { TUserItem } from '../../types/users';
|
||||
import type {
|
||||
TUsersListItem,
|
||||
TUsersDetailItem,
|
||||
TUserCreateRequest,
|
||||
TUserUpdateRequest,
|
||||
} from '../../types/users';
|
||||
import type { TApiPaginated, TPaginationParams } from '../../types/common';
|
||||
|
||||
export interface UserDetailResponseDto extends TUserItem {
|
||||
bio?: string;
|
||||
location?: string;
|
||||
website_url?: string;
|
||||
linkedin_url?: string;
|
||||
github_url?: string;
|
||||
twitter_url?: string;
|
||||
skills?: string[];
|
||||
career_status?: string;
|
||||
experience?: Array<{
|
||||
id: string;
|
||||
company: string;
|
||||
position: string;
|
||||
duration: string;
|
||||
period: string;
|
||||
}>;
|
||||
education?: Array<{
|
||||
id: string;
|
||||
institution: string;
|
||||
degree: string;
|
||||
field: string;
|
||||
period: string;
|
||||
}>;
|
||||
}
|
||||
// Re-export for backward compatibility
|
||||
export type UserDetailResponseDto = TUsersDetailItem;
|
||||
export type UserUpdateRequestDto = TUserUpdateRequest;
|
||||
|
||||
export interface UserUpdateRequestDto {
|
||||
fullname?: string;
|
||||
bio?: string;
|
||||
location?: string;
|
||||
website_url?: string;
|
||||
linkedin_url?: string;
|
||||
github_url?: string;
|
||||
twitter_url?: string;
|
||||
skills?: string[];
|
||||
phone_number?: string;
|
||||
birthdate?: string;
|
||||
gender?: string;
|
||||
career_status?: string;
|
||||
avatar?: string;
|
||||
cv_url?: string;
|
||||
phone_for_verification?: string;
|
||||
domicile?: string;
|
||||
experience?: Array<{
|
||||
id: string;
|
||||
company: string;
|
||||
position: string;
|
||||
duration: string;
|
||||
period: string;
|
||||
}>;
|
||||
education?: Array<{
|
||||
id: string;
|
||||
institution: string;
|
||||
degree: string;
|
||||
field: string;
|
||||
period: string;
|
||||
}>;
|
||||
}
|
||||
|
||||
export interface UserService {
|
||||
getUserMe(): Promise<UserDetailResponseDto>;
|
||||
getUserById(id: string): Promise<UserDetailResponseDto>;
|
||||
updateUserMe(data: UserUpdateRequestDto): Promise<UserDetailResponseDto>;
|
||||
updateUserById(id: string, data: UserUpdateRequestDto): Promise<UserDetailResponseDto>;
|
||||
}
|
||||
|
||||
export const userService: UserService = {
|
||||
async getUserMe() {
|
||||
const response = await api.get<ApiResponse<UserDetailResponseDto>>('/users/me');
|
||||
return response.data.data;
|
||||
},
|
||||
|
||||
async getUserById(id: string) {
|
||||
const response = await api.get<ApiResponse<UserDetailResponseDto>>(`/users/detail/${id}`);
|
||||
return response.data.data;
|
||||
},
|
||||
|
||||
async updateUserMe(data: UserUpdateRequestDto) {
|
||||
const response = await api.put<ApiResponse<UserDetailResponseDto>>('/users/update/me', data);
|
||||
return response.data.data;
|
||||
},
|
||||
|
||||
async updateUserById(id: string, data: UserUpdateRequestDto) {
|
||||
const response = await api.put<ApiResponse<UserDetailResponseDto>>(`/users/${id}`, data);
|
||||
return response.data.data;
|
||||
},
|
||||
export const getUserList = async (params?: TPaginationParams): Promise<TApiPaginated<TUsersListItem>> => {
|
||||
const response = await api.get<TApiPaginated<TUsersListItem>>('/v1/iam/users', { params });
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export const getUserMe = async (): Promise<TUsersDetailItem> => {
|
||||
const response = await api.get<ApiResponse<TUsersDetailItem>>('/v1/iam/users/me');
|
||||
return response.data.data;
|
||||
};
|
||||
|
||||
export const getUserById = async (id: string): Promise<TUsersDetailItem> => {
|
||||
const response = await api.get<ApiResponse<TUsersDetailItem>>(`/v1/iam/users/detail/${id}`);
|
||||
return response.data.data;
|
||||
};
|
||||
|
||||
export const createUser = async (data: TUserCreateRequest): Promise<TUsersDetailItem> => {
|
||||
const response = await api.post<ApiResponse<TUsersDetailItem>>('/v1/iam/users/create', data);
|
||||
return response.data.data;
|
||||
};
|
||||
|
||||
export const updateUserMe = async (data: TUserUpdateRequest): Promise<TUsersDetailItem> => {
|
||||
const response = await api.put<ApiResponse<TUsersDetailItem>>('/v1/iam/users/update/me', data);
|
||||
return response.data.data;
|
||||
};
|
||||
|
||||
export const updateUserById = async (id: string, data: TUserUpdateRequest): Promise<TUsersDetailItem> => {
|
||||
const response = await api.put<ApiResponse<TUsersDetailItem>>(`/v1/iam/users/update/${id}`, data);
|
||||
return response.data.data;
|
||||
};
|
||||
|
||||
export const activateUser = async (id: string, is_active: boolean): Promise<{ message: string }> => {
|
||||
const response = await api.put<{ message: string }>(`/v1/iam/users/activate/${id}`, { is_active });
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export const deleteUser = async (id: string): Promise<{ message: string }> => {
|
||||
const response = await api.delete<{ message: string }>(`/v1/iam/users/delete/${id}`);
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export const uploadUserFile = async (file: File): Promise<{ url: string }> => {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
const response = await api.post<ApiResponse<{ url: string }>>('/v1/iam/users/upload', formData, {
|
||||
headers: { 'Content-Type': 'multipart/form-data' },
|
||||
});
|
||||
return response.data.data;
|
||||
};
|
||||
|
||||
// Legacy service object for backward compatibility
|
||||
export const userService = {
|
||||
getUserMe,
|
||||
getUserById,
|
||||
updateUserMe,
|
||||
updateUserById: (id: string, data: TUserUpdateRequest) => updateUserById(id, data),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user