mirror of
https://github.com/snowball-tools/snowballtools-base.git
synced 2024-12-23 05:07:44 +00:00
Add GQL mutation for updating Project entity data (#40)
* Add update and query method for project * Rename variables to update result --------- Co-authored-by: neeraj <neeraj.rtly@gmail.com>
This commit is contained in:
parent
2fb048e8ab
commit
61120ac44a
@ -78,6 +78,22 @@ export class Database {
|
|||||||
return projects;
|
return projects;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getProjectByProjectId (projectId: string): Promise<Project | null> {
|
||||||
|
const projectRepository = this.dataSource.getRepository(Project);
|
||||||
|
|
||||||
|
const project = await projectRepository.findOne({
|
||||||
|
relations: {
|
||||||
|
organization: true,
|
||||||
|
owner: true
|
||||||
|
},
|
||||||
|
where: {
|
||||||
|
id: projectId
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return project;
|
||||||
|
}
|
||||||
|
|
||||||
async getDeploymentsByProjectId (projectId: string): Promise<Deployment[]> {
|
async getDeploymentsByProjectId (projectId: string): Promise<Deployment[]> {
|
||||||
const deploymentRepository = this.dataSource.getRepository(Deployment);
|
const deploymentRepository = this.dataSource.getRepository(Deployment);
|
||||||
|
|
||||||
@ -208,10 +224,21 @@ export class Database {
|
|||||||
|
|
||||||
async updateDeploymentById (deploymentId: string, updates: DeepPartial<Deployment>): Promise<boolean> {
|
async updateDeploymentById (deploymentId: string, updates: DeepPartial<Deployment>): Promise<boolean> {
|
||||||
const deploymentRepository = this.dataSource.getRepository(Deployment);
|
const deploymentRepository = this.dataSource.getRepository(Deployment);
|
||||||
const updatedDeployment = await deploymentRepository.update({ id: Number(deploymentId) }, updates);
|
const updateResult = await deploymentRepository.update({ id: Number(deploymentId) }, updates);
|
||||||
|
|
||||||
if (updatedDeployment.affected) {
|
if (updateResult.affected) {
|
||||||
return updatedDeployment.affected > 0;
|
return updateResult.affected > 0;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async updateProjectById (projectId: string, updates: DeepPartial<Project>): Promise<boolean> {
|
||||||
|
const projectRepository = this.dataSource.getRepository(Project);
|
||||||
|
const updateResult = await projectRepository.update({ id: projectId }, updates);
|
||||||
|
|
||||||
|
if (updateResult.affected) {
|
||||||
|
return updateResult.affected > 0;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -49,6 +49,12 @@ export const createResolvers = async (db: Database): Promise<any> => {
|
|||||||
return orgsWithProjects;
|
return orgsWithProjects;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
project: async (_: any, { projectId }: { projectId: string }) => {
|
||||||
|
const dbProject = await db.getProjectByProjectId(projectId);
|
||||||
|
|
||||||
|
return dbProject ? projectToGqlType(dbProject, [], []) : null;
|
||||||
|
},
|
||||||
|
|
||||||
deployments: async (_: any, { projectId }: { projectId: string }) => {
|
deployments: async (_: any, { projectId }: { projectId: string }) => {
|
||||||
const dbDeployments = await db.getDeploymentsByProjectId(projectId);
|
const dbDeployments = await db.getDeploymentsByProjectId(projectId);
|
||||||
|
|
||||||
@ -131,6 +137,15 @@ export const createResolvers = async (db: Database): Promise<any> => {
|
|||||||
log(err);
|
log(err);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
updateProject: async (_: any, { projectId, updateProject }: { projectId: string, updateProject: { name: string, description: string } }) => {
|
||||||
|
try {
|
||||||
|
return db.updateProjectById(projectId, updateProject);
|
||||||
|
} catch (err) {
|
||||||
|
log(err);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -115,6 +115,7 @@ type Query {
|
|||||||
user: User!
|
user: User!
|
||||||
organizations: [Organization!]
|
organizations: [Organization!]
|
||||||
projects: [Project!]
|
projects: [Project!]
|
||||||
|
project(projectId: String!): Project
|
||||||
deployments(projectId: String!): [Deployment!]
|
deployments(projectId: String!): [Deployment!]
|
||||||
environmentVariables(projectId: String!): [EnvironmentVariable!]
|
environmentVariables(projectId: String!): [EnvironmentVariable!]
|
||||||
projectMembers(projectId: String!): [ProjectMember!]
|
projectMembers(projectId: String!): [ProjectMember!]
|
||||||
@ -125,6 +126,7 @@ type Mutation {
|
|||||||
removeMember(memberId: String!): Boolean!
|
removeMember(memberId: String!): Boolean!
|
||||||
addEnvironmentVariables(projectId: String!, environmentVariables: [AddEnvironmentVariableInput!]): Boolean!
|
addEnvironmentVariables(projectId: String!, environmentVariables: [AddEnvironmentVariableInput!]): Boolean!
|
||||||
updateDeploymentToProd(deploymentId: String!): Boolean!
|
updateDeploymentToProd(deploymentId: String!): Boolean!
|
||||||
|
updateProject(projectId: String!, updateProject: UpdateProjectInput): Boolean!
|
||||||
}
|
}
|
||||||
|
|
||||||
input AddEnvironmentVariableInput {
|
input AddEnvironmentVariableInput {
|
||||||
@ -132,3 +134,8 @@ input AddEnvironmentVariableInput {
|
|||||||
key: String!
|
key: String!
|
||||||
value: String!
|
value: String!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
input UpdateProjectInput {
|
||||||
|
name: String
|
||||||
|
description: String
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user