Skip to content

Commit

Permalink
refactored code
Browse files Browse the repository at this point in the history
  • Loading branch information
MAwaisMansoor committed Mar 23, 2022
1 parent 345c2bb commit 4c6f82a
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions apps/api/src/modules/classroom/classroom.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ export default class ClassroomService {
})
}

getMemberInAction(classroomId: string, userId: string) {
return this.prismaService.classroomMember.findUnique({
where: { classroomId, userId },
})
}

async getClassroomInviteCode(classroomId: string, user: User) {
const memberRecord = await this.getClassroomById(classroomId).members({
where: { userId: user.id },
Expand Down Expand Up @@ -119,12 +125,10 @@ export default class ClassroomService {
classroomId: string,
userId: string,
memberId: string,
role: string) {
role: ClassroomRole) {

//get user from the classroom
const memberInAction = await this.prismaService.classroomMember.findUnique({
where: { classroomId, userId },
})
const memberInAction = this.getMemberInAction(classroomId, userId)

//check if user exists in the classroom
if (!memberInAction) {
Expand Down Expand Up @@ -155,7 +159,7 @@ export default class ClassroomService {
//update member role
return this.prismaService.classroomMember.update({
where: { classroomId, userId },
data: { classroomRole: role.toUpperCase() },
data: { classroomRole: role },
})
}

Expand All @@ -165,9 +169,7 @@ export default class ClassroomService {
memberId: string) {

//get member who tries to remove someone from the classroom
const memberInAction = await this.prismaService.classroomMember.findUnique({
where: { classroomId, userId },
})
const memberInAction = this.getMemberInAction(classroomId, userId)

//check if member exists in the classroom
if (!memberInAction) {
Expand Down

0 comments on commit 4c6f82a

Please sign in to comment.