Skip to content

Commit

Permalink
map result create video to video dto
Browse files Browse the repository at this point in the history
  • Loading branch information
jorodragon committed Jul 12, 2021
1 parent 5456168 commit 69b1415
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/server/src/modules/video/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class VideoController implements CrudController<Video> {
@Post()
async create(
@Body() createVideoDto: VideoCreationDTO,
): Promise<VideoCreationDTO> {
): Promise<VideoDTO> {
try {
return await this.service.create(createVideoDto);
} catch (error) {
Expand Down
9 changes: 5 additions & 4 deletions packages/server/src/modules/video/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class VideosService extends TypeOrmCrudService<Video> {
super(videoRepository);
}

async create(createVideoDto: VideoCreationDTO): Promise<VideoCreationDTO> {
async create(createVideoDto: VideoCreationDTO): Promise<VideoDTO> {
try {
if (!createVideoDto.courseId)
throw new BadRequestException('Invalid courseId');
Expand All @@ -42,10 +42,12 @@ export class VideosService extends TypeOrmCrudService<Video> {

if (!course) throw new BadRequestException('Course is not exist');

return await this.videoRepository.save({
const video = await this.videoRepository.save({
...createVideoDto,
course,
});

return mapVideoToVideoDTO(video);
} catch (error) {
this.logger.error(error);
catchError(error);
Expand All @@ -54,8 +56,7 @@ export class VideosService extends TypeOrmCrudService<Video> {

async findByCourseId(courseId: string): Promise<VideoDTO[]> {
try {
if (!courseId)
throw new BadRequestException('Invalid courseId');
if (!courseId) throw new BadRequestException('Invalid courseId');

const course = await this.coursesService.findOne(courseId);

Expand Down

0 comments on commit 69b1415

Please sign in to comment.