Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BC-8545 - add school role to RoomMemberList #5441

Merged
merged 3 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading