mirror of
https://github.com/Unleash/unleash.git
synced 2025-04-19 01:17:18 +02:00
feat: get projects by ids (#8269)
This commit is contained in:
parent
33f44072dc
commit
ceb21fbe51
@ -1,5 +1,5 @@
|
|||||||
import type { ProjectMode } from '../../types';
|
import type { ProjectMode } from '../../types';
|
||||||
import type { IProjectQuery } from './project-store-type';
|
import type { IProjectQuery, IProjectsQuery } from './project-store-type';
|
||||||
|
|
||||||
export type ProjectForUi = {
|
export type ProjectForUi = {
|
||||||
id: string;
|
id: string;
|
||||||
@ -28,7 +28,7 @@ export type ProjectForInsights = {
|
|||||||
|
|
||||||
export interface IProjectReadModel {
|
export interface IProjectReadModel {
|
||||||
getProjectsForAdminUi(
|
getProjectsForAdminUi(
|
||||||
query?: IProjectQuery,
|
query?: IProjectQuery & IProjectsQuery,
|
||||||
userId?: number,
|
userId?: number,
|
||||||
): Promise<ProjectForUi[]>;
|
): Promise<ProjectForUi[]>;
|
||||||
getProjectsForInsights(
|
getProjectsForInsights(
|
||||||
|
@ -6,7 +6,7 @@ import type {
|
|||||||
ProjectForInsights,
|
ProjectForInsights,
|
||||||
ProjectForUi,
|
ProjectForUi,
|
||||||
} from './project-read-model-type';
|
} 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 metricsHelper from '../../util/metrics-helper';
|
||||||
import type EventEmitter from 'events';
|
import type EventEmitter from 'events';
|
||||||
import type { IProjectMembersCount } from './project-store';
|
import type { IProjectMembersCount } from './project-store';
|
||||||
@ -79,7 +79,7 @@ export class ProjectReadModel implements IProjectReadModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getProjectsForAdminUi(
|
async getProjectsForAdminUi(
|
||||||
query?: IProjectQuery,
|
query?: IProjectQuery & IProjectsQuery,
|
||||||
userId?: number,
|
userId?: number,
|
||||||
): Promise<ProjectForUi[]> {
|
): Promise<ProjectForUi[]> {
|
||||||
const projectTimer = this.timer('getProjectsForAdminUi');
|
const projectTimer = this.timer('getProjectsForAdminUi');
|
||||||
@ -113,6 +113,9 @@ export class ProjectReadModel implements IProjectReadModel {
|
|||||||
if (query?.id) {
|
if (query?.id) {
|
||||||
projects = projects.where(`${TABLE}.id`, query.id);
|
projects = projects.where(`${TABLE}.id`, query.id);
|
||||||
}
|
}
|
||||||
|
if (query?.ids) {
|
||||||
|
projects = projects.whereIn(`${TABLE}.id`, query.ids);
|
||||||
|
}
|
||||||
|
|
||||||
let selectColumns = [
|
let selectColumns = [
|
||||||
this.db.raw(
|
this.db.raw(
|
||||||
|
@ -152,6 +152,11 @@ test('should create new project', async () => {
|
|||||||
expect(project.name).toEqual(ret.name);
|
expect(project.name).toEqual(ret.name);
|
||||||
expect(project.description).toEqual(ret.description);
|
expect(project.description).toEqual(ret.description);
|
||||||
expect(ret.createdAt).toBeTruthy();
|
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 () => {
|
test('should create new private project', async () => {
|
||||||
|
@ -83,6 +83,7 @@ import type {
|
|||||||
IProjectApplicationsSearchParams,
|
IProjectApplicationsSearchParams,
|
||||||
IProjectEnterpriseSettingsUpdate,
|
IProjectEnterpriseSettingsUpdate,
|
||||||
IProjectQuery,
|
IProjectQuery,
|
||||||
|
IProjectsQuery,
|
||||||
} from './project-store-type';
|
} from './project-store-type';
|
||||||
import type { IProjectFlagCreatorsReadModel } from './project-flag-creators-read-model.type';
|
import type { IProjectFlagCreatorsReadModel } from './project-flag-creators-read-model.type';
|
||||||
import { throwExceedsLimitError } from '../../error/exceeds-limit-error';
|
import { throwExceedsLimitError } from '../../error/exceeds-limit-error';
|
||||||
@ -230,13 +231,13 @@ export default class ProjectService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getProjects(
|
async getProjects(
|
||||||
query?: IProjectQuery,
|
query?: IProjectQuery & IProjectsQuery,
|
||||||
userId?: number,
|
userId?: number,
|
||||||
): Promise<ProjectForUi[]> {
|
): Promise<ProjectForUi[]> {
|
||||||
const getProjects = () =>
|
const projects = await this.projectReadModel.getProjectsForAdminUi(
|
||||||
this.projectReadModel.getProjectsForAdminUi(query, userId);
|
query,
|
||||||
|
userId,
|
||||||
const projects = await getProjects();
|
);
|
||||||
|
|
||||||
if (userId) {
|
if (userId) {
|
||||||
const projectAccess =
|
const projectAccess =
|
||||||
|
@ -48,6 +48,10 @@ export interface IProjectQuery {
|
|||||||
archived?: boolean;
|
archived?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface IProjectsQuery {
|
||||||
|
ids?: string[];
|
||||||
|
}
|
||||||
|
|
||||||
export type ProjectEnvironment = {
|
export type ProjectEnvironment = {
|
||||||
environment: string;
|
environment: string;
|
||||||
changeRequestEnabled?: boolean;
|
changeRequestEnabled?: boolean;
|
||||||
|
Loading…
Reference in New Issue
Block a user