@@ -8,6 +8,7 @@ var knex = require('../utils/database').knex;
88var jwt = require ( 'jsonwebtoken' ) ; // used to create, sign, and verify tokens
99var Errors = require ( '../utils/errors' ) ;
1010var moment = require ( 'moment' ) ;
11+ var Trimmer = require ( '../utils/trim' ) ;
1112
1213/**
1314 * apply to participate in specific course
@@ -45,7 +46,7 @@ exports.coursesCourse_idApplyPOST = function (course_id, req) {
4546 new Applications ( generateApplicationFor ( user_id , course_id , areSlotsLefToParticipate ) )
4647 . save ( )
4748 . then ( ( application ) => {
48- resolve ( application ) ;
49+ resolve ( application . toJSON ( ) ) ;
4950 } )
5051 . catch ( ( error ) => {
5152 reject ( error ) ;
@@ -106,7 +107,7 @@ exports.coursesCourse_idFeedbackPOST = function (course_id, data) {
106107 new CourseFeedback ( { ...data , kurs_id : course_id } )
107108 . save ( )
108109 . then ( ( feedback ) => {
109- resolve ( feedback . attributes ) ;
110+ resolve ( feedback . toJSON ( ) ) ;
110111 } )
111112 . catch ( ( error ) => {
112113 console . log ( error ) ;
@@ -128,12 +129,12 @@ exports.coursesCourse_idGET = function (course_id) {
128129 Courses . where ( {
129130 kurs_id : course_id
130131 } )
131- . fetch ( { withRelated : [ "location" ] } )
132+ . fetch ( { withRelated : [ "location" , "teacher" ] } )
132133 . then ( ( course ) => {
133134 if ( ! course ) {
134135 reject ( Errors . notFound ( "GET ID " + course_id , "COURSE" ) ) ;
135136 }
136- resolve ( course . toJSON ( ) ) ;
137+ resolve ( Trimmer . course ( course . toJSON ( ) ) ) ;
137138 } )
138139 . catch ( ( error ) => {
139140 reject ( error ) ;
@@ -161,11 +162,11 @@ exports.coursesCourse_idSignoffPOST = function (course_id, req) {
161162 . save ( { ANM_STAT_ID : 3 } , {
162163 patch : true
163164 } )
164- . then ( applicationModel => {
165- if ( ! applicationModel ) {
165+ . then ( application => {
166+ if ( ! application ) {
166167 reject ( Errors . notFound ( "course with ID " , course_id ) ) ;
167168 }
168- resolve ( applicationModel ) ;
169+ resolve ( application . toJSON ( ) ) ;
169170 } )
170171 . catch ( err => {
171172 reject ( Errors . notFound ( "course with ID " , course_id ) ) ;
@@ -198,9 +199,9 @@ exports.coursesGET = function (query) {
198199 } ) ;
199200 } else {
200201 Courses
201- . fetchAll ( { withRelated : [ "location" ] } )
202- . then ( ( course ) => {
203- resolve ( course . toJSON ( ) ) ;
202+ . fetchAll ( { withRelated : [ "location" , "teacher" ] } )
203+ . then ( ( courses ) => {
204+ resolve ( Trimmer . courses ( courses . toJSON ( ) ) ) ;
204205 } )
205206 . catch ( ( error ) => {
206207 reject ( error ) ;
@@ -220,9 +221,9 @@ exports.coursesHighlightsGET = function () {
220221 return new Promise ( function ( resolve , reject ) {
221222 Courses
222223 . where ( { kurs_highlight : 1 } )
223- . fetchAll ( { withRelated : [ "location" ] } )
224+ . fetchAll ( { withRelated : [ "location" , "teacher" ] } )
224225 . then ( ( courses ) => {
225- resolve ( courses . toJSON ( ) ) ;
226+ resolve ( Trimmer . courses ( courses . toJSON ( ) ) ) ;
226227 } )
227228 . catch ( ( error ) => {
228229 reject ( error ) ;
@@ -237,12 +238,14 @@ exports.coursesLastminuteGET = function() {
237238 . query ( function ( qb ) {
238239 qb . whereBetween ( 'KURS_ANMFRIST' , [ moment ( ) . format ( 'YYYY-MM-DD' ) , moment ( ) . add ( 6 , 'weeks' ) . format ( 'YYYY-MM-DD' ) ] ) ;
239240 } )
240- . fetchAll ( { withRelated : [ "applications" , "location" ] } )
241+ . fetchAll ( { withRelated : [ "applications" , "location" , "teacher" ] } )
241242 . then ( ( courses ) => {
242- resolve ( courses
243- . filter ( item => item . related ( 'applications' ) . toJSON ( ) . length < item . attributes . KURS_TEIL_MAX )
244- . filter ( item => item . attributes . KURS_KURSSTAT_ID === 3 )
245- . map ( item => item . toJSON ( ) )
243+ resolve ( Trimmer . courses (
244+ courses
245+ . filter ( item => item . related ( 'applications' ) . toJSON ( ) . length < item . attributes . KURS_TEIL_MAX )
246+ . filter ( item => item . attributes . KURS_KURSSTAT_ID === 3 )
247+ . map ( item => item . toJSON ( ) )
248+ )
246249 )
247250 } )
248251 . catch ( ( error ) => {
0 commit comments