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,
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);
}
/**

View File

@@ -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<Team> {
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, {

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
* (also deletes the membership)