Skip to content

Commit

Permalink
feat(project): add new endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
agong-coveo committed May 24, 2024
1 parent cc2f4d5 commit 1582bc3
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/resources/Projects/Project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
Expand Down Expand Up @@ -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<PageModel<ListAssociatedProjectsModel>>} List of project IDs associated to the provided resource IDs.
*/
listAssociatedProjects(
resourceType: ProjectResourceType,
resourceIds: string[],
): Promise<ListAssociatedProjectsModel> {
return this.api.post<ListAssociatedProjectsModel>(
this.buildPath(`${Project.baseUrl}/resources/ids`, {resourceType}),
resourceIds,
);
}
}
11 changes: 11 additions & 0 deletions src/resources/Projects/ProjectInterfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
}
11 changes: 11 additions & 0 deletions src/resources/Projects/tests/Project.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]);
});
});
});

0 comments on commit 1582bc3

Please sign in to comment.