Skip to content

Commit

Permalink
add schoolId to room
Browse files Browse the repository at this point in the history
  • Loading branch information
uidp committed Nov 11, 2024
1 parent 2a92516 commit a6db175
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<RoomCreateProps, 'schoolId'> {
@ApiProperty({
description: 'The name of the room',
required: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ export class RoomDetailsResponse {
@IsEnum(RoomColor)
color: RoomColor;

@ApiProperty()
schoolId: string;

@ApiPropertyOptional({ type: Date })
startDate?: Date;

Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ export class RoomItemResponse {
@IsEnum(RoomColor)
color: RoomColor;

@ApiProperty()
schoolId: string;

@ApiPropertyOptional({ type: Date })
startDate?: Date;

Expand All @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions apps/server/src/modules/room/api/mapper/room.mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
10 changes: 6 additions & 4 deletions apps/server/src/modules/room/api/room.uc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -31,11 +33,11 @@ export class RoomUc {
return rooms;
}

public async createRoom(userId: EntityId, props: RoomCreateProps): Promise<Room> {
public async createRoom(userId: EntityId, props: CreateRoomBodyParams): Promise<Room> {
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
Expand Down Expand Up @@ -72,7 +74,7 @@ export class RoomUc {
return boards;
}

public async updateRoom(userId: EntityId, roomId: EntityId, props: RoomUpdateProps): Promise<Room> {
public async updateRoom(userId: EntityId, roomId: EntityId, props: UpdateRoomBodyParams): Promise<Room> {
this.checkFeatureEnabled();
const room = await this.roomService.getSingleRoom(roomId);

Expand Down
1 change: 1 addition & 0 deletions apps/server/src/modules/room/api/test/room-get.api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
2 changes: 2 additions & 0 deletions apps/server/src/modules/room/api/test/room-index.api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down
9 changes: 7 additions & 2 deletions apps/server/src/modules/room/domain/do/room.do.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<RoomProps, 'name' | 'color' | 'startDate' | 'endDate'>;
export type RoomUpdateProps = RoomCreateProps; // will probably change in the future
export type RoomCreateProps = Pick<RoomProps, 'name' | 'color' | 'startDate' | 'endDate' | 'schoolId'>;
export type RoomUpdateProps = Omit<RoomCreateProps, 'schoolId'>;

export class Room extends DomainObject<RoomProps> {
public constructor(props: RoomProps) {
Expand Down Expand Up @@ -48,6 +49,10 @@ export class Room extends DomainObject<RoomProps> {
this.props.color = value;
}

public get schoolId(): EntityId {
return this.props.schoolId;
}

public get startDate(): Date | undefined {
return this.props.startDate;
}
Expand Down
5 changes: 5 additions & 0 deletions apps/server/src/modules/room/repo/entity/room.entity.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const roomEntityFactory = EntityFactory.define<RoomEntity, RoomProps>(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(),
Expand Down
1 change: 1 addition & 0 deletions apps/server/src/modules/room/testing/room.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const roomFactory = BaseFactory.define<Room, RoomProps>(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(),
Expand Down

0 comments on commit a6db175

Please sign in to comment.