room update names in db
This commit is contained in:
@@ -258,5 +258,8 @@
|
|||||||
- on rooms with password
|
- on rooms with password
|
||||||
- on direct rooms
|
- on direct rooms
|
||||||
- after password is change / set / removed
|
- after password is change / set / removed
|
||||||
- [ ]
|
- [ ] join empty room
|
||||||
|
- user join empty public room
|
||||||
|
- user join empty protected room
|
||||||
|
- is admin ?
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import { FriendshipsModule } from './friendship/friendships.module';
|
|||||||
import { AuthenticationModule } from './auth/42/authentication.module';
|
import { AuthenticationModule } from './auth/42/authentication.module';
|
||||||
import { PassportModule } from '@nestjs/passport';
|
import { PassportModule } from '@nestjs/passport';
|
||||||
import { GameModule } from './game/game.module';
|
import { GameModule } from './game/game.module';
|
||||||
import { ChatGateway } from './chat/chat.gateway';
|
|
||||||
import { ChatModule } from './chat/chat.module';
|
import { ChatModule } from './chat/chat.module';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
@@ -32,7 +31,6 @@ import { ChatModule } from './chat/chat.module';
|
|||||||
synchronize: true,
|
synchronize: true,
|
||||||
}),
|
}),
|
||||||
ChatModule,
|
ChatModule,
|
||||||
// GameModule,
|
|
||||||
],
|
],
|
||||||
controllers: [AppController],
|
controllers: [AppController],
|
||||||
providers: [AppService],
|
providers: [AppService],
|
||||||
|
|||||||
@@ -9,11 +9,22 @@ import { AuthenticationController } from './authentication.controller';
|
|||||||
import { AuthenticationService } from './authentication.service';
|
import { AuthenticationService } from './authentication.service';
|
||||||
import { FortyTwoStrategy } from './strategy/42strategy';
|
import { FortyTwoStrategy } from './strategy/42strategy';
|
||||||
import { SessionSerializer } from './utils/serializer';
|
import { SessionSerializer } from './utils/serializer';
|
||||||
|
import { ChatModule } from 'src/chat/chat.module';
|
||||||
|
import { ChatService } from 'src/chat/chat.service';
|
||||||
|
import { Chatroom } from 'src/chat/entities/chatroom.entity';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [TypeOrmModule.forFeature([User, Friendship]), UsersModule,
|
imports: [TypeOrmModule.forFeature([User, Friendship, Chatroom]),
|
||||||
|
UsersModule,
|
||||||
|
ChatModule,
|
||||||
],
|
],
|
||||||
providers: [AuthenticationService, FortyTwoStrategy, UsersService, SessionSerializer, FriendshipService
|
providers: [
|
||||||
|
AuthenticationService,
|
||||||
|
FortyTwoStrategy,
|
||||||
|
UsersService,
|
||||||
|
SessionSerializer,
|
||||||
|
FriendshipService,
|
||||||
|
ChatService,
|
||||||
],
|
],
|
||||||
exports: [AuthenticationService],
|
exports: [AuthenticationService],
|
||||||
controllers: [AuthenticationController],
|
controllers: [AuthenticationController],
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ export class ChatController {
|
|||||||
|
|
||||||
let fields = ["name", "type", "users", "protection", "allowed_users"];
|
let fields = ["name", "type", "users", "protection", "allowed_users"];
|
||||||
const rooms = await this.chatService.getMyRooms(req.user.username, fields);
|
const rooms = await this.chatService.getMyRooms(req.user.username, fields);
|
||||||
|
console.log("rooms:", rooms);
|
||||||
const blocked = await this.chatService.getListBlockUser(req.user.username);
|
const blocked = await this.chatService.getListBlockUser(req.user.username);
|
||||||
|
|
||||||
let filtered_rooms = rooms.filter(room =>
|
let filtered_rooms = rooms.filter(room =>
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import { Module } from '@nestjs/common';
|
import { Module, forwardRef } from '@nestjs/common';
|
||||||
|
import { FriendshipsModule } from 'src/friendship/friendships.module';
|
||||||
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
import { ChatController } from './chat.controller';
|
import { ChatController } from './chat.controller';
|
||||||
import { ChatService } from './chat.service';
|
import { ChatService } from './chat.service';
|
||||||
import { ChatGateway } from './chat.gateway';
|
import { ChatGateway } from './chat.gateway';
|
||||||
import { UsersModule } from 'src/users/users.module';
|
import { UsersModule } from 'src/users/users.module';
|
||||||
import { FriendshipsModule } from 'src/friendship/friendships.module';
|
|
||||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
|
||||||
import { Chatroom } from './entities/chatroom.entity';
|
import { Chatroom } from './entities/chatroom.entity';
|
||||||
import { User } from 'src/users/entities/user.entity';
|
import { User } from 'src/users/entities/user.entity';
|
||||||
import { Friendship } from 'src/friendship/entities/friendship.entity';
|
import { Friendship } from 'src/friendship/entities/friendship.entity';
|
||||||
@@ -12,14 +12,13 @@ import { Friendship } from 'src/friendship/entities/friendship.entity';
|
|||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
TypeOrmModule.forFeature([Chatroom, User, Friendship]),
|
TypeOrmModule.forFeature([Chatroom, User, Friendship]),
|
||||||
UsersModule,
|
|
||||||
FriendshipsModule,
|
FriendshipsModule,
|
||||||
|
forwardRef(() => UsersModule),
|
||||||
],
|
],
|
||||||
controllers: [
|
controllers: [
|
||||||
ChatController,
|
ChatController,
|
||||||
],
|
],
|
||||||
exports: [
|
exports: [],
|
||||||
],
|
|
||||||
providers: [
|
providers: [
|
||||||
ChatService,
|
ChatService,
|
||||||
ChatGateway,
|
ChatGateway,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { HttpException, HttpStatus, Injectable, Res } from '@nestjs/common';
|
import { HttpException, HttpStatus, Injectable, Res, NotFoundException, forwardRef, Inject } from '@nestjs/common';
|
||||||
import { User } from 'src/users/entities/user.entity';
|
import { User } from 'src/users/entities/user.entity';
|
||||||
import { Friendship, FriendshipStatus } from 'src/friendship/entities/friendship.entity';
|
import { Friendship, FriendshipStatus } from 'src/friendship/entities/friendship.entity';
|
||||||
import { Chatroom } from './entities/chatroom.entity';
|
import { Chatroom } from './entities/chatroom.entity';
|
||||||
@@ -19,6 +19,7 @@ import { printCaller } from './dev/dev_utils';
|
|||||||
export class ChatService {
|
export class ChatService {
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
@Inject(forwardRef(() => UsersService))
|
||||||
private usersService: UsersService,
|
private usersService: UsersService,
|
||||||
private friendshipService: FriendshipService,
|
private friendshipService: FriendshipService,
|
||||||
@InjectRepository(User)
|
@InjectRepository(User)
|
||||||
@@ -144,6 +145,11 @@ export class ChatService {
|
|||||||
printCaller("-- in ");
|
printCaller("-- in ");
|
||||||
|
|
||||||
const user_db = await this.getUserByName(username);
|
const user_db = await this.getUserByName(username);
|
||||||
|
if (!user_db)
|
||||||
|
{
|
||||||
|
printCaller(`throw error: error: true, code: 'USER_NOT_FOUND', message: 'the user was not found'`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
printCaller("-- out ");
|
printCaller("-- out ");
|
||||||
return user_db.currentRoom;
|
return user_db.currentRoom;
|
||||||
@@ -703,10 +709,61 @@ export class ChatService {
|
|||||||
/* LAST MINUTE BAD SOLUTION *******************************
|
/* LAST MINUTE BAD SOLUTION *******************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
async changeAllUsernames(socket: socketDto, room_name: string): Promise<void>
|
async changeAllUsernames(old_name: string, new_name: string): Promise<void>
|
||||||
{
|
{
|
||||||
printCaller("-- in ");
|
printCaller("-- in ");
|
||||||
|
|
||||||
|
console.log("old_name:", old_name);
|
||||||
|
console.log("new_name:", new_name);
|
||||||
|
|
||||||
|
let rooms: Chatroom[] = await this.getAllRooms();
|
||||||
|
await rooms.forEach((room) =>
|
||||||
|
{
|
||||||
|
let room_has_change: boolean = false;
|
||||||
|
|
||||||
|
// users: string[]
|
||||||
|
room.users = room.users.map(item =>
|
||||||
|
{
|
||||||
|
if (item === old_name)
|
||||||
|
{
|
||||||
|
room_has_change = true;
|
||||||
|
return new_name
|
||||||
|
}
|
||||||
|
return item;
|
||||||
|
});
|
||||||
|
|
||||||
|
// admins: string[]
|
||||||
|
room.admins = room.admins.map(item =>
|
||||||
|
{
|
||||||
|
if (item === old_name)
|
||||||
|
{
|
||||||
|
room_has_change = true;
|
||||||
|
return new_name
|
||||||
|
}
|
||||||
|
return item;
|
||||||
|
});
|
||||||
|
|
||||||
|
// users: string[]
|
||||||
|
room.allowed_users = room.allowed_users.map(item =>
|
||||||
|
{
|
||||||
|
if (item === old_name)
|
||||||
|
{
|
||||||
|
room_has_change = true;
|
||||||
|
return new_name
|
||||||
|
}
|
||||||
|
return item;
|
||||||
|
});
|
||||||
|
|
||||||
|
// owner: string
|
||||||
|
if(room.owner === old_name)
|
||||||
|
room.owner = new_name;
|
||||||
|
|
||||||
|
if (room_has_change)
|
||||||
|
this.chatroomRepository.save(room);
|
||||||
|
this.addMessageToRoom(room.name, "SERVER", `${old_name} changes it's name for ${new_name}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
rooms = await this.getAllRooms();
|
||||||
|
|
||||||
printCaller("-- out ");
|
printCaller("-- out ");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Module } from '@nestjs/common';
|
import { Module, forwardRef } from '@nestjs/common';
|
||||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
import { Friendship } from 'src/friendship/entities/friendship.entity';
|
import { Friendship } from 'src/friendship/entities/friendship.entity';
|
||||||
import { FriendshipService } from 'src/friendship/friendship.service';
|
import { FriendshipService } from 'src/friendship/friendship.service';
|
||||||
@@ -8,10 +8,21 @@ import { Game } from './entity/game.entity';
|
|||||||
import { TokenGame } from './entity/tokenGame.entity';
|
import { TokenGame } from './entity/tokenGame.entity';
|
||||||
import { GameController } from './game.controller';
|
import { GameController } from './game.controller';
|
||||||
import { GameService } from './game.service';
|
import { GameService } from './game.service';
|
||||||
|
import { ChatModule } from 'src/chat/chat.module';
|
||||||
|
import { ChatService } from 'src/chat/chat.service';
|
||||||
|
import { Chatroom } from 'src/chat/entities/chatroom.entity';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [TypeOrmModule.forFeature([TokenGame, User, Game, Friendship])],
|
imports: [
|
||||||
|
TypeOrmModule.forFeature([TokenGame, User, Game, Friendship, Chatroom]),
|
||||||
|
ChatModule,
|
||||||
|
],
|
||||||
controllers: [GameController],
|
controllers: [GameController],
|
||||||
providers: [GameService, UsersService, FriendshipService]
|
providers: [
|
||||||
|
GameService,
|
||||||
|
UsersService,
|
||||||
|
FriendshipService,
|
||||||
|
ChatService,
|
||||||
|
]
|
||||||
})
|
})
|
||||||
export class GameModule {}
|
export class GameModule {}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Module } from '@nestjs/common';
|
import { Module, forwardRef } from '@nestjs/common';
|
||||||
import { UsersService } from './users.service';
|
import { UsersService } from './users.service';
|
||||||
import { UsersController } from './users.controller';
|
import { UsersController } from './users.controller';
|
||||||
import { User } from './entities/user.entity';
|
import { User } from './entities/user.entity';
|
||||||
@@ -6,10 +6,16 @@ import { TypeOrmModule } from '@nestjs/typeorm';
|
|||||||
import { Friendship } from '../friendship/entities/friendship.entity';
|
import { Friendship } from '../friendship/entities/friendship.entity';
|
||||||
import { UserStats } from './entities/userStat.entities';
|
import { UserStats } from './entities/userStat.entities';
|
||||||
import { FriendshipService } from 'src/friendship/friendship.service';
|
import { FriendshipService } from 'src/friendship/friendship.service';
|
||||||
|
import { ChatModule } from 'src/chat/chat.module';
|
||||||
|
import { ChatService } from 'src/chat/chat.service';
|
||||||
|
import { Chatroom } from 'src/chat/entities/chatroom.entity';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [TypeOrmModule.forFeature([User, Friendship, UserStats])],
|
imports: [
|
||||||
providers: [UsersService, FriendshipService],
|
TypeOrmModule.forFeature([User, Friendship, UserStats, Chatroom]),
|
||||||
|
forwardRef(() => ChatModule),
|
||||||
|
],
|
||||||
|
providers: [UsersService, FriendshipService, ChatService],
|
||||||
exports: [UsersService],
|
exports: [UsersService],
|
||||||
controllers: [UsersController],
|
controllers: [UsersController],
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { HttpException, HttpStatus, Injectable, NotFoundException, } from '@nestjs/common';
|
import { HttpException, HttpStatus, Injectable, NotFoundException, forwardRef, Inject } from '@nestjs/common';
|
||||||
import { InjectRepository } from '@nestjs/typeorm';
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
import { User } from './entities/user.entity';
|
import { User } from './entities/user.entity';
|
||||||
import { Repository, Not } from 'typeorm';
|
import { Repository, Not } from 'typeorm';
|
||||||
@@ -7,12 +7,15 @@ import { UpdateUsersDto } from './dto/update-users.dto';
|
|||||||
import { PaginationQueryDto } from 'src/common/dto/pagination-query.dto';
|
import { PaginationQueryDto } from 'src/common/dto/pagination-query.dto';
|
||||||
import { UserStats } from './entities/userStat.entities';
|
import { UserStats } from './entities/userStat.entities';
|
||||||
import { FriendshipService } from 'src/friendship/friendship.service';
|
import { FriendshipService } from 'src/friendship/friendship.service';
|
||||||
|
import { ChatService } from 'src/chat/chat.service';
|
||||||
// On va devoir sûrement trouver un moyen plus simple pour passer l'id, sûrement via des pipes
|
// On va devoir sûrement trouver un moyen plus simple pour passer l'id, sûrement via des pipes
|
||||||
// ou des interceptors, mais pour l'instant on va faire comme ça.
|
// ou des interceptors, mais pour l'instant on va faire comme ça.
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class UsersService {
|
export class UsersService {
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
@Inject(forwardRef(() => ChatService))
|
||||||
|
private chatService: ChatService,
|
||||||
private readonly friendshipService: FriendshipService,
|
private readonly friendshipService: FriendshipService,
|
||||||
@InjectRepository(User)
|
@InjectRepository(User)
|
||||||
private readonly userRepository: Repository<User>,
|
private readonly userRepository: Repository<User>,
|
||||||
@@ -110,7 +113,8 @@ export class UsersService {
|
|||||||
if (!user)
|
if (!user)
|
||||||
throw new HttpException(`The user could not be updated.`,HttpStatus.NOT_FOUND);
|
throw new HttpException(`The user could not be updated.`,HttpStatus.NOT_FOUND);
|
||||||
this.userRepository.save(user);
|
this.userRepository.save(user);
|
||||||
|
// here goes the horrible bandage from hugo
|
||||||
|
this.chatService.changeAllUsernames(username, updateUserDto.username);
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user