From a7cd0700e0f247c8962db4995ff315f743f75f4f Mon Sep 17 00:00:00 2001 From: Alice Gong <105073504+agong-coveo@users.noreply.github.com> Date: Tue, 17 Oct 2023 12:09:30 -0400 Subject: [PATCH] feat(workspace): add new endpoint to retrieve resources by status (#754) --- src/resources/Projects/Project.ts | 18 +++++++++++++++--- src/resources/Projects/tests/Project.spec.ts | 8 ++++++++ src/resources/Resources/ResourcesInterfaces.ts | 2 ++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/resources/Projects/Project.ts b/src/resources/Projects/Project.ts index d5348ba17..8cc16e411 100644 --- a/src/resources/Projects/Project.ts +++ b/src/resources/Projects/Project.ts @@ -1,7 +1,7 @@ import API from '../../APICore.js'; import {PageModel} from '../BaseInterfaces.js'; import Resource from '../Resource.js'; -import {ResourceModel, ResourceParams} from '../Resources/index.js'; +import {ResourceModel, ResourceParams, ResourceStatus} from '../Resources/index.js'; import {ListProjectParams, ProjectModel, BaseProjectModel, ProjectResourceType} from './ProjectInterfaces.js'; export default class Project extends Resource { @@ -57,11 +57,23 @@ export default class Project extends Resource { return this.api.delete(this.buildPath(`${Project.baseUrl}/${projectId}`)); } + /** + * Returns resource IDs grouped by resource status, for a given project. + * + * @param {string} projectId + * @returns {Promise>>} A series of resource IDs grouped by their status and resource type. + */ + listResourcesByStatus(projectId: string): Promise>> { + return this.api.get>>( + this.buildPath(`${Project.baseUrl}/${projectId}/resources`), + ); + } + /** * Returns a paginated list of resources associated to a project. * - * @param projectId - * @param resourceType + * @param {string} projectId + * @param {ProjectResourceType} resourceType * @param {ResourceParams} params * @returns {Promise>} A paginated list of resources associated to a project. */ diff --git a/src/resources/Projects/tests/Project.spec.ts b/src/resources/Projects/tests/Project.spec.ts index 8cd49c5d3..942595bbc 100644 --- a/src/resources/Projects/tests/Project.spec.ts +++ b/src/resources/Projects/tests/Project.spec.ts @@ -95,6 +95,14 @@ describe('Project', () => { }); }); + describe('listResourcesByType', () => { + it('should make a GET call to the correct Project URL', () => { + project.listResourcesByStatus(mockProjectId); + expect(api.get).toHaveBeenCalledTimes(1); + expect(api.get).toHaveBeenCalledWith(`${Project.baseUrl}/${mockProjectId}/resources`); + }); + }); + describe('listResources', () => { it('should make a GET call to the correct Project URL', () => { project.listResources(mockProjectId, mockRandomResourceType); diff --git a/src/resources/Resources/ResourcesInterfaces.ts b/src/resources/Resources/ResourcesInterfaces.ts index aacf330c5..28e35fbda 100644 --- a/src/resources/Resources/ResourcesInterfaces.ts +++ b/src/resources/Resources/ResourcesInterfaces.ts @@ -1,5 +1,7 @@ import {Paginated} from '../BaseInterfaces.js'; +export type ResourceStatus = 'existingResources' | 'deletedResources'; + export interface ResourceModel { /** * The unique identifier of a resource within a project