import { Client } from ".."; import TransferInvitations from "./TransferInvitations"; import { PaginatedEvents } from "../models/regional/events"; import { EligibleNewOwner, Project } from "../models/regional/projects"; import { IndexParams } from "../params/regional/events"; import { OrganizationScopedParams } from "../params/regional/organization"; import { CreateParams, UpdateParams } from "../params/regional/projects"; import { unpackData } from "../utils"; /** * Projects API Client */ export default class Projects { /** Scalingo API Client */ _client: Client; /** * Create a new "thematic" client * @param client Scalingo API Client */ constructor(client: Client) { this._client = client; } /** * Get all projects for the current user * @see https://developers.scalingo.com/projects#list-your-projects * @param opts Optional query parameters * @param opts.organization_id ID of the organization to scope the results to * @return Promise that when resolved returns a Project array. */ all(opts?: OrganizationScopedParams): Promise { return unpackData( this._client.apiClient().get("/projects", { params: opts }), "projects", ); } /** * Fetch a specific project * @see https://developers.scalingo.com/projects#get-a-precise-project * @param id ID of the project * @return Promise that when resolved returns a Project. */ find(id: string): Promise { return unpackData( this._client.apiClient().get(`/projects/${id}`), "project", ); } /** * Create a new project * @see https://developers.scalingo.com/projects#create-a-project * @param payload Project creation parameters * @return Promise that when resolved returns the created Project. */ create(payload: CreateParams): Promise { return unpackData( this._client.apiClient().post("/projects", { project: payload }), "project", ); } /** * Update a project * @see https://developers.scalingo.com/projects#update-a-project * @param id ID of the project * @param payload Project update parameters * @return Promise that when resolved returns the updated Project. */ update(id: string, payload: UpdateParams): Promise { return unpackData( this._client.apiClient().patch(`/projects/${id}`, { project: payload }), "project", ); } /** * Delete a project * @see https://developers.scalingo.com/projects#delete-a-project * @param id ID of the project * @return Promise that when resolved indicates the project has been deleted. */ delete(id: string): Promise { return this._client.apiClient().delete(`/projects/${id}`); } /** * Get eligible new owners for a project * @see https://developers.scalingo.com/projects#list-eligible-new-owners * @param id ID of the project * @return Promise that when resolved returns an array of eligible new owners. */ eligibleNewOwners(id: string): Promise { return unpackData( this._client.apiClient().get(`/projects/${id}/eligible_new_owners`), "eligible_new_owners", ); } /** * Return all events of a project * @param id ID of the project * @param opts Object that contains the index of the page and the number of elements per page */ events(id: string, opts?: IndexParams): Promise { return unpackData( this._client.apiClient().get(`/projects/${id}/events`, { params: opts }), ); } /** * Get the transfer invitations client for a project * @param projectId ID of the project * @return TransferInvitations client for the project */ transferInvitations(projectId: string): TransferInvitations { return new TransferInvitations(this._client, projectId); } }