feat: add superadmin plan management module
This commit is contained in:
56
src/services/api/plan.service.ts
Normal file
56
src/services/api/plan.service.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import axiosClient from '../axios/axios';
|
||||
import type { Plan, PlanListParams, PlanListResponse, PlanRequest } from '@/types';
|
||||
|
||||
const PLANS_ENDPOINT = 'api/superadmin/plans';
|
||||
|
||||
function toPlanPayload(payload: PlanRequest) {
|
||||
return {
|
||||
name: payload.name,
|
||||
slug: payload.slug,
|
||||
description: payload.description,
|
||||
price: payload.price,
|
||||
billing_cycle: payload.billing_cycle,
|
||||
trial_days: payload.trial_days,
|
||||
max_projects: payload.max_projects,
|
||||
max_organizations: payload.max_organizations,
|
||||
max_users: payload.max_users,
|
||||
max_roles: payload.max_roles,
|
||||
permission_ids: payload.permission_ids,
|
||||
is_active: payload.is_active,
|
||||
is_custom: payload.is_custom,
|
||||
};
|
||||
}
|
||||
|
||||
export const planService = {
|
||||
getPlans: async (params?: PlanListParams): Promise<PlanListResponse> => {
|
||||
const response = await axiosClient.get<PlanListResponse>(PLANS_ENDPOINT, {
|
||||
params: {
|
||||
skip: params?.skip ?? 0,
|
||||
limit: params?.limit ?? 10,
|
||||
search_term: params?.search_term,
|
||||
name: params?.name,
|
||||
slug: params?.slug,
|
||||
is_active: params?.is_active,
|
||||
is_custom: params?.is_custom,
|
||||
sort_by: params?.sort_by,
|
||||
sort_order: params?.sort_order,
|
||||
},
|
||||
});
|
||||
return response.data;
|
||||
},
|
||||
|
||||
savePlan: async (payload: PlanRequest): Promise<Plan> => {
|
||||
const requestPayload = toPlanPayload(payload);
|
||||
const response = payload.id
|
||||
? await axiosClient.put<Plan>(`${PLANS_ENDPOINT}/${payload.id}`, requestPayload)
|
||||
: await axiosClient.post<Plan>(PLANS_ENDPOINT, requestPayload);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
updatePlanStatus: async (id: number, isActive: boolean): Promise<Plan> => {
|
||||
const response = await axiosClient.patch<Plan>(`${PLANS_ENDPOINT}/${id}/status`, {
|
||||
is_active: isActive,
|
||||
});
|
||||
return response.data;
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user