Skip to content

Commit

Permalink
CoursesUserController.getCourseUserByUserId endpoint created
Browse files Browse the repository at this point in the history
  • Loading branch information
Attila Cseh committed Dec 27, 2024
1 parent 75dece4 commit 10652ee
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/course-user/course-user.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { CourseUserEntity } from 'src/entities/course-user.entity';
import { CourseUserService } from './course-user.service';
import { CoursesUserController } from './courses-user.controller';

@Module({
imports: [TypeOrmModule.forFeature([CourseUserEntity])],
controllers: [CoursesUserController],
providers: [CourseUserService],
})
export class CourseUserModule {}
28 changes: 28 additions & 0 deletions src/course-user/courses-user.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Controller, Get, Req, UseGuards } from '@nestjs/common';
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
import { ICoursesWithSessions } from 'src/course/course.interface';
import { UserEntity } from 'src/entities/user.entity';
import { ControllerDecorator } from 'src/utils/controller.decorator';
import { FirebaseAuthGuard } from '../firebase/firebase-auth.guard';
import { formatCourseUserObjects } from '../utils/serialize';
import { CourseUserService } from './course-user.service';

@ApiTags('Courses User')
@ControllerDecorator()
@Controller('/v1/courses-user')
export class CoursesUserController {
constructor(private readonly courseUserService: CourseUserService) {}

@Get()
@ApiBearerAuth('access-token')
@ApiOperation({
description:
'Returns user courses and session data.',
})
@UseGuards(FirebaseAuthGuard)
async getCourseUserByUserId(@Req() req: Request) : Promise<ICoursesWithSessions[]> {
const user = req['userEntity'] as UserEntity;
const coursesUser = await this.courseUserService.getCourseUserByUserId(user.id);
return formatCourseUserObjects(coursesUser);
}
}

0 comments on commit 10652ee

Please sign in to comment.