PromucFlow_constructor/app/client/src/api/AppThemingApi.tsx
Valera Melnikov fb12f6ad87
chore:add eslint rules (#27878)
Add eslint rules
- promise-function-async
- prefer-nullish-coalescing
2023-10-09 16:54:06 +03:00

103 lines
2.2 KiB
TypeScript

import API from "api/Api";
import type { AxiosPromise } from "axios";
import type { AppTheme } from "entities/AppTheming";
import type { ApiResponse } from "./ApiResponses";
class AppThemingApi extends API {
static baseUrl = "/v1";
/**
* fires api to get all themes
*
* @returns
*/
static async fetchThemes(
applicationId: string,
): Promise<AxiosPromise<ApiResponse<AppTheme[]>>> {
return API.get(
`${AppThemingApi.baseUrl}/themes/applications/${applicationId}`,
);
}
/**
* fires api to fetch selected theme
*
* @param applicationId
* @returns
*/
static async fetchSelected(
applicationId: string,
mode = "EDIT",
): Promise<AxiosPromise<ApiResponse<AppTheme[]>>> {
return API.get(
`${AppThemingApi.baseUrl}/themes/applications/${applicationId}/current?mode=${mode}`,
);
}
/**
* fires api to updating current theme
*
* @param applicationId
* @param theme
* @returns
*/
static async updateTheme(
applicationId: string,
theme: AppTheme,
): Promise<AxiosPromise<ApiResponse<AppTheme[]>>> {
return API.put(
`${AppThemingApi.baseUrl}/themes/applications/${applicationId}`,
theme,
);
}
/**
* fires api to updating current theme
*
* @param applicationId
* @param theme
* @returns
*/
static async changeTheme(
applicationId: string,
theme: AppTheme,
): Promise<AxiosPromise<ApiResponse<AppTheme[]>>> {
return API.patch(
`${AppThemingApi.baseUrl}/applications/${applicationId}/themes/${theme.id}`,
theme,
);
}
/**
* fires api for saving current theme
*
* @param applicationId
* @param theme
* @returns
*/
static async saveTheme(
applicationId: string,
payload: { name: string },
): Promise<AxiosPromise<ApiResponse<AppTheme[]>>> {
return API.patch(
`${AppThemingApi.baseUrl}/themes/applications/${applicationId}`,
payload,
);
}
/**
* fires api for deleting theme
*
* @param applicationId
* @param theme
* @returns
*/
static async deleteTheme(
themeId: string,
): Promise<AxiosPromise<ApiResponse<AppTheme[]>>> {
return API.delete(`${AppThemingApi.baseUrl}/themes/${themeId}`);
}
}
export default AppThemingApi;