ok changing everything again, decided to simplify the Friendship.entity, so i made a class that returns the stuff we need from a Friendship
This commit is contained in:
@@ -5,9 +5,9 @@ export class CreateFriendshipDto {
|
||||
@IsPositive()
|
||||
// @Max(1000) ?
|
||||
readonly receiverId: number;
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
readonly receiverUsername: string;
|
||||
// @IsNotEmpty()
|
||||
// @IsString()
|
||||
// readonly receiverUsername: string;
|
||||
@IsEnum(FriendshipStatus)
|
||||
readonly status: FriendshipStatus;
|
||||
}
|
||||
|
||||
@@ -27,15 +27,15 @@ export class Friendship {
|
||||
|
||||
// ok so the username is still here because i think it might be useful for the frontend to have access to it, but really all i need is the ID's
|
||||
// since i have the ID's do i even need the User ?
|
||||
@Column()
|
||||
senderUsername : string;
|
||||
@Column()
|
||||
senderId : number;
|
||||
// @Column()
|
||||
// senderUsername : string;
|
||||
// @Column()
|
||||
// senderId : number;
|
||||
|
||||
@Column()
|
||||
receiverUsername : string;
|
||||
@Column()
|
||||
receiverId : number;
|
||||
// @Column()
|
||||
// receiverUsername : string;
|
||||
// @Column()
|
||||
// receiverId : number;
|
||||
|
||||
@Column({ type: 'enum', enum: FriendshipStatus, default: FriendshipStatus.REQUESTED})
|
||||
status: FriendshipStatus;
|
||||
|
||||
@@ -21,8 +21,8 @@ export class FriendshipController {
|
||||
// @Query('username') username: string,
|
||||
|
||||
// new and improved finder of people
|
||||
// GET http://transcendance:8080/api/v2/network/:friendUsername
|
||||
@Get('findfriends')
|
||||
// GET http://transcendance:8080/api/v2/network/myfriends
|
||||
@Get('myfriends')
|
||||
@UseGuards(AuthenticateGuard)
|
||||
@UseGuards(TwoFactorGuard)
|
||||
findOne(@Query('username') otherUsername: string, @Query('id') id: number, @Req() req) {
|
||||
@@ -52,8 +52,8 @@ export class FriendshipController {
|
||||
|
||||
|
||||
|
||||
// POST http://transcendance:8080/api/v2/network/myfriends
|
||||
@Post('myfriends')
|
||||
// POST http://transcendance:8080/api/v2/network/relations
|
||||
@Post('relations')
|
||||
@HttpCode(HttpStatus.CREATED)
|
||||
@UseGuards(AuthenticateGuard)
|
||||
@UseGuards(TwoFactorGuard)
|
||||
@@ -64,8 +64,8 @@ export class FriendshipController {
|
||||
return new HttpException('You can\'t request a frienship to yourself', HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
// PATCH http://transcendance:8080/api/v2/network/myfriends/relationshipId/accept
|
||||
@Patch('myfriends/:relationshipId/accept')
|
||||
// PATCH http://transcendance:8080/api/v2/network/relations/:relationshipId/accept
|
||||
@Patch('relations/:relationshipId/accept')
|
||||
@UseGuards(AuthenticateGuard)
|
||||
@UseGuards(TwoFactorGuard)
|
||||
updateAccept(@Param('relationshipId') relationshipId: number, @Req() req) {
|
||||
@@ -73,7 +73,8 @@ export class FriendshipController {
|
||||
return this.friendshipService.acceptFriendship(relationshipId, user);
|
||||
}
|
||||
|
||||
@Patch('myfriends/:relationshipId/decline')
|
||||
// PATCH http://transcendance:8080/api/v2/network/relations/:relationshipId/decline
|
||||
@Patch('relations/:relationshipId/decline')
|
||||
@UseGuards(AuthenticateGuard)
|
||||
@UseGuards(TwoFactorGuard)
|
||||
updateDecline(@Param('relationshipId') relationshipId: number, @Req() req) {
|
||||
@@ -81,7 +82,8 @@ export class FriendshipController {
|
||||
return this.friendshipService.declineFriendship(relationshipId, user);
|
||||
}
|
||||
|
||||
@Patch('myfriends/:relationshipId/block')
|
||||
// PATCH http://transcendance:8080/api/v2/network/relations/:relationshipId/block
|
||||
@Patch('relations/:relationshipId/block')
|
||||
@UseGuards(AuthenticateGuard)
|
||||
@UseGuards(TwoFactorGuard)
|
||||
updateBlock(@Param('relationshipId') relationshipId: number, @Req() req) {
|
||||
@@ -89,8 +91,8 @@ export class FriendshipController {
|
||||
return this.friendshipService.blockFriendship(relationshipId, user);
|
||||
}
|
||||
|
||||
// DELETE http://transcendance:8080/api/v2/network/myfriends/relationshipId
|
||||
@Delete('myfriends/:relationshipId')
|
||||
// DELETE http://transcendance:8080/api/v2/network/relations/:relationshipId
|
||||
@Delete('relations/:relationshipId')
|
||||
@UseGuards(AuthenticateGuard)
|
||||
@UseGuards(TwoFactorGuard)
|
||||
remove(@Param('relationshipId') relationshipId: number, @Req() req) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import { User } from 'src/users/entities/user.entity';
|
||||
import { Repository, Brackets } from 'typeorm';
|
||||
import { CreateFriendshipDto } from './dto/create-friendship.dto';
|
||||
import { Friendship, FriendshipStatus } from './entities/friendship.entity';
|
||||
import { SendableFriendship } from './sendableFriendship';
|
||||
|
||||
@Injectable()
|
||||
export class FriendshipService {
|
||||
@@ -16,21 +17,36 @@ export class FriendshipService {
|
||||
) { }
|
||||
|
||||
|
||||
// createSendableFriendship(friendship: Friendship): SendableFriendship {
|
||||
// let ret = new SendableFriendship;
|
||||
|
||||
// ret.id = friendship.id;
|
||||
// ret.date = friendship.date
|
||||
// ret.senderUsername = friendship.sender.username;
|
||||
// ret.senderId = friendship.sender.id;
|
||||
// ret.receiverUsername = friendship.receiver.username;
|
||||
// ret.receiverId = friendship.receiver.id;
|
||||
// ret.status = friendship.status;
|
||||
// return ret;
|
||||
// };
|
||||
|
||||
async findOneRelationshipById(friendId : number, userId : number) {
|
||||
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.senderId = :userId', { userId : userId})
|
||||
.andWhere('friendship.receiverId = :friendId', {friendId : friendId})
|
||||
subAQb.where('sender.id = :userId', { userId : userId})
|
||||
.andWhere('receiver.id = :friendId', {friendId : friendId})
|
||||
})
|
||||
)
|
||||
.orWhere(
|
||||
new Brackets((subBQb) => {
|
||||
subBQb.where('friendship.senderId = :friendId', {friendId : friendId})
|
||||
.andWhere('friendship.receiverId = :userId', {userId : userId})
|
||||
subBQb.where('sender.id = :friendId', {friendId : friendId})
|
||||
.andWhere('receiver.id = :userId', {userId : userId})
|
||||
})
|
||||
)
|
||||
}),
|
||||
@@ -44,7 +60,9 @@ export class FriendshipService {
|
||||
if (!friendship) {
|
||||
throw new HttpException(`There is no such friendship`, HttpStatus.NOT_FOUND);
|
||||
}
|
||||
return friendship;
|
||||
// return friendship;
|
||||
// return this.createSendableFriendship(friendship);
|
||||
return new SendableFriendship(friendship);
|
||||
}
|
||||
|
||||
// basically useless now
|
||||
@@ -79,46 +97,63 @@ export class FriendshipService {
|
||||
if (!friendship) {
|
||||
throw new HttpException(`There is no such friendship`, HttpStatus.NOT_FOUND);
|
||||
}
|
||||
return friendship;
|
||||
// return friendship;
|
||||
return new SendableFriendship(friendship);
|
||||
}
|
||||
|
||||
// lets see what happens here, doing directly receiver.id not LeftJoinAndSelect ...
|
||||
async findAllFriends(userId: number) {
|
||||
const friendship = await this.friendshipRepository
|
||||
.createQueryBuilder('friendship')
|
||||
.leftJoinAndSelect('friendship.sender', 'sender')
|
||||
.leftJoinAndSelect('friendship.receiver', 'receiver')
|
||||
.where('friendship.status = :status', { status: FriendshipStatus.ACCEPTED })
|
||||
.andWhere('friendship.receiverId = :addressee', { addressee: userId })
|
||||
.orWhere('friendship.senderId = :requester', { requester: userId })
|
||||
.andWhere('receiver.id = :addressee', { addressee: userId })
|
||||
.orWhere('sender.id = :requester', { requester: userId })
|
||||
.andWhere('friendship.status = :status', { status: FriendshipStatus.ACCEPTED })
|
||||
.getMany();
|
||||
// for (const friend of friendship)
|
||||
// console.log("FRIENDSHIP : " + friend.status);
|
||||
return friendship;
|
||||
// return friendship;
|
||||
return new SendableFriendship(friendship);
|
||||
}
|
||||
|
||||
async findOneBlocked(friendshipId: number, userId: number) {
|
||||
const friendship = await this.friendshipRepository.findOneBy({ id: friendshipId, senderId: userId, status: FriendshipStatus.BLOCKED });
|
||||
// const friendship = await this.friendshipRepository.findOneBy({ id: friendshipId, sender.id: userId, status: FriendshipStatus.BLOCKED });
|
||||
const friendship = await this.friendshipRepository
|
||||
.createQueryBuilder('friendship')
|
||||
.leftJoinAndSelect('friendship.sender', 'sender')
|
||||
.where('friendship.id = :id', { id: friendshipId })
|
||||
.andWhere('sender.id = :requester', { requester: userId })
|
||||
.andWhere('friendship.status = :status', { status: FriendshipStatus.BLOCKED })
|
||||
.getOne();
|
||||
if (!friendship)
|
||||
throw new HttpException(`The requested blocked not found.`, HttpStatus.NOT_FOUND);
|
||||
return friendship;
|
||||
// return friendship;
|
||||
return new SendableFriendship(friendship);
|
||||
}
|
||||
|
||||
async findOneBlockedByUsername(blockedUsername : string, userId : number) {
|
||||
const friendship = await this.friendshipRepository
|
||||
.createQueryBuilder('friendship')
|
||||
.where('friendship.senderId = :senderId', {senderId : userId})
|
||||
.andWhere('friendship.receiverUsername = :friendUsername', {friendUsername : blockedUsername})
|
||||
.leftJoinAndSelect('friendship.sender', 'sender')
|
||||
.leftJoinAndSelect('friendship.receiver', 'receiver')
|
||||
.where('sender.id = :senderId', {senderId : userId})
|
||||
.andWhere('receiver.username = :friendUsername', {friendUsername : blockedUsername})
|
||||
.andWhere('friendship.status = :status ', {status : FriendshipStatus.BLOCKED})
|
||||
.getOne()
|
||||
if (!friendship) {
|
||||
throw new HttpException(`The requested blocked not found.`, HttpStatus.NOT_FOUND);
|
||||
}
|
||||
return friendship;
|
||||
// return friendship;
|
||||
return new SendableFriendship(friendship);
|
||||
}
|
||||
|
||||
async findAllBlockedFriends(userId: number) {
|
||||
const friendships : Friendship[] = await this.friendshipRepository
|
||||
.createQueryBuilder('friendship')
|
||||
.where('friendship.senderId = :requestee', { requestee: userId })
|
||||
.leftJoinAndSelect('friendship.sender', 'sender')
|
||||
.where('sender.id = :requestee', { requestee: userId })
|
||||
.andWhere('friendship.status = :status', { status: FriendshipStatus.BLOCKED })
|
||||
.getMany();
|
||||
// let partialFriendship : Partial<Friendship>[] = [];
|
||||
@@ -130,13 +165,20 @@ export class FriendshipService {
|
||||
console.log('friendship.service findAllBlockedFriends, partial friendship:')
|
||||
// console.log({...partialFriendship})
|
||||
// return partialFriendship;
|
||||
return friendships;
|
||||
// return friendships;
|
||||
let sendFrienships: SendableFriendship[] = []
|
||||
for (const friendship of friendships) {
|
||||
sendFrienships.push(new SendableFriendship(friendship));
|
||||
}
|
||||
// return new SendableFriendship(friendship);
|
||||
return sendFrienships;
|
||||
}
|
||||
|
||||
async findAllPendantRequestsForFriendship(userId: number) {
|
||||
const friendships = await this.friendshipRepository
|
||||
.createQueryBuilder('friendship')
|
||||
.where('friendship.senderId = :requestee', { requestee: userId })
|
||||
.leftJoinAndSelect('friendship.sender', 'sender')
|
||||
.where('sender.id = :requestee', { requestee: userId })
|
||||
.andWhere('friendship.status = :status', { status: FriendshipStatus.REQUESTED })
|
||||
.getMany();
|
||||
// let partialFriendship : Partial<Friendship>[] = [];
|
||||
@@ -148,13 +190,19 @@ export class FriendshipService {
|
||||
// return partialFriendship;
|
||||
console.log('friendships services pendant friendships:')
|
||||
console.log({...friendships})
|
||||
return friendships;
|
||||
// return friendships;
|
||||
let sendFrienships: SendableFriendship[] = []
|
||||
for (const friendship of friendships) {
|
||||
sendFrienships.push(new SendableFriendship(friendship));
|
||||
}
|
||||
return sendFrienships;
|
||||
}
|
||||
|
||||
async findAllReceivedRequestsForFriendship(userId: number) {
|
||||
const friendships = await this.friendshipRepository
|
||||
.createQueryBuilder('friendship')
|
||||
.where('friendship.receiverId = :addressee', { addressee: userId })
|
||||
.leftJoinAndSelect('friendship.receiver', 'receiver')
|
||||
.where('receiver.id = :addressee', { addressee: userId })
|
||||
.andWhere('friendship.status = :status', { status: FriendshipStatus.REQUESTED })
|
||||
.getMany();
|
||||
// let partialFriendship : Partial<Friendship>[] = [];
|
||||
@@ -164,10 +212,17 @@ export class FriendshipService {
|
||||
// return partialFriendship;
|
||||
console.log('friendship service received requests')
|
||||
console.log({...friendships})
|
||||
return friendships;
|
||||
// return friendships;
|
||||
let sendFrienships: SendableFriendship[] = []
|
||||
for (const friendship of friendships) {
|
||||
sendFrienships.push(new SendableFriendship(friendship));
|
||||
}
|
||||
return sendFrienships;
|
||||
}
|
||||
|
||||
async create(createFriendshipDto: CreateFriendshipDto, creator : User) : Promise <Partial<Friendship>> {
|
||||
// this is no longer the right return
|
||||
// async create(createFriendshipDto: CreateFriendshipDto, creator : User) : Promise <Partial<Friendship>> {
|
||||
async create(createFriendshipDto: CreateFriendshipDto, creator : User) {
|
||||
console.log("DTO : \n")
|
||||
console.log({...createFriendshipDto})
|
||||
const receiver = await this.userRepository.findOneBy({id: createFriendshipDto.receiverId});
|
||||
@@ -193,25 +248,28 @@ export class FriendshipService {
|
||||
}
|
||||
const newFriendship = new Friendship();
|
||||
newFriendship.sender = creator;
|
||||
newFriendship.senderUsername = creator.username;
|
||||
newFriendship.senderId = creator.id;
|
||||
// newFriendship.senderUsername = creator.username;
|
||||
// newFriendship.senderId = creator.id;
|
||||
newFriendship.receiver = receiver;
|
||||
newFriendship.receiverUsername = receiver.username;
|
||||
newFriendship.receiverId = receiver.id;
|
||||
// newFriendship.receiverUsername = receiver.username;
|
||||
// newFriendship.receiverId = receiver.id;
|
||||
newFriendship.status = createFriendshipDto.status;
|
||||
const savedFriendship = this.friendshipRepository.save(newFriendship);
|
||||
const partialFriendship : Partial<Friendship> = {
|
||||
id : (await savedFriendship).id,
|
||||
date : (await savedFriendship).date,
|
||||
receiverUsername: (await savedFriendship).receiverUsername,
|
||||
receiverId: (await savedFriendship).receiverId,
|
||||
status : (await savedFriendship).status
|
||||
}
|
||||
console.log('friendship.service create friendship, partial friendship')
|
||||
console.log({...partialFriendship})
|
||||
const savedFriendship = await this.friendshipRepository.save(newFriendship);
|
||||
// const partialFriendship : Partial<Friendship> = {
|
||||
// id : (await savedFriendship).id,
|
||||
// date : (await savedFriendship).date,
|
||||
// receiverUsername: (await savedFriendship).receiverUsername,
|
||||
// receiverId: (await savedFriendship).receiverId,
|
||||
// status : (await savedFriendship).status
|
||||
// }
|
||||
// console.log('friendship.service create friendship, partial friendship')
|
||||
// console.log({...partialFriendship})
|
||||
console.log('friendship.service create friendship, NEW friendship')
|
||||
console.log({...newFriendship})
|
||||
return partialFriendship;
|
||||
console.log('friendship.service create friendship, SAVED friendship')
|
||||
console.log({...savedFriendship})
|
||||
// return partialFriendship;
|
||||
return new SendableFriendship(savedFriendship);
|
||||
}
|
||||
|
||||
async acceptFriendship(relationshipId: number, user: User) {
|
||||
@@ -224,18 +282,19 @@ export class FriendshipService {
|
||||
throw new HttpException(`You can't accept your own request.`, HttpStatus.NOT_FOUND);
|
||||
}
|
||||
relation.status = FriendshipStatus.ACCEPTED;
|
||||
const savedFriendship = this.friendshipRepository.save(relation);
|
||||
const partialFriendship : Partial<Friendship> = {
|
||||
id : (await savedFriendship).id,
|
||||
date : (await savedFriendship).date,
|
||||
receiverUsername: (await savedFriendship).receiverUsername,
|
||||
receiverId: (await savedFriendship).receiverId,
|
||||
status : (await savedFriendship).status
|
||||
}
|
||||
console.log('.service accept friendship END')
|
||||
console.log({...partialFriendship})
|
||||
const savedFriendship = await this.friendshipRepository.save(relation);
|
||||
// const partialFriendship : Partial<Friendship> = {
|
||||
// id : (await savedFriendship).id,
|
||||
// date : (await savedFriendship).date,
|
||||
// receiverUsername: (await savedFriendship).receiverUsername,
|
||||
// receiverId: (await savedFriendship).receiverId,
|
||||
// status : (await savedFriendship).status
|
||||
// }
|
||||
// console.log('.service accept friendship END')
|
||||
// console.log({...partialFriendship})
|
||||
|
||||
return partialFriendship;
|
||||
// return partialFriendship;
|
||||
return new SendableFriendship(savedFriendship);
|
||||
}
|
||||
|
||||
async declineFriendship(relationshipId: number, user: User) {
|
||||
@@ -246,16 +305,17 @@ export class FriendshipService {
|
||||
throw new HttpException(`You can't decline your own request.`, HttpStatus.NOT_FOUND);
|
||||
}
|
||||
relation.status = FriendshipStatus.DECLINED;
|
||||
const savedFriendship = this.friendshipRepository.save(relation);
|
||||
const partialFriendship : Partial<Friendship> = {
|
||||
id : (await savedFriendship).id,
|
||||
date : (await savedFriendship).date,
|
||||
receiverUsername: (await savedFriendship).receiverUsername,
|
||||
status : (await savedFriendship).status
|
||||
}
|
||||
console.log('decline friend request')
|
||||
console.log({...partialFriendship})
|
||||
return partialFriendship
|
||||
const savedFriendship = await this.friendshipRepository.save(relation);
|
||||
// const partialFriendship : Partial<Friendship> = {
|
||||
// id : (await savedFriendship).id,
|
||||
// date : (await savedFriendship).date,
|
||||
// receiverUsername: (await savedFriendship).receiverUsername,
|
||||
// status : (await savedFriendship).status
|
||||
// }
|
||||
// console.log('decline friend request')
|
||||
// console.log({...partialFriendship})
|
||||
// return partialFriendship
|
||||
return new SendableFriendship(savedFriendship);
|
||||
}
|
||||
|
||||
async blockFriendship(relationshipId: number, user: User) {
|
||||
@@ -283,15 +343,16 @@ export class FriendshipService {
|
||||
return await this.create(newFriendshipDto, user);
|
||||
} else {
|
||||
relation.status = FriendshipStatus.BLOCKED;
|
||||
const savedFriendship = this.friendshipRepository.save(relation);
|
||||
const partialFriendship : Partial<Friendship> = {
|
||||
id : (await savedFriendship).id,
|
||||
date : (await savedFriendship).date,
|
||||
receiverUsername: (await savedFriendship).receiverUsername,
|
||||
receiverId: (await savedFriendship).receiverId,
|
||||
status : (await savedFriendship).status
|
||||
}
|
||||
return partialFriendship
|
||||
const savedFriendship = await this.friendshipRepository.save(relation);
|
||||
// const partialFriendship : Partial<Friendship> = {
|
||||
// id : (await savedFriendship).id,
|
||||
// date : (await savedFriendship).date,
|
||||
// receiverUsername: (await savedFriendship).receiverUsername,
|
||||
// receiverId: (await savedFriendship).receiverId,
|
||||
// status : (await savedFriendship).status
|
||||
// }
|
||||
// return partialFriendship
|
||||
return new SendableFriendship(savedFriendship);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -323,18 +384,20 @@ export class FriendshipService {
|
||||
|
||||
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.senderId = :senderId', { senderId: userConnectedId})
|
||||
.andWhere('friendship.receiverId = :receiverId', { receiverId: userToFindId})
|
||||
subAQb.where('sender.id = :senderId', { senderId: userConnectedId})
|
||||
.andWhere('receiver.id = :receiverId', { receiverId: userToFindId})
|
||||
})
|
||||
)
|
||||
.orWhere(
|
||||
new Brackets((subBQb) => {
|
||||
subBQb.where('friendship.senderId = :senderId', {senderId : userToFindId})
|
||||
.andWhere('friendship.receiverId = :receiverId', {receiverUsername : userConnectedId})
|
||||
subBQb.where('sender.id = :senderId', {senderId : userToFindId})
|
||||
.andWhere('receiver.id = :receiverId', {receiverUsername : userConnectedId})
|
||||
})
|
||||
)
|
||||
}),
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
|
||||
import { Friendship, FriendshipStatus } from "./entities/friendship.entity";
|
||||
|
||||
|
||||
// Ok i don't really know what i'm doing but i want a thing that is typeset that i can use to send info back to the Front when they create a friendship or ask for a friendship
|
||||
// Ok it doesn't seem like i really need an interface, that just enfoces the types
|
||||
|
||||
// export interface SendableFriendship {
|
||||
export class SendableFriendship {
|
||||
id: number;
|
||||
date: Date;
|
||||
senderUsername: string;
|
||||
senderId: number;
|
||||
receiverUsername: string;
|
||||
receiverId: number;
|
||||
status: FriendshipStatus;
|
||||
|
||||
// if my constructor is here won't it get sent all over the place too?
|
||||
constructor(friendship: Friendship) {
|
||||
this.id = friendship.id;
|
||||
this.date = friendship.date
|
||||
this.senderUsername = friendship.sender.username;
|
||||
this.senderId = friendship.sender.id;
|
||||
this.receiverUsername = friendship.receiver.username;
|
||||
this.receiverId = friendship.receiver.id;
|
||||
this.status = friendship.status;
|
||||
};
|
||||
}
|
||||
@@ -19,6 +19,7 @@ export class UsersController {
|
||||
constructor(private readonly usersService: UsersService) {}
|
||||
// par exemple dans postamn ou insomnia http://localhost:3000/users?limit=10&offset=20
|
||||
|
||||
// GET http://transcendance:8080/user/all
|
||||
@UseGuards(AuthenticateGuard)
|
||||
@UseGuards(TwoFactorGuard)
|
||||
@Get('all')
|
||||
@@ -61,8 +62,16 @@ export class UsersController {
|
||||
@UseGuards(AuthenticateGuard)
|
||||
@UseGuards(TwoFactorGuard)
|
||||
@Get()
|
||||
findMe(@Req() req) {
|
||||
return this.usersService.findOne(req.user.id);
|
||||
findOne(@Query('id') toFindId: number, @Req() req) {
|
||||
console.log('users service findOne toFindId:')
|
||||
console.log(toFindId)
|
||||
console.log('users service findOne my Id:')
|
||||
console.log(req.user.id)
|
||||
if (toFindId === undefined)
|
||||
return this.usersService.findOne(req.user.id);
|
||||
else
|
||||
return this.usersService.findOne(toFindId);
|
||||
// i would rather just use numbers but i'm guessing Cherif uses this all over
|
||||
}
|
||||
|
||||
// also seems useless...
|
||||
@@ -75,6 +84,7 @@ export class UsersController {
|
||||
// }
|
||||
|
||||
|
||||
// PATCH http://transcendance:8080/user
|
||||
@UseGuards(AuthenticateGuard)
|
||||
@UseGuards(TwoFactorGuard)
|
||||
@Patch()
|
||||
@@ -93,6 +103,7 @@ export class UsersController {
|
||||
response.status(200).send("OK")
|
||||
}
|
||||
|
||||
// DELETE http://transcendance:8080/user
|
||||
@UseGuards(AuthenticateGuard)
|
||||
@UseGuards(TwoFactorGuard)
|
||||
@Delete()
|
||||
@@ -100,6 +111,7 @@ export class UsersController {
|
||||
return this.usersService.remove(req.user.id);
|
||||
}
|
||||
|
||||
// POST http://transcendance:8080/user/avatar
|
||||
@UseGuards(AuthenticateGuard)
|
||||
@UseGuards(TwoFactorGuard)
|
||||
@Post('avatar')
|
||||
@@ -109,6 +121,7 @@ export class UsersController {
|
||||
this.usersService.updateAvatar(user.id, file.filename);
|
||||
}
|
||||
|
||||
// GET http://transcendance:8080/user/avatar
|
||||
@UseGuards(AuthenticateGuard)
|
||||
@UseGuards(TwoFactorGuard)
|
||||
@Get('avatar')
|
||||
|
||||
@@ -32,11 +32,11 @@ export class UsersService {
|
||||
return user;
|
||||
}
|
||||
|
||||
async findOne(id: string) {
|
||||
async findOne(id: number) {
|
||||
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.`);
|
||||
@@ -53,6 +53,7 @@ export class UsersService {
|
||||
return partialUser;
|
||||
}
|
||||
|
||||
// Ok this gets called in the Authenitcation Service, but like i was still able to make a username === someone else's
|
||||
async isUsernameExists(usernameToSearch: string): Promise<boolean> {
|
||||
const user = await this.userRepository.findOneBy({username : usernameToSearch});
|
||||
if (!user)
|
||||
|
||||
Reference in New Issue
Block a user