1111 * or submit itself to any jurisdiction.
1212 */
1313
14- const { Op } = require ( 'sequelize' ) ;
1514const { repositories : { DataPassRepository, LhcPeriodRepository } } = require ( '../../../database' ) ;
1615const { dataSource } = require ( '../../../database/DataSource.js' ) ;
1716const { dataPassAdapter } = require ( '../../../database/adapters' ) ;
@@ -23,6 +22,7 @@ const { BadParameterError } = require('../../errors/BadParameterError');
2322const { SkimmingStage } = require ( '../../../domain/enums/SkimmingStage' ) ;
2423const { LogManager } = require ( '@aliceo2/web-ui' ) ;
2524const { NonPhysicsProductionsNamesWords } = require ( '../../../domain/enums/NonPhysicsProductionsNamesWords.js' ) ;
25+ const { dataPassSumary, dataPassVersionSummary } = require ( '../../views/dataPasses/summary.js' ) ;
2626
2727/**
2828 * @typedef DataPassIdentifier
@@ -141,12 +141,17 @@ class DataPassService {
141141 queryBuilder . where ( 'name' ) . not ( ) . substring ( `\\_${ NonPhysicsProductionsNamesWords . DEBUG } ` ) ;
142142 }
143143
144+ queryBuilder . selectAttributes ( [ ...dataPassSumary . attributes ] ) ;
145+
144146 const { count, rows } = await DataPassRepository . findAndCountAll ( queryBuilder ) ;
145- const dataPassesVersions = await DataPassVersionRepository . findAll ( {
146- include : 'statusHistory' ,
147- where : { dataPassId : { [ Op . in ] : rows . map ( ( { id } ) => id ) } } ,
148- order : [ [ 'statusHistory' , 'createdAt' , 'ASC' ] ] ,
149- } ) ;
147+ const dataPassVersionsQueryBuilder = dataSource . createQueryBuilder ( ) ;
148+
149+ dataPassVersionsQueryBuilder . selectAttributes ( [ ...dataPassVersionSummary . attributes ] ) ;
150+ dataPassVersionsQueryBuilder . includeAll ( [ ...dataPassVersionSummary . include ] ) ;
151+ dataPassVersionsQueryBuilder . where ( 'dataPassId' ) . oneOf ( ...rows . map ( ( { id } ) => id ) ) ;
152+ dataPassVersionsQueryBuilder . pushOrders ( [ ...dataPassVersionSummary . order ] ) ;
153+ const dataPassesVersions = await DataPassVersionRepository . findAll ( dataPassVersionsQueryBuilder ) ;
154+
150155 const dataPassIdToVersions = dataPassesVersions . reduce ( ( acc , version ) => {
151156 const { dataPassId } = version ;
152157 acc [ dataPassId ] = [ ...acc [ dataPassId ] ?? [ ] , version ] ;
@@ -159,7 +164,7 @@ class DataPassService {
159164
160165 return {
161166 count : count . length , // When using grouping sequelize returns from finAndCountAll counts per each group
162- rows : rows . map ( dataPassAdapter . toEntity ) ,
167+ rows : rows . map ( dataPassAdapter . toSummary ) ,
163168 } ;
164169 }
165170
0 commit comments