correction de petites erreurs
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { Friendship } from 'src/friendship/entities/friendship.entity';
|
||||
import { FriendshipService } from 'src/friendship/friendship.service';
|
||||
import { User } from 'src/users/entities/user.entity';
|
||||
import { UsersModule } from 'src/users/users.module';
|
||||
import { UsersService } from 'src/users/users.service';
|
||||
@@ -20,7 +21,7 @@ import { SessionSerializer } from './utils/serializer';
|
||||
// }
|
||||
// })
|
||||
],
|
||||
providers: [AuthenticationService, FortyTwoStrategy, UsersService, SessionSerializer,
|
||||
providers: [AuthenticationService, FortyTwoStrategy, UsersService, SessionSerializer, FriendshipService
|
||||
// JwtStrategy
|
||||
],
|
||||
exports: [AuthenticationService],
|
||||
|
||||
@@ -26,7 +26,7 @@ export class AuthenticationService {
|
||||
let createUsersDtoWithUsername : CreateUsersDto = createUsersDto;
|
||||
while (check_name === true)
|
||||
{
|
||||
createUsersDtoWithUsername = { ...createUsersDto, username: createUsersDto.username + randomUUID() };
|
||||
createUsersDtoWithUsername = { ...createUsersDto, username: createUsersDto.username + randomUUID() };
|
||||
check_name = await this.userService.isUsernameExists(createUsersDtoWithUsername.username);
|
||||
}
|
||||
return this.userService.create(createUsersDtoWithUsername);
|
||||
|
||||
@@ -117,4 +117,16 @@ export class FriendshipService {
|
||||
throw new HttpException(`Your friend could not be deleted.`, HttpStatus.NOT_FOUND);
|
||||
return this.friendshipRepository.remove(friendship);
|
||||
}
|
||||
|
||||
async findIfUserIsBlockedOrHasBlocked(userConnectedId: string, userToCheckId: string) {
|
||||
const friendship = await this.friendshipRepository
|
||||
.createQueryBuilder('friendship')
|
||||
.where('friendship.requesterId = :requestee', { requestee: userConnectedId })
|
||||
.orWhere('friendship.requesterId = :requesteeBis', { requesteeBis: userToCheckId })
|
||||
.andWhere('friendship.status = :status', { status: FriendshipStatus.BLOCKED })
|
||||
.getOne();
|
||||
if (friendship)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Exclude } from "class-transformer";
|
||||
import { IsEmail, Length } from "class-validator";
|
||||
import { Column, Entity, JoinTable, ManyToMany, OneToMany, OneToOne, PrimaryGeneratedColumn, Unique } from "typeorm";
|
||||
import { Column, Entity, JoinColumn, JoinTable, ManyToMany, OneToMany, OneToOne, PrimaryGeneratedColumn, Unique } from "typeorm";
|
||||
import { Friendship } from "../../friendship/entities/friendship.entity";
|
||||
import { UserStats } from "./userStat.entities";
|
||||
|
||||
@@ -51,7 +51,7 @@ export class User {
|
||||
@OneToMany(type => Friendship , (friendship) => friendship.addresseeId)
|
||||
addresseeId: Friendship[];
|
||||
|
||||
@JoinTable()
|
||||
@JoinColumn()
|
||||
@OneToOne(() => UserStats, { cascade: true })
|
||||
stats: UserStats;
|
||||
}
|
||||
|
||||
@@ -45,8 +45,9 @@ export class UsersController {
|
||||
@UseGuards(AuthenticateGuard)
|
||||
@UseGuards(TwoFactorGuard)
|
||||
@Get('search')
|
||||
findOneByUsername(@Query('username') username: string) {
|
||||
return this.usersService.findOneByUsername(username);
|
||||
findOneByUsername(@Query('username') username: string, @Req() req) {
|
||||
const user : User = req.user;
|
||||
return this.usersService.findOneByUsername(user.id.toString(),username);
|
||||
}
|
||||
|
||||
@UseGuards(AuthenticateGuard)
|
||||
|
||||
@@ -4,13 +4,12 @@ import { UsersController } from './users.controller';
|
||||
import { User } from './entities/user.entity';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { Friendship } from '../friendship/entities/friendship.entity';
|
||||
import { AuthenticationService } from 'src/auth/42/authentication.service';
|
||||
import { AuthenticationModule } from 'src/auth/42/authentication.module';
|
||||
import { UserStats } from './entities/userStat.entities';
|
||||
import { FriendshipService } from 'src/friendship/friendship.service';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([User, Friendship, UserStats])],
|
||||
providers: [UsersService],
|
||||
providers: [UsersService, FriendshipService],
|
||||
exports: [UsersService],
|
||||
controllers: [UsersController],
|
||||
})
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
import { HttpCode, HttpException, HttpStatus, Injectable, NotFoundException, } from '@nestjs/common';
|
||||
import { HttpException, HttpStatus, Injectable, NotFoundException, } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { NotFoundError, of } from 'rxjs';
|
||||
import { User } from './entities/user.entity';
|
||||
import { ConnectionOptionsReader, Repository } from 'typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { CreateUsersDto } from './dto/create-users.dto';
|
||||
import { UpdateUsersDto } from './dto/update-users.dto';
|
||||
import { Friendship } from '../friendship/entities/friendship.entity';
|
||||
import { isNumberString } from 'class-validator';
|
||||
import { PaginationQueryDto } from 'src/common/dto/pagination-query.dto';
|
||||
import { PartialUsersDto } from './dto/partial-users.dto';
|
||||
import { join } from 'path';
|
||||
import { UserStats } from './entities/userStat.entities';
|
||||
import { FriendshipService } from 'src/friendship/friendship.service';
|
||||
import { stringify } from 'querystring';
|
||||
|
||||
// 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.
|
||||
@@ -18,10 +16,9 @@ import { UserStats } from './entities/userStat.entities';
|
||||
export class UsersService {
|
||||
|
||||
constructor(
|
||||
private readonly friendshipService: FriendshipService,
|
||||
@InjectRepository(User)
|
||||
private readonly userRepository: Repository<User>,
|
||||
@InjectRepository(Friendship)
|
||||
private readonly friendshipRepository: Repository<Friendship>,
|
||||
) {}
|
||||
|
||||
async findOneByFourtyTwoId(fortytwo_id: string) {
|
||||
@@ -36,12 +33,15 @@ export class UsersService {
|
||||
}
|
||||
|
||||
async findOne(id: string) {
|
||||
console.log(`FIND ONE USER SERVICE Find user ${id}`);
|
||||
const user = await this.userRepository.createQueryBuilder('user')
|
||||
.leftJoinAndSelect('user.stats', 'stats')
|
||||
.where('user.id = :id', { id: id })
|
||||
.where('user.id = :id', { id: +id })
|
||||
.getOne();
|
||||
if (!user)
|
||||
throw new NotFoundException(`The requested user not found.`);
|
||||
console.log(`FIND ONE USER SERVICE The requested user found.`
|
||||
+ user.stats.id + user.stats.winGame + user.stats.loseGame + user.stats.drawGame + user.stats.totalGame);
|
||||
const partialUser : Partial<User> = {
|
||||
username: user.username,
|
||||
image_url: user.image_url,
|
||||
@@ -59,13 +59,15 @@ export class UsersService {
|
||||
return true;
|
||||
}
|
||||
|
||||
async findOneByUsername(username: string) {
|
||||
const user = await this.userRepository.createQueryBuilder('user')
|
||||
async findOneByUsername(userConnectedId : string, username: string) {
|
||||
const user : User = await this.userRepository.createQueryBuilder('user')
|
||||
.leftJoinAndSelect('user.stats', 'stats')
|
||||
.where('user.username = :username', { username: username })
|
||||
.getOne();
|
||||
if (!user)
|
||||
throw new HttpException(`The user could not be found.`,HttpStatus.NOT_FOUND);
|
||||
if (this.friendshipService.findIfUserIsBlockedOrHasBlocked(userConnectedId, user.id.toString()))
|
||||
throw new HttpException(`The user could not be found.`,HttpStatus.NOT_FOUND);
|
||||
const partialUser : Partial<User> = {
|
||||
username: user.username,
|
||||
image_url: user.image_url,
|
||||
|
||||
@@ -3,12 +3,16 @@
|
||||
import { onMount } from "svelte";
|
||||
|
||||
let user = {};
|
||||
let stats = {};
|
||||
onMount (async() => {
|
||||
console.log("PROFIL SVELTE");
|
||||
const {data} = await axios.get('http://transcendance:8080/api/v2/user');
|
||||
console.log(data.username);
|
||||
console.log(data);
|
||||
user = data;
|
||||
const response = await fetch('http://transcendance:8080/api/v2/user',
|
||||
{
|
||||
method : 'GET',
|
||||
}).then(response => response.json());
|
||||
console.log(response);
|
||||
user = response;
|
||||
stats = user.stats;
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -21,6 +25,11 @@
|
||||
<h1>Profil</h1>
|
||||
<ul>
|
||||
<li>username : {user.username}</li>
|
||||
<li>stats : Win games {stats.winGame}
|
||||
Lose games {stats.loseGame}
|
||||
Draw games {stats.drawGame}
|
||||
Total games {stats.totalGame}
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user