Compare commits
6 Commits
main
...
refactor/t
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ca6522f370 | ||
|
|
872623231f | ||
|
|
20ac35becb | ||
|
|
5eed5ce176 | ||
|
|
9694c0d373 | ||
|
|
293c93cc79 |
@@ -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,
|
||||||
@@ -318,11 +319,11 @@ export class AdminService {
|
|||||||
const user = await this.userService.findUserByEmail(userEmail);
|
const user = await this.userService.findUserByEmail(userEmail);
|
||||||
if (O.isNone(user)) return E.left(USER_NOT_FOUND);
|
if (O.isNone(user)) return E.left(USER_NOT_FOUND);
|
||||||
|
|
||||||
const teamMember = await this.teamService.getTeamMemberTE(
|
const teamMember = await this.teamService.getTeamMember(
|
||||||
teamID,
|
teamID,
|
||||||
user.value.uid,
|
user.value.uid,
|
||||||
)();
|
);
|
||||||
if (E.isLeft(teamMember)) {
|
if (!teamMember) {
|
||||||
const addedUser = await this.teamService.addMemberToTeamWithEmail(
|
const addedUser = await this.teamService.addMemberToTeamWithEmail(
|
||||||
teamID,
|
teamID,
|
||||||
userEmail,
|
userEmail,
|
||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -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, {
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import {
|
|||||||
} from '../errors';
|
} from '../errors';
|
||||||
import { mockDeep, mockReset } from 'jest-mock-extended';
|
import { mockDeep, mockReset } from 'jest-mock-extended';
|
||||||
import * as O from 'fp-ts/Option';
|
import * as O from 'fp-ts/Option';
|
||||||
|
import { skip } from 'rxjs';
|
||||||
|
|
||||||
const mockPrisma = mockDeep<PrismaService>();
|
const mockPrisma = mockDeep<PrismaService>();
|
||||||
|
|
||||||
@@ -755,6 +756,8 @@ describe('getMembersOfTeam', () => {
|
|||||||
|
|
||||||
expect(mockPrisma.teamMember.findMany).toHaveBeenCalledWith({
|
expect(mockPrisma.teamMember.findMany).toHaveBeenCalledWith({
|
||||||
take: 10,
|
take: 10,
|
||||||
|
skip: 0,
|
||||||
|
cursor: undefined,
|
||||||
where: {
|
where: {
|
||||||
teamID: team.id,
|
teamID: team.id,
|
||||||
},
|
},
|
||||||
@@ -806,6 +809,8 @@ describe('getTeamsOfUser', () => {
|
|||||||
|
|
||||||
expect(mockPrisma.teamMember.findMany).toHaveBeenCalledWith({
|
expect(mockPrisma.teamMember.findMany).toHaveBeenCalledWith({
|
||||||
take: 10,
|
take: 10,
|
||||||
|
skip: 0,
|
||||||
|
cursor: undefined,
|
||||||
where: {
|
where: {
|
||||||
userUid: dbTeamMember.userUid,
|
userUid: dbTeamMember.userUid,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import {
|
|||||||
} from '../errors';
|
} from '../errors';
|
||||||
import { PubSubService } from '../pubsub/pubsub.service';
|
import { PubSubService } from '../pubsub/pubsub.service';
|
||||||
import { flow, pipe } from 'fp-ts/function';
|
import { flow, pipe } from 'fp-ts/function';
|
||||||
import * as TE from 'fp-ts/TaskEither';
|
|
||||||
import * as TO from 'fp-ts/TaskOption';
|
import * as TO from 'fp-ts/TaskOption';
|
||||||
import * as O from 'fp-ts/Option';
|
import * as O from 'fp-ts/Option';
|
||||||
import * as E from 'fp-ts/Either';
|
import * as E from 'fp-ts/Either';
|
||||||
@@ -264,37 +263,25 @@ export class TeamService implements UserDataHandler, OnModuleInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getTeamsOfUser(uid: string, cursor: string | null): Promise<Team[]> {
|
async getTeamsOfUser(uid: string, cursor: string | null): Promise<Team[]> {
|
||||||
if (!cursor) {
|
const entries = await this.prisma.teamMember.findMany({
|
||||||
const entries = await this.prisma.teamMember.findMany({
|
take: 10,
|
||||||
take: 10,
|
skip: cursor ? 1 : 0,
|
||||||
where: {
|
cursor: cursor
|
||||||
userUid: uid,
|
? {
|
||||||
},
|
teamID_userUid: {
|
||||||
include: {
|
teamID: cursor,
|
||||||
team: true,
|
userUid: uid,
|
||||||
},
|
},
|
||||||
});
|
}
|
||||||
|
: undefined,
|
||||||
return entries.map((entry) => entry.team);
|
where: {
|
||||||
} else {
|
userUid: uid,
|
||||||
const entries = await this.prisma.teamMember.findMany({
|
},
|
||||||
take: 10,
|
include: {
|
||||||
skip: 1,
|
team: true,
|
||||||
cursor: {
|
},
|
||||||
teamID_userUid: {
|
});
|
||||||
teamID: cursor,
|
return entries.map((entry) => entry.team);
|
||||||
userUid: uid,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
where: {
|
|
||||||
userUid: uid,
|
|
||||||
},
|
|
||||||
include: {
|
|
||||||
team: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
return entries.map((entry) => entry.team);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async getTeamWithID(teamID: string): Promise<Team | null> {
|
async getTeamWithID(teamID: string): Promise<Team | null> {
|
||||||
@@ -311,19 +298,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)
|
||||||
@@ -375,19 +349,6 @@ export class TeamService implements UserDataHandler, OnModuleInit {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getTeamMemberTE(teamID: string, userUid: string) {
|
|
||||||
return pipe(
|
|
||||||
() => this.getTeamMember(teamID, userUid),
|
|
||||||
TE.fromTask,
|
|
||||||
TE.chain(
|
|
||||||
TE.fromPredicate(
|
|
||||||
(x): x is TeamMember => !!x,
|
|
||||||
() => TEAM_MEMBER_NOT_FOUND,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
async getRoleOfUserInTeam(
|
async getRoleOfUserInTeam(
|
||||||
teamID: string,
|
teamID: string,
|
||||||
userUid: string,
|
userUid: string,
|
||||||
@@ -472,25 +433,12 @@ export class TeamService implements UserDataHandler, OnModuleInit {
|
|||||||
): Promise<TeamMember[]> {
|
): Promise<TeamMember[]> {
|
||||||
let teamMembers: DbTeamMember[];
|
let teamMembers: DbTeamMember[];
|
||||||
|
|
||||||
if (!cursor) {
|
teamMembers = await this.prisma.teamMember.findMany({
|
||||||
teamMembers = await this.prisma.teamMember.findMany({
|
take: 10,
|
||||||
take: 10,
|
skip: cursor ? 1 : 0,
|
||||||
where: {
|
cursor: cursor ? { id: cursor } : undefined,
|
||||||
teamID,
|
where: { teamID },
|
||||||
},
|
});
|
||||||
});
|
|
||||||
} else {
|
|
||||||
teamMembers = await this.prisma.teamMember.findMany({
|
|
||||||
take: 10,
|
|
||||||
skip: 1,
|
|
||||||
cursor: {
|
|
||||||
id: cursor,
|
|
||||||
},
|
|
||||||
where: {
|
|
||||||
teamID,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const members = teamMembers.map(
|
const members = teamMembers.map(
|
||||||
(entry) =>
|
(entry) =>
|
||||||
|
|||||||
Reference in New Issue
Block a user