2024-05-14 08:56:54 +00:00
|
|
|
import { API_BASE_URL } from "@/helpers/common.helper";
|
2023-08-11 11:48:33 +00:00
|
|
|
// services
|
2024-05-14 16:39:29 +00:00
|
|
|
import { APIService } from "@/services/api.service";
|
2024-06-10 06:46:23 +00:00
|
|
|
// types
|
|
|
|
import { TIssuesResponse } from "@/types/issue";
|
2023-08-11 11:48:33 +00:00
|
|
|
|
|
|
|
class IssueService extends APIService {
|
|
|
|
constructor() {
|
2023-09-13 14:51:02 +00:00
|
|
|
super(API_BASE_URL);
|
2023-08-11 11:48:33 +00:00
|
|
|
}
|
|
|
|
|
2024-06-10 06:46:23 +00:00
|
|
|
async fetchPublicIssues(anchor: string, params: any): Promise<TIssuesResponse> {
|
|
|
|
return this.get(`/api/public/anchor/${anchor}/issues/`, {
|
2023-09-01 11:12:30 +00:00
|
|
|
params,
|
|
|
|
})
|
|
|
|
.then((response) => response?.data)
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-06-10 06:46:23 +00:00
|
|
|
async getIssueById(anchor: string, issueID: string): Promise<any> {
|
|
|
|
return this.get(`/api/public/anchor/${anchor}/issues/${issueID}/`)
|
2023-09-01 11:12:30 +00:00
|
|
|
.then((response) => response?.data)
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-06-10 06:46:23 +00:00
|
|
|
async getIssueVotes(anchor: string, issueID: string): Promise<any> {
|
|
|
|
return this.get(`/api/public/anchor/${anchor}/issues/${issueID}/votes/`)
|
2023-09-01 11:12:30 +00:00
|
|
|
.then((response) => response?.data)
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-06-10 06:46:23 +00:00
|
|
|
async createIssueVote(anchor: string, issueID: string, data: any): Promise<any> {
|
|
|
|
return this.post(`/api/public/anchor/${anchor}/issues/${issueID}/votes/`, data)
|
2023-09-01 11:12:30 +00:00
|
|
|
.then((response) => response?.data)
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-06-10 06:46:23 +00:00
|
|
|
async deleteIssueVote(anchor: string, issueID: string): Promise<any> {
|
|
|
|
return this.delete(`/api/public/anchor/${anchor}/issues/${issueID}/votes/`)
|
2023-09-01 11:12:30 +00:00
|
|
|
.then((response) => response?.data)
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-06-10 06:46:23 +00:00
|
|
|
async getIssueReactions(anchor: string, issueID: string): Promise<any> {
|
|
|
|
return this.get(`/api/public/anchor/${anchor}/issues/${issueID}/reactions/`)
|
2023-09-01 11:12:30 +00:00
|
|
|
.then((response) => response?.data)
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-06-10 06:46:23 +00:00
|
|
|
async createIssueReaction(anchor: string, issueID: string, data: any): Promise<any> {
|
|
|
|
return this.post(`/api/public/anchor/${anchor}/issues/${issueID}/reactions/`, data)
|
2023-09-01 11:12:30 +00:00
|
|
|
.then((response) => response?.data)
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-06-10 06:46:23 +00:00
|
|
|
async deleteIssueReaction(anchor: string, issueID: string, reactionId: string): Promise<any> {
|
|
|
|
return this.delete(`/api/public/anchor/${anchor}/issues/${issueID}/reactions/${reactionId}/`)
|
2023-09-01 11:12:30 +00:00
|
|
|
.then((response) => response?.data)
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-06-10 06:46:23 +00:00
|
|
|
async getIssueComments(anchor: string, issueID: string): Promise<any> {
|
|
|
|
return this.get(`/api/public/anchor/${anchor}/issues/${issueID}/comments/`)
|
2023-09-01 11:12:30 +00:00
|
|
|
.then((response) => response?.data)
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-06-10 06:46:23 +00:00
|
|
|
async createIssueComment(anchor: string, issueID: string, data: any): Promise<any> {
|
|
|
|
return this.post(`/api/public/anchor/${anchor}/issues/${issueID}/comments/`, data)
|
2023-09-01 11:12:30 +00:00
|
|
|
.then((response) => response?.data)
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-06-10 06:46:23 +00:00
|
|
|
async updateIssueComment(anchor: string, issueID: string, commentId: string, data: any): Promise<any> {
|
|
|
|
return this.patch(`/api/public/anchor/${anchor}/issues/${issueID}/comments/${commentId}/`, data)
|
2023-09-01 11:12:30 +00:00
|
|
|
.then((response) => response?.data)
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-06-10 06:46:23 +00:00
|
|
|
async deleteIssueComment(anchor: string, issueID: string, commentId: string): Promise<any> {
|
|
|
|
return this.delete(`/api/public/anchor/${anchor}/issues/${issueID}/comments/${commentId}/`)
|
2023-08-11 11:48:33 +00:00
|
|
|
.then((response) => response?.data)
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response;
|
|
|
|
});
|
|
|
|
}
|
2023-09-06 06:29:57 +00:00
|
|
|
|
|
|
|
async createCommentReaction(
|
2024-06-10 06:46:23 +00:00
|
|
|
anchor: string,
|
2023-09-06 06:29:57 +00:00
|
|
|
commentId: string,
|
|
|
|
data: {
|
|
|
|
reaction: string;
|
|
|
|
}
|
|
|
|
): Promise<any> {
|
2024-06-10 06:46:23 +00:00
|
|
|
return this.post(`/api/public/anchor/${anchor}/comments/${commentId}/reactions/`, data)
|
2023-09-06 06:29:57 +00:00
|
|
|
.then((response) => response?.data)
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-06-10 06:46:23 +00:00
|
|
|
async deleteCommentReaction(anchor: string, commentId: string, reactionHex: string): Promise<any> {
|
|
|
|
return this.delete(`/api/public/anchor/${anchor}/comments/${commentId}/reactions/${reactionHex}/`)
|
2023-09-06 06:29:57 +00:00
|
|
|
.then((response) => response?.data)
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response;
|
|
|
|
});
|
|
|
|
}
|
2023-08-11 11:48:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default IssueService;
|