Skip to content

Commit

Permalink
eslint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayoub Essabiry authored and Ayoub Essabiry committed Oct 13, 2023
1 parent 1c1f54e commit f8a4942
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 39 deletions.
26 changes: 11 additions & 15 deletions backend/code/src/rooms/dto/change-owner.dto.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import { ApiProperty } from '@nestjs/swagger';
import {
IsNotEmpty,
IsString,
} from 'class-validator';
import { IsNotEmpty, IsString } from 'class-validator';

export class ChangeOwnerDto{
@ApiProperty()
@IsNotEmpty()
@IsString()
roomId: string;
@ApiProperty()
@IsNotEmpty()
@IsString()
NewOwnerId: string;

}
export class ChangeOwnerDto {
@ApiProperty()
@IsNotEmpty()
@IsString()
roomId: string;
@ApiProperty()
@IsNotEmpty()
@IsString()
NewOwnerId: string;
}
22 changes: 11 additions & 11 deletions backend/code/src/rooms/dto/set-admin.dto.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { ApiProperty } from "@nestjs/swagger";
import { IsNotEmpty, IsString } from "class-validator";
import { ApiProperty } from '@nestjs/swagger';
import { IsNotEmpty, IsString } from 'class-validator';

export class SetAdminDto {
@ApiProperty()
@IsNotEmpty()
@IsString()
roomId: string;
@ApiProperty()
@IsNotEmpty()
@IsString()
newAdmin: string;
}
@ApiProperty()
@IsNotEmpty()
@IsString()
roomId: string;
@ApiProperty()
@IsNotEmpty()
@IsString()
newAdmin: string;
}
4 changes: 2 additions & 2 deletions backend/code/src/rooms/rooms.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class RoomsController {
async changeOwner(
@Body() roomdata: ChangeOwnerDto,
@GetCurrentUser('userId') userId: string,
){
) {
return await this.roomsService.changeOwner(roomdata, userId);
}
@Post('setAdmin')
Expand All @@ -87,7 +87,7 @@ export class RoomsController {
async setAdmin(
@Body() roomdata: SetAdminDto,
@GetCurrentUser('userId') userId: string,
){
) {
return await this.roomsService.setAdmin(roomdata, userId);
}
}
34 changes: 23 additions & 11 deletions backend/code/src/rooms/rooms.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,29 +134,41 @@ export class RoomsService {
where: { unique_user_room: { userId: userId, roomId: roomData.roomId } },
select: { id: true },
});
if (room.ownerId !== userId) throw new UnauthorizedException('You are not the owner of this room');
if (!member) throw new UnauthorizedException('new owner is not a member of this room');
if (room.ownerId !== userId)
throw new UnauthorizedException('You are not the owner of this room');
if (!member)
throw new UnauthorizedException('new owner is not a member of this room');
await this.prisma.room.update({
where: { id: roomData.roomId },
data: { owner: { connect: { userId: roomData.NewOwnerId } } }
data: { owner: { connect: { userId: roomData.NewOwnerId } } },
});
return { message: 'roomOwner changed successfully' };
}
}
async setAdmin(roomData: SetAdminDto, userId: string) {
const room = await this.prisma.room.findUnique({
where: { id: roomData.roomId },
select: { ownerId: true },
});
const user = await this.prisma.roomMember.findUnique({
where: { unique_user_room: { userId: userId, roomId: roomData.roomId } },
select : { is_admin: true },
select: { is_admin: true },
});
if (room.ownerId !== userId) throw new UnauthorizedException('You are not the owner of this room');
if (!user) throw new UnauthorizedException('new admin is not a member of this room');
if (user.is_admin || room.ownerId === roomData.newAdmin) throw new UnauthorizedException('new admin is already an admin of this room');
return await this.prisma.roomMember.update({
where: { unique_user_room: { userId: roomData.newAdmin, roomId: roomData.roomId } },
data: { is_admin: true }
if (room.ownerId !== userId)
throw new UnauthorizedException('You are not the owner of this room');
if (!user)
throw new UnauthorizedException('new admin is not a member of this room');
if (user.is_admin || room.ownerId === roomData.newAdmin)
throw new UnauthorizedException(
'new admin is already an admin of this room',
);
return await this.prisma.roomMember.update({
where: {
unique_user_room: {
userId: roomData.newAdmin,
roomId: roomData.roomId,
},
},
data: { is_admin: true },
});
}
}

0 comments on commit f8a4942

Please sign in to comment.