@@ -358,14 +358,39 @@ router.get('/prestaciones/solicitudes', async (req: any, res, next) => {
358358 const sort = { } ;
359359 sort [ 'esPrioritario' ] = 1 ;
360360
361- if ( req . query . ordenFecha || req . query . ordenFechaAsc ) {
362- sort [ 'solicitud.fecha' ] = - 1 ;
363- } else if ( req . query . solicitudDesde && req . query . solicitudHasta ) {
364- sort [ 'solicitud.fecha' ] = 1 ;
365- } else if ( req . query . ordenFechaEjecucion ) {
366- sort [ 'ejecucion.fecha' ] = - 1 ;
367- } else if ( req . query . solicitudDesdeActualizacion && req . query . solicitudHastaActualizacion ) {
368- sort [ 'updatedAt' ] = 1 ;
361+ if ( req . query . sortBy ) {
362+ const sortMap = {
363+ 'fechaSolicitud' : 'solicitud.fecha' ,
364+ 'fechaRegistro' : 'createdAt' ,
365+ 'actualizacion' : 'updatedAt'
366+ } ;
367+
368+ let sortBy = req . query . sortBy ;
369+ let sortOrder = - 1 ;
370+
371+ if ( sortBy . endsWith ( 'Asc' ) ) {
372+ sortBy = sortBy . replace ( 'Asc' , '' ) ;
373+ sortOrder = 1 ;
374+ } else if ( sortBy . endsWith ( 'Desc' ) ) {
375+ sortBy = sortBy . replace ( 'Desc' , '' ) ;
376+ sortOrder = - 1 ;
377+ }
378+
379+ const field = sortMap [ sortBy ] ;
380+ if ( field ) {
381+ sort [ field ] = sortOrder ;
382+ }
383+ } else {
384+ // sort['esPrioritario'] = 1;
385+ if ( req . query . ordenFecha || req . query . ordenFechaAsc ) {
386+ sort [ 'solicitud.fecha' ] = - 1 ;
387+ } else if ( req . query . solicitudDesde && req . query . solicitudHasta ) {
388+ sort [ 'solicitud.fecha' ] = 1 ;
389+ } else if ( req . query . ordenFechaEjecucion ) {
390+ sort [ 'ejecucion.fecha' ] = - 1 ;
391+ } else if ( req . query . solicitudDesdeActualizacion && req . query . solicitudHastaActualizacion ) {
392+ sort [ 'updatedAt' ] = 1 ;
393+ }
369394 }
370395
371396 pipeline . push ( { $sort : sort } ) ;
0 commit comments