;
getOneById(teamId: string, options?: FindOneOptions
): Promise;
getOneByName(teamName: string | RegExp, options?: FindOneOptions): Promise;
diff --git a/server/services/team/service.ts b/server/services/team/service.ts
index a8ff78cbcff97..0a4c87e6c5085 100644
--- a/server/services/team/service.ts
+++ b/server/services/team/service.ts
@@ -15,6 +15,7 @@ import { UsersRaw } from '../../../app/models/server/raw/Users';
import { IRoom } from '../../../definition/IRoom';
import { IPaginationOptions, IQueryOptions, IRecordsWithTotal, ITeam, ITeamMember, ITeamStats, TEAM_TYPE } from '../../../definition/ITeam';
import { IUser } from '../../../definition/IUser';
+import { Messages } from '../../../app/models/server';
import { Room, Authorization } from '../../sdk';
import {
IListRoomsFilter,
@@ -125,6 +126,7 @@ export class TeamService extends ServiceClassInternal implements ITeamService {
let roomId = room.id;
if (roomId) {
await this.RoomsModel.setTeamMainById(roomId, teamId);
+ Messages.createUserConvertChannelToTeamWithRoomIdAndUser(roomId, team.name, createdBy);
} else {
const roomType: IRoom['t'] = team.type === TEAM_TYPE.PRIVATE ? 'p' : 'c';
@@ -342,7 +344,7 @@ export class TeamService extends ServiceClassInternal implements ITeamService {
throw new Error('missing-userId');
}
- const team = await this.TeamModel.findOneById(teamId, { projection: { _id: 1 } });
+ const team = await this.TeamModel.findOneById>(teamId, { projection: { _id: 1, roomId: 1 } });
if (!team) {
throw new Error('invalid-team');
}
@@ -373,6 +375,8 @@ export class TeamService extends ServiceClassInternal implements ITeamService {
throw new Error('error-no-owner-channel');
}
+ Messages.createUserAddRoomToTeamWithRoomIdAndUser(team.roomId, room.name, user);
+
room.teamId = teamId;
}
@@ -396,15 +400,15 @@ export class TeamService extends ServiceClassInternal implements ITeamService {
throw new Error('invalid-room');
}
+ const user = await this.Users.findOneById(uid);
if (!canRemoveAnyRoom) {
- const user = await this.Users.findOneById(uid);
const canSeeRoom = await canAccessRoom(room, user);
if (!canSeeRoom) {
throw new Error('invalid-room');
}
}
- const team = await this.TeamModel.findOneById(teamId, { projection: { _id: 1 } });
+ const team = await this.TeamModel.findOneById>(teamId, { projection: { _id: 1, roomId: 1 } });
if (!team) {
throw new Error('invalid-team');
}
@@ -416,16 +420,33 @@ export class TeamService extends ServiceClassInternal implements ITeamService {
delete room.teamId;
delete room.teamDefault;
this.RoomsModel.unsetTeamById(room._id);
+
+ Messages.createUserRemoveRoomFromTeamWithRoomIdAndUser(team.roomId, room.name, user);
+
return {
...room,
};
}
- async unsetTeamIdOfRooms(teamId: string): Promise {
+ async unsetTeamIdOfRooms(uid: string, teamId: string): Promise {
if (!teamId) {
throw new Error('missing-teamId');
}
+ const team = await this.TeamModel.findOneById>(teamId, { projection: { roomId: 1 } });
+ if (!team) {
+ throw new Error('invalid-team');
+ }
+
+ const room = await this.RoomsModel.findOneById>(team.roomId, { projection: { name: 1 } });
+ if (!room) {
+ throw new Error('invalid-room');
+ }
+
+ const user = await this.Users.findOneById(uid);
+
+ Messages.createUserConvertTeamToChannelWithRoomIdAndUser(team.roomId, room.name, user);
+
await this.RoomsModel.unsetTeamId(teamId);
}