2023-04-19 10:10:31 +00:00
|
|
|
import APIService from "services/api.service";
|
2023-05-05 10:15:38 +00:00
|
|
|
import trackEventServices from "services/track-event.service";
|
2023-04-19 10:10:31 +00:00
|
|
|
|
|
|
|
// types
|
2023-06-06 16:06:00 +00:00
|
|
|
import { IJiraMetadata, IJiraResponse, IJiraImporterForm, ICurrentUserResponse } from "types";
|
2023-04-19 10:10:31 +00:00
|
|
|
|
|
|
|
const { NEXT_PUBLIC_API_BASE_URL } = process.env;
|
|
|
|
|
2023-05-05 10:15:38 +00:00
|
|
|
const trackEvent =
|
|
|
|
process.env.NEXT_PUBLIC_TRACK_EVENTS === "true" || process.env.NEXT_PUBLIC_TRACK_EVENTS === "1";
|
|
|
|
|
2023-04-19 10:10:31 +00:00
|
|
|
class JiraImportedService extends APIService {
|
|
|
|
constructor() {
|
|
|
|
super(NEXT_PUBLIC_API_BASE_URL || "http://localhost:8000");
|
|
|
|
}
|
|
|
|
|
|
|
|
async getJiraProjectInfo(workspaceSlug: string, params: IJiraMetadata): Promise<IJiraResponse> {
|
|
|
|
return this.get(`/api/workspaces/${workspaceSlug}/importers/jira`, {
|
|
|
|
params,
|
|
|
|
})
|
|
|
|
.then((response) => response?.data)
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-06-06 16:06:00 +00:00
|
|
|
async createJiraImporter(
|
|
|
|
workspaceSlug: string,
|
|
|
|
data: IJiraImporterForm,
|
|
|
|
user: ICurrentUserResponse | undefined
|
|
|
|
): Promise<IJiraResponse> {
|
2023-04-19 10:10:31 +00:00
|
|
|
return this.post(`/api/workspaces/${workspaceSlug}/projects/importers/jira/`, data)
|
2023-05-05 10:15:38 +00:00
|
|
|
.then((response) => {
|
|
|
|
if (trackEvent)
|
2023-06-06 16:06:00 +00:00
|
|
|
trackEventServices.trackImporterEvent(response?.data, "JIRA_IMPORTER_CREATE", user);
|
2023-05-05 10:15:38 +00:00
|
|
|
return response?.data;
|
|
|
|
})
|
2023-04-19 10:10:31 +00:00
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const jiraImporterService = new JiraImportedService();
|
|
|
|
|
|
|
|
export default jiraImporterService;
|