Browse Source

* last

master
vvandenb 2 years ago
parent
commit
f7e51e39d2
  1. 24
      back/volume/src/chat/chat.controller.ts
  2. 1
      back/volume/src/main.ts

24
back/volume/src/chat/chat.controller.ts

@ -140,25 +140,25 @@ export class ChatController {
@Profile42() profile: Profile @Profile42() profile: Profile
): Promise<void> { ): Promise<void> {
const channel = await this.channelService.getFullChannel(id) const channel = await this.channelService.getFullChannel(id)
const user: User | null = await this.usersService.findUser(target.data[0]) const user: User | null = await this.usersService.findUser(+target.data[0])
if (isNaN(+target.data[1])) { if (isNaN(+target.data[1])) {
throw new BadRequestException(`Invalid duration ${target.data[1]}`) throw new BadRequestException(`Invalid duration ${+target.data[1]}`)
} }
if (user == null) { if (user == null) {
throw new NotFoundException(`User #${target.data[0]} not found`) throw new NotFoundException(`User #${+target.data[0]} not found`)
} }
if (!(await this.channelService.isAdmin(channel.id, +profile.id))) { if (!(await this.channelService.isAdmin(channel.id, +profile.id))) {
throw new BadRequestException( throw new BadRequestException(
'You are not allowed to ban users from this channel' 'You are not allowed to ban users from this channel'
) )
} }
if (await this.channelService.isOwner(channel.id, target.data[0])) { if (await this.channelService.isOwner(channel.id, +target.data[0])) {
throw new BadRequestException('You cannot ban the owner of the channel') throw new BadRequestException('You cannot ban the owner of the channel')
} }
if (await this.channelService.isBanned(channel.id, target.data[0])) { if (await this.channelService.isBanned(channel.id, +target.data[0])) {
throw new BadRequestException('User is already banned from this channel') throw new BadRequestException('User is already banned from this channel')
} }
channel.banned.push([target.data[0], Date.now() + target.data[1] * 1000]) channel.banned.push([+target.data[0], Date.now() + +target.data[1] * 1000])
await this.channelService.save(channel) await this.channelService.save(channel)
} }
@ -169,25 +169,25 @@ export class ChatController {
@Profile42() profile: Profile @Profile42() profile: Profile
): Promise<void> { ): Promise<void> {
const channel = await this.channelService.getFullChannel(id) const channel = await this.channelService.getFullChannel(id)
const user: User | null = await this.usersService.findUser(mute.data[0]) const user: User | null = await this.usersService.findUser(+mute.data[0])
if (isNaN(+mute.data[1])) { if (isNaN(+mute.data[1])) {
throw new BadRequestException(`Invalid duration ${mute.data[1]}`) throw new BadRequestException(`Invalid duration ${+mute.data[1]}`)
} }
if (user == null) { if (user == null) {
throw new NotFoundException(`User #${mute.data[0]} not found`) throw new NotFoundException(`User #${+mute.data[0]} not found`)
} }
if (!(await this.channelService.isAdmin(channel.id, +profile.id))) { if (!(await this.channelService.isAdmin(channel.id, +profile.id))) {
throw new BadRequestException( throw new BadRequestException(
'You are not allowed to mute users from this channel' 'You are not allowed to mute users from this channel'
) )
} }
if (await this.channelService.isOwner(channel.id, mute.data[0])) { if (await this.channelService.isOwner(channel.id, +mute.data[0])) {
throw new BadRequestException('You cannot mute the owner of the channel') throw new BadRequestException('You cannot mute the owner of the channel')
} }
if (await this.channelService.isMuted(channel.id, mute.data[0])) { if (await this.channelService.isMuted(channel.id, +mute.data[0])) {
throw new BadRequestException('User is already muted from this channel') throw new BadRequestException('User is already muted from this channel')
} }
const newMute: number[] = [mute.data[0], Date.now() + mute.data[1] * 1000] const newMute: number[] = [+mute.data[0], Date.now() + +mute.data[1] * 1000]
channel.muted.push(newMute) channel.muted.push(newMute)
await this.channelService.save(channel) await this.channelService.save(channel)
} }

1
back/volume/src/main.ts

@ -25,7 +25,6 @@ async function bootstrap (): Promise<void> {
allowedHeaders: allowedHeaders:
['Accept', 'Content-Type', 'Authorization'] ['Accept', 'Content-Type', 'Authorization']
} }
app.useGlobalPipes(new ValidationPipe())
app.use( app.use(
session({ session({
resave: false, resave: false,

Loading…
Cancel
Save