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:
parent
afd522654c
commit
c0cee2c57f
@ -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;
|
||||
};
|
||||
|
@ -8,7 +8,7 @@ import HorizontalLine from '../../components/HorizontalLine';
|
||||
import ProjectTabs from '../../components/projects/project/ProjectTabs';
|
||||
import { useGQLClient } from '../../context/GQLClientContext';
|
||||
|
||||
const Project = () => {
|
||||
const Id = () => {
|
||||
const { id } = useParams();
|
||||
const navigate = useNavigate();
|
||||
const client = useGQLClient();
|
||||
@ -64,4 +64,4 @@ const Project = () => {
|
||||
);
|
||||
};
|
||||
|
||||
export default Project;
|
||||
export default Id;
|
@ -39,16 +39,14 @@ const Import = () => {
|
||||
|
||||
const { addProject } = await client.addProject({
|
||||
// TODO: Implement form for setting project name
|
||||
name: gitRepo.name,
|
||||
name: `${gitRepo.owner!.login}-${gitRepo.name}`,
|
||||
// TODO: Get organization id from context or URL
|
||||
organizationId: String(1),
|
||||
prodBranch: gitRepo.default_branch ?? 'main',
|
||||
repository: gitRepo.full_name,
|
||||
});
|
||||
|
||||
if (addProject) {
|
||||
navigate('/projects/create/success');
|
||||
}
|
||||
navigate(`/projects/create/success/${addProject.id}`);
|
||||
}, [client, gitRepo]);
|
||||
|
||||
return (
|
||||
|
@ -3,7 +3,7 @@ import React from 'react';
|
||||
import NewProject from './index';
|
||||
import CreateWithTemplate from './Template';
|
||||
import { templateRoutes } from './template/routes';
|
||||
import Success from './Success';
|
||||
import Id from './success/Id';
|
||||
import Import from './Import';
|
||||
|
||||
export const createProjectRoutes = [
|
||||
@ -17,8 +17,8 @@ export const createProjectRoutes = [
|
||||
children: templateRoutes,
|
||||
},
|
||||
{
|
||||
path: 'success',
|
||||
element: <Success />,
|
||||
path: 'success/:id',
|
||||
element: <Id />,
|
||||
},
|
||||
{
|
||||
path: 'import',
|
||||
|
@ -1,10 +1,10 @@
|
||||
import React from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { Link, useParams } from 'react-router-dom';
|
||||
|
||||
import { Button } from '@material-tailwind/react';
|
||||
|
||||
// TODO: Use dynamic route params for fetching project created details
|
||||
const Success = () => {
|
||||
const Id = () => {
|
||||
const { id } = useParams();
|
||||
return (
|
||||
<div className="flex justify-center">
|
||||
<div className="w-1/2">
|
||||
@ -57,7 +57,7 @@ const Success = () => {
|
||||
</Link>
|
||||
</div>
|
||||
<div>
|
||||
<Link to="/projects/1">
|
||||
<Link to={`/projects/${id}`}>
|
||||
<Button className="rounded-full" variant="gradient" color="blue">
|
||||
View project
|
||||
</Button>
|
||||
@ -69,4 +69,4 @@ const Success = () => {
|
||||
);
|
||||
};
|
||||
|
||||
export default Success;
|
||||
export default Id;
|
@ -1,7 +1,7 @@
|
||||
import React from 'react';
|
||||
|
||||
import CreateProject from './Create';
|
||||
import Project from './Project';
|
||||
import Id from './Id';
|
||||
import AddDomain from './id/domain/add';
|
||||
import { createProjectRoutes } from './create/routes';
|
||||
import { addDomainRoutes } from './id/domain/add/routes';
|
||||
@ -22,6 +22,6 @@ export const projectsRoutesWithoutSearch = [
|
||||
export const projectsRoutesWithSearch = [
|
||||
{
|
||||
path: ':id',
|
||||
element: <Project />,
|
||||
element: <Id />,
|
||||
},
|
||||
];
|
||||
|
@ -44,7 +44,9 @@ mutation ($deploymentId: String!) {
|
||||
|
||||
export const addProject = gql`
|
||||
mutation ($data: AddProjectInput) {
|
||||
addProject(data: $data)
|
||||
addProject(data: $data) {
|
||||
id
|
||||
}
|
||||
}`;
|
||||
|
||||
export const updateProjectMutation = gql`
|
||||
|
@ -220,7 +220,7 @@ export type UpdateDeploymentToProdResponse = {
|
||||
}
|
||||
|
||||
export type AddProjectResponse = {
|
||||
addProject: boolean
|
||||
addProject: Project
|
||||
}
|
||||
|
||||
export type UpdateProjectResponse = {
|
||||
|
Loading…
Reference in New Issue
Block a user