@ -16,6 +16,7 @@ import { IRoom } from '../../../definition/IRoom';
import { addUserToRoom } from '../../../app/lib/server/functions/addUserToRoom' ;
import { canAccessRoom } from '../authorization/canAccessRoom' ;
import { escapeRegExp } from '../../../lib/escapeRegExp' ;
import { checkUsernameAvailability } from '../../../app/lib/server/functions' ;
export class TeamService extends ServiceClass implements ITeamService {
protected name = 'team' ;
@ -44,8 +45,7 @@ export class TeamService extends ServiceClass implements ITeamService {
}
async create ( uid : string , { team , room = { name : team.name , extraData : { } } , members , owner } : ITeamCreateParams ) : Promise < ITeam > {
const existingTeam = await this . TeamModel . findOneByName ( team . name , { projection : { _id : 1 } } ) ;
if ( existingTeam ) {
if ( ! checkUsernameAvailability ( team . name ) ) {
throw new Error ( 'team-name-already-exists' ) ;
}
@ -604,7 +604,7 @@ export class TeamService extends ServiceClass implements ITeamService {
return this . TeamModel . findOneById ( teamId , options ) ;
}
async getOneByName ( teamName : string , options? : FindOneOptions < ITeam > ) : Promise < ITeam | null > {
async getOneByName ( teamName : string | RegExp , options? : FindOneOptions < ITeam > ) : Promise < ITeam | null > {
return this . TeamModel . findOneByName ( teamName , options ) ;
}