better findAll() in user module, no pagination tho, could add but would be hella annoying
This commit is contained in:
@@ -22,9 +22,11 @@ export class UsersController {
|
|||||||
@UseGuards(AuthenticateGuard)
|
@UseGuards(AuthenticateGuard)
|
||||||
@UseGuards(TwoFactorGuard)
|
@UseGuards(TwoFactorGuard)
|
||||||
@Get('all')
|
@Get('all')
|
||||||
findAll(@Query() paginationquery : PaginationQueryDto) {
|
findAll(@Query() paginationquery : PaginationQueryDto, @Req() req) {
|
||||||
//const { limit, offset } = query;
|
//const { limit, offset } = query;
|
||||||
return this.usersService.findAll(paginationquery);
|
// not convinced i want pagination... i mean maybe for loading and such, we shall see
|
||||||
|
const user : User = req.user;
|
||||||
|
return this.usersService.findAll(paginationquery, user.id.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////
|
||||||
@@ -36,14 +38,8 @@ export class UsersController {
|
|||||||
* car un utilisateur est crée à la première connexion avec l'Oauth de 42.
|
* car un utilisateur est crée à la première connexion avec l'Oauth de 42.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// @UseGuards(AuthenticateGuard)
|
// similar to @Get('myfriends/:friendUsername') but doesn't return a friendship just returns the user profile
|
||||||
// @UseGuards(TwoFactorGuard)
|
// GET http://transcendance:8080/user?username=NomDuUser
|
||||||
// @Get()
|
|
||||||
// findOne(@Req() req) {
|
|
||||||
// console.log("Backend Getting current user");
|
|
||||||
// return this.usersService.findOne(req.user.id);
|
|
||||||
// }
|
|
||||||
|
|
||||||
@UseGuards(AuthenticateGuard)
|
@UseGuards(AuthenticateGuard)
|
||||||
@UseGuards(TwoFactorGuard)
|
@UseGuards(TwoFactorGuard)
|
||||||
@Get()
|
@Get()
|
||||||
@@ -58,23 +54,25 @@ export class UsersController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 99% sure this is useless
|
||||||
// GET http://transcendance:8080/user?username=NomDuUser
|
// GET http://transcendance:8080/user?username=NomDuUser
|
||||||
@UseGuards(AuthenticateGuard)
|
// @UseGuards(AuthenticateGuard)
|
||||||
@UseGuards(TwoFactorGuard)
|
// @UseGuards(TwoFactorGuard)
|
||||||
@Get('search')
|
// @Get('search')
|
||||||
findOneByUsername(@Query('username') username: string, @Req() req) {
|
// findOneByUsername(@Query('username') username: string, @Req() req) {
|
||||||
const user : User = req.user;
|
// const user : User = req.user;
|
||||||
console.log('searching for user' + user.username);
|
// console.log('searching for user' + user.username);
|
||||||
return this.usersService.findOneByUsername(user.id.toString(),username);
|
// return this.usersService.findOneByUsername(user.id.toString(),username);
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
// also seems useless...
|
||||||
@UseGuards(AuthenticateGuard)
|
// GET http://transcendance:8080/user/stats
|
||||||
@UseGuards(TwoFactorGuard)
|
// @UseGuards(AuthenticateGuard)
|
||||||
@Get('stats')
|
// @UseGuards(TwoFactorGuard)
|
||||||
getStats(@Req() request) {
|
// @Get('stats')
|
||||||
return this.usersService.getStats(request.user.id);
|
// getStats(@Req() request) {
|
||||||
}
|
// return this.usersService.getStats(request.user.id);
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
@UseGuards(AuthenticateGuard)
|
@UseGuards(AuthenticateGuard)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { HttpException, HttpStatus, Injectable, NotFoundException, } from '@nestjs/common';
|
import { HttpException, HttpStatus, Injectable, NotFoundException, } 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 } from 'typeorm';
|
import { Repository, Not } from 'typeorm';
|
||||||
import { CreateUsersDto } from './dto/create-users.dto';
|
import { CreateUsersDto } from './dto/create-users.dto';
|
||||||
import { UpdateUsersDto } from './dto/update-users.dto';
|
import { UpdateUsersDto } from './dto/update-users.dto';
|
||||||
import { Friendship } from '../friendship/entities/friendship.entity';
|
import { Friendship } from '../friendship/entities/friendship.entity';
|
||||||
@@ -84,15 +84,91 @@ export class UsersService {
|
|||||||
return partialUser;
|
return partialUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Example : http://localhost:3000/users?limit=10&offset=20
|
// only useful if doing Pagination i think
|
||||||
findAll(paginationquery : PaginationQueryDto) {
|
// add return type
|
||||||
const { limit, offset } = paginationquery;
|
async createPartialUsersArray(users: User[], userConnectedId: string) {
|
||||||
return this.userRepository.find({
|
let partialUsers : Partial<User>[] = [];
|
||||||
skip: offset,
|
for (const user of users) {
|
||||||
take: limit,
|
// this will sort of work but i need more like findIfUserIsBlocked so you can unblock people... maybe ?
|
||||||
});
|
// or i have a tab for all the users you have blocked... yea idk yet
|
||||||
|
// there's already a backend func in frienships for that so yea lets do that!
|
||||||
|
if (await this.friendshipService.findIfUserIsBlockedOrHasBlocked(userConnectedId, user.id.toString()) === false) {
|
||||||
|
partialUsers.push({username: user.username, image_url: user.image_url, status: user.status, stats: user.stats});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return partialUsers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// OMG I HATE ADDING PAGINATION...
|
||||||
|
// Example : http://localhost:3000/users?limit=10&offset=20
|
||||||
|
// async findAll(paginationquery : PaginationQueryDto, userConnectedId: string) {
|
||||||
|
// // const { limit, offset } = paginationquery;
|
||||||
|
// let { limit, offset } = paginationquery;
|
||||||
|
// // ok pagination only sort of works, like if
|
||||||
|
// // const users = await this.userRepository.find({skip: offset, take: limit,});
|
||||||
|
|
||||||
|
// let users;
|
||||||
|
// let partialUsers : Partial<User>[] = [];
|
||||||
|
// // let partialUsers;
|
||||||
|
|
||||||
|
// // partialUsers = await this.createPartialUsersArray(users, userConnectedId);
|
||||||
|
|
||||||
|
// // ok this is the part where i would need to be like ok if you didn't get enough users cuz at least one is blocked, then you need to find that many more and try again and prolly put that in a loop and break when you've got enough, but like i hate that
|
||||||
|
|
||||||
|
// console.log("IN users.service");
|
||||||
|
// console.log("limit: " + limit);
|
||||||
|
// console.log("offset: " + offset);
|
||||||
|
// while (1) {
|
||||||
|
// users = await this.userRepository.find({skip: offset, take: limit,});
|
||||||
|
// console.log("users.service users");
|
||||||
|
// console.log({...users});
|
||||||
|
// if (users === undefined) // i'm just guessing what the result will be... in the case we run out of users
|
||||||
|
// break;
|
||||||
|
// partialUsers = await this.createPartialUsersArray(users, userConnectedId);
|
||||||
|
// if (limit && offset) {
|
||||||
|
// offset += limit;
|
||||||
|
// limit = limit - partialUsers.length;
|
||||||
|
// console.log(limit)
|
||||||
|
// if (limit === 0)
|
||||||
|
// break;
|
||||||
|
// } else {
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// // for (const user of users) {
|
||||||
|
// // // this will sort of work but i need more like findIfUserIsBlocked so you can unblock people... maybe ?
|
||||||
|
// // // or i have a tab for all the users you have blocked... yea idk yet
|
||||||
|
// // // there's already a backend func in frienships for that so yea lets do that!
|
||||||
|
// // if (await this.friendshipService.findIfUserIsBlockedOrHasBlocked(userConnectedId, user.id.toString()) === false) {
|
||||||
|
// // partialUsers.push({username: user.username, image_url: user.image_url, status: user.status, stats: user.stats});
|
||||||
|
// // }
|
||||||
|
// // }
|
||||||
|
// return partialUsers;
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// The fuck Pagination version
|
||||||
|
async findAll(paginationquery : PaginationQueryDto, userConnectedId: string) {
|
||||||
|
const { limit, offset } = paginationquery;
|
||||||
|
const users = await this.userRepository.find({where: {id: Not(+userConnectedId)}, order: {username: "ASC"}, skip: offset, take: limit,});
|
||||||
|
|
||||||
|
let partialUsers : Partial<User>[] = [];
|
||||||
|
|
||||||
|
for (const user of users) {
|
||||||
|
if (await this.friendshipService.findIfUserIsBlockedOrHasBlocked(userConnectedId, user.id.toString()) === false) {
|
||||||
|
partialUsers.push({username: user.username, image_url: user.image_url, status: user.status, stats: user.stats});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return partialUsers;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async create(createUserDto: CreateUsersDto) {
|
async create(createUserDto: CreateUsersDto) {
|
||||||
if (await this.userRepository.findOneBy({fortyTwoId: createUserDto.fortyTwoId}))
|
if (await this.userRepository.findOneBy({fortyTwoId: createUserDto.fortyTwoId}))
|
||||||
throw new HttpException(`The user already exists.`,HttpStatus.CONFLICT);
|
throw new HttpException(`The user already exists.`,HttpStatus.CONFLICT);
|
||||||
|
|||||||
@@ -41,6 +41,8 @@
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* TMP for Testing */
|
/* TMP for Testing */
|
||||||
let cherifFetch;
|
let cherifFetch;
|
||||||
const fetchCherif = async() => {
|
const fetchCherif = async() => {
|
||||||
@@ -220,14 +222,14 @@
|
|||||||
<!-- does this work? -->
|
<!-- does this work? -->
|
||||||
<!-- {#each allUsers as aUser (aUser.username)} -->
|
<!-- {#each allUsers as aUser (aUser.username)} -->
|
||||||
{#each allUsers as aUser}
|
{#each allUsers as aUser}
|
||||||
{#if aUser.username !== user.username}
|
<!-- {#if aUser.username !== user.username} -->
|
||||||
<div class="sidebar-item" on:click={() => viewAUser(aUser.username)}>{aUser.username}</div>
|
<div class="sidebar-item" on:click={() => viewAUser(aUser.username)}>{aUser.username}</div>
|
||||||
<!-- i could make an indicator component? like green for connected or something?
|
<!-- i could make an indicator component? like green for connected or something?
|
||||||
i could use words but color them?
|
i could use words but color them?
|
||||||
i could make it so if they're in a game -->
|
i could make it so if they're in a game -->
|
||||||
<div class="status sidebar-item">{aUser.status}</div>
|
<div class="status sidebar-item">{aUser.status}</div>
|
||||||
<br>
|
<br>
|
||||||
{/if}
|
<!-- {/if} -->
|
||||||
{/each}
|
{/each}
|
||||||
{:else if activeTabItem === 'My Friends' && myFriends !== undefined}
|
{:else if activeTabItem === 'My Friends' && myFriends !== undefined}
|
||||||
<h3>{activeTabItem}</h3>
|
<h3>{activeTabItem}</h3>
|
||||||
|
|||||||
Reference in New Issue
Block a user