From 09afb8f1e3ba0872f079488224b13080121952fe Mon Sep 17 00:00:00 2001 From: Blue Mouse Date: Sat, 14 Dec 2024 21:30:27 +0000 Subject: [PATCH] fix: getOrganisationsForUser function does not exist --- .../apps/cloud/src/auth/auth.controller.ts | 2 +- backend/apps/cloud/src/auth/auth.service.ts | 23 ++----------------- .../apps/cloud/src/user/user.controller.ts | 2 +- backend/apps/cloud/src/user/user.module.ts | 2 +- backend/apps/cloud/src/user/user.service.ts | 21 +++++++++++++++++ 5 files changed, 26 insertions(+), 24 deletions(-) diff --git a/backend/apps/cloud/src/auth/auth.controller.ts b/backend/apps/cloud/src/auth/auth.controller.ts index 1d9a191d..33b53ac7 100644 --- a/backend/apps/cloud/src/auth/auth.controller.ts +++ b/backend/apps/cloud/src/auth/auth.controller.ts @@ -168,7 +168,7 @@ export class AuthController { } else { const [sharedProjects, organisationMemberships] = await Promise.all([ this.authService.getSharedProjectsForUser(user.id), - this.authService.getOrganisationsForUser(user.id), + this.userService.getOrganisationsForUser(user.id), ]) user.sharedProjects = sharedProjects diff --git a/backend/apps/cloud/src/auth/auth.service.ts b/backend/apps/cloud/src/auth/auth.service.ts index e74d85db..c245a3d4 100644 --- a/backend/apps/cloud/src/auth/auth.service.ts +++ b/backend/apps/cloud/src/auth/auth.service.ts @@ -212,25 +212,6 @@ export class AuthService { }) } - async getOrganisationsForUser(userId: string) { - return this.organisationService.findMemberships({ - where: { - user: { id: userId }, - }, - relations: ['organisation'], - select: { - id: true, - role: true, - confirmed: true, - created: true, - organisation: { - id: true, - name: true, - }, - }, - }) - } - private async comparePassword( password: string, hashedPassword: string, @@ -519,7 +500,7 @@ export class AuthService { } else { const [sharedProjects, organisationMemberships] = await Promise.all([ this.getSharedProjectsForUser(user.id), - this.getOrganisationsForUser(user.id), + this.userService.getOrganisationsForUser(user.id), ]) user.sharedProjects = sharedProjects @@ -986,7 +967,7 @@ export class AuthService { } else { const [sharedProjects, organisationMemberships] = await Promise.all([ this.getSharedProjectsForUser(user.id), - this.getOrganisationsForUser(user.id), + this.userService.getOrganisationsForUser(user.id), ]) user.sharedProjects = sharedProjects diff --git a/backend/apps/cloud/src/user/user.controller.ts b/backend/apps/cloud/src/user/user.controller.ts index d0c42882..136f43fe 100644 --- a/backend/apps/cloud/src/user/user.controller.ts +++ b/backend/apps/cloud/src/user/user.controller.ts @@ -108,7 +108,7 @@ export class UserController { const [sharedProjects, organisationMemberships, user, totalMonthlyEvents] = await Promise.all([ this.authService.getSharedProjectsForUser(uid), - this.authService.getOrganisationsForUser(uid), + this.userService.getOrganisationsForUser(uid), this.userService.findOne({ where: { id: uid } }), this.projectService.getRedisCount(uid), ]) diff --git a/backend/apps/cloud/src/user/user.module.ts b/backend/apps/cloud/src/user/user.module.ts index a4097241..8e2d8463 100644 --- a/backend/apps/cloud/src/user/user.module.ts +++ b/backend/apps/cloud/src/user/user.module.ts @@ -25,7 +25,7 @@ import { OrganisationModule } from '../organisation/organisation.module' forwardRef(() => AuthModule), AppLoggerModule, ProjectModule, - forwardRef(() => OrganisationModule), + OrganisationModule, PayoutsModule, HttpModule, ], diff --git a/backend/apps/cloud/src/user/user.service.ts b/backend/apps/cloud/src/user/user.service.ts index e310eea3..d1395476 100644 --- a/backend/apps/cloud/src/user/user.service.ts +++ b/backend/apps/cloud/src/user/user.service.ts @@ -40,6 +40,7 @@ import { UserGoogleDTO } from './dto/user-google.dto' import { UserGithubDTO } from './dto/user-github.dto' import { EMAIL_ACTION_ENCRYPTION_KEY } from '../common/constants' import { ReportFrequency } from '../project/enums' +import { OrganisationService } from '../organisation/organisation.service' dayjs.extend(utc) @@ -109,6 +110,7 @@ export class UserService { @InjectRepository(DeleteFeedback) private readonly deleteFeedbackRepository: Repository, private readonly payoutsService: PayoutsService, + private readonly organisationService: OrganisationService, ) {} async create( @@ -296,6 +298,25 @@ export class UserService { }) } + async getOrganisationsForUser(userId: string) { + return this.organisationService.findMemberships({ + where: { + user: { id: userId }, + }, + relations: ['organisation'], + select: { + id: true, + role: true, + confirmed: true, + created: true, + organisation: { + id: true, + name: true, + }, + }, + }) + } + async updateUserTelegramId( userId: string, telegramId: number | null,