130 lines
3 KiB
TypeScript
130 lines
3 KiB
TypeScript
import { PagedAndSortedResultRequestDto, PagedResultDto } from '@/proxy/abp'
|
||
import { MenuDto } from '@/proxy/menus/models'
|
||
import apiService from '@/services/api.service'
|
||
|
||
export type ModuleLookupDto = {
|
||
key: string
|
||
name: string
|
||
group?: string
|
||
}
|
||
|
||
export class MenuService {
|
||
apiName = 'Default'
|
||
|
||
update = (id: string, input: MenuDto) =>
|
||
apiService.fetchData<MenuDto, MenuDto>(
|
||
{
|
||
method: 'PUT',
|
||
url: `/api/app/menu/${id}`,
|
||
data: input,
|
||
},
|
||
{ apiName: this.apiName },
|
||
)
|
||
|
||
create = (input: MenuDto) =>
|
||
apiService.fetchData<MenuDto, MenuDto>(
|
||
{
|
||
method: 'POST',
|
||
url: '/api/app/menu',
|
||
data: input,
|
||
},
|
||
{ apiName: this.apiName },
|
||
)
|
||
|
||
/** Menüyü tüm alanlarıyla günceller; görünen adın EN/TR dil metinlerini de yazar. */
|
||
updateWithLanguageKeyText = (id: string, input: MenuDto) =>
|
||
apiService.fetchData<MenuDto, MenuDto>(
|
||
{
|
||
method: 'PUT',
|
||
url: `/api/app/menu/${id}/with-language-key-text`,
|
||
data: input,
|
||
},
|
||
{ apiName: this.apiName },
|
||
)
|
||
|
||
createWithLanguageKeyText = (input: MenuDto) =>
|
||
apiService.fetchData<MenuDto, MenuDto>(
|
||
{
|
||
method: 'POST',
|
||
url: '/api/app/menu/with-language-key-text',
|
||
data: input,
|
||
},
|
||
{ apiName: this.apiName },
|
||
)
|
||
|
||
delete = (id: string) =>
|
||
apiService.fetchData<void>(
|
||
{
|
||
method: 'DELETE',
|
||
url: `/api/app/menu/${id}`,
|
||
},
|
||
{ apiName: this.apiName },
|
||
)
|
||
|
||
get = (id: string) =>
|
||
apiService.fetchData<MenuDto>(
|
||
{
|
||
method: 'GET',
|
||
url: `/api/app/menu/${id}`,
|
||
},
|
||
{ apiName: this.apiName },
|
||
)
|
||
|
||
getList = (input: PagedAndSortedResultRequestDto) =>
|
||
apiService.fetchData<PagedResultDto<MenuDto>, PagedAndSortedResultRequestDto>(
|
||
{
|
||
method: 'GET',
|
||
url: '/api/app/menu',
|
||
params: {
|
||
sorting: input.sorting,
|
||
skipCount: input.skipCount,
|
||
maxResultCount: input.maxResultCount,
|
||
},
|
||
},
|
||
{ apiName: this.apiName },
|
||
)
|
||
|
||
updateAll = (inputs: MenuDto[]) =>
|
||
apiService.fetchData<void, MenuDto[]>(
|
||
{
|
||
method: 'PUT',
|
||
url: '/api/app/menu/all',
|
||
data: inputs,
|
||
},
|
||
{ apiName: this.apiName },
|
||
)
|
||
|
||
getListMainMenu = () =>
|
||
apiService.fetchData<MenuDto[]>(
|
||
{
|
||
method: 'GET',
|
||
url: `/api/app/menu/main-menu`,
|
||
},
|
||
{ apiName: this.apiName },
|
||
)
|
||
|
||
getModules = () =>
|
||
apiService.fetchData<ModuleLookupDto[]>(
|
||
{
|
||
method: 'GET',
|
||
url: '/api/app/menu/modules',
|
||
},
|
||
{ apiName: this.apiName },
|
||
)
|
||
}
|
||
|
||
export const getMenus = async (skipCount = 0, maxResultCount = 1000, sorting = 'order') => {
|
||
const menuService = new MenuService()
|
||
|
||
return await menuService.getList({
|
||
sorting,
|
||
skipCount,
|
||
maxResultCount,
|
||
})
|
||
}
|
||
|
||
export const getModules = async () => {
|
||
const menuService = new MenuService()
|
||
|
||
return await menuService.getModules()
|
||
}
|