plane/apps/app/lib/services/issues.service.ts

294 lines
7.5 KiB
TypeScript
Raw Normal View History

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,
BULK_DELETE_ISSUES,
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";
const { NEXT_PUBLIC_API_BASE_URL } = process.env;
2022-11-19 14:21:26 +00:00
class ProjectIssuesServices extends APIService {
constructor() {
super(NEXT_PUBLIC_API_BASE_URL || "http://localhost:8000");
2022-11-19 14:21:26 +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;
});
}
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;
});
}
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(
workspaceSlug: string,
2022-11-19 14:21:26 +00:00
projectId: string,
issueId: string
): Promise<any> {
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;
});
}
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;
});
}
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;
});
}
async addIssueToCycle(
workspaceSlug: string,
2022-11-19 14:21:26 +00:00
projectId: string,
cycleId: string,
data: {
issues: string[];
2022-11-19 14:21:26 +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;
});
}
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;
});
}
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(
workspaceSlug: string,
2022-11-19 14:21:26 +00:00
projectId: string,
issuePropertyId: string,
data: any
): Promise<any> {
return this.patch(
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(
workspaceSlug: string,
2022-11-19 14:21:26 +00:00
projectId: string,
issueId: string,
data: any
): Promise<any> {
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(
workspaceSlug: string,
2022-11-19 14:21:26 +00:00
projectId: string,
issueId: string,
commentId: string,
data: IIssueComment
): Promise<any> {
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(
workspaceSlug: string,
2022-11-19 14:21:26 +00:00
projectId: string,
issueId: string,
commentId: string
): Promise<any> {
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;
});
}
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;
});
}
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;
});
}
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(
workspaceSlug: string,
2022-11-19 14:21:26 +00:00
projectId: string,
issueId: string,
data: any
): Promise<any> {
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(
workspaceSlug: string,
2022-11-19 14:21:26 +00:00
projectId: string,
issueId: string,
data: Partial<IIssue>
): Promise<any> {
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;
});
}
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;
});
}
async bulkDeleteIssues(workspaceSlug: string, projectId: string, data: any): Promise<any> {
return this.delete(BULK_DELETE_ISSUES(workspaceSlug, projectId), data)
.then((response) => {
return response?.data;
})
.catch((error) => {
throw error?.response?.data;
});
}
2022-11-19 14:21:26 +00:00
}
export default new ProjectIssuesServices();