Sync LMS backend source
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import { Controller, Get, Param, Query, Req, Res } from '@nestjs/common';
|
||||
import { Request, Response } from 'express';
|
||||
|
||||
import { CurriculumService } from './curriculum.service';
|
||||
|
||||
@Controller('curriculum')
|
||||
export class CurriculumController {
|
||||
constructor(private readonly curriculumService: CurriculumService) {}
|
||||
|
||||
@Get()
|
||||
getActiveCurriculum(@Req() request: Request, @Query('courseId') courseId?: string) {
|
||||
return this.curriculumService.getActiveCurriculum(
|
||||
this.getBearerToken(request),
|
||||
courseId,
|
||||
);
|
||||
}
|
||||
|
||||
@Get('courses')
|
||||
listCourses(@Req() request: Request) {
|
||||
return this.curriculumService.listCourses(this.getBearerToken(request));
|
||||
}
|
||||
|
||||
@Get('references/:referenceId/download')
|
||||
async downloadReference(
|
||||
@Req() request: Request,
|
||||
@Param('referenceId') referenceId: string,
|
||||
@Res() response: Response,
|
||||
) {
|
||||
const download = await this.curriculumService.getReferenceDownload(
|
||||
this.getBearerToken(request),
|
||||
referenceId,
|
||||
);
|
||||
response.setHeader('content-type', download.contentType);
|
||||
return response.download(download.path, download.fileName);
|
||||
}
|
||||
|
||||
private getBearerToken(request: Request): string | undefined {
|
||||
const [type, token] = request.headers.authorization?.split(' ') ?? [];
|
||||
return type === 'Bearer' ? token : undefined;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user