chore: getTeamWithIDTE function removed

This commit is contained in:
mirarifhasan
2024-04-29 22:26:00 +06:00
parent 844eee0fa4
commit 293c93cc79
3 changed files with 12 additions and 21 deletions

View File

@@ -11,6 +11,7 @@ import {
EMAIL_FAILED, EMAIL_FAILED,
INVALID_EMAIL, INVALID_EMAIL,
ONLY_ONE_ADMIN_ACCOUNT, ONLY_ONE_ADMIN_ACCOUNT,
TEAM_INVALID_ID,
TEAM_INVITE_ALREADY_MEMBER, TEAM_INVITE_ALREADY_MEMBER,
TEAM_INVITE_NO_INVITE_FOUND, TEAM_INVITE_NO_INVITE_FOUND,
USERS_NOT_FOUND, USERS_NOT_FOUND,
@@ -590,9 +591,9 @@ export class AdminService {
* @returns an Either of `Team` or error * @returns an Either of `Team` or error
*/ */
async getTeamInfo(teamID: string) { async getTeamInfo(teamID: string) {
const team = await this.teamService.getTeamWithIDTE(teamID)(); const team = await this.teamService.getTeamWithID(teamID);
if (E.isLeft(team)) return E.left(team.left); if (!team) return E.left(TEAM_INVALID_ID);
return E.right(team.right); return E.right(team);
} }
/** /**

View File

@@ -15,7 +15,11 @@ import * as TE from 'fp-ts/TaskEither';
import * as E from 'fp-ts/Either'; import * as E from 'fp-ts/Either';
import * as O from 'fp-ts/Option'; import * as O from 'fp-ts/Option';
import { Team, TeamMember, TeamMemberRole } from 'src/team/team.model'; 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 { GqlUser } from 'src/decorators/gql-user.decorator';
import { User } from 'src/user/user.model'; import { User } from 'src/user/user.model';
import { UseGuards } from '@nestjs/common'; import { UseGuards } from '@nestjs/common';
@@ -50,10 +54,9 @@ export class TeamInvitationResolver {
description: 'Get the team associated to the invite', description: 'Get the team associated to the invite',
}) })
async team(@Parent() teamInvitation: TeamInvitation): Promise<Team> { async team(@Parent() teamInvitation: TeamInvitation): Promise<Team> {
return pipe( const team = await this.teamService.getTeamWithID(teamInvitation.teamID);
this.teamService.getTeamWithIDTE(teamInvitation.teamID), if (!team) throwErr(TEAM_INVALID_ID);
TE.getOrElse(throwErr), return team;
)();
} }
@ResolveField(() => User, { @ResolveField(() => User, {

View File

@@ -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 * Filters out team members that we weren't able to match
* (also deletes the membership) * (also deletes the membership)