2019-10-24 07:03:59 +00:00
|
|
|
import Api from "./Api";
|
|
|
|
|
import { ApiResponse } from "./ApiResponses";
|
2019-10-29 12:02:58 +00:00
|
|
|
import { AxiosPromise } from "axios";
|
2019-10-24 07:03:59 +00:00
|
|
|
|
|
|
|
|
export interface PublishApplicationRequest {
|
|
|
|
|
applicationId: string;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-15 09:47:39 +00:00
|
|
|
export interface ChangeAppViewAccessRequest {
|
|
|
|
|
applicationId: string;
|
|
|
|
|
publicAccess: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-24 07:03:59 +00:00
|
|
|
export interface PublishApplicationResponse extends ApiResponse {
|
|
|
|
|
data: {};
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-07 04:59:40 +00:00
|
|
|
export interface ApplicationPagePayload {
|
|
|
|
|
id: string;
|
|
|
|
|
name: string;
|
|
|
|
|
isDefault: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface ApplicationResponsePayload {
|
|
|
|
|
id: string;
|
|
|
|
|
name: string;
|
|
|
|
|
organizationId: string;
|
|
|
|
|
pages?: ApplicationPagePayload[];
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-25 10:04:57 +00:00
|
|
|
// export interface FetchApplicationResponse extends ApiResponse {
|
|
|
|
|
// data: ApplicationResponsePayload & { pages: ApplicationPagePayload[] };
|
|
|
|
|
// }
|
2020-03-06 04:59:24 +00:00
|
|
|
|
2019-11-07 04:59:40 +00:00
|
|
|
export interface FetchApplicationsResponse extends ApiResponse {
|
|
|
|
|
data: Array<ApplicationResponsePayload & { pages: ApplicationPagePayload[] }>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface CreateApplicationResponse extends ApiResponse {
|
|
|
|
|
data: ApplicationResponsePayload;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface CreateApplicationRequest {
|
|
|
|
|
name: string;
|
2020-05-27 13:36:06 +00:00
|
|
|
orgId: string;
|
2019-11-07 04:59:40 +00:00
|
|
|
}
|
|
|
|
|
|
2020-01-27 08:24:58 +00:00
|
|
|
export interface SetDefaultPageRequest {
|
|
|
|
|
pageId: string;
|
|
|
|
|
applicationId: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface DeleteApplicationRequest {
|
|
|
|
|
applicationId: string;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-27 13:36:06 +00:00
|
|
|
export interface GetAllApplicationResponse extends ApiResponse {
|
|
|
|
|
data: Array<ApplicationResponsePayload & { pages: ApplicationPagePayload[] }>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface ApplicationObject {
|
|
|
|
|
id: string;
|
|
|
|
|
name: string;
|
|
|
|
|
organizationId: string;
|
|
|
|
|
pages: ApplicationPagePayload[];
|
|
|
|
|
userPermissions: string[];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface OrganizationApplicationObject {
|
|
|
|
|
applications: Array<ApplicationObject>;
|
|
|
|
|
organization: {
|
|
|
|
|
id: string;
|
|
|
|
|
name: string;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
export interface FetchUsersApplicationsOrgsResponse extends ApiResponse {
|
|
|
|
|
data: {
|
|
|
|
|
organizationApplications: Array<OrganizationApplicationObject>;
|
|
|
|
|
user: string;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-24 07:03:59 +00:00
|
|
|
class ApplicationApi extends Api {
|
|
|
|
|
static baseURL = "v1/applications/";
|
|
|
|
|
static publishURLPath = (applicationId: string) => `publish/${applicationId}`;
|
2020-05-27 13:36:06 +00:00
|
|
|
static createApplicationPath = (orgId: string) => `?orgId=${orgId}`;
|
2020-07-15 09:47:39 +00:00
|
|
|
static changeAppViewAccessPath = (applicationId: string) =>
|
|
|
|
|
`${applicationId}/changeAccess`;
|
2020-01-27 08:24:58 +00:00
|
|
|
static setDefaultPagePath = (request: SetDefaultPageRequest) =>
|
|
|
|
|
`${ApplicationApi.baseURL}${request.applicationId}/page/${request.pageId}/makeDefault`;
|
2019-10-24 07:03:59 +00:00
|
|
|
static publishApplication(
|
|
|
|
|
publishApplicationRequest: PublishApplicationRequest,
|
2019-10-29 12:02:58 +00:00
|
|
|
): AxiosPromise<PublishApplicationResponse> {
|
2019-10-24 07:03:59 +00:00
|
|
|
return Api.post(
|
|
|
|
|
ApplicationApi.baseURL +
|
|
|
|
|
ApplicationApi.publishURLPath(publishApplicationRequest.applicationId),
|
|
|
|
|
undefined,
|
|
|
|
|
{},
|
|
|
|
|
);
|
|
|
|
|
}
|
2019-11-07 04:59:40 +00:00
|
|
|
static fetchApplications(): AxiosPromise<FetchApplicationsResponse> {
|
|
|
|
|
return Api.get(ApplicationApi.baseURL);
|
|
|
|
|
}
|
2020-05-27 13:36:06 +00:00
|
|
|
|
|
|
|
|
static getAllApplication(): AxiosPromise<GetAllApplicationResponse> {
|
|
|
|
|
return Api.get(ApplicationApi.baseURL + "new");
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-06 04:59:24 +00:00
|
|
|
static fetchApplication(
|
|
|
|
|
applicationId: string,
|
|
|
|
|
): AxiosPromise<FetchApplicationsResponse> {
|
|
|
|
|
return Api.get(ApplicationApi.baseURL + applicationId);
|
|
|
|
|
}
|
2020-05-27 13:36:06 +00:00
|
|
|
|
2019-11-07 04:59:40 +00:00
|
|
|
static createApplication(
|
|
|
|
|
request: CreateApplicationRequest,
|
2020-05-27 13:36:06 +00:00
|
|
|
): AxiosPromise<PublishApplicationResponse> {
|
|
|
|
|
return Api.post(
|
|
|
|
|
ApplicationApi.baseURL +
|
|
|
|
|
ApplicationApi.createApplicationPath(request.orgId),
|
|
|
|
|
{ name: request.name },
|
|
|
|
|
);
|
2019-11-07 04:59:40 +00:00
|
|
|
}
|
2020-01-27 08:24:58 +00:00
|
|
|
|
|
|
|
|
static setDefaultApplicationPage(
|
|
|
|
|
request: SetDefaultPageRequest,
|
|
|
|
|
): AxiosPromise<ApiResponse> {
|
|
|
|
|
return Api.put(ApplicationApi.setDefaultPagePath(request));
|
|
|
|
|
}
|
2020-07-15 09:47:39 +00:00
|
|
|
|
|
|
|
|
static changeAppViewAccess(
|
|
|
|
|
request: ChangeAppViewAccessRequest,
|
|
|
|
|
): AxiosPromise<ApiResponse> {
|
|
|
|
|
return Api.put(
|
|
|
|
|
ApplicationApi.baseURL +
|
|
|
|
|
ApplicationApi.changeAppViewAccessPath(request.applicationId),
|
|
|
|
|
{ publicAccess: request.publicAccess },
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-27 08:24:58 +00:00
|
|
|
static deleteApplication(
|
|
|
|
|
request: DeleteApplicationRequest,
|
|
|
|
|
): AxiosPromise<ApiResponse> {
|
|
|
|
|
return Api.delete(ApplicationApi.baseURL + request.applicationId);
|
|
|
|
|
}
|
2019-10-24 07:03:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default ApplicationApi;
|