Skip to content

Commit

Permalink
Merge branch 'main' into EW-1061
Browse files Browse the repository at this point in the history
  • Loading branch information
psachmann authored Jan 20, 2025
2 parents b4ac067 + c7ab954 commit 514007b
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { ApiProperty } from '@nestjs/swagger';
import { RoomMemberResponse } from './room-member.response';

export class RoomMemberListResponse {
constructor(data: RoomMemberResponse[]) {
this.data = data;
}

@ApiProperty({ type: [RoomMemberResponse] })
public data: RoomMemberResponse[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,29 @@ import { RoleName } from '@shared/domain/interface';

export class RoomMemberResponse {
@ApiProperty()
firstName!: string;
public firstName!: string;

@ApiProperty()
lastName!: string;
public lastName!: string;

@ApiProperty()
roleName!: RoleName;
public roomRoleName!: RoleName;

@ApiProperty()
schoolName!: string;
public schoolRoleName!: RoleName;

@ApiProperty()
userId!: string;
public schoolName!: string;

@ApiProperty()
public userId!: string;

constructor(props: RoomMemberResponse) {
this.userId = props.userId;
this.firstName = props.firstName;
this.lastName = props.lastName;
this.roleName = props.roleName;
this.roomRoleName = props.roomRoleName;
this.schoolRoleName = props.schoolRoleName;
this.schoolName = props.schoolName;
}
}

export class RoomMemberListResponse {
constructor(data: RoomMemberResponse[]) {
this.data = data;
}

@ApiProperty({ type: [RoomMemberResponse] })
data: RoomMemberResponse[];
}
2 changes: 1 addition & 1 deletion apps/server/src/modules/room/api/room.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ import { RoomBoardListResponse } from './dto/response/room-board-list.response';
import { RoomDetailsResponse } from './dto/response/room-details.response';
import { RoomItemResponse } from './dto/response/room-item.response';
import { RoomListResponse } from './dto/response/room-list.response';
import { RoomMemberListResponse } from './dto/response/room-member.response';
import { RoomMapper } from './mapper/room.mapper';
import { RoomUc } from './room.uc';
import { RoomMemberListResponse } from './dto/response/room-member-list.response';

@ApiTags('Room')
@JwtAuthentication()
Expand Down
3 changes: 2 additions & 1 deletion apps/server/src/modules/room/api/room.uc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ export class RoomUc {
userId: member.userId,
firstName: user.firstName,
lastName: user.lastName,
roleName: member.roles[0].name,
roomRoleName: member.roles[0].name,
schoolRoleName: user.roles[0].name,
schoolName: user.schoolName ?? '',
});
}
Expand Down
32 changes: 26 additions & 6 deletions apps/server/src/modules/room/api/test/room-members.api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { UserAndAccountTestFactory } from '@testing/factory/user-and-account.tes
import { userFactory } from '@testing/factory/user.factory';
import { TestApiClient } from '@testing/test-api-client';
import { roomEntityFactory } from '../../testing/room-entity.factory';
import { RoomMemberListResponse } from '../dto/response/room-member.response';
import { RoomMemberListResponse } from '../dto/response/room-member-list.response';

describe('Room Controller (API)', () => {
let app: INestApplication;
Expand Down Expand Up @@ -57,8 +57,10 @@ describe('Room Controller (API)', () => {
name: RoleName.ROOMVIEWER,
permissions: [Permission.ROOM_VIEW],
});
const students = userFactory.buildList(2, { school });
const teachers = userFactory.buildList(2, { school });
const teacherRole = teacherUser.roles[0];
const studentRole = roleFactory.buildWithId({ name: RoleName.STUDENT });
const students = userFactory.buildList(2, { school, roles: [studentRole] });
const teachers = userFactory.buildList(2, { school, roles: [teacherRole] });
const userGroupEntity = groupEntityFactory.buildWithId({
users: [
{ role: editRole, user: teacherUser },
Expand Down Expand Up @@ -138,12 +140,30 @@ describe('Room Controller (API)', () => {
expect(response.status).toBe(HttpStatus.OK);
const body = response.body as RoomMemberListResponse;
expect(body.data.length).toEqual(5);
expect(body.data).toContainEqual(expect.objectContaining({ userId: teacherUser.id, roleName: editRole.name }));
expect(body.data).toContainEqual(
expect.objectContaining({
userId: teacherUser.id,
roomRoleName: editRole.name,
schoolRoleName: RoleName.TEACHER,
})
);
students.forEach((student) => {
expect(body.data).toContainEqual(expect.objectContaining({ userId: student.id, roleName: viewerRole.name }));
expect(body.data).toContainEqual(
expect.objectContaining({
userId: student.id,
roomRoleName: viewerRole.name,
schoolRoleName: RoleName.STUDENT,
})
);
});
teachers.forEach((teacher) => {
expect(body.data).toContainEqual(expect.objectContaining({ userId: teacher.id, roleName: editRole.name }));
expect(body.data).toContainEqual(
expect.objectContaining({
userId: teacher.id,
roomRoleName: editRole.name,
schoolRoleName: RoleName.TEACHER,
})
);
});
});
});
Expand Down

0 comments on commit 514007b

Please sign in to comment.