import { Authorized , CurrentUser , JsonController , Param , Post , UploadedFile , UseBefore } from 'routing-controllers' ; import passportJwtMiddleware from '../security/passportJwtMiddleware' ; import { Course } from '../models/Course' ; import { Lecture } from '../models/Lecture' ; import { Unit } from '../models/units/Unit' ; import { IUser } from '../../../shared/models/IUser' ; @ JsonController ( '/import' ) @ UseBefore ( passportJwtMiddleware ) @ Authorized ( [ 'teacher' , 'admin' ] ) export class ImportController { api apiName apiGroup apiPermission apiPermission apiParam apiParam apiSuccess apiSuccessExample @ Post ( '/course' ) async importCourse ( @ UploadedFile ( 'file' ) file , @ CurrentUser ( ) user ) { const courseDesc = JSON . parse ( file . buffer . toString ( ) ) ; return await Course . schema . statics . importJSON ( courseDesc , user ) ; } api apiName apiGroup apiPermission apiPermission apiParam apiParam apiSuccess apiSuccessExample @ Post ( '/lecture/:course' ) async importLecture ( @ UploadedFile ( 'file' ) file , @ Param ( 'course' ) courseId ) { const lectureDesc = JSON . parse ( file . buffer . toString ( ) ) ; return Lecture . schema . statics . importJSON ( lectureDesc , courseId ) ; } api apiName apiGroup apiPermission apiPermission apiParam apiParam apiParam apiSuccess apiSuccessExample @ Post ( '/unit/:course/:lecture' ) async importUnit ( @ UploadedFile ( 'file' ) file , @ Param ( 'course' ) courseId , @ Param ( 'lecture' ) lectureId ) { const unitDesc = JSON . parse ( file . buffer . toString ( ) ) ; return Unit . schema . statics . importJSON ( unitDesc , courseId , lectureId ) ; } }