forked from cerc-io/snowballtools-base
Nabarun Gogoi
c2b997a17b
* Find projects based on search text * Use get search projects client method in UI * Fetch searched projects inside useCombobox hook * Get searched project from project entity * Remove non required search projects filtering * Fetch projects if user is owner or project member --------- Co-authored-by: neeraj <neeraj.rtly@gmail.com>
87 lines
2.7 KiB
TypeScript
87 lines
2.7 KiB
TypeScript
import fs from 'fs-extra';
|
|
import path from 'path';
|
|
import toml from 'toml';
|
|
import debug from 'debug';
|
|
|
|
import { Project } from './entity/Project';
|
|
import { ProjectMember } from './entity/ProjectMember';
|
|
import { Deployment } from './entity/Deployment';
|
|
import { EnvironmentVariable } from './entity/EnvironmentVariable';
|
|
|
|
const log = debug('snowball:utils');
|
|
|
|
export const getConfig = async <ConfigType>(
|
|
configFile: string
|
|
): Promise<ConfigType> => {
|
|
const configFilePath = path.resolve(configFile);
|
|
const fileExists = await fs.pathExists(configFilePath);
|
|
if (!fileExists) {
|
|
throw new Error(`Config file not found: ${configFilePath}`);
|
|
}
|
|
|
|
const config = toml.parse(await fs.readFile(configFilePath, 'utf8'));
|
|
log('config', JSON.stringify(config, null, 2));
|
|
|
|
return config;
|
|
};
|
|
|
|
export const projectToGqlType = (dbProject: Project, projectMembers: ProjectMember[], environmentVariables: EnvironmentVariable[]): any => {
|
|
return {
|
|
id: dbProject.id,
|
|
owner: dbProject.owner,
|
|
name: dbProject.name,
|
|
repository: dbProject.repository,
|
|
prodBranch: dbProject.prodBranch,
|
|
description: dbProject.description,
|
|
template: dbProject.template,
|
|
framework: dbProject.framework,
|
|
webhooks: dbProject.webhooks,
|
|
members: projectMembers,
|
|
environmentVariables: environmentVariables,
|
|
createdAt: dbProject.createdAt,
|
|
updatedAt: dbProject.updatedAt,
|
|
organization: dbProject.organization
|
|
};
|
|
};
|
|
|
|
// TODO: Add domain field to deployment
|
|
export const deploymentToGqlType = (dbDeployment: Deployment): any => {
|
|
return {
|
|
id: dbDeployment.id,
|
|
domain: dbDeployment.domain,
|
|
branch: dbDeployment.branch,
|
|
commitHash: dbDeployment.commitHash,
|
|
title: dbDeployment.title,
|
|
environment: dbDeployment.environment,
|
|
isCurrent: dbDeployment.isCurrent,
|
|
status: dbDeployment.status,
|
|
createdAt: dbDeployment.createdAt,
|
|
updatedAt: dbDeployment.updatedAt
|
|
};
|
|
};
|
|
|
|
export const projectMemberToGqlType = (dbProjectMember: ProjectMember): any => {
|
|
return {
|
|
id: dbProjectMember.id,
|
|
member: dbProjectMember.member,
|
|
permissions: dbProjectMember.permissions,
|
|
createdAt: dbProjectMember.createdAt,
|
|
updatedAt: dbProjectMember.updatedAt
|
|
};
|
|
};
|
|
|
|
export const environmentVariableToGqlType = (dbEnvironmentVariable: EnvironmentVariable): any => {
|
|
return {
|
|
id: dbEnvironmentVariable.id,
|
|
environments: dbEnvironmentVariable.environments,
|
|
key: dbEnvironmentVariable.key,
|
|
value: dbEnvironmentVariable.value,
|
|
createdAt: dbEnvironmentVariable.createdAt,
|
|
updatedAt: dbEnvironmentVariable.updatedAt
|
|
};
|
|
};
|
|
|
|
export const isUserOwner = (userId: string, projectOwnerId: string): boolean => {
|
|
return userId === projectOwnerId;
|
|
};
|