From 293c93cc79fbd6baa3bdaef2d9dbc797315be685 Mon Sep 17 00:00:00 2001 From: mirarifhasan Date: Mon, 29 Apr 2024 22:26:00 +0600 Subject: [PATCH] chore: getTeamWithIDTE function removed --- .../hoppscotch-backend/src/admin/admin.service.ts | 7 ++++--- .../src/team-invitation/team-invitation.resolver.ts | 13 ++++++++----- .../hoppscotch-backend/src/team/team.service.ts | 13 ------------- 3 files changed, 12 insertions(+), 21 deletions(-) diff --git a/packages/hoppscotch-backend/src/admin/admin.service.ts b/packages/hoppscotch-backend/src/admin/admin.service.ts index 0bed66132..08a3d5474 100644 --- a/packages/hoppscotch-backend/src/admin/admin.service.ts +++ b/packages/hoppscotch-backend/src/admin/admin.service.ts @@ -11,6 +11,7 @@ import { EMAIL_FAILED, INVALID_EMAIL, ONLY_ONE_ADMIN_ACCOUNT, + TEAM_INVALID_ID, TEAM_INVITE_ALREADY_MEMBER, TEAM_INVITE_NO_INVITE_FOUND, USERS_NOT_FOUND, @@ -590,9 +591,9 @@ export class AdminService { * @returns an Either of `Team` or error */ async getTeamInfo(teamID: string) { - const team = await this.teamService.getTeamWithIDTE(teamID)(); - if (E.isLeft(team)) return E.left(team.left); - return E.right(team.right); + const team = await this.teamService.getTeamWithID(teamID); + if (!team) return E.left(TEAM_INVALID_ID); + return E.right(team); } /** diff --git a/packages/hoppscotch-backend/src/team-invitation/team-invitation.resolver.ts b/packages/hoppscotch-backend/src/team-invitation/team-invitation.resolver.ts index 32a903fa6..b0c586e8a 100644 --- a/packages/hoppscotch-backend/src/team-invitation/team-invitation.resolver.ts +++ b/packages/hoppscotch-backend/src/team-invitation/team-invitation.resolver.ts @@ -15,7 +15,11 @@ import * as TE from 'fp-ts/TaskEither'; import * as E from 'fp-ts/Either'; import * as O from 'fp-ts/Option'; import { Team, TeamMember, TeamMemberRole } from 'src/team/team.model'; -import { TEAM_INVITE_NO_INVITE_FOUND, USER_NOT_FOUND } from 'src/errors'; +import { + TEAM_INVALID_ID, + TEAM_INVITE_NO_INVITE_FOUND, + USER_NOT_FOUND, +} from 'src/errors'; import { GqlUser } from 'src/decorators/gql-user.decorator'; import { User } from 'src/user/user.model'; import { UseGuards } from '@nestjs/common'; @@ -50,10 +54,9 @@ export class TeamInvitationResolver { description: 'Get the team associated to the invite', }) async team(@Parent() teamInvitation: TeamInvitation): Promise { - return pipe( - this.teamService.getTeamWithIDTE(teamInvitation.teamID), - TE.getOrElse(throwErr), - )(); + const team = await this.teamService.getTeamWithID(teamInvitation.teamID); + if (!team) throwErr(TEAM_INVALID_ID); + return team; } @ResolveField(() => User, { diff --git a/packages/hoppscotch-backend/src/team/team.service.ts b/packages/hoppscotch-backend/src/team/team.service.ts index f1afcf908..86e65e0dd 100644 --- a/packages/hoppscotch-backend/src/team/team.service.ts +++ b/packages/hoppscotch-backend/src/team/team.service.ts @@ -311,19 +311,6 @@ export class TeamService implements UserDataHandler, OnModuleInit { } } - getTeamWithIDTE(teamID: string): TE.TaskEither<'team/invalid_id', Team> { - return pipe( - () => this.getTeamWithID(teamID), - TE.fromTask, - TE.chain( - TE.fromPredicate( - (x): x is Team => !!x, - () => TEAM_INVALID_ID, - ), - ), - ); - } - /** * Filters out team members that we weren't able to match * (also deletes the membership)