message: Changes promise chains to async / await
diff: @@ -4,12 +4,12 @@ import {
  } from 'routing-controllers';
  import passportJwtMiddleware from '../security/passportJwtMiddleware';
  import {IUnit} from '../../../shared/models/units/IUnit';
  -import {Lecture} from '../models/Lecture';
  -import {ILecture} from '../../../shared/models/ILecture';
  +import {ILectureModel, Lecture} from '../models/Lecture';
  import {IUnitModel, Unit} from '../models/units/Unit';
  -import {ICourse} from '../../../shared/models/ICourse';
  -import {Course} from '../models/Course';
  +import {Course, ICourseModel} from '../models/Course';
  import {UnitClassMapper} from '../utilities/UnitClassMapper';
  +import {ILecture} from '../../../shared/models/ILecture';
  +import {ICourse} from '../../../shared/models/ICourse';
  @JsonController('/duplicate')
  @@ -18,35 +18,31 @@ import {UnitClassMapper} from '../utilities/UnitClassMapper';
  export class DuplicationController {
  @Post('/course/:id')
  - duplicateCourse(@Param('id') id: string, @Body() data: any, @Req() request: Request) {
  + async duplicateCourse(@Param('id') id: string, @Body() data: any, @Req() request: Request) {
  const courseAdmin = data.courseAdmin;
  - return Course.findById(id)
  - .then((course: ICourse) => {
  - return new Course(course).exportJSON();
  - }).then((exportedCourse: ICourse) => {
  + try {
  + const courseModel: ICourseModel = await Course.findById(id);
  + const exportedCourse: ICourse = await courseModel.exportJSON();
  return Course.prototype.importJSON(exportedCourse, courseAdmin);
  - })
  - .catch((err: Error) => {
  + } catch (err) {
  const newError = new InternalServerError('Failed to duplicate course');
  newError.stack += '\nCaused by: ' + err.message + '\n' + err.stack;
  throw newError;
  - });
  + }
  }
  @Post('/lecture/:id')
  - duplicateLecture(@Param('id') id: string, @Body() data: any, @Req() request: Request) {
  + async duplicateLecture(@Param('id') id: string, @Body() data: any, @Req() request: Request) {
  const courseId = data.courseId;
  - return Lecture.findById(id)
  - .then((lecture: ILecture) => {
  - return new Lecture(lecture).exportJSON();
  - }).then((exportedLecture: ILecture) => {
  + try {
  + const lectureModel: ILectureModel = await Lecture.findById(id);
  + const exportedLecture: ILecture = await lectureModel.exportJSON();
  return Lecture.prototype.importJSON(exportedLecture, courseId);
  - })
  - .catch((err: Error) => {
  + } catch (err) {
  const newError = new InternalServerError('Failed to duplicate lecture');
  newError.stack += '\nCaused by: ' + err.message + '\n' + err.stack;
  throw newError;
  - });
  + }
  }
  @Post('/unit/:id')
  