@@ -174,117 +174,105 @@ const separateSchoolFeatures = (data) => {
174174 return data ;
175175}
176176
177- const getCreateHandler = ( service ) => {
178- return function ( req , res , next ) {
179- req . body . features = collectSchoolFeatures ( req . body ) ;
180-
181- api ( req )
182- . post ( '/' + service + '/' , {
183- // TODO: sanitize
184- json : req . body ,
185- } )
186- . then ( ( data ) => {
187- next ( ) ;
188- } )
189- . catch ( ( err ) => {
190- next ( err ) ;
191- } ) ;
192- } ;
177+ const createHandler = ( req , res , next ) => {
178+ req . body . features = collectSchoolFeatures ( req . body ) ;
179+
180+ api ( req )
181+ . post ( '/schools/' , {
182+ // TODO: sanitize
183+ json : req . body ,
184+ } )
185+ . then ( ( data ) => {
186+ next ( ) ;
187+ } )
188+ . catch ( ( err ) => {
189+ next ( err ) ;
190+ } ) ;
193191} ;
194192
195- const getUpdateHandler = ( service ) => {
196- return async function ( req , res , next ) {
197- try {
198- const configuration = await api ( req , { version : 'v3' } ) . get ( `/config/public` ) ;
199-
200-
201-
202- if ( configuration . TEACHER_STUDENT_VISIBILITY__IS_CONFIGURABLE ) {
203- await api ( req , { version : 'v3' } ) . patch ( `/school/${ req . params . id } ` , {
204- json : {
205- permissions : {
206- teacher : {
207- STUDENT_LIST : ! ! req . body . hasFeature_studentVisibility
208- }
193+ const updateHandler = async ( req , res , next ) => {
194+ try {
195+ const configuration = await api ( req , { version : 'v3' } ) . get ( `/config/public` ) ;
196+
197+ if ( configuration . TEACHER_STUDENT_VISIBILITY__IS_CONFIGURABLE ) {
198+ await api ( req , { version : 'v3' } ) . patch ( `/school/${ req . params . id } ` , {
199+ json : {
200+ permissions : {
201+ teacher : {
202+ STUDENT_LIST : ! ! req . body . hasFeature_studentVisibility
209203 }
210- } ,
211- } )
212- }
204+ }
205+ } ,
206+ } )
207+ }
213208
214- req . body . features = collectSchoolFeatures ( req . body ) ;
209+ req . body . features = collectSchoolFeatures ( req . body ) ;
215210
216- await api ( req ) . patch ( '/' + service + '/' + req . params . id , {
217- // TODO: sanitize
218- json : req . body ,
219- } )
211+ await api ( req ) . patch ( `/schools/ ${ req . params . id } ` , {
212+ // TODO: sanitize
213+ json : req . body ,
214+ } )
220215
221- res . redirect ( req . header ( 'Referer' ) ) ;
222- } catch ( err ) {
223- next ( err ) ;
224- }
225- } ;
216+ res . redirect ( req . header ( 'Referer' ) ) ;
217+ } catch ( err ) {
218+ next ( err ) ;
219+ }
226220} ;
227221
228- const getDetailHandler = ( service ) => {
229- return async function ( req , res , next ) {
230- try {
231- const configuration = await api ( req , { version : 'v3' } ) . get ( `/config/public` ) ;
232- const data = await api ( req ) . get ( '/' + service + '/' + req . params . id )
233-
234- // parse school features
235- separateSchoolFeatures ( data ) ;
222+ const detailHandler = async ( req , res , next ) => {
223+ try {
224+ const configuration = await api ( req , { version : 'v3' } ) . get ( `/config/public` ) ;
225+ const data = await api ( req ) . get ( `/schools/${ req . params . id } ` ) ;
236226
237- if ( ! configuration . TEACHER_STUDENT_VISIBILITY__IS_CONFIGURABLE ) {
238- data . hasFeature_studentVisibility_disabled = true ;
239- }
227+ // parse school features
228+ separateSchoolFeatures ( data ) ;
240229
241- data . hasFeature_studentVisibility = ! ! configuration . TEACHER_STUDENT_VISIBILITY__IS_ENABLED_BY_DEFAULT ;
230+ if ( ! configuration . TEACHER_STUDENT_VISIBILITY__IS_CONFIGURABLE ) {
231+ data . hasFeature_studentVisibility_disabled = true ;
232+ }
242233
243- if ( data . permissions && data . permissions . teacher && data . permissions . teacher . STUDENT_LIST !== undefined ) {
244- data . hasFeature_studentVisibility = data . permissions . teacher . STUDENT_LIST ;
245- }
234+ data . hasFeature_studentVisibility = ! ! configuration . TEACHER_STUDENT_VISIBILITY__IS_ENABLED_BY_DEFAULT ;
246235
247- if ( data . county && data . county . name && data . county . _id ) {
248- data . county = data . county . _id ;
249- }
236+ if ( data . permissions && data . permissions . teacher && data . permissions . teacher . STUDENT_LIST !== undefined ) {
237+ data . hasFeature_studentVisibility = data . permissions . teacher . STUDENT_LIST ;
238+ }
250239
251- res . json ( data ) ;
252- } catch ( err ) {
253- next ( err ) ;
240+ if ( data . county && data . county . name && data . county . _id ) {
241+ data . county = data . county . _id ;
254242 }
243+
244+ res . json ( data ) ;
245+ } catch ( err ) {
246+ next ( err ) ;
255247 }
256248} ;
257249
258- const getDeleteHandler = ( service ) => {
259- return function ( req , res , next ) {
260- api ( req )
261- . delete ( '/' + service + '/' + req . params . id )
262- . then ( ( _ ) => {
263- res . redirect ( req . header ( 'Referer' ) ) ;
264- } )
265- . catch ( ( err ) => {
266- next ( err ) ;
267- } ) ;
268- } ;
250+ const deleteHandler = ( req , res , next ) => {
251+ api ( req )
252+ . delete ( `/schools/${ req . params . id } ` )
253+ . then ( ( _ ) => {
254+ res . redirect ( req . header ( 'Referer' ) ) ;
255+ } )
256+ . catch ( ( err ) => {
257+ next ( err ) ;
258+ } ) ;
269259} ;
270260
271- const getDeleteFilesHandler = ( ) => {
272- return function ( req , res , next ) {
273- api ( req , { version : 'v3' , filesStorageApi : true } )
274- . delete ( '/admin/file/storage-location/school/' + req . params . id )
275- . then ( ( result ) => {
276- res . render ( 'schools/after-files-delete' , {
277- title : 'Alle Dateien der Schule wurden gelöscht' ,
278- data : result
279- } ) ;
280- } )
281- . catch ( ( err ) => {
282- next ( err ) ;
261+ const deleteFilesHandler = ( req , res , next ) => {
262+ api ( req , { version : 'v3' , filesStorageApi : true } )
263+ . delete ( '/admin/file/storage-location/school/' + req . params . id )
264+ . then ( ( result ) => {
265+ res . render ( 'schools/after-files-delete' , {
266+ title : 'Alle Dateien der Schule wurden gelöscht' ,
267+ data : result
283268 } ) ;
284- } ;
269+ } )
270+ . catch ( ( err ) => {
271+ next ( err ) ;
272+ } ) ;
285273} ;
286274
287- const getHandler = async ( req , res ) => {
275+ const findHandler = async ( req , res ) => {
288276 const itemsPerPage = req . query . limit || 10 ;
289277 const currentPage = parseInt ( req . query . p ) || 1 ;
290278 const sortCriteria = req . query . sort || '' ;
@@ -367,11 +355,11 @@ const getHandler = async (req, res) => {
367355// secure routes
368356router . use ( authHelper . authChecker ) ;
369357
370- router . patch ( '/:id' , getUpdateHandler ( 'schools' ) ) ;
371- router . get ( '/:id' , getDetailHandler ( 'schools' ) ) ;
372- router . delete ( '/:id' , getDeleteHandler ( 'schools' ) ) ;
373- router . post ( '/' , getCreateHandler ( 'schools' ) ) ;
374- router . all ( '/' , getHandler ) ;
375- router . delete ( "/:id/delete-files" , getDeleteFilesHandler ( ) ) ;
358+ router . patch ( '/:id' , updateHandler ) ;
359+ router . get ( '/:id' , detailHandler ) ;
360+ router . delete ( '/:id' , deleteHandler ) ;
361+ router . post ( '/' , createHandler ) ;
362+ router . all ( '/' , findHandler ) ;
363+ router . delete ( "/:id/delete-files" , deleteFilesHandler ) ;
376364
377365module . exports = router ;
0 commit comments