2021-08-12 15:04:37 +02:00
|
|
|
import {
|
|
|
|
IProjectHealthUpdate,
|
|
|
|
IProjectInsert,
|
|
|
|
IProjectStore,
|
|
|
|
} from '../../lib/types/stores/project-store';
|
2022-10-19 14:05:07 +02:00
|
|
|
import {
|
|
|
|
IEnvironment,
|
|
|
|
IProject,
|
|
|
|
IProjectWithCount,
|
|
|
|
} from '../../lib/types/model';
|
2021-08-12 15:04:37 +02:00
|
|
|
import NotFoundError from '../../lib/error/notfound-error';
|
2022-08-17 11:05:41 +02:00
|
|
|
import {
|
|
|
|
IEnvironmentProjectLink,
|
|
|
|
IProjectMembersCount,
|
|
|
|
} from 'lib/db/project-store';
|
2021-08-12 15:04:37 +02:00
|
|
|
|
|
|
|
export default class FakeProjectStore implements IProjectStore {
|
2022-03-11 14:52:13 +01:00
|
|
|
projects: IProject[] = [];
|
|
|
|
|
|
|
|
projectEnvironment: Map<string, Set<string>> = new Map();
|
|
|
|
|
2021-08-12 15:04:37 +02:00
|
|
|
getEnvironmentsForProject(): Promise<string[]> {
|
|
|
|
throw new Error('Method not implemented.');
|
|
|
|
}
|
|
|
|
|
2022-03-11 14:52:13 +01:00
|
|
|
getProjectLinksForEnvironments(
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
|
environments: string[],
|
|
|
|
): Promise<IEnvironmentProjectLink[]> {
|
|
|
|
throw new Error('Method not implemented.');
|
|
|
|
}
|
2021-08-12 15:04:37 +02:00
|
|
|
|
|
|
|
async addEnvironmentToProject(
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
|
id: string,
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
|
environment: string,
|
|
|
|
): Promise<void> {
|
|
|
|
const environments = this.projectEnvironment.get(id) || new Set();
|
|
|
|
environments.add(environment);
|
|
|
|
this.projectEnvironment.set(id, environments);
|
|
|
|
}
|
|
|
|
|
2022-02-21 12:46:28 +01:00
|
|
|
async getProjectsWithCounts(): Promise<IProjectWithCount[]> {
|
|
|
|
return this.projects.map((p) => {
|
|
|
|
return { ...p, memberCount: 0, featureCount: 0 };
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-08-12 15:04:37 +02:00
|
|
|
private createInternal(project: IProjectInsert): IProject {
|
|
|
|
const newProj: IProject = {
|
|
|
|
...project,
|
|
|
|
health: 100,
|
|
|
|
createdAt: new Date(),
|
|
|
|
};
|
|
|
|
this.projects.push(newProj);
|
|
|
|
return newProj;
|
|
|
|
}
|
|
|
|
|
|
|
|
async create(project: IProjectInsert): Promise<IProject> {
|
|
|
|
return this.createInternal(project);
|
|
|
|
}
|
|
|
|
|
|
|
|
async delete(key: string): Promise<void> {
|
|
|
|
this.projects.splice(
|
|
|
|
this.projects.findIndex((p) => p.id === key),
|
|
|
|
1,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
async deleteAll(): Promise<void> {
|
|
|
|
this.projects = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
async deleteEnvironmentForProject(
|
|
|
|
id: string,
|
|
|
|
environment: string,
|
|
|
|
): Promise<void> {
|
|
|
|
const environments = this.projectEnvironment.get(id);
|
|
|
|
if (environments) {
|
|
|
|
environments.delete(environment);
|
|
|
|
this.projectEnvironment.set(id, environments);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
destroy(): void {}
|
|
|
|
|
2021-08-27 10:10:14 +02:00
|
|
|
async count(): Promise<number> {
|
|
|
|
return this.projects.length;
|
|
|
|
}
|
|
|
|
|
2021-08-12 15:04:37 +02:00
|
|
|
async exists(key: string): Promise<boolean> {
|
|
|
|
return this.projects.some((p) => p.id === key);
|
|
|
|
}
|
|
|
|
|
|
|
|
async get(key: string): Promise<IProject> {
|
|
|
|
const project = this.projects.find((p) => p.id === key);
|
|
|
|
if (project) {
|
|
|
|
return project;
|
|
|
|
}
|
|
|
|
throw new NotFoundError(`Could not find project with id: ${key}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
async getAll(): Promise<IProject[]> {
|
|
|
|
return this.projects;
|
|
|
|
}
|
|
|
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
2022-08-17 11:05:41 +02:00
|
|
|
async getMembersCountByProject(projectId: string): Promise<number> {
|
2021-08-12 15:04:37 +02:00
|
|
|
return Promise.resolve(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
async hasProject(id: string): Promise<boolean> {
|
|
|
|
return this.exists(id);
|
|
|
|
}
|
|
|
|
|
2022-10-19 14:05:07 +02:00
|
|
|
async importProjects(
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
|
projects: IProjectInsert[],
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
|
environments?: IEnvironment[],
|
|
|
|
): Promise<IProject[]> {
|
2021-08-12 15:04:37 +02:00
|
|
|
return projects.map((p) => this.createInternal(p));
|
|
|
|
}
|
|
|
|
|
|
|
|
async update(update: IProjectInsert): Promise<void> {
|
|
|
|
await this.delete(update.id);
|
|
|
|
this.createInternal(update);
|
|
|
|
}
|
|
|
|
|
|
|
|
async updateHealth(healthUpdate: IProjectHealthUpdate): Promise<void> {
|
|
|
|
this.projects.find((p) => p.id === healthUpdate.id).health =
|
|
|
|
healthUpdate.health;
|
|
|
|
}
|
2022-08-17 11:05:41 +02:00
|
|
|
|
|
|
|
getMembersCount(): Promise<IProjectMembersCount[]> {
|
|
|
|
throw new Error('Method not implemented.');
|
|
|
|
}
|
2022-09-29 15:27:54 +02:00
|
|
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
|
getProjectsByUser(userId: number): Promise<string[]> {
|
|
|
|
throw new Error('Method not implemented.');
|
|
|
|
}
|
2022-10-28 11:27:11 +02:00
|
|
|
|
|
|
|
addEnvironmentToProjects(
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
|
environment: string,
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
|
projects: string[],
|
|
|
|
): Promise<void> {
|
|
|
|
throw new Error('Method not implemented.');
|
|
|
|
}
|
2021-08-12 15:04:37 +02:00
|
|
|
}
|