diff --git a/apps/server/src/modules/room/api/dto/request/create-room.body.params.ts b/apps/server/src/modules/room/api/dto/request/create-room.body.params.ts index 286abeba50c..d21d64fd10a 100644 --- a/apps/server/src/modules/room/api/dto/request/create-room.body.params.ts +++ b/apps/server/src/modules/room/api/dto/request/create-room.body.params.ts @@ -4,7 +4,7 @@ import { RoomCreateProps } from '@src/modules/room/domain'; import { RoomColor } from '@src/modules/room/domain/type'; import { IsDate, IsEnum, IsOptional, IsString, MaxLength, MinLength } from 'class-validator'; -export class CreateRoomBodyParams implements RoomCreateProps { +export class CreateRoomBodyParams implements Omit { @ApiProperty({ description: 'The name of the room', required: true, diff --git a/apps/server/src/modules/room/api/dto/response/room-details.response.ts b/apps/server/src/modules/room/api/dto/response/room-details.response.ts index f0d39b68284..197c1763206 100644 --- a/apps/server/src/modules/room/api/dto/response/room-details.response.ts +++ b/apps/server/src/modules/room/api/dto/response/room-details.response.ts @@ -13,6 +13,9 @@ export class RoomDetailsResponse { @IsEnum(RoomColor) color: RoomColor; + @ApiProperty() + schoolId: string; + @ApiPropertyOptional({ type: Date }) startDate?: Date; @@ -29,6 +32,7 @@ export class RoomDetailsResponse { this.id = room.id; this.name = room.name; this.color = room.color; + this.schoolId = room.schoolId; this.startDate = room.startDate; this.endDate = room.endDate; diff --git a/apps/server/src/modules/room/api/dto/response/room-item.response.ts b/apps/server/src/modules/room/api/dto/response/room-item.response.ts index 88b13ec3dab..3c8bffded23 100644 --- a/apps/server/src/modules/room/api/dto/response/room-item.response.ts +++ b/apps/server/src/modules/room/api/dto/response/room-item.response.ts @@ -13,6 +13,9 @@ export class RoomItemResponse { @IsEnum(RoomColor) color: RoomColor; + @ApiProperty() + schoolId: string; + @ApiPropertyOptional({ type: Date }) startDate?: Date; @@ -29,6 +32,7 @@ export class RoomItemResponse { this.id = room.id; this.name = room.name; this.color = room.color; + this.schoolId = room.schoolId; this.startDate = room.startDate; this.endDate = room.endDate; diff --git a/apps/server/src/modules/room/api/mapper/room.mapper.ts b/apps/server/src/modules/room/api/mapper/room.mapper.ts index 02fd43a659f..4b69e2a34ef 100644 --- a/apps/server/src/modules/room/api/mapper/room.mapper.ts +++ b/apps/server/src/modules/room/api/mapper/room.mapper.ts @@ -14,6 +14,7 @@ export class RoomMapper { id: room.id, name: room.name, color: room.color, + schoolId: room.schoolId, startDate: room.startDate, endDate: room.endDate, createdAt: room.createdAt, @@ -37,6 +38,7 @@ export class RoomMapper { id: room.id, name: room.name, color: room.color, + schoolId: room.schoolId, startDate: room.startDate, endDate: room.endDate, createdAt: room.createdAt, diff --git a/apps/server/src/modules/room/api/room.uc.ts b/apps/server/src/modules/room/api/room.uc.ts index 1691df897a9..d7b5ef8e3a1 100644 --- a/apps/server/src/modules/room/api/room.uc.ts +++ b/apps/server/src/modules/room/api/room.uc.ts @@ -8,8 +8,10 @@ import { Page, UserDO } from '@shared/domain/domainobject'; import { IFindOptions, Permission, RoleName, RoomRole } from '@shared/domain/interface'; import { EntityId } from '@shared/domain/types'; import { BoardExternalReferenceType, ColumnBoard, ColumnBoardService } from '@src/modules/board'; -import { Room, RoomCreateProps, RoomService, RoomUpdateProps } from '../domain'; +import { Room, RoomService } from '../domain'; import { RoomConfig } from '../room.config'; +import { CreateRoomBodyParams } from './dto/request/create-room.body.params'; +import { UpdateRoomBodyParams } from './dto/request/update-room.body.params'; import { RoomMemberResponse } from './dto/response/room-member.response'; @Injectable() @@ -31,11 +33,11 @@ export class RoomUc { return rooms; } - public async createRoom(userId: EntityId, props: RoomCreateProps): Promise { + public async createRoom(userId: EntityId, props: CreateRoomBodyParams): Promise { this.checkFeatureEnabled(); const user = await this.authorizationService.getUserWithPermissions(userId); - const room = await this.roomService.createRoom(props); + const room = await this.roomService.createRoom({ ...props, schoolId: user.school.id }); // NOTE: currently only teacher are allowed to create rooms. Could not find simpler way to check this. this.authorizationService.checkOneOfPermissions(user, [Permission.COURSE_CREATE]); await this.roomMemberService @@ -72,7 +74,7 @@ export class RoomUc { return boards; } - public async updateRoom(userId: EntityId, roomId: EntityId, props: RoomUpdateProps): Promise { + public async updateRoom(userId: EntityId, roomId: EntityId, props: UpdateRoomBodyParams): Promise { this.checkFeatureEnabled(); const room = await this.roomService.getSingleRoom(roomId); diff --git a/apps/server/src/modules/room/api/test/room-get.api.spec.ts b/apps/server/src/modules/room/api/test/room-get.api.spec.ts index fe842db3d7f..ef4b1462ebb 100644 --- a/apps/server/src/modules/room/api/test/room-get.api.spec.ts +++ b/apps/server/src/modules/room/api/test/room-get.api.spec.ts @@ -114,6 +114,7 @@ describe('Room Controller (API)', () => { id: room.id, name: room.name, color: room.color, + schoolId: room.schoolId, startDate: room.startDate?.toISOString(), endDate: room.endDate?.toISOString(), createdAt: room.createdAt.toISOString(), diff --git a/apps/server/src/modules/room/api/test/room-index.api.spec.ts b/apps/server/src/modules/room/api/test/room-index.api.spec.ts index ca0a1c22658..e43d1ef113f 100644 --- a/apps/server/src/modules/room/api/test/room-index.api.spec.ts +++ b/apps/server/src/modules/room/api/test/room-index.api.spec.ts @@ -86,6 +86,7 @@ describe('Room Controller (API)', () => { id: room.id, name: room.name, color: room.color, + schoolId: room.schoolId, startDate: room.startDate?.toISOString(), endDate: room.endDate?.toISOString(), createdAt: room.createdAt.toISOString(), @@ -152,6 +153,7 @@ describe('Room Controller (API)', () => { id: room.id, name: room.name, color: room.color, + schoolId: room.schoolId, startDate: room.startDate?.toISOString(), endDate: room.endDate?.toISOString(), createdAt: room.createdAt.toISOString(), diff --git a/apps/server/src/modules/room/domain/do/room.do.ts b/apps/server/src/modules/room/domain/do/room.do.ts index 05feb9d07d4..e5ee61ad6da 100644 --- a/apps/server/src/modules/room/domain/do/room.do.ts +++ b/apps/server/src/modules/room/domain/do/room.do.ts @@ -9,12 +9,13 @@ export interface RoomProps extends AuthorizableObject { color: RoomColor; startDate?: Date; endDate?: Date; + schoolId: EntityId; createdAt: Date; updatedAt: Date; } -export type RoomCreateProps = Pick; -export type RoomUpdateProps = RoomCreateProps; // will probably change in the future +export type RoomCreateProps = Pick; +export type RoomUpdateProps = Omit; export class Room extends DomainObject { public constructor(props: RoomProps) { @@ -48,6 +49,10 @@ export class Room extends DomainObject { this.props.color = value; } + public get schoolId(): EntityId { + return this.props.schoolId; + } + public get startDate(): Date | undefined { return this.props.startDate; } diff --git a/apps/server/src/modules/room/repo/entity/room.entity.ts b/apps/server/src/modules/room/repo/entity/room.entity.ts index 3a174be1d9d..a44cf367482 100644 --- a/apps/server/src/modules/room/repo/entity/room.entity.ts +++ b/apps/server/src/modules/room/repo/entity/room.entity.ts @@ -1,5 +1,7 @@ import { Entity, Property } from '@mikro-orm/core'; import { BaseEntityWithTimestamps } from '@shared/domain/entity/base.entity'; +import { EntityId } from '@shared/domain/types'; +import { ObjectIdType } from '@shared/repo/types/object-id.type'; import { Room, RoomProps } from '../../domain/do/room.do'; import { RoomColor } from '../../domain/type'; @@ -11,6 +13,9 @@ export class RoomEntity extends BaseEntityWithTimestamps implements RoomProps { @Property({ nullable: false }) color!: RoomColor; + @Property({ type: ObjectIdType, nullable: false }) + schoolId!: EntityId; + @Property({ nullable: true }) startDate?: Date; diff --git a/apps/server/src/modules/room/testing/room-entity.factory.ts b/apps/server/src/modules/room/testing/room-entity.factory.ts index fee0b2c80b0..ad2e979750e 100644 --- a/apps/server/src/modules/room/testing/room-entity.factory.ts +++ b/apps/server/src/modules/room/testing/room-entity.factory.ts @@ -9,6 +9,7 @@ export const roomEntityFactory = EntityFactory.define(Roo id: new ObjectId().toHexString(), name: `room #${sequence}`, color: [RoomColor.BLUE, RoomColor.RED, RoomColor.GREEN, RoomColor.MAGENTA][Math.floor(Math.random() * 4)], + schoolId: new ObjectId().toHexString(), startDate: new Date(), endDate: new Date(Date.now() + 1000 * 60 * 60 * 24 * 7), createdAt: new Date(), diff --git a/apps/server/src/modules/room/testing/room.factory.ts b/apps/server/src/modules/room/testing/room.factory.ts index 099c98b831c..7f1ef879488 100644 --- a/apps/server/src/modules/room/testing/room.factory.ts +++ b/apps/server/src/modules/room/testing/room.factory.ts @@ -8,6 +8,7 @@ export const roomFactory = BaseFactory.define(Room, ({ sequence id: new ObjectId().toHexString(), name: `room #${sequence}`, color: [RoomColor.BLUE, RoomColor.RED, RoomColor.GREEN, RoomColor.MAGENTA][Math.floor(Math.random() * 4)], + schoolId: new ObjectId().toHexString(), startDate: new Date(), createdAt: new Date(), updatedAt: new Date(),