231 lines
6.0 KiB
TypeScript
231 lines
6.0 KiB
TypeScript
import {
|
|
httpPostInterceptor,
|
|
httpGetInterceptor,
|
|
httpPutInterceptor,
|
|
httpDeleteInterceptor,
|
|
} from "./http-config/http-interceptor-service";
|
|
|
|
// Types
|
|
export interface MasterMenu {
|
|
id: number;
|
|
name: string;
|
|
description: string;
|
|
moduleId: number;
|
|
parentMenuId?: number;
|
|
group: string;
|
|
icon?: string;
|
|
statusId: number;
|
|
isActive: boolean;
|
|
position?: number;
|
|
createdAt?: string;
|
|
updatedAt?: string;
|
|
}
|
|
|
|
export interface MasterModule {
|
|
id: number;
|
|
name: string;
|
|
description: string;
|
|
pathUrl: string;
|
|
actionType?: string;
|
|
statusId: number;
|
|
isActive: boolean;
|
|
createdAt?: string;
|
|
updatedAt?: string;
|
|
}
|
|
|
|
export interface MenuModule {
|
|
id: number;
|
|
menuId: number;
|
|
moduleId: number;
|
|
position?: number;
|
|
isActive: boolean;
|
|
menu?: MasterMenu;
|
|
module?: MasterModule;
|
|
createdAt?: string;
|
|
updatedAt?: string;
|
|
}
|
|
|
|
export interface MenuModuleCreateRequest {
|
|
menuId: number;
|
|
moduleId: number;
|
|
position?: number;
|
|
isActive?: boolean;
|
|
}
|
|
|
|
export interface MenuModuleBatchCreateRequest {
|
|
menuId: number;
|
|
moduleIds: number[];
|
|
}
|
|
|
|
export interface MenuModuleUpdateRequest {
|
|
menuId?: number;
|
|
moduleId?: number;
|
|
position?: number;
|
|
isActive?: boolean;
|
|
}
|
|
|
|
// API Functions
|
|
export async function getMenuModules(params?: {
|
|
menuId?: number;
|
|
moduleId?: number;
|
|
page?: number;
|
|
limit?: number;
|
|
}) {
|
|
const queryParams = new URLSearchParams();
|
|
if (params?.menuId) queryParams.append("menu_id", params.menuId.toString());
|
|
if (params?.moduleId) queryParams.append("module_id", params.moduleId.toString());
|
|
if (params?.page) queryParams.append("page", params.page.toString());
|
|
if (params?.limit) queryParams.append("limit", params.limit.toString());
|
|
|
|
const url = `menu-modules${queryParams.toString() ? `?${queryParams.toString()}` : ""}`;
|
|
return httpGetInterceptor(url);
|
|
}
|
|
|
|
export async function getMenuModuleById(id: number) {
|
|
const url = `menu-modules/${id}`;
|
|
return httpGetInterceptor(url);
|
|
}
|
|
|
|
export async function getMenuModulesByMenuId(menuId: number) {
|
|
const url = `menu-modules/menu/${menuId}`;
|
|
return httpGetInterceptor(url);
|
|
}
|
|
|
|
export async function getMenuModulesByModuleId(moduleId: number) {
|
|
const url = `menu-modules/module/${moduleId}`;
|
|
return httpGetInterceptor(url);
|
|
}
|
|
|
|
export async function createMenuModule(data: MenuModuleCreateRequest) {
|
|
const url = "menu-modules";
|
|
return httpPostInterceptor(url, data);
|
|
}
|
|
|
|
export async function createMenuModulesBatch(data: MenuModuleBatchCreateRequest) {
|
|
const url = "menu-modules/batch";
|
|
return httpPostInterceptor(url, data);
|
|
}
|
|
|
|
export async function updateMenuModule(id: number, data: MenuModuleUpdateRequest) {
|
|
const url = `menu-modules/${id}`;
|
|
return httpPutInterceptor(url, data);
|
|
}
|
|
|
|
export async function deleteMenuModule(id: number) {
|
|
const url = `menu-modules/${id}`;
|
|
return httpDeleteInterceptor(url);
|
|
}
|
|
|
|
// Master Menus API
|
|
export async function getMasterMenus(params?: {
|
|
name?: string;
|
|
description?: string;
|
|
moduleId?: number;
|
|
parentMenuId?: number;
|
|
statusId?: number;
|
|
page?: number;
|
|
limit?: number;
|
|
}) {
|
|
const queryParams = new URLSearchParams();
|
|
if (params?.name) queryParams.append("name", params.name);
|
|
if (params?.description) queryParams.append("description", params.description);
|
|
if (params?.moduleId) queryParams.append("moduleId", params.moduleId.toString());
|
|
if (params?.parentMenuId) queryParams.append("parentMenuId", params.parentMenuId.toString());
|
|
if (params?.statusId) queryParams.append("statusId", params.statusId.toString());
|
|
if (params?.page) queryParams.append("page", params.page.toString());
|
|
if (params?.limit) queryParams.append("limit", params.limit.toString());
|
|
|
|
const url = `master-menus${queryParams.toString() ? `?${queryParams.toString()}` : ""}`;
|
|
return httpGetInterceptor(url);
|
|
}
|
|
|
|
export async function getMasterMenuById(id: number) {
|
|
const url = `master-menus/${id}`;
|
|
return httpGetInterceptor(url);
|
|
}
|
|
|
|
export async function createMasterMenu(data: {
|
|
name: string;
|
|
description: string;
|
|
moduleId?: number;
|
|
group: string;
|
|
statusId: number;
|
|
parentMenuId?: number;
|
|
icon?: string;
|
|
}) {
|
|
const url = "master-menus";
|
|
return httpPostInterceptor(url, data);
|
|
}
|
|
|
|
export async function updateMasterMenu(id: number, data: {
|
|
name: string;
|
|
description: string;
|
|
moduleId?: number;
|
|
group: string;
|
|
statusId: number;
|
|
parentMenuId?: number;
|
|
icon?: string;
|
|
}) {
|
|
const url = `master-menus/${id}`;
|
|
return httpPutInterceptor(url, data);
|
|
}
|
|
|
|
export async function deleteMasterMenu(id: number) {
|
|
const url = `master-menus/${id}`;
|
|
return httpDeleteInterceptor(url);
|
|
}
|
|
|
|
// Master Modules API
|
|
export async function getMasterModules(params?: {
|
|
name?: string;
|
|
description?: string;
|
|
statusId?: number;
|
|
page?: number;
|
|
limit?: number;
|
|
}) {
|
|
const queryParams = new URLSearchParams();
|
|
if (params?.name) queryParams.append("name", params.name);
|
|
if (params?.description) queryParams.append("description", params.description);
|
|
if (params?.statusId) queryParams.append("statusId", params.statusId.toString());
|
|
if (params?.page) queryParams.append("page", params.page.toString());
|
|
if (params?.limit) queryParams.append("limit", params.limit.toString());
|
|
|
|
const url = `master-modules${queryParams.toString() ? `?${queryParams.toString()}` : ""}`;
|
|
return httpGetInterceptor(url);
|
|
}
|
|
|
|
export async function getMasterModuleById(id: number) {
|
|
const url = `master-modules/${id}`;
|
|
return httpGetInterceptor(url);
|
|
}
|
|
|
|
export async function createMasterModule(data: {
|
|
name: string;
|
|
description: string;
|
|
pathUrl: string;
|
|
actionType?: string;
|
|
statusId: number;
|
|
menuIds?: number[];
|
|
}) {
|
|
const url = "master-modules";
|
|
return httpPostInterceptor(url, data);
|
|
}
|
|
|
|
export async function updateMasterModule(id: number, data: {
|
|
name: string;
|
|
description: string;
|
|
pathUrl: string;
|
|
actionType?: string;
|
|
statusId: number;
|
|
menuIds?: number[];
|
|
}) {
|
|
const url = `master-modules/${id}`;
|
|
return httpPutInterceptor(url, data);
|
|
}
|
|
|
|
export async function deleteMasterModule(id: number) {
|
|
const url = `master-modules/${id}`;
|
|
return httpDeleteInterceptor(url);
|
|
}
|
|
|