diff --git a/back/volume/src/users/users.service.ts b/back/volume/src/users/users.service.ts index 3ac5ea4..c8e617a 100644 --- a/back/volume/src/users/users.service.ts +++ b/back/volume/src/users/users.service.ts @@ -81,9 +81,24 @@ export class UsersService { } async invit (ftId: number, targetFtId: number) { - const user = await this.findUser(ftId) + const user = await this.usersRepository.findOne({ + where: { ftId }, + relations: { + followers: true, + friends: true, + } + }) if (user == null) return null - const target = await this.findUser(targetFtId) + if (user.friends.findIndex( + (friend) => friend.ftId === targetFtId) != -1) + return null + const target = await this.usersRepository.findOne({ + where: { ftId: targetFtId }, + relations: { + followers: true, + friends: true, + } + }) if (target == null) { return new NotFoundException( `Error: user id ${targetFtId} isn't in our db.` @@ -97,7 +112,8 @@ export class UsersService { `Friend relation complete between ${user.username} and ${target.username}` ) user.friends.push(target) - target.friends.push(user) + if (user != target) + target.friends.push(user) user.followers.slice(id, 1) this.usersRepository.save(user) } else { diff --git a/front/volume/src/App.svelte b/front/volume/src/App.svelte index 3731c9e..20cc86f 100644 --- a/front/volume/src/App.svelte +++ b/front/volume/src/App.svelte @@ -51,11 +51,15 @@ export async function getFriends(): Promise { let response = await fetch(API_URL + "/friends", { credentials: "include", + mode: "cors", }); return await response.json(); } export async function getInvits(): Promise { - let response = await fetch(API_URL + "/invits", { credentials: "include" }); + let response = await fetch(API_URL + "/invits", { + credentials: "include", + mode: "cors", + }); return await response.json(); } diff --git a/front/volume/src/components/Friends.svelte b/front/volume/src/components/Friends.svelte index 8472c9c..08a8b33 100644 --- a/front/volume/src/components/Friends.svelte +++ b/front/volume/src/components/Friends.svelte @@ -29,6 +29,7 @@ response = await fetch(API_URL + "/invit/" + target.ftId, { credentials: "include", + mode: "cors", }); if (response.ok) { console.log("Invitation send.");