2022-11-19 14:21:26 +00:00
|
|
|
// api routes
|
|
|
|
import {
|
|
|
|
ISSUES_ENDPOINT,
|
|
|
|
ISSUE_DETAIL,
|
|
|
|
ISSUE_ACTIVITIES,
|
|
|
|
ISSUE_COMMENTS,
|
|
|
|
ISSUE_COMMENT_DETAIL,
|
|
|
|
ISSUE_PROPERTIES_ENDPOINT,
|
|
|
|
CYCLE_DETAIL,
|
|
|
|
ISSUE_LABELS,
|
2022-11-30 15:58:45 +00:00
|
|
|
BULK_DELETE_ISSUES,
|
|
|
|
BULK_ADD_ISSUES_TO_CYCLE,
|
2022-12-06 14:38:28 +00:00
|
|
|
REMOVE_ISSUE_FROM_CYCLE,
|
|
|
|
ISSUE_LABEL_DETAILS,
|
2022-11-19 14:21:26 +00:00
|
|
|
} from "constants/api-routes";
|
|
|
|
// services
|
|
|
|
import APIService from "lib/services/api.service";
|
|
|
|
import { IIssue, IIssueComment } from "types";
|
|
|
|
|
2022-11-30 21:39:33 +00:00
|
|
|
const { NEXT_PUBLIC_API_BASE_URL } = process.env;
|
|
|
|
|
2022-11-19 14:21:26 +00:00
|
|
|
class ProjectIssuesServices extends APIService {
|
|
|
|
constructor() {
|
2022-11-30 21:39:33 +00:00
|
|
|
super(NEXT_PUBLIC_API_BASE_URL || "http://localhost:8000");
|
2022-11-19 14:21:26 +00:00
|
|
|
}
|
|
|
|
|
2022-12-02 14:12:58 +00:00
|
|
|
async createIssues(workspaceSlug: string, projectId: string, data: any): Promise<any> {
|
|
|
|
return this.post(ISSUES_ENDPOINT(workspaceSlug, projectId), data)
|
2022-11-19 14:21:26 +00:00
|
|
|
.then((response) => {
|
|
|
|
return response?.data;
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-12-02 14:12:58 +00:00
|
|
|
async getIssues(workspaceSlug: string, projectId: string): Promise<any> {
|
|
|
|
return this.get(ISSUES_ENDPOINT(workspaceSlug, projectId))
|
2022-11-19 14:21:26 +00:00
|
|
|
.then((response) => {
|
|
|
|
return response?.data;
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-12-02 14:12:58 +00:00
|
|
|
async getIssue(workspaceSlug: string, projectId: string, issueId: string): Promise<any> {
|
|
|
|
return this.get(ISSUE_DETAIL(workspaceSlug, projectId, issueId))
|
2022-11-19 14:21:26 +00:00
|
|
|
.then((response) => {
|
|
|
|
return response?.data;
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async getIssueActivities(
|
2022-12-02 14:12:58 +00:00
|
|
|
workspaceSlug: string,
|
2022-11-19 14:21:26 +00:00
|
|
|
projectId: string,
|
|
|
|
issueId: string
|
|
|
|
): Promise<any> {
|
2022-12-02 14:12:58 +00:00
|
|
|
return this.get(ISSUE_ACTIVITIES(workspaceSlug, projectId, issueId))
|
2022-11-19 14:21:26 +00:00
|
|
|
.then((response) => {
|
|
|
|
return response?.data;
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-12-02 14:12:58 +00:00
|
|
|
async getIssueComments(workspaceSlug: string, projectId: string, issueId: string): Promise<any> {
|
|
|
|
return this.get(ISSUE_COMMENTS(workspaceSlug, projectId, issueId))
|
2022-11-19 14:21:26 +00:00
|
|
|
.then((response) => {
|
|
|
|
return response?.data;
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-12-02 14:12:58 +00:00
|
|
|
async getIssueProperties(workspaceSlug: string, projectId: string): Promise<any> {
|
|
|
|
return this.get(ISSUE_PROPERTIES_ENDPOINT(workspaceSlug, projectId))
|
2022-11-19 14:21:26 +00:00
|
|
|
.then((response) => {
|
|
|
|
return response?.data;
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-12-13 15:52:44 +00:00
|
|
|
async addIssueToCycle(
|
2022-12-02 14:12:58 +00:00
|
|
|
workspaceSlug: string,
|
2022-11-19 14:21:26 +00:00
|
|
|
projectId: string,
|
|
|
|
cycleId: string,
|
|
|
|
data: {
|
|
|
|
issue: string;
|
|
|
|
}
|
|
|
|
) {
|
2022-12-02 14:12:58 +00:00
|
|
|
return this.post(CYCLE_DETAIL(workspaceSlug, projectId, cycleId), data)
|
2022-11-19 14:21:26 +00:00
|
|
|
.then((response) => {
|
|
|
|
return response?.data;
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-12-06 14:38:28 +00:00
|
|
|
async removeIssueFromCycle(
|
|
|
|
workspaceSlug: string,
|
|
|
|
projectId: string,
|
|
|
|
cycleId: string,
|
|
|
|
bridgeId: string
|
|
|
|
) {
|
|
|
|
return this.delete(REMOVE_ISSUE_FROM_CYCLE(workspaceSlug, projectId, cycleId, bridgeId))
|
|
|
|
.then((response) => {
|
|
|
|
return response?.data;
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-12-02 14:12:58 +00:00
|
|
|
async createIssueProperties(workspaceSlug: string, projectId: string, data: any): Promise<any> {
|
|
|
|
return this.post(ISSUE_PROPERTIES_ENDPOINT(workspaceSlug, projectId), data)
|
2022-11-19 14:21:26 +00:00
|
|
|
.then((response) => {
|
|
|
|
return response?.data;
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async patchIssueProperties(
|
2022-12-02 14:12:58 +00:00
|
|
|
workspaceSlug: string,
|
2022-11-19 14:21:26 +00:00
|
|
|
projectId: string,
|
|
|
|
issuePropertyId: string,
|
|
|
|
data: any
|
|
|
|
): Promise<any> {
|
|
|
|
return this.patch(
|
2022-12-02 14:12:58 +00:00
|
|
|
ISSUE_PROPERTIES_ENDPOINT(workspaceSlug, projectId) + `${issuePropertyId}/`,
|
2022-11-19 14:21:26 +00:00
|
|
|
data
|
|
|
|
)
|
|
|
|
|
|
|
|
.then((response) => {
|
|
|
|
return response?.data;
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async createIssueComment(
|
2022-12-02 14:12:58 +00:00
|
|
|
workspaceSlug: string,
|
2022-11-19 14:21:26 +00:00
|
|
|
projectId: string,
|
|
|
|
issueId: string,
|
|
|
|
data: any
|
|
|
|
): Promise<any> {
|
2022-12-02 14:12:58 +00:00
|
|
|
return this.post(ISSUE_COMMENTS(workspaceSlug, projectId, issueId), data)
|
2022-11-19 14:21:26 +00:00
|
|
|
.then((response) => {
|
|
|
|
return response?.data;
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async patchIssueComment(
|
2022-12-02 14:12:58 +00:00
|
|
|
workspaceSlug: string,
|
2022-11-19 14:21:26 +00:00
|
|
|
projectId: string,
|
|
|
|
issueId: string,
|
|
|
|
commentId: string,
|
|
|
|
data: IIssueComment
|
|
|
|
): Promise<any> {
|
2022-12-02 14:12:58 +00:00
|
|
|
return this.patch(ISSUE_COMMENT_DETAIL(workspaceSlug, projectId, issueId, commentId), data)
|
2022-11-19 14:21:26 +00:00
|
|
|
.then((response) => {
|
|
|
|
return response?.data;
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async deleteIssueComment(
|
2022-12-02 14:12:58 +00:00
|
|
|
workspaceSlug: string,
|
2022-11-19 14:21:26 +00:00
|
|
|
projectId: string,
|
|
|
|
issueId: string,
|
|
|
|
commentId: string
|
|
|
|
): Promise<any> {
|
2022-12-02 14:12:58 +00:00
|
|
|
return this.delete(ISSUE_COMMENT_DETAIL(workspaceSlug, projectId, issueId, commentId))
|
2022-11-19 14:21:26 +00:00
|
|
|
.then((response) => {
|
|
|
|
return response?.data;
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-12-02 14:12:58 +00:00
|
|
|
async getIssueLabels(workspaceSlug: string, projectId: string): Promise<any> {
|
|
|
|
return this.get(ISSUE_LABELS(workspaceSlug, projectId))
|
2022-11-19 14:21:26 +00:00
|
|
|
.then((response) => {
|
|
|
|
return response?.data;
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-12-02 14:12:58 +00:00
|
|
|
async createIssueLabel(workspaceSlug: string, projectId: string, data: any): Promise<any> {
|
|
|
|
return this.post(ISSUE_LABELS(workspaceSlug, projectId), data)
|
2022-11-19 14:21:26 +00:00
|
|
|
.then((response) => {
|
|
|
|
return response?.data;
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-12-06 14:38:28 +00:00
|
|
|
async patchIssueLabel(
|
|
|
|
workspaceSlug: string,
|
|
|
|
projectId: string,
|
|
|
|
labelId: string,
|
|
|
|
data: any
|
|
|
|
): Promise<any> {
|
|
|
|
return this.patch(ISSUE_LABEL_DETAILS(workspaceSlug, projectId, labelId), data)
|
|
|
|
.then((response) => {
|
|
|
|
return response?.data;
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async deleteIssueLabel(workspaceSlug: string, projectId: string, labelId: string): Promise<any> {
|
|
|
|
return this.delete(ISSUE_LABEL_DETAILS(workspaceSlug, projectId, labelId))
|
|
|
|
.then((response) => {
|
|
|
|
return response?.data;
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-11-19 14:21:26 +00:00
|
|
|
async updateIssue(
|
2022-12-02 14:12:58 +00:00
|
|
|
workspaceSlug: string,
|
2022-11-19 14:21:26 +00:00
|
|
|
projectId: string,
|
|
|
|
issueId: string,
|
|
|
|
data: any
|
|
|
|
): Promise<any> {
|
2022-12-02 14:12:58 +00:00
|
|
|
return this.put(ISSUE_DETAIL(workspaceSlug, projectId, issueId), data)
|
2022-11-19 14:21:26 +00:00
|
|
|
.then((response) => {
|
|
|
|
return response?.data;
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async patchIssue(
|
2022-12-02 14:12:58 +00:00
|
|
|
workspaceSlug: string,
|
2022-11-19 14:21:26 +00:00
|
|
|
projectId: string,
|
|
|
|
issueId: string,
|
|
|
|
data: Partial<IIssue>
|
|
|
|
): Promise<any> {
|
2022-12-02 14:12:58 +00:00
|
|
|
return this.patch(ISSUE_DETAIL(workspaceSlug, projectId, issueId), data)
|
2022-11-19 14:21:26 +00:00
|
|
|
.then((response) => {
|
|
|
|
return response?.data;
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-12-02 14:12:58 +00:00
|
|
|
async deleteIssue(workspaceSlug: string, projectId: string, issuesId: string): Promise<any> {
|
|
|
|
return this.delete(ISSUE_DETAIL(workspaceSlug, projectId, issuesId))
|
2022-11-19 14:21:26 +00:00
|
|
|
.then((response) => {
|
|
|
|
return response?.data;
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
2022-11-30 15:58:45 +00:00
|
|
|
|
2022-12-02 14:12:58 +00:00
|
|
|
async bulkDeleteIssues(workspaceSlug: string, projectId: string, data: any): Promise<any> {
|
|
|
|
return this.delete(BULK_DELETE_ISSUES(workspaceSlug, projectId), data)
|
2022-11-30 15:58:45 +00:00
|
|
|
.then((response) => {
|
|
|
|
return response?.data;
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async bulkAddIssuesToCycle(
|
2022-12-02 14:12:58 +00:00
|
|
|
workspaceSlug: string,
|
2022-11-30 15:58:45 +00:00
|
|
|
projectId: string,
|
|
|
|
cycleId: string,
|
|
|
|
data: any
|
|
|
|
): Promise<any> {
|
2022-12-02 14:12:58 +00:00
|
|
|
return this.post(BULK_ADD_ISSUES_TO_CYCLE(workspaceSlug, projectId, cycleId), data)
|
2022-11-30 15:58:45 +00:00
|
|
|
.then((response) => {
|
|
|
|
return response?.data;
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
2022-11-19 14:21:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default new ProjectIssuesServices();
|