forked from cerc-io/snowballtools-base
Add GQL mutation to delete project (#43)
* Implement delete project functionality * Use delete project client method in UI * Refetch projects information on deleting project * Use project's current deployment domain name for url * Handle review changes --------- Co-authored-by: neeraj <neeraj.rtly@gmail.com>
This commit is contained in:
committed by
Ashwin Phatak
co-authored by
neeraj
parent
cfb4b4637c
commit
1ae1564878
@@ -78,22 +78,39 @@ export class Database {
|
||||
return projects;
|
||||
}
|
||||
|
||||
async getProjectByProjectId (projectId: string): Promise<Project | null> {
|
||||
async getProjectById (projectId: string): Promise<Project | null> {
|
||||
const projectRepository = this.dataSource.getRepository(Project);
|
||||
|
||||
const project = await projectRepository.findOne({
|
||||
relations: {
|
||||
organization: true,
|
||||
owner: true
|
||||
},
|
||||
where: {
|
||||
id: projectId
|
||||
}
|
||||
});
|
||||
const project = await projectRepository
|
||||
.createQueryBuilder('project')
|
||||
.leftJoinAndSelect('project.deployments', 'deployments', 'deployments.isCurrent = true')
|
||||
.leftJoinAndSelect('deployments.domain', 'domain')
|
||||
.leftJoinAndSelect('project.owner', 'owner')
|
||||
.where('project.id = :projectId', {
|
||||
projectId
|
||||
})
|
||||
.getOne();
|
||||
|
||||
return project;
|
||||
}
|
||||
|
||||
async getProjectsInOrganization (userId: string, organizationId: string): Promise<Project[]> {
|
||||
const projectRepository = this.dataSource.getRepository(Project);
|
||||
|
||||
const projects = await projectRepository
|
||||
.createQueryBuilder('project')
|
||||
.leftJoinAndSelect('project.deployments', 'deployments', 'deployments.isCurrent = true')
|
||||
.leftJoinAndSelect('deployments.domain', 'domain')
|
||||
.leftJoin('project.projectMembers', 'projectMembers')
|
||||
.where('(project.ownerId = :userId OR projectMembers.userId = :userId) AND project.organizationId = :organizationId', {
|
||||
userId,
|
||||
organizationId
|
||||
})
|
||||
.getMany();
|
||||
|
||||
return projects;
|
||||
}
|
||||
|
||||
async getDeploymentsByProjectId (projectId: string): Promise<Deployment[]> {
|
||||
const deploymentRepository = this.dataSource.getRepository(Deployment);
|
||||
|
||||
@@ -275,4 +292,15 @@ export class Database {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async deleteProjectById (projectId: string): Promise<boolean> {
|
||||
const projectRepository = this.dataSource.getRepository(Project);
|
||||
const deleteResult = await projectRepository.softDelete({ id: projectId });
|
||||
|
||||
if (deleteResult.affected) {
|
||||
return deleteResult.affected > 0;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,12 +6,14 @@ import {
|
||||
UpdateDateColumn,
|
||||
ManyToOne,
|
||||
JoinColumn,
|
||||
OneToMany
|
||||
OneToMany,
|
||||
DeleteDateColumn
|
||||
} from 'typeorm';
|
||||
|
||||
import { User } from './User';
|
||||
import { Organization } from './Organization';
|
||||
import { ProjectMember } from './ProjectMember';
|
||||
import { Deployment } from './Deployment';
|
||||
|
||||
@Entity()
|
||||
export class Project {
|
||||
@@ -49,12 +51,21 @@ export class Project {
|
||||
})
|
||||
webhooks!: string[];
|
||||
|
||||
@Column('varchar')
|
||||
icon!: string;
|
||||
|
||||
@CreateDateColumn()
|
||||
createdAt!: Date;
|
||||
|
||||
@UpdateDateColumn()
|
||||
updatedAt!: Date;
|
||||
|
||||
@DeleteDateColumn()
|
||||
deletedAt?: Date;
|
||||
|
||||
@OneToMany(() => ProjectMember, projectMember => projectMember.project)
|
||||
projectMembers!: ProjectMember[];
|
||||
|
||||
@OneToMany(() => Deployment, (deployment) => deployment.project)
|
||||
deployments!: Deployment[];
|
||||
}
|
||||
|
||||
@@ -50,9 +50,14 @@ export const createResolvers = async (db: Database): Promise<any> => {
|
||||
},
|
||||
|
||||
project: async (_: any, { projectId }: { projectId: string }) => {
|
||||
const dbProject = await db.getProjectByProjectId(projectId);
|
||||
const dbProject = await db.getProjectById(projectId);
|
||||
|
||||
return dbProject ? projectToGqlType(dbProject, [], []) : null;
|
||||
return dbProject || null;
|
||||
},
|
||||
|
||||
projectsInOrganization: async (_: any, { organizationId }: {organizationId: string }, context: any) => {
|
||||
const dbProject = await db.getProjectsInOrganization(context.userId, organizationId);
|
||||
return dbProject;
|
||||
},
|
||||
|
||||
deployments: async (_: any, { projectId }: { projectId: string }) => {
|
||||
@@ -155,6 +160,15 @@ export const createResolvers = async (db: Database): Promise<any> => {
|
||||
log(err);
|
||||
return false;
|
||||
}
|
||||
},
|
||||
|
||||
deleteProject: async (_: any, { projectId }: { projectId: string }) => {
|
||||
try {
|
||||
return db.deleteProjectById(projectId);
|
||||
} catch (err) {
|
||||
log(err);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -69,6 +69,7 @@ type Project {
|
||||
createdAt: String!
|
||||
updatedAt: String!
|
||||
organization: Organization!
|
||||
icon: String
|
||||
}
|
||||
|
||||
type ProjectMember {
|
||||
@@ -115,6 +116,7 @@ type Query {
|
||||
user: User!
|
||||
organizations: [Organization!]
|
||||
projects: [Project!]
|
||||
projectsInOrganization(organizationId: String!): [Project!]
|
||||
project(projectId: String!): Project
|
||||
deployments(projectId: String!): [Deployment!]
|
||||
environmentVariables(projectId: String!): [EnvironmentVariable!]
|
||||
@@ -128,6 +130,7 @@ type Mutation {
|
||||
updateDeploymentToProd(deploymentId: String!): Boolean!
|
||||
updateProject(projectId: String!, updateProject: UpdateProjectInput): Boolean!
|
||||
redeployToProd(deploymentId: String!): Boolean!
|
||||
deleteProject(projectId: String!): Boolean!
|
||||
}
|
||||
|
||||
input AddEnvironmentVariableInput {
|
||||
|
||||
+20
-15
@@ -1,57 +1,62 @@
|
||||
[
|
||||
{
|
||||
"ownerIndex":0,
|
||||
"organizationIndex":0,
|
||||
"ownerIndex": 0,
|
||||
"organizationIndex": 0,
|
||||
"name": "testProject",
|
||||
"repository": "test",
|
||||
"prodBranch": "main",
|
||||
"description": "test",
|
||||
"template": "test",
|
||||
"framework": "test",
|
||||
"webhooks": []
|
||||
"webhooks": [],
|
||||
"icon": ""
|
||||
},
|
||||
{
|
||||
"ownerIndex":1,
|
||||
"organizationIndex":0,
|
||||
"ownerIndex": 1,
|
||||
"organizationIndex": 0,
|
||||
"name": "testProject-2",
|
||||
"repository": "test-2",
|
||||
"prodBranch": "main",
|
||||
"description": "test-2",
|
||||
"template": "test-2",
|
||||
"framework": "test-2",
|
||||
"webhooks": []
|
||||
"webhooks": [],
|
||||
"icon": ""
|
||||
},
|
||||
{
|
||||
"ownerIndex":2,
|
||||
"organizationIndex":0,
|
||||
"ownerIndex": 2,
|
||||
"organizationIndex": 0,
|
||||
"name": "iglootools",
|
||||
"repository": "test-3",
|
||||
"prodBranch": "main",
|
||||
"description": "test-3",
|
||||
"template": "test-3",
|
||||
"framework": "test-3",
|
||||
"webhooks": []
|
||||
"webhooks": [],
|
||||
"icon": ""
|
||||
},
|
||||
{
|
||||
"ownerIndex":1,
|
||||
"organizationIndex":0,
|
||||
"ownerIndex": 1,
|
||||
"organizationIndex": 0,
|
||||
"name": "iglootools-2",
|
||||
"repository": "test-4",
|
||||
"prodBranch": "main",
|
||||
"description": "test-4",
|
||||
"template": "test-4",
|
||||
"framework": "test-4",
|
||||
"webhooks": []
|
||||
"webhooks": [],
|
||||
"icon": ""
|
||||
},
|
||||
{
|
||||
"ownerIndex":0,
|
||||
"organizationIndex":1,
|
||||
"ownerIndex": 0,
|
||||
"organizationIndex": 1,
|
||||
"name": "snowball-2",
|
||||
"repository": "test-5",
|
||||
"prodBranch": "main",
|
||||
"description": "test-5",
|
||||
"template": "test-5",
|
||||
"framework": "test-5",
|
||||
"webhooks": []
|
||||
"webhooks": [],
|
||||
"icon": ""
|
||||
}
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user