Browse Source

fix invitations

fix double invitations
master
nicolas-arnaud 2 years ago
parent
commit
aa3fbb98cb
  1. 22
      back/volume/src/users/users.service.ts
  2. 6
      front/volume/src/App.svelte
  3. 1
      front/volume/src/components/Friends.svelte

22
back/volume/src/users/users.service.ts

@ -81,9 +81,24 @@ export class UsersService {
} }
async invit (ftId: number, targetFtId: number) { 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 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) { if (target == null) {
return new NotFoundException( return new NotFoundException(
`Error: user id ${targetFtId} isn't in our db.` `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}` `Friend relation complete between ${user.username} and ${target.username}`
) )
user.friends.push(target) user.friends.push(target)
target.friends.push(user) if (user != target)
target.friends.push(user)
user.followers.slice(id, 1) user.followers.slice(id, 1)
this.usersRepository.save(user) this.usersRepository.save(user)
} else { } else {

6
front/volume/src/App.svelte

@ -51,11 +51,15 @@
export async function getFriends(): Promise<Friend[]> { export async function getFriends(): Promise<Friend[]> {
let response = await fetch(API_URL + "/friends", { let response = await fetch(API_URL + "/friends", {
credentials: "include", credentials: "include",
mode: "cors",
}); });
return await response.json(); return await response.json();
} }
export async function getInvits(): Promise<Friend[]> { export async function getInvits(): Promise<Friend[]> {
let response = await fetch(API_URL + "/invits", { credentials: "include" }); let response = await fetch(API_URL + "/invits", {
credentials: "include",
mode: "cors",
});
return await response.json(); return await response.json();
} }

1
front/volume/src/components/Friends.svelte

@ -29,6 +29,7 @@
response = await fetch(API_URL + "/invit/" + target.ftId, { response = await fetch(API_URL + "/invit/" + target.ftId, {
credentials: "include", credentials: "include",
mode: "cors",
}); });
if (response.ok) { if (response.ok) {
console.log("Invitation send."); console.log("Invitation send.");

Loading…
Cancel
Save