Browse Source

*fix private chan visibles

*socketKey safety
*fix rank
master
nicolas-arnaud 2 years ago
parent
commit
b7fb9617d5
  1. 1
      back/volume/src/pong/pong.service.ts
  2. 20
      back/volume/src/users/users.service.ts
  3. 4
      front/volume/src/components/Channels.svelte

1
back/volume/src/pong/pong.service.ts

@ -20,7 +20,6 @@ export class PongService {
if (result.score[i] === maxScore) player.wins++ if (result.score[i] === maxScore) player.wins++
else player.looses++ else player.looses++
player.winrate = (100 * player.wins) / player.matchs player.winrate = (100 * player.wins) / player.matchs
player.rank = (await this.usersService.getRank(player.ftId)) + 1
} }
async updatePlayer (i: number, result: Result, maxScore: number): Promise<void> { async updatePlayer (i: number, result: Result, maxScore: number): Promise<void> {

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

@ -21,9 +21,7 @@ export class UsersService {
async findUsers (): Promise<User[]> { async findUsers (): Promise<User[]> {
const users = await this.usersRepository.find({}) const users = await this.usersRepository.find({})
users.forEach((usr) => { users.forEach((usr) => usr.socketKey = '')
usr.socketKey = ''
})
return users return users
} }
@ -33,6 +31,7 @@ export class UsersService {
relations: { results: true } relations: { results: true }
}) })
if (user == null) throw new BadRequestException('User not found.') if (user == null) throw new BadRequestException('User not found.')
user.rank = (await this.getRank(user.ftId)) + 1;
return user return user
} }
@ -43,9 +42,7 @@ export class UsersService {
if (Date.now() - usr.lastAccess > 60000) { if (Date.now() - usr.lastAccess > 60000) {
usr.isVerified = false usr.isVerified = false
usr.status = 'offline' usr.status = 'offline'
this.usersRepository.save(usr).catch((err) => { this.usersRepository.save(usr).catch((err) => console.log(err))
console.log(err)
})
} }
}) })
} }
@ -53,6 +50,7 @@ export class UsersService {
async findUser (ftId: number): Promise<User | null> { async findUser (ftId: number): Promise<User | null> {
const user = await this.usersRepository.findOneBy({ ftId }) const user = await this.usersRepository.findOneBy({ ftId })
if (user == null) return null if (user == null) return null
user.rank = (await this.getRank(user.ftId)) + 1;
user.lastAccess = Date.now() user.lastAccess = Date.now()
if (user.status === 'offline') user.status = 'online' if (user.status === 'offline') user.status = 'online'
await this.usersRepository.save(user) await this.usersRepository.save(user)
@ -63,9 +61,7 @@ export class UsersService {
const users = await this.usersRepository.find({ const users = await this.usersRepository.find({
where: { status: 'online' } where: { status: 'online' }
}) })
users.forEach((usr) => { users.forEach((usr) => usr.socketKey = '')
usr.socketKey = ''
})
return users return users
} }
@ -102,6 +98,7 @@ export class UsersService {
relations: { friends: true } relations: { friends: true }
}) })
if (user == null) throw new BadRequestException('User not found.') if (user == null) throw new BadRequestException('User not found.')
user.friends.forEach((friend) => friend.socketKey = '')
return user.friends return user.friends
} }
@ -113,6 +110,7 @@ export class UsersService {
} }
}) })
if (user == null) throw new BadRequestException('User not found.') if (user == null) throw new BadRequestException('User not found.')
user.followers.forEach((follower) => follower.socketKey = '')
return user.followers return user.followers
} }
@ -122,7 +120,9 @@ export class UsersService {
winrate: 'DESC' winrate: 'DESC'
} }
}) })
return leaderboard.filter((user) => user.rank !== 0) let ret = leaderboard.filter((user) => user.rank !== 0)
ret.forEach((follower) => follower.socketKey = '')
return ret
} }
async getRank (ftId: number): Promise<number> { async getRank (ftId: number): Promise<number> {

4
front/volume/src/components/Channels.svelte

@ -56,8 +56,8 @@
body: JSON.stringify({ body: JSON.stringify({
name: name, name: name,
owner: $store.ftId, owner: $store.ftId,
password: password || "", password: password,
isPrivate: privacy, isPrivate: privacy === "private",
}), }),
}); });
if (response.ok) { if (response.ok) {

Loading…
Cancel
Save