ok so i'm changing the Friendship and User modules in the back, and i've already started changing entites and DTO's so i'm saving now...
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
import { IsEnum, IsNotEmpty, IsString } from 'class-validator';
|
||||
import { IsEnum, IsNotEmpty, IsString, IsPositive } from 'class-validator';
|
||||
import { FriendshipStatus } from '../entities/friendship.entity';
|
||||
|
||||
export class CreateFriendshipDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
readonly receiverUsername: string;
|
||||
// @IsNotEmpty()
|
||||
@IsPositive()
|
||||
// @Max(1000) ?
|
||||
readonly receiverId: number;
|
||||
@IsEnum(FriendshipStatus)
|
||||
readonly status: FriendshipStatus;
|
||||
}
|
||||
|
||||
@@ -27,7 +27,10 @@ export class Friendship {
|
||||
senderUsername : string;
|
||||
|
||||
@Column()
|
||||
receiverUsername : string;
|
||||
senderId : number;
|
||||
|
||||
@Column()
|
||||
receiverId : number;
|
||||
|
||||
@Column({ type: 'enum', enum: FriendshipStatus, default: FriendshipStatus.REQUESTED})
|
||||
status: FriendshipStatus;
|
||||
|
||||
@@ -9,42 +9,48 @@ export class FriendshipController {
|
||||
constructor(private readonly friendshipService: FriendshipService) { }
|
||||
|
||||
// GET http://transcendance:8080/api/v2/network/myfriends
|
||||
@Get('myfriends')
|
||||
// @Get('myfriends')
|
||||
// @UseGuards(AuthenticateGuard)
|
||||
// @UseGuards(TwoFactorGuard)
|
||||
// findEmpty(@Req() req) {
|
||||
// const user = req.user;
|
||||
// console.log('GET myfriends')
|
||||
// return this.friendshipService.findAllFriends(user.id);
|
||||
// }
|
||||
|
||||
// @Query('username') username: string,
|
||||
|
||||
// new and improved finder of people
|
||||
// GET http://transcendance:8080/api/v2/network/:friendUsername
|
||||
@Get('findfriends')
|
||||
@UseGuards(AuthenticateGuard)
|
||||
@UseGuards(TwoFactorGuard)
|
||||
findEmpty(@Req() req) {
|
||||
findOne(@Query('username') otherUsername: string, @Query('id') id: string, @Req() req) {
|
||||
console.log('GET myfriend')
|
||||
const user = req.user;
|
||||
console.log('GET myfriends')
|
||||
if (id !== undefined) {
|
||||
return this.friendshipService.findOneRelationshipById(id, user.id)
|
||||
} else if (otherUsername !== undefined) {
|
||||
return this.friendshipService.findOneRelationshipByUsername(otherUsername, user.username);
|
||||
}
|
||||
// might change this
|
||||
return this.friendshipService.findAllFriends(user.id);
|
||||
// return this.friendshipService.findOneRelationshipByUsername(friendUsername, user.username);
|
||||
}
|
||||
|
||||
|
||||
// GET http://transcendance:8080/api/v2/network/:friendUsername
|
||||
@Get('myfriends/:friendUsername')
|
||||
@UseGuards(AuthenticateGuard)
|
||||
@UseGuards(TwoFactorGuard)
|
||||
findOneRelationByUsername(@Param('friendUsername') friendUsername : string, @Req() req) {
|
||||
console.log('GET myfriend')
|
||||
console.log(friendUsername);
|
||||
const user = req.user;
|
||||
return this.friendshipService.findOneRelationshipByUsername(friendUsername, user.username);
|
||||
}
|
||||
// @Get('myfriends/:friendUsername')
|
||||
// @UseGuards(AuthenticateGuard)
|
||||
// @UseGuards(TwoFactorGuard)
|
||||
// findOneRelationByUsername(@Param('friendUsername') friendUsername : string, @Req() req) {
|
||||
// console.log('GET myfriend')
|
||||
// console.log(friendUsername);
|
||||
// const user = req.user;
|
||||
// return this.friendshipService.findOneRelationshipByUsername(friendUsername, user.username);
|
||||
// }
|
||||
|
||||
// GET http://transcendance:8080/api/v2/network/blocked
|
||||
@Get('blocked')
|
||||
@UseGuards(AuthenticateGuard)
|
||||
@UseGuards(TwoFactorGuard)
|
||||
findAllBlocked(@Req() req) {
|
||||
const user = req.user;
|
||||
return this.friendshipService.findAllBlockedFriends(user.username);
|
||||
}
|
||||
|
||||
@Get('blocked/:relationshipId')
|
||||
@UseGuards(AuthenticateGuard)
|
||||
@UseGuards(TwoFactorGuard)
|
||||
findOneBlocked(@Param('relationshipId') relationshipId: string, @Req() req) {
|
||||
const user = req.user;
|
||||
return this.friendshipService.findOneBlocked(relationshipId, user.username);
|
||||
}
|
||||
|
||||
// POST http://transcendance:8080/api/v2/network/myfriends
|
||||
@Post('myfriends')
|
||||
@@ -53,7 +59,7 @@ export class FriendshipController {
|
||||
@UseGuards(TwoFactorGuard)
|
||||
create(@Body() createFriendshipDto: CreateFriendshipDto, @Req() req) {
|
||||
const user = req.user;
|
||||
if (user.username !== createFriendshipDto.receiverUsername)
|
||||
if (user.id !== createFriendshipDto.receiverId)
|
||||
return this.friendshipService.create(createFriendshipDto, user);
|
||||
return new HttpException('You can\'t request a frienship to yourself', HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
@@ -110,4 +116,24 @@ export class FriendshipController {
|
||||
const user = req.user;
|
||||
return this.friendshipService.findAllReceivedRequestsForFriendship(user.username);
|
||||
}
|
||||
|
||||
// GET http://transcendance:8080/api/v2/network/blocked
|
||||
@Get('blocked')
|
||||
@UseGuards(AuthenticateGuard)
|
||||
@UseGuards(TwoFactorGuard)
|
||||
findBlocked(@Query('relationshipId') relationshipId: string, @Req() req) {
|
||||
const user = req.user;
|
||||
if (relationshipId === undefined)
|
||||
return this.friendshipService.findAllBlockedFriends(user.id);
|
||||
else
|
||||
return this.friendshipService.findOneBlocked(relationshipId, user.id);
|
||||
}
|
||||
|
||||
// @Get('blocked/:relationshipId')
|
||||
// @UseGuards(AuthenticateGuard)
|
||||
// @UseGuards(TwoFactorGuard)
|
||||
// findOneBlocked(@Param('relationshipId') relationshipId: string, @Req() req) {
|
||||
// const user = req.user;
|
||||
// return this.friendshipService.findOneBlocked(relationshipId, user.username);
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -15,60 +15,24 @@ export class FriendshipService {
|
||||
private readonly userRepository: Repository<User>,
|
||||
) { }
|
||||
|
||||
// old, only Accept and Request but not Decline or Block
|
||||
// async findOneFriendByUsername(friendUsername : string, username : string) {
|
||||
// const friendship = await this.friendshipRepository
|
||||
// .createQueryBuilder('friendship')
|
||||
// .where(
|
||||
// new Brackets((qb) => {
|
||||
// qb.where(
|
||||
// new Brackets((subAQb) => {
|
||||
// subAQb.where('friendship.senderUsername = :username', {username : username})
|
||||
// .andWhere('friendship.receiverUsername = :friendUsername', {friendUsername : friendUsername})
|
||||
// })
|
||||
// )
|
||||
// .orWhere(
|
||||
// new Brackets((subBQb) => {
|
||||
// subBQb.where('friendship.senderUsername = :friendUsername', {friendUsername : friendUsername})
|
||||
// .andWhere('friendship.receiverUsername = :username', {username : username})
|
||||
// })
|
||||
// )
|
||||
// }),
|
||||
// )
|
||||
// .andWhere(
|
||||
// new Brackets((qb2) => {
|
||||
// qb2.where('friendship.status = :statusA', {statusA : FriendshipStatus.ACCEPTED})
|
||||
// .orWhere('friendship.status = :statusR', {statusR : FriendshipStatus.REQUESTED})
|
||||
// }),
|
||||
// )
|
||||
// .getOne()
|
||||
|
||||
// // console.log('END Find one friend by username: ')
|
||||
// // console.log({...friendship})
|
||||
|
||||
// if (!friendship) {
|
||||
// throw new HttpException(`There is no such friendship`, HttpStatus.NOT_FOUND);
|
||||
// }
|
||||
// return friendship;
|
||||
// }
|
||||
|
||||
// should i be using UserID rather than Username???? i mean prolly...
|
||||
|
||||
async findOneRelationshipByUsername(friendUsername : string, username : string) {
|
||||
async findOneRelationshipById(friendId : string, userId : string) {
|
||||
const friendship = await this.friendshipRepository
|
||||
.createQueryBuilder('friendship')
|
||||
.leftJoinAndSelect('friendship.sender', 'sender')
|
||||
.leftJoinAndSelect('friendship.receiver', 'receiver')
|
||||
.where(
|
||||
new Brackets((qb) => {
|
||||
qb.where(
|
||||
new Brackets((subAQb) => {
|
||||
subAQb.where('friendship.senderUsername = :username', {username : username})
|
||||
.andWhere('friendship.receiverUsername = :friendUsername', {friendUsername : friendUsername})
|
||||
subAQb.where('sender.id = :userId', { userId : userId})
|
||||
.andWhere('receiver.id = :friendId', {friendId : friendId})
|
||||
})
|
||||
)
|
||||
.orWhere(
|
||||
new Brackets((subBQb) => {
|
||||
subBQb.where('friendship.senderUsername = :friendUsername', {friendUsername : friendUsername})
|
||||
.andWhere('friendship.receiverUsername = :username', {username : username})
|
||||
subBQb.where('sender.id = :friendId', {friendId : friendId})
|
||||
.andWhere('receiver.id = :userId', {userId : userId})
|
||||
})
|
||||
)
|
||||
}),
|
||||
@@ -76,8 +40,8 @@ export class FriendshipService {
|
||||
.andWhere('friendship.status != :status', {status : FriendshipStatus.BLOCKED})
|
||||
.getOne()
|
||||
|
||||
// console.log('END Find one friend by username: ')
|
||||
// console.log({...friendship})
|
||||
console.log('END Find one friend by username: ')
|
||||
console.log({...friendship})
|
||||
|
||||
if (!friendship) {
|
||||
throw new HttpException(`There is no such friendship`, HttpStatus.NOT_FOUND);
|
||||
@@ -85,6 +49,54 @@ export class FriendshipService {
|
||||
return friendship;
|
||||
}
|
||||
|
||||
// basically useless now
|
||||
async findOneRelationshipByUsername(friendUsername : string, username : string) {
|
||||
// This seems to work, finding friendships by username but checking the actual users not the friendship
|
||||
const friendship = await this.friendshipRepository
|
||||
.createQueryBuilder('friendship')
|
||||
.leftJoinAndSelect('friendship.sender', 'sender')
|
||||
.leftJoinAndSelect('friendship.receiver', 'receiver')
|
||||
.where(
|
||||
new Brackets((qb) => {
|
||||
qb.where(
|
||||
new Brackets((subAQb) => {
|
||||
subAQb.where('sender.username = :username', {username : username})
|
||||
.andWhere('receiver.username = :friendUsername', {friendUsername : friendUsername})
|
||||
})
|
||||
)
|
||||
.orWhere(
|
||||
new Brackets((subBQb) => {
|
||||
subBQb.where('sender.username = :friendUsername', {friendUsername : friendUsername})
|
||||
.andWhere('receiver.username = :username', {username : username})
|
||||
})
|
||||
)
|
||||
}),
|
||||
)
|
||||
.andWhere('friendship.status != :status', {status : FriendshipStatus.BLOCKED})
|
||||
.getOne()
|
||||
|
||||
console.log('END Find one friend by username: ')
|
||||
console.log({...friendship})
|
||||
|
||||
if (!friendship) {
|
||||
throw new HttpException(`There is no such friendship`, HttpStatus.NOT_FOUND);
|
||||
}
|
||||
return friendship;
|
||||
}
|
||||
|
||||
async findAllFriends(username: string) {
|
||||
const friendship = await this.friendshipRepository
|
||||
.createQueryBuilder('friendship')
|
||||
.where('friendship.status = :status', { status: FriendshipStatus.ACCEPTED })
|
||||
.andWhere('friendship.receiverUsername = :addressee', { addressee: username })
|
||||
.orWhere('friendship.senderUsername = :requester', { requester: username })
|
||||
.andWhere('friendship.status = :status', { status: FriendshipStatus.ACCEPTED })
|
||||
.getMany();
|
||||
// for (const friend of friendship)
|
||||
// console.log("FRIENDSHIP : " + friend.status);
|
||||
return friendship;
|
||||
}
|
||||
|
||||
async findOneBlocked(friendshipId: string, username: string) {
|
||||
const friendship = await this.friendshipRepository.find({ where: { id: +friendshipId, senderUsername: username, status: FriendshipStatus.BLOCKED } });
|
||||
if (!friendship)
|
||||
@@ -105,19 +117,6 @@ export class FriendshipService {
|
||||
return friendship;
|
||||
}
|
||||
|
||||
async findAllFriends(username: string) {
|
||||
const friendship = await this.friendshipRepository
|
||||
.createQueryBuilder('friendship')
|
||||
.where('friendship.status = :status', { status: FriendshipStatus.ACCEPTED })
|
||||
.andWhere('friendship.receiverUsername = :addressee', { addressee: username })
|
||||
.orWhere('friendship.senderUsername = :requester', { requester: username })
|
||||
.andWhere('friendship.status = :status', { status: FriendshipStatus.ACCEPTED })
|
||||
.getMany();
|
||||
// for (const friend of friendship)
|
||||
// console.log("FRIENDSHIP : " + friend.status);
|
||||
return friendship;
|
||||
}
|
||||
|
||||
async findAllBlockedFriends(username: string) {
|
||||
const friendships : Friendship[] = await this.friendshipRepository
|
||||
.createQueryBuilder('friendship')
|
||||
@@ -166,7 +165,7 @@ export class FriendshipService {
|
||||
async create(createFriendshipDto: CreateFriendshipDto, creator : User) : Promise <Partial<Friendship>> {
|
||||
console.log("DTO : \n")
|
||||
console.log({...createFriendshipDto})
|
||||
const receiver = await this.userRepository.findOneBy({username: createFriendshipDto.receiverUsername});
|
||||
const receiver = await this.userRepository.findOneBy({id: createFriendshipDto.receiverId});
|
||||
if (!receiver)
|
||||
throw new HttpException(`The addressee does not exist.`, HttpStatus.NOT_FOUND);
|
||||
if (createFriendshipDto.status !== FriendshipStatus.REQUESTED && createFriendshipDto.status !== FriendshipStatus.BLOCKED)
|
||||
@@ -198,6 +197,7 @@ export class FriendshipService {
|
||||
id : (await savedFriendship).id,
|
||||
date : (await savedFriendship).date,
|
||||
receiverUsername: (await savedFriendship).receiverUsername,
|
||||
// receiverId: (await savedFriendship).receiver.id,
|
||||
status : (await savedFriendship).status
|
||||
}
|
||||
console.log('friendship.service create friendship, partial friendship')
|
||||
@@ -311,49 +311,34 @@ export class FriendshipService {
|
||||
console.log("finding if user is blocked")
|
||||
console.log('user connected: ' + userConnectedId)
|
||||
console.log('user to find: ' + userToFindId)
|
||||
// const friendship = await this.friendshipRepository
|
||||
// .createQueryBuilder('friendship')
|
||||
// .where('friendship.senderUsername = :requestee', { requestee: userConnectedId })
|
||||
// .orWhere('friendship.senderUsername = :requesteeBis', { requesteeBis: userToFindId })
|
||||
// .andWhere('friendship.status = :status', { status: FriendshipStatus.BLOCKED })
|
||||
// .getOne();
|
||||
|
||||
|
||||
// const friendship = await this.friendshipRepository
|
||||
// .createQueryBuilder('friendship')
|
||||
// .where(
|
||||
// new Brackets((qb) => {
|
||||
// qb.where('friendship.senderUsername = :requestee', { requestee: userConnectedId })
|
||||
// .orWhere('friendship.receiverUsername = :requesteeBis', { requesteeBis: userToFindId })
|
||||
// }),
|
||||
// )
|
||||
// .andWhere('friendship.status = :status', { status: FriendshipStatus.BLOCKED })
|
||||
// .getOne();
|
||||
|
||||
|
||||
const friendship = await this.friendshipRepository
|
||||
.createQueryBuilder('friendship')
|
||||
.leftJoinAndSelect('friendship.sender', 'sender')
|
||||
.leftJoinAndSelect('friendship.receiver', 'receiver')
|
||||
.where(
|
||||
new Brackets((qb) => {
|
||||
qb.where(
|
||||
new Brackets((subAQb) => {
|
||||
subAQb.where('friendship.senderUsername = :username', {username : userConnectedId})
|
||||
.andWhere('friendship.receiverUsername = :friendUsername', {friendUsername : userToFindId})
|
||||
subAQb.where('sender.id = :senderId', { senderId: userConnectedId})
|
||||
.andWhere('receiver.id = :receiverId', { receiverId: userToFindId})
|
||||
})
|
||||
)
|
||||
.orWhere(
|
||||
new Brackets((subBQb) => {
|
||||
subBQb.where('friendship.senderUsername = :friendUsername', {friendUsername : userToFindId})
|
||||
.andWhere('friendship.receiverUsername = :username', {username : userConnectedId})
|
||||
subBQb.where('sender.id = :senderId', {senderId : userToFindId})
|
||||
.andWhere('receiver.id = :receiverId', {receiverUsername : userConnectedId})
|
||||
})
|
||||
)
|
||||
}),
|
||||
)
|
||||
// .andWhere('friendship.status = :status', {status : FriendshipStatus.BLOCKED})
|
||||
.andWhere('friendship.status = :status', {status : FriendshipStatus.BLOCKED})
|
||||
.getOne()
|
||||
|
||||
|
||||
console.log('printing friendship queried')
|
||||
console.log({...friendship})
|
||||
|
||||
// console.log('printing friendship queried')
|
||||
// console.log({...friendship})
|
||||
if (friendship) {
|
||||
console.log('we are blocked in friendship.service')
|
||||
return true;
|
||||
@@ -362,3 +347,7 @@ export class FriendshipService {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// SELECT "friendship"."id" AS "friendship_id", "friendship"."date" AS "friendship_date", "friendship"."senderUsername" AS "friendship_senderUsername", "friendship"."receiverUsername" AS "friendship_receiverUsername", "friendship"."status" AS "friendship_status", "friendship"."senderId" AS "friendship_senderId", "friendship"."receiverId" AS "friendship_receiverId", "sender"."id" AS "sender_id", "sender"."fortyTwoId" AS "sender_fortyTwoId", "sender"."username" AS "sender_username", "sender"."email" AS "sender_email", "sender"."image_url" AS "sender_image_url", "sender"."phone" AS "sender_phone", "sender"."status" AS "sender_status", "sender"."isEnabledTwoFactorAuth" AS "sender_isEnabledTwoFactorAuth", "sender"."isTwoFactorAuthenticated" AS "sender_isTwoFactorAuthenticated", "sender"."secretTwoFactorAuth" AS "sender_secretTwoFactorAuth", "sender"."statsId" AS "sender_statsId", "receiver"."id" AS "receiver_id", "receiver"."fortyTwoId" AS "receiver_fortyTwoId", "receiver"."username" AS "receiver_username", "receiver"."email" AS "receiver_email", "receiver"."image_url" AS "receiver_image_url", "receiver"."phone" AS "receiver_phone", "receiver"."status" AS "receiver_status", "receiver"."isEnabledTwoFactorAuth" AS "receiver_isEnabledTwoFactorAuth", "receiver"."isTwoFactorAuthenticated" AS "receiver_isTwoFactorAuthenticated", "receiver"."secretTwoFactorAuth" AS "receiver_secretTwoFactorAuth", "receiver"."statsId" AS "receiver_statsId" FROM "friendships" "friendship" LEFT JOIN "user" "sender" ON "sender"."id"="friendship"."senderId" LEFT JOIN "user" "receiver" ON "receiver"."id"="friendship"."receiverId" WHERE (("sender"."id" = $1 AND "receiver"."id" = :receiverId) OR ("sender"."id" = $2 AND "receiver"."id" = :receiverId)) AND "friendship"."status" = $3
|
||||
@@ -22,11 +22,13 @@ export class UsersController {
|
||||
@UseGuards(AuthenticateGuard)
|
||||
@UseGuards(TwoFactorGuard)
|
||||
@Get('all')
|
||||
findAll(@Query() paginationquery : PaginationQueryDto, @Req() req) {
|
||||
findAll(@Req() req) {
|
||||
// findAll(@Query() paginationquery : PaginationQueryDto, @Req() req) {
|
||||
//const { limit, offset } = query;
|
||||
// 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());
|
||||
// return this.usersService.findAll(paginationquery, user);
|
||||
return this.usersService.findAll(user);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
|
||||
@@ -40,7 +40,7 @@ export class UsersService {
|
||||
.getOne();
|
||||
if (!user)
|
||||
throw new NotFoundException(`The requested user not found.`);
|
||||
console.log(`FIND ONE USER SERVICE The requested user found.` + user.username
|
||||
console.log(`FIND ONE USER SERVICE The requested user found. ` + user.username + " "
|
||||
+ user.stats.id + user.stats.winGame + user.stats.loseGame + user.stats.drawGame + user.stats.totalGame);
|
||||
const partialUser : Partial<User> = {
|
||||
username: user.username,
|
||||
@@ -84,88 +84,24 @@ export class UsersService {
|
||||
return partialUser;
|
||||
}
|
||||
|
||||
// only useful if doing Pagination i think
|
||||
// add return type
|
||||
async createPartialUsersArray(users: User[], userConnectedId: string) {
|
||||
let partialUsers : Partial<User>[] = [];
|
||||
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;
|
||||
}
|
||||
|
||||
// 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 otherUsers = await this.userRepository.find({where: {id: Not(+userConnectedId)}, order: {username: "ASC"}, skip: offset, take: limit,});
|
||||
// fuck pagination Query
|
||||
// async findAll(paginationquery : PaginationQueryDto, currentUser: User) {
|
||||
async findAll(currentUser: User) {
|
||||
// const { limit, offset } = paginationquery;
|
||||
// const otherUsers = await this.userRepository.find({where: {id: Not(+currentUser.id)}, order: {username: "ASC"}, skip: offset, take: limit,});
|
||||
const otherUsers = await this.userRepository.find({where: {id: Not(+currentUser.id)}, order: {username: "ASC"}});
|
||||
|
||||
let partialUsers : Partial<User>[] = [];
|
||||
|
||||
for (const otherUser of otherUsers) {
|
||||
let tmp = await this.friendshipService.findIfUserIsBlockedOrHasBlocked(userConnectedId, otherUser.id.toString());
|
||||
console.log('user.services findIF Blocked... : ')
|
||||
console.log(tmp)
|
||||
// if (await this.friendshipService.findIfUserIsBlockedOrHasBlocked(userConnectedId, user.id.toString()) === false) {
|
||||
if (tmp === false) {
|
||||
partialUsers.push({username: otherUser.username, image_url: otherUser.image_url, status: otherUser.status, stats: otherUser.stats});
|
||||
// console.log('other user: ')
|
||||
// console.log({...otherUser})
|
||||
// let tmp = await this.friendshipService.findIfUserIsBlockedOrHasBlocked(user.username, otherUser.username);
|
||||
// console.log('user.services findIF Blocked... : ')
|
||||
// console.log(tmp)
|
||||
// if (tmp === false) {
|
||||
if (await this.friendshipService.findIfUserIsBlockedOrHasBlocked(currentUser.id.toString(), otherUser.id.toString()) === false) {
|
||||
partialUsers.push({id: otherUser.id, username: otherUser.username, image_url: otherUser.image_url, status: otherUser.status, stats: otherUser.stats});
|
||||
}
|
||||
}
|
||||
console.log('user.services findAll, partialUsers:')
|
||||
|
||||
Reference in New Issue
Block a user