Skip to content

Commit f45aee8

Browse files
authored
Merge pull request #319 from tmddus2/fix/240325-mongoose-type-error
Fix(#320): Mongoose Schema 속성 νƒ€μž… Uint8Array 지원 μ•ˆ ν•˜λŠ” 문제 ν•΄κ²°
2 parents 53f5e46 + 3516cab commit f45aee8

7 files changed

+23
-10
lines changed

β€Žbackend/src/lecture/dto/response/response-lecture-record.dto.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { ApiProperty } from '@nestjs/swagger';
22
import { WhiteboardEventDto } from '../whiteboard-event.dto';
33
import { Subtitle } from '../../interfaces/Subtitle';
4+
import { WhiteboardLog } from 'src/lecture/schema/whiteboard-log.schema';
45

56
export class LectureRecordDto {
67
@ApiProperty()
@@ -12,8 +13,8 @@ export class LectureRecordDto {
1213
@ApiProperty()
1314
audio_file: string;
1415

15-
constructor(logs: WhiteboardEventDto[], subtitles: [Subtitle], audio_file: string) {
16-
this.logs = logs;
16+
constructor(logs: WhiteboardLog[], subtitles: [Subtitle], audio_file: string) {
17+
this.logs = logs.map((log) => new WhiteboardEventDto(log));
1718
this.subtitles = subtitles;
1819
this.audio_file = audio_file;
1920
}

β€Žbackend/src/lecture/dto/whiteboard-event.dto.ts

+12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { WhiteboardLog } from "../schema/whiteboard-log.schema";
2+
13
export class WhiteboardEventDto {
24
objects: Uint8Array;
35

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

1012
height: number;
13+
14+
constructor(log?: WhiteboardLog) {
15+
if (log) {
16+
this.objects = new Uint8Array(log.objects);
17+
this.viewport = log.viewport;
18+
this.eventTime = log.eventTime;
19+
this.width = log.width;
20+
this.height = log.height;
21+
}
22+
}
1123
}

β€Žbackend/src/lecture/lecture.controller.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export class LectureController {
107107
if (!enterCodeDocument) {
108108
throw new HttpException('ν•΄λ‹Ή κ°•μ˜κ°€ μ—†μŠ΅λ‹ˆλ‹€.', HttpStatus.NOT_FOUND);
109109
}
110-
110+
111111
await this.lectureService.saveWhiteBoardLog(enterCodeDocument.lecture_id, whiteboardEventDto);
112112
res.status(HttpStatus.CREATED).send();
113113
}

β€Žbackend/src/lecture/lecture.module.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Module } from '@nestjs/common';
22
import { MongooseModule } from '@nestjs/mongoose';
33
import { User, UserSchema } from 'src/user/user.schema';
44
import { UserService } from 'src/user/user.service';
5-
import { LectureSubtitle, LectureSubtitleSchema } from './lecture-subtitle.schema';
5+
import { LectureSubtitle, LectureSubtitleSchema } from './schema/lecture-subtitle.schema';
66
import { LectureController } from './lecture.controller';
77
import { Lecture, LectureSchema } from './schema/lecture.schema';
88
import { LectureService } from './lecture.service';

β€Žbackend/src/lecture/lecture.service.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { CreateLectureDto } from './dto/create-lecture.dto';
55
import { UpdateLectureDto } from './dto/update-lecture.dto';
66
import { WhiteboardLog } from './schema/whiteboard-log.schema';
77
import { WhiteboardEventDto } from './dto/whiteboard-event.dto';
8-
import { LectureSubtitle } from './lecture-subtitle.schema';
8+
import { LectureSubtitle } from './schema/lecture-subtitle.schema';
99
import { Lecture } from './schema/lecture.schema';
1010
import { EnterCode } from './schema/lecture-code.schema';
1111
import { generateRandomNumber } from 'src/utils/GenerateUtils';
@@ -71,7 +71,7 @@ export class LectureService {
7171

7272
async saveWhiteBoardLog(lecture: Lecture, whiteboardEventDto: WhiteboardEventDto) {
7373
const whiteboardLog = new this.whiteboardLogModel({
74-
objects: whiteboardEventDto.objects,
74+
objects: whiteboardEventDto.objects['data'],
7575
viewport: whiteboardEventDto.viewport,
7676
eventTime: whiteboardEventDto.eventTime,
7777
width: whiteboardEventDto.width,
@@ -102,7 +102,7 @@ export class LectureService {
102102
async findLectureRecord(id: Types.ObjectId) {
103103
const lecture = await this.lectureModel.findById(id).exec();
104104
const logs = await this.findLogs(lecture);
105-
const subtitles = (await this.lectureSubtitleModel.findOne({ lecture_id: lecture }).exec()).subtitle;
105+
const subtitles = (await this.lectureSubtitleModel.findOne({ lecture_id: lecture }).exec())?.subtitle;
106106
const audioFile = lecture.audio_file;
107107
return new LectureRecordDto(logs, subtitles, audioFile);
108108
}

β€Žbackend/src/lecture/lecture-subtitle.schema.ts renamed to β€Žbackend/src/lecture/schema/lecture-subtitle.schema.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
22
import mongoose from 'mongoose';
3-
import { Subtitle } from './interfaces/Subtitle';
4-
import { Lecture } from './schema/lecture.schema';
3+
import { Subtitle } from '../interfaces/Subtitle';
4+
import { Lecture } from './lecture.schema';
55

66
@Schema()
77
export class LectureSubtitle {

β€Žbackend/src/lecture/schema/whiteboard-log.schema.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export type WhiteBoardLogDocument = HydratedDocument<WhiteboardLog>;
77
@Schema()
88
export class WhiteboardLog {
99
@Prop({ required: true })
10-
objects: Uint8Array;
10+
objects: number[];
1111

1212
@Prop({ required: true })
1313
viewport: number[];

0 commit comments

Comments
Β (0)