Skip to content

Commit

Permalink
feat(workspace): add new endpoint to retrieve resources by status (#754)
Browse files Browse the repository at this point in the history
  • Loading branch information
agong-coveo authored Oct 17, 2023
1 parent c07b3aa commit a7cd070
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/resources/Projects/Project.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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<Record<ResourceStatus, Record<ProjectResourceType, string[]>>>} A series of resource IDs grouped by their status and resource type.
*/
listResourcesByStatus(projectId: string): Promise<Record<ResourceStatus, Record<ProjectResourceType, string[]>>> {
return this.api.get<Record<ResourceStatus, Record<ProjectResourceType, string[]>>>(
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<PageModel<ResourceModel>>} A paginated list of resources associated to a project.
*/
Expand Down
8 changes: 8 additions & 0 deletions src/resources/Projects/tests/Project.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/resources/Resources/ResourcesInterfaces.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit a7cd070

Please sign in to comment.