diff --git a/packages/backend/src/resolvers.ts b/packages/backend/src/resolvers.ts index 99a93b09..4eff1e48 100644 --- a/packages/backend/src/resolvers.ts +++ b/packages/backend/src/resolvers.ts @@ -132,10 +132,9 @@ export const createResolvers = async (db: Database, app: OAuthApp, service: Serv addProject: async (_: any, { data }: { data: DeepPartial }, context: any) => { try { - return Boolean(await service.addProject(context.userId, data)); + return service.addProject(context.userId, data); } catch (err) { log(err); - return false; } }, diff --git a/packages/backend/src/schema.gql b/packages/backend/src/schema.gql index 5315c88b..2caa0af3 100644 --- a/packages/backend/src/schema.gql +++ b/packages/backend/src/schema.gql @@ -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! diff --git a/packages/backend/src/service.ts b/packages/backend/src/service.ts index dfe68d41..251c197d 100644 --- a/packages/backend/src/service.ts +++ b/packages/backend/src/service.ts @@ -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): Promise { + async addProject (userId: string, data: DeepPartial): Promise { return this.db.addProject(userId, data); } diff --git a/packages/backend/src/utils.ts b/packages/backend/src/utils.ts index 6d7f8066..f33963f9 100644 --- a/packages/backend/src/utils.ts +++ b/packages/backend/src/utils.ts @@ -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 ( @@ -24,66 +19,3 @@ export const getConfig = async ( 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; -}; diff --git a/packages/frontend/src/pages/projects/Project.tsx b/packages/frontend/src/pages/projects/Id.tsx similarity index 97% rename from packages/frontend/src/pages/projects/Project.tsx rename to packages/frontend/src/pages/projects/Id.tsx index 118b4085..035d0dc5 100644 --- a/packages/frontend/src/pages/projects/Project.tsx +++ b/packages/frontend/src/pages/projects/Id.tsx @@ -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; diff --git a/packages/frontend/src/pages/projects/create/Import.tsx b/packages/frontend/src/pages/projects/create/Import.tsx index d8f0b1c3..e7030b30 100644 --- a/packages/frontend/src/pages/projects/create/Import.tsx +++ b/packages/frontend/src/pages/projects/create/Import.tsx @@ -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 ( diff --git a/packages/frontend/src/pages/projects/create/routes.tsx b/packages/frontend/src/pages/projects/create/routes.tsx index 03fc1154..5076a028 100644 --- a/packages/frontend/src/pages/projects/create/routes.tsx +++ b/packages/frontend/src/pages/projects/create/routes.tsx @@ -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: , + path: 'success/:id', + element: , }, { path: 'import', diff --git a/packages/frontend/src/pages/projects/create/Success.tsx b/packages/frontend/src/pages/projects/create/success/Id.tsx similarity index 91% rename from packages/frontend/src/pages/projects/create/Success.tsx rename to packages/frontend/src/pages/projects/create/success/Id.tsx index e416a98a..64d633b5 100644 --- a/packages/frontend/src/pages/projects/create/Success.tsx +++ b/packages/frontend/src/pages/projects/create/success/Id.tsx @@ -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 (
@@ -57,7 +57,7 @@ const Success = () => {
- + @@ -69,4 +69,4 @@ const Success = () => { ); }; -export default Success; +export default Id; diff --git a/packages/frontend/src/pages/projects/routes.tsx b/packages/frontend/src/pages/projects/routes.tsx index a247db98..3a89f70e 100644 --- a/packages/frontend/src/pages/projects/routes.tsx +++ b/packages/frontend/src/pages/projects/routes.tsx @@ -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: , + element: , }, ]; diff --git a/packages/gql-client/src/mutations.ts b/packages/gql-client/src/mutations.ts index c853250a..5d4448c2 100644 --- a/packages/gql-client/src/mutations.ts +++ b/packages/gql-client/src/mutations.ts @@ -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` diff --git a/packages/gql-client/src/types.ts b/packages/gql-client/src/types.ts index 15ebe345..05b6ec02 100644 --- a/packages/gql-client/src/types.ts +++ b/packages/gql-client/src/types.ts @@ -220,7 +220,7 @@ export type UpdateDeploymentToProdResponse = { } export type AddProjectResponse = { - addProject: boolean + addProject: Project } export type UpdateProjectResponse = {