Skip to content

Commit

Permalink
Merge pull request #319 from tmddus2/fix/240325-mongoose-type-error
Browse files Browse the repository at this point in the history
Fix(#320): Mongoose Schema 속성 νƒ€μž… Uint8Array 지원 μ•ˆ ν•˜λŠ” 문제 ν•΄κ²°
  • Loading branch information
platinouss authored Apr 6, 2024
2 parents 53f5e46 + 3516cab commit f45aee8
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ApiProperty } from '@nestjs/swagger';
import { WhiteboardEventDto } from '../whiteboard-event.dto';
import { Subtitle } from '../../interfaces/Subtitle';
import { WhiteboardLog } from 'src/lecture/schema/whiteboard-log.schema';

export class LectureRecordDto {
@ApiProperty()
Expand All @@ -12,8 +13,8 @@ export class LectureRecordDto {
@ApiProperty()
audio_file: string;

constructor(logs: WhiteboardEventDto[], subtitles: [Subtitle], audio_file: string) {
this.logs = logs;
constructor(logs: WhiteboardLog[], subtitles: [Subtitle], audio_file: string) {
this.logs = logs.map((log) => new WhiteboardEventDto(log));
this.subtitles = subtitles;
this.audio_file = audio_file;
}
Expand Down
12 changes: 12 additions & 0 deletions backend/src/lecture/dto/whiteboard-event.dto.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { WhiteboardLog } from "../schema/whiteboard-log.schema";

export class WhiteboardEventDto {
objects: Uint8Array;

Expand All @@ -8,4 +10,14 @@ export class WhiteboardEventDto {
width: number;

height: number;

constructor(log?: WhiteboardLog) {
if (log) {
this.objects = new Uint8Array(log.objects);
this.viewport = log.viewport;
this.eventTime = log.eventTime;
this.width = log.width;
this.height = log.height;
}
}
}
2 changes: 1 addition & 1 deletion backend/src/lecture/lecture.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export class LectureController {
if (!enterCodeDocument) {
throw new HttpException('ν•΄λ‹Ή κ°•μ˜κ°€ μ—†μŠ΅λ‹ˆλ‹€.', HttpStatus.NOT_FOUND);
}

await this.lectureService.saveWhiteBoardLog(enterCodeDocument.lecture_id, whiteboardEventDto);
res.status(HttpStatus.CREATED).send();
}
Expand Down
2 changes: 1 addition & 1 deletion backend/src/lecture/lecture.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Module } from '@nestjs/common';
import { MongooseModule } from '@nestjs/mongoose';
import { User, UserSchema } from 'src/user/user.schema';
import { UserService } from 'src/user/user.service';
import { LectureSubtitle, LectureSubtitleSchema } from './lecture-subtitle.schema';
import { LectureSubtitle, LectureSubtitleSchema } from './schema/lecture-subtitle.schema';
import { LectureController } from './lecture.controller';
import { Lecture, LectureSchema } from './schema/lecture.schema';
import { LectureService } from './lecture.service';
Expand Down
6 changes: 3 additions & 3 deletions backend/src/lecture/lecture.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { CreateLectureDto } from './dto/create-lecture.dto';
import { UpdateLectureDto } from './dto/update-lecture.dto';
import { WhiteboardLog } from './schema/whiteboard-log.schema';
import { WhiteboardEventDto } from './dto/whiteboard-event.dto';
import { LectureSubtitle } from './lecture-subtitle.schema';
import { LectureSubtitle } from './schema/lecture-subtitle.schema';
import { Lecture } from './schema/lecture.schema';
import { EnterCode } from './schema/lecture-code.schema';
import { generateRandomNumber } from 'src/utils/GenerateUtils';
Expand Down Expand Up @@ -71,7 +71,7 @@ export class LectureService {

async saveWhiteBoardLog(lecture: Lecture, whiteboardEventDto: WhiteboardEventDto) {
const whiteboardLog = new this.whiteboardLogModel({
objects: whiteboardEventDto.objects,
objects: whiteboardEventDto.objects['data'],
viewport: whiteboardEventDto.viewport,
eventTime: whiteboardEventDto.eventTime,
width: whiteboardEventDto.width,
Expand Down Expand Up @@ -102,7 +102,7 @@ export class LectureService {
async findLectureRecord(id: Types.ObjectId) {
const lecture = await this.lectureModel.findById(id).exec();
const logs = await this.findLogs(lecture);
const subtitles = (await this.lectureSubtitleModel.findOne({ lecture_id: lecture }).exec()).subtitle;
const subtitles = (await this.lectureSubtitleModel.findOne({ lecture_id: lecture }).exec())?.subtitle;
const audioFile = lecture.audio_file;
return new LectureRecordDto(logs, subtitles, audioFile);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import mongoose from 'mongoose';
import { Subtitle } from './interfaces/Subtitle';
import { Lecture } from './schema/lecture.schema';
import { Subtitle } from '../interfaces/Subtitle';
import { Lecture } from './lecture.schema';

@Schema()
export class LectureSubtitle {
Expand Down
2 changes: 1 addition & 1 deletion backend/src/lecture/schema/whiteboard-log.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export type WhiteBoardLogDocument = HydratedDocument<WhiteboardLog>;
@Schema()
export class WhiteboardLog {
@Prop({ required: true })
objects: Uint8Array;
objects: number[];

@Prop({ required: true })
viewport: number[];
Expand Down

0 comments on commit f45aee8

Please sign in to comment.