diff --git a/src/resources/Projects/Project.ts b/src/resources/Projects/Project.ts index 8cc16e411..bd0b8317b 100644 --- a/src/resources/Projects/Project.ts +++ b/src/resources/Projects/Project.ts @@ -2,7 +2,13 @@ import API from '../../APICore.js'; import {PageModel} from '../BaseInterfaces.js'; import Resource from '../Resource.js'; import {ResourceModel, ResourceParams, ResourceStatus} from '../Resources/index.js'; -import {ListProjectParams, ProjectModel, BaseProjectModel, ProjectResourceType} from './ProjectInterfaces.js'; +import { + ListProjectParams, + ProjectModel, + BaseProjectModel, + ProjectResourceType, + ListAssociatedProjectsModel, +} from './ProjectInterfaces.js'; export default class Project extends Resource { static baseUrl = `/rest/organizations/${API.orgPlaceholder}/projects`; @@ -86,4 +92,21 @@ export default class Project extends Resource { this.buildPath(`${Project.baseUrl}/${projectId}/resources/${resourceType}`, params), ); } + + /** + * Returns a list of project IDs associated to the provided resource IDs. + * + * @param {ProjectResourceType} resourceType + * @param {string[]} resourceIds + * @returns {Promise} List of project IDs associated to the provided resource IDs. + */ + listAssociatedProjects( + resourceType: ProjectResourceType, + resourceIds: string[], + ): Promise { + return this.api.post( + this.buildPath(`${Project.baseUrl}/resources/ids`, {resourceType}), + resourceIds, + ); + } } diff --git a/src/resources/Projects/ProjectInterfaces.ts b/src/resources/Projects/ProjectInterfaces.ts index 80298dd48..85209bfd5 100644 --- a/src/resources/Projects/ProjectInterfaces.ts +++ b/src/resources/Projects/ProjectInterfaces.ts @@ -127,3 +127,14 @@ export interface ListProjectParams extends Paginated { */ order?: SortingOrder; } + +export interface ListAssociatedProjectsModel { + /** + * Resource ID + */ + id: string; + /** + * Associated project IDs that are associated to the resource id + */ + projectIds: string[]; +} diff --git a/src/resources/Projects/tests/Project.spec.ts b/src/resources/Projects/tests/Project.spec.ts index 942595bbc..741e0802d 100644 --- a/src/resources/Projects/tests/Project.spec.ts +++ b/src/resources/Projects/tests/Project.spec.ts @@ -120,4 +120,15 @@ describe('Project', () => { ); }); }); + + describe('listAssociatedProjects', () => { + it('should make a POST call to the correct Project URL', () => { + const randomSourceId = 'random-id'; + project.listAssociatedProjects('SOURCE', [randomSourceId]); + expect(api.post).toHaveBeenCalledTimes(1); + expect(api.post).toHaveBeenCalledWith(`${Project.baseUrl}/resources/ids?resourceType=SOURCE`, [ + randomSourceId, + ]); + }); + }); });