Browse Source

fix invitations

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

20
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,6 +112,7 @@ export class UsersService {
`Friend relation complete between ${user.username} and ${target.username}`
)
user.friends.push(target)
if (user != target)
target.friends.push(user)
user.followers.slice(id, 1)
this.usersRepository.save(user)

6
front/volume/src/App.svelte

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

1
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.");

Loading…
Cancel
Save