Skip to content

Commit

Permalink
[REFACTOR]: Merge development into dev (#621)
Browse files Browse the repository at this point in the history
* fix(NI): ESLint errors (#506)

* Feat/add page for creating a new team (#515)

* feat: add page to create a team

* feat: add input for team name

* feat: add tipbar

* fix: fix esslint error on sprite

* feat: add margin bottom to team name title

* feat: change page title

* Feat/add card member to create new team page (#517)

* feat: add page to create a team

* feat: add input for team name

* feat: add tipbar

* fix: fix esslint error on sprite

* feat: add margin bottom to team name title

* feat: add card member w/ hard coded info

* fix: fix layout of create new team and team card

* feat: add btn to add members

* feat: organize components by directory/add changes

* fix: fix joi error on refresh create team page

* feat: add count to input

* feat: add borderBottom to header

* feat: add requested changes on ListCardMembers

* [FEATURE]: add form buttons to create team page (#520)

feat: add layout of cancel and create team btn

* [FEATURE]: Drawer with members (#523)

* feat: add drawer layout to display members list

* feat: add schema to search member form

* [FEATURE]: add users controller (#526)

* feat: add users controller

* fix: remove commented line from code

* feat: add requested changes

* fix: remove password and token from user response

* Feat/change searchinput (#529)

* feat: add new organization

* feat: change search input

* fix: fix onChange with function reference

* [FEATURE]: checklist with members (#532)

* feat: add user endpoint to api

* fix: fix search member input

* feat: render list of users with checkboxes

* fix: fix layout of the list with users

* feat: add toastState to listMembers

* fix: change button name to add

* fix: change onChange to function reference

* fix: fix create team title

* fix: fix imports and remove duplicated component

* fix: fix name of searchInput

* fix: remove useEffect from listMembers

* feat: list with checks is being preserved

* [FEATURE]: filter users list (#536)

* feat: add user endpoint to api

* fix: fix search member input

* feat: render list of users with checkboxes

* fix: fix layout of the list with users

* feat: add toastState to listMembers

* fix: change button name to add

* fix: change onChange to function reference

* fix: fix create team title

* fix: fix imports and remove duplicated component

* fix: fix name of searchInput

* fix: remove useEffect from listMembers

* feat: list with checks is being preserved

* feat: add filtered function to input

* feat: refine search user function

* [FEATURE]: list of selected users on recoil (#540)

* feat: add user endpoint to api

* fix: fix search member input

* feat: render list of users with checkboxes

* fix: fix layout of the list with users

* feat: add toastState to listMembers

* fix: change button name to add

* fix: change onChange to function reference

* fix: fix create team title

* fix: fix imports and remove duplicated component

* fix: fix name of searchInput

* fix: remove useEffect from listMembers

* feat: list with checks is being preserved

* feat: add filtered function to input

* feat: refine search user function

* feat: add team atom to recoil

* feat: change method find to some

* feat: add listUsersWithCheck to recoil

* [FEATURE]: endoint to get the teams of a user (#543)

* feat: add getTeamOfUser to controller

* feat: change to getTeamsOfUser endpoint

* feat: add suggested change

* feat: change userId to requestWithUser

* [FEATURE]: render members card (#547)

* feat: change type of membersList

* feat: render members cards

* fix: fix layout of the card member

* [FEATURE]: add newbee tip if members are > 1 (#549)

* [FEATURE]: show btn if scroll exists (#550)

feat: show btn if scroll exists

* Refactor/update development (#561)

* feat(NI): update main branch (#507)

* feat(NI): update main with development (#508)

* [BUG] Adding cards to closed sub-board (#509)

feat: add socket at merge board

* [FIX]: adding cards to closed sub boad eslint issues (#510)

* feat: add socket at merge board

* fix: eslint fix

* fix: lint issues react unknown property

Co-authored-by: Catia Barroco <104831678+CatiaBarroco-xgeeks@users.noreply.github.com>

* fix(NI): ESLint errors on Sprite (#511)

* [FEATURE]: disable teams button from sidebar menu (#513)

feat: disable teams btn from sidebar menu

* [FIX]: fix card team layout (#505)

fix: fix card team layout

* [BUG] Accessing a deleted board (#522)

feat: add socket to deleted boards

* [BUG]: Board Settings Info cancel button to reset info (#490)

feat: reset board settings info

* [REFACTOR]: update readme (#531)

Add usage icon and `/boards` url

* docs: add CatiaAntunes96 as a contributor for code, doc, and review (#533)

* docs: update README.md

* docs: update .all-contributorsrc

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>

* docs: add mourabraz as a contributor for code, doc, and review (#534)

* docs: update README.md

* docs: update .all-contributorsrc

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>

* docs: add miguel-felix1 as a contributor for code, bug, and 2 more (#535)

* docs: update README.md

* docs: update .all-contributorsrc

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
Co-authored-by: Nuno Caseiro <90208434+nunocaseiro@users.noreply.github.com>

* chore(deps): bump vm2 from 3.9.10 to 3.9.11 in /backend (#537)

Bumps [vm2](https://github.com/patriksimek/vm2) from 3.9.10 to 3.9.11.
- [Release notes](https://github.com/patriksimek/vm2/releases)
- [Changelog](https://github.com/patriksimek/vm2/blob/master/CHANGELOG.md)
- [Commits](patriksimek/vm2@3.9.10...3.9.11)

---
updated-dependencies:
- dependency-name: vm2
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* [FIX]:  Board list bottom cut off (#554)

fix: scrollable content height fixed

* [REFACTOR]: list boards without showing subboards  (#557)

feat: change initial state to false

* [FIX]: stakeholders, delete cron job (#559)

* [FEATURE]: show boards members  (#560)

* feat: show users on board page

* fix: fix listUsers if user is not found

* fix: change users.length for const usersCount

* fix: change numbersOfAvatars to ternary condition

* Feat/add page for creating a new team (#515)

* feat: add page to create a team

* feat: add input for team name

* feat: add tipbar

* fix: fix esslint error on sprite

* feat: add margin bottom to team name title

* feat: change page title

* Feat/add card member to create new team page (#517)

* feat: add page to create a team

* feat: add input for team name

* feat: add tipbar

* fix: fix esslint error on sprite

* feat: add margin bottom to team name title

* feat: add card member w/ hard coded info

* fix: fix layout of create new team and team card

* feat: add btn to add members

* feat: organize components by directory/add changes

* fix: fix joi error on refresh create team page

* feat: add count to input

* feat: add borderBottom to header

* feat: add requested changes on ListCardMembers

* [FEATURE]: add form buttons to create team page (#520)

feat: add layout of cancel and create team btn

* [FEATURE]: Drawer with members (#523)

* feat: add drawer layout to display members list

* feat: add schema to search member form

* [FEATURE]: add users controller (#526)

* feat: add users controller

* fix: remove commented line from code

* feat: add requested changes

* fix: remove password and token from user response

* Feat/change searchinput (#529)

* feat: add new organization

* feat: change search input

* fix: fix onChange with function reference

* [FEATURE]: checklist with members (#532)

* feat: add user endpoint to api

* fix: fix search member input

* feat: render list of users with checkboxes

* fix: fix layout of the list with users

* feat: add toastState to listMembers

* fix: change button name to add

* fix: change onChange to function reference

* fix: fix create team title

* fix: fix imports and remove duplicated component

* fix: fix name of searchInput

* fix: remove useEffect from listMembers

* feat: list with checks is being preserved

* [FEATURE]: filter users list (#536)

* feat: add user endpoint to api

* fix: fix search member input

* feat: render list of users with checkboxes

* fix: fix layout of the list with users

* feat: add toastState to listMembers

* fix: change button name to add

* fix: change onChange to function reference

* fix: fix create team title

* fix: fix imports and remove duplicated component

* fix: fix name of searchInput

* fix: remove useEffect from listMembers

* feat: list with checks is being preserved

* feat: add filtered function to input

* feat: refine search user function

* [FEATURE]: list of selected users on recoil (#540)

* feat: add user endpoint to api

* fix: fix search member input

* feat: render list of users with checkboxes

* fix: fix layout of the list with users

* feat: add toastState to listMembers

* fix: change button name to add

* fix: change onChange to function reference

* fix: fix create team title

* fix: fix imports and remove duplicated component

* fix: fix name of searchInput

* fix: remove useEffect from listMembers

* feat: list with checks is being preserved

* feat: add filtered function to input

* feat: refine search user function

* feat: add team atom to recoil

* feat: change method find to some

* feat: add listUsersWithCheck to recoil

* [FEATURE]: endoint to get the teams of a user (#543)

* feat: add getTeamOfUser to controller

* feat: change to getTeamsOfUser endpoint

* feat: add suggested change

* feat: change userId to requestWithUser

* [FEATURE]: render members card (#547)

* feat: change type of membersList

* feat: render members cards

* fix: fix layout of the card member

* [FEATURE]: add newbee tip if members are > 1 (#549)

* [FEATURE]: show btn if scroll exists (#550)

feat: show btn if scroll exists

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Daniel Sousa <104842894+dsousa12@users.noreply.github.com>
Co-authored-by: Cátia Barroco <104831678+CatiaBarroco-xgeeks@users.noreply.github.com>
Co-authored-by: f-morgado <99803749+f-morgado@users.noreply.github.com>
Co-authored-by: Nuno Caseiro <90208434+nunocaseiro@users.noreply.github.com>
Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* [FEATURE]: change role of team member (#566)

* feat: add popover with options

* fix: team members avatar fixed

* feat: add popover as select to change roles

* fix: fix goBack btn as it is on main

* fix: scrollbar height

* fix: add requested changes

* [REFACTOR]: change create teams logic (#570)

* feat: add isNewbie attribute

* refactor: remove userId from createTeams

* fix: fix countTeams of user

* refactor: remove createTeam from user module

* fix: fix undefined users error

* refactor: show teams refactor

* fix: patch on the signUp error

* refactor: add count()

* [FEATURE]: newbee prop (#568)

* feat: add popover with options

* fix: team members avatar fixed

* feat: add popover as select to change roles

* fix: fix goBack btn as it is on main

* fix: scrollbar height

* fix: add requested changes

* feat: add newbee functionality

* fix: refactor code

* refactor: change from sort to unshift

* fix: change newbee to newbie

* fix: change Newbie name / add changes

* [REFACTOR]: fix card team (#574)

* feat: add boards service

* feat: add boardsCount attribute

* fix: fix layout of cardBody

* fix: fix cardBody

* fix: conditionally map data

* fix: change px to token

* fix: change returned type to LeanDocument<Team>

* [FEATURE]: submit created team (#572)

* fix: change attribute name

* refactor: add useTeam with queries/mutations

* feat: save new team function

* fix: fix return data from new team page

* [BUG]: fix docker-compose.dev (#586)

fix: change file to accept redis

* [FEATURE]: add get team endpoint (#592)

* fix: fix returned information and attribute name

* fix: remove link to boards page/change blob color

* fix: fix members list layout

* feat: add animation to tooltip

* feat: add getTeam query as hook

* fix: resolve requested changes

* [FEATURE]: Team Page (#603)

* feat: add layout to display the team page

* fix: add requested changes

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Daniel Sousa <104842894+dsousa12@users.noreply.github.com>
Co-authored-by: Cátia Barroco <104831678+CatiaBarroco-xgeeks@users.noreply.github.com>
Co-authored-by: f-morgado <99803749+f-morgado@users.noreply.github.com>
Co-authored-by: Nuno Caseiro <90208434+nunocaseiro@users.noreply.github.com>
Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
7 people authored Nov 22, 2022
1 parent 1ff6ac8 commit 7735a3f
Show file tree
Hide file tree
Showing 83 changed files with 2,012 additions and 288 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,8 @@ export class GetBoardApplication implements GetBoardApplicationInterface {
countBoards(userId: string) {
return this.getBoardService.countBoards(userId);
}

getAllBoardIdsAndTeamIdsOfUser(userId: string) {
return this.getBoardService.getAllBoardIdsAndTeamIdsOfUser(userId);
}
}
4 changes: 2 additions & 2 deletions backend/src/modules/boards/boards.module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Module } from '@nestjs/common';
import { forwardRef, Module } from '@nestjs/common';

import {
mongooseBoardModule,
Expand All @@ -24,7 +24,7 @@ import BoardsController from './controller/boards.controller';
@Module({
imports: [
UsersModule,
TeamsModule,
forwardRef(() => TeamsModule),
SchedulesModule,
CommunicationModule,
mongooseBoardModule,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@ export interface GetBoardApplicationInterface {
>;

countBoards(userId: string): Promise<number>;

getAllBoardIdsAndTeamIdsOfUser(
userId: string
): Promise<{ boardIds: LeanDocument<any>[]; teamIds: any[] }>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,8 @@ export interface GetBoardServiceInterface {
): Promise<LeanDocument<Board & Document<any, any, any> & { _id: any }> | null>;

countBoards(userId: string): Promise<number>;

getAllBoardIdsAndTeamIdsOfUser(
userId: string
): Promise<{ boardIds: LeanDocument<any>[]; teamIds: any[] }>;
}
4 changes: 2 additions & 2 deletions backend/src/modules/boards/services/create.board.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Inject, Injectable, Logger } from '@nestjs/common';
import { forwardRef, Inject, Injectable, Logger } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose';
import { LeanDocument, Model } from 'mongoose';

Expand Down Expand Up @@ -45,7 +45,7 @@ export default class CreateBoardServiceImpl implements CreateBoardService {
@InjectModel(Board.name) private boardModel: Model<BoardDocument>,
@InjectModel(BoardUser.name)
private boardUserModel: Model<BoardUserDocument>,
@Inject(TeamType.services.GetTeamService)
@Inject(forwardRef(() => TeamType.services.GetTeamService))
private getTeamService: GetTeamServiceInterface,
@Inject(TYPES.services.GetBoardService)
private getBoardService: GetBoardServiceInterface,
Expand Down
10 changes: 5 additions & 5 deletions backend/src/modules/boards/services/delete.board.service.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import { Inject, Injectable, NotFoundException } from '@nestjs/common';
import { forwardRef, Inject, Injectable, NotFoundException } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose';
import { ClientSession, LeanDocument, Model, ObjectId } from 'mongoose';

import { TeamRoles } from 'libs/enum/team.roles';
import { DELETE_FAILED } from 'libs/exceptions/messages';
import isEmpty from 'libs/utils/isEmpty';
import { DeleteSchedulesServiceInterface } from 'modules/schedules/interfaces/services/delete.schedules.service.interface';
import * as Schedules from 'modules/schedules/interfaces/types';
import { GetTeamServiceInterface } from 'modules/teams/interfaces/services/get.team.service.interface';
import * as Teams from 'modules/teams/interfaces/types';
import * as Schedules from 'modules/schedules/interfaces/types'
import { TeamUserDocument } from 'modules/teams/schemas/team.user.schema';
import { UserDocument } from 'modules/users/schemas/user.schema';

import { DeleteBoardService } from '../interfaces/services/delete.board.service.interface';
import Board, { BoardDocument } from '../schemas/board.schema';
import BoardUser, { BoardUserDocument } from '../schemas/board.user.schema';
import { DeleteSchedulesServiceInterface } from 'modules/schedules/interfaces/services/delete.schedules.service.interface';

@Injectable()
export default class DeleteBoardServiceImpl implements DeleteBoardService {
constructor(
@InjectModel(Board.name)
private boardModel: Model<BoardDocument>,
@Inject(Teams.TYPES.services.GetTeamService)
@Inject(forwardRef(() => Teams.TYPES.services.GetTeamService))
private getTeamService: GetTeamServiceInterface,
@Inject(Schedules.TYPES.services.DeleteSchedulesService)
private deleteSheduleService: DeleteSchedulesServiceInterface,
Expand Down Expand Up @@ -116,7 +116,7 @@ export default class DeleteBoardServiceImpl implements DeleteBoardService {
boardUserSession.startTransaction();
try {
const { _id, dividedBoards } = await this.deleteBoard(boardId, userId, boardSession);
this.deleteSheduleService.findAndDeleteScheduleByBoardId(boardId)
this.deleteSheduleService.findAndDeleteScheduleByBoardId(boardId);

if (!isEmpty(dividedBoards)) {
await this.deleteSubBoards(dividedBoards, boardSession);
Expand Down
4 changes: 2 additions & 2 deletions backend/src/modules/boards/services/get.board.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Inject, Injectable, Logger } from '@nestjs/common';
import { forwardRef, Inject, Injectable, Logger } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose';
import { ObjectId } from 'mongodb';
import { LeanDocument, Model } from 'mongoose';
Expand All @@ -24,7 +24,7 @@ export default class GetBoardServiceImpl implements GetBoardServiceInterface {
@InjectModel(Board.name) private boardModel: Model<BoardDocument>,
@InjectModel(BoardUser.name)
private boardUserModel: Model<BoardUserDocument>,
@Inject(Team.TYPES.services.GetTeamService)
@Inject(forwardRef(() => Team.TYPES.services.GetTeamService))
private getTeamService: GetTeamServiceInterface
) {}

Expand Down
3 changes: 2 additions & 1 deletion backend/src/modules/boards/services/update.board.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
BadRequestException,
ForbiddenException,
forwardRef,
Inject,
Injectable,
NotFoundException
Expand Down Expand Up @@ -31,7 +32,7 @@ import BoardUser, { BoardUserDocument } from '../schemas/board.user.schema';
export default class UpdateBoardServiceImpl implements UpdateBoardServiceInterface {
constructor(
@InjectModel(Board.name) private boardModel: Model<BoardDocument>,
@Inject(Teams.TYPES.services.GetTeamService)
@Inject(forwardRef(() => Teams.TYPES.services.GetTeamService))
private getTeamService: GetTeamServiceInterface,
@Inject(CommunicationsType.TYPES.services.SlackCommunicationService)
private slackCommunicationService: CommunicationServiceInterface,
Expand Down
4 changes: 1 addition & 3 deletions backend/src/modules/schedules/dto/add.cronjob.dto.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { Configs } from 'modules/boards/interfaces/services/create.board.service.interface';

export class AddCronJobDto {
boardId!: string;

ownerId!: string;

teamId!: string;

maxUsersPerTeam!: number
maxUsersPerTeam!: number;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class CreateTeamApplication implements CreateTeamApplicationInterface {
return this.createTeamService.createTeamUser(teamUser);
}

create(teamData: TeamDto, userId: string) {
return this.createTeamService.create(teamData, userId);
create(teamData: TeamDto) {
return this.createTeamService.create(teamData);
}
}
23 changes: 21 additions & 2 deletions backend/src/modules/teams/controller/team.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ export default class TeamsController {
type: InternalServerErrorResponse
})
@Post()
async create(@Req() request: RequestWithUser, @Body() teamData: CreateTeamDto) {
const team = await this.createTeamApp.create(teamData, request.user._id);
async create(@Body() teamData: CreateTeamDto) {
const team = await this.createTeamApp.create(teamData);
if (!team) throw new BadRequestException(INSERT_FAILED);
return team;
}
Expand Down Expand Up @@ -120,6 +120,25 @@ export default class TeamsController {
return this.getTeamApp.getAllTeams();
}

@ApiOperation({ summary: 'Retrieve a list of teams that belongs to an user' })
@ApiOkResponse({ description: 'Teams successfully retrieved!', type: TeamDto, isArray: true })
@ApiUnauthorizedResponse({
description: 'Unauthorized',
type: UnauthorizedResponse
})
@ApiBadRequestResponse({
description: 'Bad Request',
type: BadRequestResponse
})
@ApiInternalServerErrorResponse({
description: 'Internal Server Error',
type: InternalServerErrorResponse
})
@Get('user')
getTeamsOfUser(@Req() request: RequestWithUser) {
return this.getTeamApp.getTeamsOfUser(request.user._id);
}

@ApiOperation({ summary: 'Get a list of users belongs to the team' })
@ApiParam({ name: 'teamId', type: String })
@ApiQuery({
Expand Down
8 changes: 7 additions & 1 deletion backend/src/modules/teams/dto/team.user.dto.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { IsEnum, IsMongoId, IsNotEmpty, IsOptional, IsString } from 'class-validator';
import { IsBoolean, IsEnum, IsMongoId, IsNotEmpty, IsOptional, IsString } from 'class-validator';

import { TeamRoles } from 'libs/enum/team.roles';

Expand All @@ -21,4 +21,10 @@ export default class TeamUserDto {
@IsString()
@IsMongoId()
team?: string;

@ApiPropertyOptional()
@IsOptional()
@IsBoolean()
@IsMongoId()
isNewJoiner?: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ import { TeamDocument } from '../../schemas/teams.schema';
export interface CreateTeamApplicationInterface {
createTeamUser(teamUser: TeamUserDto): Promise<TeamUserDocument>;

create(teamData: CreateTeamDto, userId: string): Promise<TeamDocument>;
create(teamData: CreateTeamDto): Promise<TeamDocument>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { TeamUserDocument } from '../../schemas/team.user.schema';
import { TeamDocument } from '../../schemas/teams.schema';

export interface CreateTeamServiceInterface {
create(teamData: TeamDto, userId: string): Promise<TeamDocument>;
create(teamData: TeamDto): Promise<TeamDocument>;

createTeam(name: string): Promise<TeamDocument>;

Expand Down
6 changes: 6 additions & 0 deletions backend/src/modules/teams/schemas/team.user.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ export default class TeamUser {
})
role!: string;

@Prop({
type: Boolean,
nullable: false
})
isNewJoiner!: boolean;

@Prop({ type: SchemaTypes.ObjectId, ref: 'User', nullable: false })
user!: User | ObjectId;

Expand Down
11 changes: 11 additions & 0 deletions backend/src/modules/teams/schemas/teams.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Document } from 'mongoose';
import * as leanVirtualsPlugin from 'mongoose-lean-virtuals';

import Board from '../../boards/schemas/board.schema';

export type TeamDocument = Team & Document;

@Schema({
Expand All @@ -12,6 +14,8 @@ export type TeamDocument = Team & Document;
export default class Team {
@Prop({ nullable: false })
name!: string;

boards?: Board[];
}

export const TeamSchema = SchemaFactory.createForClass(Team);
Expand All @@ -24,3 +28,10 @@ TeamSchema.virtual('users', {
foreignField: 'team',
justOne: false
});

TeamSchema.virtual('boards', {
ref: 'Board',
localField: '_id',
foreignField: 'team',
justOne: false
});
15 changes: 3 additions & 12 deletions backend/src/modules/teams/services/create.team.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Injectable } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose';
import { Model } from 'mongoose';

import { TeamRoles } from 'libs/enum/team.roles';
import isEmpty from 'libs/utils/isEmpty';

import { CreateTeamDto } from '../dto/crate-team.dto';
Expand Down Expand Up @@ -32,22 +31,14 @@ export default class CreateTeamService implements CreateTeamServiceInterface {
return this.teamModel.create({ name });
}

async create(teamData: CreateTeamDto, userId: string) {
async create(teamData: CreateTeamDto) {
const { users, name } = teamData;
const newTeam = await this.teamModel.create({
name
});

const newUsers = [
...users,
{
user: userId,
role: TeamRoles.ADMIN
}
];

if (!isEmpty(newUsers)) {
await this.createTeamUsers(newUsers, newTeam._id);
if (!isEmpty(users)) {
await this.createTeamUsers(users, newTeam._id);
}

return newTeam.populate('users');
Expand Down
58 changes: 43 additions & 15 deletions backend/src/modules/teams/services/get.team.service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { Injectable } from '@nestjs/common';
import { forwardRef, Inject, Injectable } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose';
import { Model } from 'mongoose';
import { LeanDocument, Model } from 'mongoose';

import * as BoardTypes from 'modules/boards/interfaces/types';

import { TeamQueryParams } from '../../../libs/dto/param/team.query.params';
import { GetBoardServiceInterface } from '../../boards/interfaces/services/get.board.service.interface';
import { GetTeamServiceInterface } from '../interfaces/services/get.team.service.interface';
import TeamUser, { TeamUserDocument } from '../schemas/team.user.schema';
import Team, { TeamDocument } from '../schemas/teams.schema';
Expand All @@ -11,15 +14,13 @@ import Team, { TeamDocument } from '../schemas/teams.schema';
export default class GetTeamService implements GetTeamServiceInterface {
constructor(
@InjectModel(Team.name) private teamModel: Model<TeamDocument>,
@InjectModel(TeamUser.name) private teamUserModel: Model<TeamUserDocument>
@InjectModel(TeamUser.name) private teamUserModel: Model<TeamUserDocument>,
@Inject(forwardRef(() => BoardTypes.TYPES.services.GetBoardService))
private getBoardService: GetBoardServiceInterface
) {}

countTeams(userId: string) {
return this.teamModel
.countDocuments({
users: { $elemMatch: { user: userId } }
})
.exec();
async countTeams(userId: string) {
return this.teamUserModel.find({ user: userId }).distinct('team').count();
}

countAllTeams() {
Expand All @@ -39,7 +40,7 @@ export default class GetTeamService implements GetTeamServiceInterface {
teamModel
.populate({
path: 'users',
select: 'user role',
select: 'user role isNewJoiner',
...teamUserRoleFilter,
populate: {
path: 'user',
Expand All @@ -51,17 +52,44 @@ export default class GetTeamService implements GetTeamServiceInterface {
teamModel.lean();
}

return teamModel.exec();
return teamModel
.select('_id name')
.populate({
path: 'users',
select: 'user role isNewJoiner',
populate: {
path: 'user',
select: '_id firstName lastName email joinedAt'
}
})
.lean()
.exec();
}

async getTeamsOfUser(userId: string) {
const teams = await this.teamUserModel.find({ user: userId }).distinct('team');
return this.teamModel
.find({ _id: { $in: teams } })
const teamsUser = await this.teamUserModel.find({ user: userId }).distinct('team');

const teams: LeanDocument<TeamDocument>[] = await this.teamModel
.find({ _id: { $in: teamsUser } })
.select('_id name')
.populate({ path: 'users', select: '_id user role' })
.populate({
path: 'users',
select: 'user role',
populate: {
path: 'user',
select: '_id firstName lastName email joinedAt'
}
})
.populate({
path: 'boards',
select: '_id'
})
.lean()
.exec();

return teams.map((team) => {
return { ...team, boardsCount: team.boards?.length ?? 0, boards: undefined };
});
}

getTeamUser(userId: string, teamId: string) {
Expand Down
Loading

0 comments on commit 7735a3f

Please sign in to comment.