Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: get projects by ids #8269

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/lib/features/project/project-read-model-type.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ProjectMode } from '../../types';
import type { IProjectQuery } from './project-store-type';
import type { IProjectQuery, IProjectsQuery } from './project-store-type';

export type ProjectForUi = {
id: string;
Expand Down Expand Up @@ -28,7 +28,7 @@ export type ProjectForInsights = {

export interface IProjectReadModel {
getProjectsForAdminUi(
query?: IProjectQuery,
query?: IProjectQuery & IProjectsQuery,
userId?: number,
): Promise<ProjectForUi[]>;
getProjectsForInsights(
Expand Down
7 changes: 5 additions & 2 deletions src/lib/features/project/project-read-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
ProjectForInsights,
ProjectForUi,
} from './project-read-model-type';
import type { IProjectQuery } from './project-store-type';
import type { IProjectQuery, IProjectsQuery } from './project-store-type';
import metricsHelper from '../../util/metrics-helper';
import type EventEmitter from 'events';
import type { IProjectMembersCount } from './project-store';
Expand Down Expand Up @@ -79,7 +79,7 @@ export class ProjectReadModel implements IProjectReadModel {
}

async getProjectsForAdminUi(
query?: IProjectQuery,
query?: IProjectQuery & IProjectsQuery,
userId?: number,
): Promise<ProjectForUi[]> {
const projectTimer = this.timer('getProjectsForAdminUi');
Expand Down Expand Up @@ -113,6 +113,9 @@ export class ProjectReadModel implements IProjectReadModel {
if (query?.id) {
projects = projects.where(`${TABLE}.id`, query.id);
}
if (query?.ids) {
projects = projects.whereIn(`${TABLE}.id`, query.ids);
}

let selectColumns = [
this.db.raw(
Expand Down
5 changes: 5 additions & 0 deletions src/lib/features/project/project-service.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ test('should create new project', async () => {
expect(project.name).toEqual(ret.name);
expect(project.description).toEqual(ret.description);
expect(ret.createdAt).toBeTruthy();

const projectsById = await projectService.getProjects({ id: 'test' });
const projectsByIds = await projectService.getProjects({ ids: ['test'] });
expect(projectsById).toMatchObject([{ id: 'test' }]);
expect(projectsByIds).toMatchObject([{ id: 'test' }]);
});

test('should create new private project', async () => {
Expand Down
11 changes: 6 additions & 5 deletions src/lib/features/project/project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ import type {
IProjectApplicationsSearchParams,
IProjectEnterpriseSettingsUpdate,
IProjectQuery,
IProjectsQuery,
} from './project-store-type';
import type { IProjectFlagCreatorsReadModel } from './project-flag-creators-read-model.type';
import { throwExceedsLimitError } from '../../error/exceeds-limit-error';
Expand Down Expand Up @@ -230,13 +231,13 @@ export default class ProjectService {
}

async getProjects(
query?: IProjectQuery,
query?: IProjectQuery & IProjectsQuery,
userId?: number,
): Promise<ProjectForUi[]> {
const getProjects = () =>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gitar leftover

this.projectReadModel.getProjectsForAdminUi(query, userId);

const projects = await getProjects();
const projects = await this.projectReadModel.getProjectsForAdminUi(
query,
userId,
);

if (userId) {
const projectAccess =
Expand Down
4 changes: 4 additions & 0 deletions src/lib/features/project/project-store-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ export interface IProjectQuery {
archived?: boolean;
}

export interface IProjectsQuery {
ids?: string[];
}

export type ProjectEnvironment = {
environment: string;
changeRequestEnabled?: boolean;
Expand Down
Loading