bb-plane-fork/packages/services/src/cycle/cycle-operations.service.ts
sriram veeraghanta 043f4eaa5e
chore: common services package (#6255)
* fix: initial services package setup

* fix: services packages updates

* fix: services changes

* fix: merge conflicts

* chore: file structuring

* fix: import fixes
2024-12-23 01:51:30 +05:30

70 lines
2.3 KiB
TypeScript

import { API_BASE_URL } from "@plane/constants";
import { APIService } from "@/api.service";
export class CycleOperationsService extends APIService {
constructor(BASE_URL?: string) {
super(BASE_URL || API_BASE_URL);
}
/**
* Adds a cycle to user favorites.
* @param {string} workspaceSlug - The workspace identifier
* @param {string} projectId - The project identifier
* @param {{cycle: string}} data - The favorite cycle data
* @returns {Promise<any>} The response data
* @throws {Error} If the request fails
*/
async addToFavorites(
workspaceSlug: string,
projectId: string,
data: {
cycle: string;
}
): Promise<any> {
return this.post(`/api/workspaces/${workspaceSlug}/projects/${projectId}/user-favorite-cycles/`, data)
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
/**
* Removes a cycle from user favorites.
* @param {string} workspaceSlug - The workspace identifier
* @param {string} projectId - The project identifier
* @param {string} cycleId - The cycle identifier
* @returns {Promise<any>} The removal response
* @throws {Error} If the request fails
*/
async removeFromFavorites(workspaceSlug: string, projectId: string, cycleId: string): Promise<any> {
return this.delete(`/api/workspaces/${workspaceSlug}/projects/${projectId}/user-favorite-cycles/${cycleId}/`)
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
/**
* Transfers issues between cycles.
* @param {string} workspaceSlug - The workspace identifier
* @param {string} projectId - The project identifier
* @param {string} cycleId - The source cycle identifier
* @param {{new_cycle_id: string}} data - The target cycle data
* @returns {Promise<any>} The transfer response
* @throws {Error} If the request fails
*/
async transferIssues(
workspaceSlug: string,
projectId: string,
cycleId: string,
data: {
new_cycle_id: string;
}
): Promise<any> {
return this.post(`/api/workspaces/${workspaceSlug}/projects/${projectId}/cycles/${cycleId}/transfer-issues/`, data)
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
}