forked from cerc-io/snowballtools-base
Implement functionality to transfer project to different organization (#50)
* Add GQL mutation for transfer project * Integrate transfer project GQL client method * Use update project GQL method for transfer project --------- Co-authored-by: neeraj <neeraj.rtly@gmail.com>
This commit is contained in:
@@ -6,7 +6,6 @@ import assert from 'assert';
|
||||
import { DatabaseConfig } from './config';
|
||||
import { User } from './entity/User';
|
||||
import { Organization } from './entity/Organization';
|
||||
import { UserOrganization } from './entity/UserOrganization';
|
||||
import { Project } from './entity/Project';
|
||||
import { Deployment, Environment } from './entity/Deployment';
|
||||
import { Permission, ProjectMember } from './entity/ProjectMember';
|
||||
@@ -52,22 +51,19 @@ export class Database {
|
||||
}
|
||||
|
||||
async getOrganizationsByUserId (userId: number): Promise<Organization[]> {
|
||||
const userOrganizationRepository = this.dataSource.getRepository(UserOrganization);
|
||||
const organizationRepository = this.dataSource.getRepository(Organization);
|
||||
|
||||
const userOrgs = await userOrganizationRepository.find({
|
||||
relations: {
|
||||
member: true,
|
||||
organization: true
|
||||
},
|
||||
const userOrgs = await organizationRepository.find({
|
||||
where: {
|
||||
member: {
|
||||
id: userId
|
||||
userOrganizations: {
|
||||
member: {
|
||||
id: userId
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const organizations = userOrgs.map(userOrg => userOrg.organization);
|
||||
return organizations;
|
||||
return userOrgs;
|
||||
}
|
||||
|
||||
async getProjectsByOrganizationId (organizationId: number): Promise<Project[]> {
|
||||
@@ -96,6 +92,7 @@ export class Database {
|
||||
.leftJoinAndSelect('project.deployments', 'deployments', 'deployments.isCurrent = true')
|
||||
.leftJoinAndSelect('deployments.domain', 'domain')
|
||||
.leftJoinAndSelect('project.owner', 'owner')
|
||||
.leftJoinAndSelect('project.organization', 'organization')
|
||||
.where('project.id = :projectId', {
|
||||
projectId
|
||||
})
|
||||
|
||||
@@ -5,7 +5,7 @@ import { DeepPartial } from 'typeorm';
|
||||
import { OAuthApp } from '@octokit/oauth-app';
|
||||
|
||||
import { Database } from './database';
|
||||
import { deploymentToGqlType, projectMemberToGqlType, projectToGqlType, environmentVariableToGqlType, isUserOwner } from './utils';
|
||||
import { deploymentToGqlType, projectMemberToGqlType, projectToGqlType, isUserOwner } from './utils';
|
||||
import { Environment } from './entity/Deployment';
|
||||
import { Permission } from './entity/ProjectMember';
|
||||
import { Domain } from './entity/Domain';
|
||||
@@ -22,37 +22,7 @@ export const createResolvers = async (db: Database, app: OAuthApp): Promise<any>
|
||||
},
|
||||
|
||||
organizations: async (_:any, __: any, context: any) => {
|
||||
const organizations = await db.getOrganizationsByUserId(context.userId);
|
||||
|
||||
const orgsWithProjectsPromises = organizations.map(async (org) => {
|
||||
const dbProjects = await db.getProjectsByOrganizationId(org.id);
|
||||
|
||||
const projectsPromises = dbProjects.map(async (dbProject) => {
|
||||
const dbProjectMembers = await db.getProjectMembersByProjectId(dbProject.id);
|
||||
const dbEnvironmentVariables = await db.getEnvironmentVariablesByProjectId(dbProject.id);
|
||||
|
||||
const projectMembers = dbProjectMembers.map(dbProjectMember => {
|
||||
return projectMemberToGqlType(dbProjectMember);
|
||||
});
|
||||
|
||||
const environmentVariables = dbEnvironmentVariables.map(dbEnvironmentVariable => {
|
||||
return environmentVariableToGqlType(dbEnvironmentVariable);
|
||||
});
|
||||
|
||||
return projectToGqlType(dbProject, projectMembers, environmentVariables);
|
||||
});
|
||||
|
||||
const projects = await Promise.all(projectsPromises);
|
||||
|
||||
return {
|
||||
...org,
|
||||
projects
|
||||
};
|
||||
});
|
||||
|
||||
// TODO: Add organizationMembers field when / if required
|
||||
const orgsWithProjects = await Promise.all(orgsWithProjectsPromises);
|
||||
return orgsWithProjects;
|
||||
return db.getOrganizationsByUserId(context.userId);
|
||||
},
|
||||
|
||||
project: async (_: any, { projectId }: { projectId: string }) => {
|
||||
|
||||
@@ -137,6 +137,7 @@ input UpdateProjectInput {
|
||||
name: String
|
||||
description: String
|
||||
prodBranch: String
|
||||
organizationId: String
|
||||
webhooks: [String!]
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user