forked from cerc-io/snowballtools-base
Add a mutation to remove project member by member id (#30)
* Add mutation to remove project member by member id * Add query to fetch project members by project id * Handle review changes --------- Co-authored-by: neeraj <neeraj.rtly@gmail.com>
This commit is contained in:
parent
2d7e56c0e1
commit
58e20c15db
@ -95,7 +95,7 @@ export class Database {
|
|||||||
return deployments;
|
return deployments;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getProjectMembers (projectId: string): Promise<ProjectMember[]> {
|
async getProjectMembersByProjectId (projectId: string): Promise<ProjectMember[]> {
|
||||||
const projectMemberRepository = this.dataSource.getRepository(ProjectMember);
|
const projectMemberRepository = this.dataSource.getRepository(ProjectMember);
|
||||||
|
|
||||||
const projectMembers = await projectMemberRepository.find({
|
const projectMembers = await projectMemberRepository.find({
|
||||||
@ -129,4 +129,16 @@ export class Database {
|
|||||||
|
|
||||||
return environmentVariables;
|
return environmentVariables;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async removeProjectMemberByMemberId (memberId: string): Promise<boolean> {
|
||||||
|
// TODO: Check if user is authorized to delete members
|
||||||
|
const projectMemberRepository = this.dataSource.getRepository(ProjectMember);
|
||||||
|
const deleted = await projectMemberRepository.delete(memberId);
|
||||||
|
|
||||||
|
if (deleted.affected) {
|
||||||
|
return deleted.affected > 0;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
|
import debug from 'debug';
|
||||||
|
|
||||||
import { Database } from './database';
|
import { Database } from './database';
|
||||||
import { deploymentToGqlType, projectMemberToGqlType, projectToGqlType, environmentVariableToGqlType } from './utils';
|
import { deploymentToGqlType, projectMemberToGqlType, projectToGqlType, environmentVariableToGqlType } from './utils';
|
||||||
|
|
||||||
|
const log = debug('snowball:database');
|
||||||
|
|
||||||
export const createResolvers = async (db: Database): Promise<any> => {
|
export const createResolvers = async (db: Database): Promise<any> => {
|
||||||
return {
|
return {
|
||||||
Query: {
|
Query: {
|
||||||
@ -16,7 +20,7 @@ export const createResolvers = async (db: Database): Promise<any> => {
|
|||||||
const dbProjects = await db.getProjectsByOrganizationId(org.id);
|
const dbProjects = await db.getProjectsByOrganizationId(org.id);
|
||||||
|
|
||||||
const projectsWithPromises = dbProjects.map(async (dbProject) => {
|
const projectsWithPromises = dbProjects.map(async (dbProject) => {
|
||||||
const dbProjectMembers = await db.getProjectMembers(dbProject.id);
|
const dbProjectMembers = await db.getProjectMembersByProjectId(dbProject.id);
|
||||||
const dbEnvironmentVariables = await db.getEnvironmentVariablesByProjectId(dbProject.id);
|
const dbEnvironmentVariables = await db.getEnvironmentVariablesByProjectId(dbProject.id);
|
||||||
|
|
||||||
const projectMembers = dbProjectMembers.map(dbProjectMember => {
|
const projectMembers = dbProjectMembers.map(dbProjectMember => {
|
||||||
@ -51,6 +55,27 @@ export const createResolvers = async (db: Database): Promise<any> => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return deployments;
|
return deployments;
|
||||||
|
},
|
||||||
|
|
||||||
|
projectMembers: async (_: any, { projectId }: { projectId: string }) => {
|
||||||
|
const dbProjectMembers = await db.getProjectMembersByProjectId(projectId);
|
||||||
|
|
||||||
|
const projectMembers = dbProjectMembers.map(dbProjectMember => {
|
||||||
|
return projectMemberToGqlType(dbProjectMember);
|
||||||
|
});
|
||||||
|
|
||||||
|
return projectMembers;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
Mutation: {
|
||||||
|
removeMember: async (_: any, { memberId }:{ memberId: string }) => {
|
||||||
|
try {
|
||||||
|
return await db.removeProjectMemberByMemberId(memberId);
|
||||||
|
} catch (error) {
|
||||||
|
log(error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -115,4 +115,9 @@ type Query {
|
|||||||
organizations: [Organization!]
|
organizations: [Organization!]
|
||||||
projects: [Project!]
|
projects: [Project!]
|
||||||
deployments(projectId: String!): [Deployment!]
|
deployments(projectId: String!): [Deployment!]
|
||||||
|
projectMembers(projectId: String!): [ProjectMember!]
|
||||||
|
}
|
||||||
|
|
||||||
|
type Mutation {
|
||||||
|
removeMember(memberId: String!): Boolean!
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user