forked from cerc-io/snowballtools-base
Set project name for repository organization and name (#57)
* Remove unused methods from backend utils * Set project name from repo organization and name when creating project * Rename success and project components according to routes
This commit is contained in:
@@ -132,10 +132,9 @@ export const createResolvers = async (db: Database, app: OAuthApp, service: Serv
|
||||
|
||||
addProject: async (_: any, { data }: { data: DeepPartial<Project> }, context: any) => {
|
||||
try {
|
||||
return Boolean(await service.addProject(context.userId, data));
|
||||
return service.addProject(context.userId, data);
|
||||
} catch (err) {
|
||||
log(err);
|
||||
return false;
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -192,7 +192,7 @@ type Mutation {
|
||||
updateEnvironmentVariable(environmentVariableId: String!, data: UpdateEnvironmentVariableInput!): Boolean!
|
||||
removeEnvironmentVariable(environmentVariableId: String!): Boolean!
|
||||
updateDeploymentToProd(deploymentId: String!): Boolean!
|
||||
addProject(data: AddProjectInput): Boolean!
|
||||
addProject(data: AddProjectInput): Project!
|
||||
updateProject(projectId: String!, projectDetails: UpdateProjectInput): Boolean!
|
||||
redeployToProd(deploymentId: String!): Boolean!
|
||||
deleteProject(projectId: String!): Boolean!
|
||||
|
||||
@@ -11,7 +11,6 @@ import { Organization } from './entity/Organization';
|
||||
import { Project } from './entity/Project';
|
||||
import { Permission, ProjectMember } from './entity/ProjectMember';
|
||||
import { User } from './entity/User';
|
||||
import { isUserOwner } from './utils';
|
||||
|
||||
const nanoid = customAlphabet(lowercase + numbers, 8);
|
||||
|
||||
@@ -116,7 +115,7 @@ export class Service {
|
||||
const memberProject = member.project;
|
||||
assert(memberProject);
|
||||
|
||||
if (isUserOwner(String(userId), String(memberProject.owner.id))) {
|
||||
if (String(userId) === String(memberProject.owner.id)) {
|
||||
return this.db.removeProjectMemberById(projectMemberId);
|
||||
} else {
|
||||
throw new Error('Invalid operation: not authorized');
|
||||
@@ -182,7 +181,7 @@ export class Service {
|
||||
return updateResult;
|
||||
}
|
||||
|
||||
async addProject (userId: string, data: DeepPartial<Project>): Promise<Project> {
|
||||
async addProject (userId: string, data: DeepPartial<Project>): Promise<Project | undefined> {
|
||||
return this.db.addProject(userId, data);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,11 +3,6 @@ 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>(
|
||||
@@ -24,66 +19,3 @@ export const getConfig = async <ConfigType>(
|
||||
|
||||
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,
|
||||
url: dbDeployment.url,
|
||||
environment: dbDeployment.environment,
|
||||
isCurrent: dbDeployment.isCurrent,
|
||||
status: dbDeployment.status,
|
||||
createdBy: dbDeployment.createdBy,
|
||||
createdAt: dbDeployment.createdAt,
|
||||
updatedAt: dbDeployment.updatedAt
|
||||
};
|
||||
};
|
||||
|
||||
export const projectMemberToGqlType = (dbProjectMember: ProjectMember): any => {
|
||||
return {
|
||||
id: dbProjectMember.id,
|
||||
member: dbProjectMember.member,
|
||||
isPending: dbProjectMember.isPending,
|
||||
permissions: dbProjectMember.permissions,
|
||||
createdAt: dbProjectMember.createdAt,
|
||||
updatedAt: dbProjectMember.updatedAt
|
||||
};
|
||||
};
|
||||
|
||||
export const environmentVariableToGqlType = (dbEnvironmentVariable: EnvironmentVariable): any => {
|
||||
return {
|
||||
id: dbEnvironmentVariable.id,
|
||||
environments: dbEnvironmentVariable.environment,
|
||||
key: dbEnvironmentVariable.key,
|
||||
value: dbEnvironmentVariable.value,
|
||||
createdAt: dbEnvironmentVariable.createdAt,
|
||||
updatedAt: dbEnvironmentVariable.updatedAt
|
||||
};
|
||||
};
|
||||
|
||||
export const isUserOwner = (userId: string, projectOwnerId: string): boolean => {
|
||||
return userId === projectOwnerId;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user